Kaynağa Gözat

有盛每日报表

donglang 2 gün önce
ebeveyn
işleme
c472c6c44c

+ 3 - 3
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/param/WaybillOrderReportQueryParam.java

@@ -37,10 +37,10 @@ public class WaybillOrderReportQueryParam extends PageReq implements Serializabl
     private List<Long> customerEntIds;
     private List<Long> customerEntIds;
 
 
     /**
     /**
-     * 商品名称
+     * 商品id
      */
      */
-    @Schema(description = "商品名称")
-    private String goodsName;
+    @Schema(description = "商品id")
+    private List<Long> dictIds;
 
 
     /**
     /**
      * 时间
      * 时间

+ 1 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/param/WaybillOrderReportResp.java

@@ -54,7 +54,7 @@ public class WaybillOrderReportResp implements Serializable {
      * 商品id
      * 商品id
      */
      */
     @Schema(description = "商品id")
     @Schema(description = "商品id")
-    private String goodsId;
+    private Long dictId;
 
 
     /**
     /**
      * 商品名称
      * 商品名称

+ 1 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/vo/WaybillOrderReportRespExcelVO.java

@@ -55,7 +55,7 @@ public class WaybillOrderReportRespExcelVO implements Serializable {
     /**
     /**
      * 商品id
      * 商品id
      */
      */
