| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.entity.*; |
| | | import com.moral.api.mapper.*; |
| | | import com.moral.api.pojo.redisBean.SpecialDeviceInfoDTO; |
| | | import com.moral.api.pojo.vo.device.DeviceVO; |
| | | import com.moral.api.service.SpecialDeviceService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.util.AdjustDataUtils; |
| | | import com.moral.api.util.CacheUtils; |
| | | import com.moral.api.util.LogUtils; |
| | | import com.moral.constant.Constants; |
| | |
| | | @Autowired(required = false) |
| | | private VersionSensorUnitMapper versionSensorUnitMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private GovMonitorPointMapper govMonitorPointMapper; |
| | | |
| | | @Autowired |
| | | private LogUtils logUtils; |
| | | private AdjustDataUtils adjustDataUtils; |
| | | |
| | | /* |
| | | * 从redis获取设备信息 |
| | | * */ |
| | | private Map<String, Object> getDeviceInfoFromRedis(String mac) { |
| | | return (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DEVICE, mac); |
| | | private SpecialDeviceInfoDTO getDeviceInfoFromRedis(String mac) { |
| | | return (SpecialDeviceInfoDTO) redisTemplate.opsForHash().get(RedisConstants.SPECIAL_DEVICE, mac); |
| | | } |
| | | |
| | | /* |
| | | * 设备信息存入redis |
| | | */ |
| | | private void setDeviceInfoToRedis(String mac, Map<String, Object> deviceInfo) { |
| | | redisTemplate.opsForHash().put(RedisConstants.DEVICE, mac, deviceInfo); |
| | | private void setDeviceInfoToRedis(String mac, SpecialDeviceInfoDTO specialDeviceInfoDTO) { |
| | | redisTemplate.opsForHash().put(RedisConstants.SPECIAL_DEVICE, mac, specialDeviceInfoDTO); |
| | | } |
| | | |
| | | /* |
| | | * 从redis删除设备信息 |
| | | */ |
| | | private void delDeviceInfoFromRedis(String mac) { |
| | | redisTemplate.opsForHash().delete(RedisConstants.DEVICE, mac); |
| | | redisTemplate.opsForHash().delete(RedisConstants.SPECIAL_DEVICE, mac); |
| | | } |
| | | |
| | | @Override |
| | |
| | | String updateTime = SDF.format(specialDevice.getUpdateTime()); |
| | | specialDeviceMap.put("createTime",createTime); |
| | | specialDeviceMap.put("updateTime",updateTime); |
| | | Map<String,Object> govMonitorPointMap = new HashMap<>(); |
| | | if (!ObjectUtils.isEmpty(specialDevice.getGuid()) && specialDevice.getGuid()!=null && !"".equals(specialDevice.getGuid())){ |
| | | String guid = specialDevice.getGuid().toString(); |
| | | QueryWrapper<GovMonitorPoint> wapper_govMonitorPoint = new QueryWrapper<>(); |
| | | wapper_govMonitorPoint.eq("is_delete",Constants.NOT_DELETE); |
| | | wapper_govMonitorPoint.eq("guid",guid); |
| | | GovMonitorPoint govMonitorPoint = govMonitorPointMapper.selectOne(wapper_govMonitorPoint); |
| | | if (!ObjectUtils.isEmpty(govMonitorPoint)){ |
| | | govMonitorPointMap.put("id",govMonitorPoint.getId()); |
| | | govMonitorPointMap.put("guid",govMonitorPoint.getGuid()); |
| | | govMonitorPointMap.put("name",govMonitorPoint.getName()); |
| | | } |
| | | } |
| | | specialDeviceMap.put("govMonitorPoint",govMonitorPointMap); |
| | | List<Map<String,Object>> operateList = new ArrayList<>(); |
| | | if (!ObjectUtils.isEmpty(specialDevice.getOperateIds()) && specialDevice.getOperateIds()!=null){ |
| | | String operateIds = specialDevice.getOperateIds(); |
| | |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("添加了特殊设备历史数据:").append(insertSpecialDeviceHistory.getName()).append(":").append("mac:").append(insertSpecialDeviceHistory.getMac()); |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); |
| | | }else { |
| | | /*UpdateWrapper<SpecialDeviceHistory> wrapper_insertSpecialDeviceHistory = new UpdateWrapper<>(); |
| | | wrapper_specialDeviceHistory.eq("is_delete",Constants.NOT_DELETE); |
| | |
| | | } |
| | | |
| | | } |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | } |
| | | Map<String, Object> deviceInfo = selectDeviceInfoById(specialDevice.getId()); |
| | | //Map<String, Object> deviceInfo = selectDeviceInfoById(specialDevice.getId()); |
| | | SpecialDeviceInfoDTO specialDeviceInfoDTO = selectDeviceInfoDTOById(specialDevice.getId()); |
| | | //维护组织型号关系表 |
| | | insertOrganizationUnitAlarm(specialDevice.getOrganizationId(), specialDevice.getDeviceVersionId()); |
| | | //新增设备信息存入redis |
| | |
| | | //从redis中删除设备信息 |
| | | delDeviceInfoFromRedis(mac1); |
| | | //设备信息存入redis |
| | | setDeviceInfoToRedis(mac1, deviceInfo); |
| | | setDeviceInfoToRedis(mac1, specialDeviceInfoDTO); |
| | | //刷新deviceInfo缓存 |
| | | CacheUtils.refreshSpecialDeviceAlarmInfo(); |
| | | //操作日志记录 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("添加了特殊设备:").append(specialDevice.getName()).append(":").append("mac:").append(mac); |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); |
| | | resultMap.put("code", ResponseCodeEnum.SUCCESS.getCode()); |
| | | resultMap.put("msg", ResponseCodeEnum.SUCCESS.getMsg()); |
| | | return resultMap; |
| | |
| | | } |
| | | //从redis中删除设备信息 |
| | | delDeviceInfoFromRedis(oleMac); |
| | | Map<String, Object> deviceInfo = selectDeviceInfoById(specialDeviceId); |
| | | SpecialDeviceInfoDTO specialDeviceInfoDTO = selectDeviceInfoDTOById(specialDevice.getId()); |
| | | //设备信息存入redis |
| | | setDeviceInfoToRedis(updateSpecialDevice.getMac(), deviceInfo); |
| | | setDeviceInfoToRedis(updateSpecialDevice.getMac(), specialDeviceInfoDTO); |
| | | //刷新deviceInfo缓存 |
| | | CacheUtils.refreshSpecialDeviceAlarmInfo(); |
| | | QueryWrapper<SpecialDeviceHistory> wrapper_specialDeviceHistory = new QueryWrapper<>(); |
| | |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("添加了特殊设备历史数据:").append(updateSpecialDeviceHistory.getName()).append(":").append("mac:").append(updateSpecialDeviceHistory.getMac()); |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); |
| | | }else { |
| | | /*UpdateWrapper<SpecialDeviceHistory> wrapper_insertSpecialDeviceHistory = new UpdateWrapper<>(); |
| | | wrapper_specialDeviceHistory.eq("is_delete",Constants.NOT_DELETE); |
| | |
| | | //操作日志记录 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("修改了特殊设备:").append(specialDeviceHistory.getId()).append(":"); |
| | | content.append("修改了历史特殊设备:").append(specialDeviceHistory.getId()).append(";"); |
| | | Field[] fields = SpecialDevice.class.getDeclaredFields(); |
| | | for (Field field : fields) { |
| | | if (field.getName().equals("id")) { |
| | |
| | | Object o1 = method.invoke(specialDeviceHistory); |
| | | Object o2 = method.invoke(updateSpecialDeviceHistory); |
| | | if (o2 != null) { |
| | | content.append(fieldName).append(":").append(o1).append("-->").append(o2).append(":"); |
| | | content.append(fieldName).append(":").append(o1).append("-->").append(o2).append(";"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | |
| | | } |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | } |
| | | //操作日志记录 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("修改了特殊设备:").append(specialDeviceId).append(":"); |
| | | content.append("修改了特殊设备:").append(specialDeviceId).append(";"); |
| | | Field[] fields = SpecialDevice.class.getDeclaredFields(); |
| | | for (Field field : fields) { |
| | | if (field.getName().equals("id")) { |
| | |
| | | Object o1 = method.invoke(oldSpecialDevice); |
| | | Object o2 = method.invoke(specialDevice); |
| | | if (o2 != null) { |
| | | content.append(fieldName).append(":").append(o1).append("-->").append(o2).append(":"); |
| | | content.append(fieldName).append(":").append(o1).append("-->").append(o2).append(";"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | |
| | | } |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); |
| | | } |
| | | |
| | | @Override |
| | |
| | | Integer orgId = specialDevice.getOrganizationId(); |
| | | deleteOrganizationUnitAlarm(orgId, versionId); |
| | | //刷新deviceInfo缓存 |
| | | CacheUtils.refreshDeviceAlarmInfo(); |
| | | CacheUtils.refreshSpecialDeviceAlarmInfo(); |
| | | //操作日志记录 |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("删除了设备:").append(specialDevice.getName()).append(";").append("mac:").append(mac); |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE); |
| | | LogUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> selectDeviceInfoById(Integer deviceId) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public SpecialDeviceInfoDTO selectDeviceInfoDTOById(Integer deviceId) { |
| | | String mac = specialDeviceMapper.selectById(deviceId).getMac(); |
| | | Map<String, Object> specialDeviceInfo = getDeviceInfoFromRedis(mac); |
| | | SpecialDeviceInfoDTO specialDeviceInfoDTO = new SpecialDeviceInfoDTO(); |
| | | SpecialDeviceInfoDTO specialDeviceInfoDTORedis = getDeviceInfoFromRedis(mac); |
| | | //先从redis中取 |
| | | if (specialDeviceInfo != null) { |
| | | return specialDeviceInfo; |
| | | if (specialDeviceInfoDTORedis != null) { |
| | | return specialDeviceInfoDTORedis; |
| | | } |
| | | specialDeviceInfo = new LinkedHashMap<>(); |
| | | //DeviceVO device = deviceMapper.selectDeviceInfoById(deviceId); |
| | | |
| | | //存放特殊设备信息 |
| | | SpecialDevice specialDeviceInfo = new SpecialDevice(); |
| | | SpecialDevice specialDevice = specialDeviceMapper.selectById(deviceId); |
| | | //设备 |
| | | specialDeviceInfo.put("id", specialDevice.getId()); |
| | | specialDeviceInfo.put("name", specialDevice.getName()); |
| | | specialDeviceInfo.put("mac", specialDevice.getMac()); |
| | | specialDeviceInfo.put("createTime", DateUtils.dateToDateString(specialDevice.getCreateTime())); |
| | | System.out.println(specialDevice); |
| | | /*specialDeviceInfo.setId(specialDevice.getId()); |
| | | specialDeviceInfo.setName(specialDevice.getName()); |
| | | specialDeviceInfo.setMac(specialDevice.getMac()); |
| | | specialDeviceInfo.setCreateTime(specialDevice.getCreateTime());*/ |
| | | specialDeviceInfoDTO.setSpecialDevice(specialDevice); |
| | | |
| | | //扩展字段 |
| | | //specialDeviceInfo.put("extend", device.getExtend()); |
| | | //存放政府站点信息 |
| | | GovMonitorPoint govMonitorPointInfo = new GovMonitorPoint(); |
| | | QueryWrapper<GovMonitorPoint> wrapper_govMonitorPoint = new QueryWrapper<>(); |
| | | wrapper_govMonitorPoint.eq("is_delete",Constants.NOT_DELETE); |
| | | wrapper_govMonitorPoint.eq("guid",specialDevice.getGuid()); |
| | | GovMonitorPoint govMonitorPoint = govMonitorPointMapper.selectOne(wrapper_govMonitorPoint); |
| | | /*govMonitorPointInfo.setId(govMonitorPoint.getId()); |
| | | govMonitorPointInfo.setGuid(govMonitorPoint.getGuid()); |
| | | govMonitorPointInfo.setName(govMonitorPoint.getName());*/ |
| | | specialDeviceInfoDTO.setGovMonitorPoint(govMonitorPoint); |
| | | |
| | | //型号 |
| | | Map<String, Object> versionInfo = new LinkedHashMap<>(); |
| | | //存放型号信息 |
| | | Version versionInfo = new Version(); |
| | | Version version = versionMapper.selectById(specialDevice.getDeviceVersionId()); |
| | | versionInfo.put("id", version.getId()); |
| | | versionInfo.put("name", version.getName()); |
| | | specialDeviceInfo.put("version", versionInfo); |
| | | /*versionInfo.setId(version.getId()); |
| | | versionInfo.setName(version.getName());*/ |
| | | specialDeviceInfoDTO.setVersion(version); |
| | | |
| | | //维护人 |
| | | List<Map<String, Object>> operatorsInfo = new ArrayList<>(); |
| | | //存放维护人 |
| | | List<ManageAccount> operatorsInfo = new ArrayList<>(); |
| | | String operateIds = specialDevice.getOperateIds(); |
| | | if (!ObjectUtils.isEmpty(operateIds)){ |
| | | String[] operateIdArr = operateIds.split(","); |
| | | if (operateIdArr.length>0){ |
| | | if (operateIdArr.length > 0){ |
| | | List<Integer> operateIdList = new ArrayList<>(); |
| | | for (int i = 0; i < operateIdArr.length; i++){ |
| | | operateIdList.add(Integer.parseInt(operateIdArr[i])); |
| | |
| | | QueryWrapper<ManageAccount> wapper_manageAccount = new QueryWrapper<>(); |
| | | wapper_manageAccount.eq("is_delete",Constants.NOT_DELETE); |
| | | wapper_manageAccount.in("id",operateIdList); |
| | | List<ManageAccount> manageAccounts = manageAccountMapper.selectList(wapper_manageAccount); |
| | | for (ManageAccount manageAccount:manageAccounts) { |
| | | Map<String,Object> operateMap = new HashMap<>(); |
| | | operateMap.put("id",manageAccount.getId()); |
| | | operateMap.put("name",manageAccount.getUserName()); |
| | | operatorsInfo.add(operateMap); |
| | | } |
| | | operatorsInfo = manageAccountMapper.selectList(wapper_manageAccount); |
| | | } |
| | | } |
| | | specialDeviceInfo.put("operators", operatorsInfo); |
| | | specialDeviceInfoDTO.setOperates(operatorsInfo); |
| | | |
| | | //组织 |
| | | Map<String, Object> orgInfo = new LinkedHashMap<>(); |
| | | Organization organization = organizationMapper.selectById(specialDevice.getOrganizationId()); |
| | | orgInfo.put("id", organization.getId()); |
| | | orgInfo.put("name", organization.getName()); |
| | | specialDeviceInfo.put("organization", orgInfo); |
| | | //存放组织 |
| | | Organization organizationInfo = new Organization(); |
| | | organizationInfo = organizationMapper.selectById(specialDevice.getOrganizationId()); |
| | | specialDeviceInfoDTO.setOrganization(organizationInfo); |
| | | |
| | | setDeviceInfoToRedis(mac, specialDeviceInfo); |
| | | return specialDeviceInfo; |
| | | return specialDeviceInfoDTO; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> adjustSpecialDeviceData(Map<String, Object> deviceData) { |
| | | // String mac = deviceData.remove("mac").toString(); |
| | | String mac = deviceData.get("mac").toString(); |
| | | //从redis获取校准公式 |
| | | Map<String, Object> adjustFormula = redisTemplate.opsForHash().entries(RedisConstants.ADJUST + "_" + mac); |
| | | if (!org.springframework.util.ObjectUtils.isEmpty(adjustFormula)) { |
| | | SpecialDeviceInfoDTO specialDeviceInfo = getDeviceInfoFromRedis(mac); |
| | | if (org.springframework.util.ObjectUtils.isEmpty(specialDeviceInfo)) { |
| | | QueryWrapper<SpecialDevice> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("mac", mac).eq("is_delete", Constants.NOT_DELETE); |
| | | SpecialDevice specialDevice = specialDeviceMapper.selectOne(queryWrapper); |
| | | if (specialDevice != null) { |
| | | specialDeviceInfo = selectDeviceInfoDTOById(specialDevice.getId()); |
| | | setDeviceInfoToRedis(mac, specialDeviceInfo); |
| | | } |
| | | } |
| | | //获取设备绑定的国控站信息 |
| | | //Map<String, Object> govMpInfo = (Map<String, Object>) specialDeviceInfo.getGovMonitorPoint(); |
| | | Map<String, Object> govMpInfo = JSON.parseObject(JSON.toJSONString(specialDeviceInfo.getGovMonitorPoint()),Map.class); |
| | | Map<String, Object> aqiMap = null; |
| | | if (null != govMpInfo && null != govMpInfo.get("guid")) { |
| | | aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, govMpInfo.get("guid").toString()); |
| | | } |
| | | return adjustDataUtils.adjust(deviceData, adjustFormula, org.springframework.util.ObjectUtils.isEmpty(aqiMap) ? null : aqiMap,"0"); |
| | | } |
| | | deviceData.remove("DataTime"); |
| | | return deviceData; |
| | | } |
| | | |
| | | private void insertOrganizationUnitAlarm(Integer orgId, Integer versionId) { |