|
@@ -1,7 +1,11 @@
|
|
package com.ruoyi.qdtl.service.impl;
|
|
package com.ruoyi.qdtl.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.convert.Convert;
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
+import cn.hutool.core.date.DateField;
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
@@ -11,11 +15,17 @@ import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
-import com.ruoyi.qdtl.domain.TlElectricDevice;
|
|
|
|
-import com.ruoyi.qdtl.domain.TlElectricDeviceLocation;
|
|
|
|
|
|
+import com.ruoyi.qdtl.domain.*;
|
|
|
|
+import com.ruoyi.qdtl.mapper.TlInspectionLocationLogMapper;
|
|
|
|
+import com.ruoyi.qdtl.mapper.TlInspectionPlanMapper;
|
|
|
|
+import com.ruoyi.qdtl.mapper.TlPlanRecordMapper;
|
|
import com.ruoyi.qdtl.service.IQdCommonService;
|
|
import com.ruoyi.qdtl.service.IQdCommonService;
|
|
|
|
+import com.ruoyi.qdtl.service.ITlAreaService;
|
|
import com.ruoyi.qdtl.service.ITlInspectionDeviceService;
|
|
import com.ruoyi.qdtl.service.ITlInspectionDeviceService;
|
|
|
|
+import com.ruoyi.qdtl.service.ITlInspectionLineLocationService;
|
|
|
|
+import com.ruoyi.qdtl.service.ITlInspectionLineService;
|
|
import com.ruoyi.qdtl.service.ITlInspectionLocationService;
|
|
import com.ruoyi.qdtl.service.ITlInspectionLocationService;
|
|
|
|
+import com.ruoyi.qdtl.service.ITlInspectionPlanService;
|
|
import com.ruoyi.qdtl.service.ITlPatrolmanService;
|
|
import com.ruoyi.qdtl.service.ITlPatrolmanService;
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -23,10 +33,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: TODO
|
|
* @Description: TODO
|
|
@@ -61,6 +75,20 @@ public class QdCommonServiceImpl implements IQdCommonService {
|
|
private ITlInspectionDeviceService tlInspectionDeviceService;
|
|
private ITlInspectionDeviceService tlInspectionDeviceService;
|
|
@Autowired
|
|
@Autowired
|
|
private ITlPatrolmanService tlPatrolmanService;
|
|
private ITlPatrolmanService tlPatrolmanService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITlInspectionPlanService inspectionPlanService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITlInspectionLineLocationService inspectionLineLocationService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITlInspectionLineService inspectionLineService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TlInspectionPlanMapper tlInspectionPlanMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TlInspectionLocationLogMapper tlInspectionLocationLogMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TlPlanRecordMapper planRecordMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITlAreaService areaService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取巡检接口的token
|
|
* 获取巡检接口的token
|
|
@@ -298,5 +326,82 @@ public class QdCommonServiceImpl implements IQdCommonService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> monthStatic(Long areaId, String startDate, String endDate) {
|
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ // 查询所有的线路点位
|
|
|
|
+ List<TlInspectionLineLocation> lineLocations = inspectionLineLocationService.selectTlInspectionLineLocationList(new TlInspectionLineLocation());
|
|
|
|
+ Map<Long, List<TlInspectionLineLocation>> lineLocationsCollect = lineLocations.stream().collect(Collectors.groupingBy(TlInspectionLineLocation::getLineId));
|
|
|
|
+ // 查询线路数据
|
|
|
|
+ TlInspectionLine line = new TlInspectionLine();
|
|
|
|
+ line.setAreaId(areaId);
|
|
|
|
+ List<TlInspectionLine> lines = inspectionLineService.selectTlInspectionLineList(line);
|
|
|
|
+ for (TlInspectionLine tlInspectionLine : lines) {
|
|
|
|
+ tlInspectionLine.setLineLocations(lineLocationsCollect.getOrDefault(tlInspectionLine.getId(), new ArrayList<>()));
|
|
|
|
+ }
|
|
|
|
+ Map<Long, Integer> LineLocationCount = lines.stream().collect(Collectors.toMap(TlInspectionLine::getId, a -> a.getLineLocations().size()));
|
|
|
|
+ // 查询计划相关
|
|
|
|
+ List<TlInspectionPlan> list = tlInspectionPlanMapper.queryByDatePeriod(startDate, endDate);
|
|
|
|
+ List<DateTime> dateTimes = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR);
|
|
|
|
+ // 查询areaId对应我爱巡后台是哪个区域
|
|
|
|
+ String areaName = "";
|
|
|
|
+ if (ObjectUtil.isNotEmpty(areaId)) {
|
|
|
|
+ TlArea tlArea = areaService.selectTlAreaById(areaId);
|
|
|
|
+ if (tlArea != null) {
|
|
|
|
+ areaName = tlArea.getAreaName();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查询巡更记录表
|
|
|
|
+ List<TlInspectionLocationLog> locationLogList = tlInspectionLocationLogMapper.queryDistanceByDateRange(areaName, startDate, endDate);
|
|
|
|
+ Map<String, Long> locationLogCollectCount = locationLogList.stream().collect(Collectors.groupingBy(a -> DateUtil.formatDate(a.getCreateTime()), Collectors.counting()));
|
|
|
|
+ // 查询计划中的数据
|
|
|
|
+ List<TlPlanRecord> planRecords = planRecordMapper.selectTlPlanRecordListByDatePeriod(areaId, startDate, endDate);
|
|
|
|
+ Map<String, Long> unPlanRecordsCollect = planRecords.stream().filter(a -> StrUtil.isBlank(a.getFence())).collect(Collectors.groupingBy(TlPlanRecord::getPlanDate, Collectors.counting()));
|
|
|
|
+ Map<String, Long> planRecordsCollect = planRecords.stream().collect(Collectors.groupingBy(TlPlanRecord::getPlanDate, Collectors.counting()));
|
|
|
|
+
|
|
|
|
+ List<XunStaticMonth> result = new ArrayList<>();
|
|
|
|
+ for (DateTime existTime : dateTimes) {
|
|
|
|
+ XunStaticMonth xunStaticMonth = new XunStaticMonth();
|
|
|
|
+ // 计划巡更点总数
|
|
|
|
+ int planLocationTotal = 0;
|
|
|
|
+ for (TlInspectionPlan inspectionPlan : list) {
|
|
|
|
+ // 每一个计划所有的日期
|
|
|
|
+ String weeks = inspectionPlan.getWeeks();
|
|
|
|
+ int week = DateUtil.dayOfWeek(existTime);
|
|
|
|
+ if (CollUtil.contains(StrUtil.split(weeks, ","), Convert.toStr(week))) {
|
|
|
|
+ // 计划巡更点数
|
|
|
|
+ planLocationTotal += inspectionPlan.getXunNum() * LineLocationCount.getOrDefault(inspectionPlan.getLineId(), 0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ xunStaticMonth.setStaticDate(DateUtil.formatDate(existTime));
|
|
|
|
+ xunStaticMonth.setPlanLocationTotal(planLocationTotal);
|
|
|
|
+ xunStaticMonth.setActualXunTotal(locationLogCollectCount.getOrDefault(DateUtil.formatDate(existTime), 0L));
|
|
|
|
+ xunStaticMonth.setUnXunTotal(unPlanRecordsCollect.getOrDefault(DateUtil.formatDate(existTime), 0L));
|
|
|
|
+ Long xun = planRecordsCollect.getOrDefault(DateUtil.formatDate(existTime), 0L);
|
|
|
|
+ xunStaticMonth.setXunTotal(xun);
|
|
|
|
+ xunStaticMonth.setUnXunPercent(xun == 0L ? new BigDecimal(0) : NumberUtil.mul(NumberUtil.div(xunStaticMonth.getUnXunTotal(), xun, 4), 100));
|
|
|
|
+ result.add(xunStaticMonth);
|
|
|
|
+ }
|
|
|
|
+ data.put("xunList", result);
|
|
|
|
+ // 本月计划巡更点总数
|
|
|
|
+ Integer planXunLocationTotal = result.stream().mapToInt(XunStaticMonth::getPlanLocationTotal).sum();
|
|
|
|
+ data.put("planXunLocationTotal", planXunLocationTotal);
|
|
|
|
+ // 本月漏巡更点总数
|
|
|
|
+ int unXunTotal = result.stream().mapToInt(a -> Convert.toInt(a.getUnXunTotal())).sum();
|
|
|
|
+ data.put("unXunTotal", unXunTotal);
|
|
|
|
+ // 本月已巡更点总数
|
|
|
|
+ int actualXunTotal = result.stream().mapToInt(a -> Convert.toInt(a.getActualXunTotal())).sum();
|
|
|
|
+ data.put("actualXunTotal", actualXunTotal);
|
|
|
|
+ // 本月未巡更点总数
|
|
|
|
+ int weiXun = result.stream().filter(a -> DateUtil.compare(new Date(), DateUtil.parseDate(a.getStaticDate())) < 0).mapToInt(XunStaticMonth::getPlanLocationTotal).sum();
|
|
|
|
+ data.put("weiXun", weiXun);
|
|
|
|
+ // 本月漏巡率
|
|
|
|
+ int xunTotal = result.stream().mapToInt(a -> Convert.toInt(a.getXunTotal())).sum();
|
|
|
|
+ double unPercent = (xunTotal == 0) ? (double) 0 : NumberUtil.mul(NumberUtil.div(unXunTotal, xunTotal, 4), 100);
|
|
|
|
+ data.put("unPercent", unPercent);
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|