|
|
@@ -17,7 +17,6 @@ import com.sckw.core.model.enums.LogisticsOrderV1Enum;
|
|
|
import com.sckw.core.model.enums.UnitTypeEnum;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.DateUtils;
|
|
|
-import com.sckw.core.web.response.BaseResult;
|
|
|
import com.sckw.core.web.response.result.PageDataResult;
|
|
|
import com.sckw.fleet.api.RemoteFleetService;
|
|
|
import com.sckw.fleet.api.model.vo.RTruckVo;
|
|
|
@@ -35,9 +34,7 @@ import com.sckw.transport.model.vo.OrderTotalTakeVo;
|
|
|
import com.sckw.transport.model.vo.StatisticsWaybillResp;
|
|
|
import com.sckw.transport.repository.*;
|
|
|
import com.sckw.transport.service.KwtWaybillOrderV1Service;
|
|
|
-import io.swagger.v3.oas.annotations.Operation;
|
|
|
import jakarta.annotation.Resource;
|
|
|
-import jakarta.validation.Valid;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -46,8 +43,6 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
@@ -79,6 +74,7 @@ public class WaybillOrderService {
|
|
|
private final KwtWaybillOrderAddressRepository waybillOrderAddressRepository;
|
|
|
private final KwtWaybillOrderTicketRepository waybillOrderTicketRepository;
|
|
|
private final KwtWaybillOrderNodeRepository waybillOrderNodeRepository;
|
|
|
+ private final KwtWaybillOrderWeighbridgeRepository waybillOrderWeighbridgeRepository;
|
|
|
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
|
|
|
RemoteSystemService remoteSystemService;
|
|
|
@@ -135,7 +131,10 @@ public class WaybillOrderService {
|
|
|
CarWaybillV1Enum.REPLENISHING.getCode(),
|
|
|
CarWaybillV1Enum.REPLENISH_FINISH.getCode(),
|
|
|
CarWaybillV1Enum.RELEASED_NOT_EXITED.getCode(),
|
|
|
- CarWaybillV1Enum.WAIT_LOADING.getCode());
|
|
|
+ CarWaybillV1Enum.WAIT_LOADING.getCode(),
|
|
|
+ CarWaybillV1Enum.UNLOADING_POINT.getCode(),
|
|
|
+ CarWaybillV1Enum.UNLOADING_WAIT_LEAVE.getCode(),
|
|
|
+ CarWaybillV1Enum.UNLOADING_WAIT_RELEASE.getCode());
|
|
|
|
|
|
// 定义审核的状态集合
|
|
|
private static final List<Integer> REVIEW = Arrays.asList(
|
|
|
@@ -229,8 +228,60 @@ public class WaybillOrderService {
|
|
|
log.info("当前车辆无物流订单,truckNo:{}", param.getTruckNo());
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.DRIVER_STATUS_ERROR, "当前车辆无物流订单");
|
|
|
}
|
|
|
- Map<Long, List<KwtLogisticsOrder>> tradeIdAndLogOrderList = logOrderList.stream()
|
|
|
- .collect(Collectors.groupingBy(KwtLogisticsOrder::getTOrderId));
|
|
|
+
|
|
|
+ // 按照order_type区分“正常订单”和“原矿运输订单”
|
|
|
+ Map<Boolean, List<KwtLogisticsOrder>> partitionedMap = logOrderList.stream()
|
|
|
+ .collect(Collectors.partitioningBy(order -> Integer.valueOf(1).equals(order.getOrderType())));
|
|
|
+
|
|
|
+ // 获取order_type=null的订单集合
|
|
|
+ List<KwtLogisticsOrder> typeNullList = partitionedMap.get(false);
|
|
|
+ log.info("正常流程的订单信息: {},数量:{}", JSON.toJSONString(typeNullList), typeNullList.size());
|
|
|
+
|
|
|
+ // 获取order_type=1的订单集合
|
|
|
+ List<KwtLogisticsOrder> typeOneList = partitionedMap.get(true);
|
|
|
+ log.info("原矿运输的订单信息: {},数量:{}", JSON.toJSONString(typeOneList), typeOneList.size());
|
|
|
+
|
|
|
+ List<LogisticsOrderResp> orderList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 正常流程
|
|
|
+ //1.查询正常流程物流运运单
|
|
|
+ if (CollectionUtils.isNotEmpty(typeNullList)) {
|
|
|
+ List<LogisticsOrderResp> normalOrderList = getLogisticsOrderResps(param, typeNullList, logOrderIdAndCirculateMap, rTruckVo);
|
|
|
+ orderList.addAll(normalOrderList);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(typeOneList)) {
|
|
|
+ // 原矿运输
|
|
|
+ List<LogisticsOrderResp> rawOreOrdderList = getRawOreLogisticsOrderResps(param, typeOneList, logOrderIdAndCirculateMap, rTruckVo);
|
|
|
+ orderList.addAll(rawOreOrdderList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //内存分页
|
|
|
+ List<List<LogisticsOrderResp>> pageList = Lists.partition(orderList, param.getPageSize());
|
|
|
+ List<LogisticsOrderResp> walletPageList = pageList.size() >= param.getPageNum() ?
|
|
|
+ pageList.get(param.getPageNum() - 1) : Collections.emptyList();
|
|
|
+
|
|
|
+ PageDataResult<LogisticsOrderResp> walletPageResponse = PageDataResult.success(param.getPageNum(), param.getPageSize(), (long) walletPageList.size(), walletPageList);
|
|
|
+ log.info("查询司机关联车辆的物流订单成功,resouce:{}", JSON.toJSONString(walletPageResponse));
|
|
|
+ return walletPageResponse;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 正常流程查询物流订单
|
|
|
+ * @param param
|
|
|
+ * @param logOrderList
|
|
|
+ * @param logOrderIdList
|
|
|
+ * @param logOrderIdAndCirculateMap
|
|
|
+ * @param rTruckVo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<LogisticsOrderResp> getLogisticsOrderResps(OrderCirculateQueryParam param, List<KwtLogisticsOrder> logOrderList,
|
|
|
+ Map<Long, KwtLogisticsOrderCirculate> logOrderIdAndCirculateMap,
|
|
|
+ RTruckVo rTruckVo) {
|
|
|
+ log.info("开始查询正常流程物流订单,param:{}", JSON.toJSONString(param));
|
|
|
+ List<Long> logOrderIdList = logOrderList.stream().map(KwtLogisticsOrder::getId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Long, List<KwtLogisticsOrder>> tradeIdAndLogOrderList = logOrderList.stream().collect(Collectors.groupingBy(KwtLogisticsOrder::getTOrderId));
|
|
|
|
|
|
//物流id映射物流商品
|
|
|
List<KwtLogisticsOrderGoods> logOrderGoods = logisticsOrderGoodsRepository.queryByLogOrderIds(logOrderIdList);
|
|
|
@@ -260,7 +311,7 @@ public class WaybillOrderService {
|
|
|
|
|
|
//贸易订单id
|
|
|
Set<Long> tradeOrderIds = logOrderList.stream().map(KwtLogisticsOrder::getTOrderId).collect(Collectors.toSet());
|
|
|
-
|
|
|
+
|
|
|
//供应企业
|
|
|
List<OrderUnitInfoDetailVO> orderUnitDetailVOS = tradeOrderInfoService.queryOrderUnitInfByTOrderId(tradeOrderIds);
|
|
|
if (CollectionUtils.isEmpty(orderUnitDetailVOS)) {
|
|
|
@@ -306,16 +357,83 @@ public class WaybillOrderService {
|
|
|
return checkCurTruckLoadVolume(rTruckVo, logisticsOrderResp.getRemainingAmount());
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
+ log.info("查询正常流程物流订单结束,resouse:{}", JSON.toJSONString(ordderList));
|
|
|
+ return ordderList;
|
|
|
+ }
|
|
|
|
|
|
- //内存分页
|
|
|
- List<List<LogisticsOrderResp>> pageList = Lists.partition(ordderList, param.getPageSize());
|
|
|
- List<LogisticsOrderResp> walletPageList = pageList.size() >= param.getPageNum() ?
|
|
|
- pageList.get(param.getPageNum() - 1) : Collections.emptyList();
|
|
|
+ /**
|
|
|
+ * 原矿运输
|
|
|
+ * @param param
|
|
|
+ * @param logOrderList
|
|
|
+ * @param logOrderIdList
|
|
|
+ * @param logOrderIdAndCirculateMap
|
|
|
+ * @param rTruckVo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<LogisticsOrderResp> getRawOreLogisticsOrderResps(OrderCirculateQueryParam param, List<KwtLogisticsOrder> logOrderList,
|
|
|
+ Map<Long, KwtLogisticsOrderCirculate> logOrderIdAndCirculateMap,
|
|
|
+ RTruckVo rTruckVo) {
|
|
|
+ log.info("开始查询原矿运输流程物流订单,param:{}", JSON.toJSONString(param));
|
|
|
+ List<Long> logOrderIdList = logOrderList.stream().map(KwtLogisticsOrder::getId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
|
- PageDataResult<LogisticsOrderResp> walletPageResponse = PageDataResult.success(param.getPageNum(), param.getPageSize(), (long) walletPageList.size(), walletPageList);
|
|
|
- log.info("查询司机关联车辆的物流订单成功!");
|
|
|
- return walletPageResponse;
|
|
|
+ Map<Long, List<KwtLogisticsOrder>> tradeIdAndLogOrderList = logOrderList.stream()
|
|
|
+ .collect(Collectors.groupingBy(KwtLogisticsOrder::getTOrderId));
|
|
|
+
|
|
|
+ //物流id映射物流商品
|
|
|
+ List<KwtLogisticsOrderGoods> logOrderGoods = logisticsOrderGoodsRepository.queryByLogOrderIds(logOrderIdList);
|
|
|
+ if (CollectionUtils.isEmpty(logOrderGoods)) {
|
|
|
+ log.info("当前车辆的物流订单无商品信息,truckNo:{}", param.getTruckNo());
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.LOGISTICS_ORDER_NOT_GOODS, "当前车辆的物流订单无商品信息");
|
|
|
+ }
|
|
|
+ Map<Long, KwtLogisticsOrderGoods> logOrderIdAndGoodsMap = logOrderGoods.stream().collect(Collectors.toMap(KwtLogisticsOrderGoods::getLOrderId,
|
|
|
+ Function.identity(), (x, y) -> x));
|
|
|
+
|
|
|
+ //交易商品信息
|
|
|
+ List<Long> goodsIds = logOrderGoods.stream().map(KwtLogisticsOrderGoods::getGoodsId).distinct().collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(goodsIds)) {
|
|
|
+ log.info("物流订单无关联商品信息,logOrderId:{}", JSON.toJSONString(logOrderIdList));
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.LOGISTICS_ORDER_NOT_GOODS, "物流订单无关联商品信息");
|
|
|
+ }
|
|
|
+ Map<Long, KwpGoods> goodsIdAndGoodsMap = goodsInfoService.getGoodsByIds(goodsIds);
|
|
|
+
|
|
|
+ //承运托运企业
|
|
|
+ List<KwtLogisticsOrderUnit> logOrderUnits = logisticsOrderUnitRepository.queryByLogOrderIds(logOrderIdList);
|
|
|
+ if (CollectionUtils.isEmpty(logOrderUnits)) {
|
|
|
+ log.info("物流订单无关联承运托运企业,logOrderId:{}", JSON.toJSONString(logOrderIdList));
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.LOGISTICS_ORDER_NOT_ENT, "物流订单无关联承运托运企业");
|
|
|
+ }
|
|
|
+ Map<String, KwtLogisticsOrderUnit> logOrderIdAndUnitMap = logOrderUnits.stream().collect(Collectors.toMap(
|
|
|
+ unit -> unit.getLOrderId() + "-" + unit.getUnitType(), Function.identity(), (x, y) -> x));
|
|
|
+
|
|
|
+ //地址
|
|
|
+ Map<String, KwtLogisticsOrderAddress> logOrderIdAndAddressMap = getKwtLogisticsOrderAddressMap(logOrderIdList);
|
|
|
+
|
|
|
+ //子运单
|
|
|
+ List<KwtWaybillOrderSubtask> orderSubtaskList = waybillOrderSubtaskRepository.queryByLogIds(logOrderIdList);
|
|
|
+ if(CollectionUtils.isEmpty(orderSubtaskList)) {
|
|
|
+ orderSubtaskList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ Map<Long, List<KwtWaybillOrderSubtask>> logOrderIdAndSubtaskMap = orderSubtaskList.stream()
|
|
|
+ .collect(Collectors.groupingBy(KwtWaybillOrderSubtask::getLOrderId));
|
|
|
|
|
|
+ //查询字典
|
|
|
+ Map<String, Map<String, String>> dictValueAndDictResDtoMap = remoteSystemService.queryDictByType(
|
|
|
+ Arrays.asList(DictTypeEnum.PRODUCT_NAME_TYPE.getType(), DictTypeEnum.GOODS_SPEC.getType()));
|
|
|
+
|
|
|
+ //组装数据
|
|
|
+ List<LogisticsOrderResp> ordderList = logOrderList.stream()
|
|
|
+ .map(order -> {
|
|
|
+ return getRawOreLogisticsOrderResp(order, logOrderIdAndGoodsMap, goodsIdAndGoodsMap, logOrderIdAndUnitMap,
|
|
|
+ logOrderIdAndAddressMap, logOrderIdAndCirculateMap,
|
|
|
+ tradeIdAndLogOrderList, logOrderIdAndSubtaskMap, dictValueAndDictResDtoMap);
|
|
|
+ })
|
|
|
+ .filter(logisticsOrderResp -> {
|
|
|
+ // 校验是否满足车辆任务量,满足才保留
|
|
|
+ return checkCurTruckLoadVolume(rTruckVo, logisticsOrderResp.getRemainingAmount());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ log.info("查询原矿运输流程物流订单结束,resouse:{}", JSON.toJSONString(ordderList));
|
|
|
+ return ordderList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -348,7 +466,7 @@ public class WaybillOrderService {
|
|
|
* @param truckNo
|
|
|
*/
|
|
|
private Boolean checkCurTruckLoadVolume(RTruckVo truckNo, BigDecimal remainingAmount) {
|
|
|
- log.info("开始校验当前车辆任务量!");
|
|
|
+ log.info("开始校验当前车辆任务量!param:{}, 订单余量:{}", JSON.toJSONString(truckNo), JSON.toJSONString(remainingAmount));
|
|
|
//核定载重
|
|
|
BigDecimal actualWeight = truckNo.getLegalLoad();
|
|
|
//首次皮重
|
|
|
@@ -392,7 +510,7 @@ public class WaybillOrderService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 组装订单列表信息
|
|
|
+ * 组装正常流程订单列表信息
|
|
|
* @param order
|
|
|
* @param logOrderIdAndGoodsMap
|
|
|
* @param goodsIdAndGoodsMap
|
|
|
@@ -468,6 +586,77 @@ public class WaybillOrderService {
|
|
|
return orderResp;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 组装原矿运输订单列表信息
|
|
|
+ * @param order
|
|
|
+ * @param logOrderIdAndGoodsMap
|
|
|
+ * @param goodsIdAndGoodsMap
|
|
|
+ * @param logOrderIdAndUnitMap
|
|
|
+ * @param tOrderIdAndUnitMap
|
|
|
+ * @param logOrderIdAndAddressMap
|
|
|
+ * @param logOrderIdAndCirculateMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private LogisticsOrderResp getRawOreLogisticsOrderResp(KwtLogisticsOrder order, Map<Long, KwtLogisticsOrderGoods> logOrderIdAndGoodsMap,
|
|
|
+ Map<Long, KwpGoods> goodsIdAndGoodsMap,
|
|
|
+ Map<String, KwtLogisticsOrderUnit> logOrderIdAndUnitMap,
|
|
|
+ Map<String, KwtLogisticsOrderAddress> logOrderIdAndAddressMap,
|
|
|
+ Map<Long, KwtLogisticsOrderCirculate> logOrderIdAndCirculateMap,
|
|
|
+ Map<Long, List<KwtLogisticsOrder>> tradeIdAndLogOrderList ,
|
|
|
+ Map<Long, List<KwtWaybillOrderSubtask>> logisticsOrderIdAndSubtaskList,
|
|
|
+ Map<String, Map<String, String>> dictValueAndDictResDtoMap) {
|
|
|
+ LogisticsOrderResp orderResp = new LogisticsOrderResp();
|
|
|
+ orderResp.setOrderType(order.getOrderType());
|
|
|
+ orderResp.setLogisticsOrderId(Optional.ofNullable(order.getId()).map(String::valueOf).orElse(null));
|
|
|
+ orderResp.setLogisticsOrderNo(order.getLOrderNo());
|
|
|
+ //商品
|
|
|
+ KwtLogisticsOrderGoods orderGoods = logOrderIdAndGoodsMap.getOrDefault(order.getId(), new KwtLogisticsOrderGoods());
|
|
|
+ KwpGoods goods = goodsIdAndGoodsMap.getOrDefault(orderGoods.getGoodsId(), new KwpGoods());
|
|
|
+ if (Objects.nonNull(goods)){
|
|
|
+ orderResp.setGoodsId(Optional.ofNullable(goods.getId()).map(String::valueOf).orElse(null));
|
|
|
+ Map<String, String> goodsTypeMap= dictValueAndDictResDtoMap.getOrDefault(DictTypeEnum.PRODUCT_NAME_TYPE.getType(), new HashMap<>());
|
|
|
+ Map<String, String> goodsSpecMap= dictValueAndDictResDtoMap.getOrDefault(DictTypeEnum.GOODS_SPEC.getType(), new HashMap<>());
|
|
|
+ orderResp.setGoodsName(goods.getName()+"/"+goodsTypeMap.getOrDefault(goods.getGoodsType(),"")+"/"+goodsSpecMap.getOrDefault(goods.getSpec(), ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ //供应企业
|
|
|
+ KwtLogisticsOrderUnit supplierEnt = logOrderIdAndUnitMap.getOrDefault(order.getId() + "-" + 1, new KwtLogisticsOrderUnit());
|
|
|
+ orderResp.setSupplierCompanyId(Optional.ofNullable(supplierEnt.getEntId()).map(String::valueOf).orElse(null));
|
|
|
+ orderResp.setSupplierCompanyName(supplierEnt.getFirmName());
|
|
|
+ //承运企业
|
|
|
+ KwtLogisticsOrderUnit carriageEnt = logOrderIdAndUnitMap.getOrDefault(order.getId() + "-" + 2, new KwtLogisticsOrderUnit());
|
|
|
+ orderResp.setCarriageCompanyId(Optional.ofNullable(carriageEnt.getEntId()).map(String::valueOf).orElse(null));
|
|
|
+ orderResp.setCarriageCompanyName(carriageEnt.getFirmName());
|
|
|
+
|
|
|
+ //装货地址
|
|
|
+ KwtLogisticsOrderAddress shipmentAddress = logOrderIdAndAddressMap.getOrDefault(order.getId() + "-" + AddressTypeEnum.SHIPMENT.getCode(), new KwtLogisticsOrderAddress());
|
|
|
+ orderResp.setLoadAddress(shipmentAddress.getCityName()+shipmentAddress.getDetailAddress());
|
|
|
+ //卸货地址
|
|
|
+ KwtLogisticsOrderAddress takeAddress = logOrderIdAndAddressMap.getOrDefault(order.getId() + "-" + AddressTypeEnum.TAKE.getCode(), new KwtLogisticsOrderAddress());
|
|
|
+ orderResp.setUnloadAddress(takeAddress.getCityName()+takeAddress.getDetailAddress());
|
|
|
+ //装卸地之间距离
|
|
|
+ orderResp.setDistanceKm(order.getDistance());
|
|
|
+
|
|
|
+ //时间
|
|
|
+ orderResp.setStartTime(DateUtils.format(order.getStartTime(), DateUtils.DATE_PATTERN));
|
|
|
+ orderResp.setEndTime(DateUtils.format(order.getEndTime(), DateUtils.DATE_PATTERN));
|
|
|
+ KwtLogisticsOrderCirculate orderCirculate = logOrderIdAndCirculateMap.getOrDefault(order.getId(), new KwtLogisticsOrderCirculate());
|
|
|
+ orderResp.setSendTime(DateUtils.format(orderCirculate.getCreateTime(), DateUtils.DATE_TIME_PATTERN));
|
|
|
+
|
|
|
+ //派单人信息
|
|
|
+ UserCacheResDto userCacheResDto = remoteSystemService.queryUserCacheById(orderCirculate.getCreateBy());
|
|
|
+ orderResp.setSendOperator(Optional.ofNullable(userCacheResDto).map(UserCacheResDto::getName).orElse(null));
|
|
|
+ orderResp.setSendPhone(Optional.ofNullable(userCacheResDto).map(UserCacheResDto::getPhone).orElse(null));
|
|
|
+ orderResp.setStatus(Optional.ofNullable(order.getStatus()).map(String::valueOf).orElse(null));
|
|
|
+ orderResp.setStatusDesc(LogisticsOrderV1Enum.IN_TRANSIT.getCode().equals(order.getStatus()) ? "待接单" : "未知状态");
|
|
|
+ //设置余量
|
|
|
+ BigDecimal orderSurplus = getRawOreSupAmount(order, logisticsOrderIdAndSubtaskList);
|
|
|
+ orderResp.setOrderSurplus(orderSurplus.toPlainString());
|
|
|
+ orderResp.setRemainingAmount(orderSurplus);
|
|
|
+
|
|
|
+ return orderResp;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 查询司机关联车辆的物流运单
|
|
|
@@ -492,6 +681,7 @@ public class WaybillOrderService {
|
|
|
|
|
|
//获取运单关联数据并返回结果
|
|
|
List<WaybillOrderStatusResp> ordderList = getWaybillOrderRelevantData(param, records);
|
|
|
+ sort(param, ordderList);
|
|
|
log.info("查询司机的物流运单成功!");
|
|
|
return PageDataResult.success(param.getPageNum(), param.getPageSize(), waybillOrderList.getTotal() , ordderList);
|
|
|
}
|
|
|
@@ -748,22 +938,72 @@ public class WaybillOrderService {
|
|
|
log.info("当前车辆无物流订单,truckNo:{}", param.getTruckNo());
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.DRIVER_STATUS_ERROR, "当前车辆无物流订单");
|
|
|
}
|
|
|
- Map<Long, KwtLogisticsOrder> logOrderMap = logOrderList.stream().collect(Collectors.toMap(logOrder -> logOrder.getId(),
|
|
|
+
|
|
|
+ // 按照order_type区分“正常订单”和“原矿运输订单”
|
|
|
+ Map<Boolean, List<KwtLogisticsOrder>> partitionedMap = logOrderList.stream()
|
|
|
+ .collect(Collectors.partitioningBy(order -> Integer.valueOf(1).equals(order.getOrderType())));
|
|
|
+ List<KwtLogisticsOrder> typeNullList = partitionedMap.get(false);
|
|
|
+ List<KwtLogisticsOrder> typeOneList = partitionedMap.get(true);
|
|
|
+ log.info("正常流程订单信息: {},数量:{}, 原矿运输订单信息: {},数量:{}", JSON.toJSONString(typeNullList), typeNullList.size(),
|
|
|
+ JSON.toJSONString(typeOneList), typeOneList.size());
|
|
|
+
|
|
|
+ List<WaybillOrderStatusResp> ordderList = new ArrayList<>();
|
|
|
+ //1.查询正常流程物流运运单
|
|
|
+ if (CollectionUtils.isNotEmpty(typeNullList)) {
|
|
|
+ List<WaybillOrderStatusResp> normalOrdderList = getWaybillOrderStatusResps(param, records, typeNullList,
|
|
|
+ orderSubtaskList, wbOrderIdList, subtaskMap, logOrderIdAndCirculateMap, Boolean.FALSE);
|
|
|
+ ordderList.addAll(normalOrdderList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.查询原矿运输物流运运单
|
|
|
+ if (CollectionUtils.isNotEmpty(typeOneList)) {
|
|
|
+ List<WaybillOrderStatusResp> rawOreOrdderList = getWaybillOrderStatusResps(param, records, typeOneList,
|
|
|
+ orderSubtaskList,wbOrderIdList, subtaskMap, logOrderIdAndCirculateMap, Boolean.TRUE);
|
|
|
+ ordderList.addAll(rawOreOrdderList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ordderList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询正常流程物流运单
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<WaybillOrderStatusResp> getWaybillOrderStatusResps(WaybillOrderQueryParam param, List<KwtWaybillOrder> records,
|
|
|
+ List<KwtLogisticsOrder> logOrderList,
|
|
|
+ List<KwtWaybillOrderSubtask> orderSubtaskList,
|
|
|
+ List<Long> wbOrderIdList,
|
|
|
+ Map<Long, KwtWaybillOrderSubtask> subtaskMap,
|
|
|
+ Map<Long, KwtLogisticsOrderCirculate> logOrderIdAndCirculateMap,
|
|
|
+ boolean isRawOre) {
|
|
|
+ log.info("开始{}物流运单查询,param:{}", isRawOre ? "原矿运输" : "正常流程", JSON.toJSONString(param));
|
|
|
+ List<Long> logOrderIdList = logOrderList.stream().map(KwtLogisticsOrder::getId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ // 物流订单映射
|
|
|
+ Map<Long, KwtLogisticsOrder> logOrderMap = logOrderList.stream().collect(Collectors.toMap(KwtLogisticsOrder::getId,
|
|
|
Function.identity(), (x, y) -> x));
|
|
|
- Set<Long> tradeIds = logOrderList.stream()
|
|
|
- .map(KwtLogisticsOrder::getTOrderId)
|
|
|
- .collect(Collectors.toSet());
|
|
|
- //获取贸易订单
|
|
|
- List<OrderDetailVo> orderDetailVos = tradeOrderInfoService.queryByTradeOrderIds(tradeIds);
|
|
|
- if (CollectionUtils.isEmpty(orderDetailVos)) {
|
|
|
- log.info("当前车辆的贸易订单无数据,truckNo:{}", param.getTruckNo());
|
|
|
- throw new BusinessPlatfromException(ErrorCodeEnum.TRADE_ORDER_NOT_FOUND, "当前车辆的贸易订单数据不存在");
|
|
|
+
|
|
|
+ // 贸易订单相关(仅非原矿运输查询)
|
|
|
+ Map<Long, OrderDetailVo> tradeIdAndOrderDetailVoMap;
|
|
|
+ Map<Long, List<KwtLogisticsOrder>> tradeIdAndLogOrderList;
|
|
|
+ if (!isRawOre) {
|
|
|
+ Set<Long> tradeIds = logOrderList.stream().map(KwtLogisticsOrder::getTOrderId).collect(Collectors.toSet());
|
|
|
+ //获取贸易订单
|
|
|
+ List<OrderDetailVo> orderDetailVos = tradeOrderInfoService.queryByTradeOrderIds(tradeIds);
|
|
|
+ if (CollectionUtils.isEmpty(orderDetailVos)) {
|
|
|
+ log.info("当前车辆的贸易订单无数据,truckNo:{}", param.getTruckNo());
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.TRADE_ORDER_NOT_FOUND, "当前车辆的贸易订单数据不存在");
|
|
|
+ }
|
|
|
+ tradeIdAndOrderDetailVoMap = orderDetailVos.stream().collect(Collectors.toMap(OrderDetailVo::getId,
|
|
|
+ Function.identity(), (x, y) -> x));
|
|
|
+
|
|
|
+ tradeIdAndLogOrderList = logOrderList.stream().collect(Collectors.groupingBy(KwtLogisticsOrder::getTOrderId));
|
|
|
+ } else {
|
|
|
+ tradeIdAndOrderDetailVoMap = new HashMap<>();
|
|
|
+ tradeIdAndLogOrderList = new HashMap<>();
|
|
|
}
|
|
|
- Map<Long, OrderDetailVo> tradeIdAndOrderDetailVoMap = orderDetailVos.stream()
|
|
|
- .collect(Collectors.toMap(OrderDetailVo::getId, Function.identity(), (x, y) -> x));
|
|
|
|
|
|
- Map<Long, List<KwtLogisticsOrder>> tradeIdAndLogOrderList = logOrderList.stream()
|
|
|
- .collect(Collectors.groupingBy(KwtLogisticsOrder::getTOrderId));
|
|
|
+ // 子任务分组
|
|
|
Map<Long, List<KwtWaybillOrderSubtask>> logisticsOrderIdAndSubtaskList = orderSubtaskList.stream()
|
|
|
.collect(Collectors.groupingBy(KwtWaybillOrderSubtask::getLOrderId));
|
|
|
|
|
|
@@ -785,7 +1025,6 @@ public class WaybillOrderService {
|
|
|
}
|
|
|
Map<Long, KwpGoods> goodsIdAndGoodsMap = goodsInfoService.getGoodsByIds(goodsIds);
|
|
|
|
|
|
-
|
|
|
//承运托运企业
|
|
|
List<KwtLogisticsOrderUnit> logOrderUnits = logisticsOrderUnitRepository.queryByLogOrderIds(logOrderIdList);
|
|
|
if (CollectionUtils.isEmpty(logOrderUnits)) {
|
|
|
@@ -804,22 +1043,24 @@ public class WaybillOrderService {
|
|
|
log.info("当前车辆无物流运单装卸货信息,truckNo:{}", param.getTruckNo());
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_TICKET, "当前车辆无物流运单装卸货信息");
|
|
|
}
|
|
|
- Map<String, KwtWaybillOrderTicket> ticketMap = orderTicketList.stream().collect(
|
|
|
- Collectors.toMap(ticket -> ticket.getWOrderId() + "-" + ticket.getType(),
|
|
|
+ Map<String, KwtWaybillOrderTicket> ticketMap = orderTicketList.stream()
|
|
|
+ .collect(Collectors.toMap(ticket -> ticket.getWOrderId() + "-" + ticket.getType(),
|
|
|
Function.identity(), (x, y) -> x));
|
|
|
|
|
|
//查询字典
|
|
|
Map<String, Map<String, String>> dictValueAndDictResDtoMap = remoteSystemService.queryDictByType(
|
|
|
Arrays.asList(DictTypeEnum.PRODUCT_NAME_TYPE.getType(), DictTypeEnum.GOODS_SPEC.getType()));
|
|
|
|
|
|
- List<WaybillOrderStatusResp> ordderList = records.stream().map(
|
|
|
- billOrder -> {
|
|
|
+ List<WaybillOrderStatusResp> orderList = records.stream()
|
|
|
+ .filter(record -> record.getLOrderId() != null && logOrderIdList.contains(record.getLOrderId()))
|
|
|
+ .map(billOrder -> {
|
|
|
return getWaybillOrderResp(billOrder, subtaskMap, logOrderMap, logOrderIdAndCirculateMap,
|
|
|
logOrderIdAndGoodsMap, logOrderIdAndUnitMap, logOrderIdAndAddressMap, ticketMap,
|
|
|
tradeIdAndOrderDetailVoMap,tradeIdAndLogOrderList,logisticsOrderIdAndSubtaskList,
|
|
|
dictValueAndDictResDtoMap, goodsIdAndGoodsMap);
|
|
|
}).collect(Collectors.toList());
|
|
|
- return ordderList;
|
|
|
+ log.info("{}物流运单查询结束,result:{}", isRawOre ? "原矿运输" : "正常流程", JSON.toJSONString(orderList));
|
|
|
+ return orderList;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -848,6 +1089,8 @@ public class WaybillOrderService {
|
|
|
wbOrderResp.setLogisticsOrderId(Optional.ofNullable(wbOrder.getLOrderId()).map(String::valueOf).orElse(null));
|
|
|
wbOrderResp.setWaybillNo(wbOrder.getWOrderNo());
|
|
|
wbOrderResp.setRemark(wbOrder.getRemark());
|
|
|
+ wbOrderResp.setLabel(wbOrder.getLabel());
|
|
|
+ wbOrderResp.setUpdateTime(wbOrder.getUpdateTime());
|
|
|
//装货、卸货净重、任务量
|
|
|
KwtWaybillOrderSubtask subtask = subtaskMap.getOrDefault(wbOrder.getId(), new KwtWaybillOrderSubtask());
|
|
|
wbOrderResp.setLoadingNetWeight(subtask.getLoadAmount());
|
|
|
@@ -859,11 +1102,13 @@ public class WaybillOrderService {
|
|
|
wbOrderResp.setLogisticsOrderNo(logOrder.getLOrderNo());
|
|
|
wbOrderResp.setChargeType(logOrder.getBillingMode());
|
|
|
wbOrderResp.setChargeTypeDesc(DictEnum.getLabel(DictTypeEnum.CHARGING_TYPE.getType(), logOrder.getBillingMode()));
|
|
|
+ wbOrderResp.setOrderType(logOrder.getOrderType());
|
|
|
+
|
|
|
//设置余量
|
|
|
- KwtLogisticsOrder order = logOrderMap.getOrDefault(wbOrder.getLOrderId(), new KwtLogisticsOrder());
|
|
|
- BigDecimal supAmount = getSupAmount(order.getTOrderId(), tradeIdAndOrderDetailVoMap, tradeIdAndLogOrderList,
|
|
|
- logisticsOrderIdAndSubtaskList);
|
|
|
+ BigDecimal supAmount = Objects.equals(1, logOrder.getOrderType()) ? getRawOreSupAmount(logOrder, logisticsOrderIdAndSubtaskList)
|
|
|
+ : getSupAmount(logOrder.getTOrderId(), tradeIdAndOrderDetailVoMap, tradeIdAndLogOrderList, logisticsOrderIdAndSubtaskList);
|
|
|
wbOrderResp.setOrderSurplus(supAmount);
|
|
|
+
|
|
|
//托运企业
|
|
|
KwtLogisticsOrderUnit consignEnt = logOrderIdAndUnitMap.getOrDefault(wbOrder.getLOrderId() + "-" + UnitTypeEnum.CONSIGN.getCode(), new KwtLogisticsOrderUnit());
|
|
|
wbOrderResp.setConsignCompanyId(Optional.ofNullable(consignEnt.getEntId()).map(String::valueOf).orElse(null));
|
|
|
@@ -924,7 +1169,11 @@ public class WaybillOrderService {
|
|
|
} else if (Objects.equals(wbOrder.getStatus(), CarWaybillV1Enum.COMPLETION_LOADING.getCode())) {
|
|
|
wbOrderResp.setStatusDesc("待审核");
|
|
|
} else if (Objects.equals(wbOrder.getStatus(), CarWaybillV1Enum.COMPLETED.getCode())) {
|
|
|
- wbOrderResp.setStatusDesc("已完成");
|
|
|
+ if (Objects.equals(subtask.getRemark(), "空载离场")) {
|
|
|
+ wbOrderResp.setStatusDesc("空载完成");
|
|
|
+ } else {
|
|
|
+ wbOrderResp.setStatusDesc("已完成");
|
|
|
+ }
|
|
|
} else if (Objects.equals(wbOrder.getStatus(), CarWaybillV1Enum.REVIEW_REJECTION.getCode())) {
|
|
|
wbOrderResp.setStatusDesc("待修改");
|
|
|
} else if (Objects.equals(wbOrder.getStatus(), CarWaybillV1Enum.CANCELLED.getCode())) {
|
|
|
@@ -1021,6 +1270,75 @@ public class WaybillOrderService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算贸易订单余量
|
|
|
+ * 逻辑:贸易订单总量 - (所有关联物流订单下,非取消/完成状态的子运单委托量 + 对应计费模式的磅单量)
|
|
|
+ *
|
|
|
+ * @param tradeOrderId 贸易订单ID
|
|
|
+ * @param tradeIdAndOrderDetailVoMap 贸易订单详情映射
|
|
|
+ * @param tradeIdAndLogOrderList 贸易订单关联的物流订单列表映射
|
|
|
+ * @param logisticsOrderIdAndSubtaskList 物流订单关联的子运单列表映射
|
|
|
+ * @param waybillOrderIdAndTicketList 运单ID关联的磅单列表映射
|
|
|
+ * @return 订单余量,保留两位小数
|
|
|
+ */
|
|
|
+ private BigDecimal getRawOreSupAmount(KwtLogisticsOrder order,
|
|
|
+ Map<Long, List<KwtWaybillOrderSubtask>> logisticsOrderIdAndSubtaskList) {
|
|
|
+ log.debug("开始计算物流订单余量,param: {}", JSON.toJSONString(order));
|
|
|
+
|
|
|
+ // 1. 获取贸易订单总货物量
|
|
|
+ BigDecimal tradeAmount = order.getAmount();
|
|
|
+ log.debug("物流订单[{}]总货物量: {}", order.getId(), tradeAmount);
|
|
|
+
|
|
|
+ Long logOrderId = order.getId();
|
|
|
+ // 获取当前物流订单下的所有子运单
|
|
|
+ List<KwtWaybillOrderSubtask> waybillOrderSubtasks = logisticsOrderIdAndSubtaskList.getOrDefault(logOrderId, Collections.emptyList());
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(waybillOrderSubtasks)) {
|
|
|
+ BigDecimal tradeTotalAmount = tradeAmount.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : tradeAmount;
|
|
|
+ BigDecimal bigDecimal = tradeTotalAmount.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ log.debug("物流订单[{}]无子运单,跳过, 最终余量: {}",logOrderId, bigDecimal);
|
|
|
+ return bigDecimal;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 定义需要剔除的状态:已取消、已完成、空载(这些状态下的运单不再占用当前可接单的余量,或者其量已结算)
|
|
|
+ // 注意:具体业务逻辑中,通常“进行中”的运单会占用余量。这里根据原代码逻辑,剔除CANCELLED和COMPLETED。
|
|
|
+ // 空载待离场,实际装货量接近0,所以也要剔除
|
|
|
+ List<Integer> excludeStatusList = Arrays.asList(CarWaybillV1Enum.CANCELLED.getCode(), CarWaybillV1Enum.COMPLETED.getCode()
|
|
|
+ , CarWaybillV1Enum.EMPTY_WAIT_LEAVE.getCode());
|
|
|
+
|
|
|
+ // 4. 计算子运单委托量合计(仅统计未取消/未完成/空载的有效子运单)
|
|
|
+ BigDecimal entrustAmount = waybillOrderSubtasks.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(subtask -> !excludeStatusList.contains(subtask.getStatus()))
|
|
|
+ .map(KwtWaybillOrderSubtask::getEntrustAmount)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ log.debug("物流订单[{}]子运单委托量合计: {}", logOrderId, entrustAmount);
|
|
|
+
|
|
|
+ // 5. 计算运单已完成的合计量
|
|
|
+ BigDecimal totalLoadAmount = order.getTotalLoadAmount();
|
|
|
+ totalLoadAmount = totalLoadAmount == null || totalLoadAmount.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : totalLoadAmount;
|
|
|
+ log.debug("物流订单[{}]有完成的运单实际装货量合计: {}", logOrderId, totalLoadAmount);
|
|
|
+
|
|
|
+ // 累加到总占用量
|
|
|
+ BigDecimal usedAmount = entrustAmount.add(totalLoadAmount);
|
|
|
+
|
|
|
+ log.debug("物流订单[{}]总占用量: {}", logOrderId, usedAmount);
|
|
|
+
|
|
|
+ // 6. 计算余量:贸易订单总量 - 已占用量
|
|
|
+ // 如果计算结果小于等于0,则余量为0,避免负数
|
|
|
+ BigDecimal surplus = tradeAmount.subtract(usedAmount);
|
|
|
+ BigDecimal finalSurplus = surplus.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : surplus;
|
|
|
+
|
|
|
+ // 保留两位小数,四舍五入
|
|
|
+ BigDecimal result = finalSurplus.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ log.debug("物流订单[{}]最终余量: {}", logOrderId, result);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 批量构建运单ID与磅单信息映射,供订单余量计算复用。
|
|
|
*/
|
|
|
@@ -1046,6 +1364,22 @@ public class WaybillOrderService {
|
|
|
.collect(Collectors.groupingBy(KwtWaybillOrderTicket::getWOrderId));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 排序
|
|
|
+ * @param param
|
|
|
+ * @param gatekeeperOrderPageResult
|
|
|
+ */
|
|
|
+ private void sort(WaybillOrderQueryParam param, List<WaybillOrderStatusResp> ordderList) {
|
|
|
+ log.info("运单分页列表排序,param:{}, order:{}", JSON.toJSONString(param), JSON.toJSONString(ordderList));
|
|
|
+ if (CollectionUtils.isEmpty(ordderList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 完成运单,根据时间倒叙排列
|
|
|
+ if (Objects.equals(3, param.getStatus())) {
|
|
|
+ ordderList.sort(Comparator.comparing(WaybillOrderStatusResp::getUpdateTime).reversed());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 运单统计
|
|
|
* @param param
|
|
|
@@ -1294,10 +1628,6 @@ public class WaybillOrderService {
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "当前车辆没有可以称重过磅状态的运单");
|
|
|
}
|
|
|
param.setWaybillOrderId(wbOrderByTruckNo.get(0).getId());
|
|
|
-
|
|
|
- //mock
|
|
|
- param.setWeighbridgeName("测试名称");
|
|
|
- param.setWeighUrl("chengdu.aliyuncs.com/kll/uploads/20251126/792a668bf5034ddc24d7a3dbe4ca88bf1764125000057.png");
|
|
|
comeIntoHandler.handler(param);
|
|
|
}
|
|
|
|
|
|
@@ -1405,6 +1735,42 @@ public class WaybillOrderService {
|
|
|
unloadingHandler.handler(param);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 过磅推送图片
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ public void weighImage(WaybillOrderWeighImageParam param) {
|
|
|
+ if (StringUtils.isBlank(param.getTruckNo())){
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "车牌号不能为空!");
|
|
|
+ }
|
|
|
+ // 定义运单可以过磅的状态集合(无论山上山下地磅)
|
|
|
+ List<Integer> FORBIDDEN_STATUSES = Arrays.asList(
|
|
|
+ CarWaybillV1Enum.PENDING_VEHICLE.getCode(),
|
|
|
+ CarWaybillV1Enum.REFUSE_TRAFFIC.getCode(),
|
|
|
+ CarWaybillV1Enum.EXIT_COMPLETED.getCode(),
|
|
|
+ CarWaybillV1Enum.EMPTY_WAIT_LEAVE.getCode(),
|
|
|
+ CarWaybillV1Enum.WAIT_LEAVE.getCode(),
|
|
|
+ CarWaybillV1Enum.UNLOADING.getCode(),
|
|
|
+ CarWaybillV1Enum.REPLENISHING.getCode(),
|
|
|
+ CarWaybillV1Enum.REPLENISH_FINISH.getCode(),
|
|
|
+ CarWaybillV1Enum.WAIT_LOADING.getCode(),
|
|
|
+ CarWaybillV1Enum.UNLOADING_POINT.getCode()
|
|
|
+ );
|
|
|
+ List<KwtWaybillOrder> wbOrderByTruckNo = waybillOrderRepository.findWbOrderByTruckNoAndStatus(param.getTruckNo(), FORBIDDEN_STATUSES);
|
|
|
+ if (CollectionUtils.isEmpty(wbOrderByTruckNo)) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "[过磅推送图片]当前车辆没有可以过磅称重状态的运单");
|
|
|
+ }
|
|
|
+ if (wbOrderByTruckNo.size() > 1) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "[过磅推送图片]当前车辆过磅称重状态存在多条运单");
|
|
|
+ }
|
|
|
+ KwtWaybillOrder waybillOrder = wbOrderByTruckNo.get(0);
|
|
|
+ KwtWaybillOrderNode waybillOrderNode = waybillOrderNodeRepository.queryNodesByOrderId(waybillOrder.getId(), waybillOrder.getStatus());
|
|
|
+ if (waybillOrderNode == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "[过磅推送图片]未查询运单节点数据");
|
|
|
+ }
|
|
|
+ waybillOrderNode.setWeighUrl(param.getWeighUrl());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
// /**
|