|
@@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.DeviceHistoryParam;
|
|
|
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.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;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.OrderVo;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO;
|
|
@@ -29,6 +30,7 @@ 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.iotmainworkorder.IotMainWorkOrderMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotsapstock.IotSapStockMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.maintain.IotMaintainMapper;
|
|
|
import cn.iocoder.yudao.module.pms.service.DeviceServiceImpl;
|
|
@@ -57,14 +59,17 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.annotation.security.PermitAll;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.io.Serializable;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
-import static cn.iocoder.yudao.framework.common.util.date.DateUtils.getLastYearMonthRanges;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
|
|
|
|
|
@Tag(name = "统计接口")
|
|
|
@RestController
|
|
@@ -103,6 +108,8 @@ public class IotStaticController {
|
|
|
private IotInspectOrderDetailMapper iotInspectOrderDetailMapper;
|
|
|
@Autowired
|
|
|
private DeptService deptService;
|
|
|
+ @Autowired
|
|
|
+ private IotOpeationFillMapper iotOpeationFillMapper;
|
|
|
|
|
|
@GetMapping("/main/day")
|
|
|
public CommonResult<Map<String, Object>> getMaintainDay() {
|
|
@@ -521,4 +528,136 @@ public class IotStaticController {
|
|
|
});
|
|
|
return success(ImmutableMap.of("todo", todo.get(),"finished", finished.get()));
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/rh/order")
|
|
|
+ @PermitAll
|
|
|
+ public CommonResult<Map<String, Object>> getOrderNumberStat() {
|
|
|
+ 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};
|
|
|
+
|
|
|
+ IotOpeationFillPageReqVO iotOpeationFillPageReqVO = new IotOpeationFillPageReqVO();
|
|
|
+ iotOpeationFillPageReqVO.setCreateTime(createTime);
|
|
|
+ List<Map<String, Object>> fills = iotOpeationFillMapper.selectListByCreateTime(iotOpeationFillPageReqVO).stream().map(e -> {
|
|
|
+ Map<String, Object> abc = new HashMap<>();
|
|
|
+ abc.put("id", e.getId());
|
|
|
+ abc.put("createTime", e.getCreateTime());
|
|
|
+ return abc;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Map<String, Long> fillMap = countRecordsByDate(fills, 7);
|
|
|
+ LinkedList<Object> xAxis = new LinkedList<>();
|
|
|
+ LinkedList<Object> fillData = new LinkedList<>();
|
|
|
+ fillMap.forEach( (k,v)->{
|
|
|
+ xAxis.add(k);
|
|
|
+ fillData.add(v);
|
|
|
+ });
|
|
|
+
|
|
|
+ IotMaintainPageReqVO iotMaintainPageReqVO = new IotMaintainPageReqVO();
|
|
|
+ iotMaintainPageReqVO.setCreateTime(createTime);
|
|
|
+ List<Map<String, Object>> maintains = iotMaintainMapper.selectListByCreateTime(iotMaintainPageReqVO).stream().map(e -> {
|
|
|
+ Map<String, Object> abc = new HashMap<>();
|
|
|
+ abc.put("id", e.getId());
|
|
|
+ abc.put("createTime", e.getCreateTime());
|
|
|
+ return abc;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Map<String, Long> maintainMap = countRecordsByDate(maintains, 7);
|
|
|
+ LinkedList<Object> maintainData = new LinkedList<>();
|
|
|
+ maintainMap.forEach( (k,v)->{
|
|
|
+ maintainData.add(v);
|
|
|
+ });
|
|
|
+
|
|
|
+ IotMainWorkOrderPageReqVO iotMainWorkOrderPageReqVO = new IotMainWorkOrderPageReqVO();
|
|
|
+ iotMainWorkOrderPageReqVO.setCreateTime(createTime);
|
|
|
+ List<Map<String, Object>> works = iotMainWorkOrderMapper.selectListByCreateTime(iotMainWorkOrderPageReqVO).stream().map(e -> {
|
|
|
+ Map<String, Object> abc = new HashMap<>();
|
|
|
+ abc.put("id", e.getId());
|
|
|
+ abc.put("createTime", e.getCreateTime());
|
|
|
+ return abc;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Map<String, Long> workMap = countRecordsByDate(works, 7);
|
|
|
+ LinkedList<Object> workData = new LinkedList<>();
|
|
|
+ workMap.forEach( (k,v)->{
|
|
|
+ workData.add(v);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ IotInspectOrderPageReqVO iotInspectOrderPageReqVO = new IotInspectOrderPageReqVO();
|
|
|
+ iotInspectOrderPageReqVO.setCreateTime(createTime);
|
|
|
+ List<Map<String, Object>> inspects = iotInspectOrderMapper.selectListByCreateTime(iotInspectOrderPageReqVO).stream().map(e -> {
|
|
|
+ Map<String, Object> abc = new HashMap<>();
|
|
|
+ abc.put("id", e.getId());
|
|
|
+ abc.put("createTime", e.getCreateTime());
|
|
|
+ return abc;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Map<String, Long> inspectMap = countRecordsByDate(inspects, 7);
|
|
|
+ LinkedList<Object> inspectData = new LinkedList<>();
|
|
|
+ inspectMap.forEach( (k,v)->{
|
|
|
+ inspectData.add(v);
|
|
|
+ });
|
|
|
+
|
|
|
+ ImmutableMap<String, Serializable> maintainResult = ImmutableMap.of("name", "维修工单", "data", maintainData);
|
|
|
+ ImmutableMap<String, Serializable> workResult = ImmutableMap.of("name", "保养工单", "data", workData);
|
|
|
+ ImmutableMap<String, Serializable> inspectResult = ImmutableMap.of("name", "巡检工单", "data", inspectData);
|
|
|
+ ImmutableMap<String, Serializable> fillResult = ImmutableMap.of("name", "运行记录", "data", fillData);
|
|
|
+ return success(ImmutableMap.of("xAxis", xAxis, "series", ImmutableList.of(maintainResult, workResult,inspectResult, fillResult)));
|
|
|
+// for (String lastSevenDay : lastSevenDays) {
|
|
|
+// // 转换为LocalDateTime
|
|
|
+// LocalDateTime startOfDay = getStartOfDay(lastSevenDay);
|
|
|
+// LocalDateTime endOfDay = getEndOfDay(lastSevenDay);
|
|
|
+// IotMaintainPageReqVO iotMaintainPageReqVO = new IotMaintainPageReqVO();
|
|
|
+// LocalDateTime[] createTime = new LocalDateTime[]{startOfDay, endOfDay};
|
|
|
+// iotMaintainPageReqVO.setCreateTime(createTime);
|
|
|
+// Long maintainCount = iotMaintainMapper.selectCountByTimeAndStatus(iotMaintainPageReqVO);
|
|
|
+// maintain.add(maintainCount);
|
|
|
+// IotMainWorkOrderPageReqVO iotMainWorkOrderPageReqVO = new IotMainWorkOrderPageReqVO();
|
|
|
+// iotMainWorkOrderPageReqVO.setCreateTime(createTime);
|
|
|
+// Long workOrderCount = iotMainWorkOrderMapper.selectCountByTimeAndStatus(iotMainWorkOrderPageReqVO);
|
|
|
+// workorder.add(workOrderCount);
|
|
|
+// IotInspectOrderPageReqVO iotInspectOrderPageReqVO = new IotInspectOrderPageReqVO();
|
|
|
+// iotInspectOrderPageReqVO.setCreateTime(createTime);
|
|
|
+// Long inspectCount = iotInspectOrderMapper.selectCountByTimeAndStatus(iotInspectOrderPageReqVO);
|
|
|
+// inspect.add(inspectCount);
|
|
|
+// }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Map<String, Long> countRecordsByDate(List<Map<String, Object>> records, int days) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+
|
|
|
+ // 生成近七天的日期列表
|
|
|
+ Map<String, Long> dateMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < days; i++) {
|
|
|
+ LocalDate date = today.minusDays(i);
|
|
|
+ dateMap.put(date.format(formatter), 0L);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 统计每天的记录数量
|
|
|
+ Map<String, Long> countMap = records.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ record -> {
|
|
|
+ try {
|
|
|
+ // 提取日期部分
|
|
|
+ return String.valueOf(record.get("createTime")).substring(0, 10);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("日期格式错误: " + record.get("createTime"));
|
|
|
+ return "invalid_date";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ Collectors.counting()
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 合并两个映射,确保所有日期都存在
|
|
|
+ dateMap.forEach((date, count) -> {
|
|
|
+ if (countMap.containsKey(date)) {
|
|
|
+ dateMap.put(date, countMap.get(date));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return dateMap;
|
|
|
+ }
|
|
|
}
|
|
|
+
|