|
|
@@ -1,11 +1,14 @@
|
|
|
package com.sckw.transport.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.sckw.core.exception.SystemException;
|
|
|
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.IdWorker;
|
|
|
+import com.sckw.core.utils.StringUtils;
|
|
|
+import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.mongo.enums.BusinessTypeEnum;
|
|
|
@@ -36,6 +39,8 @@ public class KwtWaybillOrderService {
|
|
|
@Autowired
|
|
|
KwtLogisticsOrderMapper logisticsOrderDao;
|
|
|
@Autowired
|
|
|
+ KwtLogisticsOrderTrackMapper logisticsOrderTrackDao;
|
|
|
+ @Autowired
|
|
|
KwtLogisticsOrderAddressMapper logisticsOrderAddressDao;
|
|
|
@Autowired
|
|
|
KwtWaybillOrderAddressMapper waybillOrderAddressDao;
|
|
|
@@ -58,9 +63,53 @@ public class KwtWaybillOrderService {
|
|
|
**/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HttpResult sendCar(List<SendCarDto1> params) {
|
|
|
- /**校验物流运单是否可以派车**/
|
|
|
+ /**校验**/
|
|
|
//承运单信息
|
|
|
KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(params.get(0).getLOrderId());
|
|
|
+ HttpResult result = checkWaybillOrder(params, logisticsOrder);
|
|
|
+ if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //下游司机委派量累加(趟次)
|
|
|
+ BigDecimal ranksAmount = (BigDecimal)result.getData();
|
|
|
+
|
|
|
+ /**数据处理**/
|
|
|
+ result = setWaybillOrder(params, logisticsOrder);
|
|
|
+ if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //Mongodb数据存储model
|
|
|
+ List<SckwWaybillOrder> sckwWaybillOrders = (List<SckwWaybillOrder>) result.getData();
|
|
|
+
|
|
|
+ /**变更承运单状态(累计派车量等于剩余可运量)/已委托量entrust_amount**/
|
|
|
+ setLogisticsBySendCar(logisticsOrder.getId(), ranksAmount);
|
|
|
+
|
|
|
+ /**Mongodb数据存储**/
|
|
|
+ for (SckwWaybillOrder waybillOrder:sckwWaybillOrders) {
|
|
|
+ //rabbitMq业务汇总数据发送/消费对象
|
|
|
+ SckwBusSum busSum = new SckwBusSum();
|
|
|
+ //业务汇总类型
|
|
|
+ busSum.setBusSumType(BusinessTypeEnum.WAYBILL_ORDER_TYPE.getName());
|
|
|
+ //操作对象(1新增/2修改)
|
|
|
+ busSum.setMethod(1);
|
|
|
+ //业务汇总数据对象
|
|
|
+ busSum.setObject(waybillOrder);
|
|
|
+ streamBridge.send("sckw-busSum", busSum);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**发送消息**/
|
|
|
+ return HttpResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 派车请求参数
|
|
|
+ * @param logisticsOrder 物流订单
|
|
|
+ * @desc 派车校验
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/19
|
|
|
+ **/
|
|
|
+ public HttpResult checkWaybillOrder(List<SendCarDto1> params, KwtLogisticsOrder logisticsOrder) {
|
|
|
+ /**校验物流运单是否可以派车**/
|
|
|
if (logisticsOrder == null) {
|
|
|
return HttpResult.error("订单已不存在!" );
|
|
|
}
|
|
|
@@ -100,14 +149,7 @@ public class KwtWaybillOrderService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**数据处理**/
|
|
|
- setWaybillOrder(params, logisticsOrder);
|
|
|
-
|
|
|
- //变更承运单状态(累计派车量等于剩余可运量)/已委托量entrust_amount
|
|
|
-
|
|
|
- /**发送消息**/
|
|
|
- return HttpResult.ok();
|
|
|
+ return HttpResult.ok(ranksAmount);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -138,7 +180,6 @@ public class KwtWaybillOrderService {
|
|
|
|
|
|
/**数据存储**/
|
|
|
if (sendCarDto.getType() == Global.NUMERICAL_ONE) {
|
|
|
-
|
|
|
for (int i=0; i<sendCarDto.getCount(); i++) {
|
|
|
//趟次派车存储
|
|
|
ranksSave(waybillOrder, loadAddress, unloadAddress);
|
|
|
@@ -158,12 +199,9 @@ public class KwtWaybillOrderService {
|
|
|
sckwWaybillOrders.add(mongoOrder);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- /**Mongodb数据存储**/
|
|
|
+ /**Mongodb数据存储
|
|
|
for (SckwWaybillOrder waybillOrder:sckwWaybillOrders) {
|
|
|
//rabbitMq业务汇总数据发送/消费对象
|
|
|
SckwBusSum busSum = new SckwBusSum();
|
|
|
@@ -174,12 +212,11 @@ public class KwtWaybillOrderService {
|
|
|
//业务汇总数据对象
|
|
|
busSum.setObject(waybillOrder);
|
|
|
streamBridge.send("sckw-busSum", busSum);
|
|
|
- }
|
|
|
+ }**/
|
|
|
|
|
|
- return HttpResult.ok();
|
|
|
+ return HttpResult.ok(sckwWaybillOrders);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* @param waybillOrder 车辆订单信息
|
|
|
* @param loadAddress 装货地址信息
|
|
|
@@ -407,4 +444,101 @@ public class KwtWaybillOrderService {
|
|
|
return order;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param lOrderId 承运订单ID
|
|
|
+ * @param ranksAmount 当前派车总量
|
|
|
+ * @description 派车更新承运订单信息
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/24
|
|
|
+ **/
|
|
|
+ public void setLogisticsBySendCar(Long lOrderId, BigDecimal ranksAmount) {
|
|
|
+ /**
|
|
|
+ 状态判断是否是分包承运单(不考虑该承运单下级分包)
|
|
|
+ 存在:更新当前承运订单状态及委派量entrustAmount,并且校验承运订单所有父级状态是否需要修改(是修改状态,否则不修改)
|
|
|
+ 不存在:更新当前承运订单状态及委派量entrustAmount
|
|
|
+ **/
|
|
|
+ //承运单信息
|
|
|
+ KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(lOrderId);
|
|
|
+
|
|
|
+ //当前承运订单所属分包层级
|
|
|
+ //int level = checkLogisticsLevel(logisticsOrder);
|
|
|
+ String pids = logisticsOrder.getPids();
|
|
|
+ if (StringUtils.isNotBlank(pids)) {
|
|
|
+ String [] idArray = pids.split(",");
|
|
|
+ for (String id : idArray) {
|
|
|
+ KwtLogisticsOrder order = logisticsOrderDao.selectById(id);
|
|
|
+ //承运订单-待派车
|
|
|
+ if (logisticsOrder.getStatus() == LogisticsOrderEnum.WAIT_DELIVERY.getCode()) {
|
|
|
+ //承运订单不存在分包:更新当前承运订单状态及委派量entrustAmount
|
|
|
+ if (order.getId() == logisticsOrder.getId()) {
|
|
|
+ //承运订单已委派量
|
|
|
+ BigDecimal entrustAmount = logisticsOrder.getEntrustAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getEntrustAmount();
|
|
|
+ logisticsOrder.setEntrustAmount(entrustAmount.add(ranksAmount));
|
|
|
+ }
|
|
|
+ //承运订单:待派车->运输中
|
|
|
+ logisticsOrder.setStatus(LogisticsOrderEnum.IN_TRANSIT.getCode());
|
|
|
+ logisticsOrderDao.updateById(order);
|
|
|
+
|
|
|
+ //承运订单状态记录
|
|
|
+ KwtLogisticsOrderTrack orderTrack = new KwtLogisticsOrderTrack();
|
|
|
+ orderTrack.setLOrderId(order.getId());
|
|
|
+ orderTrack.setStatus(order.getStatus());
|
|
|
+ orderTrack.setRemark(LogisticsOrderEnum.getName(order.getStatus()));
|
|
|
+ logisticsOrderTrackDao.insert(orderTrack);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param logisticsOrder 承运订单
|
|
|
+ * @description 当前承运订单所属分包层级
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/24
|
|
|
+ **/
|
|
|
+ public int checkLogisticsLevel(KwtLogisticsOrder logisticsOrder) {
|
|
|
+ String pids = logisticsOrder.getPids();
|
|
|
+ String [] idArrays = StringUtils.isBlank(pids) ? new String[0] : pids.split(Global.COMMA);
|
|
|
+ return idArrays.length <= 1 ? Global.NUMERICAL_ONE : (idArrays.length - Global.NUMERICAL_ONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ids 车辆运单主键ID,多个已逗号隔开
|
|
|
+ * @description 取消派车
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/7/24
|
|
|
+ **/
|
|
|
+ public HttpResult cancelSendCar(String ids){
|
|
|
+ /**数据校验**/
|
|
|
+ if (StringUtils.isBlank(ids)) {
|
|
|
+ return HttpResult.error("请选择需要撤回的车辆运单!");
|
|
|
+ }
|
|
|
+ //校验运单ID是否有效/运单当前状态是否可以撤销
|
|
|
+ String[] idArray = ids.split(",");
|
|
|
+ for (String id : idArray) {
|
|
|
+ KwtWaybillOrder order = waybillOrderDao.selectById(id);
|
|
|
+ if (order != null) {
|
|
|
+ if (order.getStatus() != CarWaybillEnum.PENDING_ORDER.getCode()); {
|
|
|
+ return HttpResult.error("运单"+order.getWOrderNo()+"当前已不能撤回!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return HttpResult.error("选择撤回的数据已不存在!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**业务处理**/
|
|
|
+ for (String id : idArray) {
|
|
|
+ KwtWaybillOrder order = waybillOrderDao.selectById(id);
|
|
|
+ if (order != null) {
|
|
|
+ if (order.getStatus() == CarWaybillEnum.PENDING_ORDER.getCode()); {
|
|
|
+ //----------------------
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return HttpResult.error("选择撤回的数据已不存在!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return HttpResult.ok();
|
|
|
+ }
|
|
|
}
|