-    private String goodsId;
+    private Long goodsId;
 
 
     /**
     /**
      * 商品名称
      * 商品名称

+ 8 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/repository/KwtForkliftWaybillOrderRepository.java

@@ -72,6 +72,14 @@ public class KwtForkliftWaybillOrderRepository extends ServiceImpl<KwtForkliftWa
                 .orderByDesc(KwtForkliftWaybillOrder::getCreateTime));
                 .orderByDesc(KwtForkliftWaybillOrder::getCreateTime));
     }
     }
 
 
+    public List<KwtForkliftWaybillOrder> queryForkliftByWOrderIdsAndType(List<Long> wOrderIds, Integer type) {
+        return list(
+                Wrappers.<KwtForkliftWaybillOrder>lambdaQuery()
+                        .in(KwtForkliftWaybillOrder::getWOrderId, wOrderIds)
+                        .eq(KwtForkliftWaybillOrder::getLoadingType, type)
+                        .orderByDesc(KwtForkliftWaybillOrder::getId));
+    }
+
 
 
 
 
 
 

+ 133 - 82
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/app/WaybillOrderService.java

@@ -82,6 +82,8 @@ public class WaybillOrderService {
     private final KwtWaybillOrderWeighbridgeRepository waybillOrderWeighbridgeRepository;
     private final KwtWaybillOrderWeighbridgeRepository waybillOrderWeighbridgeRepository;
     private final KwtLogisticsOrderContractRepository logisticsOrderContractRepository;
     private final KwtLogisticsOrderContractRepository logisticsOrderContractRepository;
     private final KwtGatekeeperWaybillOrderRepository gatekeeperWaybillOrderRepository;
     private final KwtGatekeeperWaybillOrderRepository gatekeeperWaybillOrderRepository;
+    private final KwtForkliftWaybillOrderRepository forkliftWaybillOrderRepository;
+
 
 
     @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
     @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
     RemoteSystemService remoteSystemService;
     RemoteSystemService remoteSystemService;
@@ -1984,90 +1986,15 @@ public class WaybillOrderService {
         log.info("[报表]开始查询运单每日报表:{}", JSON.toJSONString(param));
         log.info("[报表]开始查询运单每日报表:{}", JSON.toJSONString(param));
         // 查询运单数据
         // 查询运单数据
         List<WaybillOrderReportResp> orderRepoost = getWaybillOrderRepoost(param);
         List<WaybillOrderReportResp> orderRepoost = getWaybillOrderRepoost(param);
+        // 过滤
+        filter(param, orderRepoost);
+
         //汇总数据
         //汇总数据
         List<WaybillOrderReportResp> orderGroupedReportList = buildGroupedReport(orderRepoost);
         List<WaybillOrderReportResp> orderGroupedReportList = buildGroupedReport(orderRepoost);
 
 
         return orderGroupedReportList;
         return orderGroupedReportList;
     }
     }
 
 
-    /**
-     * 将扁平的运单列表转换为“汇总行在前,明细在后”的报表格式
-     */
-    public List<WaybillOrderReportResp> buildGroupedReport(List<WaybillOrderReportResp> rawList) {
-        log.info("[报表]开始分组汇总!");
-        if (rawList == null || rawList.isEmpty()) {
-            return Collections.emptyList();
-        }
-
-        // 1. 排序优先级:单位ID -> 商品名称 -> 离场时间(倒序或正序均可)
-        rawList.sort(Comparator.comparing(WaybillOrderReportResp::getProcurementEntId, Comparator.nullsLast(Long::compareTo))
-                .thenComparing(WaybillOrderReportResp::getGoodsName, Comparator.nullsLast(String::compareTo))
-                .thenComparing(WaybillOrderReportResp::getLeaveTime, Comparator.nullsLast(Date::compareTo)));
-
-        // 2. 分组:LinkedHashMap保持插入顺序
-        Map<String, List<WaybillOrderReportResp>> groupedMap = rawList.stream()
-                .collect(Collectors.groupingBy(
-                        item -> item.getProcurementEntId() + "_" + item.getGoodsName(),
-                        LinkedHashMap::new,
-                        Collectors.toList()
-                ));
-
-        List<WaybillOrderReportResp> resultList = new ArrayList<>();
-
-        // 3. 遍历组装:【汇总行】 -> 【明细行】
-        for (Map.Entry<String, List<WaybillOrderReportResp>> entry : groupedMap.entrySet()) {
-            List<WaybillOrderReportResp> details = entry.getValue();
-            if (details.isEmpty())  {
-                continue;
-            }
-
-            WaybillOrderReportResp firstItem = details.get(0);
-            // A. 添加【明细行】 ---
-            resultList.addAll(details);
-
-            // B. 创建并添加【汇总行】 ---
-            WaybillOrderReportResp summaryRow = createSummaryRow(firstItem, details);
-            resultList.add(summaryRow);
-        }
-        log.info("[报表]分组汇总结束!");
-        return resultList;
-    }
-
-    /**
-     * 计算并生成一行汇总数据
-     */
-    private WaybillOrderReportResp createSummaryRow(WaybillOrderReportResp sample, List<WaybillOrderReportResp> details) {
-        log.info("[报表]开始生成一行汇总数据!");
-        WaybillOrderReportResp summary = new WaybillOrderReportResp();
-
-        // 复制分组维度的信息
-        summary.setId(-1L);
-        summary.setProcurementEntId(sample.getProcurementEntId());
-
-        BigDecimal totalMoney = BigDecimal.ZERO;
-        BigDecimal totalNetWeight = BigDecimal.ZERO;
-        BigDecimal totalGrossWeight = BigDecimal.ZERO;
-        BigDecimal totalTareWeight = BigDecimal.ZERO;
-
-
-        // 累加计算
-        for (WaybillOrderReportResp item : details) {
-            totalMoney = totalMoney.add(item.getTotalPrice() != null ? item.getTotalPrice() : BigDecimal.ZERO);
-            totalNetWeight = totalNetWeight.add(item.getAmount() != null ? item.getAmount() : BigDecimal.ZERO);
-            totalGrossWeight = totalGrossWeight.add(item.getGrossAmount() != null ? item.getGrossAmount() : BigDecimal.ZERO);
-            totalTareWeight = totalTareWeight.add(item.getTareAmount() != null ? item.getTareAmount() : BigDecimal.ZERO);
-        }
-
-        // 赋值给汇总行
-        summary.setTotalPrice(totalMoney);
-        summary.setAmount(totalNetWeight);
-        summary.setGrossAmount(totalGrossWeight);
-        summary.setTareAmount(totalTareWeight);
-        log.info("[报表]生成一行汇总数据结束!");
-        return summary;
-    }
-
-
     private List<WaybillOrderReportResp> getWaybillOrderRepoost(WaybillOrderReportQueryParam param) {
     private List<WaybillOrderReportResp> getWaybillOrderRepoost(WaybillOrderReportQueryParam param) {
 
 
         // 1. 贸易订单id
         // 1. 贸易订单id
@@ -2130,10 +2057,17 @@ public class WaybillOrderService {
         Map<Long, KwtGatekeeperWaybillOrder> gatekeeperMap = gatekeepers.stream()
         Map<Long, KwtGatekeeperWaybillOrder> gatekeeperMap = gatekeepers.stream()
                 .collect(Collectors.toMap(KwtGatekeeperWaybillOrder::getWOrderId, Function.identity(), (x, y) -> x));
                 .collect(Collectors.toMap(KwtGatekeeperWaybillOrder::getWOrderId, Function.identity(), (x, y) -> x));
 
 
+        //铲车
+        List<KwtForkliftWaybillOrder> forklifts = forkliftWaybillOrderRepository.queryForkliftByWOrderIdsAndType(wOrderIds, Global.NUMERICAL_ZERO);
+        if (CollectionUtils.isEmpty(forklifts)) {
+            throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "铲车订单不存在,wOrderIds:" + JSON.toJSONString(wOrderIds));
+        }
+        Map<Long, KwtForkliftWaybillOrder> forkliftMap = forklifts.stream().collect(Collectors.toMap(KwtForkliftWaybillOrder::getWOrderId, Function.identity(), (x, y) -> x));
+
         //组装参数
         //组装参数
         List<WaybillOrderReportResp> orderList = waybillOrderList.stream()
         List<WaybillOrderReportResp> orderList = waybillOrderList.stream()
                 .map(waybillOrder -> {
                 .map(waybillOrder -> {
-                    return getWaybillOrderReport(waybillOrder, tOrderUnitMap, tOrderGoodsMap, logOrderMap, addressMap, ticketMap, gatekeeperMap);
+                    return getWaybillOrderReport(waybillOrder, tOrderUnitMap, tOrderGoodsMap, logOrderMap, addressMap, ticketMap, gatekeeperMap, forkliftMap);
                 }).collect(Collectors.toList());
                 }).collect(Collectors.toList());
         log.info("[报表]查询运单每日报表结算,还未分组, size:{}",orderList.size());
         log.info("[报表]查询运单每日报表结算,还未分组, size:{}",orderList.size());
         return orderList;
         return orderList;
@@ -2176,7 +2110,8 @@ public class WaybillOrderService {
                                                          Map<Long, KwtLogisticsOrder> logOrderMap,
                                                          Map<Long, KwtLogisticsOrder> logOrderMap,
                                                          Map<Long, KwtLogisticsOrderAddress> addressMap,
                                                          Map<Long, KwtLogisticsOrderAddress> addressMap,
                                                          Map<Long, KwtWaybillOrderTicket> ticketMap,
                                                          Map<Long, KwtWaybillOrderTicket> ticketMap,
-                                                         Map<Long, KwtGatekeeperWaybillOrder> gatekeeperMap) {
+                                                         Map<Long, KwtGatekeeperWaybillOrder> gatekeeperMap,
+                                                         Map<Long, KwtForkliftWaybillOrder> forkliftMap) {
 
 
         //订单
         //订单
         KwtLogisticsOrder logOrder = logOrderMap.getOrDefault(waybillOrder.getLOrderId(), new KwtLogisticsOrder());
         KwtLogisticsOrder logOrder = logOrderMap.getOrDefault(waybillOrder.getLOrderId(), new KwtLogisticsOrder());
@@ -2190,6 +2125,8 @@ public class WaybillOrderService {
         KwtWaybillOrderTicket ticket = ticketMap.getOrDefault(waybillOrder.getId(), new KwtWaybillOrderTicket());
         KwtWaybillOrderTicket ticket = ticketMap.getOrDefault(waybillOrder.getId(), new KwtWaybillOrderTicket());
         //门卫
         //门卫
         KwtGatekeeperWaybillOrder gatekeeper = gatekeeperMap.getOrDefault(waybillOrder.getId(), new KwtGatekeeperWaybillOrder());
         KwtGatekeeperWaybillOrder gatekeeper = gatekeeperMap.getOrDefault(waybillOrder.getId(), new KwtGatekeeperWaybillOrder());
+        //铲车
+        KwtForkliftWaybillOrder forklift = forkliftMap.getOrDefault(waybillOrder.getId(), new KwtForkliftWaybillOrder());
 
 
         WaybillOrderReportResp resp = new WaybillOrderReportResp();
         WaybillOrderReportResp resp = new WaybillOrderReportResp();
         resp.setId(waybillOrder.getId());
         resp.setId(waybillOrder.getId());
@@ -2202,7 +2139,14 @@ public class WaybillOrderService {
         resp.setTareAmount(ticket.getTareAmount());
         resp.setTareAmount(ticket.getTareAmount());
         resp.setGrossAmount(ticket.getGrossAmount());
         resp.setGrossAmount(ticket.getGrossAmount());
         resp.setAmount(ticket.getAmount());
         resp.setAmount(ticket.getAmount());
-        resp.setGoodsName(gatekeeper.getGoodsName());
+        resp.setDictId(forklift.getDictId());
+        String goodsName = gatekeeper.getGoodsName();
+        // 商品名称
+        if (StringUtils.isNotBlank(goodsName)) {
+            int lastSlashIndex = goodsName.lastIndexOf("/");
+            String dictName = lastSlashIndex >= 0 ? goodsName.substring(lastSlashIndex + 1) : goodsName;
+            resp.setGoodsName(dictName);
+        }
         resp.setLeaveTime(gatekeeper.getLeaveTime());
         resp.setLeaveTime(gatekeeper.getLeaveTime());
         resp.setUnloadingPerson(loAddress.getContacts());
         resp.setUnloadingPerson(loAddress.getContacts());
         resp.setUnitPrice(tradeOrderGoods.getAmount());
         resp.setUnitPrice(tradeOrderGoods.getAmount());
@@ -2212,6 +2156,112 @@ public class WaybillOrderService {
         return resp;
         return resp;
     }
     }
 
 
+    /**
+     * 将扁平的运单列表转换为“汇总行在前,明细在后”的报表格式
+     */
+    public List<WaybillOrderReportResp> filter(WaybillOrderReportQueryParam param, List<WaybillOrderReportResp> orderRepoost) {
+        if (orderRepoost == null || orderRepoost.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        //过滤
+        return orderRepoost.stream().filter(
+                report -> {
+                    // 条件1:客户ID过滤
+                    boolean customerMatch = true;
+                    if (CollectionUtils.isNotEmpty(param.getCustomerEntIds())) {
+                        customerMatch = param.getCustomerEntIds().contains(report.getProcurementEntId());
+                    }
+
+                    // 条件2:商品ID过滤(如果传了才过滤)
+                    boolean goodsMatch = true;
+                    if (CollectionUtils.isNotEmpty(param.getDictIds())) {
+                        goodsMatch = param.getDictIds().contains(report.getDictId());
+                    }
+
+                    return customerMatch && goodsMatch;
+
+                }).collect(Collectors.toList());
+    }
+
+
+    /**
+     * 将扁平的运单列表转换为“汇总行在前,明细在后”的报表格式
+     */
+    public List<WaybillOrderReportResp> buildGroupedReport(List<WaybillOrderReportResp> rawList) {
+        log.info("[报表]开始分组汇总!");
+        if (rawList == null || rawList.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        // 1. 排序优先级:单位ID -> 商品名称 -> 离场时间(倒序或正序均可)
+        rawList.sort(Comparator.comparing(WaybillOrderReportResp::getProcurementEntId, Comparator.nullsLast(Long::compareTo))
+                .thenComparing(WaybillOrderReportResp::getGoodsName, Comparator.nullsLast(String::compareTo))
+                .thenComparing(WaybillOrderReportResp::getLeaveTime, Comparator.nullsLast(Date::compareTo)));
+
+        // 2. 分组:LinkedHashMap保持插入顺序
+        Map<String, List<WaybillOrderReportResp>> groupedMap = rawList.stream()
+                .collect(Collectors.groupingBy(
+                        item -> item.getProcurementEntId() + "_" + item.getGoodsName(),
+                        LinkedHashMap::new,
+                        Collectors.toList()
+                ));
+
+        List<WaybillOrderReportResp> resultList = new ArrayList<>();
+
+        // 3. 遍历组装:【汇总行】 -> 【明细行】
+        for (Map.Entry<String, List<WaybillOrderReportResp>> entry : groupedMap.entrySet()) {
+            List<WaybillOrderReportResp> details = entry.getValue();
+            if (details.isEmpty())  {
+                continue;
+            }
+
+            WaybillOrderReportResp firstItem = details.get(0);
+            // A. 添加【明细行】 ---
+            resultList.addAll(details);
+
+            // B. 创建并添加【汇总行】 ---
+            WaybillOrderReportResp summaryRow = createSummaryRow(firstItem, details);
+            resultList.add(summaryRow);
+        }
+        log.info("[报表]分组汇总结束!");
+        return resultList;
+    }
+
+    /**
+     * 计算并生成一行汇总数据
+     */
+    private WaybillOrderReportResp createSummaryRow(WaybillOrderReportResp sample, List<WaybillOrderReportResp> details) {
+        log.info("[报表]开始生成一行汇总数据!");
+        WaybillOrderReportResp summary = new WaybillOrderReportResp();
+
+        // 复制分组维度的信息
+        summary.setId(-1L);
+        summary.setProcurementEntId(sample.getProcurementEntId());
+
+        BigDecimal totalMoney = BigDecimal.ZERO;
+        BigDecimal totalNetWeight = BigDecimal.ZERO;
+        BigDecimal totalGrossWeight = BigDecimal.ZERO;
+        BigDecimal totalTareWeight = BigDecimal.ZERO;
+
+
+        // 累加计算
+        for (WaybillOrderReportResp item : details) {
+            totalMoney = totalMoney.add(item.getTotalPrice() != null ? item.getTotalPrice() : BigDecimal.ZERO);
+            totalNetWeight = totalNetWeight.add(item.getAmount() != null ? item.getAmount() : BigDecimal.ZERO);
+            totalGrossWeight = totalGrossWeight.add(item.getGrossAmount() != null ? item.getGrossAmount() : BigDecimal.ZERO);
+            totalTareWeight = totalTareWeight.add(item.getTareAmount() != null ? item.getTareAmount() : BigDecimal.ZERO);
+        }
+
+        // 赋值给汇总行
+        summary.setTotalPrice(totalMoney);
+        summary.setAmount(totalNetWeight);
+        summary.setGrossAmount(totalGrossWeight);
+        summary.setTareAmount(totalTareWeight);
+        log.info("[报表]生成一行汇总数据结束!");
+        return summary;
+    }
+
 
 
     /**
     /**
      * 查询运单每日报表
      * 查询运单每日报表
@@ -2222,9 +2272,10 @@ public class WaybillOrderService {
         log.info("[报表]开始查询运单每日报表:{}", JSON.toJSONString(param));
         log.info("[报表]开始查询运单每日报表:{}", JSON.toJSONString(param));
         // 查询运单数据
         // 查询运单数据
         List<WaybillOrderReportResp> orderRepoost = getWaybillOrderRepoost(param);
         List<WaybillOrderReportResp> orderRepoost = getWaybillOrderRepoost(param);
+        // 过滤
+        filter(param, orderRepoost);
         //汇总数据
         //汇总数据
         List<WaybillOrderReportResp> orderGroupedReportList = buildGroupedReport(orderRepoost);
         List<WaybillOrderReportResp> orderGroupedReportList = buildGroupedReport(orderRepoost);
-
         return BeanUtils.copyToList(orderGroupedReportList, WaybillOrderReportRespExcelVO.class);
         return BeanUtils.copyToList(orderGroupedReportList, WaybillOrderReportRespExcelVO.class);
     }
     }