|
|
@@ -3,10 +3,7 @@ package com.sckw.transport.service;
|
|
|
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.utils.CollectionUtils;
|
|
|
-import com.sckw.core.utils.IdWorker;
|
|
|
-import com.sckw.core.utils.StringUtils;
|
|
|
+import com.sckw.core.utils.*;
|
|
|
import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
@@ -17,6 +14,7 @@ import com.sckw.stream.model.SckwBusSum;
|
|
|
import com.sckw.transport.dao.*;
|
|
|
import com.sckw.transport.model.*;
|
|
|
import com.sckw.transport.model.dto.*;
|
|
|
+import com.sckw.transport.model.vo.WaybillCountVo;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.cloud.stream.function.StreamBridge;
|
|
|
@@ -26,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -1000,9 +999,12 @@ public class KwtWaybillOrderService {
|
|
|
//承运订单已装货量=承运订单原装货量+当前车辆运单装货量
|
|
|
BigDecimal loadAmount = logisticsOrder.getLoadAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getLoadAmount();
|
|
|
logisticsOrder.setLoadAmount(loadAmount.add(waybillOrder.getLoadAmount()));
|
|
|
- logisticsOrder.setLoadTime(waybillOrder.getUpdateTime());
|
|
|
+ logisticsOrder.setLoadTime(logisticsOrder.getLoadTime() == null ?waybillOrder.getUpdateTime() : logisticsOrder.getLoadTime());
|
|
|
logisticsOrderDao.updateById(logisticsOrder);
|
|
|
|
|
|
+ //校验当前承运订单是否运输完成(修改状态+统计量)
|
|
|
+ checkLogisticsByStatusV1(waybillOrder.getLOrderId());
|
|
|
+
|
|
|
/**5Mongodb数据更新**/
|
|
|
//1车辆运单
|
|
|
SckwWaybillOrder wOrder = new SckwWaybillOrder();
|
|
|
@@ -1106,10 +1108,12 @@ public class KwtWaybillOrderService {
|
|
|
//承运订单亏吨量=承运订单装货量-承运订单卸货量
|
|
|
logisticsOrder.setDeficitAmount(logisticsOrder.getLoadAmount().subtract(logisticsOrder.getUnloadAmount()));
|
|
|
//承运订单亏吨扣款
|
|
|
- deficitPrice(logisticsOrder);
|
|
|
+ BigDecimal deficitPrice = deficitPrice(logisticsOrder.getLoadAmount(), logisticsOrder.getDeficitAmount(), logisticsOrder.getLoss(), logisticsOrder.getGoodsPrice());
|
|
|
+ logisticsOrder.setDeficitPrice(deficitPrice);
|
|
|
logisticsOrderDao.updateById(logisticsOrder);
|
|
|
- //校验当前承运订单是否运输完成
|
|
|
- setLogisticsByUnloading(logisticsOrder.getId());
|
|
|
+
|
|
|
+ //校验当前承运订单是否运输完成(修改状态+统计量)
|
|
|
+ checkLogisticsByStatusV1(waybillOrder.getLOrderId());
|
|
|
|
|
|
/**5Mongodb数据更新**/
|
|
|
//1车辆运单
|
|
|
@@ -1134,33 +1138,34 @@ public class KwtWaybillOrderService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param logisticsOrder 物流订单
|
|
|
- * @desc 计算物流订单亏吨扣款
|
|
|
+ * @param loadAmount 装货量
|
|
|
+ * @param deficitAmount 亏吨量
|
|
|
+ * @param loss 合理损耗
|
|
|
+ * @param goodsPrice 货值单价
|
|
|
+ * @desc 计算亏吨扣款
|
|
|
* @author zk
|
|
|
* @date 2023/7/27
|
|
|
**/
|
|
|
- public void deficitPrice(KwtLogisticsOrder logisticsOrder) {
|
|
|
+ public BigDecimal deficitPrice(BigDecimal loadAmount, BigDecimal deficitAmount, BigDecimal loss, BigDecimal goodsPrice) {
|
|
|
//承运订单亏吨扣款=(承运订单亏吨量 -(承运订单装货量 * 承运订单合理损耗))* 扣亏货值
|
|
|
- BigDecimal loadAmount = logisticsOrder.getLoadAmount();
|
|
|
- BigDecimal deficitAmount = logisticsOrder.getDeficitAmount();
|
|
|
- BigDecimal loss = logisticsOrder.getLoss() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getLoss();
|
|
|
- BigDecimal goodsPrice = logisticsOrder.getGoodsPrice() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getGoodsPrice();
|
|
|
+ loss = loss == null ? new BigDecimal(Global.AMOUNT) : loss;
|
|
|
+ goodsPrice = goodsPrice == null ? new BigDecimal(Global.AMOUNT) : goodsPrice;
|
|
|
BigDecimal deficitPrice = deficitAmount.subtract(loadAmount.multiply(loss).setScale(4, RoundingMode.HALF_UP))
|
|
|
.multiply(goodsPrice).setScale(4, RoundingMode.HALF_UP);
|
|
|
- logisticsOrder.setDeficitPrice(deficitPrice);
|
|
|
+ return deficitPrice;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param lOrderId 承运订单ID
|
|
|
- * @description 校验当前承运订单是否运输完成
|
|
|
+ * @description 校验当前承运订单是否运输完成(修改状态)
|
|
|
* @author zk
|
|
|
* @date 2023/7/27
|
|
|
**/
|
|
|
- public void setLogisticsByUnloading(Long lOrderId) {
|
|
|
+ public void checkLogisticsByStatus(Long lOrderId) {
|
|
|
/**
|
|
|
校验当前承运订单是否运输完成(虑该当前承运订单上下级物流订单)
|
|
|
- 存在下级分包,下级物流订单和当前物流订单全部运输完成则修改当前物流订单状态为已完成(HAVE_FINISHED)
|
|
|
- 当前物流订单属于分包:需要判断上级及同级分包全部运输完成修改上级物流订单状态为已完成(HAVE_FINISHED)-一直向上到一级物流订单
|
|
|
+ 1存在下级分包,下级物流订单和当前物流订单全部运输完成则修改当前物流订单状态为已完成(HAVE_FINISHED)
|
|
|
+ 2当前物流订单属于分包:需要判断上级及同级分包全部运输完成修改上级物流订单状态为已完成(HAVE_FINISHED)-一直向上到一级物流订单
|
|
|
**/
|
|
|
//承运单信息
|
|
|
KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(lOrderId);
|
|
|
@@ -1169,11 +1174,11 @@ public class KwtWaybillOrderService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- /**存在下级分包**/
|
|
|
+ /**1存在下级分包**/
|
|
|
BigDecimal subcontractAmount = logisticsOrder.getSubcontractAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getSubcontractAmount();
|
|
|
if (subcontractAmount.compareTo(new BigDecimal(Global.AMOUNT)) == 0) {
|
|
|
List<KwtLogisticsOrder> logisticsOrders = logisticsOrderDao.findLogisticsOrder(
|
|
|
- new HashMap(){{put("upperlOrderId", logisticsOrder.getId()); put("lOrderId", logisticsOrder.getId());}});
|
|
|
+ new HashMap(){{put("upperlOrderId", logisticsOrder.getId()); put("ownOrderId", logisticsOrder.getId());}});
|
|
|
for (KwtLogisticsOrder logisticsOrder1:logisticsOrders) {
|
|
|
if (logisticsOrder1.getStatus() == LogisticsOrderEnum.TO_BE_PLANNED.getCode()
|
|
|
|| logisticsOrder1.getStatus() == LogisticsOrderEnum.PENDING_ORDER.getCode()
|
|
|
@@ -1200,15 +1205,98 @@ public class KwtWaybillOrderService {
|
|
|
editSckwLogisticsOrder(lOrder, logisticsOrder);
|
|
|
}
|
|
|
|
|
|
- /**当前物流订单属于分包(存在上级物流订单)**/
|
|
|
- //当前承运订单所属分包层级
|
|
|
- //int level = checkLogisticsLevel(logisticsOrder);
|
|
|
+ /**2当前物流订单属于分包(存在上级物流订单)**/
|
|
|
+ //获取所有上级物流订单ID(当前物流订单ID除外)
|
|
|
String pids = logisticsOrder.getPids();
|
|
|
if (StringUtils.isNotBlank(pids)) {
|
|
|
- String [] idArray = pids.split(",");
|
|
|
- for (String id : idArray) {
|
|
|
- KwtLogisticsOrder order = logisticsOrderDao.selectById(id);
|
|
|
+ List<Long> idArray = (List)Arrays.asList(pids);
|
|
|
+ for (Long id : idArray) {
|
|
|
+ //当前物流订单ID除外
|
|
|
+ if (id != lOrderId) {
|
|
|
+ /**校验当前承运订单是否运输完成**/
|
|
|
+ checkLogisticsByStatus(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param lOrderId 承运订单ID
|
|
|
+ * @description 校验当前承运订单是否运输完成(修改状态+统计量)
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/27
|
|
|
+ **/
|
|
|
+ public void checkLogisticsByStatusV1(Long lOrderId) {
|
|
|
+ /**
|
|
|
+ 校验当前承运订单是否运输完成(虑该当前承运订单上下级物流订单)
|
|
|
+ 1存在下级分包,下级物流订单和当前物流订单全部运输完成则修改当前物流订单状态为已完成(HAVE_FINISHED)、统计值
|
|
|
+ 2当前物流订单属于分包:需要判断上级及同级分包全部运输完成修改上级物流订单状态为已完成(HAVE_FINISHED)、统计值-一直向上到一级物流订单
|
|
|
+ **/
|
|
|
+ //承运单信息
|
|
|
+ KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(lOrderId);
|
|
|
|
|
|
+ /**1存在下级分包**/
|
|
|
+ boolean subcontractBool = true;
|
|
|
+ BigDecimal subcontractAmount = logisticsOrder.getSubcontractAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getSubcontractAmount();
|
|
|
+ if (subcontractAmount.compareTo(new BigDecimal(Global.AMOUNT)) > 0) {
|
|
|
+ /**1-1校验下级分包是否全部运输完成**/
|
|
|
+ List<KwtLogisticsOrder> logisticsOrders = logisticsOrderDao.findLogisticsOrder(
|
|
|
+ new HashMap(){{put("upperlOrderId", logisticsOrder.getId()); put("ownOrderId", logisticsOrder.getId());}});
|
|
|
+ for (KwtLogisticsOrder logisticsOrder1:logisticsOrders) {
|
|
|
+ if (!LogisticsOrderEnum.transportCompleted(logisticsOrder1.getStatus())) {
|
|
|
+ //下级分包承运订单运输未完成
|
|
|
+ subcontractBool = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**校验当前承运订单是否运输完成**/
|
|
|
+ WaybillCountVo waybillCount = waybillOrderDao.findWaybillOrderCount( new HashMap(){{put("lOrderId", logisticsOrder.getId());
|
|
|
+ put("passStatus", 1); }});
|
|
|
+ //物流运单状态(不包含已完成、已对账、已结算)+ 物流订单上级委派量-下游分包总量 <= 自己承运总装货量 + 下级分包全部运输完成
|
|
|
+ if (!LogisticsOrderEnum.transportCompleted(logisticsOrder.getStatus())
|
|
|
+ && logisticsOrder.getAmount().subtract(subcontractAmount).compareTo(waybillCount.getLoadAmount()) <= 0
|
|
|
+ && subcontractBool) {
|
|
|
+ /**1-2下级分包承运订单运输完成**/
|
|
|
+ logisticsOrder.setStatus(LogisticsOrderEnum.HAVE_FINISHED.getCode());
|
|
|
+ logisticsOrderDao.updateById(logisticsOrder);
|
|
|
+
|
|
|
+ /**1-3承运订单状态记录**/
|
|
|
+ KwtLogisticsOrderTrack orderTrack = new KwtLogisticsOrderTrack();
|
|
|
+ orderTrack.setLOrderId(logisticsOrder.getId());
|
|
|
+ orderTrack.setStatus(logisticsOrder.getStatus());
|
|
|
+ orderTrack.setRemark(LogisticsOrderEnum.getName(logisticsOrder.getStatus()));
|
|
|
+ logisticsOrderTrackDao.insert(orderTrack);
|
|
|
+ }
|
|
|
+
|
|
|
+ //车辆运单统计
|
|
|
+ /**1-4Mongodb数据更新**/
|
|
|
+ //车辆运单统计
|
|
|
+ waybillCount = waybillOrderDao.findWaybillOrderCount( new HashMap(){{put("lOrderId", logisticsOrder.getId());
|
|
|
+ put("unloadCountStatus", 1); put("upperlOrderId", logisticsOrder.getId()); }});
|
|
|
+ //2承运订单
|
|
|
+ SckwLogisticsOrder lOrder = new SckwLogisticsOrder();
|
|
|
+ lOrder.setLoadTime(waybillCount.getLoadTime());
|
|
|
+ lOrder.setUnloadTime(waybillCount.getUnloadTime());
|
|
|
+ lOrder.setLoadTotalAmount(waybillCount.getLoadAmount());
|
|
|
+ lOrder.setUnloadTotalAmount(waybillCount.getUnloadAmount());
|
|
|
+ lOrder.setDeficitTotalAmount(waybillCount.getDeficitAmount());
|
|
|
+ BigDecimal deficitPrice = deficitPrice(waybillCount.getLoadAmount(), waybillCount.getDeficitAmount(),
|
|
|
+ logisticsOrder.getLoss(), logisticsOrder.getGoodsPrice());
|
|
|
+ lOrder.setDeficitPrice(deficitPrice);
|
|
|
+ editSckwLogisticsOrder(lOrder, logisticsOrder);
|
|
|
+
|
|
|
+ /**2当前物流订单属于分包(存在上级物流订单)**/
|
|
|
+ //获取所有上级物流订单ID(当前物流订单ID除外)
|
|
|
+ String pids = logisticsOrder.getPids();
|
|
|
+ if (StringUtils.isNotBlank(pids)) {
|
|
|
+ List<Long> idArray = (List)Arrays.asList(pids);
|
|
|
+ for (Long id : idArray) {
|
|
|
+ //当前物流订单ID除外
|
|
|
+ if (id != lOrderId) {
|
|
|
+ /**校验当前承运订单是否运输完成**/
|
|
|
+ checkLogisticsByStatusV1(id);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1221,16 +1309,32 @@ public class KwtWaybillOrderService {
|
|
|
**/
|
|
|
public HttpResult editTicket(WaybillOrderTicketDto params) {
|
|
|
/**校验**/
|
|
|
+ KwtWaybillOrder waybillOrder = waybillOrderDao.selectById(params.getWOrderId());
|
|
|
+ if (waybillOrder == null) {
|
|
|
+ return HttpResult.error("车辆运单信息不存在!");
|
|
|
+ }
|
|
|
KwtWaybillOrderTicket ticket = waybillOrderTicketDao.findWaybillOrderTicket(params.getWOrderId(), params.getType());
|
|
|
if (ticket == null) {
|
|
|
return HttpResult.error("车辆运单榜单信息不存在!");
|
|
|
}
|
|
|
|
|
|
+ /**更新车辆运单信息**/
|
|
|
+ waybillOrder.setLoadAmount(params.getType() == 1 ? params.getAmount() : waybillOrder.getLoadAmount());
|
|
|
+ waybillOrder.setUnloadAmount(params.getType() == 2 ? params.getAmount() : waybillOrder.getUnloadAmount());
|
|
|
+ waybillOrder.setDeficitAmount(waybillOrder.getLoadAmount().subtract(waybillOrder.getUnloadAmount()));
|
|
|
+ waybillOrderDao.updateById(waybillOrder);
|
|
|
+
|
|
|
/**更新榜单信息**/
|
|
|
BeanUtils.copyProperties(params, ticket);
|
|
|
waybillOrderTicketDao.updateById(ticket);
|
|
|
|
|
|
/**更新承运订单装卸货量**/
|
|
|
+ //有更新装卸货量才会更新物流订单量
|
|
|
+ if (waybillOrder.getLoadAmount().compareTo(params.getAmount()) != 0
|
|
|
+ || waybillOrder.getUnloadAmount().compareTo(params.getAmount()) != 0) {
|
|
|
+ //校验当前承运订单是否运输完成(修改状态+统计量)
|
|
|
+ checkLogisticsByStatusV1(waybillOrder.getLOrderId());
|
|
|
+ }
|
|
|
|
|
|
return HttpResult.ok("修改单证成功!");
|
|
|
}
|
|
|
@@ -1272,6 +1376,9 @@ public class KwtWaybillOrderService {
|
|
|
wOrder.set_id(waybillOrder.getId());
|
|
|
editSckwWaybillOrder(wOrder, waybillOrder, 2);
|
|
|
|
|
|
+ /**4校验当前承运订单是否运输完成(修改状态+统计量)**/
|
|
|
+ checkLogisticsByStatusV1(waybillOrder.getLOrderId());
|
|
|
+
|
|
|
/**4发送消息**/
|
|
|
|
|
|
return HttpResult.ok("车辆运单审核完成!");
|