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; }
public DBProcessResult ModifyVehicle(EMVehicleViewModel view) { DBProcessResult result = new DBProcessResult(); try { IEMVehicleService service = new EMVehicleService(); IEMVehicleLogService logService = new EMVehicleLogService(); IdentityNoService noService = new IdentityNoService(); IEMGpsTypeService gpsTypeService = new EMGpsTypeService(); EMVehicle entity = ConvertHelper.ConvertObj<EMVehicleViewModel, EMVehicle>(view); EMVehicle oldEntity = service.Select(view.VehicleCode); entity.ExpireTime = oldEntity.ExpireTime; entity.InstallTime = oldEntity.InstallTime; entity.CreateTime = oldEntity.CreateTime; entity.IsStop = oldEntity.IsStop; EMGpsType gpsTypeEntity = gpsTypeService.Get(entity.GPSTypeID); entity.GPSTypeName = gpsTypeEntity.TypeName; //如果设备号改变,要重新获取GPSCode,添加和修改日志 if (entity.DeviceNo != oldEntity.DeviceNo) { bool bo = service.IsExist(view.DeviceNo); if (bo != true) { EnumGPSCodeRule codeType = (EnumGPSCodeRule)gpsTypeEntity.GPSCodeRule; entity.GPSCode = GetGPSCodeHelper.GetGPSCode(gpsTypeEntity.PrefixCode, codeType, entity.SIMNo, entity.DeviceNo); if (entity.DeviceNo.Length == gpsTypeEntity.MachineCodeLength) { //修改上一个日志 DateTime now = DateTime.Now; EMVehicleLog lastLog = logService.GetLast(entity.VehicleCode); if (lastLog != null) { lastLog.EndDate = now; logService.Update(lastLog); } //新增一个日志 EMVehicleLog vehicleLog = new EMVehicleLog() { BeginDate = 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, GroupID = entity.GroupID, VehicleCode = entity.VehicleCode }; logService.Insert(vehicleLog); entity.InstallTime = DateTime.Now; service.Update(entity); result.IsSuccess = true; } else { result.IsSuccess = false; result.Message = "GPS设备号长度,不在指定范围内,请重新填写!"; } } else { result.IsSuccess = false; result.Message = "GPS设备号已存在,请重新填写!"; } } else { service.Update(entity); result.IsSuccess = true; } } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; } return result; }
public DBProcessResult ModifyVehicle(VehicleViewModel view) { DBProcessResult result = new DBProcessResult(); try { IEMVehicleService service = new EMVehicleService(); EMVehicle entity = ConvertHelper.ConvertObj<VehicleViewModel, EMVehicle>(view); //同一租户下车牌号码不能重复 EMVehicle old = service.Select(view.VehicleCode); if (old.LicenceNumber != entity.LicenceNumber) { bool licenceNumberIsExist = service.IsExist(entity.TenantCode, entity.LicenceNumber); if (licenceNumberIsExist) { result.IsSuccess = false; result.Message = "已经有相同车牌号的车辆"; return result; } } service.Update(entity); result.IsSuccess = true; } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; } return result; }