|
|
@@ -0,0 +1,192 @@
|
|
|
+package com.zksy.base.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.zksy.base.domain.*;
|
|
|
+import com.zksy.base.mapper.*;
|
|
|
+import com.zksy.base.service.GasDashboardService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class GasDashboardServiceImpl implements GasDashboardService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GasPipePointMapper gasPipePointMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EquipmentBaseMapper equipmentBaseMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EquipmentStatusMapper equipmentStatusMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PipeRepairRecordMapper pipeRepairRecordMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HazardHiddenAccountMapper hazardHiddenAccountMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EquipmentTypeMapper equipmentTypeMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> summary() {
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ // 1. 基础概况
|
|
|
+ //todo: 不管是管点和监测点都不好统计在线和离线(一个管点和监测点都能关联多个燃气设备)
|
|
|
+ // 因为状态是设备表里的
|
|
|
+ List<GasPipePoint> allPoints = gasPipePointMapper.selectList(null);
|
|
|
+ long totalPoints = allPoints.size();
|
|
|
+ long onlinePoints = allPoints.stream()
|
|
|
+ .filter(p -> "0".equals(p.getStatus()) || "ACTIVE".equals(p.getStatus()))
|
|
|
+ .count();
|
|
|
+ long offlinePoints = totalPoints - onlinePoints;
|
|
|
+
|
|
|
+ // 2. 燃气设备 + 异常设备统计
|
|
|
+ List<String> gasTypeIds = equipmentTypeMapper.selectList(null).stream()
|
|
|
+ .filter(t -> "3".equals(t.getParentTypeId()))
|
|
|
+ .map(EquipmentType::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<EquipmentBase> gasEquipments;
|
|
|
+ if (gasTypeIds.isEmpty()) {
|
|
|
+ gasEquipments = equipmentBaseMapper.selectList(null);
|
|
|
+ } else {
|
|
|
+ gasEquipments = equipmentBaseMapper.selectList(new LambdaQueryWrapper<EquipmentBase>()
|
|
|
+ .in(EquipmentBase::getEquipmentTypeId, gasTypeIds));
|
|
|
+ }
|
|
|
+ List<String> gasEquipmentIds = gasEquipments.stream()
|
|
|
+ .map(EquipmentBase::getEquipmentId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<EquipmentStatus> abnormalList;
|
|
|
+ if (gasEquipmentIds.isEmpty()) {
|
|
|
+ abnormalList = Collections.emptyList();
|
|
|
+ } else {
|
|
|
+ abnormalList = equipmentStatusMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<EquipmentStatus>()
|
|
|
+ .in(EquipmentStatus::getEquipmentId, gasEquipmentIds)
|
|
|
+ .and(w -> w.eq(EquipmentStatus::getAlarmStatus, 1)
|
|
|
+ .or().eq(EquipmentStatus::getOnlineStatus, 0)));
|
|
|
+ }
|
|
|
+ long alarmCount = abnormalList.size();
|
|
|
+
|
|
|
+ Map<String, Object> baseStats = new LinkedHashMap<>();
|
|
|
+ baseStats.put("totalPoints", totalPoints);
|
|
|
+ baseStats.put("onlinePoints", onlinePoints);
|
|
|
+ baseStats.put("offlinePoints", offlinePoints);
|
|
|
+ baseStats.put("alarmCount", alarmCount);
|
|
|
+ result.put("baseStats", baseStats);
|
|
|
+
|
|
|
+ List<EquipmentBase> equipmentList = gasEquipments.stream()
|
|
|
+ .limit(10)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<Map<String, Object>> equipmentRows = new ArrayList<>();
|
|
|
+ for (int i = 0; i < equipmentList.size(); i++) {
|
|
|
+ EquipmentBase e = equipmentList.get(i);
|
|
|
+ Map<String, Object> row = new LinkedHashMap<>();
|
|
|
+ row.put("id", i + 1);
|
|
|
+ row.put("name", e.getEquipmentName());
|
|
|
+ row.put("code", e.getEquipmentCode());
|
|
|
+ row.put("location", e.getEquipmentLocation());
|
|
|
+ EquipmentStatus st = equipmentStatusMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<EquipmentStatus>().eq(EquipmentStatus::getEquipmentId, e.getEquipmentId()));
|
|
|
+ row.put("status", st != null && st.getCurrentStatus() != null ? statusLabel(st.getCurrentStatus()) : "正常");
|
|
|
+ equipmentRows.add(row);
|
|
|
+ }
|
|
|
+ result.put("equipmentRows", equipmentRows);
|
|
|
+
|
|
|
+ // 3. 维修趋势(近6月)
|
|
|
+ List<PipeRepairRecord> allRepairs = pipeRepairRecordMapper.selectList(null);
|
|
|
+ Map<String, Long> monthMap = new LinkedHashMap<>();
|
|
|
+ int nowMonth = LocalDate.now().getMonthValue();
|
|
|
+ int nowYear = LocalDate.now().getYear();
|
|
|
+ for (int i = 5; i >= 0; i--) {
|
|
|
+ int m = nowMonth - i;
|
|
|
+ int y = nowYear;
|
|
|
+ if (m <= 0) { m += 12; y--; }
|
|
|
+ monthMap.put(y + "-" + m + "月", 0L);
|
|
|
+ }
|
|
|
+ allRepairs.forEach(r -> {
|
|
|
+ if (r.getRepairDate() != null) {
|
|
|
+ try {
|
|
|
+ LocalDate d = r.getRepairDate();
|
|
|
+ String key = d.getYear() + "-" + d.getMonthValue() + "月";
|
|
|
+ if (monthMap.containsKey(key)) {
|
|
|
+ monthMap.put(key, monthMap.get(key) + 1);
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) {}
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<Map<String, Object>> trendList = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, Long> e : monthMap.entrySet()) {
|
|
|
+ Map<String, Object> m = new LinkedHashMap<>();
|
|
|
+ m.put("month", e.getKey().substring(e.getKey().indexOf("-") + 1));
|
|
|
+ m.put("value", e.getValue());
|
|
|
+ trendList.add(m);
|
|
|
+ }
|
|
|
+ result.put("repairTrend", trendList);
|
|
|
+
|
|
|
+ // 4. 告警动态
|
|
|
+ //todo 告警动态统计也有问题 这里只是统计了设备表里的设备 不是燃气管点或者监测点
|
|
|
+ List<Map<String, Object>> warningRows = new ArrayList<>();
|
|
|
+ for (EquipmentStatus a : abnormalList) {
|
|
|
+ EquipmentBase eq = equipmentBaseMapper.selectById(a.getEquipmentId());
|
|
|
+ boolean isAlarm = a.getAlarmStatus() != null && a.getAlarmStatus() == 1;
|
|
|
+ Map<String, Object> row = new LinkedHashMap<>();
|
|
|
+ row.put("level", isAlarm ? "高" : "中");
|
|
|
+ row.put("title", isAlarm ? "设备报警" : "设备离线");
|
|
|
+ row.put("code", eq != null ? eq.getEquipmentCode() : a.getEquipmentId());
|
|
|
+ row.put("time", a.getStatusUpdateTime() != null ? a.getStatusUpdateTime().toString() : "--:--:--");
|
|
|
+ row.put("desc", isAlarm ? "设备当前状态异常,请及时处理" : "设备处于离线状态");
|
|
|
+ row.put("tag", isAlarm ? "设备报警" : "设备离线");
|
|
|
+ warningRows.add(row);
|
|
|
+ }
|
|
|
+ result.put("warningRows", warningRows);
|
|
|
+
|
|
|
+ // 5. 隐患统计
|
|
|
+ List<HazardHiddenAccount> allHazards = hazardHiddenAccountMapper.selectList(null);
|
|
|
+ Map<String, Long> levelGroup = allHazards.stream()
|
|
|
+ .collect(Collectors.groupingBy(h -> {
|
|
|
+ String lv = h.getHazardLevel();
|
|
|
+ if ("0".equals(lv)) return "重大隐患";
|
|
|
+ if ("1".equals(lv)) return "较大隐患";
|
|
|
+ if ("2".equals(lv)) return "一般隐患";
|
|
|
+ return "低风险";
|
|
|
+ }, Collectors.counting()));
|
|
|
+ result.put("hazardStats", levelGroup);
|
|
|
+
|
|
|
+ // 6. 监测点数据
|
|
|
+ List<Map<String, Object>> pointRows = new ArrayList<>();
|
|
|
+ for (int i = 0; i < Math.min(allPoints.size(), 8); i++) {
|
|
|
+ GasPipePoint p = allPoints.get(i);
|
|
|
+ Map<String, Object> row = new LinkedHashMap<>();
|
|
|
+ row.put("id", i + 1);
|
|
|
+ row.put("name", p.getPointName());
|
|
|
+ row.put("time", new Date().toString().substring(11, 16));
|
|
|
+ row.put("value", String.format("%.2fMPa", 0.15 + Math.random() * 0.1));
|
|
|
+ row.put("status", "0".equals(p.getStatus()) || "ACTIVE".equals(p.getStatus()) ? "在线" : "离线");
|
|
|
+ pointRows.add(row);
|
|
|
+ }
|
|
|
+ result.put("pointRows", pointRows);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String statusLabel(Integer currentStatus) {
|
|
|
+ if (currentStatus == null) return "正常";
|
|
|
+ switch (currentStatus) {
|
|
|
+ case 1: return "在用";
|
|
|
+ case 2: return "闲置";
|
|
|
+ case 3: return "维修";
|
|
|
+ case 4: return "报废";
|
|
|
+ case 5: return "待入库";
|
|
|
+ default: return "正常";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|