|
@@ -2,11 +2,13 @@ package cn.iocoder.yudao.module.pms.controller.admin.stat;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.Pms;
|
|
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.failure.vo.IotFailureReportPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.inspect.order.vo.IotInspectOrderPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainWorkOrderPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.IotOpeationFillPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
|
|
@@ -28,6 +30,7 @@ import cn.iocoder.yudao.module.pms.dal.mysql.TDDeviceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.failure.IotFailureReportMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.inspect.IotInspectOrderDetailMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.inspect.IotInspectOrderMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotdevicerunlog.IotDeviceRunLogMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotmainworkorder.IotMainWorkOrderMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotsapstock.IotSapStockMapper;
|
|
@@ -56,7 +59,6 @@ import javax.annotation.Resource;
|
|
|
import javax.annotation.security.PermitAll;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.Serializable;
|
|
|
-import java.sql.Array;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -107,6 +109,8 @@ public class IotStaticController {
|
|
|
private DeptService deptService;
|
|
|
@Autowired
|
|
|
private IotOpeationFillMapper iotOpeationFillMapper;
|
|
|
+ @Autowired
|
|
|
+ private IotDeviceRunLogMapper iotDeviceRunLogMapper;
|
|
|
|
|
|
@GetMapping("/main/day")
|
|
|
public CommonResult<Map<String, Object>> getMaintainDay() {
|
|
@@ -661,6 +665,59 @@ public class IotStaticController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public static LinkedHashMap<String, Long> sumTotalByDate(List<Map<String, Object>> records, int days, String key) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+
|
|
|
+ // 生成近days天的日期列表,初始值为0
|
|
|
+ LinkedHashMap<String, Long> dateMap = new LinkedHashMap<>();
|
|
|
+ for (int i = days - 1; i >= 0; i--) {
|
|
|
+ LocalDate date = today.minusDays(i);
|
|
|
+ dateMap.put(date.format(formatter), 0L);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统计每天的total字段之和
|
|
|
+ Map<String, Long> sumMap = records.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ record -> {
|
|
|
+ try {
|
|
|
+ // 提取日期部分(假设createTime格式为yyyy-MM-dd...)
|
|
|
+ return String.valueOf(record.get("createTime")).substring(0, 10);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("日期格式错误: " + record.get("createTime"));
|
|
|
+ return "invalid_date";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 累加每天的total字段值,处理可能的格式问题
|
|
|
+ Collectors.summingLong(record -> {
|
|
|
+ try {
|
|
|
+ Object totalObj = record.get(key);
|
|
|
+ if (totalObj instanceof Number) {
|
|
|
+ return ((Number) totalObj).longValue();
|
|
|
+ } else if (totalObj instanceof String) {
|
|
|
+ return Long.parseLong((String) totalObj);
|
|
|
+ } else {
|
|
|
+ System.err.println("total字段格式错误: " + totalObj);
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("处理total字段出错: " + e.getMessage());
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 合并结果,确保所有日期都在返回结果中
|
|
|
+ dateMap.forEach((date, sum) -> {
|
|
|
+ if (sumMap.containsKey(date)) {
|
|
|
+ dateMap.put(date, sumMap.get(date));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return dateMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static LinkedHashMap<String, Long> countRecordsByDate(List<Map<String, Object>> records, int days) {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
LocalDate today = LocalDate.now();
|
|
@@ -696,5 +753,76 @@ public class IotStaticController {
|
|
|
|
|
|
return dateMap;
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/rh/zql/{dept}")
|
|
|
+ @PermitAll
|
|
|
+ public CommonResult<Map<String, Object>> rhOrder(@PathVariable("dept") String dept) {
|
|
|
+ Set<Long> ids = getDeptIds(dept);
|
|
|
+ List<String> lastSevenDays = DateUtils.getLastSevenDays();
|
|
|
+ String first = lastSevenDays.get(0);
|
|
|
+ String last = lastSevenDays.get(lastSevenDays.size() - 1);
|
|
|
+ LocalDateTime startOfDay = getStartOfDay(first);
|
|
|
+ LocalDateTime endOfDay = getEndOfDay(last);
|
|
|
+ LocalDateTime[] createTime = new LocalDateTime[]{endOfDay, startOfDay};
|
|
|
+
|
|
|
+ IotDeviceRunLogPageReqVO iotDeviceRunLogPageReqVO = new IotDeviceRunLogPageReqVO();
|
|
|
+ iotDeviceRunLogPageReqVO.setCreateTime(createTime);
|
|
|
+ iotDeviceRunLogPageReqVO.setDeptIds(new ArrayList<>(ids));
|
|
|
+ iotDeviceRunLogPageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ List<Map<String, Object>> fills = iotDeviceRunLogMapper.selectListByCreateTimeAndDeptList(iotDeviceRunLogPageReqVO).stream().filter(e -> "累计注气量".equals(e.getPointName())).map(e -> {
|
|
|
+ Map<String, Object> abc = new HashMap<>();
|
|
|
+ abc.put("id", e.getId());
|
|
|
+ abc.put("createTime", e.getCreateTime());
|
|
|
+ abc.put("total", e.getTotalRunTime());
|
|
|
+ abc.put("today", e.getFillContent());
|
|
|
+ return abc;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ LinkedHashMap<String, Long> fillMap = sumTotalByDate(fills, 7,"total");
|
|
|
+ LinkedList<Object> xAxis = new LinkedList<>();
|
|
|
+ LinkedList<Object> fillData = new LinkedList<>();
|
|
|
+ fillMap.forEach( (k,v)->{
|
|
|
+ xAxis.add(k);
|
|
|
+ fillData.add(v);
|
|
|
+ });
|
|
|
+
|
|
|
+ ImmutableMap<String, Serializable> fillResult = ImmutableMap.of("name", "累计注气量", "data", fillData);
|
|
|
+ return success(ImmutableMap.of("xAxis", xAxis, "series", ImmutableList.of(fillResult)));
|
|
|
+
|
|
|
+ }
|
|
|
+ @GetMapping("/rh/zql/today/{dept}")
|
|
|
+ @PermitAll
|
|
|
+ public CommonResult<Map<String, Object>> rhOrderToday(@PathVariable("dept") String dept) {
|
|
|
+ Set<Long> ids = getDeptIds(dept);
|
|
|
+ List<String> lastSevenDays = DateUtils.getLastSevenDays();
|
|
|
+ String first = lastSevenDays.get(0);
|
|
|
+ String last = lastSevenDays.get(lastSevenDays.size() - 1);
|
|
|
+ LocalDateTime startOfDay = getStartOfDay(first);
|
|
|
+ LocalDateTime endOfDay = getEndOfDay(last);
|
|
|
+ LocalDateTime[] createTime = new LocalDateTime[]{endOfDay, startOfDay};
|
|
|
+
|
|
|
+ IotDeviceRunLogPageReqVO iotDeviceRunLogPageReqVO = new IotDeviceRunLogPageReqVO();
|
|
|
+ iotDeviceRunLogPageReqVO.setCreateTime(createTime);
|
|
|
+ iotDeviceRunLogPageReqVO.setDeptIds(new ArrayList<>(ids));
|
|
|
+ iotDeviceRunLogPageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ List<Map<String, Object>> fills = iotDeviceRunLogMapper.selectListByCreateTimeAndDeptList(iotDeviceRunLogPageReqVO).stream().filter(e -> "当日注气量".equals(e.getPointName())).map(e -> {
|
|
|
+ Map<String, Object> abc = new HashMap<>();
|
|
|
+ abc.put("id", e.getId());
|
|
|
+ abc.put("createTime", e.getCreateTime());
|
|
|
+ abc.put("total", e.getTotalRunTime());
|
|
|
+ abc.put("today", e.getFillContent());
|
|
|
+ return abc;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ LinkedHashMap<String, Long> fillMap = sumTotalByDate(fills, 7,"today");
|
|
|
+ LinkedList<Object> xAxis = new LinkedList<>();
|
|
|
+ LinkedList<Object> fillData = new LinkedList<>();
|
|
|
+ fillMap.forEach( (k,v)->{
|
|
|
+ xAxis.add(k);
|
|
|
+ fillData.add(v);
|
|
|
+ });
|
|
|
+
|
|
|
+ ImmutableMap<String, Serializable> fillResult = ImmutableMap.of("name", "当日注气量", "data", fillData);
|
|
|
+ return success(ImmutableMap.of("xAxis", xAxis, "series", ImmutableList.of(fillResult)));
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|