|
|
@@ -1,5 +1,6 @@
|
|
|
package com.sckw.transport.service;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -7,7 +8,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.sckw.contract.api.RemoteContractService;
|
|
|
import com.sckw.core.common.enums.NumberConstant;
|
|
|
-import com.sckw.core.common.enums.StringConstant;
|
|
|
import com.sckw.core.common.enums.enums.DictTypeEnum;
|
|
|
import com.sckw.core.exception.BusinessException;
|
|
|
import com.sckw.core.model.enums.CarWaybillEnum;
|
|
|
@@ -27,8 +27,8 @@ import com.sckw.mongo.enums.BusinessTypeEnum;
|
|
|
import com.sckw.mongo.model.SckwLogisticsOrder;
|
|
|
import com.sckw.order.api.dubbo.TradeOrderInfoService;
|
|
|
import com.sckw.order.api.model.AddressInfoDetail;
|
|
|
+import com.sckw.order.api.model.CreateOrCancelLogisticsOrderParam;
|
|
|
import com.sckw.order.api.model.OrderDetailRes;
|
|
|
-import com.sckw.order.api.model.UpdateOrderAmountParam;
|
|
|
import com.sckw.product.api.dubbo.GoodsInfoService;
|
|
|
import com.sckw.product.api.model.KwpGoods;
|
|
|
import com.sckw.stream.model.SckwBusSum;
|
|
|
@@ -40,6 +40,7 @@ import com.sckw.transport.model.dto.OrderCarDTO;
|
|
|
import com.sckw.transport.model.dto.OrderFinishDTO;
|
|
|
import com.sckw.transport.model.param.LogisticsConsignmentParam;
|
|
|
import com.sckw.transport.model.vo.OrderFinishVO;
|
|
|
+import io.seata.core.context.RootContext;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
@@ -50,10 +51,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -526,7 +524,7 @@ public class LogisticsConsignmentService {
|
|
|
*/
|
|
|
public HttpResult purchaseLogisticsOrder(String id, Integer page, Integer pageSize, String type) {
|
|
|
Long count = getLogisticsOrderCount(id, type);
|
|
|
- Integer newPage = page - 1;
|
|
|
+ Integer newPage = (page - 1) * pageSize;
|
|
|
List<LogisticsOrderDTO> list = getLogisticsOrderData(id, newPage, pageSize, type);
|
|
|
PageResult build = PageResult.build(page, pageSize, count, list);
|
|
|
return HttpResult.ok(build);
|
|
|
@@ -765,19 +763,58 @@ public class LogisticsConsignmentService {
|
|
|
return HttpResult.ok(build);
|
|
|
}
|
|
|
|
|
|
+ // /**
|
|
|
+// * 销售订单获取车辆信息
|
|
|
+// *
|
|
|
+// * @param id
|
|
|
+// * @param page
|
|
|
+// * @param pageSize
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public HttpResult sellLogisticsCar(String id, Integer page, Integer pageSize) {
|
|
|
+// Long count = getLogisticsCarDataCount(id);
|
|
|
+// Integer newPage = (page - 1) * pageSize;
|
|
|
+// List<OrderCarDTO> list = getLogisticsCarData(id, newPage, pageSize);
|
|
|
+// PageResult build = PageResult.build(page, pageSize, count, list);
|
|
|
+// return HttpResult.ok(build);
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
- * 销售订单获取车辆信息
|
|
|
+ * 销售订单-车辆列表-销售订单id
|
|
|
*
|
|
|
- * @param id
|
|
|
+ * @param ids
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
- public HttpResult sellLogisticsCar(String id, Integer page, Integer pageSize) {
|
|
|
- Long count = getLogisticsCarDataCount(id);
|
|
|
- Integer newPage = page - 1;
|
|
|
- List<OrderCarDTO> list = getLogisticsCarData(id, newPage, pageSize);
|
|
|
- PageResult build = PageResult.build(page, pageSize, count, list);
|
|
|
+ public HttpResult sellLogisticsCar(String ids, Integer page, Integer pageSize) {
|
|
|
+ List<String> stringList = StringUtils.splitStrToList(ids, String.class);
|
|
|
+ if (CollectionUtils.isEmpty(stringList)) {
|
|
|
+ return HttpResult.ok();
|
|
|
+ }
|
|
|
+ List<OrderCarDTO> returnList = new ArrayList<>();
|
|
|
+ for (String id : stringList) {
|
|
|
+ List<OrderCarDTO> list = waybillOrderMapper.selectWaybillOrderCarListNotPage(id);
|
|
|
+ List<String> collect = list.stream().map(OrderCarDTO::getTruckNo).collect(Collectors.toList());
|
|
|
+ Map<String, RTruckVo> truck = remoteFleetService.findTruck(collect);
|
|
|
+ for (OrderCarDTO orderCarDTO : list) {
|
|
|
+// orderCarDTO.setDriverId(String.valueOf(orderCarDTO.getDriverId()));
|
|
|
+// orderCarDTO.setDriverName(orderCarDTO.getDriverName());
|
|
|
+// orderCarDTO.setDriverPhone(orderCarDTO.getDriverPhone());
|
|
|
+// orderCarDTO.setDriverCard(orderCarDTO.getDriverCard());
|
|
|
+ orderCarDTO.setLoadAmount(truck.get(orderCarDTO.getTruckNo()) == null ?
|
|
|
+ null : (truck.get(orderCarDTO.getTruckNo()).getActualWeight() == null ?
|
|
|
+ null : (String.valueOf(truck.get(orderCarDTO.getTruckNo()).getActualWeight()))));
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ returnList.addAll(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<OrderCarDTO> subList = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(returnList)) {
|
|
|
+ subList = returnList.stream().skip((page - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ PageResult build = PageResult.build(page, pageSize, returnList.stream().count(), subList);
|
|
|
return HttpResult.ok(build);
|
|
|
}
|
|
|
|
|
|
@@ -843,21 +880,29 @@ public class LogisticsConsignmentService {
|
|
|
jsonObject.put("message", "单据状态异常或单据不存在");
|
|
|
jsonObject.put("status", HttpStatus.GLOBAL_EXCEPTION_CODE);
|
|
|
} else {
|
|
|
- OrderDetailRes orderDetailRes = tradeOrderInfoService.getOrderDetailById(Long.parseLong(s));
|
|
|
- UpdateOrderAmountParam param = new UpdateOrderAmountParam();
|
|
|
+ /**撤退推送接口数据溯源修改贸易订单已委托量*/
|
|
|
+ CreateOrCancelLogisticsOrderParam param = new CreateOrCancelLogisticsOrderParam();
|
|
|
param.setTOrderId(Long.parseLong(s));
|
|
|
- param.setActualAmount(orderDetailRes.getActualAmount().add(kwtLogisticsOrder.getLoadAmount()));
|
|
|
- param.setEntrustAmount(orderDetailRes.getEntrustAmount().add(kwtLogisticsOrder.getEntrustAmount().subtract(kwtLogisticsOrder.getLoadAmount())));
|
|
|
- tradeOrderInfoService.updateOrderAmount(param);
|
|
|
- kwtLogisticsOrder.setDelFlag(1);
|
|
|
- kwtLogisticsOrder.setUpdateTime(new Date());
|
|
|
- kwtLogisticsOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
- kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
- .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getId())
|
|
|
- .set(KwtLogisticsOrder::getDelFlag, NumberConstant.ONE)
|
|
|
- .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
- .set(KwtLogisticsOrder::getUpdateTime, new Date()));
|
|
|
- jsonObject.put("status", HttpStatus.SUCCESS_CODE);
|
|
|
+ param.setEntrustAmount(kwtLogisticsOrder.getLoadAmount().negate());
|
|
|
+ param.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ param.setUpdateByName(LoginUserHolder.getUserName());
|
|
|
+ HttpResult httpResult = tradeOrderInfoService.createOrCancelLogisticsOrder(param);
|
|
|
+ if (HttpStatus.SUCCESS_CODE == httpResult.getCode()) {
|
|
|
+ kwtLogisticsOrder.setDelFlag(NumberConstant.ONE);
|
|
|
+ kwtLogisticsOrder.setUpdateTime(new Date());
|
|
|
+ kwtLogisticsOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getId())
|
|
|
+ .set(KwtLogisticsOrder::getDelFlag, NumberConstant.ONE)
|
|
|
+ .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
+ .set(KwtLogisticsOrder::getUpdateTime, new Date()));
|
|
|
+ jsonObject.put("status", HttpStatus.SUCCESS_CODE);
|
|
|
+ jsonObject.put("message", "操作成功");
|
|
|
+ } else {
|
|
|
+ JSONObject.toJSONString(httpResult);
|
|
|
+ jsonObject.put("status", HttpStatus.GLOBAL_EXCEPTION_CODE);
|
|
|
+ jsonObject.put("message", "操作失败:" + httpResult.getMsg());
|
|
|
+ }
|
|
|
}
|
|
|
list.add(jsonObject);
|
|
|
});
|
|
|
@@ -885,21 +930,28 @@ public class LogisticsConsignmentService {
|
|
|
jsonObject.put("message", "单据状态异常或单据不存在");
|
|
|
jsonObject.put("status", HttpStatus.GLOBAL_EXCEPTION_CODE);
|
|
|
} else {
|
|
|
- OrderDetailRes orderDetailRes = tradeOrderInfoService.getOrderDetailById(Long.parseLong(s));
|
|
|
- UpdateOrderAmountParam param = new UpdateOrderAmountParam();
|
|
|
+ /**撤退推送接口数据溯源修改贸易订单已委托量*/
|
|
|
+ CreateOrCancelLogisticsOrderParam param = new CreateOrCancelLogisticsOrderParam();
|
|
|
param.setTOrderId(Long.parseLong(s));
|
|
|
- param.setActualAmount(orderDetailRes.getActualAmount().add(kwtLogisticsOrder.getLoadAmount()));
|
|
|
- param.setEntrustAmount(orderDetailRes.getEntrustAmount().add(kwtLogisticsOrder.getEntrustAmount().subtract(kwtLogisticsOrder.getLoadAmount())));
|
|
|
- tradeOrderInfoService.updateOrderAmount(param);
|
|
|
- kwtLogisticsOrder.setDelFlag(1);
|
|
|
- kwtLogisticsOrder.setUpdateTime(new Date());
|
|
|
- kwtLogisticsOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
- kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
- .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getId())
|
|
|
- .set(KwtLogisticsOrder::getDelFlag, NumberConstant.ONE)
|
|
|
- .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
- .set(KwtLogisticsOrder::getUpdateTime, new Date()));
|
|
|
- jsonObject.put("status", HttpStatus.SUCCESS_CODE);
|
|
|
+ param.setEntrustAmount(kwtLogisticsOrder.getLoadAmount().negate());
|
|
|
+ param.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ param.setUpdateByName(LoginUserHolder.getUserName());
|
|
|
+ HttpResult httpResult = tradeOrderInfoService.createOrCancelLogisticsOrder(param);
|
|
|
+ if (HttpStatus.SUCCESS_CODE == httpResult.getCode()) {
|
|
|
+ kwtLogisticsOrder.setDelFlag(NumberConstant.ONE);
|
|
|
+ kwtLogisticsOrder.setUpdateTime(new Date());
|
|
|
+ kwtLogisticsOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getId())
|
|
|
+ .set(KwtLogisticsOrder::getDelFlag, NumberConstant.ONE)
|
|
|
+ .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
+ .set(KwtLogisticsOrder::getUpdateTime, new Date()));
|
|
|
+ jsonObject.put("status", HttpStatus.SUCCESS_CODE);
|
|
|
+ jsonObject.put("message", "操作失败:" + httpResult.getMsg());
|
|
|
+ } else {
|
|
|
+ jsonObject.put("status", HttpStatus.GLOBAL_EXCEPTION_CODE);
|
|
|
+ jsonObject.put("message", "操作失败:" + httpResult.getMsg());
|
|
|
+ }
|
|
|
}
|
|
|
list.add(jsonObject);
|
|
|
});
|
|
|
@@ -913,6 +965,7 @@ public class LogisticsConsignmentService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
+// @GlobalTransactional(timeoutMills = 120000)
|
|
|
public HttpResult orderFinish(OrderFinishDTO orderFinishDTO, String type) {
|
|
|
HttpResult httpResult = ValidUtil.serviceValid(orderFinishDTO);
|
|
|
if (!String.valueOf(httpResult.getCode()).equals(String.valueOf(HttpStatus.SUCCESS_CODE))) {
|
|
|
@@ -920,9 +973,13 @@ public class LogisticsConsignmentService {
|
|
|
}
|
|
|
//1采购 2销售
|
|
|
if (String.valueOf(NumberConstant.ONE).equals(type)) {
|
|
|
+ log.info("采购订单-托运订单列表-完结订单 处理开始 seata xid:{}", RootContext.getXID());
|
|
|
purchaseOrderFinish(orderFinishDTO);
|
|
|
+ log.info("采购订单-托运订单列表-完结订单 处理结束 seata xid:{}", RootContext.getXID());
|
|
|
} else if (String.valueOf(NumberConstant.TWO).equals(type)) {
|
|
|
+ log.info("销售订单-托运订单列表-完结订单 处理开始 seata xid:{}", RootContext.getXID());
|
|
|
sellOrderFinish(orderFinishDTO);
|
|
|
+ log.info("销售订单-托运订单列表-完结订单 处理结束 seata xid:{}", RootContext.getXID());
|
|
|
} else {
|
|
|
throw new RuntimeException("完结订单-单据类型异常!");
|
|
|
}
|
|
|
@@ -943,7 +1000,7 @@ public class LogisticsConsignmentService {
|
|
|
*
|
|
|
* @param orderFinishDTO
|
|
|
*/
|
|
|
- private void purchaseOrderFinish(OrderFinishDTO orderFinishDTO) {
|
|
|
+ public void purchaseOrderFinish(OrderFinishDTO orderFinishDTO) {
|
|
|
/** 订单完结 物流运单状态为【待派车】、【运输中】可操作*/
|
|
|
/**完结拦截 必须车辆运单无正在运输中的单据才能完结 状态有 待接单之后已核弹之前的状态 都不能完结*/
|
|
|
/**完结订单-对应物流订单下子订单都要进行完结*/
|
|
|
@@ -953,7 +1010,7 @@ public class LogisticsConsignmentService {
|
|
|
KwtLogisticsOrder logisticsOrder = kwtLogisticsOrderMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
.eq(KwtLogisticsOrder::getId, id));
|
|
|
if (logisticsOrder == null) {
|
|
|
- throw new RuntimeException("采购订单-完结订单-物流单据不存在!");
|
|
|
+ throw new BusinessException("采购订单-完结订单-物流单据不存在!");
|
|
|
}
|
|
|
if (logisticsOrder.getLoadAmount().compareTo(orderFinishDTO.getLoadAmount()) > 0) {
|
|
|
throw new BusinessException("完结订单,实装量不能大于分配量");
|
|
|
@@ -961,49 +1018,472 @@ public class LogisticsConsignmentService {
|
|
|
/**订单状态验证*/
|
|
|
if (!LogisticsOrderEnum.WAIT_DELIVERY.getStatus().equals(String.valueOf(logisticsOrder.getStatus()))
|
|
|
&& !LogisticsOrderEnum.IN_TRANSIT.getStatus().equals(String.valueOf(logisticsOrder.getStatus()))) {
|
|
|
- throw new RuntimeException("当前运单并不属于【待派车】,【运输中】状态");
|
|
|
+ throw new BusinessException("当前运单并不属于【待派车】,【运输中】状态");
|
|
|
+ }
|
|
|
+ //验证当前物流订单是否还存在进行的车辆运单
|
|
|
+ boolean flag = judgmentWaybillOrderIsFinish(id);
|
|
|
+ if (flag) {
|
|
|
+ throw new BusinessException("您现在有车辆运单正在执行中,该订单目前不可完结,请先将运单执行完毕");
|
|
|
+ }
|
|
|
+ //修改单据本身数据
|
|
|
+ logisticsOrder.setTotalLoadAmount(orderFinishDTO.getLoadAmount());
|
|
|
+ logisticsOrder.setTotalUnloadAmount(orderFinishDTO.getUnloadAmount());
|
|
|
+ logisticsOrder.setStatus(LogisticsOrderEnum.HAVE_FINISHED.getCode());
|
|
|
+ logisticsOrder.setUpdateTime(new Date());
|
|
|
+ logisticsOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwtLogisticsOrderMapper.updateById(logisticsOrder);
|
|
|
+ //修改mongodb的数据
|
|
|
+ updateMongoDbByLogisticsOrder(logisticsOrder, orderFinishDTO);
|
|
|
+ //获取物流订单下的子单
|
|
|
+ /**完结订单-对应物流订单下子订单都要进行完结*/
|
|
|
+ List<KwtLogisticsOrder> kwtLogisticsOrders = kwtLogisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getDelFlag, NumberConstant.ZERO)
|
|
|
+ .apply(id != null, "FIND_IN_SET ('" + id + "', pids)").ne(KwtLogisticsOrder::getId, id));
|
|
|
+ //找到该订单下所有的物流订单
|
|
|
+ if (!org.springframework.util.CollectionUtils.isEmpty(kwtLogisticsOrders)) {
|
|
|
+ //修改单据状态
|
|
|
+// List<Long> ids = kwtLogisticsOrders.stream().map(KwtLogisticsOrder::getId).collect(Collectors.toList());
|
|
|
+ //修改单据剩余运输量
|
|
|
+ kwtLogisticsOrders.forEach(kwtLogisticsOrder -> {
|
|
|
+ BigDecimal subtract = kwtLogisticsOrder.getAmount().subtract(kwtLogisticsOrder.getTotalLoadAmount());
|
|
|
+ updateLogisticOrderAndTrack(kwtLogisticsOrder.getId(), orderFinishDTO, subtract);
|
|
|
+ //修改mongodb的数据
|
|
|
+ updateMongoDbByLogisticsOrder(kwtLogisticsOrder,orderFinishDTO);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //todo 直接订单完结-不递归操作
|
|
|
+//
|
|
|
+// //存在子集
|
|
|
+// if (CollectionUtils.isNotEmpty(kwtLogisticsOrders)) {
|
|
|
+// if (kwtLogisticsOrders.size() == 1 && !(kwtLogisticsOrders.get(0).getPids().contains(StringConstant.COMMA))) {
|
|
|
+// //不存在子集
|
|
|
+// /**
|
|
|
+// * 验证是否存在进行中的车辆运单
|
|
|
+// * 统计当前物流订单的 分配量/实装量/实卸量
|
|
|
+// * 验证当前贸易订单是否存在进行中的物流运单
|
|
|
+// * */
|
|
|
+// judgmentLogisticsOrderIsFinish(logisticsOrder);
|
|
|
+// //直接修改数据以及状态
|
|
|
+// } else {
|
|
|
+// //分组排序
|
|
|
+// Map<String, List<KwtLogisticsOrder>> collect1 = kwtLogisticsOrders.stream().collect(Collectors.groupingBy(KwtLogisticsOrder::getLevel,
|
|
|
+// Collectors.collectingAndThen(Collectors.toList(),
|
|
|
+// logisticsOrders -> logisticsOrders.stream().sorted(Comparator.comparing(KwtLogisticsOrder::getLevel).reversed())
|
|
|
+// .collect(Collectors.toList()))
|
|
|
+// ));
|
|
|
+// //查出来最原始的数据
|
|
|
+// List<KwtLogisticsOrder> orderLists = new ArrayList<>();
|
|
|
+// for (List<KwtLogisticsOrder> value : collect1.values()) {
|
|
|
+// orderLists.addAll(value);
|
|
|
+// }
|
|
|
+// //当前订单下的最大分包等级
|
|
|
+// int maxLevel = kwtLogisticsOrderMapper.selectMaxLevel(id);
|
|
|
+// List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+// for (int level = maxLevel; level > 0; level--) {
|
|
|
+// if (maxLevel == level) {
|
|
|
+// List<KwtLogisticsOrder> logisticsOrderList = collect1.get(String.valueOf(level));
|
|
|
+// //操作最底层数据,溯源父级
|
|
|
+// for (KwtLogisticsOrder kwtLogisticsOrder : logisticsOrderList) {
|
|
|
+// BigDecimal entrustAmount = kwtLogisticsOrder.getEntrustAmount();
|
|
|
+// BigDecimal subcontractAmount = kwtLogisticsOrder.getSubcontractAmount();
|
|
|
+// BigDecimal amount = kwtLogisticsOrder.getAmount();
|
|
|
+// BigDecimal loadAmount = kwtLogisticsOrder.getLoadAmount();
|
|
|
+// BigDecimal unloadAmount = kwtLogisticsOrder.getUnloadAmount();
|
|
|
+// //已完成的量
|
|
|
+// BigDecimal subtract = subcontractAmount.add(loadAmount);
|
|
|
+// //本身数据修改(剩余量=上游给的委托量-(分包量+实际装货))
|
|
|
+// //剩余量
|
|
|
+// BigDecimal ignoreAmount = amount.subtract((subcontractAmount.add(loadAmount)));
|
|
|
+// kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+// .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getId())
|
|
|
+// .set(KwtLogisticsOrder::getIgnoreAmount, ignoreAmount)
|
|
|
+// );
|
|
|
+// //最底下根节点-获取父级
|
|
|
+// KwtLogisticsOrder selectOne = kwtLogisticsOrderMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+// .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getPid())
|
|
|
+// );
|
|
|
+// BigDecimal amount1 = selectOne.getAmount();
|
|
|
+// BigDecimal loadAmount1 = selectOne.getLoadAmount();
|
|
|
+// BigDecimal subcontractAmount1 = selectOne.getSubcontractAmount();
|
|
|
+// BigDecimal ignoreAmount1 = selectOne.getIgnoreAmount();
|
|
|
+// subcontractAmount1 = subcontractAmount1.subtract(subtract);
|
|
|
+// ignoreAmount1 = amount1.subtract((subcontractAmount1.add(loadAmount1)));
|
|
|
+// kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+// .eq(KwtLogisticsOrder::getId, selectOne.getId())
|
|
|
+// .set(KwtLogisticsOrder::getSubcontractAmount, subcontractAmount1)
|
|
|
+// .set(KwtLogisticsOrder::getIgnoreAmount, ignoreAmount1)
|
|
|
+// );
|
|
|
+// }
|
|
|
+//// List<KwtLogisticsOrder> collect = logisticsOrderList.stream().filter(item -> StringUtils.isNotBlank(item.getPid())).collect(Collectors.toList());
|
|
|
+// } else {
|
|
|
+// //不是一级,也不是最后一级
|
|
|
+// List<KwtLogisticsOrder> logisticsOrderList = collect1.get(String.valueOf(level));
|
|
|
+// if (CollectionUtils.isNotEmpty(logisticsOrderList)) {
|
|
|
+// for (KwtLogisticsOrder kwtLogisticsOrder : logisticsOrderList) {
|
|
|
+// Map<String, Object> map = new HashMap<>(NumberConstant.SIXTEEN);
|
|
|
+// List<Object> collect = list.stream().map(item -> item.get("level")).collect(Collectors.toList());
|
|
|
+// if (!collect.contains(kwtLogisticsOrder.getId())) {
|
|
|
+// map.put("level", level);
|
|
|
+// map.put("id", kwtLogisticsOrder.getId());
|
|
|
+// list.add(map);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// lllll(list);
|
|
|
+// }
|
|
|
+////
|
|
|
+//// List<Long> collect = kwtLogisticsOrders.stream().map(KwtLogisticsOrder::getId).collect(Collectors.toList());
|
|
|
+//// //验证 是否存在进行中车辆运单
|
|
|
+//// List<KwtLogisticsOrder> kwtLogisticsOrderList = kwtLogisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>().in(KwtLogisticsOrder::getId, collect));
|
|
|
+//// if (CollectionUtils.isNotEmpty(kwtLogisticsOrderList)) {
|
|
|
+//// judgmentLogisticsOrderIsFinish(logisticsOrder);
|
|
|
+//// }
|
|
|
+//// // 按照父级ID分组
|
|
|
+//// //判断是不是一级(一级的情况下,pid为null 方便处理,赋值为OL)
|
|
|
+//// List<KwtLogisticsOrder> list = kwtLogisticsOrders.stream()
|
|
|
+//// .map(object -> {
|
|
|
+//// KwtLogisticsOrder LogisticsOrder = new KwtLogisticsOrder();
|
|
|
+//// BeanUtils.copyProperties(object, LogisticsOrder);
|
|
|
+//// if (LogisticsOrder.getPid() == null) {
|
|
|
+//// LogisticsOrder.setPid(0L);
|
|
|
+//// }
|
|
|
+//// return LogisticsOrder;
|
|
|
+//// })
|
|
|
+//// .collect(Collectors.toList());
|
|
|
+//// Map<Long, List<KwtLogisticsOrder>> groupByParentIdMap = list.stream().collect(Collectors.groupingBy(KwtLogisticsOrder::getPid));
|
|
|
+//// //存放:对应的当前节点ID数据
|
|
|
+//// Set<Long> topToLowerChildIdSet = new HashSet<>();
|
|
|
+//// // 取出顶级数据(也就是父级ID为0的数据 父级ID也可以自定义 当前赋值0L)
|
|
|
+//// List<KwtLogisticsOrder> topTreeNodes = groupByParentIdMap.get(0L);
|
|
|
+//// if (CollectionUtils.isEmpty(topTreeNodes)) {
|
|
|
+//// /**当前传输的代表不是一级 可能是二级或者三级
|
|
|
+//// topTreeNodes = groupByParentIdMap.get(Long.parseLong(id));*/
|
|
|
+//// getMinimumChildIdArray(groupByParentIdMap, Long.parseLong(id), topToLowerChildIdSet);
|
|
|
+//// System.out.println("当前节点【" + id + "】节点下所有的根节点数据集合:" + topToLowerChildIdSet.toString());
|
|
|
+//// //根据等级分组倒序排序
|
|
|
+//// List<KwtLogisticsOrder> orderList = kwtLogisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+//// .in(KwtLogisticsOrder::getId, topToLowerChildIdSet)
|
|
|
+//// );
|
|
|
+////
|
|
|
+//// } else {
|
|
|
+//// for (KwtLogisticsOrder node : topTreeNodes) {
|
|
|
+//// getMinimumChildIdArray(groupByParentIdMap, node.getId(), topToLowerChildIdSet);
|
|
|
+//// }
|
|
|
+//// System.out.println("0节点(传输为一级)下所有的根节点数据集合:" + topToLowerChildIdSet.toString());
|
|
|
+//// }
|
|
|
+//// //处理当前传递的id下 全部完结需要改的量
|
|
|
+//// BigDecimal decimals = new BigDecimal("0.00");
|
|
|
+//// BigDecimal decimal = judgmentOrderFinish(id, topToLowerChildIdSet, decimals, logisticsOrder);
|
|
|
+//// //返回给贸易订单实际装卸货量
|
|
|
+//// Map map = countOrderNumber(logisticsOrder.getTOrderId());
|
|
|
+//// //修改单据状态
|
|
|
+////// updateLogisticOrderStatus(id,orderFinishDTO);
|
|
|
+// } else {
|
|
|
+// throw new BusinessException("不存在物流订单,不可操作!");
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据物流订单修改mongodb数据
|
|
|
+ *
|
|
|
+ * @param logisticsOrder
|
|
|
+ * @param orderFinishDTO
|
|
|
+ */
|
|
|
+ private void updateMongoDbByLogisticsOrder(KwtLogisticsOrder logisticsOrder, OrderFinishDTO orderFinishDTO) {
|
|
|
+ //更新mongodb
|
|
|
+ SckwLogisticsOrder lOrder = new SckwLogisticsOrder();
|
|
|
+ lOrder.set_id(logisticsOrder.getId());
|
|
|
+ lOrder.setLOrderId(logisticsOrder.getId());
|
|
|
+ lOrder.setStatus(LogisticsOrderEnum.HAVE_FINISHED.getStatus());
|
|
|
+ lOrder.setUpdateTime(new Date());
|
|
|
+ lOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ lOrder.setUpdateByName(LoginUserHolder.getUserName());
|
|
|
+ lOrder.setTotalLoadAmount(orderFinishDTO.getLoadAmount());
|
|
|
+ lOrder.setTotalUnloadAmount(orderFinishDTO.getUnloadAmount());
|
|
|
+ //rabbitMq业务汇总数据发送/消费对象
|
|
|
+ SckwBusSum busSum = new SckwBusSum();
|
|
|
+ //业务汇总类型
|
|
|
+ busSum.setBusSumType(BusinessTypeEnum.LOGISTICS_ORDER_TYPE.getName());
|
|
|
+ //操作对象(1新增/2修改/3替换数据)
|
|
|
+ busSum.setMethod(2);
|
|
|
+ //业务汇总数据对象
|
|
|
+ busSum.setObject(lOrder);
|
|
|
+ busSum.setBusSumType(BusinessTypeEnum.LOGISTICS_ORDER_TYPE.getName());
|
|
|
+ busSum.setMethod(NumberConstant.TWO);
|
|
|
+ streamBridge.send("sckw-busSum", JSON.toJSONString(busSum));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void lllll(List<Map<String, Object>> list) {
|
|
|
+ if (!org.springframework.util.CollectionUtils.isEmpty(list) && list.size() > 0) {
|
|
|
+ //倒序排序
|
|
|
+// List<Map<String, Object>> maps = ListUtils.sortMapListByFeild(list, "level", "desc");
|
|
|
+ int level = list.stream().mapToInt(m -> (Integer) m.getOrDefault("level", Long.MAX_VALUE)).max().getAsInt();
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ for (int i = level; i > 0; i--) {
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (String.valueOf(i).equals(String.valueOf(map.get("level")))) {
|
|
|
+ List<KwtLogisticsOrder> orderList = kwtLogisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, map.get("id"))
|
|
|
+ );
|
|
|
+ if (CollectionUtils.isNotEmpty(orderList)) {
|
|
|
+ //操作最底层数据,溯源父级
|
|
|
+ for (KwtLogisticsOrder kwtLogisticsOrder : orderList) {
|
|
|
+ BigDecimal entrustAmount = kwtLogisticsOrder.getEntrustAmount();
|
|
|
+ BigDecimal subcontractAmount = kwtLogisticsOrder.getSubcontractAmount();
|
|
|
+ BigDecimal amount = kwtLogisticsOrder.getAmount();
|
|
|
+ BigDecimal loadAmount = kwtLogisticsOrder.getLoadAmount();
|
|
|
+ BigDecimal unloadAmount = kwtLogisticsOrder.getUnloadAmount();
|
|
|
+ //剩余未完成的量
|
|
|
+ BigDecimal subtract = amount.subtract(loadAmount);
|
|
|
+ //最底下根节点-获取父级
|
|
|
+ if (kwtLogisticsOrder.getPid() == null && kwtLogisticsOrder.getPids().equals(String.valueOf(kwtLogisticsOrder.getId()))) {
|
|
|
+ //代表是一级
|
|
|
+ //todo 当前不做操作
|
|
|
+ } else {
|
|
|
+ KwtLogisticsOrder selectOne = kwtLogisticsOrderMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getPid())
|
|
|
+ );
|
|
|
+ kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, selectOne.getId())
|
|
|
+ .set(KwtLogisticsOrder::getEntrustAmount, selectOne.getEntrustAmount().add(subtract))
|
|
|
+ .set(KwtLogisticsOrder::getSubcontractAmount, selectOne.getSubcontractAmount().subtract(subtract))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ ids.add(kwtLogisticsOrder.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!ObjectUtils.isEmpty(map.get(String.valueOf(i)))) {
|
|
|
+ List<KwtLogisticsOrder> orderList = kwtLogisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, Long.parseLong((String) map.get("id")))
|
|
|
+ );
|
|
|
+ if (CollectionUtils.isNotEmpty(orderList)) {
|
|
|
+ for (KwtLogisticsOrder kwtLogisticsOrder : orderList) {
|
|
|
+ Map<String, Object> maps = new HashMap<>(NumberConstant.SIXTEEN);
|
|
|
+ List<Object> collect = list.stream().map(item -> item.get("level")).collect(Collectors.toList());
|
|
|
+ if (!collect.contains(kwtLogisticsOrder.getId())) {
|
|
|
+ maps.put("level", level);
|
|
|
+ maps.put("id", kwtLogisticsOrder.getId());
|
|
|
+ list.add(maps);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Iterator<Map<String, Object>> iterator = list.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Map<String, Object> next = iterator.next();
|
|
|
+ String key = String.valueOf(next.get(("id")));
|
|
|
+ for (Long id : ids) {
|
|
|
+ if (key.equals(String.valueOf(id))) {
|
|
|
+ iterator.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lllll(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Map countOrderNumber(Long tOrderId) {
|
|
|
+ Map<String, BigDecimal> map = new HashMap<>();
|
|
|
+ BigDecimal loadAmountTotal = new BigDecimal("0.00");
|
|
|
+ BigDecimal unloadAmountTotal = new BigDecimal("0.00");
|
|
|
+ List<KwtLogisticsOrder> kwtLogisticsOrderList = kwtLogisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>().eq(KwtLogisticsOrder::getTOrderId, tOrderId));
|
|
|
+ for (KwtLogisticsOrder kwtLogisticsOrder : kwtLogisticsOrderList) {
|
|
|
+ BigDecimal loadAmount = kwtLogisticsOrder.getLoadAmount();
|
|
|
+ BigDecimal unloadAmount = kwtLogisticsOrder.getUnloadAmount();
|
|
|
+ loadAmountTotal = loadAmountTotal.add(loadAmount);
|
|
|
+ unloadAmountTotal = unloadAmountTotal.add(unloadAmount);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理当前传递的id下 全部完结
|
|
|
+ *
|
|
|
+ * @param id 当前完结物流订单传递id
|
|
|
+ * @param topToLowerChildIdSet 当前传递的下的最末一级的物流订单主键id
|
|
|
+ * @param logisticsOrder 本身物流订单
|
|
|
+ */
|
|
|
+ private BigDecimal judgmentOrderFinish(String id, Set<Long> topToLowerChildIdSet, BigDecimal amount, KwtLogisticsOrder logisticsOrder) {
|
|
|
+ if (CollectionUtils.isNotEmpty(topToLowerChildIdSet)) {
|
|
|
+ List<KwtLogisticsOrder> kwtLogisticsOrderList = kwtLogisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+ .in(KwtLogisticsOrder::getId, topToLowerChildIdSet)
|
|
|
+ );
|
|
|
+ List<KwtLogisticsOrder> logisticsOrders = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(kwtLogisticsOrderList)) {
|
|
|
+ for (KwtLogisticsOrder kwtLogisticsOrder : kwtLogisticsOrderList) {
|
|
|
+ BigDecimal entrustAmount = kwtLogisticsOrder.getEntrustAmount();
|
|
|
+ BigDecimal subcontractAmount = kwtLogisticsOrder.getSubcontractAmount();
|
|
|
+ if (subcontractAmount.compareTo(new BigDecimal("0.00")) == 0) {
|
|
|
+ //最底下根节点-获取父级
|
|
|
+ KwtLogisticsOrder selectOne = kwtLogisticsOrderMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, kwtLogisticsOrder.getPid())
|
|
|
+ );
|
|
|
+ BigDecimal amount1 = kwtLogisticsOrder.getAmount().subtract(entrustAmount.add(subcontractAmount));
|
|
|
+ amount = amount.add(amount1);
|
|
|
+ kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getId, selectOne.getId())
|
|
|
+ .set(KwtLogisticsOrder::getEntrustAmount, selectOne.getEntrustAmount().subtract(kwtLogisticsOrder.getEntrustAmount()))
|
|
|
+ .set(KwtLogisticsOrder::getSubcontractAmount, selectOne.getSubcontractAmount().subtract(kwtLogisticsOrder.getSubcontractAmount()))
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ logisticsOrders.add(kwtLogisticsOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return amount;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void updateLogisticOrderAndTrack(Long lOrderId, OrderFinishDTO orderFinishDTO, BigDecimal ignoreAmount) {
|
|
|
+ Integer code = LogisticsOrderEnum.HAVE_FINISHED.getCode();
|
|
|
+ kwtLogisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
|
|
|
+ .set(KwtLogisticsOrder::getStatus, code)
|
|
|
+ .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
+ .set(KwtLogisticsOrder::getIgnoreAmount, ignoreAmount)
|
|
|
+ .set(KwtLogisticsOrder::getUpdateTime, new Date())
|
|
|
+ .eq(KwtLogisticsOrder::getId, lOrderId)
|
|
|
+ );
|
|
|
+ KwtLogisticsOrderTrack track = kwtLogisticsOrderTrackMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderTrack>()
|
|
|
+ .eq(KwtLogisticsOrderTrack::getLOrderId, lOrderId).eq(KwtLogisticsOrderTrack::getStatus, code)
|
|
|
+ );
|
|
|
+ if (track != null) {
|
|
|
+ kwtLogisticsOrderTrackMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrderTrack>()
|
|
|
+ .set(KwtLogisticsOrderTrack::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
+ .set(KwtLogisticsOrderTrack::getUpdateTime, new Date())
|
|
|
+ .set(KwtLogisticsOrderTrack::getRemark, orderFinishDTO.getRemark())
|
|
|
+ .eq(KwtLogisticsOrderTrack::getId, track.getId())
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ KwtLogisticsOrderTrack orderTrack = new KwtLogisticsOrderTrack();
|
|
|
+ orderTrack.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
+ orderTrack.setLOrderId(lOrderId);
|
|
|
+ orderTrack.setRemark(orderFinishDTO.getRemark());
|
|
|
+ orderTrack.setStatus(code);
|
|
|
+ orderTrack.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ orderTrack.setCreateTime(new Date());
|
|
|
+ orderTrack.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ orderTrack.setUpdateTime(new Date());
|
|
|
+ orderTrack.setDelFlag(NumberConstant.ZERO);
|
|
|
+ kwtLogisticsOrderTrackMapper.insert(orderTrack);
|
|
|
}
|
|
|
- /**完结拦截*/
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据父级节点获取最低层次 那一级的节点数据
|
|
|
+ * 1
|
|
|
+ * / \
|
|
|
+ * 2 3
|
|
|
+ * / \ / \
|
|
|
+ * 4 5 6 7
|
|
|
+ * 上面的树形结构调用此方法 根据1 可以获取到 [4 5 6 7]
|
|
|
+ * 根据3 可以获得到 [6 7]
|
|
|
+ *
|
|
|
+ * @param groupByParentIdMap 所有的元素集合(根据父级ID进行了分组) 分组方法可以使用lambda 如下:
|
|
|
+ * Map<String, List<Person>> peopleByCity = personStream.collect(Collectors.groupingBy(Person::getCity));
|
|
|
+ * @param pid 父级ID
|
|
|
+ * @param topToLowerChildIdSet 存储最深根节点的数据集合
|
|
|
+ */
|
|
|
+ public static Set<Long> getMinimumChildIdArray(Map<Long, List<KwtLogisticsOrder>> groupByParentIdMap,
|
|
|
+ Long pid, Set<Long> topToLowerChildIdSet) {
|
|
|
+ // 存放当前pid对应的所有根节点ID数据
|
|
|
+ Set<Long> currentPidLowerChildIdSet = new HashSet<>();
|
|
|
+ // 获取当前pid下所有的子节点
|
|
|
+ List<KwtLogisticsOrder> childTreeNodes = groupByParentIdMap.get(pid);
|
|
|
+ if (CollUtil.isEmpty(childTreeNodes)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ for (KwtLogisticsOrder treeNode : childTreeNodes) {
|
|
|
+ Set<Long> lowerChildIdSet = getMinimumChildIdArray(groupByParentIdMap, treeNode.getId(), currentPidLowerChildIdSet);
|
|
|
+ if (CollUtil.isEmpty(lowerChildIdSet)) {
|
|
|
+ // 如果返回null 表示当前遍历的treeNode节点为最底层的节点
|
|
|
+ currentPidLowerChildIdSet.add(treeNode.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("当前父级ID:" + pid + "下所有的根节点数据:" + currentPidLowerChildIdSet.toString());
|
|
|
+ // 把当前获取到的根节点数据 一并保存到上一个节点父级ID集合中
|
|
|
+ topToLowerChildIdSet.addAll(currentPidLowerChildIdSet);
|
|
|
+ return currentPidLowerChildIdSet;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证当前物流订单是否存在未完结的车辆运单
|
|
|
+ *
|
|
|
+ * @param id 对应物流订单id
|
|
|
+ */
|
|
|
+ private boolean judgmentWaybillOrderIsFinish(String id) {
|
|
|
+ boolean flag = false;
|
|
|
List<Integer> statusList = new ArrayList<>();
|
|
|
+ statusList.add(CarWaybillEnum.PENDING_ORDER.getCode());
|
|
|
statusList.add(CarWaybillEnum.PENDING_VEHICLE.getCode());
|
|
|
statusList.add(CarWaybillEnum.EXIT_COMPLETED.getCode());
|
|
|
statusList.add(CarWaybillEnum.WAIT_LOADING.getCode());
|
|
|
statusList.add(CarWaybillEnum.COMPLETION_LOADING.getCode());
|
|
|
statusList.add(CarWaybillEnum.WAIT_UNLOADING.getCode());
|
|
|
statusList.add(CarWaybillEnum.COMPLETION_UNLOADING.getCode());
|
|
|
+ statusList.add(CarWaybillEnum.APPROVAL_PASS.getCode());
|
|
|
int count = waybillOrderMapper.selectDataByLorderId(id, statusList);
|
|
|
if (count > NumberConstant.ZERO) {
|
|
|
- throw new RuntimeException("检测您现在有运单正在执行中,该订单目前不可完结,请先将运单执行完毕");
|
|
|
+ flag = true;
|
|
|
}
|
|
|
- /**完结订单-对应物流订单下子订单都要进行完结*/
|
|
|
- List<KwtLogisticsOrder> kwtLogisticsOrders = kwtLogisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
- .in(KwtLogisticsOrder::getPids, Long.parseLong(orderFinishDTO.getId())));
|
|
|
- if (CollectionUtils.isNotEmpty(kwtLogisticsOrders)) {
|
|
|
- for (KwtLogisticsOrder kwtLogisticsOrder : kwtLogisticsOrders) {
|
|
|
- String[] split = kwtLogisticsOrder.getPids().split(StringConstant.COMMA);
|
|
|
- if (split.length > NumberConstant.ONE) {
|
|
|
- for (String s : split) {
|
|
|
- if (String.valueOf(kwtLogisticsOrder.getId()).equals(s)) {
|
|
|
- //本身订单
|
|
|
- //只存在当前订单无分包订单
|
|
|
- /**单据完结修改状态以及数据*/
|
|
|
- updateDataByItself(logisticsOrder, orderFinishDTO);
|
|
|
- } else {
|
|
|
- //修改分包后的订单-代表存在分包订单
|
|
|
- /**单据完结修改状态以及数据*/
|
|
|
- updateDataBySubset(orderFinishDTO, s);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- //只存在当前订单无分包订单
|
|
|
- /**单据完结修改状态以及数据*/
|
|
|
- updateDataByItself(logisticsOrder, orderFinishDTO);
|
|
|
- }
|
|
|
- }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证是否存在进行中的车辆运单
|
|
|
+ * 统计当前物流订单的 分配量/实装量/实卸量
|
|
|
+ * 验证当前贸易订单是否存在进行中的物流运单
|
|
|
+ *
|
|
|
+ * @param logisticsOrder 物流订单数据
|
|
|
+ */
|
|
|
+ public void judgmentLogisticsOrderIsFinish(KwtLogisticsOrder logisticsOrder) {
|
|
|
+ //查询是否存在进行中的车辆运单 取至 CarWaybillEnum 枚举类
|
|
|
+ long[] waybillStatus = {1, 2, 3, 4, 5, 6, 7, 8};
|
|
|
+ List<KwtWaybillOrder> waybillOrders = waybillOrderMapper.selectList(new LambdaQueryWrapper<KwtWaybillOrder>()
|
|
|
+ .eq(KwtWaybillOrder::getLOrderId, logisticsOrder.getId())
|
|
|
+ .in(KwtWaybillOrder::getStatus, waybillStatus));
|
|
|
+ if (CollectionUtils.isNotEmpty(waybillOrders)) {
|
|
|
+ log.info("完结订单时存在进行中的车辆运单,物流订单id:{},物流订单编号:{},车辆运单:{}",
|
|
|
+ logisticsOrder.getId(), logisticsOrder.getLOrderNo(), JSONObject.toJSONString(waybillOrders));
|
|
|
+ throw new BusinessException("不能进行订单完结,存在进行中的车辆运单");
|
|
|
+ }
|
|
|
+ //获取贸易订单下物流运单是否存在进行中的单据(贸易订单统计物流订单) 取至 LogisticsOrderEnum枚举类
|
|
|
+ long[] logisticsStatus = {0, 1, 2, 3};
|
|
|
+ List<KwtLogisticsOrder> orderList = kwtLogisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getTOrderId, logisticsOrder.getTOrderId())
|
|
|
+ .in(KwtLogisticsOrder::getStatus, logisticsStatus));
|
|
|
+ boolean flag = true;
|
|
|
+ if (CollectionUtils.isNotEmpty(orderList)) {
|
|
|
+ log.info("完结订单时存在当前进行中的贸易订单下的物流运单,物流订单id:{},物流订单编号:{},贸易订单id:{},贸易订单编号:{},当前贸易订单其他物流订单:{}",
|
|
|
+ logisticsOrder.getId(), logisticsOrder.getLOrderNo(), logisticsOrder.getTOrderId(), JSONObject.toJSONString(waybillOrders), JSONObject.toJSONString(orderList));
|
|
|
+ throw new BusinessException("完结订单时存在当前进行中的贸易订单下的物流运单");
|
|
|
}
|
|
|
+ //防止事务脏读,幻读.重新查询 物流订单数据
|
|
|
+// KwtLogisticsOrder kwtLogisticsOrder = kwtLogisticsOrderMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrder>().eq(KwtLogisticsOrder::getId, logisticsOrder.getId()));
|
|
|
+// CompleteLogisticsOrderParam param = new CompleteLogisticsOrderParam();
|
|
|
+// param.setTOrderId(logisticsOrder.getTOrderId());
|
|
|
+// param.setEntrustAmount(kwtLogisticsOrder.getAmount().negate());
|
|
|
+// param.setActualLoadAmount(kwtLogisticsOrder.getLoadAmount());
|
|
|
+// param.setActualUnloadAmount(kwtLogisticsOrder.getUnloadAmount());
|
|
|
+// param.setIsAllComplete(flag);
|
|
|
+// param.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+// param.setUpdateByName(LoginUserHolder.getUserName());
|
|
|
+// tradeOrderInfoService.completeLogisticsOrder(param);
|
|
|
}
|
|
|
|
|
|
- private void updateDataBySubset(OrderFinishDTO orderFinishDTO, String orderId) {
|
|
|
+ public void updateDataBySubset(OrderFinishDTO orderFinishDTO, String orderId) {
|
|
|
KwtLogisticsOrder kwtLogisticsOrder = kwtLogisticsOrderMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
.eq(KwtLogisticsOrder::getId, Long.parseLong(orderId)));
|
|
|
if (kwtLogisticsOrder != null) {
|
|
|
@@ -1012,16 +1492,27 @@ public class LogisticsConsignmentService {
|
|
|
kwtLogisticsOrder.setUpdateTime(new Date());
|
|
|
kwtLogisticsOrder.setRemark(orderFinishDTO.getRemark());
|
|
|
kwtLogisticsOrderMapper.updateById(kwtLogisticsOrder);
|
|
|
- KwtLogisticsOrderTrack track = new KwtLogisticsOrderTrack();
|
|
|
- track.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
- track.setLOrderId(kwtLogisticsOrder.getId());
|
|
|
- track.setStatus(LogisticsOrderEnum.HAVE_FINISHED.getCode());
|
|
|
- track.setCreateTime(new Date());
|
|
|
- track.setRemark(orderFinishDTO.getRemark());
|
|
|
- track.setCreateBy(LoginUserHolder.getUserId());
|
|
|
- track.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
- track.setUpdateTime(new Date());
|
|
|
- kwtLogisticsOrderTrackMapper.insert(track);
|
|
|
+ KwtLogisticsOrderTrack logisticsOrderTrack = kwtLogisticsOrderTrackMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderTrack>()
|
|
|
+ .eq(KwtLogisticsOrderTrack::getLOrderId, orderId)
|
|
|
+ .eq(KwtLogisticsOrderTrack::getStatus, LogisticsOrderEnum.HAVE_FINISHED.getCode()));
|
|
|
+ if (logisticsOrderTrack == null) {
|
|
|
+ KwtLogisticsOrderTrack track = new KwtLogisticsOrderTrack();
|
|
|
+ track.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
+ track.setLOrderId(kwtLogisticsOrder.getId());
|
|
|
+ track.setStatus(LogisticsOrderEnum.HAVE_FINISHED.getCode());
|
|
|
+ track.setCreateTime(new Date());
|
|
|
+ track.setRemark(orderFinishDTO.getRemark());
|
|
|
+ track.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ track.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ track.setUpdateTime(new Date());
|
|
|
+ kwtLogisticsOrderTrackMapper.insert(track);
|
|
|
+ } else {
|
|
|
+ kwtLogisticsOrderTrackMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrderTrack>()
|
|
|
+ .eq(KwtLogisticsOrderTrack::getLOrderId, orderId)
|
|
|
+ .set(KwtLogisticsOrderTrack::getRemark, orderFinishDTO.getRemark())
|
|
|
+ .set(KwtLogisticsOrderTrack::getUpdateTime, new Date())
|
|
|
+ .set(KwtLogisticsOrderTrack::getUpdateBy, LoginUserHolder.getUserId()));
|
|
|
+ }
|
|
|
/**单据完结修改Mongodb*/
|
|
|
SckwLogisticsOrder updateParam = new SckwLogisticsOrder();
|
|
|
updateParam.setLOrderId(kwtLogisticsOrder.getId())
|
|
|
@@ -1049,16 +1540,27 @@ public class LogisticsConsignmentService {
|
|
|
logisticsOrder.setUpdateTime(new Date());
|
|
|
logisticsOrder.setRemark(orderFinishDTO.getRemark());
|
|
|
kwtLogisticsOrderMapper.updateById(logisticsOrder);
|
|
|
- KwtLogisticsOrderTrack track = new KwtLogisticsOrderTrack();
|
|
|
- track.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
- track.setLOrderId(logisticsOrder.getId());
|
|
|
- track.setStatus(LogisticsOrderEnum.HAVE_FINISHED.getCode());
|
|
|
- track.setCreateTime(new Date());
|
|
|
- track.setRemark(orderFinishDTO.getRemark());
|
|
|
- track.setCreateBy(LoginUserHolder.getUserId());
|
|
|
- track.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
- track.setUpdateTime(new Date());
|
|
|
- kwtLogisticsOrderTrackMapper.insert(track);
|
|
|
+ KwtLogisticsOrderTrack logisticsOrderTrack = kwtLogisticsOrderTrackMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderTrack>()
|
|
|
+ .eq(KwtLogisticsOrderTrack::getLOrderId, logisticsOrder.getId())
|
|
|
+ .eq(KwtLogisticsOrderTrack::getStatus, LogisticsOrderEnum.HAVE_FINISHED.getCode()));
|
|
|
+ if (logisticsOrderTrack == null) {
|
|
|
+ KwtLogisticsOrderTrack track = new KwtLogisticsOrderTrack();
|
|
|
+ track.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
+ track.setLOrderId(logisticsOrder.getId());
|
|
|
+ track.setStatus(LogisticsOrderEnum.HAVE_FINISHED.getCode());
|
|
|
+ track.setCreateTime(new Date());
|
|
|
+ track.setRemark(orderFinishDTO.getRemark());
|
|
|
+ track.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ track.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ track.setUpdateTime(new Date());
|
|
|
+ kwtLogisticsOrderTrackMapper.insert(track);
|
|
|
+ } else {
|
|
|
+ kwtLogisticsOrderTrackMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrderTrack>()
|
|
|
+ .eq(KwtLogisticsOrderTrack::getLOrderId, logisticsOrder.getId())
|
|
|
+ .set(KwtLogisticsOrderTrack::getRemark, orderFinishDTO.getRemark())
|
|
|
+ .set(KwtLogisticsOrderTrack::getUpdateTime, new Date())
|
|
|
+ .set(KwtLogisticsOrderTrack::getUpdateBy, LoginUserHolder.getUserId()));
|
|
|
+ }
|
|
|
/**单据完结修改Mongodb*/
|
|
|
SckwLogisticsOrder updateParam = new SckwLogisticsOrder();
|
|
|
updateParam.setLOrderId(Long.parseLong(orderFinishDTO.getId()))
|