|
@@ -2989,6 +2989,11 @@ public class KwtWaybillOrderV1Service {
|
|
|
|
|
|
|
|
public PageDataResult<WaybillOrderResp> findBillOrderListPage(WaybillOrderReq req) {
|
|
public PageDataResult<WaybillOrderResp> findBillOrderListPage(WaybillOrderReq req) {
|
|
|
log.info("查询订单列表请求参数:{}", JSON.toJSONString(req));
|
|
log.info("查询订单列表请求参数:{}", JSON.toJSONString(req));
|
|
|
|
|
+ KwtLogisticsOrder logisticsOrder = new KwtLogisticsOrder() ;
|
|
|
|
|
+ if (StringUtils.isNotBlank(req.getLogisticsOrderId())){
|
|
|
|
|
+ log.debug("查询物流订单ID: {}", req.getLogisticsOrderId());
|
|
|
|
|
+ logisticsOrder = logisticsOrderRepository.queryByLogisticsOrderId(Long.valueOf(req.getLogisticsOrderId()));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 处理状态参数
|
|
// 处理状态参数
|
|
|
Integer status = parseStatus(req.getStatus());
|
|
Integer status = parseStatus(req.getStatus());
|
|
@@ -3093,83 +3098,103 @@ public class KwtWaybillOrderV1Service {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// ====== 提取 tradeOrderIds ======
|
|
// ====== 提取 tradeOrderIds ======
|
|
|
- log.debug("开始提取贸易订单ID");
|
|
|
|
|
- CompletableFuture<Set<Long>> tradeOrderIdsFuture =
|
|
|
|
|
- logisticsOrderFuture.thenApply(list -> {
|
|
|
|
|
- log.debug("物流订单数据处理完成,数量: {}", list.size());
|
|
|
|
|
- return list.stream()
|
|
|
|
|
- .map(KwtLogisticsOrder::getTOrderId)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ CompletableFuture<Set<Long>> tradeOrderIdsFuture = CompletableFuture.completedFuture(Collections.emptySet());
|
|
|
|
|
+ CompletableFuture<Set<Long>> goodsIdsFuture = CompletableFuture.completedFuture(Collections.emptySet());
|
|
|
|
|
+ CompletableFuture<List<TradeOrderContractVo>> tradeOrderContractFuture = CompletableFuture.completedFuture(Collections.emptyList());
|
|
|
|
|
+ CompletableFuture<List<TradeContractGoodsDto>> contractGoodsFuture = CompletableFuture.completedFuture(Collections.emptyList());
|
|
|
|
|
+ if (Objects.nonNull(logisticsOrder) && logisticsOrder.getOrderType() != 1) {
|
|
|
|
|
+ log.info("非原矿订单,订单iD: {}, 订单类型: {}", logisticsOrder.getId(), logisticsOrder.getOrderType());
|
|
|
|
|
+ log.debug("开始提取贸易订单ID");
|
|
|
|
|
+ tradeOrderIdsFuture =
|
|
|
|
|
+ logisticsOrderFuture.thenApply(list -> {
|
|
|
|
|
+ log.debug("物流订单数据处理完成,数量: {}", list.size());
|
|
|
|
|
+ return list.stream()
|
|
|
|
|
+ .map(KwtLogisticsOrder::getTOrderId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- // ====== 提取 goodsIds ======
|
|
|
|
|
- log.debug("开始提取商品ID");
|
|
|
|
|
- CompletableFuture<Set<Long>> goodsIdsFuture =
|
|
|
|
|
- goodsInfoFuture.thenApply(list -> {
|
|
|
|
|
- log.debug("商品信息数据处理完成,数量: {}", list.size());
|
|
|
|
|
- return list.stream()
|
|
|
|
|
- .map(KwtLogisticsOrderGoods::getGoodsId)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
- }).handle(((goodsIds, ex) -> {
|
|
|
|
|
- if (ex != null) {
|
|
|
|
|
- log.error("查询商品ID失败", ex);
|
|
|
|
|
- return Set.of();
|
|
|
|
|
- } else {
|
|
|
|
|
- log.debug("商品ID提取完成,数量: {}", goodsIds.size());
|
|
|
|
|
- return goodsIds;
|
|
|
|
|
- }
|
|
|
|
|
- }));
|
|
|
|
|
-
|
|
|
|
|
- // ====== 查询贸易订单合同 ======
|
|
|
|
|
- log.debug("开始查询贸易订单合同");
|
|
|
|
|
- CompletableFuture<List<TradeOrderContractVo>> tradeOrderContractFuture =
|
|
|
|
|
- tradeOrderIdsFuture.thenCompose(tradeOrderIds -> {
|
|
|
|
|
- log.debug("贸易订单ID准备完成,数量: {}", tradeOrderIds.size());
|
|
|
|
|
- return CompletableFuture.supplyAsync(() -> {
|
|
|
|
|
- log.debug("开始查询贸易订单合同,贸易订单ID数量: {}", tradeOrderIds.size());
|
|
|
|
|
- List<TradeOrderContractVo> result = tradeOrderInfoService.queryTradeOrderIds(tradeOrderIds);
|
|
|
|
|
- log.debug("贸易订单合同查询完成,数量: {}", result.size());
|
|
|
|
|
- return result;
|
|
|
|
|
|
|
+ // ====== 提取 goodsIds ======
|
|
|
|
|
+ log.debug("开始提取商品ID");
|
|
|
|
|
+ goodsIdsFuture =
|
|
|
|
|
+ goodsInfoFuture.thenApply(list -> {
|
|
|
|
|
+ log.debug("商品信息数据处理完成,数量: {}", list.size());
|
|
|
|
|
+ return list.stream()
|
|
|
|
|
+ .map(KwtLogisticsOrderGoods::getGoodsId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+ }).handle(((goodsIds, ex) -> {
|
|
|
|
|
+ if (ex != null) {
|
|
|
|
|
+ log.error("查询商品ID失败", ex);
|
|
|
|
|
+ return Set.of();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.debug("商品ID提取完成,数量: {}", goodsIds.size());
|
|
|
|
|
+ return goodsIds;
|
|
|
|
|
+ }
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ // ====== 查询贸易订单合同 ======
|
|
|
|
|
+ log.debug("开始查询贸易订单合同");
|
|
|
|
|
+ tradeOrderContractFuture =
|
|
|
|
|
+ tradeOrderIdsFuture.thenCompose(tradeOrderIds -> {
|
|
|
|
|
+ log.debug("贸易订单ID准备完成,数量: {}", tradeOrderIds.size());
|
|
|
|
|
+ return CompletableFuture.supplyAsync(() -> {
|
|
|
|
|
+ log.debug("开始查询贸易订单合同,贸易订单ID数量: {}", tradeOrderIds.size());
|
|
|
|
|
+ List<TradeOrderContractVo> result = tradeOrderInfoService.queryTradeOrderIds(tradeOrderIds);
|
|
|
|
|
+ log.debug("贸易订单合同查询完成,数量: {}", result.size());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ });
|
|
|
|
|
+ }).exceptionally(ex -> {
|
|
|
|
|
+ log.error("查询贸易订单合同失败", ex);
|
|
|
|
|
+ throw new BusinessException("查询贸易订单合同失败");
|
|
|
});
|
|
});
|
|
|
- }).exceptionally(ex -> {
|
|
|
|
|
- log.error("查询贸易订单合同失败", ex);
|
|
|
|
|
- throw new BusinessException("查询贸易订单合同失败");
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- // ====== 查询贸易合同商品 ======
|
|
|
|
|
- log.debug("开始查询贸易合同商品");
|
|
|
|
|
- CompletableFuture<List<TradeContractGoodsDto>> contractGoodsFuture =
|
|
|
|
|
- tradeOrderContractFuture.thenCombine(goodsIdsFuture, (contracts, goodsIds) -> {
|
|
|
|
|
- log.debug("贸易合同和商品ID准备完成,合同数量: {}, 商品ID数量: {}",
|
|
|
|
|
- Optional.ofNullable(contracts).map(List::size).orElse(0),
|
|
|
|
|
- goodsIds.size());
|
|
|
|
|
- Set<Long> contractIds = Optional.ofNullable(contracts)
|
|
|
|
|
- .orElse(List.of())
|
|
|
|
|
- .stream()
|
|
|
|
|
- .map(TradeOrderContractVo::getContractId)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
- log.debug("合同ID提取完成,数量: {}", contractIds.size());
|
|
|
|
|
- List<TradeContractGoodsDto> result = remoteContractService.queryContractGoodsByContractIds(contractIds, goodsIds);
|
|
|
|
|
- log.debug("贸易合同商品查询完成,数量: {}", result.size());
|
|
|
|
|
- return result;
|
|
|
|
|
- }).thenApply(goods -> Optional.ofNullable(goods).orElse(List.of()))
|
|
|
|
|
- .exceptionally(ex -> {
|
|
|
|
|
- log.error("查询贸易订单商品失败", ex);
|
|
|
|
|
- throw new BusinessException("查询贸易订单商品失败");
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // ====== 查询贸易合同商品 ======
|
|
|
|
|
+ log.debug("开始查询贸易合同商品");
|
|
|
|
|
+ contractGoodsFuture =
|
|
|
|
|
+ tradeOrderContractFuture.thenCombine(goodsIdsFuture, (contracts, goodsIds) -> {
|
|
|
|
|
+ log.debug("贸易合同和商品ID准备完成,合同数量: {}, 商品ID数量: {}",
|
|
|
|
|
+ Optional.ofNullable(contracts).map(List::size).orElse(0),
|
|
|
|
|
+ goodsIds.size());
|
|
|
|
|
+ Set<Long> contractIds = Optional.ofNullable(contracts)
|
|
|
|
|
+ .orElse(List.of())
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .map(TradeOrderContractVo::getContractId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+ log.debug("合同ID提取完成,数量: {}", contractIds.size());
|
|
|
|
|
+ List<TradeContractGoodsDto> result = remoteContractService.queryContractGoodsByContractIds(contractIds, goodsIds);
|
|
|
|
|
+ log.debug("贸易合同商品查询完成,数量: {}", result.size());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }).thenApply(goods -> Optional.ofNullable(goods).orElse(List.of()))
|
|
|
|
|
+ .exceptionally(ex -> {
|
|
|
|
|
+ log.error("查询贸易订单商品失败", ex);
|
|
|
|
|
+ throw new BusinessException("查询贸易订单商品失败");
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- log.debug("所有异步任务创建完成");
|
|
|
|
|
|
|
+ log.debug("所有异步任务创建完成");
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 等待所有并行操作完成
|
|
// 等待所有并行操作完成
|
|
|
log.debug("等待所有并行操作完成");
|
|
log.debug("等待所有并行操作完成");
|
|
|
- CompletableFuture.allOf(orderDataFuture,logisticsOrderFuture,
|
|
|
|
|
- goodsInfoFuture, tradeOrderIdsFuture, goodsIdsFuture,
|
|
|
|
|
- tradeOrderContractFuture, dictFuture,contractGoodsFuture).join();
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ CompletableFuture.allOf(
|
|
|
|
|
+ orderDataFuture,
|
|
|
|
|
+ logisticsOrderFuture,
|
|
|
|
|
+ goodsInfoFuture,
|
|
|
|
|
+ tradeOrderIdsFuture,
|
|
|
|
|
+ goodsIdsFuture,
|
|
|
|
|
+ tradeOrderContractFuture,
|
|
|
|
|
+ dictFuture,
|
|
|
|
|
+ contractGoodsFuture
|
|
|
|
|
+ ).orTimeout(30, TimeUnit.SECONDS).join();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("执行超时或异常", e);
|
|
|
|
|
+ }
|
|
|
log.debug("所有并行操作完成");
|
|
log.debug("所有并行操作完成");
|
|
|
OrderData orderData = orderDataFuture.join();
|
|
OrderData orderData = orderDataFuture.join();
|
|
|
Map<String, Map<String, String>> dictValueAndDictResDtoMap = dictFuture.join();
|
|
Map<String, Map<String, String>> dictValueAndDictResDtoMap = dictFuture.join();
|
|
@@ -4194,22 +4219,34 @@ public class KwtWaybillOrderV1Service {
|
|
|
KwtLogisticsOrderGoods kwtLogisticsOrderGoods = finalLogOrderIdAndGoodsIdMap.getOrDefault(lOrderId, new KwtLogisticsOrderGoods());
|
|
KwtLogisticsOrderGoods kwtLogisticsOrderGoods = finalLogOrderIdAndGoodsIdMap.getOrDefault(lOrderId, new KwtLogisticsOrderGoods());
|
|
|
TradeOrderContractVo tradeOrderContractVo = tradeOrderContractVoMap.getOrDefault(logOrder.getTOrderId(), new TradeOrderContractVo());
|
|
TradeOrderContractVo tradeOrderContractVo = tradeOrderContractVoMap.getOrDefault(logOrder.getTOrderId(), new TradeOrderContractVo());
|
|
|
TradeContractGoodsDto contractGoodsDto = orderContracGoodstoMap.getOrDefault(tradeOrderContractVo.getContractId()+"-"+kwtLogisticsOrderGoods.getGoodsId(), new TradeContractGoodsDto());
|
|
TradeContractGoodsDto contractGoodsDto = orderContracGoodstoMap.getOrDefault(tradeOrderContractVo.getContractId()+"-"+kwtLogisticsOrderGoods.getGoodsId(), new TradeContractGoodsDto());
|
|
|
- if (org.apache.commons.lang3.StringUtils.equals(logOrder.getBillingMode(), DictEnum.CHARGING_TYPE_1.getValue())){
|
|
|
|
|
- BigDecimal actualPrice = Objects.nonNull(logOrder.getPrice()) && Objects.nonNull(record.getLoadAmount()) ?
|
|
|
|
|
- logOrder.getPrice().multiply(record.getLoadAmount()) : BigDecimal.ZERO;
|
|
|
|
|
- BigDecimal actualGoodsPrice = Objects.nonNull(contractGoodsDto.getPrice()) && Objects.nonNull(record.getLoadAmount()) ?
|
|
|
|
|
- contractGoodsDto.getPrice().multiply(record.getLoadAmount()) : BigDecimal.ZERO;
|
|
|
|
|
- waybillOrderResp.setActualPrice(actualPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
|
|
|
- waybillOrderResp.setActualGoodsPrice(actualGoodsPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
|
|
|
- }else if (org.apache.commons.lang3.StringUtils.equals(logOrder.getBillingMode(), DictEnum.CHARGING_TYPE_2.getValue())){
|
|
|
|
|
|
|
+ if (Objects.equals(logOrder.getOrderType(),1)){
|
|
|
|
|
+ log.info("原矿转运,计算运费{}", record.getWOrderNo());
|
|
|
BigDecimal actualPrice = Objects.nonNull(logOrder.getPrice()) && Objects.nonNull(record.getUnloadAmount()) ?
|
|
BigDecimal actualPrice = Objects.nonNull(logOrder.getPrice()) && Objects.nonNull(record.getUnloadAmount()) ?
|
|
|
logOrder.getPrice().multiply(record.getUnloadAmount()) : BigDecimal.ZERO;
|
|
logOrder.getPrice().multiply(record.getUnloadAmount()) : BigDecimal.ZERO;
|
|
|
BigDecimal actualGoodsPrice = Objects.nonNull(contractGoodsDto.getPrice()) && Objects.nonNull(record.getUnloadAmount()) ?
|
|
BigDecimal actualGoodsPrice = Objects.nonNull(contractGoodsDto.getPrice()) && Objects.nonNull(record.getUnloadAmount()) ?
|
|
|
contractGoodsDto.getPrice().multiply(record.getUnloadAmount()) : BigDecimal.ZERO;
|
|
contractGoodsDto.getPrice().multiply(record.getUnloadAmount()) : BigDecimal.ZERO;
|
|
|
waybillOrderResp.setActualPrice(actualPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
waybillOrderResp.setActualPrice(actualPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
|
waybillOrderResp.setActualGoodsPrice(actualGoodsPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
waybillOrderResp.setActualGoodsPrice(actualGoodsPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("普通订单,计算运费{}", record.getWOrderNo());
|
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.equals(logOrder.getBillingMode(), DictEnum.CHARGING_TYPE_1.getValue())){
|
|
|
|
|
+ BigDecimal actualPrice = Objects.nonNull(logOrder.getPrice()) && Objects.nonNull(record.getLoadAmount()) ?
|
|
|
|
|
+ logOrder.getPrice().multiply(record.getLoadAmount()) : BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal actualGoodsPrice = Objects.nonNull(contractGoodsDto.getPrice()) && Objects.nonNull(record.getLoadAmount()) ?
|
|
|
|
|
+ contractGoodsDto.getPrice().multiply(record.getLoadAmount()) : BigDecimal.ZERO;
|
|
|
|
|
+ waybillOrderResp.setActualPrice(actualPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
|
|
|
+ waybillOrderResp.setActualGoodsPrice(actualGoodsPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
|
|
|
+ }else if (org.apache.commons.lang3.StringUtils.equals(logOrder.getBillingMode(), DictEnum.CHARGING_TYPE_2.getValue())){
|
|
|
|
|
+ BigDecimal actualPrice = Objects.nonNull(logOrder.getPrice()) && Objects.nonNull(record.getUnloadAmount()) ?
|
|
|
|
|
+ logOrder.getPrice().multiply(record.getUnloadAmount()) : BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal actualGoodsPrice = Objects.nonNull(contractGoodsDto.getPrice()) && Objects.nonNull(record.getUnloadAmount()) ?
|
|
|
|
|
+ contractGoodsDto.getPrice().multiply(record.getUnloadAmount()) : BigDecimal.ZERO;
|
|
|
|
|
+ waybillOrderResp.setActualPrice(actualPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
|
|
|
+ waybillOrderResp.setActualGoodsPrice(actualGoodsPrice.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
return waybillOrderResp;
|
|
return waybillOrderResp;
|
|
|
}
|
|
}
|
|
|
|
|
|