|
|
@@ -3,6 +3,7 @@ package com.sckw.transport.service;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.model.enums.CarWaybillEnum;
|
|
|
+import com.sckw.core.model.enums.LogisticsOrderEnum;
|
|
|
import com.sckw.core.utils.BeanUtils;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
@@ -17,7 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.cloud.stream.function.StreamBridge;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
@@ -49,20 +49,36 @@ public class KwtWaybillOrderService {
|
|
|
|
|
|
/**
|
|
|
* @param params
|
|
|
- * @desc 派车
|
|
|
+ * @desc 派车-趟次
|
|
|
* @author zk
|
|
|
* @date 2023/7/19
|
|
|
**/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public HttpResult commitSendCar(List<SendCarDto1> params) {
|
|
|
- /**校验是车辆委托量否超过物流订单剩余量**/
|
|
|
+ public HttpResult sendCar(List<SendCarDto1> params) {
|
|
|
+ /**校验物流运单是否可以派车**/
|
|
|
//承运单信息
|
|
|
KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(params.get(0).getLOrderId());
|
|
|
if (logisticsOrder == null) {
|
|
|
return HttpResult.error("订单已不存在!" );
|
|
|
}
|
|
|
|
|
|
- //下游司机委派量累加
|
|
|
+ //状态校验
|
|
|
+ if (logisticsOrder.getStatus() != LogisticsOrderEnum.WAIT_DELIVERY.getCode()
|
|
|
+ && logisticsOrder.getStatus() != LogisticsOrderEnum.IN_TRANSIT.getCode()) {
|
|
|
+ return HttpResult.error("订单"+LogisticsOrderEnum.getName(logisticsOrder.getStatus())+"不能派车!" );
|
|
|
+ }
|
|
|
+
|
|
|
+ //剩余可运量校验
|
|
|
+ BigDecimal entrustAmount = logisticsOrder.getEntrustAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getEntrustAmount();
|
|
|
+ BigDecimal subcontractAmount = logisticsOrder.getSubcontractAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getSubcontractAmount();
|
|
|
+ //历史下游司机委派量 + 分包量
|
|
|
+ BigDecimal entrustAmountTotal = entrustAmount.add(subcontractAmount);
|
|
|
+ if (entrustAmountTotal.compareTo(logisticsOrder.getAmount()) > 0) {
|
|
|
+ return HttpResult.error("剩余可运量已不能派车!" );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**校验是车辆委托量否超过物流订单剩余量**/
|
|
|
+ //下游司机委派量累加(趟次)
|
|
|
BigDecimal ranksAmount = new BigDecimal(Global.AMOUNT);
|
|
|
for (SendCarDto1 sendCarDto:params) {
|
|
|
if (sendCarDto.getType() == Global.NUMERICAL_ONE) {
|
|
|
@@ -70,18 +86,16 @@ public class KwtWaybillOrderService {
|
|
|
if (sendCarDto.getCount() == null || sendCarDto.getCount() <= 0) {
|
|
|
return HttpResult.error(sendCarDto.getTruckNo() + "趟次必须等于或大于0!" );
|
|
|
}
|
|
|
- //核定载量 * 趟次
|
|
|
- Double entrustAmount = sendCarDto.getEntrustAmount() * sendCarDto.getCount();
|
|
|
- ranksAmount = ranksAmount.add(new BigDecimal(entrustAmount));
|
|
|
- }
|
|
|
- }
|
|
|
+ //承运订单该车辆计划运输总量:核定载量 * 趟次
|
|
|
+ Double truckEntrustAmount = sendCarDto.getEntrustAmount() * sendCarDto.getCount();
|
|
|
+ ranksAmount = ranksAmount.add(new BigDecimal(truckEntrustAmount));
|
|
|
|
|
|
- //当前下游司机委派量 + 历史下游司机委派量 + 分包量
|
|
|
- BigDecimal entrustAmount = logisticsOrder.getEntrustAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getEntrustAmount();
|
|
|
- BigDecimal subcontractAmount = logisticsOrder.getSubcontractAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getSubcontractAmount();
|
|
|
- BigDecimal actualAmount = ranksAmount.add(entrustAmount).add(subcontractAmount);
|
|
|
- if (actualAmount.compareTo(logisticsOrder.getAmount()) > 0) {
|
|
|
- return HttpResult.error("累计派车量已大于剩余可运量!" );
|
|
|
+ //当前下游司机委派量 + 历史下游司机委派量 + 分包量
|
|
|
+ BigDecimal actualAmount = ranksAmount.add(entrustAmountTotal);
|
|
|
+ if (actualAmount.compareTo(logisticsOrder.getAmount()) > 0) {
|
|
|
+ return HttpResult.error("累计派车量已大于剩余可运量!" );
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**数据处理**/
|
|
|
@@ -119,17 +133,14 @@ public class KwtWaybillOrderService {
|
|
|
/**KwtWaybillOrder数据组装**/
|
|
|
KwtWaybillOrder waybillOrder = this.setKwtWaybillOrder(sendCarDto);
|
|
|
|
|
|
- /**车辆运单信息**/
|
|
|
- waybillOrderDao.insert(waybillOrder);
|
|
|
-
|
|
|
- /**车辆运单地址信息**/
|
|
|
- loadAddress.setWOrderId(waybillOrder.getId());
|
|
|
- waybillOrderAddressDao.insert(loadAddress);
|
|
|
- unloadAddress.setWOrderId(waybillOrder.getId());
|
|
|
- waybillOrderAddressDao.insert(unloadAddress);
|
|
|
-
|
|
|
- /**车辆运单状态记录**/
|
|
|
- this.setWaybillOrderTrack(waybillOrder.getId(), waybillOrder.getStatus());
|
|
|
+ /**数据存储**/
|
|
|
+ if (sendCarDto.getType() == Global.NUMERICAL_ONE) {
|
|
|
+ //趟次派车存储
|
|
|
+ ranksSave(waybillOrder, loadAddress, unloadAddress);
|
|
|
+ } else {
|
|
|
+ //循环派车存储
|
|
|
+ circulateSave(waybillOrder);
|
|
|
+ }
|
|
|
|
|
|
/**SckwWaybillOrder数据组装**/
|
|
|
SckwWaybillOrder mongoOrder = setSckwWaybillOrder(sendCarDto, waybillOrder, logisticsOrder, loadAddress,
|
|
|
@@ -153,6 +164,52 @@ public class KwtWaybillOrderService {
|
|
|
return HttpResult.ok();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param waybillOrder 车辆订单信息
|
|
|
+ * @param loadAddress 装货地址信息
|
|
|
+ * @param unloadAddress 卸货地址信息
|
|
|
+ * @desc 趟次派车数据存储
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/21
|
|
|
+ **/
|
|
|
+ public void ranksSave(KwtWaybillOrder waybillOrder, KwtWaybillOrderAddress loadAddress, KwtWaybillOrderAddress unloadAddress) {
|
|
|
+ /**车辆运单信息**/
|
|
|
+ waybillOrderDao.insert(waybillOrder);
|
|
|
+
|
|
|
+ /**车辆运单地址信息**/
|
|
|
+ loadAddress.setWOrderId(waybillOrder.getId());
|
|
|
+ waybillOrderAddressDao.insert(loadAddress);
|
|
|
+ unloadAddress.setWOrderId(waybillOrder.getId());
|
|
|
+ waybillOrderAddressDao.insert(unloadAddress);
|
|
|
+
|
|
|
+ /**车辆运单状态记录**/
|
|
|
+ this.setWaybillOrderTrack(waybillOrder.getId(), waybillOrder.getStatus());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KwtLogisticsOrderCirculateMapper logisticsOrderCirculateDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param waybillOrder 车辆订单信息
|
|
|
+ * @desc 循环派车数据存储
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/21
|
|
|
+ **/
|
|
|
+ public boolean circulateSave(KwtWaybillOrder waybillOrder) {
|
|
|
+ //循环派车信息
|
|
|
+ KwtLogisticsOrderCirculate circulate = logisticsOrderCirculateDao.findCirculate(waybillOrder.getLOrderId(),
|
|
|
+ waybillOrder.getTruckNo(), waybillOrder.getDriverId());
|
|
|
+ if (circulate == null || circulate.getStatus() == Global.UN_READ) {
|
|
|
+ circulate = new KwtLogisticsOrderCirculate();
|
|
|
+ BeanUtils.copyProperties(waybillOrder, circulate);
|
|
|
+ circulate.setWOrderId(null);
|
|
|
+ int count = logisticsOrderCirculateDao.insert(circulate);
|
|
|
+ return count > 0 ? true : false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param lOrderId 物流订单ID
|
|
|
* @param addressType 地址类型(1装货地址、2卸货地址)
|
|
|
@@ -167,6 +224,11 @@ public class KwtWaybillOrderService {
|
|
|
/**组装数据**/
|
|
|
KwtWaybillOrderAddress address = new KwtWaybillOrderAddress();
|
|
|
BeanUtils.copyProperties(orderAddress, address);
|
|
|
+ address.setId(null);
|
|
|
+ address.setCreateBy(null);
|
|
|
+ address.setCreateTime(null);
|
|
|
+ address.setUpdateBy(null);
|
|
|
+ address.setUpdateBy(null);
|
|
|
return address;
|
|
|
}
|
|
|
|
|
|
@@ -223,9 +285,9 @@ public class KwtWaybillOrderService {
|
|
|
* @date 2023/7/20
|
|
|
**/
|
|
|
public SckwWaybillOrder setSckwWaybillOrder(SendCarDto1 sendCarDto, KwtWaybillOrder waybillOrder,
|
|
|
- KwtLogisticsOrder logisticsOrder, KwtWaybillOrderAddress loadAddress,
|
|
|
- KwtWaybillOrderAddress unloadAddress, KwtLogisticsOrderUnit checkEnt,
|
|
|
- KwtLogisticsOrderUnit carrierEnt, KwtLogisticsOrderGoods goods) {
|
|
|
+ KwtLogisticsOrder logisticsOrder, KwtWaybillOrderAddress loadAddress,
|
|
|
+ KwtWaybillOrderAddress unloadAddress, KwtLogisticsOrderUnit checkEnt,
|
|
|
+ KwtLogisticsOrderUnit carrierEnt, KwtLogisticsOrderGoods goods) {
|
|
|
//基础信息
|
|
|
SckwWaybillOrder order = new SckwWaybillOrder();
|
|
|
order.set_id(waybillOrder.getId());
|