|
@@ -15,6 +15,7 @@ import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.model.enums.CarWaybillV1Enum;
|
|
import com.sckw.core.model.enums.CarWaybillV1Enum;
|
|
|
import com.sckw.core.model.enums.GatekeeperStatusEnum;
|
|
import com.sckw.core.model.enums.GatekeeperStatusEnum;
|
|
|
import com.sckw.core.model.enums.GatekeeperTypeEnum;
|
|
import com.sckw.core.model.enums.GatekeeperTypeEnum;
|
|
|
|
|
+import com.sckw.core.model.enums.LogisticsOrderV1Enum;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.DateUtils;
|
|
import com.sckw.core.utils.DateUtils;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
import com.sckw.core.utils.StringUtils;
|
|
@@ -45,7 +46,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -95,6 +95,24 @@ public class GatekeeperOrderService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
WaybillOrderService waybillOrderService;
|
|
WaybillOrderService waybillOrderService;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 定义运单未完结的状态集合
|
|
|
|
|
+ private static final List<Integer> UNFINISHED_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.WAIT_RELEASE.getCode(),
|
|
|
|
|
+ CarWaybillV1Enum.REPLENISHING.getCode(),
|
|
|
|
|
+ CarWaybillV1Enum.REPLENISH_FINISH.getCode(),
|
|
|
|
|
+ CarWaybillV1Enum.RELEASED_NOT_EXITED.getCode(),
|
|
|
|
|
+ CarWaybillV1Enum.WAIT_LOADING.getCode(),
|
|
|
|
|
+ CarWaybillV1Enum.COMPLETION_LOADING.getCode(),
|
|
|
|
|
+ CarWaybillV1Enum.REVIEW_REJECTION.getCode()
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 分页查询门卫订单
|
|
* 分页查询门卫订单
|
|
|
* @param param
|
|
* @param param
|
|
@@ -735,8 +753,35 @@ public class GatekeeperOrderService {
|
|
|
|
|
|
|
|
//放行后直接抬杆离场
|
|
//放行后直接抬杆离场
|
|
|
driverPass(param, gatekeeper);
|
|
driverPass(param, gatekeeper);
|
|
|
|
|
+
|
|
|
|
|
+ //更新物流订单装货量
|
|
|
|
|
+ updateLogisticsOrderAmot(gatekeeper);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 原矿运输更新物流订单装货量
|
|
|
|
|
+ * @param gatekeeper
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateLogisticsOrderAmot(KwtGatekeeperWaybillOrder gatekeeper) {
|
|
|
|
|
+ //查询物流订单
|
|
|
|
|
+ KwtLogisticsOrder logisticsOrder = getLogisticsOrder(gatekeeper.getLOrderId());
|
|
|
|
|
+
|
|
|
|
|
+ //原矿运输的,按照装货量计算更改物流订单装货量
|
|
|
|
|
+ if (Objects.equals(logisticsOrder.getOrderType(), 1) && Objects.equals(gatekeeper.getType(), 2)) {
|
|
|
|
|
+ //计算净装货量
|
|
|
|
|
+ BigDecimal loadAmount = getLoadAmount(gatekeeper.getWOrderId());
|
|
|
|
|
+
|
|
|
|
|
+ KwtWaybillOrder waybillOrder = getWaybillOrder(gatekeeper.getWOrderId());
|
|
|
|
|
+
|
|
|
|
|
+ //1.更新物流订单装货量
|
|
|
|
|
+ updateLogisticsOrder(waybillOrder, logisticsOrder, loadAmount);
|
|
|
|
|
+
|
|
|
|
|
+ //2.解绑车辆
|
|
|
|
|
+ unbindTruck(waybillOrder);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 放行后 mock抬杆流程
|
|
* 放行后 mock抬杆流程
|
|
|
* @param param
|
|
* @param param
|
|
@@ -1105,6 +1150,75 @@ public class GatekeeperOrderService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算装货单装货净量
|
|
|
|
|
+ * @param waybillOrderId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private BigDecimal getLoadAmount(Long waybillOrderId) {
|
|
|
|
|
+ KwtWaybillOrderTicket ticket = waybillOrderTicketRepository.queryByWOrderIdByIdAndType(waybillOrderId, 1);
|
|
|
|
|
+ if (ticket == null) {
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_TICKET_NOT_FOUND, "当前物流运单装货单信息不存在!");
|
|
|
|
|
+ }
|
|
|
|
|
+ //装货净重
|
|
|
|
|
+ return ticket.getAmount();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新物流订单装货量和已委托量
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateLogisticsOrder(KwtWaybillOrder waybill, KwtLogisticsOrder logisticsOrder, BigDecimal loadAmount) {
|
|
|
|
|
+ //查询子运单
|
|
|
|
|
+ KwtWaybillOrderSubtask subtask = getWaybillSubtask(waybill.getId());
|
|
|
|
|
+
|
|
|
|
|
+ //物流订单装货量累加
|
|
|
|
|
+ BigDecimal currentTotalLoad = Optional.ofNullable(logisticsOrder.getTotalLoadAmount())
|
|
|
|
|
+ .filter(amount -> amount.compareTo(BigDecimal.ZERO) > 0)
|
|
|
|
|
+ .orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal totalLoadAmount = currentTotalLoad.add(Optional.ofNullable(loadAmount).orElse(BigDecimal.ZERO));
|
|
|
|
|
+ logisticsOrder.setTotalLoadAmount(totalLoadAmount);
|
|
|
|
|
+
|
|
|
|
|
+ // 物流订单已委托量扣减
|
|
|
|
|
+ BigDecimal currentEntrust = Optional.ofNullable(logisticsOrder.getEntrustAmount())
|
|
|
|
|
+ .filter(amount -> amount.compareTo(BigDecimal.ZERO) > 0)
|
|
|
|
|
+ .orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal subtractAmount = Optional.ofNullable(subtask.getEntrustAmount()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal totalEntrustAmount = currentEntrust.subtract(subtractAmount);
|
|
|
|
|
+ // 确保已委托量不为负数
|
|
|
|
|
+ logisticsOrder.setEntrustAmount(totalEntrustAmount.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : totalEntrustAmount);
|
|
|
|
|
+ //如果当前运单的物流订单下没有其它进行中的运单,则修改物流订单状态已完成
|
|
|
|
|
+ if (Objects.equals(LogisticsOrderV1Enum.NEARING_COMPLETION.getCode(), logisticsOrder.getStatus())) {
|
|
|
|
|
+ List<KwtWaybillOrder> waybillOrderList = waybillOrderRepository
|
|
|
|
|
+ .findOneByLogOrderIdAndStatus(logisticsOrder.getId(), UNFINISHED_STATUSES, subtask.getWOrderId());
|
|
|
|
|
+ if (CollectionUtils.isEmpty(waybillOrderList)) {
|
|
|
|
|
+ logisticsOrder.setStatus(LogisticsOrderV1Enum.COMPLETED.getCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ logisticsOrderRepository.updateById(logisticsOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解绑车辆
|
|
|
|
|
+ * @param waybillOrder
|
|
|
|
|
+ */
|
|
|
|
|
+ private void unbindTruck(KwtWaybillOrder waybillOrder) {
|
|
|
|
|
+ //查询运单运单信息
|
|
|
|
|
+ remoteFleetService.unbindTruck(waybillOrder.getEntId(), waybillOrder.getDriverId());
|
|
|
|
|
+ log.info("运单完成,解绑司机与车辆关系,运单id:{},企业id:{},司机id:{}", waybillOrder.getId(), waybillOrder.getEntId(), waybillOrder.getDriverId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询运单
|
|
|
|
|
+ */
|
|
|
|
|
+ protected KwtWaybillOrder getWaybillOrder(Long waybillOrderId) {
|
|
|
|
|
+ KwtWaybillOrder waybillOrder = waybillOrderRepository.queryByBillOrderId(waybillOrderId);
|
|
|
|
|
+ if (waybillOrder == null) {
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "物流运单不存在!");
|
|
|
|
|
+ }
|
|
|
|
|
+ return waybillOrder;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询物流订单
|
|
* 查询物流订单
|
|
|
*/
|
|
*/
|