Parcourir la source

统一车辆运行看板接口跟班次工作台的统计逻辑

lingpeng.li il y a 2 mois
Parent
commit
8e46be3f3c

+ 0 - 1
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/controller/StorageBillController.java

@@ -159,7 +159,6 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 		List<StorageBill> filteredRecords = allRecords.stream()
 				.peek(bill -> bill.setAmountTotal(
 						bill.getAmountTotal() + billetCountMap.getOrDefault(bill.getId(), 0L).intValue()))
-				.filter(bill -> bill.getOutTime() == null || bill.getAmountTotal() > 0) // 仅当 outTime 非空时过滤 0
 				.collect(Collectors.toList());
 
 		// 5. **一次性查询所有 `BilletBasicInfo`,避免循环查询**

+ 11 - 157
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/service/impl/StorageBillServiceImpl.java

@@ -3094,17 +3094,14 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
             steelDetailsVo.setRollClubOneDetailsList(rollClubOneDetailsList);
         }
 
-        // 根据铸机号、班组、班别、时间范围。查询棒二明细表
+        // 根据铸机号、装运单id集合或时间范围。查询棒二明细表
         LambdaQueryWrapper<RollClubTwoDetails> queryWrapper2 = new LambdaQueryWrapper<>();
         if (idList != null && !idList.isEmpty()) {
             queryWrapper2.eq(RollClubTwoDetails::getCcmNo, ccmNo)
-                    .eq(RollClubTwoDetails::getShift, shift)
-                    .eq(RollClubTwoDetails::getShiftGroup, shiftGroup)
                     .in(RollClubTwoDetails::getStorageBillId, idList);
         } else {
             queryWrapper2.eq(RollClubTwoDetails::getCcmNo, ccmNo)
-                    .eq(RollClubTwoDetails::getShift, shift)
-                    .eq(RollClubTwoDetails::getShiftGroup, shiftGroup);
+                    .between(RollClubTwoDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
         }
 
         List<RollClubTwoDetails> rollClubTwoDetailsList = rollClubTwoDetailsService.list(queryWrapper2);
@@ -3114,17 +3111,14 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
 
         }
 
-        // 根据铸机号、班组、班别、时间范围。查询棒三明细表
+        // 根据铸机号、装运单id集合或时间范围。查询棒三明细表
         LambdaQueryWrapper<RollClubThreeDetails> queryWrapper3 = new LambdaQueryWrapper<>();
         if (idList != null && !idList.isEmpty()) {
             queryWrapper3.eq(RollClubThreeDetails::getCcmNo, ccmNo)
-                    .eq(RollClubThreeDetails::getShift, shift)
-                    .eq(RollClubThreeDetails::getShiftGroup, shiftGroup)
                     .in(RollClubThreeDetails::getStorageBillId, idList);
         } else {
             queryWrapper3.eq(RollClubThreeDetails::getCcmNo, ccmNo)
-                    .eq(RollClubThreeDetails::getShift, shift)
-                    .eq(RollClubThreeDetails::getShiftGroup, shiftGroup);
+                    .between(RollClubThreeDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
         }
 
 
@@ -3147,17 +3141,14 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
             steelDetailsVo.setRollHeightDetails(rollHeightDetailsList);
         }
 
-        // 根据铸机号、班组、班别、时间范围。查询上若明细表
+        // 根据铸机号、装运单id集合或时间范围。查询上若明细表
         LambdaQueryWrapper<RollOutShippDetails> queryWrapper5 = new LambdaQueryWrapper<>();
         if (idList != null && !idList.isEmpty()) {
             queryWrapper5.eq(RollOutShippDetails::getCcmNo, ccmNo)
-                    .eq(RollOutShippDetails::getShift, shift)
-                    .eq(RollOutShippDetails::getShiftGroup, shiftGroup)
                     .in(RollOutShippDetails::getStorageBillId, idList);
         } else {
             queryWrapper5.eq(RollOutShippDetails::getCcmNo, ccmNo)
-                    .eq(RollOutShippDetails::getShift, shift)
-                    .eq(RollOutShippDetails::getShiftGroup, shiftGroup);
+                    .between(RollOutShippDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
         }
 
         List<RollOutShippDetails> rollOutShippDetailsList = rollOutShippDetailsService.list(queryWrapper5);
@@ -3659,135 +3650,10 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
             log.info("{}{}", "查询当班装运单信息为空!", ccmNo);
         }
         int allCarNum = storageBillList.size();
