Пример #1
0
        public DBProcessResult AddVehicle(EMVehicleViewModel view)
        {

            DBProcessResult result = new DBProcessResult();
            try
            {
                EMVehicleService service = new EMVehicleService();
                EHistoryDataStoreConfigService configService = new EHistoryDataStoreConfigService();
                EMGpsTypeService gpsTypeService = new EMGpsTypeService();
                EMVehicleLogService logService = new EMVehicleLogService();
                IdentityNoService noService = new IdentityNoService();

                bool licenceNumberIsExist = service.IsExist(view.TenantCode, view.LicenceNumber);
                if (licenceNumberIsExist)
                {
                    result.IsSuccess = false;
                    result.Message = "已经有相同车牌号的车辆";
                    return result;
                }

                EMVehicle entity = ConvertHelper.ConvertObj<EMVehicleViewModel, EMVehicle>(view);
                EMGpsType gpsTypeEntity = gpsTypeService.Get(entity.GPSTypeID);
                Logger.Info("code line 290: gpsTypeService.Get(entity.GPSTypeID)");
                entity.GPSTypeName = gpsTypeEntity.TypeName;

                bool bo = service.IsExist(view.DeviceNo);
                if (bo != true)
                {
                    //新增车辆历史数据配置
                    string tableName = GetTableNameByCondition(gpsTypeEntity.PrefixCode);
                    EHisotryDataStoreTables table = configService.GetHistoryTable(tableName);
                    Logger.Info("code line 299: configService.GetHistoryTable(tableName)");
                    if (table == null)
                    {
                        result.IsSuccess = false;
                        result.Message = string.Format("找不到对应的历史数据表[{0}],请联系DBA!", tableName);
                        return result;
                    }

                    //新增车辆
                    EnumGPSCodeRule codeType = (EnumGPSCodeRule)gpsTypeEntity.GPSCodeRule;
                    entity.GPSCode = GetGPSCodeHelper.GetGPSCode(gpsTypeEntity.PrefixCode, codeType, entity.SIMNo, entity.DeviceNo);

                    if (entity.DeviceNo.Length == gpsTypeEntity.MachineCodeLength)
                    {
                        entity.CreateTime = DateTime.Now;
                        entity.InstallTime = DateTime.Now;
                        GetVehicleGroupID(entity);    //客户管理中新增车辆时,没有车辆组,默认增加到顶级车辆组
                        service.Insert(entity);

                        EHistoryDataStoreConfig configEntity = new EHistoryDataStoreConfig();
                        configEntity.CreateDate = DateTime.Now;
                        configEntity.Enable = true;
                        configEntity.StoreTable = table;
                        configEntity.VehicleCode = entity.VehicleCode;
                        configService.Insert(configEntity);

                        //新增车辆Log
                        EMVehicleLog vehicleLog = new EMVehicleLog()
                        {
                            BeginDate = DateTime.Now,
                            LogID = noService.GetVehicleLogID(),
                            DeviceNo = entity.DeviceNo,
                            EndDate = null,
                            GPSCode = entity.GPSCode,
                            GPSTypeID = entity.GPSTypeID,
                            InitMileage = entity.InitMileage,
                            LicenceNumber = entity.LicenceNumber,
                            Operator = view.UserName,
                            SIMNo = entity.SIMNo,
                            TenantCode = entity.TenantCode,
                            VehicleCode = entity.VehicleCode,
                            GroupID = entity.GroupID,
                        };
                        logService.Insert(vehicleLog);
                        view.VehicleCode = entity.VehicleCode;
                        result.IsSuccess = true;
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message = "GPS设备号长度,不在指定范围内,请重新填写!";
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message = "设备号已存在,请重新填写!";
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message = ex.Message;
                Logger.Info(ex.StackTrace + "【" + ex.Message + "】");
            }
            return result;
        }