Example #1
0
        private Task <OperationResult> InternalAddRegionSettings(
            RegionProperty RegionProperty,
            string PlateNum,
            string TerminalCode,
            List <MapRegionsEditModel> RegionModel,
            TerminalOperationClient client
            )
        {
            return(Task <OperationResult> .Run(() =>
            {
                dynamic settingData = new ExpandoObject();
                settingData.OperationType = RegionSettingType.追加区域;
                settingData.RegionProperty = RegionProperty;
                settingData.Vehicles = new string[] { PlateNum };
                settingData.RegionID = RegionModel[0].ID;

                var exists = TerminalSettingsBLL.RegionVehicleRelationExists(PlateNum, TerminalCode, RegionModel[0].ID);
                if (exists.Item1)
                {
                    var r = new OperationResult()
                    {
                        Success = false,
                        Message = "数据库中已存在与指定车辆、区域对应的设置记录。"
                    };
                    TerminalSettingsBLL.InsertTerminalOperationsLog(
                        base.CurrentUserID,
                        TerminalSettingType.RegionSettings_Add,
                        PlateNum,
                        TerminalCode,
                        false,
                        JsonConvert.SerializeObject(settingData),
                        r.Message,
                        GetRemoteAddress()
                        );
                    return r;
                }

                StringBuilder start = new StringBuilder(), end = new StringBuilder();
                start.Append(RegionModel[0].StartDate == null ? "1601.01.01" : RegionModel[0].StartDate);
                start.Append(" ");
                start.Append(RegionModel[0].StartTime == null ? "00:00:00.000" : RegionModel[0].StartTime);

                end.Append(RegionModel[0].EndDate == null ? "1601.01.01" : RegionModel[0].EndDate);
                end.Append(" ");
                end.Append(RegionModel[0].EndTime == null ? "00:00:00.000" : RegionModel[0].EndTime);

                OperationResultGeneralRep response = null;
                switch (RegionModel[0].RegionsType)
                {
                case 1:        //圆形
                    response = client.SetCircularRegion(TerminalCode, new CircularRegionSettingData()
                    {
                        RegionSettingType = RegionSettingType.追加区域,
                        CircularRegionItems = new CircularRegionItem[]
                        {
                            new CircularRegionItem()
                            {
                                RegionID = (uint)RegionModel[0].ID,
                                CentralPointLatitude = RegionModel[0].CenterLatitude,
                                CentralPointLongitude = RegionModel[0].CenterLongitude,
                                Radius = Convert.ToUInt32(RegionModel[0].Radius),
                                MaxSpeed = Convert.ToUInt16(RegionModel[0].SpeedLimit),
                                OverSpeedDuration = (byte)RegionModel[0].OverSpeedDuration,
                                IsCyclical = RegionModel[0].Periodic,
                                StartDateTime = DateTime.Parse(start.ToString()),
                                EndDateTime = DateTime.Parse(end.ToString()),
                                RegionProperty = (RegionProperty)RegionProperty,
                            }
                        }
                    });
                    break;

                case 2:        //矩形
                    response = client.SetRectangularRegion(TerminalCode, new RectangularRegionSettingData()
                    {
                        RegionSettingType = RegionSettingType.追加区域,
                        RectangularRegionItems = new RectangularRegionItem[]
                        {
                            new RectangularRegionItem()
                            {
                                RegionID = (uint)RegionModel[0].ID,
                                TopLeftPointLatitude = RegionModel[0].LeftUpperLatitude,
                                TopLeftPointLongitude = RegionModel[0].LeftUpperLongitude,
                                BottomRightPointLatitude = RegionModel[0].RightLowerLatitude,
                                BottomRightPointLongitude = RegionModel[0].RightLowerLongitude,
                                MaxSpeed = Convert.ToUInt16(RegionModel[0].SpeedLimit),
                                OverSpeedDuration = (byte)RegionModel[0].OverSpeedDuration,
                                IsCyclical = RegionModel[0].Periodic,
                                StartDateTime = DateTime.Parse(start.ToString()),
                                EndDateTime = DateTime.Parse(end.ToString()),
                                RegionProperty = (RegionProperty)RegionProperty,
                            }
                        }
                    });
                    break;

                case 3:        //多边形
                    break;

                default:
                    break;
                }

                OperationResult resultElement = null;

                if (!response.State)
                {
                    //车机端操作失败
                    resultElement = new OperationResult()
                    {
                        Success = false,
                        Message = response.Message
                    };
                    TerminalSettingsBLL.InsertTerminalOperationsLog(
                        base.CurrentUserID,
                        TerminalSettingType.RegionSettings_Update,
                        PlateNum,
                        TerminalCode,
                        false,
                        JsonConvert.SerializeObject(settingData),
                        resultElement.Message,
                        GetRemoteAddress()
                        );
                }
                else
                {
                    bool success = TerminalSettingsBLL.AddRegionVehicleRelation(PlateNum, TerminalCode, RegionModel[0].ID, (ushort)RegionProperty);
                    resultElement = new OperationResult()
                    {
                        Success = success,
                        Message = success ? DisplayText.OperationSucceeded : "车机端更新操作成功完成,添加数据库记录出错。"
                    };
                    TerminalSettingsBLL.InsertTerminalOperationsLog(
                        base.CurrentUserID,
                        TerminalSettingType.RegionSettings_Update,
                        PlateNum,
                        TerminalCode,
                        success,
                        JsonConvert.SerializeObject(settingData),
                        resultElement.Message,
                        GetRemoteAddress()
                        );
                }
                return resultElement;
            }));
        }