|
|
@@ -17,6 +17,8 @@ import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.DateUtils;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
|
import com.sckw.core.web.response.result.PageDataResult;
|
|
|
+import com.sckw.fleet.api.RemoteFleetService;
|
|
|
+import com.sckw.fleet.api.model.vo.RTruckVo;
|
|
|
import com.sckw.order.api.dubbo.TradeOrderInfoService;
|
|
|
import com.sckw.order.api.model.OrderUnitInfoDetailVO;
|
|
|
import com.sckw.product.api.dubbo.GoodsInfoService;
|
|
|
@@ -35,7 +37,9 @@ import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -75,6 +79,9 @@ public class GatekeeperOrderService {
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
|
|
|
GoodsInfoService goodsInfoService;
|
|
|
|
|
|
+ @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
|
|
|
+ protected RemoteFleetService remoteFleetService;
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
|
WaybillOrderService waybillOrderService;
|
|
|
@@ -609,6 +616,19 @@ public class GatekeeperOrderService {
|
|
|
if (gatekeeper == null) {
|
|
|
throw new BusinessPlatfromException(ErrorCodeEnum.FORKLIFT_ORDER_NOT_FOUND, "当前门卫订单不存在!");
|
|
|
}
|
|
|
+ //放行后 mock抬杆流程
|
|
|
+// mockPass(param, gatekeeper);
|
|
|
+
|
|
|
+ //放行后直接抬杆离场
|
|
|
+ driverPass(param, gatekeeper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 放行后 mock抬杆流程
|
|
|
+ * @param param
|
|
|
+ * @param gatekeeper
|
|
|
+ */
|
|
|
+ private void mockPass(GatekeeperOrderPassParam param, KwtGatekeeperWaybillOrder gatekeeper) {
|
|
|
//1. 更改门卫状态为:已放行
|
|
|
updateGatekeeperOrderStatus(gatekeeper, param);
|
|
|
|
|
|
@@ -758,6 +778,213 @@ public class GatekeeperOrderService {
|
|
|
log.info("[门卫放行]记录节点轨迹成功,节点ID:{}", node.getId());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 放行后直接离场
|
|
|
+ * @param param
|
|
|
+ * @param gatekeeper
|
|
|
+ */
|
|
|
+ private void driverPass(GatekeeperOrderPassParam param, KwtGatekeeperWaybillOrder gatekeeper) {
|
|
|
+ // 查询运单
|
|
|
+ KwtWaybillOrder waybillOrder = waybillOrderRepository.getById(gatekeeper.getWOrderId());
|
|
|
+ if (waybillOrder == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.FORKLIFT_ORDER_NOT_FOUND, "[门卫放行]当前运单数据不存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //1. 计算是否空载离场
|
|
|
+ Boolean isEmptyLoadLeave = calculateEmptyLoad(waybillOrder);
|
|
|
+
|
|
|
+ //2. 更改门卫状态为:已离场
|
|
|
+ updateGatekeeperOrderStatus2(gatekeeper, param, isEmptyLoadLeave);
|
|
|
+
|
|
|
+ //3. 更改司机状态为:已离场
|
|
|
+ updateWaybillOrderStatus2(gatekeeper, param, waybillOrder, isEmptyLoadLeave);
|
|
|
+
|
|
|
+ //4. 创建门卫卸货订单
|
|
|
+ creatGatekeeperUnLoadingOrder(waybillOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算是否空载离场
|
|
|
+ * @param waybillOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Boolean calculateEmptyLoad(KwtWaybillOrder waybillOrder) {
|
|
|
+ //查询运单装卸货信息
|
|
|
+ KwtWaybillOrderTicket orderTicket = waybillOrderTicketRepository.queryByWOrderIdByIdAndType(waybillOrder.getId(), 1);
|
|
|
+ if (orderTicket == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_TICKET_NOT_FOUND, "当前物流运单装卸货信息不存在,无法记录皮重!");
|
|
|
+ }
|
|
|
+ BigDecimal loadAmount = orderTicket.getAmount();
|
|
|
+
|
|
|
+ //空载离场,净重<=0.5
|
|
|
+ return loadAmount != null && loadAmount.compareTo(BigDecimal.valueOf(0.5)) <= 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更改门卫状态为:已放行
|
|
|
+ * @param gatekeeper
|
|
|
+ */
|
|
|
+ private void updateGatekeeperOrderStatus2(KwtGatekeeperWaybillOrder gatekeeper, GatekeeperOrderPassParam param, Boolean isEmptyLoadLeave) {
|
|
|
+ if (!GatekeeperStatusEnum.PENDING_RELEASE.getCode().equals(gatekeeper.getStatus())) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.FORKLIFT_ORDER_STATUS_ERROR, "当前门卫订单状态异常,不能放行!");
|
|
|
+ }
|
|
|
+ //门卫放行后状态更改为:已离场/空载离场
|
|
|
+ GatekeeperStatusEnum targetStatus = isEmptyLoadLeave ? GatekeeperStatusEnum.EMPTY_EXITED : GatekeeperStatusEnum.EXITED;
|
|
|
+ gatekeeper.setStatus(targetStatus.getCode());
|
|
|
+ gatekeeper.setLeaveTime(new Date());
|
|
|
+ gatekeeper.setGatekeeperUserId(param.getGatekeeperUserId());
|
|
|
+ gatekeeper.setGatekeeperName(param.getGatekeeperName());
|
|
|
+ gatekeeper.setUpdateUser(param.getGatekeeperUserId());
|
|
|
+ gatekeeperWaybillOrderRepository.updateById(gatekeeper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更改司机状态为:已离场
|
|
|
+ * @param gatekeeper
|
|
|
+ */
|
|
|
+ private void updateWaybillOrderStatus2(KwtGatekeeperWaybillOrder gatekeeper, GatekeeperOrderPassParam param,
|
|
|
+ KwtWaybillOrder waybillOrder, Boolean isEmptyLoadLeave) {
|
|
|
+ // 1. 修改运单状态:已离场
|
|
|
+ updateWaybillStatus2(gatekeeper, waybillOrder, isEmptyLoadLeave);
|
|
|
+
|
|
|
+ // 2. 修改子运单状态:已离场
|
|
|
+ updateWaybillSubtaskStatus2(gatekeeper, isEmptyLoadLeave);
|
|
|
+
|
|
|
+ // 3.创建运单轨迹日日志
|
|
|
+ creatWaybillOrderNode(gatekeeper, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改运单状态
|
|
|
+ * @param gatekeeper
|
|
|
+ */
|
|
|
+ private void updateWaybillStatus2(KwtGatekeeperWaybillOrder gatekeeper, KwtWaybillOrder waybillOrder,Boolean isEmptyLoadLeave) {
|
|
|
+ //装货单
|
|
|
+ if (Objects.equals(gatekeeper.getType(), GatekeeperTypeEnum.LOADING.getCode())) {
|
|
|
+ if (!CarWaybillV1Enum.WAIT_RELEASE.getCode().equals(waybillOrder.getStatus())) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_STATUS_ERROR, "当前运单状态异常,不能推进为已离场!");
|
|
|
+ }
|
|
|
+ // 校验状态:若是空载离场,运单状态为已完成
|
|
|
+ CarWaybillV1Enum status = isEmptyLoadLeave ? CarWaybillV1Enum.COMPLETED : CarWaybillV1Enum.WAIT_LOADING;
|
|
|
+ if (isEmptyLoadLeave) {
|
|
|
+ waybillOrder.setRemark("空载离场");
|
|
|
+ }
|
|
|
+ waybillOrder.setStatus(status.getCode());
|
|
|
+ } else {
|
|
|
+ //卸货单校验
|
|
|
+ if (!CarWaybillV1Enum.UNLOADING_WAIT_RELEASE.getCode().equals(waybillOrder.getStatus())) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_STATUS_ERROR, "当前运单状态异常,不能推进为已完成!");
|
|
|
+ }
|
|
|
+ waybillOrder.setStatus(CarWaybillV1Enum.COMPLETED.getCode());
|
|
|
+ }
|
|
|
+ waybillOrderRepository.updateById(waybillOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改子运单状态
|
|
|
+ * @param gatekeeper
|
|
|
+ */
|
|
|
+ private void updateWaybillSubtaskStatus2(KwtGatekeeperWaybillOrder gatekeeper, Boolean isEmptyLoadLeave) {
|
|
|
+ KwtWaybillOrderSubtask waybillSubtask = waybillOrderSubtaskRepository.queryByWOrderId(gatekeeper.getWOrderId());
|
|
|
+ if (waybillSubtask == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_SUB_NOT_FOUND, "未找到关联的子运单!");
|
|
|
+ }
|
|
|
+ //装货单
|
|
|
+ if (Objects.equals(gatekeeper.getType(), GatekeeperTypeEnum.LOADING.getCode())) {
|
|
|
+ if (!CarWaybillV1Enum.WAIT_RELEASE.getCode().equals(waybillSubtask.getStatus())) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_STATUS_ERROR, "当前子运单状态异常,不能推进为已离场!");
|
|
|
+ }
|
|
|
+ // 校验状态:若是空载离场,运单状态为已完成
|
|
|
+ CarWaybillV1Enum status = isEmptyLoadLeave ? CarWaybillV1Enum.COMPLETED : CarWaybillV1Enum.WAIT_LOADING;
|
|
|
+ waybillSubtask.setStatus(status.getCode());
|
|
|
+ } else {
|
|
|
+ //卸货单校验
|
|
|
+ if (!CarWaybillV1Enum.UNLOADING_WAIT_RELEASE.getCode().equals(waybillSubtask.getStatus())) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_STATUS_ERROR, "当前子运单状态异常,不能推进为已完成!");
|
|
|
+ }
|
|
|
+ waybillSubtask.setStatus(CarWaybillV1Enum.COMPLETED.getCode());
|
|
|
+ }
|
|
|
+ waybillOrderSubtaskRepository.updateById(waybillSubtask);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建卸货门卫订单
|
|
|
+ *
|
|
|
+ * @param waybillOrder
|
|
|
+ */
|
|
|
+ private void creatGatekeeperUnLoadingOrder(KwtWaybillOrder waybillOrder) {
|
|
|
+ // 只有原矿运输的才会新增卸货门卫订单
|
|
|
+ KwtLogisticsOrder logisticsOrder = getLogisticsOrder(waybillOrder.getLOrderId());
|
|
|
+ if (!Objects.equals(1, logisticsOrder.getStatus())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ RTruckVo truck = remoteFleetService.findTruckByTruckNo(waybillOrder.getTruckNo());
|
|
|
+ if (truck == null || !Objects.equals(truck.getStatus(), 0)) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.TRUCK_STATUS_ERROR, "当前车辆非正常状态,不能接单!");
|
|
|
+ }
|
|
|
+ //查询子运单
|
|
|
+ KwtWaybillOrderSubtask waybillSubtask = getWaybillSubtask(waybillOrder.getId());
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ KwtGatekeeperWaybillOrder gatekeeper = new KwtGatekeeperWaybillOrder();
|
|
|
+ gatekeeper.setEntId(waybillOrder.getEntId());
|
|
|
+ gatekeeper.setWOrderId(waybillOrder.getId());
|
|
|
+ gatekeeper.setWOrderNo(waybillOrder.getWOrderNo());
|
|
|
+ gatekeeper.setLOrderId(waybillOrder.getLOrderId());
|
|
|
+ // 查询商品信息
|
|
|
+ KwtLogisticsOrderGoods orderGoods = logisticsOrderGoodsRepository.queryByLogOrderId(waybillOrder.getLOrderId());
|
|
|
+ if (orderGoods != null) {
|
|
|
+ gatekeeper.setGoodsId(orderGoods.getGoodsId());
|
|
|
+ gatekeeper.setGoodsName(orderGoods.getGoodsName());
|
|
|
+ }
|
|
|
+ gatekeeper.setWaybillAcceptTime(waybillOrder.getCreateTime());
|
|
|
+ gatekeeper.setType(GatekeeperTypeEnum.UNLOADING.getCode());
|
|
|
+ gatekeeper.setStatus(GatekeeperStatusEnum.PENDING_ENTRY.getCode());
|
|
|
+ gatekeeper.setWaybillAcceptTime(waybillOrder.getCreateTime());
|
|
|
+ gatekeeper.setTruckType(truck.getTruckType());
|
|
|
+ gatekeeper.setEntrustAmount(waybillSubtask.getEntrustAmount());
|
|
|
+ gatekeeper.setCarAxis(truck.getCarAxis());
|
|
|
+ gatekeeper.setLegalLoad(truck.getLegalLoad());
|
|
|
+ gatekeeper.setCreateTime(new Date());
|
|
|
+ gatekeeper.setCreateUser(waybillOrder.getDriverId());
|
|
|
+ gatekeeper.setUpdateUser(waybillOrder.getDriverId());
|
|
|
+
|
|
|
+ log.debug("开始异步保存卸货门卫订单数据,运单ID:{}", waybillOrder.getId());
|
|
|
+ gatekeeperWaybillOrderRepository.save(gatekeeper);
|
|
|
+ log.debug("卸货门卫订单数据保存成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("异步保存卸货门卫订单数据失败!");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询物流订单
|
|
|
+ */
|
|
|
+ protected KwtLogisticsOrder getLogisticsOrder(Long logOrderId) {
|
|
|
+ KwtLogisticsOrder logisticsOrder = logisticsOrderRepository.queryByLogisticsOrderId(logOrderId);
|
|
|
+ if (logisticsOrder == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.LOGISTICS_ORDER_NOT_FOUND, "物流订单数据不存在!");
|
|
|
+ }
|
|
|
+ return logisticsOrder;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询子运单
|
|
|
+ */
|
|
|
+ protected KwtWaybillOrderSubtask getWaybillSubtask(Long waybillOrderId) {
|
|
|
+ KwtWaybillOrderSubtask subtask = waybillOrderSubtaskRepository.queryByWOrderId(waybillOrderId);
|
|
|
+ if (subtask == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_SUB_NOT_FOUND, "未找到关联的子运单!");
|
|
|
+ }
|
|
|
+ return subtask;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 校验是否可放行
|
|
|
* @param gatekeeper
|