From 85e36a5016633748bbd76bb4ddaef49566a505d5 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期四, 08 五月 2025 17:57:31 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/WarehouseServiceImpl.java |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/WarehouseServiceImpl.java b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/WarehouseServiceImpl.java
index c4e7a2c..50083ca 100644
--- a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/WarehouseServiceImpl.java
+++ b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/WarehouseServiceImpl.java
@@ -1,11 +1,22 @@
 package org.jeecg.modules.tms.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.jeecg.common.api.vo.CommonGenericTree;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.util.StrUtils;
 import org.jeecg.modules.tms.entity.Warehouse;
 import org.jeecg.modules.tms.mapper.WarehouseMapper;
 import org.jeecg.modules.tms.service.IWarehouseService;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import java.util.*;
 
 /**
  * @Description: tms_warehouse
@@ -16,4 +27,108 @@
 @Service
 public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements IWarehouseService {
 
+    @Override
+    public List<CommonGenericTree<Warehouse>> loadTree() {
+        List<Warehouse> warehouseList = list(new LambdaQueryWrapper<Warehouse>()
+                .eq(Warehouse::getStatus, CommonConstant.STATUS_1));
+        return loadTree(warehouseList);
+    }
+
+    @Override
+    public IPage<Warehouse> queryPageList(Page<Warehouse> page, Map<String, String[]> parameterMap) {
+        QueryWrapper<Warehouse> queryWrapper = Wrappers.query();
+        String[] warehouseNames = parameterMap.get("warehouseName");
+        if (warehouseNames != null && warehouseNames.length > 0) {
+            queryWrapper.like("t.warehouse_name", warehouseNames[0]);
+        }
+        String[] parentIds = parameterMap.get("parentId");
+        if (parentIds != null && parentIds.length > 0) {
+            queryWrapper.eq("t.parent_id", parentIds[0]);
+        }
+        String[] beginTimes = parameterMap.get("beginTime");
+        String[] endTimes = parameterMap.get("endTime");
+        if (beginTimes != null && beginTimes.length > 0) {
+            queryWrapper.ge("t.create_time", beginTimes[0]);
+        }
+        if (endTimes != null && endTimes.length > 0) {
+            queryWrapper.le("t.create_time", endTimes[0]);
+        }
+        queryWrapper.orderByAsc("t.seq");
+        return this.baseMapper.queryPageList(page, queryWrapper);
+    }
+
+    private List<CommonGenericTree<Warehouse>> loadTree(List<Warehouse> warehouseList) {
+        Warehouse warehouse = new Warehouse();
+        List<CommonGenericTree<Warehouse>> list = new ArrayList<>();
+        Map<String, CommonGenericTree<Warehouse>> map = new HashMap<>();
+        CommonGenericTree<Warehouse> node = new CommonGenericTree<>();//鎵嬪姩鍒涘缓鏍硅妭鐐�
+        node.setKey("-1");
+        node.setTitle("鑸畤鏁戠敓");
+        node.setRField1("");
+        node.setRField2("");
+        node.setEntity(new Warehouse()
+                .setId("-1")
+                .setWarehouseId("-1")
+                .setWarehouseName("鑸畤鏁戠敓")
+                .setLeafFlag("2"));
+        list.add(node);
+        if (CollectionUtils.isNotEmpty(warehouseList)) {
+            CommonGenericTree<Warehouse> tcNode;
+            for (Warehouse wh : warehouseList) {
+                if (StrUtils.isBlankOrNull(wh.getParentId()) || wh.getParentId().equals("-1")) {
+                    tcNode = new CommonGenericTree<>();
+                    tcNode.setKey(wh.getId());
+                    tcNode.setTitle(wh.getWarehouseId() + "/" + wh.getWarehouseName());
+                    tcNode.setParentId(node.getKey());
+                    tcNode.setIcon("");
+                    tcNode.setType(1);
+                    tcNode.setValue(wh.getWarehouseName());
+                    //tcNode.setDisabled(CommonConstant.STATUS_0.equals(wh.getStatus()) ? true : false);
+                    tcNode.setRField1(wh.getWarehouseId());
+                    tcNode.setRField2(getBaseParent(wh.getId(), 0).getWarehouseId());
+                    tcNode.setEntity(wh);
+                    node.addChildren(tcNode);
+                    map.put(wh.getId(), tcNode);
+                }
+            }
+            CommonGenericTree<Warehouse> childNode;
+            for (Warehouse wh : warehouseList) {
+                Warehouse child = wh;
+                if (map.containsKey(child.getParentId())) {
+                    if (StrUtils.isBlankOrNull(wh.getParentId()) || wh.getParentId().equals("-1")) {
+                        warehouse = wh;
+                    } else {
+                        tcNode = map.get(child.getParentId());
+                        childNode = new CommonGenericTree<>();
+                        childNode.setKey(wh.getId());
+                        childNode.setTitle(wh.getWarehouseId() + "/" + wh.getWarehouseName());
+                        childNode.setParentId(wh.getParentId());
+                        childNode.setIcon("");
+                        childNode.setType(0);
+                        childNode.setValue(wh.getWarehouseName());
+                        //childNode.setDisabled(CommonConstant.STATUS_0.equals(wh.getStatus()) ? true : false);
+                        childNode.setRField1(wh.getWarehouseId());
+                        childNode.setRField2(getBaseParent(wh.getId(), 0).getWarehouseId());
+                        childNode.setEntity(wh);
+                        tcNode.addChildren(childNode);
+                        map.put(child.getId(), childNode);
+                    }
+                }
+            }
+        }
+        return list;
+    }
+
+    public Warehouse getBaseParent(String id, int index) {
+        Warehouse warehouse = null;
+        if (index < 99) {
+            warehouse = getById(id);
+            if (StrUtils.isNotBlankOrNull(warehouse.getParentId())) {
+                if (!warehouse.getParentId().equals("-1")) {
+                    warehouse = getBaseParent(warehouse.getParentId(), index++);
+                }
+            }
+        }
+        return warehouse;
+    }
 }

--
Gitblit v1.9.3