|
|
@@ -825,7 +825,7 @@ public class IotStaticController {
|
|
|
@PermitAll
|
|
|
public CommonResult<Map<String, Object>> getRhYwcbStat(@PathVariable("dept") String dept) {
|
|
|
Set<Long> ids = getDeptIds(dept);
|
|
|
- List<String> lastSevenDays = getLastSevenDays();
|
|
|
+ List<String> lastSevenDays = lastSevenDaysWithoutToday();
|
|
|
String first = lastSevenDays.get(0);
|
|
|
String last = lastSevenDays.get(lastSevenDays.size() - 1);
|
|
|
LocalDateTime startOfDay = getStartOfDay(last);
|
|
|
@@ -845,7 +845,6 @@ public class IotStaticController {
|
|
|
workOrderReqVO.setCreateTime(createTime);
|
|
|
List<IotMainWorkOrderDO> workOrders = iotMainWorkOrderService.workOrders(workOrderReqVO);
|
|
|
LinkedHashMap<String, Long> byOutMap = countBycbByDate(workOrders, 7);
|
|
|
-// LinkedHashMap<String, Long> outMap = countYwcbByDate(outs, 7);
|
|
|
LinkedList<Object> xAxis = new LinkedList<>();
|
|
|
LinkedList<Object> outData = new LinkedList<>();
|
|
|
repairMap.forEach( (k,v)->{
|
|
|
@@ -1086,73 +1085,41 @@ public class IotStaticController {
|
|
|
|
|
|
public static LinkedHashMap<String, Long> countBycbByDate(List<IotMainWorkOrderDO> records, int days) {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
-
|
|
|
- // 生成近七天的日期列表
|
|
|
- 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);
|
|
|
- }
|
|
|
+ // 基准日期为昨天,往前推 days 天
|
|
|
+ LocalDate baseDate = LocalDate.now().minusDays(1);
|
|
|
|
|
|
Map<String, Long> amountMap = records.stream()
|
|
|
+ .filter(r -> r.getCreateTime() != null)
|
|
|
.collect(Collectors.groupingBy(
|
|
|
- record -> {
|
|
|
- try {
|
|
|
- // 提取日期部分(假设createTime是类似"yyyy-MM-ddHH:mm:ss"的字符串)
|
|
|
- return String.valueOf(record.getCreateTime()).substring(0, 10);
|
|
|
- } catch (Exception e) {
|
|
|
- System.err.println("日期格式错误: " + record.getCreateTime());
|
|
|
- return "invalid_date";
|
|
|
- }
|
|
|
- },
|
|
|
- // 对每个分组计算金额总和:quantity * price累加
|
|
|
- Collectors.summingLong(record -> record.getCost().longValue())
|
|
|
+ r -> String.valueOf(r.getCreateTime()).substring(0, 10),
|
|
|
+ Collectors.summingLong(r -> Objects.isNull(r.getCost()) ? 0L : r.getCost().longValue())
|
|
|
));
|
|
|
|
|
|
- // 合并两个映射,确保所有日期都存在
|
|
|
- dateMap.forEach((date, count) -> {
|
|
|
- if (amountMap.containsKey(date)) {
|
|
|
- dateMap.put(date, amountMap.get(date));
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
+ LinkedHashMap<String, Long> dateMap = new LinkedHashMap<>();
|
|
|
+ for (int i = days - 1; i >= 0; i--) {
|
|
|
+ String date = baseDate.minusDays(i).format(formatter);
|
|
|
+ dateMap.put(date, amountMap.getOrDefault(date, 0L));
|
|
|
+ }
|
|
|
return dateMap;
|
|
|
}
|
|
|
|
|
|
public static LinkedHashMap<String, Long> countWxcbByDate(List<IotMaintainDO> records, int days) {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
-
|
|
|
- // 生成近七天的日期列表
|
|
|
- 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);
|
|
|
- }
|
|
|
+ // 基准日期为昨天,往前推 days 天
|
|
|
+ LocalDate baseDate = LocalDate.now().minusDays(1);
|
|
|
|
|
|
Map<String, Long> amountMap = records.stream()
|
|
|
+ .filter(r -> r.getCreateTime() != null)
|
|
|
.collect(Collectors.groupingBy(
|
|
|
- record -> {
|
|
|
- try {
|
|
|
- // 提取日期部分(假设createTime是类似"yyyy-MM-ddHH:mm:ss"的字符串)
|
|
|
- return String.valueOf(record.getCreateTime()).substring(0, 10);
|
|
|
- } catch (Exception e) {
|
|
|
- System.err.println("日期格式错误: " + record.getCreateTime());
|
|
|
- return "invalid_date";
|
|
|
- }
|
|
|
- },
|
|
|
- // 对每个分组计算金额总和:quantity * price累加
|
|
|
- Collectors.summingLong(record -> Objects.isNull(record.getMaintainFee())?0L:record.getMaintainFee().longValue())
|
|
|
+ r -> String.valueOf(r.getCreateTime()).substring(0, 10),
|
|
|
+ Collectors.summingLong(r -> Objects.isNull(r.getMaintainFee()) ? 0L : r.getMaintainFee().longValue())
|
|
|
));
|
|
|
|
|
|
- // 合并两个映射,确保所有日期都存在
|
|
|
- dateMap.forEach((date, count) -> {
|
|
|
- if (amountMap.containsKey(date)) {
|
|
|
- dateMap.put(date, amountMap.get(date));
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
+ LinkedHashMap<String, Long> dateMap = new LinkedHashMap<>();
|
|
|
+ for (int i = days - 1; i >= 0; i--) {
|
|
|
+ String date = baseDate.minusDays(i).format(formatter);
|
|
|
+ dateMap.put(date, amountMap.getOrDefault(date, 0L));
|
|
|
+ }
|
|
|
return dateMap;
|
|
|
}
|
|
|
public static LinkedHashMap<String, Long> countRecordsByDate(List<Map<String, Object>> records, int days) {
|