-        List<DestinationStatisticsDetails> statisticsDetailsList1 = new ArrayList<>();
-        List<DestinationStatisticsDetails> statisticsDetailsList2 = new ArrayList<>();
-        List<DestinationStatisticsDetails> statisticsDetailsList3 = new ArrayList<>();
-
-
-
-        for (StorageBill storageBill : storageBillList) {
-            if ("棒二".equals(storageBill.getDestination())) {
-                LambdaQueryWrapper<RollClubTwoDetails> queryWrapper3 = new LambdaQueryWrapper<>();
-                queryWrapper3.eq(RollClubTwoDetails::getCcmNo, ccmNo)
-                        .eq(RollClubTwoDetails::getShift,shift)
-                        .eq(RollClubTwoDetails::getShiftGroup,shiftGroup);
-
-                queryWrapper3.between(RollClubTwoDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
-
-                if (storageBill != null && storageBill.getId() != null) {
-                    queryWrapper3.eq(RollClubTwoDetails::getStorageBillId, storageBill.getId());
-                }
-                List<RollClubTwoDetails> rollClubTwoDetailsList = rollClubTwoDetailsService.list(queryWrapper3);
-                if (oConvertUtils.listIsNotEmpty(rollClubTwoDetailsList)) {
-                    List<DestinationStatisticsDetails> currentList1 = rollClubTwoDetailsList.stream()
-                            .collect(Collectors.groupingBy(RollClubTwoDetails::getSize))
-                            .entrySet().stream()
-                            .map(entry -> {
-                                String size = entry.getKey();
-                                List<RollClubTwoDetails> group = entry.getValue();
-                                // 统计 blankOutput 总和
-                                Double totalBlankOutput = group.stream()
-                                        .mapToDouble(RollClubTwoDetails::getBlankOutput)
-                                        .sum();
-                                // 统计数量
-                                Integer totalNums = group.stream()
-                                        .mapToInt(detail -> detail.getStackAddr() != null ? 4 : 1).sum();
-                                // 取第一个元素的 ccmNo 作为该分组的 ccmNo
-                                String ccmNos = group.isEmpty() ? null : group.get(0).getCcmNo();
-                                return new DestinationStatisticsDetails(size, totalNums, totalBlankOutput, ccmNos);
-                            }).collect(Collectors.toList());
-                    statisticsDetailsList1.addAll(currentList1);
-                }
-            }
-
-            if ("棒三".equals(storageBill.getDestination())) {
-                LambdaQueryWrapper<RollClubThreeDetails> queryWrapper3 = new LambdaQueryWrapper<>();
-                queryWrapper3.eq(RollClubThreeDetails::getCcmNo, ccmNo)
-                        .eq(RollClubThreeDetails::getShift,shift)
-                        .eq(RollClubThreeDetails::getShiftGroup,shiftGroup);
-
-                queryWrapper3.between(RollClubThreeDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
-
-                if (storageBill != null && storageBill.getId() != null) {
-                    queryWrapper3.eq(RollClubThreeDetails::getStorageBillId, storageBill.getId());
-                }
-                List<RollClubThreeDetails> rollClubThreeDetailsList = rollClubThreeDetailsService.list(queryWrapper3);
-                if (oConvertUtils.listIsNotEmpty(rollClubThreeDetailsList)) {
-                    List<DestinationStatisticsDetails> currentList2 = rollClubThreeDetailsList.stream()
-                            .collect(Collectors.groupingBy(RollClubThreeDetails::getSize))
-                            .entrySet().stream()
-                            .map(entry -> {
-                                String size = entry.getKey();
-                                List<RollClubThreeDetails> group = entry.getValue();
-                                // 统计 blankOutput 总和
-                                Double totalBlankOutput = group.stream()
-                                        .mapToDouble(RollClubThreeDetails::getBlankOutput)
-                                        .sum();
-                                // 统计数量
-                                Integer totalNums = group.stream()
-                                        .mapToInt(detail -> detail.getStackAddr() != null ? 4 : 1).sum();
-                                // 取第一个元素的 ccmNo 作为该分组的 ccmNo
-                                String ccmNos = group.isEmpty() ? null : group.get(0).getCcmNo();
-                                return new DestinationStatisticsDetails(size, totalNums, totalBlankOutput, ccmNos);
-                            }).collect(Collectors.toList());
-                    statisticsDetailsList2.addAll(currentList2);
-                }
-            }
-
-            if ("上若".equals(storageBill.getDestination())) {
-                LambdaQueryWrapper<RollOutShippDetails> queryWrapper3 = new LambdaQueryWrapper<>();
-                queryWrapper3.eq(RollOutShippDetails::getCcmNo, ccmNo)
-                        .eq(RollOutShippDetails::getShift,shift)
-                        .eq(RollOutShippDetails::getShiftGroup,shiftGroup);
-
-                queryWrapper3.between(RollOutShippDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
-
-                if (storageBill != null && storageBill.getId() != null) {
-                    queryWrapper3.eq(RollOutShippDetails::getStorageBillId, storageBill.getId());
-                }
-                List<RollOutShippDetails> rollOutShippDetailsList = rollOutShippDetailsService.list(queryWrapper3);
-                if (oConvertUtils.listIsNotEmpty(rollOutShippDetailsList)) {
-                    List<DestinationStatisticsDetails> currentList3 = rollOutShippDetailsList.stream()
-                            .collect(Collectors.groupingBy(RollOutShippDetails::getSize))
-                            .entrySet().stream()
-                            .map(entry -> {
-                                String size = entry.getKey();
-                                List<RollOutShippDetails> group = entry.getValue();
-                                // 统计 blankOutput 总和
-                                Double totalBlankOutput = group.stream()
-                                        .mapToDouble(RollOutShippDetails::getBlankOutput)
-                                        .sum();
-                                // 统计数量
-                                Integer totalNums = group.stream()
-                                        .mapToInt(detail -> detail.getStackAddr() != null ? 4 : 1).sum();
-                                // 取第一个元素的 ccmNo 作为该分组的 ccmNo
-                                String ccmNos = group.isEmpty() ? null : group.get(0).getCcmNo();
-                                return new DestinationStatisticsDetails(size, totalNums, totalBlankOutput, ccmNos);
-                            }).collect(Collectors.toList());
-                    statisticsDetailsList3.addAll(currentList3);
-                }
-            }
-        }
-
-        // 合并三个列表并根据 size 分组统计
-        List<DestinationStatisticsDetails> mergedList = Stream.concat(
-                        Stream.concat(statisticsDetailsList1.stream(), statisticsDetailsList2.stream()),
-                        statisticsDetailsList3.stream()
-                ).collect(Collectors.groupingBy(DestinationStatisticsDetails::getSize))
-                .entrySet().stream()
-                .map(entry -> {
-                    String size = entry.getKey();
-                    List<DestinationStatisticsDetails> group = entry.getValue();
-                    int totalNums = group.stream().mapToInt(DestinationStatisticsDetails::getNums).sum();
-                    double totalBlankOutput = group.stream().mapToDouble(DestinationStatisticsDetails::getBlankOutput).sum();
-                    BigDecimal bd = BigDecimal.valueOf(totalBlankOutput).setScale(4, BigDecimal.ROUND_HALF_UP);
-                    double finalBlankOutput = bd.doubleValue();
-                    String ccmNoForGroup = group.isEmpty() ? null : group.get(0).getCcmNo();
-                    return new DestinationStatisticsDetails(size, totalNums, finalBlankOutput, ccmNoForGroup);
-                }).collect(Collectors.toList());
-        // 遍历mergedList获取nums总和
-        int finalAmountTotal = mergedList.stream().mapToInt(DestinationStatisticsDetails::getNums).sum();
 
+        int totalAmount = storageBillList.stream()
+                .mapToInt(item -> item.getAmountTotal() != null ? item.getAmountTotal() : 0)
+                .sum();
 
         int hotSendSum = 0;
         int hotChargeSum = 0;
@@ -3864,15 +3730,11 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
         LambdaQueryWrapper<RollClubTwoDetails> queryWrapper2 = new LambdaQueryWrapper<>();
         if (idList != null && !idList.isEmpty()) {
             queryWrapper2.eq(RollClubTwoDetails::getCcmNo, ccmNo)
-                         .eq(RollClubTwoDetails::getShift, shift)
-                         .eq(RollClubTwoDetails::getShiftGroup, shiftGroup)
                           .in(RollClubTwoDetails::getStorageBillId, idList)
                           .between(RollClubTwoDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
 
         } else {
             queryWrapper2.eq(RollClubTwoDetails::getCcmNo, ccmNo)
-                         .eq(RollClubTwoDetails::getShift, shift)
-                         .eq(RollClubTwoDetails::getShiftGroup, shiftGroup)
                          .between(RollClubTwoDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
         }
 
@@ -3896,14 +3758,10 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
         LambdaQueryWrapper<RollClubThreeDetails> queryWrapper3 = new LambdaQueryWrapper<>();
         if (idList != null && !idList.isEmpty()) {
             queryWrapper3.eq(RollClubThreeDetails::getCcmNo, ccmNo)
-                    .eq(RollClubThreeDetails::getShift, shift)
-                    .eq(RollClubThreeDetails::getShiftGroup, shiftGroup)
                     .in(RollClubThreeDetails::getStorageBillId, idList)
                     .between(RollClubThreeDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
         } else {
             queryWrapper3.eq(RollClubThreeDetails::getCcmNo, ccmNo)
-                    .eq(RollClubThreeDetails::getShift, shift)
-                    .eq(RollClubThreeDetails::getShiftGroup, shiftGroup)
                     .between(RollClubThreeDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
         }
 
@@ -3953,14 +3811,10 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
         LambdaQueryWrapper<RollOutShippDetails> queryWrapper5 = new LambdaQueryWrapper<>();
         if (idList != null && !idList.isEmpty()) {
             queryWrapper5.eq(RollOutShippDetails::getCcmNo, ccmNo)
-                    .eq(RollOutShippDetails::getShift, shift)
-                    .eq(RollOutShippDetails::getShiftGroup, shiftGroup)
                     .in(RollOutShippDetails::getStorageBillId, idList)
                     .between(RollOutShippDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
         } else {
             queryWrapper5.eq(RollOutShippDetails::getCcmNo, ccmNo)
-                    .eq(RollOutShippDetails::getShift, shift)
-                    .eq(RollOutShippDetails::getShiftGroup, shiftGroup)
                     .between(RollOutShippDetails::getCreateTime, billetHotsendChangeShift.getCreateTime(), new Date());
         }
 
@@ -3986,7 +3840,7 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
 
 
         onDutyStorageBillStatistics.setAllCarNum(allCarNum);
-        onDutyStorageBillStatistics.setCounts(finalAmountTotal);
+        onDutyStorageBillStatistics.setCounts(totalAmount);
 
         return onDutyStorageBillStatistics;
     }
@@ -4017,7 +3871,7 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
         }
 
 
-        // 根据铸机号、班组、班别,amountTotal不等于0 ,查询当班装运单信息
+        // 根据铸机号、班组、班别,查询当班装运单信息
         LambdaQueryWrapper<StorageBill> queryWrapper2 = new LambdaQueryWrapper<>();
         queryWrapper2.eq(StringUtils.isNotBlank(ccmNo), StorageBill::getCcmNo, ccmNo)
                 .eq(StorageBill::getShift, shift)