|
|
@@ -4,34 +4,16 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.zksy.base.domain.EquipmentBase;
|
|
|
-import com.zksy.base.domain.EquipmentStatus;
|
|
|
-import com.zksy.base.domain.EquipmentType;
|
|
|
import com.zksy.base.domain.MaintenanceDataStat;
|
|
|
-import com.zksy.base.enums.DistrictEnum;
|
|
|
-import com.zksy.ops.domain.WorkOrder;
|
|
|
-import com.zksy.base.manhole.domain.ManholeData;
|
|
|
-import com.zksy.base.manhole.mapper.ManholeDataMapper;
|
|
|
-import com.zksy.base.mapper.EquipmentBaseMapper;
|
|
|
-import com.zksy.base.mapper.EquipmentStatusMapper;
|
|
|
-import com.zksy.base.mapper.EquipmentTypeMapper;
|
|
|
import com.zksy.base.mapper.MaintenanceDataStatMapper;
|
|
|
-import com.zksy.ops.mapper.WorkOrderMapper;
|
|
|
import com.zksy.base.service.MaintenanceDataStatService;
|
|
|
import com.zksy.common.exception.ServiceException;
|
|
|
-import com.zksy.manhole.dto.in.MaintenanceDataStatDashboardInDTO;
|
|
|
import com.zksy.manhole.dto.in.MaintenanceDataStatQueryInDTO;
|
|
|
import com.zksy.manhole.dto.in.MaintenanceDataStatTrendInDTO;
|
|
|
import com.zksy.manhole.dto.out.AbnormalTerminalTrendOutDTO;
|
|
|
import com.zksy.manhole.dto.out.CaseRateTrendOutDTO;
|
|
|
-import com.zksy.manhole.dto.out.EquipmentBaseOutDTO;
|
|
|
-import com.zksy.manhole.dto.out.EquipmentStatusOutDTO;
|
|
|
-import com.zksy.manhole.dto.out.MaintenanceDataStatDashboardOutDTO;
|
|
|
import com.zksy.manhole.dto.out.MaintenanceDataStatOutDTO;
|
|
|
-import com.zksy.manhole.dto.out.ManholeDataOutDTO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -40,9 +22,12 @@ import java.time.LocalDate;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.WeekFields;
|
|
|
-import java.util.*;
|
|
|
-import java.util.function.Function;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author Administrator
|
|
|
@@ -54,25 +39,8 @@ import java.util.stream.Collectors;
|
|
|
public class MaintenanceDataStatServiceImpl extends ServiceImpl<MaintenanceDataStatMapper, MaintenanceDataStat>
|
|
|
implements MaintenanceDataStatService{
|
|
|
|
|
|
- @Autowired
|
|
|
- private EquipmentBaseMapper equipmentBaseMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private EquipmentTypeMapper equipmentTypeMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private EquipmentStatusMapper equipmentStatusMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ManholeDataMapper manholeDataMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private WorkOrderMapper workOrderMapper;
|
|
|
-
|
|
|
/**
|
|
|
* 根据日期查询运维数据统计
|
|
|
- * @param queryInDTO
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public MaintenanceDataStatOutDTO queryByDate(MaintenanceDataStatQueryInDTO queryInDTO) {
|
|
|
@@ -89,8 +57,6 @@ public class MaintenanceDataStatServiceImpl extends ServiceImpl<MaintenanceDataS
|
|
|
|
|
|
/**
|
|
|
* 周度/月度 异常终端设备数量趋势分析
|
|
|
- * @param inDTO
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public List<AbnormalTerminalTrendOutDTO> abnormalTerminalTrend(MaintenanceDataStatTrendInDTO inDTO) {
|
|
|
@@ -99,16 +65,13 @@ public class MaintenanceDataStatServiceImpl extends ServiceImpl<MaintenanceDataS
|
|
|
if(CollUtil.isEmpty(statList)){
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
- // 按周度/月度分组
|
|
|
Map<String, List<MaintenanceDataStat>> groupedMap = groupByPeriod(statList, inDTO.getTrendType());
|
|
|
List<AbnormalTerminalTrendOutDTO> result = new ArrayList<>();
|
|
|
for(Map.Entry<String, List<MaintenanceDataStat>> entry : groupedMap.entrySet()){
|
|
|
List<MaintenanceDataStat> periodList = entry.getValue();
|
|
|
AbnormalTerminalTrendOutDTO outDTO = new AbnormalTerminalTrendOutDTO();
|
|
|
outDTO.setTrendLabel(entry.getKey());
|
|
|
- // 取该周期内第一条记录的统计日期作为代表日期
|
|
|
outDTO.setStatDate(periodList.get(0).getStatDate());
|
|
|
- // 计算平均异常终端设备数量
|
|
|
double avgAbnormal = periodList.stream()
|
|
|
.filter(s -> s.getAbnormalTerminal() != null)
|
|
|
.mapToInt(MaintenanceDataStat::getAbnormalTerminal)
|
|
|
@@ -117,15 +80,12 @@ public class MaintenanceDataStatServiceImpl extends ServiceImpl<MaintenanceDataS
|
|
|
outDTO.setAbnormalTerminal((int) Math.round(avgAbnormal));
|
|
|
result.add(outDTO);
|
|
|
}
|
|
|
- // 按趋势标签排序
|
|
|
result.sort(Comparator.comparing(AbnormalTerminalTrendOutDTO::getTrendLabel));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 周度/月度 案件处置率、案件延期率趋势分析
|
|
|
- * @param inDTO
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public List<CaseRateTrendOutDTO> caseRateTrend(MaintenanceDataStatTrendInDTO inDTO) {
|
|
|
@@ -134,7 +94,6 @@ public class MaintenanceDataStatServiceImpl extends ServiceImpl<MaintenanceDataS
|
|
|
if(CollUtil.isEmpty(statList)){
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
- // 按周度/月度分组
|
|
|
Map<String, List<MaintenanceDataStat>> groupedMap = groupByPeriod(statList, inDTO.getTrendType());
|
|
|
List<CaseRateTrendOutDTO> result = new ArrayList<>();
|
|
|
for(Map.Entry<String, List<MaintenanceDataStat>> entry : groupedMap.entrySet()){
|
|
|
@@ -142,14 +101,12 @@ public class MaintenanceDataStatServiceImpl extends ServiceImpl<MaintenanceDataS
|
|
|
CaseRateTrendOutDTO outDTO = new CaseRateTrendOutDTO();
|
|
|
outDTO.setTrendLabel(entry.getKey());
|
|
|
outDTO.setStatDate(periodList.get(0).getStatDate());
|
|
|
- // 计算平均案件处置率
|
|
|
double avgDisposalRate = periodList.stream()
|
|
|
.filter(s -> s.getCaseDisposalRate() != null)
|
|
|
.mapToDouble(s -> s.getCaseDisposalRate().doubleValue())
|
|
|
.average()
|
|
|
.orElse(0);
|
|
|
outDTO.setCaseDisposalRate(BigDecimal.valueOf(avgDisposalRate).setScale(2, RoundingMode.HALF_UP));
|
|
|
- // 计算平均案件延期率
|
|
|
double avgDelayRate = periodList.stream()
|
|
|
.filter(s -> s.getCaseDelayRate() != null)
|
|
|
.mapToDouble(s -> s.getCaseDelayRate().doubleValue())
|
|
|
@@ -158,414 +115,12 @@ public class MaintenanceDataStatServiceImpl extends ServiceImpl<MaintenanceDataS
|
|
|
outDTO.setCaseDelayRate(BigDecimal.valueOf(avgDelayRate).setScale(2, RoundingMode.HALF_UP));
|
|
|
result.add(outDTO);
|
|
|
}
|
|
|
- // 按趋势标签排序
|
|
|
result.sort(Comparator.comparing(CaseRateTrendOutDTO::getTrendLabel));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 运维看板统计数据:一次返回KPI指标、异常终端趋势、处置率/延期率趋势、问题类型分布、区域排行、异常终端列表
|
|
|
- * 数据来源:
|
|
|
- * - KPI/问题类型分布/区域排行/异常终端列表:equipment_base + equipment_status + jg_device_data + work_order 实时计算
|
|
|
- * - 趋势:日期范围内 jg_device_data 历史记录与 work_order 按周度/月度分组统计
|
|
|
- * @param inDTO
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public MaintenanceDataStatDashboardOutDTO getDashboardStat(MaintenanceDataStatDashboardInDTO inDTO) {
|
|
|
- log.info("运维看板统计数据-入参:{}", inDTO);
|
|
|
- MaintenanceDataStatDashboardOutDTO outDTO = new MaintenanceDataStatDashboardOutDTO();
|
|
|
-
|
|
|
- // ============ 日期范围:默认近6个月 ============
|
|
|
- Date endDate = inDTO.getEndDate() != null ? inDTO.getEndDate() : new Date();
|
|
|
- Date startDate = inDTO.getStartDate();
|
|
|
- if (startDate == null) {
|
|
|
- Calendar cal = Calendar.getInstance();
|
|
|
- cal.setTime(endDate);
|
|
|
- cal.add(Calendar.MONTH, -5);
|
|
|
- cal.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
- startDate = cal.getTime();
|
|
|
- }
|
|
|
- int trendType = inDTO.getTrendType() != null ? inDTO.getTrendType() : 2;
|
|
|
-
|
|
|
- // ============ 1. 查询窨井设备(排水9/供水10/燃气5) ============
|
|
|
- List<String> manholeTypeIds = Arrays.asList("5", "9", "10");
|
|
|
- List<EquipmentBase> equipmentList = equipmentBaseMapper.selectList(
|
|
|
- new LambdaQueryWrapper<EquipmentBase>()
|
|
|
- .in(EquipmentBase::getEquipmentTypeId, manholeTypeIds)
|
|
|
- .orderByDesc(EquipmentBase::getUpdateTime));
|
|
|
- if (CollUtil.isEmpty(equipmentList)) {
|
|
|
- outDTO.setKpi(buildEmptyKpi());
|
|
|
- return outDTO;
|
|
|
- }
|
|
|
- List<EquipmentBaseOutDTO> deviceList = BeanUtil.copyToList(equipmentList, EquipmentBaseOutDTO.class);
|
|
|
- List<String> equipmentIdList = deviceList.stream().map(EquipmentBaseOutDTO::getEquipmentId).distinct().collect(Collectors.toList());
|
|
|
- List<String> equipmentCodeList = deviceList.stream().map(EquipmentBaseOutDTO::getEquipmentCode).distinct().collect(Collectors.toList());
|
|
|
-
|
|
|
- // ============ 2. 批量查询设备类型名称 ============
|
|
|
- Map<Integer, String> typeNameMap = new HashMap<>();
|
|
|
- List<EquipmentType> equipmentTypeList = equipmentTypeMapper.selectList(
|
|
|
- new LambdaQueryWrapper<EquipmentType>().in(EquipmentType::getId, equipmentTypeIdsOf(deviceList)));
|
|
|
- if (CollUtil.isNotEmpty(equipmentTypeList)) {
|
|
|
- typeNameMap = equipmentTypeList.stream()
|
|
|
- .collect(Collectors.toMap(EquipmentType::getId, EquipmentType::getTypeName, (a, b) -> b));
|
|
|
- }
|
|
|
-
|
|
|
- // ============ 3. 批量查询设备运维状态 ============
|
|
|
- Map<String, EquipmentStatus> equipmentStatusMap = new HashMap<>();
|
|
|
- List<EquipmentStatus> equipmentStatusList = equipmentStatusMapper.selectList(
|
|
|
- new LambdaQueryWrapper<EquipmentStatus>().in(EquipmentStatus::getEquipmentId, equipmentIdList));
|
|
|
- if (CollUtil.isNotEmpty(equipmentStatusList)) {
|
|
|
- equipmentStatusMap = equipmentStatusList.stream()
|
|
|
- .collect(Collectors.toMap(EquipmentStatus::getEquipmentId, Function.identity(), (a, b) -> a));
|
|
|
- }
|
|
|
-
|
|
|
- // ============ 4. 批量查询最新 jg_device_data 记录 ============
|
|
|
- Map<String, List<ManholeData>> imeiDataMap = new HashMap<>();
|
|
|
- List<ManholeData> manholeDataList = manholeDataMapper.selectList(
|
|
|
- new LambdaQueryWrapper<ManholeData>()
|
|
|
- .in(ManholeData::getImeiCardNumber, equipmentCodeList)
|
|
|
- .orderByDesc(ManholeData::getCreateTime));
|
|
|
- if (CollUtil.isNotEmpty(manholeDataList)) {
|
|
|
- imeiDataMap = manholeDataList.stream().collect(Collectors.groupingBy(ManholeData::getImeiCardNumber));
|
|
|
- }
|
|
|
-
|
|
|
- // ============ 5. 批量查询未办结工单(待派单/待接单/已接单/处理中/待验收/延期审核) ============
|
|
|
- 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 = CollUtil.isNotEmpty(activeWorkOrders)
|
|
|
- ? activeWorkOrders.stream().map(WorkOrder::getDeviceId).collect(Collectors.toSet())
|
|
|
- : new HashSet<>();
|
|
|
-
|
|
|
- // ============ 6. 逐设备判定异常并组装 ============
|
|
|
- List<EquipmentBaseOutDTO> abnormalDeviceList = new ArrayList<>();
|
|
|
- int abnormalCount = 0, submittedCount = 0;
|
|
|
- Map<String, Integer> problemTypeMap = new LinkedHashMap<>();
|
|
|
- Map<String, int[]> districtStatMap = new LinkedHashMap<>();
|
|
|
-
|
|
|
- for (EquipmentBaseOutDTO out : deviceList) {
|
|
|
- // 设备类型名称
|
|
|
- String typeName = typeNameMap.get(out.getEquipmentTypeId());
|
|
|
- out.setEquipmentTypeName(typeName);
|
|
|
-
|
|
|
- // 设备运维状态
|
|
|
- EquipmentStatus equipmentStatus = equipmentStatusMap.get(out.getEquipmentId());
|
|
|
- if (equipmentStatus != null) {
|
|
|
- out.setEquipmentStatus(BeanUtil.copyProperties(equipmentStatus, EquipmentStatusOutDTO.class));
|
|
|
- }
|
|
|
- // 是否有未办结工单
|
|
|
- out.setWorkOrderSubmitted(deviceWithActiveOrder.contains(out.getEquipmentId()));
|
|
|
-
|
|
|
- // 最新监测数据
|
|
|
- ManholeData latest = null;
|
|
|
- List<ManholeData> dataList = imeiDataMap.get(out.getEquipmentCode());
|
|
|
- if (CollUtil.isNotEmpty(dataList)) {
|
|
|
- latest = dataList.get(0);
|
|
|
- out.setManholeData(BeanUtil.copyProperties(latest, ManholeDataOutDTO.class));
|
|
|
- }
|
|
|
-
|
|
|
- // 异常判定
|
|
|
- List<String> faultTypes = judgeFaultTypes(latest, equipmentStatus);
|
|
|
- boolean isAbnormal = CollUtil.isNotEmpty(faultTypes);
|
|
|
- if (isAbnormal) {
|
|
|
- abnormalCount++;
|
|
|
- if (Boolean.TRUE.equals(out.getWorkOrderSubmitted())) {
|
|
|
- submittedCount++;
|
|
|
- }
|
|
|
- // 问题类型分布
|
|
|
- for (String faultType : faultTypes) {
|
|
|
- problemTypeMap.merge(faultType, 1, Integer::sum);
|
|
|
- }
|
|
|
- abnormalDeviceList.add(out);
|
|
|
- }
|
|
|
- // 区域排行
|
|
|
- String district = out.getDistrict() != null ? DistrictEnum.getDescByCode(out.getDistrict()) : null;
|
|
|
- if (StringUtils.isBlank(district)) {
|
|
|
- district = "未分配";
|
|
|
- }
|
|
|
- int[] stat = districtStatMap.computeIfAbsent(district, k -> new int[2]);
|
|
|
- stat[0]++;
|
|
|
- if (isAbnormal) {
|
|
|
- stat[1]++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // ============ 7. KPI 指标 ============
|
|
|
- Map<String, Object> kpi = new LinkedHashMap<>();
|
|
|
- kpi.put("totalTerminal", equipmentList.size());
|
|
|
- kpi.put("abnormalTerminal", abnormalCount);
|
|
|
- kpi.put("abnormalRate", equipmentList.size() > 0 ? round1(abnormalCount * 100.0 / equipmentList.size()) : 0);
|
|
|
- kpi.put("submittedCount", submittedCount);
|
|
|
- kpi.put("solvedRate", abnormalCount > 0 ? round1(submittedCount * 100.0 / abnormalCount) : 0);
|
|
|
- // 工单统计(日期范围内)
|
|
|
- List<WorkOrder> rangeOrders = workOrderMapper.selectList(
|
|
|
- new LambdaQueryWrapper<WorkOrder>()
|
|
|
- .ge(WorkOrder::getCreateTime, startDate)
|
|
|
- .le(WorkOrder::getCreateTime, endDate));
|
|
|
- int totalCase = rangeOrders.size();
|
|
|
- long finishedCase = rangeOrders.stream().filter(o -> Integer.valueOf(6).equals(o.getOrderStatus())).count();
|
|
|
- long delayCase = rangeOrders.stream().filter(o -> Integer.valueOf(8).equals(o.getOrderStatus()) || Integer.valueOf(9).equals(o.getOrderStatus())).count();
|
|
|
- kpi.put("totalCase", totalCase);
|
|
|
- kpi.put("disposalRate", totalCase > 0 ? round1(finishedCase * 100.0 / totalCase) : 0);
|
|
|
- kpi.put("delayRate", totalCase > 0 ? round1(delayCase * 100.0 / totalCase) : 0);
|
|
|
- // 平均处置时长(已结案工单:实际完成时间-派单时间,小时)
|
|
|
- kpi.put("avgDisposalTime", calcAvgDisposalTime(rangeOrders));
|
|
|
- outDTO.setKpi(kpi);
|
|
|
-
|
|
|
- // ============ 8. 异常终端趋势(基于 jg_device_data 历史记录) ============
|
|
|
- outDTO.setAbnormalTerminalTrend(buildAbnormalTerminalTrend(equipmentCodeList, startDate, endDate, trendType));
|
|
|
-
|
|
|
- // ============ 9. 处置率/延期率趋势(基于 work_order) ============
|
|
|
- outDTO.setCaseRateTrend(buildCaseRateTrend(rangeOrders, startDate, endDate, trendType));
|
|
|
-
|
|
|
- // ============ 10. 问题类型分布 ============
|
|
|
- List<Map<String, Object>> problemTypeDistribution = new ArrayList<>();
|
|
|
- for (Map.Entry<String, Integer> entry : problemTypeMap.entrySet()) {
|
|
|
- Map<String, Object> item = new LinkedHashMap<>();
|
|
|
- item.put("name", entry.getKey());
|
|
|
- item.put("value", entry.getValue());
|
|
|
- problemTypeDistribution.add(item);
|
|
|
- }
|
|
|
- outDTO.setProblemTypeDistribution(problemTypeDistribution);
|
|
|
-
|
|
|
- // ============ 11. 区域排行 ============
|
|
|
- List<Map<String, Object>> regionRank = new ArrayList<>();
|
|
|
- for (Map.Entry<String, int[]> entry : districtStatMap.entrySet()) {
|
|
|
- Map<String, Object> item = new LinkedHashMap<>();
|
|
|
- item.put("name", entry.getKey());
|
|
|
- item.put("total", entry.getValue()[0]);
|
|
|
- item.put("abnormal", entry.getValue()[1]);
|
|
|
- regionRank.add(item);
|
|
|
- }
|
|
|
- regionRank.sort((a, b) -> ((Integer) b.get("abnormal")) - ((Integer) a.get("abnormal")));
|
|
|
- outDTO.setRegionRank(regionRank);
|
|
|
-
|
|
|
- // ============ 12. 异常终端列表 ============
|
|
|
- outDTO.setAbnormalDevices(abnormalDeviceList);
|
|
|
- return outDTO;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 异常判定:倾斜超标/水位超限/水浸报警/通讯故障/电池低电量(<=15)/信号弱(<=20)
|
|
|
- * 注意:equipmentStatus 为 null 时不判定通讯故障(用于历史记录趋势统计,无法获知当时在线状态)
|
|
|
- */
|
|
|
- private List<String> judgeFaultTypes(ManholeData data, EquipmentStatus equipmentStatus) {
|
|
|
- List<String> faultTypes = new ArrayList<>();
|
|
|
- boolean hasStatus = equipmentStatus != null;
|
|
|
- boolean online = hasStatus && Integer.valueOf(1).equals(equipmentStatus.getOnlineStatus());
|
|
|
- if (data == null) {
|
|
|
- // 无监测数据:有状态记录且不在线视为通讯故障,无状态记录也视为通讯故障
|
|
|
- if (!hasStatus || !online) {
|
|
|
- faultTypes.add("通讯故障");
|
|
|
- }
|
|
|
- return faultTypes;
|
|
|
- }
|
|
|
- if (hasStatus && !online) {
|
|
|
- faultTypes.add("通讯故障");
|
|
|
- }
|
|
|
- // 倾斜超标
|
|
|
- if (isOverThreshold(data.getTiltAngle(), data.getAngleAlarmThreshold())) {
|
|
|
- faultTypes.add("倾斜超标");
|
|
|
- }
|
|
|
- // 水位超限
|
|
|
- if ("1".equals(data.getWaterLevelAlarmStatus())) {
|
|
|
- faultTypes.add("水位超限");
|
|
|
- }
|
|
|
- // 水浸报警
|
|
|
- if ("1".equals(data.getWaterInfiltrationAlarmStatus())) {
|
|
|
- faultTypes.add("水浸报警");
|
|
|
- }
|
|
|
- // 电池低电量(<=15%)
|
|
|
- if (isNumberNotAbove(data.getBatteryLevel(), 15)) {
|
|
|
- faultTypes.add("电池低电量");
|
|
|
- }
|
|
|
- // 信号弱(<=20)
|
|
|
- if (isNumberNotAbove(data.getSignalStrength(), 20)) {
|
|
|
- faultTypes.add("信号弱");
|
|
|
- }
|
|
|
- return faultTypes;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数值字段超过阈值判定
|
|
|
- */
|
|
|
- private boolean isOverThreshold(String value, String threshold) {
|
|
|
- if (StringUtils.isBlank(value) || StringUtils.isBlank(threshold)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- try {
|
|
|
- return Double.parseDouble(value.trim()) > Double.parseDouble(threshold.trim());
|
|
|
- } catch (NumberFormatException ignored) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数值字段不大于阈值判定
|
|
|
- */
|
|
|
- private boolean isNumberNotAbove(String value, double maxValue) {
|
|
|
- if (StringUtils.isBlank(value)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- try {
|
|
|
- double v = Double.parseDouble(value.trim());
|
|
|
- return v > 0 && v <= maxValue;
|
|
|
- } catch (NumberFormatException ignored) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 平均处置时长:已结案工单 (realFinishTime - createTime) 平均小时
|
|
|
- * 注:派单时间(dispatch_time)已废弃,处置时长起点改用工单创建时间(createTime)。
|
|
|
- */
|
|
|
- private double calcAvgDisposalTime(List<WorkOrder> orders) {
|
|
|
- if (CollUtil.isEmpty(orders)) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- List<WorkOrder> finishedOrders = orders.stream()
|
|
|
- .filter(o -> Integer.valueOf(6).equals(o.getOrderStatus()))
|
|
|
- .filter(o -> o.getRealFinishTime() != null && o.getCreateTime() != null)
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (CollUtil.isEmpty(finishedOrders)) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- double totalHours = 0;
|
|
|
- for (WorkOrder order : finishedOrders) {
|
|
|
- long diffMillis = order.getRealFinishTime().getTime() - order.getCreateTime().getTime();
|
|
|
- totalHours += diffMillis / (1000.0 * 60 * 60);
|
|
|
- }
|
|
|
- return round1(totalHours / finishedOrders.size());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 异常终端趋势:按周度/月度分组统计 jg_device_data 历史记录中的异常设备去重数
|
|
|
- */
|
|
|
- private List<Map<String, Object>> buildAbnormalTerminalTrend(List<String> equipmentCodeList,
|
|
|
- Date startDate, Date endDate, int trendType) {
|
|
|
- List<Map<String, Object>> result = new ArrayList<>();
|
|
|
- if (CollUtil.isEmpty(equipmentCodeList)) {
|
|
|
- return result;
|
|
|
- }
|
|
|
- List<ManholeData> historyDataList = manholeDataMapper.selectList(
|
|
|
- new LambdaQueryWrapper<ManholeData>()
|
|
|
- .in(ManholeData::getImeiCardNumber, equipmentCodeList)
|
|
|
- .ge(ManholeData::getCreateTime, startDate)
|
|
|
- .le(ManholeData::getCreateTime, endDate)
|
|
|
- .orderByAsc(ManholeData::getCreateTime));
|
|
|
- if (CollUtil.isEmpty(historyDataList)) {
|
|
|
- return result;
|
|
|
- }
|
|
|
- Map<String, Set<String>> periodAbnormalDevices = new LinkedHashMap<>();
|
|
|
- Map<String, Set<String>> periodAllDevices = new LinkedHashMap<>();
|
|
|
- for (ManholeData data : historyDataList) {
|
|
|
- String periodKey = formatPeriodKey(data.getCreateTime(), trendType);
|
|
|
- if (periodKey == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- periodAllDevices.computeIfAbsent(periodKey, k -> new HashSet<>()).add(data.getImeiCardNumber());
|
|
|
- if (CollUtil.isNotEmpty(judgeFaultTypes(data, null))) {
|
|
|
- periodAbnormalDevices.computeIfAbsent(periodKey, k -> new HashSet<>()).add(data.getImeiCardNumber());
|
|
|
- }
|
|
|
- }
|
|
|
- for (Map.Entry<String, Set<String>> entry : periodAbnormalDevices.entrySet()) {
|
|
|
- Map<String, Object> item = new LinkedHashMap<>();
|
|
|
- item.put("trendLabel", entry.getKey());
|
|
|
- item.put("abnormalTerminal", entry.getValue().size());
|
|
|
- item.put("totalTerminal", periodAllDevices.getOrDefault(entry.getKey(), new HashSet<>()).size());
|
|
|
- result.add(item);
|
|
|
- }
|
|
|
- result.sort(Comparator.comparing(m -> String.valueOf(m.get("trendLabel"))));
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处置率/延期率趋势:按周度/月度分组统计工单
|
|
|
- */
|
|
|
- private List<Map<String, Object>> buildCaseRateTrend(List<WorkOrder> orders,
|
|
|
- Date startDate, Date endDate, int trendType) {
|
|
|
- List<Map<String, Object>> result = new ArrayList<>();
|
|
|
- if (CollUtil.isEmpty(orders)) {
|
|
|
- return result;
|
|
|
- }
|
|
|
- Map<String, List<WorkOrder>> periodGroup = new LinkedHashMap<>();
|
|
|
- for (WorkOrder order : orders) {
|
|
|
- String periodKey = formatPeriodKey(order.getCreateTime(), trendType);
|
|
|
- if (periodKey != null) {
|
|
|
- periodGroup.computeIfAbsent(periodKey, k -> new ArrayList<>()).add(order);
|
|
|
- }
|
|
|
- }
|
|
|
- for (Map.Entry<String, List<WorkOrder>> entry : periodGroup.entrySet()) {
|
|
|
- List<WorkOrder> periodOrders = entry.getValue();
|
|
|
- long finished = periodOrders.stream().filter(o -> Integer.valueOf(6).equals(o.getOrderStatus())).count();
|
|
|
- long delay = periodOrders.stream().filter(o -> Integer.valueOf(8).equals(o.getOrderStatus()) || Integer.valueOf(9).equals(o.getOrderStatus())).count();
|
|
|
- Map<String, Object> item = new LinkedHashMap<>();
|
|
|
- item.put("trendLabel", entry.getKey());
|
|
|
- item.put("caseDisposalRate", periodOrders.size() > 0 ? round1(finished * 100.0 / periodOrders.size()) : 0);
|
|
|
- item.put("caseDelayRate", periodOrders.size() > 0 ? round1(delay * 100.0 / periodOrders.size()) : 0);
|
|
|
- result.add(item);
|
|
|
- }
|
|
|
- result.sort(Comparator.comparing(m -> String.valueOf(m.get("trendLabel"))));
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 周期标签:周度 yyyy-Www / 月度 yyyy-MM
|
|
|
- */
|
|
|
- private String formatPeriodKey(Date date, int trendType) {
|
|
|
- if (date == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
- if (trendType == 1) {
|
|
|
- WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
|
|
- int weekYear = localDate.get(weekFields.weekBasedYear());
|
|
|
- int weekNum = localDate.get(weekFields.weekOfWeekBasedYear());
|
|
|
- return String.format("%d-W%02d", weekYear, weekNum);
|
|
|
- }
|
|
|
- return localDate.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设备类型ID列表(避免空集合导致SQL错误)
|
|
|
- */
|
|
|
- private List<Integer> equipmentTypeIdsOf(List<EquipmentBaseOutDTO> deviceList) {
|
|
|
- List<Integer> typeIds = deviceList.stream().map(EquipmentBaseOutDTO::getEquipmentTypeId)
|
|
|
- .filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
- return typeIds.isEmpty() ? Collections.singletonList(-1) : typeIds;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保留一位小数
|
|
|
- */
|
|
|
- private double round1(double value) {
|
|
|
- return Math.round(value * 10) / 10.0;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 空数据KPI
|
|
|
- */
|
|
|
- private Map<String, Object> buildEmptyKpi() {
|
|
|
- Map<String, Object> kpi = new LinkedHashMap<>();
|
|
|
- kpi.put("totalTerminal", 0);
|
|
|
- kpi.put("abnormalTerminal", 0);
|
|
|
- kpi.put("abnormalRate", 0);
|
|
|
- kpi.put("submittedCount", 0);
|
|
|
- kpi.put("solvedRate", 0);
|
|
|
- kpi.put("totalCase", 0);
|
|
|
- kpi.put("disposalRate", 0);
|
|
|
- kpi.put("delayRate", 0);
|
|
|
- kpi.put("avgDisposalTime", 0);
|
|
|
- return kpi;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 查询统计数据列表(公共方法)
|
|
|
- * @param inDTO
|
|
|
- * @return
|
|
|
*/
|
|
|
private List<MaintenanceDataStat> queryStatList(MaintenanceDataStatTrendInDTO inDTO) {
|
|
|
if(inDTO.getTrendType() == null){
|
|
|
@@ -581,9 +136,7 @@ public class MaintenanceDataStatServiceImpl extends ServiceImpl<MaintenanceDataS
|
|
|
|
|
|
/**
|
|
|
* 按周度/月度分组
|
|
|
- * @param statList
|
|
|
* @param trendType 1-周度 2-月度
|
|
|
- * @return
|
|
|
*/
|
|
|
private Map<String, List<MaintenanceDataStat>> groupByPeriod(List<MaintenanceDataStat> statList, Integer trendType) {
|
|
|
Map<String, List<MaintenanceDataStat>> groupedMap = new LinkedHashMap<>();
|
|
|
@@ -593,12 +146,10 @@ public class MaintenanceDataStatServiceImpl extends ServiceImpl<MaintenanceDataS
|
|
|
LocalDate localDate = stat.getStatDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
String key;
|
|
|
if(trendType == 1){
|
|
|
- // 周度:yyyy-Www
|
|
|
int weekYear = localDate.get(weekFields.weekBasedYear());
|
|
|
int weekNum = localDate.get(weekFields.weekOfWeekBasedYear());
|
|
|
key = String.format("%d-W%02d", weekYear, weekNum);
|
|
|
} else {
|
|
|
- // 月度:yyyy-MM
|
|
|
key = localDate.format(monthFormatter);
|
|
|
}
|
|
|
groupedMap.computeIfAbsent(key, k -> new ArrayList<>()).add(stat);
|