| | |
| | | import com.moral.api.service.DeviceService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import com.moral.api.util.CacheUtils; |
| | | import com.moral.api.util.AdjustDataUtils; |
| | | import com.moral.api.util.LogUtils; |
| | | import com.moral.constant.Constants; |
| | |
| | | * 从redis获取设备信息 |
| | | * */ |
| | | private Map<String, Object> getDeviceInfoFromRedis(String mac) { |
| | | Map<String, Object> deviceInfo = (Map<String, Object>) redisTemplate.opsForValue().get(getDeviceKey(mac)); |
| | | return deviceInfo; |
| | | return (Map<String, Object>) redisTemplate.opsForValue().get(getDeviceKey(mac)); |
| | | } |
| | | |
| | | /* |
| | |
| | | return keysConnect(RedisConstants.DEVICE, mac); |
| | | } |
| | | |
| | | /* |
| | | * 从redis获取报警级别 |
| | | * */ |
| | | private Map<String, Object> getOrgAlarmConfigFromRedis(String orId) { |
| | | return null; |
| | | } |
| | | |
| | | //redis key前缀 |
| | | private String keysConnect(String... keys) { |
| | | StringBuilder key = new StringBuilder(keys[0]); |
| | |
| | | deviceMapper.insert(device); |
| | | Map<String, Object> deviceInfo = selectDeviceInfoById(device.getId()); |
| | | //维护组织型号关系表 |
| | | insertOrganizationUnitAlarm(orgId, device.getDeviceVersionId()); |
| | | insertOrganizationUnitAlarm(orgId,device.getDeviceVersionId()); |
| | | //新增设备信息存入redis |
| | | String mac = device.getMac(); |
| | | //从redis中删除设备信息 |
| | | delDeviceInfoFromRedis(mac); |
| | | //设备信息存入redis |
| | | setDeviceInfoToRedis(mac, deviceInfo); |
| | | //刷新deviceInfo缓存 |
| | | CacheUtils.flushDeviceAlarmInfo(); |
| | | //操作日志记录 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | |
| | | String mac = device.getMac(); |
| | | //从redis中删除设备信息 |
| | | delDeviceInfoFromRedis(mac); |
| | | //维护组织型号关系表 |
| | | Integer versionId = device.getDeviceVersionId(); |
| | | Integer orgId = device.getOrganizationId(); |
| | | deleteOrganizationUnitAlarm(orgId,versionId); |
| | | //刷新deviceInfo缓存 |
| | | CacheUtils.flushDeviceAlarmInfo(); |
| | | //操作日志记录 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | |
| | | Integer deviceId = device.getId(); |
| | | Device oldDevice = deviceMapper.selectById(deviceId); |
| | | //判断是否更新了站点,如果更新了站点则查询对应站点的组织id进行更新 |
| | | if (!ObjectUtils.isEmpty(device.getMonitorPointId())) { |
| | | if(!ObjectUtils.isEmpty(device.getMonitorPointId())){ |
| | | MonitorPoint monitorPoint = monitorPointMapper.selectById(device.getMonitorPointId()); |
| | | device.setOrganizationId(monitorPoint.getOrganizationId()); |
| | | } |
| | |
| | | Device updateDevice = deviceMapper.selectById(deviceId); |
| | | String mac = updateDevice.getMac(); |
| | | //维护组织型号关系表 |
| | | Integer oldOrgId = oldDevice.getOrganizationId(); |
| | | Integer newOrgId = updateDevice.getOrganizationId(); |
| | | Integer oldVersionId = oldDevice.getDeviceVersionId(); |
| | | Integer newVersionId = updateDevice.getDeviceVersionId(); |
| | | if (!oldOrgId.equals(newOrgId) || !oldVersionId.equals(newVersionId)) { |
| | | deleteOrganizationUnitAlarm(oldOrgId, oldVersionId); |
| | | insertOrganizationUnitAlarm(newOrgId, newVersionId); |
| | | } |
| | | Integer oldOrgId = oldDevice.getOrganizationId(); |
| | | Integer newOrgId = updateDevice.getOrganizationId(); |
| | | Integer oldVersionId = oldDevice.getDeviceVersionId(); |
| | | Integer newVersionId = updateDevice.getDeviceVersionId(); |
| | | if(!oldOrgId.equals(newOrgId)||!oldVersionId.equals(newVersionId)){ |
| | | deleteOrganizationUnitAlarm(oldOrgId,oldVersionId); |
| | | insertOrganizationUnitAlarm(newOrgId,newVersionId); |
| | | } |
| | | //从redis中删除设备信息 |
| | | delDeviceInfoFromRedis(mac); |
| | | Map<String, Object> deviceInfo = selectDeviceInfoById(deviceId); |
| | | //设备信息存入redis |
| | | setDeviceInfoToRedis(mac, deviceInfo); |
| | | //刷新deviceInfo缓存 |
| | | CacheUtils.flushDeviceAlarmInfo(); |
| | | //操作日志记录 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | |
| | | return state; |
| | | } |
| | | |
| | | private void insertOrganizationUnitAlarm(Integer orgId, Integer versionId) { |
| | | private void insertOrganizationUnitAlarm(Integer orgId,Integer versionId){ |
| | | QueryWrapper<OrganizationUnitAlarm> queryOrganizationVersionWrapper = new QueryWrapper<>(); |
| | | queryOrganizationVersionWrapper.eq("organization_id", orgId); |
| | | queryOrganizationVersionWrapper.eq("version_id", versionId); |
| | | queryOrganizationVersionWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | queryOrganizationVersionWrapper.eq("organization_id",orgId); |
| | | queryOrganizationVersionWrapper.eq("version_id",versionId); |
| | | queryOrganizationVersionWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | List<OrganizationUnitAlarm> organizationUnitAlarms = organizationUnitAlarmMapper.selectList(queryOrganizationVersionWrapper); |
| | | if (ObjectUtils.isEmpty(organizationUnitAlarms)) { |
| | | QueryWrapper<VersionSensorUnit> queryVersionSensorUnitWrapper = new QueryWrapper<>(); |
| | | queryVersionSensorUnitWrapper.eq("version_id", versionId); |
| | | queryVersionSensorUnitWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | if(ObjectUtils.isEmpty(organizationUnitAlarms)){ |
| | | QueryWrapper<VersionSensorUnit> queryVersionSensorUnitWrapper =new QueryWrapper<>(); |
| | | queryVersionSensorUnitWrapper.eq("version_id",versionId); |
| | | queryVersionSensorUnitWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | List<VersionSensorUnit> versionSensorUnits = versionSensorUnitMapper.selectList(queryVersionSensorUnitWrapper); |
| | | if (!ObjectUtils.isEmpty(versionSensorUnits)) { |
| | | if(!ObjectUtils.isEmpty(versionSensorUnits)){ |
| | | for (VersionSensorUnit versionSensorUnit : versionSensorUnits) { |
| | | OrganizationUnitAlarm organizationUnitAlarm = new OrganizationUnitAlarm(); |
| | | organizationUnitAlarm.setOrganizationId(orgId); |
| | |
| | | } |
| | | } |
| | | |
| | | private void deleteOrganizationUnitAlarm(Integer orgId, Integer versionId) { |
| | | private void deleteOrganizationUnitAlarm(Integer orgId,Integer versionId){ |
| | | QueryWrapper<Device> queryOrganizationVersionWrapper = new QueryWrapper<>(); |
| | | queryOrganizationVersionWrapper.eq("organization_id", orgId); |
| | | queryOrganizationVersionWrapper.eq("device_version_id", versionId); |
| | | queryOrganizationVersionWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | queryOrganizationVersionWrapper.eq("organization_id",orgId); |
| | | queryOrganizationVersionWrapper.eq("device_version_id",versionId); |
| | | queryOrganizationVersionWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | List<Device> devices = deviceMapper.selectList(queryOrganizationVersionWrapper); |
| | | if (ObjectUtils.isEmpty(devices)) {//如果为空,则组织没有该型号的设备了。 |
| | | if(ObjectUtils.isEmpty(devices)){//如果为空,则组织没有该型号的设备了。 |
| | | UpdateWrapper deleteWrapper = new UpdateWrapper(); |
| | | deleteWrapper.eq("organization_id", orgId); |
| | | deleteWrapper.eq("version_id", versionId); |
| | | deleteWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | deleteWrapper.set("is_delete", Constants.DELETE); |
| | | organizationUnitAlarmMapper.update(null, deleteWrapper); |
| | | deleteWrapper.eq("organization_id",orgId); |
| | | deleteWrapper.eq("version_id",versionId); |
| | | deleteWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | deleteWrapper.set("is_delete",Constants.DELETE); |
| | | organizationUnitAlarmMapper.update(null,deleteWrapper); |
| | | } |
| | | } |
| | | } |