|
|
@@ -4,14 +4,21 @@ package com.sckw.transport.handler;
|
|
|
import com.sckw.core.common.enums.enums.ErrorCodeEnum;
|
|
|
import com.sckw.core.exception.BusinessPlatfromException;
|
|
|
import com.sckw.core.model.enums.CarWaybillV1Enum;
|
|
|
-import com.sckw.transport.model.KwtWaybillOrder;
|
|
|
-import com.sckw.transport.model.KwtWaybillOrderSubtask;
|
|
|
-import com.sckw.transport.model.KwtWaybillOrderTicket;
|
|
|
+import com.sckw.core.model.enums.GatekeeperStatusEnum;
|
|
|
+import com.sckw.core.model.enums.GatekeeperTypeEnum;
|
|
|
+import com.sckw.core.utils.StringUtils;
|
|
|
+import com.sckw.transport.model.*;
|
|
|
+import com.sckw.transport.model.enuma.WeighbridgeTypeEnum;
|
|
|
import com.sckw.transport.model.param.WaybillOrderUnloadingWeighParam;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
/**
|
|
|
* Author: donglang
|
|
|
@@ -31,8 +38,8 @@ public class UnloadingWeighHandler extends AbstractWaybillOrderHandler<WaybillOr
|
|
|
|
|
|
@Override
|
|
|
protected void checkState(WaybillOrderUnloadingWeighParam param, KwtWaybillOrder waybillOrder) {
|
|
|
- if (!Objects.equals(CarWaybillV1Enum.WAIT_LOADING.getCode(), waybillOrder.getStatus())) {
|
|
|
- throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_STATUS_ERROR, "运单状态不是“已离场”状态,无法推进下一节点!");
|
|
|
+ if (StringUtils.isBlank(param.getTruckNo())) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "车牌号不能为空!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -42,10 +49,125 @@ public class UnloadingWeighHandler extends AbstractWaybillOrderHandler<WaybillOr
|
|
|
if (takeTicket == null) {
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_TICKET_NOT_FOUND, "当前物流运单卸货单信息不存在,无法记录毛重!");
|
|
|
}
|
|
|
+ //校验是否第一次卸货过磅
|
|
|
+ if (checkIsFirst(waybillOrder)) {
|
|
|
+ //第一次卸货过磅
|
|
|
+ firstWeighbridge(param, waybillOrder, takeTicket);
|
|
|
+ } else {
|
|
|
+ //第二次过磅
|
|
|
+ laterWeighbridge(param,waybillOrder, takeTicket);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验是否第一次过磅
|
|
|
+ * @param waybillOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Boolean checkIsFirst(KwtWaybillOrder waybillOrder) {
|
|
|
+ List<KwtWaybillOrderWeighbridge> weighbridges = waybillOrderWeighbridgeRepository
|
|
|
+ .queryWaybillOrderWeighbridgeByWOrderId(waybillOrder.getId(), WeighbridgeTypeEnum.UNLOADING.getCode());
|
|
|
+ return CollectionUtils.isEmpty(weighbridges);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 第一次过磅
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ private void firstWeighbridge(WaybillOrderUnloadingWeighParam param, KwtWaybillOrder waybillOrder, KwtWaybillOrderTicket takeTicket) {
|
|
|
+ if (param.getGrossAmount() == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "毛重不能为空!");
|
|
|
+ }
|
|
|
+ // 校验运单
|
|
|
+ if (!Objects.equals(CarWaybillV1Enum.WAIT_LOADING.getCode(), waybillOrder.getStatus())) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_STATUS_ERROR, "当前物流运单状态不是“已离场”状态,无法卸货称重过磅!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 填充毛重
|
|
|
+ updateWaybillTicketGrossAmount(param, takeTicket);
|
|
|
+
|
|
|
+ // 2.修改门卫卸货状态:卸货已进场
|
|
|
+ updateGatekeeperOrderStatus(waybillOrder);
|
|
|
+
|
|
|
+ // 3.创建卸货过磅记录
|
|
|
+ createWeighbridges(waybillOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充毛重
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ private void updateWaybillTicketGrossAmount(WaybillOrderUnloadingWeighParam param, KwtWaybillOrderTicket takeTicket) {
|
|
|
//填充卸货单毛重
|
|
|
takeTicket.setGrossAmount(param.getGrossAmount());
|
|
|
waybillOrderTicketRepository.updateById(takeTicket);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改门卫卸货状态:卸货已进场
|
|
|
+ * @param waybillOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public void updateGatekeeperOrderStatus(KwtWaybillOrder waybillOrder) {
|
|
|
+ KwtGatekeeperWaybillOrder gatekeeper = gatekeeperWaybillOrderRepository
|
|
|
+ .queryGatekeeperWaybillOrderByWOrderId(waybillOrder.getId(), GatekeeperTypeEnum.UNLOADING.getCode());
|
|
|
+ if (gatekeeper == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.GATEKEEPER_ORDER_NOT_FOUND, "当前门卫订单数据不存在!");
|
|
|
+ }
|
|
|
+ if (!(GatekeeperStatusEnum.IN_YARD.getCode().equals(gatekeeper.getStatus()))) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.GATEKEEPER_ORDER_STATUS_ERROR, "当前门卫订单状态异常,不能推进为待放行状态!");
|
|
|
+ }
|
|
|
+ //修改门卫:待放行
|
|
|
+ gatekeeper.setStatus(GatekeeperStatusEnum.PENDING_RELEASE.getCode());
|
|
|
+ gatekeeperWaybillOrderRepository.updateById(gatekeeper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建卸货过磅记录
|
|
|
+ * @param waybillOrder
|
|
|
+ */
|
|
|
+ private void createWeighbridges(KwtWaybillOrder waybillOrder) {
|
|
|
+ CompletableFuture.runAsync(() ->{
|
|
|
+ try {
|
|
|
+ log.debug("开始异步保存地磅记录,运单ID:{}", waybillOrder.getId());
|
|
|
+ KwtWaybillOrderWeighbridge weighbridge = new KwtWaybillOrderWeighbridge();
|
|
|
+ weighbridge.setWOrderId(waybillOrder.getId());
|
|
|
+ weighbridge.setLOrderId(waybillOrder.getLOrderId());
|
|
|
+ weighbridge.setTruckId(waybillOrder.getTruckId());
|
|
|
+ weighbridge.setTruckNo(waybillOrder.getTruckNo());
|
|
|
+ weighbridge.setType(WeighbridgeTypeEnum.UNLOADING.getCode());
|
|
|
+ weighbridge.setWeighbridgeId(10001l);
|
|
|
+ weighbridge.setWeight(BigDecimal.ZERO);
|
|
|
+ weighbridge.setWeighUrl(null);
|
|
|
+ weighbridge.setCreateTime(new Date());
|
|
|
+ weighbridge.setCreateUser(waybillOrder.getDriverId());
|
|
|
+ weighbridge.setUpdateUser(waybillOrder.getDriverId());
|
|
|
+
|
|
|
+ waybillOrderWeighbridgeRepository.save(weighbridge);
|
|
|
+ log.debug("异步保存过磅数据保存成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_SAVE_FAIL, "异步保存过磅数据失败!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 第二次过磅
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ private void laterWeighbridge(WaybillOrderUnloadingWeighParam param, KwtWaybillOrder waybillOrder, KwtWaybillOrderTicket takeTicket) {
|
|
|
+ if (StringUtils.isBlank(param.getTareAmount())) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "皮重不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //1.填充运单卸货单皮重
|
|
|
+ takeTicket.setTareAmount(param.getTareAmount());
|
|
|
+ waybillOrderTicketRepository.updateById(takeTicket);
|
|
|
|
|
|
+ // 2.创建卸货过磅记录
|
|
|
+ createWeighbridges(waybillOrder);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -55,18 +177,22 @@ public class UnloadingWeighHandler extends AbstractWaybillOrderHandler<WaybillOr
|
|
|
|
|
|
@Override
|
|
|
protected String getProcessName() {
|
|
|
- return "离场过磅";
|
|
|
+ return "卸货离场过磅";
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void getStatus(KwtWaybillOrder waybillOrder) {
|
|
|
+ // 校验是否第一次卸货过磅
|
|
|
+ CarWaybillV1Enum status = Objects.equals(waybillOrder.getStatus(), CarWaybillV1Enum.WAIT_LOADING)
|
|
|
+ ? CarWaybillV1Enum.UNLOADING_POINT : CarWaybillV1Enum.UNLOADING_WAIT_LEAVE;
|
|
|
+
|
|
|
// 1. 修改运单状态
|
|
|
- waybillOrder.setStatus(CarWaybillV1Enum.INTO_UNLOADING.getCode());
|
|
|
+ waybillOrder.setStatus(status.getCode());
|
|
|
waybillOrderRepository.updateById(waybillOrder);
|
|
|
|
|
|
// 2. 修改子运单状态
|
|
|
KwtWaybillOrderSubtask waybillSubtask = getWaybillSubtask(waybillOrder.getId());
|
|
|
- waybillSubtask.setStatus(CarWaybillV1Enum.INTO_UNLOADING.getCode());
|
|
|
+ waybillSubtask.setStatus(status.getCode());
|
|
|
waybillOrderSubtaskRepository.updateById(waybillSubtask);
|
|
|
}
|
|
|
|