|
|
@@ -82,6 +82,8 @@ public class WaybillOrderService {
|
|
|
private final KwtWaybillOrderWeighbridgeRepository waybillOrderWeighbridgeRepository;
|
|
|
private final KwtLogisticsOrderContractRepository logisticsOrderContractRepository;
|
|
|
private final KwtGatekeeperWaybillOrderRepository gatekeeperWaybillOrderRepository;
|
|
|
+ private final KwtForkliftWaybillOrderRepository forkliftWaybillOrderRepository;
|
|
|
+
|
|
|
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
|
|
|
RemoteSystemService remoteSystemService;
|
|
|
@@ -1984,90 +1986,15 @@ public class WaybillOrderService {
|
|
|
log.info("[报表]开始查询运单每日报表:{}", JSON.toJSONString(param));
|
|
|
// 查询运单数据
|
|
|
List<WaybillOrderReportResp> orderRepoost = getWaybillOrderRepoost(param);
|
|
|
+ // 过滤
|
|
|
+ filter(param, orderRepoost);
|
|
|
+
|
|
|
//汇总数据
|
|
|
List<WaybillOrderReportResp> orderGroupedReportList = buildGroupedReport(orderRepoost);
|
|
|
|
|
|
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) {
|
|
|
|
|
|
// 1. 贸易订单id
|
|
|
@@ -2130,10 +2057,17 @@ public class WaybillOrderService {
|
|
|
Map<Long, KwtGatekeeperWaybillOrder> gatekeeperMap = gatekeepers.stream()
|
|
|
.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()
|
|
|
.map(waybillOrder -> {
|
|
|
- return getWaybillOrderReport(waybillOrder, tOrderUnitMap, tOrderGoodsMap, logOrderMap, addressMap, ticketMap, gatekeeperMap);
|
|
|
+ return getWaybillOrderReport(waybillOrder, tOrderUnitMap, tOrderGoodsMap, logOrderMap, addressMap, ticketMap, gatekeeperMap, forkliftMap);
|
|
|
}).collect(Collectors.toList());
|
|
|
log.info("[报表]查询运单每日报表结算,还未分组, size:{}",orderList.size());
|
|
|
return orderList;
|
|
|
@@ -2176,7 +2110,8 @@ public class WaybillOrderService {
|
|
|
Map<Long, KwtLogisticsOrder> logOrderMap,
|
|
|
Map<Long, KwtLogisticsOrderAddress> addressMap,
|
|
|
Map<Long, KwtWaybillOrderTicket> ticketMap,
|
|
|
- Map<Long, KwtGatekeeperWaybillOrder> gatekeeperMap) {
|
|
|
+ Map<Long, KwtGatekeeperWaybillOrder> gatekeeperMap,
|
|
|
+ Map<Long, KwtForkliftWaybillOrder> forkliftMap) {
|
|
|
|
|
|
//订单
|
|
|
KwtLogisticsOrder logOrder = logOrderMap.getOrDefault(waybillOrder.getLOrderId(), new KwtLogisticsOrder());
|
|
|
@@ -2190,6 +2125,8 @@ public class WaybillOrderService {
|
|
|
KwtWaybillOrderTicket ticket = ticketMap.getOrDefault(waybillOrder.getId(), new KwtWaybillOrderTicket());
|
|
|
//门卫
|
|
|
KwtGatekeeperWaybillOrder gatekeeper = gatekeeperMap.getOrDefault(waybillOrder.getId(), new KwtGatekeeperWaybillOrder());
|
|
|
+ //铲车
|
|
|
+ KwtForkliftWaybillOrder forklift = forkliftMap.getOrDefault(waybillOrder.getId(), new KwtForkliftWaybillOrder());
|
|
|
|
|
|
WaybillOrderReportResp resp = new WaybillOrderReportResp();
|
|
|
resp.setId(waybillOrder.getId());
|
|
|
@@ -2202,7 +2139,14 @@ public class WaybillOrderService {
|
|
|
resp.setTareAmount(ticket.getTareAmount());
|
|
|
resp.setGrossAmount(ticket.getGrossAmount());
|
|
|
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.setUnloadingPerson(loAddress.getContacts());
|
|
|
resp.setUnitPrice(tradeOrderGoods.getAmount());
|
|
|
@@ -2212,6 +2156,112 @@ public class WaybillOrderService {
|
|
|
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));
|
|
|
// 查询运单数据
|
|
|
List<WaybillOrderReportResp> orderRepoost = getWaybillOrderRepoost(param);
|
|
|
+ // 过滤
|
|
|
+ filter(param, orderRepoost);
|
|
|
//汇总数据
|
|
|
List<WaybillOrderReportResp> orderGroupedReportList = buildGroupedReport(orderRepoost);
|
|
|
-
|
|
|
return BeanUtils.copyToList(orderGroupedReportList, WaybillOrderReportRespExcelVO.class);
|
|
|
}
|
|
|
|