Example #1
0
        private Task <OperationResult> InternalSendLineSettings(
            LineProperty LineProperty,
            string PlateNum,
            string TerminalCode,
            List <MapLinesDetailModel> LineModel,
            TerminalOperationClient client
            )
        {
            return(Task <OperationResult> .Run(() =>
            {
                dynamic settingData = new ExpandoObject();
                settingData.LineProperty = LineProperty;
                settingData.Vehicles = new string[] { PlateNum };
                settingData.LineID = LineModel[0].ID;

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

                var LineInflectionPointItems = new LineInflectionPointItem[LineModel.Count];
                for (int i = 0; i != LineModel.Count; i++)
                {
                    LineInflectionPointItems[i] = new LineInflectionPointItem()
                    {
                        PointID = (uint)LineModel[i].OrderID,
                        RoadID = (uint)LineModel[i].ID,
                        PointLatitude = LineModel[i].Latitude,
                        PointLongitude = LineModel[i].Longitude,
                        RoadWidth = (byte)LineModel[i].RoadWidth.GetValueOrDefault(),
                        DrivingTooLongThresholding = (ushort)LineModel[i].MaxSecond.GetValueOrDefault(),
                        DrivingTooLackThresholding = (ushort)LineModel[i].MinSecond.GetValueOrDefault(),
                        MaxSpeed = (ushort)LineModel[i].SpeedLimit.GetValueOrDefault(),
                        OverSpeedDuration = (byte)LineModel[i].OverSpeedDuration.GetValueOrDefault()
                    };

                    if (LineModel[i].IsCheckTime.HasValue && LineModel[i].IsCheckTime.Value)
                    {
                        LineInflectionPointItems[i].RoadProperty |= RoadProperty.行驶时间;
                    }
                    if (LineModel[i].IsCheckSpeed.HasValue && LineModel[i].IsCheckSpeed.Value)
                    {
                        LineInflectionPointItems[i].RoadProperty |= RoadProperty.限速;
                    }
                }

                var response = client.SetLine(TerminalCode, new LineSettingData()
                {
                    LineID = (uint)LineModel[0].ID,
                    IsCyclical = false,
                    LineProperty = LineProperty,
                    StartDateTime = DateTime.Parse(LineModel[0].StartTime),
                    EndDateTime = DateTime.Parse(LineModel[0].EndTime),
                    LineInflectionPointItems = LineInflectionPointItems
                });

                OperationResult resultElement = null;

                if (!response.State)
                {
                    //车机端操作失败
                    resultElement = new OperationResult()
                    {
                        Success = false,
                        Message = response.Message
                    };
                    TerminalSettingsBLL.InsertTerminalOperationsLog(
                        base.CurrentUserID,
                        TerminalSettingType.RouteSettings_Add,
                        PlateNum,
                        TerminalCode,
                        false,
                        JsonConvert.SerializeObject(settingData),
                        resultElement.Message,
                        GetRemoteAddress()
                        );
                }
                else
                {
                    bool success = TerminalSettingsBLL.AddLineVehicleRelation(PlateNum, TerminalCode, exists.Item2.Value, (ushort)LineProperty);
                    resultElement = new OperationResult()
                    {
                        Success = success,
                        Message = success ? DisplayText.OperationSucceeded : "车机端更新操作成功完成,更新数据库记录出错。"
                    };
                    TerminalSettingsBLL.InsertTerminalOperationsLog(
                        base.CurrentUserID,
                        TerminalSettingType.RouteSettings_Add,
                        PlateNum,
                        TerminalCode,
                        success,
                        JsonConvert.SerializeObject(settingData),
                        resultElement.Message,
                        GetRemoteAddress()
                        );
                }
                return resultElement;
            }));
        }