|
|
@@ -1,16 +1,20 @@
|
|
|
package com.sckw.transport.service;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
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.contract.api.model.dto.res.ContractCommonInfoResDto;
|
|
|
+import com.sckw.core.annotation.Log;
|
|
|
import com.sckw.core.common.enums.NumberConstant;
|
|
|
import com.sckw.core.common.enums.enums.DictEnum;
|
|
|
import com.sckw.core.common.enums.enums.DictTypeEnum;
|
|
|
+import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.model.enums.LogisticsOrderEnum;
|
|
|
import com.sckw.core.model.page.PageResult;
|
|
|
+import com.sckw.core.utils.BeanUtils;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.IdWorker;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
|
@@ -36,8 +40,7 @@ import com.sckw.transport.model.dto.CancelOrderDTO;
|
|
|
import com.sckw.transport.model.dto.DocumentParamDTO;
|
|
|
import com.sckw.transport.model.param.ContractParam;
|
|
|
import com.sckw.transport.model.param.LogisticsOrderParam;
|
|
|
-import com.sckw.transport.model.vo.OrderDetailVO;
|
|
|
-import com.sckw.transport.model.vo.SckwLogisticsOrderVO;
|
|
|
+import com.sckw.transport.model.vo.*;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
@@ -733,4 +736,231 @@ public class TransportCommonService {
|
|
|
PageResult build = PageResult.build(contractParam.getPage(), contractParam.getPageSize(), list.stream().count(), returnList);
|
|
|
return HttpResult.ok(build);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param lOrderId 承运订单ID
|
|
|
+ * @desc 完结物流订单数据处理
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/9/18
|
|
|
+ **/
|
|
|
+ public void closeHandle(Long lOrderId) {
|
|
|
+ /**1数据校验**/
|
|
|
+ KwtLogisticsOrder logisticsOrder = logisticsOrderMapper.selectById(lOrderId);
|
|
|
+ if (logisticsOrder == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**2物流订单树形数据结构**/
|
|
|
+ //所有管理物流订单
|
|
|
+ List<KwtLogisticsOrder> orders = logisticsOrderMapper.findLogisticsOrder(new HashMap<>(){{
|
|
|
+ put("upperlOrderId", lOrderId);
|
|
|
+ put("belowlOrderId", logisticsOrder.getPids());
|
|
|
+ }});
|
|
|
+ //数据copy
|
|
|
+ List<KwtLogisticsOrderTreeVo> logisticsOrders = orders.stream().map( order -> {
|
|
|
+ KwtLogisticsOrderTreeVo logisticsOrderVo = new KwtLogisticsOrderTreeVo();
|
|
|
+ BeanUtils.copyPropertiesValue(order, logisticsOrderVo);
|
|
|
+ return logisticsOrderVo;
|
|
|
+ }
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ List<KwtLogisticsOrderTreeVo> treeData = findTree(logisticsOrders);
|
|
|
+ /**数据去除已完结订单下级*/
|
|
|
+ orderTreeHandle(treeData);
|
|
|
+
|
|
|
+ /**3链路数据组装*/
|
|
|
+ List<List<KwtLogisticsOrderTreeVo>> orderLinks = new ArrayList<>();
|
|
|
+ for (KwtLogisticsOrderTreeVo order:treeData) {
|
|
|
+ Stack<KwtLogisticsOrderTreeVo> pathStack = new Stack<>();
|
|
|
+ iteratorNode(order, pathStack, orderLinks);
|
|
|
+ }
|
|
|
+ List<KwtLogisticsOrderTreeVo> orderLink = findLink(orderLinks, lOrderId);
|
|
|
+ //倒序
|
|
|
+ Collections.reverse(orderLink);
|
|
|
+
|
|
|
+ /**4数据处理**/
|
|
|
+ for (KwtLogisticsOrderTreeVo order:orderLink) {
|
|
|
+ //排除已完结订单
|
|
|
+ if (Objects.equals(order.getStatus(), LogisticsOrderEnum.HAVE_FINISHED.getCode())) {
|
|
|
+ //计算总装总卸向上级统计
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //车辆运单统计(运输中的物流订单+车辆运单审核通过)
|
|
|
+ WaybillCountVo waybillCount = waybillOrderMapper.findWaybillOrderCount(new HashMap() {{
|
|
|
+ put("upperlOrderId", order.getId());
|
|
|
+ put("passStatus", Global.NUMERICAL_ONE);
|
|
|
+ put("logisticsStatus", LogisticsOrderEnum.IN_TRANSIT.getCode());
|
|
|
+ }});
|
|
|
+ //物流订单统计(运输完成后的物流订单)
|
|
|
+ LogisticsCountVo LogisticsCount = logisticsOrderMapper.findLogisticsOrderCount(new HashMap(){{
|
|
|
+ put("upperlOrderId", order.getId());
|
|
|
+ put("finishedStatus", Global.NUMERICAL_ONE);
|
|
|
+ }});
|
|
|
+
|
|
|
+ KwtLogisticsOrder currentOrder = logisticsOrderMapper.selectById(lOrderId);
|
|
|
+ currentOrder.setTotalLoadAmount(waybillCount.getLoadAmount().add(LogisticsCount.getLoadAmount()));
|
|
|
+ currentOrder.setTotalUnloadAmount(waybillCount.getUnloadAmount().add(LogisticsCount.getUnloadAmount()));
|
|
|
+ logisticsOrderMapper.updateById(currentOrder);
|
|
|
+
|
|
|
+ /**Mongodb数据更新**/
|
|
|
+ SckwLogisticsOrder lOrder = new SckwLogisticsOrder();
|
|
|
+ lOrder.setTotalLoadAmount(waybillCount.getLoadAmount());
|
|
|
+ lOrder.setTotalUnloadAmount(waybillCount.getUnloadAmount());
|
|
|
+ SckwBusSum busSum = new SckwBusSum();
|
|
|
+ //业务汇总类型
|
|
|
+ busSum.setBusSumType(BusinessTypeEnum.LOGISTICS_ORDER_TYPE.getName());
|
|
|
+ //操作对象(1新增/2修改)
|
|
|
+ busSum.setMethod(NumberConstant.TWO);
|
|
|
+ //业务汇总数据对象
|
|
|
+ busSum.setObject(order);
|
|
|
+ streamBridge.send("sckw-busSum", JSON.toJSONString(busSum));
|
|
|
+
|
|
|
+ //一级物流订单向贸易订单推送数据
|
|
|
+ if (order.getPid() == null) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param treeData 物流订单树形数据
|
|
|
+ * @desc 数据去除已完结订单下级
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/9/18
|
|
|
+ **/
|
|
|
+ public static void orderTreeHandle(List<KwtLogisticsOrderTreeVo> treeData){
|
|
|
+ if (CollectionUtil.isEmpty(treeData)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KwtLogisticsOrderTreeVo order:treeData) {
|
|
|
+ orderTreeHandle(order.getChildren());
|
|
|
+ if (order.getStatus() == 4) {
|
|
|
+ order.setChildren(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param orders 物流订单
|
|
|
+ * @desc 树形数据处理
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/9/18
|
|
|
+ **/
|
|
|
+ public static List<KwtLogisticsOrderTreeVo> findTree(List<KwtLogisticsOrderTreeVo> orders) {
|
|
|
+ //跟节点
|
|
|
+ List<KwtLogisticsOrderTreeVo> rootList = new ArrayList();
|
|
|
+
|
|
|
+ //获取根节点数据
|
|
|
+ if (CollectionUtil.isNotEmpty(orders)) {
|
|
|
+ for(KwtLogisticsOrderTreeVo order:orders){
|
|
|
+ if (order.getPid() == null) {
|
|
|
+ rootList.add(order);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //遍历,找到二级节点(根节点的id和所有节点中的pid比较)
|
|
|
+ for (KwtLogisticsOrderTreeVo order : rootList) {
|
|
|
+ List<KwtLogisticsOrderTreeVo> child = getChild(order.getId(), orders);
|
|
|
+ order.setChildren(child);
|
|
|
+ }
|
|
|
+
|
|
|
+ return rootList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param pid 上级物流订单ID
|
|
|
+ * @param orders 物流订单
|
|
|
+ * @desc 树形数据处理-递归
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/9/18
|
|
|
+ **/
|
|
|
+ public static List<KwtLogisticsOrderTreeVo> getChild(Long pid, List<KwtLogisticsOrderTreeVo> orders) {
|
|
|
+ List<KwtLogisticsOrderTreeVo> childList = new ArrayList();
|
|
|
+ for (KwtLogisticsOrderTreeVo order : orders) {
|
|
|
+ if(pid.equals(order.getPid())){
|
|
|
+ //获取当前节点id的所有子列表
|
|
|
+ childList.add(order);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (KwtLogisticsOrderTreeVo order : childList) {
|
|
|
+ //将该id的子节点进行遍历,通过递归调用,获取每一个子节点的子节点数据
|
|
|
+ List<KwtLogisticsOrderTreeVo> child = getChild(order.getId(), orders);
|
|
|
+ order.setChildren(child);
|
|
|
+ }
|
|
|
+ if(childList.size()==0){
|
|
|
+ //子节点的长度为0,返回null,null不会被阿里的FastJson包解析
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return childList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param: order 当前节点
|
|
|
+ * @param: pathstack 栈
|
|
|
+ * @param: orderLinks 设备链路信息
|
|
|
+ * @desc 链路组装
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/8/8
|
|
|
+ **/
|
|
|
+ public static void iteratorNode(KwtLogisticsOrderTreeVo order, Stack<KwtLogisticsOrderTreeVo> pathstack, List orderLinks) {
|
|
|
+ //入栈
|
|
|
+ pathstack.push(order);
|
|
|
+ List childlist = order.getChildren();
|
|
|
+ //没有子节点 说明是叶子结点
|
|
|
+ if (childlist == null){
|
|
|
+ List list = new ArrayList();
|
|
|
+ Iterator stackIt = pathstack.iterator();
|
|
|
+ while (stackIt.hasNext()) {
|
|
|
+ list.add(stackIt.next());
|
|
|
+ }
|
|
|
+ List<KwtLogisticsOrderTreeVo> orders = print(list);
|
|
|
+ orderLinks.add(orders);
|
|
|
+ } else {
|
|
|
+ Iterator iterator = childlist.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ KwtLogisticsOrderTreeVo child = (KwtLogisticsOrderTreeVo) iterator.next();
|
|
|
+ //深度优先 进入递归
|
|
|
+ iteratorNode(child, pathstack, orderLinks);
|
|
|
+ //回溯时候出栈
|
|
|
+ pathstack.pop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param list 树形数据
|
|
|
+ * @desc 链路组装
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/8/8
|
|
|
+ **/
|
|
|
+ private static List<KwtLogisticsOrderTreeVo> print(List list) {
|
|
|
+ List<KwtLogisticsOrderTreeVo> orders = new ArrayList();
|
|
|
+ Iterator iterator = list.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ KwtLogisticsOrderTreeVo order = (KwtLogisticsOrderTreeVo) iterator.next();
|
|
|
+ order.setChildren(null);
|
|
|
+ orders.add(order);
|
|
|
+ }
|
|
|
+ return orders;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param orderLinks 物流订单链路信息
|
|
|
+ * @param lOrderId 物流订单id
|
|
|
+ * @desc 获取当前物流订单垂直链路
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/9/18
|
|
|
+ **/
|
|
|
+ public static List<KwtLogisticsOrderTreeVo> findLink(List<List<KwtLogisticsOrderTreeVo>> orderLinks, Long lOrderId) {
|
|
|
+ for (List<KwtLogisticsOrderTreeVo> logisticsOrders:orderLinks) {
|
|
|
+ for (KwtLogisticsOrderTreeVo order:logisticsOrders) {
|
|
|
+ if (Objects.equals(lOrderId, order.getId())) {
|
|
|
+ return logisticsOrders;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|