public void SaveDevice(EDevice device) { var odevice = _rep.Get<EDevice>(p => p.Id == device.Id); if (odevice == null) { throw new NullReferenceException("不存在设备!"); } if (device.DeviceGpsNo != odevice.DeviceGpsNo) { if (CheckDeviceGpsNoIsExist(device.DeviceGpsNo)) { throw new BusinessException("已经存在Gps设备号!"); } } if (device.DeviceGpsSimNo != odevice.DeviceGpsSimNo) { if (CheckDeviceGpsSimNoIsExist(device.DeviceGpsSimNo)) { throw new BusinessException("已经存在Sim卡号!"); } } if (device.UserId != odevice.UserId) { device.DeviceGroupId = _deviceGroupService.GetRootDeviceGroupByUserId(device.UserId).Id; } using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); var deviceLog = new EDeviceLog { DeviceId = device.Id, CreateTime = DateTime.Now, LogType = EnumDeviceLogType.EditDevice, UserName = _stateService.GetPassport().User.UserName, LogContent = new { old = odevice, last = device }.ToJson() }; _rep.Add(deviceLog, tran); device.DeviceGpsCode = GetDeviceGpsCode(device.DeviceGpsTypeId.Value, device.DeviceGpsNo, device.DeviceGpsSimNo); _rep.Save(device, p => p.Id == device.Id, p => new Columns(p.DeviceName, p.DeviceTypeId, p.DeviceExpireTime, p.DeviceGpsNo, p.DeviceGpsCode, p.DeviceGpsTypeId, p.DeviceGpsSimNo, p.DeviceGpsInstallTime, p.UserId, p.DeviceGroupId), tran); dmTrans.Commit(); _cacheService.UpdateCacheDependent(CacheKey.Gps_Device_By_DeviceGpsCode.GetFormat(odevice.DeviceGpsCode)); _cacheService.UpdateCacheDependent(CacheKey.Gps_Auto_Complete_Device); } catch { dmTrans.Rollback(); throw; } } }
public void RemoveDeviceByDeviceId(int deviceId, IDbTransaction tran) { var odevice = _rep.Get<EDevice>(p => p.Id == deviceId); if (odevice == null) { return; } var deviceLog = new EDeviceLog { DeviceId = odevice.Id, CreateTime = DateTime.Now, DeviceName = odevice.DeviceName, LogType = EnumDeviceLogType.RemoveDevice, UserName = _stateService.GetPassport().User.UserName, LogContent = new { old = odevice }.ToJson() }; _rep.Add(deviceLog, tran); _rep.Remove<EDevice>(p => p.Id == odevice.Id, tran); _rep.Remove<EDeviceCurrentData>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EMileageReportDay>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmSettingOverspeed>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmSettingInOutArea>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmSettingParkingNotStalled>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmSettingTired>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmSettingAutoFortify>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmSettingMainPowerBreak>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmReportOverspeed>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmReportInOutArea>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmReportParkingNotStalled>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmReportTired>(p => p.DeviceId == odevice.Id, tran); _rep.Remove<EAlarmReportMainPowerBreak>(p => p.DeviceId == odevice.Id, tran); _cacheService.UpdateCacheDependent(CacheKey.Gps_Auto_Complete_Device); _cacheService.UpdateCacheDependent(CacheKey.Gps_Device_By_DeviceGpsCode.GetFormat(odevice.DeviceGpsCode)); _cacheService.UpdateCacheDependent(CacheKey.Gps_AlarmSetting_By_DeviceId.GetFormat(typeof(EAlarmSettingInOutArea).Name, odevice.Id)); _cacheService.UpdateCacheDependent(CacheKey.Gps_AlarmSetting_By_DeviceId.GetFormat(typeof(EAlarmSettingOverspeed).Name, odevice.Id)); _cacheService.UpdateCacheDependent(CacheKey.Gps_AlarmSetting_By_DeviceId.GetFormat(typeof(EAlarmSettingParkingNotStalled).Name, odevice.Id)); _cacheService.UpdateCacheDependent(CacheKey.Gps_AlarmSetting_By_DeviceId.GetFormat(typeof(EAlarmSettingTired).Name, odevice.Id)); _cacheService.UpdateCacheDependent(CacheKey.Gps_AlarmSetting_By_DeviceId.GetFormat(typeof(EAlarmSettingAutoFortify).Name, odevice.Id)); _cacheService.UpdateCacheDependent(CacheKey.Gps_AlarmSetting_By_DeviceId.GetFormat(typeof(EAlarmSettingMainPowerBreak).Name, odevice.Id)); _cacheService.UpdateCacheDependent(CacheKey.Gps_VDeviceCurrentDataStatusDetail_By_DeviceId.GetFormat(odevice.Id)); }