|
@@ -1,408 +0,0 @@
|
|
|
-package com.zksy.base.service.impl;
|
|
|
|
|
-
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
-import com.zksy.base.constant.GasEquipmentTypeEnum;
|
|
|
|
|
-import com.zksy.base.domain.*;
|
|
|
|
|
-import com.zksy.base.mapper.*;
|
|
|
|
|
-import com.zksy.base.gas.domain.GasMonitorData;
|
|
|
|
|
-import com.zksy.base.gas.mapper.GasMonitorDataMapper;
|
|
|
|
|
-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 GasPipePointDeviceRelMapper gasPipePointDeviceRelMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private GasMonitorDataMapper gasMonitorDataMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private EquipmentBaseMapper equipmentBaseMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private EquipmentStatusMapper equipmentStatusMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private PipeRepairRecordMapper pipeRepairRecordMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private HazardHiddenAccountMapper hazardHiddenAccountMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private EquipmentTypeMapper equipmentTypeMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private PipeNetworkBaseMapper pipeNetworkBaseMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private com.zksy.base.service.PressureMonitorService pressureMonitorService;
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public Map<String, Object> summary() {
|
|
|
|
|
- Map<String, Object> result = new LinkedHashMap<>();
|
|
|
|
|
-
|
|
|
|
|
- // 1. 管点口径(地图右侧「当前管点信息」用,保留原统计方式)
|
|
|
|
|
- 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<EquipmentType> allTypes = equipmentTypeMapper.selectList(null);
|
|
|
|
|
- Set<String> gasTypeIds = resolveTypeIdsUnderRoot(allTypes, GasEquipmentTypeEnum.parent_id);
|
|
|
|
|
- List<EquipmentBase> gasEquipments;
|
|
|
|
|
- if (gasTypeIds.isEmpty()) {
|
|
|
|
|
- gasEquipments = Collections.emptyList();
|
|
|
|
|
- } else {
|
|
|
|
|
- gasEquipments = equipmentBaseMapper.selectList(new LambdaQueryWrapper<EquipmentBase>()
|
|
|
|
|
- .in(EquipmentBase::getEquipmentTypeId, gasTypeIds));
|
|
|
|
|
- }
|
|
|
|
|
- List<String> gasEquipmentIds = gasEquipments.stream()
|
|
|
|
|
- .map(EquipmentBase::getEquipmentId)
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- // 每台设备只取最新一条状态记录,避免历史状态重复计入
|
|
|
|
|
- Map<String, EquipmentStatus> latestStatus = latestStatusByEquipment(gasEquipmentIds);
|
|
|
|
|
- long onlineEquipments = latestStatus.values().stream()
|
|
|
|
|
- .filter(s -> s.getOnlineStatus() != null && s.getOnlineStatus() == 1)
|
|
|
|
|
- .count();
|
|
|
|
|
- long offlineEquipments = gasEquipments.size() - onlineEquipments;
|
|
|
|
|
- // 在线率按燃气设备统计
|
|
|
|
|
- double onlineRate = gasEquipments.isEmpty()
|
|
|
|
|
- ? 0d
|
|
|
|
|
- : Math.round(onlineEquipments * 1000.0 / gasEquipments.size()) / 10.0;
|
|
|
|
|
-
|
|
|
|
|
- List<EquipmentStatus> abnormalList = latestStatus.values().stream()
|
|
|
|
|
- .filter(s -> (s.getAlarmStatus() != null && s.getAlarmStatus() == 1)
|
|
|
|
|
- || (s.getOnlineStatus() != null && s.getOnlineStatus() == 0))
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- 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);
|
|
|
|
|
- baseStats.put("totalEquipments", gasEquipments.size());
|
|
|
|
|
- baseStats.put("onlineEquipments", onlineEquipments);
|
|
|
|
|
- baseStats.put("offlineEquipments", offlineEquipments);
|
|
|
|
|
- baseStats.put("onlineRate", onlineRate);
|
|
|
|
|
- result.put("baseStats", baseStats);
|
|
|
|
|
-
|
|
|
|
|
- // ---- 管网统计 ----
|
|
|
|
|
- // 燃气模块:仅统计 network_type=0 的燃气设施
|
|
|
|
|
- List<PipeNetworkBase> allNetworks = pipeNetworkBaseMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<PipeNetworkBase>()
|
|
|
|
|
- .eq(PipeNetworkBase::getNetworkType, PipeNetworkBase.NETWORK_TYPE_GAS));
|
|
|
|
|
- // 管网总长度(公里)
|
|
|
|
|
- double totalLength = allNetworks.stream()
|
|
|
|
|
- .filter(n -> n.getLength() != null)
|
|
|
|
|
- .mapToDouble(n -> n.getLength().doubleValue())
|
|
|
|
|
- .sum();
|
|
|
|
|
- double totalLengthKm = Math.round(totalLength / 1000.0 * 100) / 100.0;
|
|
|
|
|
- // 燃气管网数量(上方已按燃气设施过滤)
|
|
|
|
|
- long gasNetworkCount = allNetworks.size();
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> pipeStats = new LinkedHashMap<>();
|
|
|
|
|
- pipeStats.put("totalLength", totalLengthKm); // 管网总长度(km)
|
|
|
|
|
- pipeStats.put("totalNetworks", allNetworks.size()); // 管网总数
|
|
|
|
|
- pipeStats.put("gasNetworks", gasNetworkCount); // 燃气管网数
|
|
|
|
|
- result.put("pipeStats", pipeStats);
|
|
|
|
|
-
|
|
|
|
|
- // ---- 设备统计 ----
|
|
|
|
|
- // 门阀数 = 燃气设备中类型名称含"阀"的数量
|
|
|
|
|
- Map<String, String> typeIdToName = allTypes.stream()
|
|
|
|
|
- .collect(Collectors.toMap(type -> String.valueOf(type.getId()), EquipmentType::getTypeName, (a, b) -> a));
|
|
|
|
|
- long valveCount = gasEquipments.stream()
|
|
|
|
|
- .filter(e -> {
|
|
|
|
|
- String typeName = typeIdToName.getOrDefault(e.getEquipmentTypeId(), "");
|
|
|
|
|
- return typeName.contains("阀");
|
|
|
|
|
- })
|
|
|
|
|
- .count();
|
|
|
|
|
- // 今日告警
|
|
|
|
|
- String todayStr = LocalDate.now().toString();
|
|
|
|
|
- long todayAlarm = abnormalList.stream()
|
|
|
|
|
- .filter(s -> s.getAlarmStatus() != null && s.getAlarmStatus() == 1)
|
|
|
|
|
- .filter(s -> s.getStatusUpdateTime() != null && s.getStatusUpdateTime().toString().startsWith(todayStr))
|
|
|
|
|
- .count();
|
|
|
|
|
-
|
|
|
|
|
- // 压力:每个遥测站点取最新一条采集值,再对最新值求均值(kPa → MPa)
|
|
|
|
|
- List<Map<String, Object>> pressurePoints = new ArrayList<>();
|
|
|
|
|
- Double avgPressureMpa = null;
|
|
|
|
|
- String pressureUpdatedAt = null;
|
|
|
|
|
- try {
|
|
|
|
|
- List<Map<String, Object>> points = pressureMonitorService.getPoints();
|
|
|
|
|
- if (points != null) {
|
|
|
|
|
- pressurePoints = points;
|
|
|
|
|
- double sum = 0;
|
|
|
|
|
- int count = 0;
|
|
|
|
|
- for (Map<String, Object> point : points) {
|
|
|
|
|
- Object latest = point.get("latestPressure");
|
|
|
|
|
- if (latest instanceof Number) {
|
|
|
|
|
- double value = ((Number) latest).doubleValue();
|
|
|
|
|
- if (value > 0) {
|
|
|
|
|
- sum += value;
|
|
|
|
|
- count++;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- Object time = point.get("latestTime");
|
|
|
|
|
- if (time != null && !String.valueOf(time).isEmpty()) {
|
|
|
|
|
- String text = String.valueOf(time);
|
|
|
|
|
- if (pressureUpdatedAt == null || text.compareTo(pressureUpdatedAt) > 0) {
|
|
|
|
|
- pressureUpdatedAt = text;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (count > 0) {
|
|
|
|
|
- avgPressureMpa = Math.round(sum / count / 1000.0 * 100) / 100.0;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.warn("统计燃气压力最新值失败", e);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- Map<String, Object> equipmentStats = new LinkedHashMap<>();
|
|
|
|
|
- equipmentStats.put("valveCount", valveCount);
|
|
|
|
|
- equipmentStats.put("totalEquipment", gasEquipments.size());
|
|
|
|
|
- equipmentStats.put("todayAlarm", todayAlarm);
|
|
|
|
|
- equipmentStats.put("avgPressure", avgPressureMpa);
|
|
|
|
|
- equipmentStats.put("onlineEquipments", onlineEquipments);
|
|
|
|
|
- equipmentStats.put("offlineEquipments", offlineEquipments);
|
|
|
|
|
- equipmentStats.put("onlineRate", onlineRate);
|
|
|
|
|
- result.put("equipmentStats", equipmentStats);
|
|
|
|
|
-
|
|
|
|
|
- // 地图压力点位(含最新压力值与阈值状态),供首页实时打击
|
|
|
|
|
- result.put("pressurePoints", pressurePoints);
|
|
|
|
|
- result.put("pressureUpdatedAt", pressureUpdatedAt);
|
|
|
|
|
-
|
|
|
|
|
- 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<GasPipePointDeviceRel> pointDeviceRels = gasPipePointDeviceRelMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<GasPipePointDeviceRel>()
|
|
|
|
|
- .eq(GasPipePointDeviceRel::getDelFlag, "0"));
|
|
|
|
|
- Map<Long, List<GasPipePointDeviceRel>> relByPoint = pointDeviceRels.stream()
|
|
|
|
|
- .filter(rel -> rel.getPointId() != null)
|
|
|
|
|
- .collect(Collectors.groupingBy(GasPipePointDeviceRel::getPointId));
|
|
|
|
|
- List<Map<String, Object>> pointRows = new ArrayList<>();
|
|
|
|
|
- int rowIndex = 1;
|
|
|
|
|
- for (GasPipePoint p : allPoints) {
|
|
|
|
|
- List<GasPipePointDeviceRel> relations = relByPoint.getOrDefault(p.getPointId(), Collections.emptyList());
|
|
|
|
|
- // 没有关联设备的监测点也保留一行,便于识别未配置设备的点位。
|
|
|
|
|
- if (relations.isEmpty()) {
|
|
|
|
|
- pointRows.add(buildPointRow(rowIndex++, p, null));
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- for (GasPipePointDeviceRel rel : relations) {
|
|
|
|
|
- pointRows.add(buildPointRow(rowIndex++, p, rel));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- result.put("pointRows", pointRows);
|
|
|
|
|
-
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 取某个根类型下的全部类型主键(含根自身与多级子类型)
|
|
|
|
|
- *
|
|
|
|
|
- * 设备类型是多级树,只看一级子类型会漏掉挂在三级类型上的设备。
|
|
|
|
|
- */
|
|
|
|
|
- private Set<String> resolveTypeIdsUnderRoot(List<EquipmentType> allTypes, Integer rootId) {
|
|
|
|
|
- Map<Integer, Integer> parentOf = new HashMap<>();
|
|
|
|
|
- for (EquipmentType type : allTypes) {
|
|
|
|
|
- parentOf.put(type.getId(), type.getParentId());
|
|
|
|
|
- }
|
|
|
|
|
- Set<String> result = new HashSet<>();
|
|
|
|
|
- for (EquipmentType type : allTypes) {
|
|
|
|
|
- Integer current = type.getId();
|
|
|
|
|
- int guard = 0;
|
|
|
|
|
- while (current != null && guard++ < 20) {
|
|
|
|
|
- if (Objects.equals(current, rootId)) {
|
|
|
|
|
- result.add(String.valueOf(type.getId()));
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- current = parentOf.get(current);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 按设备取最新一条状态记录
|
|
|
|
|
- *
|
|
|
|
|
- * 设备状态表可能保留多条历史记录,直接 selectList 会把历史状态重复计入统计。
|
|
|
|
|
- */
|
|
|
|
|
- private Map<String, EquipmentStatus> latestStatusByEquipment(List<String> equipmentIds) {
|
|
|
|
|
- if (equipmentIds == null || equipmentIds.isEmpty()) {
|
|
|
|
|
- return Collections.emptyMap();
|
|
|
|
|
- }
|
|
|
|
|
- List<EquipmentStatus> list = equipmentStatusMapper.selectList(
|
|
|
|
|
- new LambdaQueryWrapper<EquipmentStatus>()
|
|
|
|
|
- .in(EquipmentStatus::getEquipmentId, equipmentIds)
|
|
|
|
|
- .orderByDesc(EquipmentStatus::getStatusUpdateTime));
|
|
|
|
|
- Map<String, EquipmentStatus> latest = new LinkedHashMap<>();
|
|
|
|
|
- for (EquipmentStatus status : list) {
|
|
|
|
|
- latest.putIfAbsent(status.getEquipmentId(), status);
|
|
|
|
|
- }
|
|
|
|
|
- return latest;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private Map<String, Object> buildPointRow(int id, GasPipePoint point, GasPipePointDeviceRel relation) {
|
|
|
|
|
- Map<String, Object> row = new LinkedHashMap<>();
|
|
|
|
|
- row.put("id", id);
|
|
|
|
|
- row.put("name", point.getPointName());
|
|
|
|
|
- row.put("pointName", point.getPointName());
|
|
|
|
|
- row.put("pointCode", point.getPointCode());
|
|
|
|
|
- String equipmentName = relation == null ? null : relation.getEquipmentName();
|
|
|
|
|
- String equipmentCode = null;
|
|
|
|
|
- String status = "0".equals(point.getStatus()) || "ACTIVE".equals(point.getStatus()) ? "在线" : "离线";
|
|
|
|
|
- String value = "--";
|
|
|
|
|
- String time = "--";
|
|
|
|
|
- if (relation != null && relation.getEquipmentId() != null) {
|
|
|
|
|
- EquipmentBase equipment = equipmentBaseMapper.selectById(relation.getEquipmentId());
|
|
|
|
|
- if (equipment != null) {
|
|
|
|
|
- equipmentName = equipmentName == null || equipmentName.isEmpty() ? equipment.getEquipmentName() : equipmentName;
|
|
|
|
|
- equipmentCode = equipment.getEquipmentCode();
|
|
|
|
|
- EquipmentStatus equipmentStatus = equipmentStatusMapper.selectOne(
|
|
|
|
|
- new LambdaQueryWrapper<EquipmentStatus>()
|
|
|
|
|
- .eq(EquipmentStatus::getEquipmentId, equipment.getEquipmentId())
|
|
|
|
|
- .orderByDesc(EquipmentStatus::getStatusUpdateTime)
|
|
|
|
|
- .last("LIMIT 1"));
|
|
|
|
|
- if (equipmentStatus != null && equipmentStatus.getOnlineStatus() != null) {
|
|
|
|
|
- status = equipmentStatus.getOnlineStatus() == 1 ? "在线" : "离线";
|
|
|
|
|
- }
|
|
|
|
|
- GasMonitorData latest = gasMonitorDataMapper.selectOne(
|
|
|
|
|
- new LambdaQueryWrapper<GasMonitorData>()
|
|
|
|
|
- .eq(GasMonitorData::getMacAddress, equipment.getEquipmentCode())
|
|
|
|
|
- .orderByDesc(GasMonitorData::getReportTime)
|
|
|
|
|
- .last("LIMIT 1"));
|
|
|
|
|
- if (latest == null && relation.getEquipmentId() != null) {
|
|
|
|
|
- latest = gasMonitorDataMapper.selectOne(
|
|
|
|
|
- new LambdaQueryWrapper<GasMonitorData>()
|
|
|
|
|
- .eq(GasMonitorData::getMacAddress, relation.getEquipmentId())
|
|
|
|
|
- .orderByDesc(GasMonitorData::getReportTime)
|
|
|
|
|
- .last("LIMIT 1"));
|
|
|
|
|
- }
|
|
|
|
|
- if (latest != null) {
|
|
|
|
|
- if (latest.getGasConcentration() != null) {
|
|
|
|
|
- value = latest.getGasConcentration().stripTrailingZeros().toPlainString() + "%LEL";
|
|
|
|
|
- }
|
|
|
|
|
- if (latest.getReportTime() != null) {
|
|
|
|
|
- time = latest.getReportTime().toString().replace('T', ' ');
|
|
|
|
|
- } else if (latest.getCreateTime() != null) {
|
|
|
|
|
- time = latest.getCreateTime().toString().replace('T', ' ');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- row.put("deviceName", equipmentName == null ? "-" : equipmentName);
|
|
|
|
|
- row.put("deviceCode", equipmentCode == null && relation != null ? relation.getEquipmentId() : equipmentCode);
|
|
|
|
|
- row.put("time", time);
|
|
|
|
|
- row.put("value", value);
|
|
|
|
|
- row.put("status", status);
|
|
|
|
|
- return row;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- 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 "正常";
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|