|
|
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zksy.base.alarm.domain.AlarmData;
|
|
|
import com.zksy.base.alarm.mapper.AlarmDataMapper;
|
|
|
import com.zksy.base.audio.domain.NoiseInfo;
|
|
|
import com.zksy.base.audio.mapper.NoiseInfoMapper;
|
|
|
@@ -13,6 +14,7 @@ import com.zksy.base.domain.EquipmentBase;
|
|
|
import com.zksy.base.domain.EquipmentMaintain;
|
|
|
import com.zksy.base.domain.EquipmentStatus;
|
|
|
import com.zksy.base.domain.EquipmentType;
|
|
|
+import com.zksy.base.domain.WorkOrder;
|
|
|
import com.zksy.base.domain.vo.*;
|
|
|
import com.zksy.base.event.DeviceStatusChangePublisher;
|
|
|
import com.zksy.base.environment.domain.ERealTimeData;
|
|
|
@@ -23,18 +25,24 @@ import com.zksy.base.mapper.EquipmentBaseMapper;
|
|
|
import com.zksy.base.mapper.EquipmentMaintainMapper;
|
|
|
import com.zksy.base.mapper.EquipmentStatusMapper;
|
|
|
import com.zksy.base.mapper.EquipmentTypeMapper;
|
|
|
+import com.zksy.base.mapper.WorkOrderMapper;
|
|
|
import com.zksy.base.pressure.domain.FirefightingPressure;
|
|
|
import com.zksy.base.pressure.mapper.FirefightingPressureMapper;
|
|
|
import com.zksy.base.radar.domain.RadarData;
|
|
|
import com.zksy.base.radar.mapper.RadarDataMapper;
|
|
|
+import com.zksy.base.service.EquipmentBaseService;
|
|
|
import com.zksy.base.service.WaterSupplyDeviceService;
|
|
|
import com.zksy.base.telemetry.domain.TelemetryData;
|
|
|
import com.zksy.base.telemetry.mapper.TelemetryDataMapper;
|
|
|
import com.zksy.base.water.domain.WaterMonitorData;
|
|
|
import com.zksy.base.water.mapper.WaterMonitorDataMapper;
|
|
|
import com.zksy.common.sms.SmsTemplate;
|
|
|
+import com.zksy.common.core.domain.entity.SysUser;
|
|
|
+import com.zksy.common.utils.SecurityUtils;
|
|
|
+import com.zksy.system.service.ISysUserService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -84,44 +92,69 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
@Autowired
|
|
|
private AlarmDataMapper alarmDataMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EquipmentBaseService equipmentBaseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkOrderMapper workOrderMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private com.zksy.base.service.BusinessWorkOrderService businessWorkOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ @Value("${waterSupply.device.top-level-type:供水}")
|
|
|
+ private String waterTopLevelTypeName = "供水";
|
|
|
+
|
|
|
@Autowired(required = false)
|
|
|
private SmsTemplate smsTemplate;
|
|
|
|
|
|
@Override
|
|
|
public List<DeviceTypeStatisticsVO> getDeviceTypeStatistics() {
|
|
|
+ List<EquipmentBase> waterDevices = findWaterDevices();
|
|
|
+ if (CollUtil.isEmpty(waterDevices)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Long> typeCountMap = waterDevices.stream()
|
|
|
+ .filter(d -> d.getEquipmentTypeId() != null)
|
|
|
+ .collect(Collectors.groupingBy(EquipmentBase::getEquipmentTypeId, Collectors.counting()));
|
|
|
+
|
|
|
List<EquipmentType> allTypes = equipmentTypeMapper.selectList(
|
|
|
new LambdaQueryWrapper<EquipmentType>().orderByAsc(EquipmentType::getTypeId)
|
|
|
);
|
|
|
if (CollUtil.isEmpty(allTypes)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
-
|
|
|
- List<EquipmentBase> allDevices = this.list(
|
|
|
- new LambdaQueryWrapper<EquipmentBase>()
|
|
|
- .select(EquipmentBase::getEquipmentId, EquipmentBase::getEquipmentTypeId)
|
|
|
- );
|
|
|
- Map<String, Long> typeCountMap = allDevices.stream()
|
|
|
- .filter(d -> d.getEquipmentTypeId() != null)
|
|
|
- .collect(Collectors.groupingBy(EquipmentBase::getEquipmentTypeId, Collectors.counting()));
|
|
|
+ Set<String> waterTypeRecordIds = resolveOwnedTypeRecordIds(allTypes, typeCountMap.keySet());
|
|
|
|
|
|
Map<String, DeviceTypeStatisticsVO> voMap = new HashMap<>();
|
|
|
for (EquipmentType type : allTypes) {
|
|
|
+ if (!waterTypeRecordIds.contains(type.getId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
DeviceTypeStatisticsVO vo = new DeviceTypeStatisticsVO();
|
|
|
vo.setTypeId(type.getTypeId());
|
|
|
vo.setTypeName(type.getTypeName());
|
|
|
vo.setParentTypeId(type.getParentTypeId());
|
|
|
- vo.setDeviceCount(typeCountMap.getOrDefault(type.getTypeId(), 0L).intValue());
|
|
|
+ vo.setDeviceCount(typeCountMap.getOrDefault(type.getId(), 0L).intValue());
|
|
|
vo.setChildren(new ArrayList<>());
|
|
|
- voMap.put(type.getTypeId(), vo);
|
|
|
+ voMap.put(type.getId(), vo);
|
|
|
}
|
|
|
|
|
|
List<DeviceTypeStatisticsVO> roots = new ArrayList<>();
|
|
|
- for (DeviceTypeStatisticsVO vo : voMap.values()) {
|
|
|
- String parentId = vo.getParentTypeId();
|
|
|
- if (parentId == null || "0".equals(parentId) || !voMap.containsKey(parentId)) {
|
|
|
+ for (EquipmentType type : allTypes) {
|
|
|
+ DeviceTypeStatisticsVO vo = voMap.get(type.getId());
|
|
|
+ if (vo == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String parentRecordId = type.getParentTypeId();
|
|
|
+ if (parentRecordId == null || "0".equals(parentRecordId)
|
|
|
+ || !voMap.containsKey(parentRecordId)) {
|
|
|
roots.add(vo);
|
|
|
} else {
|
|
|
- voMap.get(parentId).getChildren().add(vo);
|
|
|
+ voMap.get(parentRecordId).getChildren().add(vo);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -145,25 +178,47 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
@Override
|
|
|
public Page<DeviceGisVO> getDeviceLedgerPage(long pageNum, long pageSize,
|
|
|
String equipmentName, String equipmentCode,
|
|
|
- String equipmentTypeId, Integer status) {
|
|
|
- Page<EquipmentBase> page = new Page<>(pageNum, pageSize);
|
|
|
- LambdaQueryWrapper<EquipmentBase> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.like(StrUtil.isNotBlank(equipmentName), EquipmentBase::getEquipmentName, equipmentName)
|
|
|
- .like(StrUtil.isNotBlank(equipmentCode), EquipmentBase::getEquipmentCode, equipmentCode)
|
|
|
- .eq(StrUtil.isNotBlank(equipmentTypeId), EquipmentBase::getEquipmentTypeId, equipmentTypeId)
|
|
|
- .orderByDesc(EquipmentBase::getCreateTime);
|
|
|
- Page<EquipmentBase> basePage = this.page(page, wrapper);
|
|
|
+ String equipmentTypeId, Integer status,
|
|
|
+ Integer alarmStatus, Integer alertLevel) {
|
|
|
+ List<EquipmentBase> waterDevices = findWaterDevices();
|
|
|
+ if (CollUtil.isEmpty(waterDevices)) {
|
|
|
+ return emptyPage(pageNum, pageSize);
|
|
|
+ }
|
|
|
|
|
|
+ Map<String, EquipmentStatus> statusMap = status != null || alarmStatus != null || alertLevel != null
|
|
|
+ ? getStatusMap(waterDevices.stream().map(EquipmentBase::getEquipmentId).collect(Collectors.toList()))
|
|
|
+ : new HashMap<>();
|
|
|
+ final Map<String, EquipmentStatus> filterStatusMap = statusMap;
|
|
|
+ Map<String, AlarmData> alarmMap = alertLevel != null ? getActiveAlarmMap(waterDevices) : new HashMap<>();
|
|
|
+
|
|
|
+ List<EquipmentBase> records = waterDevices.stream()
|
|
|
+ .filter(device -> matchesLedgerFilters(device, equipmentName, equipmentCode, equipmentTypeId))
|
|
|
+ .filter(device -> status == null || status.equals(Optional.ofNullable(filterStatusMap
|
|
|
+ .get(device.getEquipmentId())).map(EquipmentStatus::getCurrentStatus).orElse(null)))
|
|
|
+ .filter(device -> alarmStatus == null || alarmStatus.equals(Optional.ofNullable(filterStatusMap
|
|
|
+ .get(device.getEquipmentId())).map(EquipmentStatus::getAlarmStatus).orElse(null)))
|
|
|
+ .filter(device -> alertLevel == null || alertLevel.equals(resolveAlertLevel(device,
|
|
|
+ filterStatusMap.get(device.getEquipmentId()), alarmMap)))
|
|
|
+ .sorted(Comparator.comparing(EquipmentBase::getCreateTime,
|
|
|
+ Comparator.nullsLast(Comparator.reverseOrder())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ Page<EquipmentBase> basePage = paginate(records, pageNum, pageSize);
|
|
|
Page<DeviceGisVO> resultPage = new Page<>(pageNum, pageSize, basePage.getTotal());
|
|
|
if (CollUtil.isEmpty(basePage.getRecords())) {
|
|
|
resultPage.setRecords(new ArrayList<>());
|
|
|
return resultPage;
|
|
|
}
|
|
|
|
|
|
- List<EquipmentBase> records = basePage.getRecords();
|
|
|
+ records = basePage.getRecords();
|
|
|
List<String> equipmentIds = records.stream().map(EquipmentBase::getEquipmentId).collect(Collectors.toList());
|
|
|
|
|
|
- Map<String, EquipmentStatus> statusMap = getStatusMap(equipmentIds);
|
|
|
+ if (status == null && alarmStatus == null && alertLevel == null) {
|
|
|
+ statusMap = getStatusMap(equipmentIds);
|
|
|
+ }
|
|
|
+ Map<String, AlarmData> displayAlarmMap = CollUtil.isEmpty(alarmMap)
|
|
|
+ ? getActiveAlarmMap(records)
|
|
|
+ : alarmMap;
|
|
|
Map<String, EquipmentType> typeMap = getTypeMap(records);
|
|
|
|
|
|
List<DeviceGisVO> voList = new ArrayList<>();
|
|
|
@@ -175,6 +230,10 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
vo.setAlarmStatus(es.getAlarmStatus());
|
|
|
vo.setCurrentStatus(es.getCurrentStatus());
|
|
|
}
|
|
|
+ AlarmData alarm = displayAlarmMap.get(base.getEquipmentCode());
|
|
|
+ if (alarm != null) {
|
|
|
+ vo.setAlertLevel(alarm.getAlarmLevel());
|
|
|
+ }
|
|
|
EquipmentType et = typeMap.get(base.getEquipmentTypeId());
|
|
|
if (et != null) {
|
|
|
vo.setEquipmentTypeName(et.getTypeName());
|
|
|
@@ -186,13 +245,21 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
return resultPage;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<DeviceGisVO> getDeviceLedgerExport(String equipmentName, String equipmentCode,
|
|
|
+ String equipmentTypeId, Integer status,
|
|
|
+ Integer alarmStatus, Integer alertLevel) {
|
|
|
+ return getDeviceLedgerPage(1, Integer.MAX_VALUE, equipmentName, equipmentCode,
|
|
|
+ equipmentTypeId, status, alarmStatus, alertLevel).getRecords();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<DeviceGisVO> getAllDeviceGisPoints(String equipmentTypeId) {
|
|
|
- LambdaQueryWrapper<EquipmentBase> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(StrUtil.isNotBlank(equipmentTypeId), EquipmentBase::getEquipmentTypeId, equipmentTypeId)
|
|
|
- .isNotNull(EquipmentBase::getLongitude)
|
|
|
- .isNotNull(EquipmentBase::getLatitude);
|
|
|
- List<EquipmentBase> list = this.list(wrapper);
|
|
|
+ List<EquipmentBase> list = findWaterDevices().stream()
|
|
|
+ .filter(device -> StrUtil.isBlank(equipmentTypeId)
|
|
|
+ || equipmentTypeId.equals(device.getEquipmentTypeId()))
|
|
|
+ .filter(device -> device.getLongitude() != null && device.getLatitude() != null)
|
|
|
+ .collect(Collectors.toList());
|
|
|
if (CollUtil.isEmpty(list)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
@@ -222,7 +289,7 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
|
|
|
@Override
|
|
|
public DeviceDetailVO getDeviceDetail(String equipmentId) {
|
|
|
- EquipmentBase base = this.getById(equipmentId);
|
|
|
+ EquipmentBase base = findWaterDeviceById(equipmentId);
|
|
|
if (base == null) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -242,6 +309,25 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
vo.setCurrentStatus(status.getCurrentStatus());
|
|
|
}
|
|
|
|
|
|
+ // alarm_data is historical evidence only; equipment_status is authoritative
|
|
|
+ // for whether the device is currently alarming.
|
|
|
+ AlarmData activeAlarm = status != null && Objects.equals(status.getAlarmStatus(), 1)
|
|
|
+ ? getActiveAlarmMap(Collections.singletonList(base)).get(base.getEquipmentCode())
|
|
|
+ : null;
|
|
|
+ if (activeAlarm != null) {
|
|
|
+ vo.setAlertLevel(activeAlarm.getAlarmLevel());
|
|
|
+ vo.setAbnormalReason(StrUtil.isNotBlank(activeAlarm.getWarningType()) ? activeAlarm.getWarningType() : "设备报警");
|
|
|
+ } else if (status != null && Objects.equals(status.getCurrentStatus(), 3)) {
|
|
|
+ // Maintenance is an operational status, not a monitoring alarm level.
|
|
|
+ vo.setAbnormalReason("设备维修中");
|
|
|
+ }
|
|
|
+ WorkOrder relatedOrder = getLatestWorkOrderMap(Collections.singletonList(base)).get(equipmentId);
|
|
|
+ if (relatedOrder != null) {
|
|
|
+ vo.setRelatedWorkOrderNo(relatedOrder.getOrderNo());
|
|
|
+ vo.setRelatedWorkOrderStatus(relatedOrder.getOrderStatus());
|
|
|
+ vo.setRelatedWorkOrderPerson(resolveWorkOrderPerson(relatedOrder));
|
|
|
+ }
|
|
|
+
|
|
|
fillGpsFields(vo, base.getLongitude(), base.getLatitude());
|
|
|
|
|
|
Map<String, Object> latestData = getLatestMonitorData(base.getEquipmentCode(), base.getEquipmentTypeId());
|
|
|
@@ -271,54 +357,56 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
+ @Deprecated
|
|
|
public boolean createMaintainOrder(MaintainOrderVO vo) {
|
|
|
- EquipmentBase device = this.getById(vo.getEquipmentId());
|
|
|
- if (device == null) {
|
|
|
- throw new RuntimeException("设备不存在:" + vo.getEquipmentId());
|
|
|
- }
|
|
|
-
|
|
|
- EquipmentMaintain maintain = new EquipmentMaintain();
|
|
|
- maintain.setEquipmentId(vo.getEquipmentId());
|
|
|
- maintain.setMaintainType(StrUtil.isNotBlank(vo.getMaintainType()) ? vo.getMaintainType() : "故障维修");
|
|
|
- maintain.setMaintainContent(vo.getMaintainContent());
|
|
|
- maintain.setMaintainPerson(vo.getMaintainPerson());
|
|
|
- maintain.setMaintainPersonPhone(vo.getMaintainPersonPhone());
|
|
|
- maintain.setMaintainCost(vo.getMaintainCost());
|
|
|
- maintain.setMaintainRemark(vo.getMaintainRemark());
|
|
|
- int insert = equipmentMaintainMapper.insert(maintain);
|
|
|
-
|
|
|
- if (insert > 0) {
|
|
|
- EquipmentStatus status = equipmentStatusMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<EquipmentStatus>().eq(EquipmentStatus::getEquipmentId, vo.getEquipmentId())
|
|
|
- );
|
|
|
- if (status != null) {
|
|
|
- boolean changed = !Objects.equals(status.getCurrentStatus(), 3);
|
|
|
- status.setCurrentStatus(3);
|
|
|
- status.setStatusUpdateTime(LocalDateTime.now());
|
|
|
- boolean updated = equipmentStatusMapper.updateById(status) > 0;
|
|
|
- if (updated && changed) {
|
|
|
- publishEquipmentStatusChange(device, status, "pipe-network:createMaintainOrder");
|
|
|
- }
|
|
|
- } else {
|
|
|
- EquipmentStatus newStatus = new EquipmentStatus();
|
|
|
- newStatus.setEquipmentId(vo.getEquipmentId());
|
|
|
- newStatus.setCurrentStatus(3);
|
|
|
- newStatus.setAlarmStatus(0);
|
|
|
- newStatus.setOnlineStatus(1);
|
|
|
- newStatus.setStatusUpdateTime(LocalDateTime.now());
|
|
|
- newStatus.setCreateTime(LocalDateTime.now());
|
|
|
- if (equipmentStatusMapper.insert(newStatus) > 0) {
|
|
|
- publishEquipmentStatusChange(device, newStatus, "pipe-network:createMaintainOrder");
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("设备[{}]派单成功,工单ID:{},维修人:{}",
|
|
|
- vo.getEquipmentId(), maintain.getMaintainId(), vo.getMaintainPerson());
|
|
|
+ // Keep the legacy service signature for binary compatibility, but route it
|
|
|
+ // through the same unified WorkOrder lifecycle as the current endpoint.
|
|
|
+ WorkOrder workOrder = createAbnormalWorkOrder(vo);
|
|
|
+ if (workOrder == null || workOrder.getOrderId() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (vo.getReceiveUserId() == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return businessWorkOrderService.dispatchOrder(workOrder.getOrderId(), vo.getReceiveUserId(),
|
|
|
+ vo.getMaintainRemark(), currentUserIdOrNull(), currentUserNameOrNull());
|
|
|
+ }
|
|
|
|
|
|
- // 发送短信通知维修人员
|
|
|
- sendMaintainSmsNotify(device, maintain);
|
|
|
+ private Long currentUserIdOrNull() {
|
|
|
+ try {
|
|
|
+ return SecurityUtils.getUserId();
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String currentUserNameOrNull() {
|
|
|
+ try {
|
|
|
+ return SecurityUtils.getUsername();
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- return insert > 0;
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public WorkOrder createAbnormalWorkOrder(MaintainOrderVO vo) {
|
|
|
+ if (vo == null || StrUtil.isBlank(vo.getEquipmentId())) {
|
|
|
+ throw new RuntimeException("设备ID不能为空");
|
|
|
+ }
|
|
|
+ EquipmentBase device = findWaterDeviceById(vo.getEquipmentId());
|
|
|
+ if (device == null) {
|
|
|
+ throw new RuntimeException("仅支持供水设备派发维修工单");
|
|
|
+ }
|
|
|
+ WorkOrder workOrder = new WorkOrder();
|
|
|
+ workOrder.setDeviceId(device.getEquipmentId());
|
|
|
+ workOrder.setDeviceCode(device.getEquipmentCode());
|
|
|
+ workOrder.setOrderType(1);
|
|
|
+ workOrder.setOrderLevel(2);
|
|
|
+ workOrder.setOrderDesc(StrUtil.isNotBlank(vo.getFaultDescription()) ? vo.getFaultDescription() : vo.getMaintainContent());
|
|
|
+ Long orderId = businessWorkOrderService.createWorkOrder(workOrder);
|
|
|
+ workOrder.setOrderId(orderId);
|
|
|
+ return workOrder;
|
|
|
}
|
|
|
|
|
|
private void publishEquipmentStatusChange(EquipmentBase equipment, EquipmentStatus status, String source) {
|
|
|
@@ -366,122 +454,117 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
public Page<AbnormalDeviceVO> getAbnormalDevicePage(long pageNum, long pageSize,
|
|
|
String equipmentName, String equipmentCode,
|
|
|
String equipmentTypeId, Integer alertLevel) {
|
|
|
+ return getAbnormalDevicePage(pageNum, pageSize, equipmentName, equipmentCode,
|
|
|
+ equipmentTypeId, alertLevel, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<AbnormalDeviceVO> getAbnormalDevicePage(long pageNum, long pageSize,
|
|
|
+ String equipmentName, String equipmentCode,
|
|
|
+ String equipmentTypeId, Integer alertLevel,
|
|
|
+ Boolean dispatchableOnly) {
|
|
|
+ List<EquipmentBase> waterDevices = findWaterDevices();
|
|
|
+ if (CollUtil.isEmpty(waterDevices)) {
|
|
|
+ return emptyAbnormalPage(pageNum, pageSize, 0);
|
|
|
+ }
|
|
|
+
|
|
|
LambdaQueryWrapper<EquipmentStatus> statusWrapper = new LambdaQueryWrapper<>();
|
|
|
statusWrapper.and(w -> w.eq(EquipmentStatus::getAlarmStatus, 1)
|
|
|
.or().eq(EquipmentStatus::getCurrentStatus, 3));
|
|
|
|
|
|
List<EquipmentStatus> allAbnormalStatus = equipmentStatusMapper.selectList(statusWrapper);
|
|
|
- if (CollUtil.isEmpty(allAbnormalStatus)) {
|
|
|
- Page<AbnormalDeviceVO> emptyPage = new Page<>(pageNum, pageSize, 0);
|
|
|
- emptyPage.setRecords(new ArrayList<>());
|
|
|
- return emptyPage;
|
|
|
- }
|
|
|
-
|
|
|
- List<String> equipmentIds = allAbnormalStatus.stream()
|
|
|
- .map(EquipmentStatus::getEquipmentId).distinct().collect(Collectors.toList());
|
|
|
+ Map<String, EquipmentStatus> statusMap = allAbnormalStatus.stream()
|
|
|
+ .collect(Collectors.toMap(EquipmentStatus::getEquipmentId, s -> s, (a, b) -> a));
|
|
|
|
|
|
- LambdaQueryWrapper<EquipmentBase> baseWrapper = new LambdaQueryWrapper<>();
|
|
|
- baseWrapper.in(EquipmentBase::getEquipmentId, equipmentIds)
|
|
|
- .like(StrUtil.isNotBlank(equipmentName), EquipmentBase::getEquipmentName, equipmentName)
|
|
|
- .like(StrUtil.isNotBlank(equipmentCode), EquipmentBase::getEquipmentCode, equipmentCode)
|
|
|
- .eq(StrUtil.isNotBlank(equipmentTypeId), EquipmentBase::getEquipmentTypeId, equipmentTypeId);
|
|
|
+ List<EquipmentBase> allDevices = waterDevices.stream()
|
|
|
+ .filter(device -> Optional.ofNullable(statusMap.get(device.getEquipmentId()))
|
|
|
+ .map(status -> Objects.equals(status.getAlarmStatus(), 1)
|
|
|
+ || Objects.equals(status.getCurrentStatus(), 3))
|
|
|
+ .orElse(false))
|
|
|
+ .filter(device -> matchesLedgerFilters(device, equipmentName, equipmentCode, equipmentTypeId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- List<EquipmentBase> allDevices = this.list(baseWrapper);
|
|
|
- if (CollUtil.isEmpty(allDevices)) {
|
|
|
- Page<AbnormalDeviceVO> emptyPage = new Page<>(pageNum, pageSize, 0);
|
|
|
- emptyPage.setRecords(new ArrayList<>());
|
|
|
- return emptyPage;
|
|
|
- }
|
|
|
+ Map<String, AlarmData> alarmMap = getActiveAlarmMap(allDevices);
|
|
|
+ Map<String, WorkOrder> workOrderMap = getLatestWorkOrderMap(allDevices);
|
|
|
+ Map<String, EquipmentMaintain> maintainMap = getLatestMaintainMap(
|
|
|
+ allDevices.stream().map(EquipmentBase::getEquipmentId).collect(Collectors.toList())
|
|
|
+ );
|
|
|
|
|
|
- int total = allDevices.size();
|
|
|
- long offset = (pageNum - 1) * pageSize;
|
|
|
- if (pageNum < 1 || pageSize < 1 || offset >= total) {
|
|
|
- Page<AbnormalDeviceVO> emptyPage = new Page<>(pageNum, pageSize, total);
|
|
|
- emptyPage.setRecords(new ArrayList<>());
|
|
|
- return emptyPage;
|
|
|
+ List<EquipmentBase> filteredDevices = allDevices.stream()
|
|
|
+ .filter(device -> !Boolean.TRUE.equals(dispatchableOnly)
|
|
|
+ || !workOrderMap.containsKey(device.getEquipmentId()))
|
|
|
+ .filter(device -> alertLevel == null
|
|
|
+ || alertLevel.equals(resolveAlertLevel(device, statusMap.get(device.getEquipmentId()), alarmMap)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollUtil.isEmpty(filteredDevices)) {
|
|
|
+ return emptyAbnormalPage(pageNum, pageSize, filteredDevices.size());
|
|
|
}
|
|
|
- int fromIndex = (int) offset;
|
|
|
- int toIndex = Math.min(fromIndex + (int) pageSize, total);
|
|
|
- List<EquipmentBase> pageDevices = allDevices.subList(fromIndex, toIndex);
|
|
|
|
|
|
- Map<String, EquipmentStatus> statusMap = allAbnormalStatus.stream()
|
|
|
- .collect(Collectors.toMap(EquipmentStatus::getEquipmentId, s -> s, (a, b) -> a));
|
|
|
+ Page<EquipmentBase> basePage = paginate(filteredDevices, pageNum, pageSize);
|
|
|
+ List<EquipmentBase> pageDevices = basePage.getRecords();
|
|
|
Map<String, EquipmentType> typeMap = getTypeMap(pageDevices);
|
|
|
- Map<String, EquipmentMaintain> maintainMap = getLatestMaintainMap(
|
|
|
- pageDevices.stream().map(EquipmentBase::getEquipmentId).collect(Collectors.toList())
|
|
|
- );
|
|
|
|
|
|
List<AbnormalDeviceVO> voList = new ArrayList<>();
|
|
|
for (EquipmentBase base : pageDevices) {
|
|
|
AbnormalDeviceVO vo = BeanUtil.copyProperties(base, AbnormalDeviceVO.class);
|
|
|
- EquipmentStatus es = statusMap.get(base.getEquipmentId());
|
|
|
- if (es != null) {
|
|
|
- vo.setCurrentStatus(es.getCurrentStatus());
|
|
|
- vo.setAlarmStatus(es.getAlarmStatus());
|
|
|
- vo.setOnlineStatus(es.getOnlineStatus());
|
|
|
- vo.setStatusUpdateTime(es.getStatusUpdateTime());
|
|
|
- }
|
|
|
- EquipmentType et = typeMap.get(base.getEquipmentTypeId());
|
|
|
- if (et != null) {
|
|
|
- vo.setEquipmentTypeName(et.getTypeName());
|
|
|
- }
|
|
|
- EquipmentMaintain maintain = maintainMap.get(base.getEquipmentId());
|
|
|
- if (maintain != null) {
|
|
|
- vo.setLatestMaintainId(maintain.getMaintainId());
|
|
|
- vo.setLatestMaintainPerson(maintain.getMaintainPerson());
|
|
|
- }
|
|
|
- vo.setAlertLevel(calcAlertLevel(base.getEquipmentCode(), es));
|
|
|
- fillGpsFields(vo, base.getLongitude(), base.getLatitude());
|
|
|
+ fillAbnormalDeviceVO(vo, base, statusMap.get(base.getEquipmentId()),
|
|
|
+ typeMap.get(base.getEquipmentTypeId()), alarmMap.get(base.getEquipmentCode()),
|
|
|
+ workOrderMap.get(base.getEquipmentId()), maintainMap.get(base.getEquipmentId()));
|
|
|
voList.add(vo);
|
|
|
}
|
|
|
|
|
|
- Page<AbnormalDeviceVO> resultPage = new Page<>(pageNum, pageSize, total);
|
|
|
+ Page<AbnormalDeviceVO> resultPage = new Page<>(pageNum, pageSize, basePage.getTotal());
|
|
|
resultPage.setRecords(voList);
|
|
|
return resultPage;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<AbnormalDeviceVO> getAbnormalDeviceExport(String equipmentName, String equipmentCode,
|
|
|
+ String equipmentTypeId, Integer alertLevel) {
|
|
|
+ return getAbnormalDevicePage(1, Integer.MAX_VALUE, equipmentName, equipmentCode,
|
|
|
+ equipmentTypeId, alertLevel).getRecords();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<AbnormalDeviceVO> getAbnormalDeviceGisPoints(String equipmentTypeId) {
|
|
|
+ List<EquipmentBase> ownedDevices = findWaterDevices();
|
|
|
+ if (CollUtil.isEmpty(ownedDevices)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
LambdaQueryWrapper<EquipmentStatus> statusWrapper = new LambdaQueryWrapper<>();
|
|
|
statusWrapper.and(w -> w.eq(EquipmentStatus::getAlarmStatus, 1)
|
|
|
.or().eq(EquipmentStatus::getCurrentStatus, 3));
|
|
|
List<EquipmentStatus> allAbnormalStatus = equipmentStatusMapper.selectList(statusWrapper);
|
|
|
- if (CollUtil.isEmpty(allAbnormalStatus)) {
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
-
|
|
|
- List<String> equipmentIds = allAbnormalStatus.stream()
|
|
|
- .map(EquipmentStatus::getEquipmentId).distinct().collect(Collectors.toList());
|
|
|
+ Map<String, EquipmentStatus> statusMap = allAbnormalStatus.stream()
|
|
|
+ .collect(Collectors.toMap(EquipmentStatus::getEquipmentId, s -> s, (a, b) -> a));
|
|
|
|
|
|
- LambdaQueryWrapper<EquipmentBase> baseWrapper = new LambdaQueryWrapper<>();
|
|
|
- baseWrapper.in(EquipmentBase::getEquipmentId, equipmentIds)
|
|
|
- .eq(StrUtil.isNotBlank(equipmentTypeId), EquipmentBase::getEquipmentTypeId, equipmentTypeId)
|
|
|
- .isNotNull(EquipmentBase::getLongitude)
|
|
|
- .isNotNull(EquipmentBase::getLatitude);
|
|
|
- List<EquipmentBase> devices = this.list(baseWrapper);
|
|
|
+ List<EquipmentBase> devices = ownedDevices.stream()
|
|
|
+ .filter(device -> StrUtil.isBlank(equipmentTypeId)
|
|
|
+ || equipmentTypeId.equals(device.getEquipmentTypeId()))
|
|
|
+ .filter(device -> device.getLongitude() != null && device.getLatitude() != null)
|
|
|
+ .filter(device -> Optional.ofNullable(statusMap.get(device.getEquipmentId()))
|
|
|
+ .map(status -> Objects.equals(status.getAlarmStatus(), 1)
|
|
|
+ || Objects.equals(status.getCurrentStatus(), 3))
|
|
|
+ .orElse(false))
|
|
|
+ .collect(Collectors.toList());
|
|
|
if (CollUtil.isEmpty(devices)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
- Map<String, EquipmentStatus> statusMap = allAbnormalStatus.stream()
|
|
|
- .collect(Collectors.toMap(EquipmentStatus::getEquipmentId, s -> s, (a, b) -> a));
|
|
|
+ Map<String, AlarmData> alarmMap = getActiveAlarmMap(devices);
|
|
|
+ Map<String, WorkOrder> workOrderMap = getLatestWorkOrderMap(devices);
|
|
|
+ Map<String, EquipmentMaintain> maintainMap = getLatestMaintainMap(
|
|
|
+ devices.stream().map(EquipmentBase::getEquipmentId).collect(Collectors.toList())
|
|
|
+ );
|
|
|
Map<String, EquipmentType> typeMap = getTypeMap(devices);
|
|
|
|
|
|
List<AbnormalDeviceVO> result = new ArrayList<>();
|
|
|
for (EquipmentBase base : devices) {
|
|
|
AbnormalDeviceVO vo = BeanUtil.copyProperties(base, AbnormalDeviceVO.class);
|
|
|
- EquipmentStatus es = statusMap.get(base.getEquipmentId());
|
|
|
- if (es != null) {
|
|
|
- vo.setCurrentStatus(es.getCurrentStatus());
|
|
|
- vo.setAlarmStatus(es.getAlarmStatus());
|
|
|
- vo.setOnlineStatus(es.getOnlineStatus());
|
|
|
- }
|
|
|
- EquipmentType et = typeMap.get(base.getEquipmentTypeId());
|
|
|
- if (et != null) {
|
|
|
- vo.setEquipmentTypeName(et.getTypeName());
|
|
|
- }
|
|
|
- vo.setAlertLevel(calcAlertLevel(base.getEquipmentCode(), es));
|
|
|
- fillGpsFields(vo, base.getLongitude(), base.getLatitude());
|
|
|
+ fillAbnormalDeviceVO(vo, base, statusMap.get(base.getEquipmentId()),
|
|
|
+ typeMap.get(base.getEquipmentTypeId()), alarmMap.get(base.getEquipmentCode()),
|
|
|
+ workOrderMap.get(base.getEquipmentId()), maintainMap.get(base.getEquipmentId()));
|
|
|
result.add(vo);
|
|
|
}
|
|
|
return result;
|
|
|
@@ -489,6 +572,9 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
|
|
|
@Override
|
|
|
public List<Map<String, Object>> getMaintainRecordList(String equipmentId) {
|
|
|
+ if (findWaterDeviceById(equipmentId) == null) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
List<EquipmentMaintain> list = equipmentMaintainMapper.selectList(
|
|
|
new LambdaQueryWrapper<EquipmentMaintain>()
|
|
|
.eq(EquipmentMaintain::getEquipmentId, equipmentId)
|
|
|
@@ -515,9 +601,9 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
if (StrUtil.isBlank(vo.getEquipmentId())) {
|
|
|
throw new RuntimeException("设备ID不能为空");
|
|
|
}
|
|
|
- EquipmentBase device = this.getById(vo.getEquipmentId());
|
|
|
+ EquipmentBase device = findWaterDeviceById(vo.getEquipmentId());
|
|
|
if (device == null) {
|
|
|
- throw new RuntimeException("设备不存在");
|
|
|
+ throw new RuntimeException("仅支持供水设备维护记录");
|
|
|
}
|
|
|
EquipmentMaintain maintain = BeanUtil.copyProperties(vo, EquipmentMaintain.class);
|
|
|
return equipmentMaintainMapper.insert(maintain) > 0;
|
|
|
@@ -529,13 +615,30 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
if (StrUtil.isBlank(vo.getMaintainId())) {
|
|
|
throw new RuntimeException("维护记录ID不能为空");
|
|
|
}
|
|
|
+ EquipmentMaintain existing = equipmentMaintainMapper.selectById(vo.getMaintainId());
|
|
|
+ if (existing == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (findWaterDeviceById(existing.getEquipmentId()) == null
|
|
|
+ || (StrUtil.isNotBlank(vo.getEquipmentId())
|
|
|
+ && !vo.getEquipmentId().equals(existing.getEquipmentId()))) {
|
|
|
+ throw new RuntimeException("仅支持供水设备维护记录");
|
|
|
+ }
|
|
|
EquipmentMaintain maintain = BeanUtil.copyProperties(vo, EquipmentMaintain.class);
|
|
|
+ maintain.setEquipmentId(existing.getEquipmentId());
|
|
|
return equipmentMaintainMapper.updateById(maintain) > 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean deleteMaintainRecord(String maintainId) {
|
|
|
+ EquipmentMaintain existing = equipmentMaintainMapper.selectById(maintainId);
|
|
|
+ if (existing == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (findWaterDeviceById(existing.getEquipmentId()) == null) {
|
|
|
+ throw new RuntimeException("仅支持供水设备维护记录");
|
|
|
+ }
|
|
|
return equipmentMaintainMapper.deleteById(maintainId) > 0;
|
|
|
}
|
|
|
|
|
|
@@ -544,85 +647,282 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
String equipmentName, String maintainPerson,
|
|
|
String maintainType, String status,
|
|
|
String startTime, String endTime) {
|
|
|
+ LambdaQueryWrapper<EquipmentMaintain> wrapper = maintainRecordWrapper(maintainPerson, maintainType);
|
|
|
+ return buildMaintainRecordPage(equipmentMaintainMapper.selectList(wrapper),
|
|
|
+ pageNum, pageSize, equipmentName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<EquipmentMaintainDataVO> getMyMaintainRecordPage(long pageNum, long pageSize,
|
|
|
+ String maintainPerson,
|
|
|
+ String maintainType, String status,
|
|
|
+ String startTime, String endTime) {
|
|
|
+ LambdaQueryWrapper<EquipmentMaintain> wrapper = maintainRecordWrapper(maintainPerson, maintainType);
|
|
|
+ return buildMaintainRecordPage(equipmentMaintainMapper.selectList(wrapper),
|
|
|
+ pageNum, pageSize, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<EquipmentMaintain> maintainRecordWrapper(String maintainPerson,
|
|
|
+ String maintainType) {
|
|
|
LambdaQueryWrapper<EquipmentMaintain> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.like(StrUtil.isNotBlank(maintainPerson), EquipmentMaintain::getMaintainPerson, maintainPerson)
|
|
|
.eq(StrUtil.isNotBlank(maintainType), EquipmentMaintain::getMaintainType, maintainType)
|
|
|
.orderByDesc(EquipmentMaintain::getMaintainDate);
|
|
|
+ return wrapper;
|
|
|
+ }
|
|
|
|
|
|
- Page<EquipmentMaintain> maintainPage = equipmentMaintainMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
|
|
|
+ private Page<EquipmentMaintainDataVO> buildMaintainRecordPage(List<EquipmentMaintain> records,
|
|
|
+ long pageNum, long pageSize,
|
|
|
+ String equipmentName) {
|
|
|
+ Map<String, EquipmentBase> deviceMap = findWaterDevices().stream()
|
|
|
+ .collect(Collectors.toMap(EquipmentBase::getEquipmentId, device -> device, (left, right) -> left));
|
|
|
+ List<EquipmentMaintain> ownedRecords = records == null ? Collections.emptyList() : records.stream()
|
|
|
+ .filter(record -> deviceMap.containsKey(record.getEquipmentId()))
|
|
|
+ .filter(record -> StrUtil.isBlank(equipmentName) || Optional.ofNullable(deviceMap.get(record.getEquipmentId()))
|
|
|
+ .map(EquipmentBase::getEquipmentName)
|
|
|
+ .map(name -> name.contains(equipmentName))
|
|
|
+ .orElse(false))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ Page<EquipmentMaintain> maintainPage = paginate(ownedRecords, pageNum, pageSize);
|
|
|
Page<EquipmentMaintainDataVO> resultPage = new Page<>(pageNum, pageSize, maintainPage.getTotal());
|
|
|
-
|
|
|
- if (CollUtil.isEmpty(maintainPage.getRecords())) {
|
|
|
- resultPage.setRecords(new ArrayList<>());
|
|
|
- return resultPage;
|
|
|
- }
|
|
|
-
|
|
|
- List<String> equipmentIds = maintainPage.getRecords().stream()
|
|
|
- .map(EquipmentMaintain::getEquipmentId).distinct().collect(Collectors.toList());
|
|
|
- List<EquipmentBase> devices = this.listByIds(equipmentIds);
|
|
|
- Map<String, EquipmentBase> deviceMap = devices.stream()
|
|
|
- .collect(Collectors.toMap(EquipmentBase::getEquipmentId, d -> d, (a, b) -> a));
|
|
|
-
|
|
|
List<EquipmentMaintainDataVO> voList = new ArrayList<>();
|
|
|
for (EquipmentMaintain m : maintainPage.getRecords()) {
|
|
|
EquipmentMaintainDataVO vo = BeanUtil.copyProperties(m, EquipmentMaintainDataVO.class);
|
|
|
EquipmentBase device = deviceMap.get(m.getEquipmentId());
|
|
|
- if (device != null) {
|
|
|
- vo.setEquipmentCode(device.getEquipmentCode());
|
|
|
- vo.setEquipmentName(device.getEquipmentName());
|
|
|
- vo.setEquipmentLocation(device.getEquipmentLocation());
|
|
|
- vo.setLongitude(device.getLongitude());
|
|
|
- vo.setLatitude(device.getLatitude());
|
|
|
- }
|
|
|
- if (StrUtil.isNotBlank(equipmentName) && (vo.getEquipmentName() == null
|
|
|
- || !vo.getEquipmentName().contains(equipmentName))) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ vo.setEquipmentCode(device.getEquipmentCode());
|
|
|
+ vo.setEquipmentName(device.getEquipmentName());
|
|
|
+ vo.setEquipmentLocation(device.getEquipmentLocation());
|
|
|
+ vo.setLongitude(device.getLongitude());
|
|
|
+ vo.setLatitude(device.getLatitude());
|
|
|
voList.add(vo);
|
|
|
}
|
|
|
resultPage.setRecords(voList);
|
|
|
return resultPage;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Page<EquipmentMaintainDataVO> getMyMaintainRecordPage(long pageNum, long pageSize,
|
|
|
- String maintainPerson,
|
|
|
- String maintainType, String status,
|
|
|
- String startTime, String endTime) {
|
|
|
- LambdaQueryWrapper<EquipmentMaintain> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(StrUtil.isNotBlank(maintainPerson), EquipmentMaintain::getMaintainPerson, maintainPerson)
|
|
|
- .eq(StrUtil.isNotBlank(maintainType), EquipmentMaintain::getMaintainType, maintainType)
|
|
|
- .orderByDesc(EquipmentMaintain::getMaintainDate);
|
|
|
+ private List<EquipmentBase> findWaterDevices() {
|
|
|
+ return equipmentBaseService.findByTopLevelType(waterTopLevelTypeName);
|
|
|
+ }
|
|
|
|
|
|
- Page<EquipmentMaintain> maintainPage = equipmentMaintainMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
|
|
|
- Page<EquipmentMaintainDataVO> resultPage = new Page<>(pageNum, pageSize, maintainPage.getTotal());
|
|
|
+ private EquipmentBase findWaterDeviceById(String equipmentId) {
|
|
|
+ if (StrUtil.isBlank(equipmentId)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return findWaterDevices().stream()
|
|
|
+ .filter(device -> equipmentId.equals(device.getEquipmentId()))
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
|
|
|
- if (CollUtil.isEmpty(maintainPage.getRecords())) {
|
|
|
- resultPage.setRecords(new ArrayList<>());
|
|
|
- return resultPage;
|
|
|
+ private Set<String> resolveOwnedTypeRecordIds(List<EquipmentType> allTypes, Set<String> usedTypeIds) {
|
|
|
+ Map<String, List<EquipmentType>> childrenByParent = allTypes.stream()
|
|
|
+ .filter(type -> StrUtil.isNotBlank(type.getParentTypeId()))
|
|
|
+ .collect(Collectors.groupingBy(EquipmentType::getParentTypeId));
|
|
|
+ Map<String, EquipmentType> typesById = allTypes.stream()
|
|
|
+ .collect(Collectors.toMap(EquipmentType::getId, type -> type, (left, right) -> left));
|
|
|
+
|
|
|
+ Set<String> ownedIds = new HashSet<>();
|
|
|
+ for (String usedTypeId : usedTypeIds) {
|
|
|
+ EquipmentType type = typesById.get(usedTypeId);
|
|
|
+ while (type != null && type.getParentTypeId() != null
|
|
|
+ && !"0".equals(type.getParentTypeId())
|
|
|
+ && ownedIds.add(type.getId())) {
|
|
|
+ type = typesById.get(type.getParentTypeId());
|
|
|
+ }
|
|
|
+ if (type != null) {
|
|
|
+ ownedIds.add(type.getId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- List<String> equipmentIds = maintainPage.getRecords().stream()
|
|
|
- .map(EquipmentMaintain::getEquipmentId).distinct().collect(Collectors.toList());
|
|
|
- List<EquipmentBase> devices = this.listByIds(equipmentIds);
|
|
|
- Map<String, EquipmentBase> deviceMap = devices.stream()
|
|
|
- .collect(Collectors.toMap(EquipmentBase::getEquipmentId, d -> d, (a, b) -> a));
|
|
|
+ Set<String> expandedIds = new HashSet<>(ownedIds);
|
|
|
+ for (String ownedId : ownedIds) {
|
|
|
+ expandChildTypeIds(ownedId, childrenByParent, expandedIds);
|
|
|
+ }
|
|
|
+ return expandedIds;
|
|
|
+ }
|
|
|
|
|
|
- List<EquipmentMaintainDataVO> voList = new ArrayList<>();
|
|
|
- for (EquipmentMaintain m : maintainPage.getRecords()) {
|
|
|
- EquipmentMaintainDataVO vo = BeanUtil.copyProperties(m, EquipmentMaintainDataVO.class);
|
|
|
- EquipmentBase device = deviceMap.get(m.getEquipmentId());
|
|
|
- if (device != null) {
|
|
|
- vo.setEquipmentCode(device.getEquipmentCode());
|
|
|
- vo.setEquipmentName(device.getEquipmentName());
|
|
|
- vo.setEquipmentLocation(device.getEquipmentLocation());
|
|
|
- vo.setLongitude(device.getLongitude());
|
|
|
- vo.setLatitude(device.getLatitude());
|
|
|
+ private void expandChildTypeIds(String parentId,
|
|
|
+ Map<String, List<EquipmentType>> childrenByParent,
|
|
|
+ Set<String> result) {
|
|
|
+ for (EquipmentType child : childrenByParent.getOrDefault(parentId, Collections.emptyList())) {
|
|
|
+ if (result.add(child.getId())) {
|
|
|
+ expandChildTypeIds(child.getId(), childrenByParent, result);
|
|
|
}
|
|
|
- voList.add(vo);
|
|
|
}
|
|
|
- resultPage.setRecords(voList);
|
|
|
- return resultPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean matchesLedgerFilters(EquipmentBase device, String equipmentName,
|
|
|
+ String equipmentCode, String equipmentTypeId) {
|
|
|
+ return (StrUtil.isBlank(equipmentName)
|
|
|
+ || (device.getEquipmentName() != null && device.getEquipmentName().contains(equipmentName)))
|
|
|
+ && (StrUtil.isBlank(equipmentCode)
|
|
|
+ || (device.getEquipmentCode() != null && device.getEquipmentCode().contains(equipmentCode)))
|
|
|
+ && (StrUtil.isBlank(equipmentTypeId) || equipmentTypeId.equals(device.getEquipmentTypeId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private <T> Page<T> paginate(List<T> records, long pageNum, long pageSize) {
|
|
|
+ Page<T> page = new Page<>(pageNum, pageSize, records.size());
|
|
|
+ if (pageNum < 1 || pageSize < 1) {
|
|
|
+ page.setRecords(new ArrayList<>());
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+ int fromIndex = (int) Math.min((pageNum - 1) * pageSize, records.size());
|
|
|
+ int toIndex = (int) Math.min(fromIndex + pageSize, records.size());
|
|
|
+ page.setRecords(new ArrayList<>(records.subList(fromIndex, toIndex)));
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Page<DeviceGisVO> emptyPage(long pageNum, long pageSize) {
|
|
|
+ Page<DeviceGisVO> page = new Page<>(pageNum, pageSize, 0);
|
|
|
+ page.setRecords(new ArrayList<>());
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Page<AbnormalDeviceVO> emptyAbnormalPage(long pageNum, long pageSize, long total) {
|
|
|
+ Page<AbnormalDeviceVO> page = new Page<>(pageNum, pageSize, total);
|
|
|
+ page.setRecords(new ArrayList<>());
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, AlarmData> getActiveAlarmMap(List<EquipmentBase> devices) {
|
|
|
+ if (CollUtil.isEmpty(devices)) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ List<String> deviceCodes = devices.stream()
|
|
|
+ .map(EquipmentBase::getEquipmentCode)
|
|
|
+ .filter(StrUtil::isNotBlank)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollUtil.isEmpty(deviceCodes)) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ List<AlarmData> alarms = alarmDataMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<AlarmData>()
|
|
|
+ .in(AlarmData::getDeviceCode, deviceCodes)
|
|
|
+ .eq(AlarmData::getAlarmStatus, 0)
|
|
|
+ .orderByAsc(AlarmData::getAlarmLevel)
|
|
|
+ .orderByDesc(AlarmData::getAlarmTime)
|
|
|
+ );
|
|
|
+ Map<String, AlarmData> result = new HashMap<>();
|
|
|
+ for (AlarmData alarm : alarms) {
|
|
|
+ AlarmData existing = result.get(alarm.getDeviceCode());
|
|
|
+ if (existing == null || isMoreSevereAlarm(alarm, existing)) {
|
|
|
+ result.put(alarm.getDeviceCode(), alarm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isMoreSevereAlarm(AlarmData candidate, AlarmData existing) {
|
|
|
+ if (candidate.getAlarmLevel() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (existing.getAlarmLevel() == null || candidate.getAlarmLevel() < existing.getAlarmLevel()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return Objects.equals(candidate.getAlarmLevel(), existing.getAlarmLevel())
|
|
|
+ && candidate.getAlarmTime() != null
|
|
|
+ && (existing.getAlarmTime() == null || candidate.getAlarmTime().isAfter(existing.getAlarmTime()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, WorkOrder> getLatestWorkOrderMap(List<EquipmentBase> devices) {
|
|
|
+ if (CollUtil.isEmpty(devices)) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ List<String> equipmentIds = devices.stream()
|
|
|
+ .map(EquipmentBase::getEquipmentId)
|
|
|
+ .filter(StrUtil::isNotBlank)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollUtil.isEmpty(equipmentIds)) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ List<WorkOrder> orders = workOrderMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<WorkOrder>()
|
|
|
+ .in(WorkOrder::getDeviceId, equipmentIds)
|
|
|
+ .eq(WorkOrder::getOrderType, 1)
|
|
|
+ .notIn(WorkOrder::getOrderStatus, 6, 7)
|
|
|
+ .orderByDesc(WorkOrder::getCreateTime)
|
|
|
+ );
|
|
|
+ Map<String, WorkOrder> result = new HashMap<>();
|
|
|
+ for (WorkOrder order : orders) {
|
|
|
+ if (!Objects.equals(order.getOrderType(), 1)
|
|
|
+ || Objects.equals(order.getOrderStatus(), 6)
|
|
|
+ || Objects.equals(order.getOrderStatus(), 7)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ result.putIfAbsent(order.getDeviceId(), order);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer resolveAlertLevel(EquipmentBase device, EquipmentStatus status, Map<String, AlarmData> alarmMap) {
|
|
|
+ if (status == null || status.getAlarmStatus() == null || status.getAlarmStatus() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ AlarmData alarm = alarmMap.get(device.getEquipmentCode());
|
|
|
+ return alarm != null && alarm.getAlarmLevel() != null ? alarm.getAlarmLevel() : 4;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillAbnormalDeviceVO(AbnormalDeviceVO vo, EquipmentBase base, EquipmentStatus status,
|
|
|
+ EquipmentType type, AlarmData alarm, WorkOrder workOrder,
|
|
|
+ EquipmentMaintain maintain) {
|
|
|
+ if (status != null) {
|
|
|
+ vo.setCurrentStatus(status.getCurrentStatus());
|
|
|
+ vo.setAlarmStatus(status.getAlarmStatus());
|
|
|
+ vo.setOnlineStatus(status.getOnlineStatus());
|
|
|
+ vo.setStatusUpdateTime(status.getStatusUpdateTime());
|
|
|
+ }
|
|
|
+ if (type != null) {
|
|
|
+ vo.setEquipmentTypeName(type.getTypeName());
|
|
|
+ }
|
|
|
+ if (alarm != null) {
|
|
|
+ vo.setAbnormalReason(StrUtil.isNotBlank(alarm.getWarningType())
|
|
|
+ ? alarm.getWarningType() : "设备报警");
|
|
|
+ vo.setAlarmTime(alarm.getAlarmTime());
|
|
|
+ } else if (Objects.equals(vo.getCurrentStatus(), 3)) {
|
|
|
+ vo.setAbnormalReason("设备维修中");
|
|
|
+ } else {
|
|
|
+ vo.setAbnormalReason("设备异常");
|
|
|
+ }
|
|
|
+ if (workOrder != null) {
|
|
|
+ vo.setRelatedWorkOrderNo(workOrder.getOrderNo());
|
|
|
+ vo.setRelatedWorkOrderStatus(workOrder.getOrderStatus());
|
|
|
+ vo.setRelatedWorkOrderPerson(resolveWorkOrderPerson(workOrder));
|
|
|
+ }
|
|
|
+ if (maintain != null) {
|
|
|
+ vo.setLatestMaintainId(maintain.getMaintainId());
|
|
|
+ vo.setLatestMaintainPerson(maintain.getMaintainPerson());
|
|
|
+ }
|
|
|
+ vo.setAlertLevel(resolveAlertLevel(base, status,
|
|
|
+ alarm == null ? new HashMap<>() : Collections.singletonMap(alarm.getDeviceCode(), alarm)));
|
|
|
+ fillGpsFields(vo, base.getLongitude(), base.getLatitude());
|
|
|
+ }
|
|
|
+
|
|
|
+ private String resolveWorkOrderPerson(WorkOrder workOrder) {
|
|
|
+ if (workOrder == null || StrUtil.isBlank(workOrder.getReceiveUser())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return Arrays.stream(workOrder.getReceiveUser().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(StrUtil::isNotBlank)
|
|
|
+ .map(this::resolveUserName)
|
|
|
+ .filter(StrUtil::isNotBlank)
|
|
|
+ .collect(Collectors.joining("、"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private String resolveUserName(String userId) {
|
|
|
+ try {
|
|
|
+ if (sysUserService == null) {
|
|
|
+ return userId;
|
|
|
+ }
|
|
|
+ SysUser user = sysUserService.selectUserById(Long.valueOf(userId));
|
|
|
+ if (user == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return StrUtil.isNotBlank(user.getNickName()) ? user.getNickName() : user.getUserName();
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return userId;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private Map<String, EquipmentStatus> getStatusMap(List<String> equipmentIds) {
|
|
|
@@ -648,7 +948,7 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
}
|
|
|
List<EquipmentType> types = equipmentTypeMapper.selectBatchIds(typeIds);
|
|
|
return types.stream()
|
|
|
- .collect(Collectors.toMap(EquipmentType::getTypeId, t -> t, (a, b) -> a));
|
|
|
+ .collect(Collectors.toMap(EquipmentType::getId, t -> t, (a, b) -> a));
|
|
|
}
|
|
|
|
|
|
private Map<String, EquipmentMaintain> getLatestMaintainMap(List<String> equipmentIds) {
|
|
|
@@ -799,12 +1099,9 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private int calcAlertLevel(String deviceCode, EquipmentStatus status) {
|
|
|
+ private Integer calcAlertLevel(String deviceCode, EquipmentStatus status) {
|
|
|
if (status == null || status.getAlarmStatus() == null || status.getAlarmStatus() == 0) {
|
|
|
- if (status != null && status.getCurrentStatus() != null && status.getCurrentStatus() == 3) {
|
|
|
- return 3;
|
|
|
- }
|
|
|
- return 4;
|
|
|
+ return null;
|
|
|
}
|
|
|
int maxLevel = 4;
|
|
|
try {
|
|
|
@@ -812,7 +1109,7 @@ public class WaterSupplyDeviceServiceImpl extends ServiceImpl<EquipmentBaseMappe
|
|
|
new LambdaQueryWrapper<com.zksy.base.alarm.domain.AlarmData>()
|
|
|
.eq(com.zksy.base.alarm.domain.AlarmData::getDeviceCode, deviceCode)
|
|
|
.eq(com.zksy.base.alarm.domain.AlarmData::getAlarmStatus, 0)
|
|
|
- .orderByDesc(com.zksy.base.alarm.domain.AlarmData::getAlarmLevel)
|
|
|
+ .orderByAsc(com.zksy.base.alarm.domain.AlarmData::getAlarmLevel)
|
|
|
.last("LIMIT 1")
|
|
|
);
|
|
|
if (CollUtil.isNotEmpty(alarms) && alarms.get(0).getAlarmLevel() != null) {
|