|
|
@@ -25,7 +25,6 @@ import com.zksy.base.manhole.mapper.ManholeDataMapper;
|
|
|
import com.zksy.base.mapper.*;
|
|
|
import com.zksy.base.service.EquipmentBaseService;
|
|
|
import com.zksy.common.exception.ServiceException;
|
|
|
-import com.zksy.manhole.dto.in.AlarmMonitorListInDTO;
|
|
|
import com.zksy.manhole.dto.in.EquipmentCountByTypeInDTO;
|
|
|
import com.zksy.manhole.dto.in.EquipmentExportInDTO;
|
|
|
import com.zksy.manhole.dto.in.ManholeDevicePageInDTO;
|
|
|
@@ -648,144 +647,6 @@ public class EquipmentBaseServiceImpl extends ServiceImpl<EquipmentBaseMapper, E
|
|
|
return new BigDecimal(count * 100.0 / total).setScale(1, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 窨井盖实时监测-设备报警监控列表
|
|
|
- * 查询所有窨井类型设备(equipment_type_id IN (9,10))的 jg_device_data 最新一条记录
|
|
|
- * 告警等级判定:
|
|
|
- * 严重告警(critical) — 倾斜角度超阈值 / 水浸报警 / 水位报警
|
|
|
- * 一般告警(warning) — 低电量(battery<=20) / 弱信号(signal<=20)
|
|
|
- */
|
|
|
- @Override
|
|
|
- public AlarmMonitorListOutDTO getAlarmMonitorList(AlarmMonitorListInDTO inDTO) {
|
|
|
- log.info("窨井盖实时监测-设备报警监控列表入参:{}", inDTO);
|
|
|
- // 仅查询窨井类型设备:排水窨井(9)/供水窨井(10)
|
|
|
- List<String> manholeTypeIds = Arrays.asList("5", "9", "10");
|
|
|
- LambdaQueryWrapper<EquipmentBase> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.in(EquipmentBase::getEquipmentTypeId, manholeTypeIds)
|
|
|
- .and(StringUtils.isNotBlank(inDTO.getKeyword()), w -> w
|
|
|
- .like(EquipmentBase::getEquipmentCode, inDTO.getKeyword())
|
|
|
- .or()
|
|
|
- .like(EquipmentBase::getEquipmentName, inDTO.getKeyword())
|
|
|
- .or()
|
|
|
- .like(EquipmentBase::getEquipmentLocation, inDTO.getKeyword()))
|
|
|
- .orderByDesc(EquipmentBase::getUpdateTime);
|
|
|
- List<EquipmentBase> equipmentList = this.list(queryWrapper);
|
|
|
- if (CollUtil.isEmpty(equipmentList)) {
|
|
|
- AlarmMonitorListOutDTO emptyResult = new AlarmMonitorListOutDTO();
|
|
|
- emptyResult.setDevices(new ArrayList<>());
|
|
|
- Map<String, Object> emptyStats = new HashMap<>();
|
|
|
- emptyStats.put("total", 0);
|
|
|
- emptyStats.put("critical", 0);
|
|
|
- emptyStats.put("warning", 0);
|
|
|
- emptyStats.put("normal", 0);
|
|
|
- emptyStats.put("onlineCount", 0);
|
|
|
- emptyStats.put("avgBattery", 0);
|
|
|
- emptyResult.setStatistics(emptyStats);
|
|
|
- return emptyResult;
|
|
|
- }
|
|
|
- List<EquipmentBaseOutDTO> outDTOList = BeanUtil.copyToList(equipmentList, EquipmentBaseOutDTO.class);
|
|
|
-
|
|
|
- // 批量查询设备类型名称
|
|
|
- List<Integer> typeIdList = outDTOList.stream().map(EquipmentBaseOutDTO::getEquipmentTypeId).distinct().collect(Collectors.toList());
|
|
|
- List<EquipmentType> equipmentTypeList = equipmentTypeMapper.selectList(new LambdaQueryWrapper<EquipmentType>()
|
|
|
- .in(EquipmentType::getId, typeIdList));
|
|
|
- Map<Integer, EquipmentType> equipmentTypeMap = new HashMap<>();
|
|
|
- if (CollUtil.isNotEmpty(equipmentTypeList)) {
|
|
|
- equipmentTypeMap.putAll(equipmentTypeList.stream().collect(Collectors.toMap(EquipmentType::getId, Function.identity(), (k1, k2) -> k2)));
|
|
|
- }
|
|
|
-
|
|
|
- // 批量查询设备运维状态
|
|
|
- List<String> equipmentIdList = outDTOList.stream().map(EquipmentBaseOutDTO::getEquipmentId).distinct().collect(Collectors.toList());
|
|
|
- List<EquipmentStatus> equipmentStatusList = equipmentStatusMapper.selectList(new LambdaQueryWrapper<EquipmentStatus>()
|
|
|
- .in(EquipmentStatus::getEquipmentId, equipmentIdList));
|
|
|
- Map<String, EquipmentStatus> equipmentStatusMap = new HashMap<>();
|
|
|
- if (CollUtil.isNotEmpty(equipmentStatusList)) {
|
|
|
- equipmentStatusMap.putAll(equipmentStatusList.stream().collect(Collectors.toMap(EquipmentStatus::getEquipmentId, Function.identity(), (k1, k2) -> k2)));
|
|
|
- }
|
|
|
-
|
|
|
- // 批量查询最新 jg_device_data 记录(按 imei_card_number = equipment_code 关联)
|
|
|
- List<String> equipmentCodeList = outDTOList.stream().map(EquipmentBaseOutDTO::getEquipmentCode).distinct().collect(Collectors.toList());
|
|
|
- List<ManholeData> manholeDataList = manholeDataMapper.selectList(new LambdaQueryWrapper<ManholeData>()
|
|
|
- .in(ManholeData::getImeiCardNumber, equipmentCodeList)
|
|
|
- .orderByDesc(ManholeData::getCreateTime));
|
|
|
- Map<String, List<ManholeData>> imeiMapList = new HashMap<>();
|
|
|
- if (CollUtil.isNotEmpty(manholeDataList)) {
|
|
|
- imeiMapList.putAll(manholeDataList.stream().collect(Collectors.groupingBy(ManholeData::getImeiCardNumber)));
|
|
|
- }
|
|
|
-
|
|
|
- // 批量查询未办结工单(待派单/待接单/已接单/处理中/待验收/延期审核)
|
|
|
- List<Integer> activeStatusList = Arrays.asList(1, 2, 3, 4, 5, 8);
|
|
|
- List<WorkOrder> activeWorkOrders = workOrderMapper.selectList(new LambdaQueryWrapper<WorkOrder>()
|
|
|
- .in(WorkOrder::getDeviceId, equipmentIdList)
|
|
|
- .in(WorkOrder::getOrderStatus, activeStatusList));
|
|
|
- Set<String> deviceWithActiveOrder = activeWorkOrders.stream()
|
|
|
- .map(WorkOrder::getDeviceId)
|
|
|
- .collect(Collectors.toSet());
|
|
|
-
|
|
|
- // 统计变量
|
|
|
- int critical = 0, warning = 0, normal = 0, onlineCount = 0;
|
|
|
- double batterySum = 0;
|
|
|
- int batteryCount = 0;
|
|
|
-
|
|
|
- for (EquipmentBaseOutDTO outDTO : outDTOList) {
|
|
|
- // 设备类型名称
|
|
|
- EquipmentType equipmentType = equipmentTypeMap.get(outDTO.getEquipmentTypeId());
|
|
|
- if (equipmentType != null) {
|
|
|
- outDTO.setEquipmentTypeName(equipmentType.getTypeName());
|
|
|
- }
|
|
|
- // 设备运维状态
|
|
|
- EquipmentStatus equipmentStatus = equipmentStatusMap.get(outDTO.getEquipmentId());
|
|
|
- if (equipmentStatus != null) {
|
|
|
- EquipmentStatusOutDTO statusOutDTO = BeanUtil.copyProperties(equipmentStatus, EquipmentStatusOutDTO.class);
|
|
|
- outDTO.setEquipmentStatus(statusOutDTO);
|
|
|
- if (Integer.valueOf(1).equals(equipmentStatus.getOnlineStatus())) {
|
|
|
- onlineCount++;
|
|
|
- }
|
|
|
- }
|
|
|
- // 是否有未办结工单
|
|
|
- outDTO.setWorkOrderSubmitted(deviceWithActiveOrder.contains(outDTO.getEquipmentId()));
|
|
|
- // 最新 jg_device_data 记录
|
|
|
- List<ManholeData> dataList = imeiMapList.get(outDTO.getEquipmentCode());
|
|
|
- if (CollUtil.isNotEmpty(dataList)) {
|
|
|
- ManholeData latest = dataList.get(0);
|
|
|
- ManholeDataOutDTO manholeDataOutDTO = BeanUtil.copyProperties(latest, ManholeDataOutDTO.class);
|
|
|
- outDTO.setManholeData(manholeDataOutDTO);
|
|
|
-
|
|
|
- // 统计电量
|
|
|
- if (StringUtils.isNotBlank(latest.getBatteryLevel())) {
|
|
|
- try {
|
|
|
- batterySum += Double.parseDouble(latest.getBatteryLevel().trim());
|
|
|
- batteryCount++;
|
|
|
- } catch (NumberFormatException ignored) {}
|
|
|
- }
|
|
|
-
|
|
|
- // 告警等级判定
|
|
|
- boolean isCritical = isCriticalAlarm(latest);
|
|
|
- boolean isWarning = !isCritical && isGeneralAlarm(latest);
|
|
|
- if (isCritical) critical++;
|
|
|
- else if (isWarning) warning++;
|
|
|
- else normal++;
|
|
|
- } else {
|
|
|
- normal++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 构建统计信息
|
|
|
- Map<String, Object> statistics = new HashMap<>();
|
|
|
- statistics.put("total", outDTOList.size());
|
|
|
- statistics.put("critical", critical);
|
|
|
- statistics.put("warning", warning);
|
|
|
- statistics.put("normal", normal);
|
|
|
- statistics.put("onlineCount", onlineCount);
|
|
|
- statistics.put("avgBattery", batteryCount > 0 ? (int) (batterySum / batteryCount) : 0);
|
|
|
-
|
|
|
- AlarmMonitorListOutDTO result = new AlarmMonitorListOutDTO();
|
|
|
- result.setDevices(outDTOList);
|
|
|
- result.setStatistics(statistics);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 严重告警判定:倾斜角度超阈值 / 水浸报警 / 水位报警
|
|
|
*/
|