From da4495adb23e6bd4e0cbf70f98f35ba04231a78b Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期日, 04 二月 2024 17:36:04 +0800
Subject: [PATCH] 添加 根据资料类别查询目录 接口

---
 src/main/java/com/lf/server/service/show/DataLibService.java |   55 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/lf/server/service/show/DataLibService.java b/src/main/java/com/lf/server/service/show/DataLibService.java
index cb9c738..88f9bf4 100644
--- a/src/main/java/com/lf/server/service/show/DataLibService.java
+++ b/src/main/java/com/lf/server/service/show/DataLibService.java
@@ -2,6 +2,7 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.lf.server.entity.ctrl.DownloadReqEntity;
+import com.lf.server.entity.ctrl.KeyValueEntity;
 import com.lf.server.entity.data.DownloadEntity;
 import com.lf.server.entity.sys.AttachEntity;
 import com.lf.server.entity.sys.UserEntity;
@@ -17,6 +18,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 
 import java.io.File;
 import java.util.*;
@@ -26,6 +28,7 @@
  * @author WWW
  */
 @Service
+@SuppressWarnings("ALL")
 public class DataLibService {
     @Autowired
     PathHelper pathHelper;
@@ -284,15 +287,16 @@
             return null;
         }
 
-        List<String> list = codesAsList(codes);
-        list = copeDirCodes(list);
+        List<String> list = Arrays.asList(codes.split(","));
+        //List<String> list = codesAsList(codes);
+        //list = copeDirCodes(list);
         setRightLike(list, field);
 
         return "(" + StringHelper.join(list, " or ") + ")";
     }
 
     /**
-     * 鍗曚綅缂栫爜杞泦鍚�
+     * 鍗曚綅缂栫爜杞泦鍚� *
      */
     private static List<String> codesAsList(String codes) {
         List<String> list = Arrays.asList(codes.split(","));
@@ -305,7 +309,7 @@
     }
 
     /**
-     * 澶勭悊鐩綍缂栫爜
+     * 澶勭悊鐩綍缂栫爜 *
      */
     private static List<String> copeDirCodes(List<String> list) {
         List<String> prjList = getDirCodesByLen(list, 0, 2);
@@ -324,7 +328,7 @@
     }
 
     /**
-     * 鏍规嵁闀垮害鑾峰彇鍗曚綅缂栫爜
+     * 鏍规嵁闀垮害鑾峰彇鍗曚綅缂栫爜 *
      */
     private static List<String> getDirCodesByLen(List<String> list, int start, int end) {
         List<String> rs = new ArrayList<>();
@@ -342,7 +346,7 @@
     }
 
     /**
-     * 杩囨护椤圭洰缂栫爜
+     * 杩囨护椤圭洰缂栫爜 *
      */
     private static List<String> filterCodes(List<String> prjList, List<String> appList) {
         int i = 0;
@@ -369,14 +373,49 @@
      * 璁剧疆 鍙砽ike
      */
     private static void setRightLike(List<String> list, String field) {
-        if (list.isEmpty()) {
+        /*if (list.isEmpty()) {
             list.add("1 = 2");
             return;
-        }
+        }*/
 
         for (int i = 0, c = list.size(); i < c; i++) {
             String str = String.format("%s like '%s%%'", field, list.get(i));
             list.set(i, str);
         }
     }
+
+    /**
+     * 鏍规嵁璧勬枡绫诲埆鑾峰彇鐩綍缂栫爜
+     */
+    public String getDirsByTypes(String types, String dirs, String field) {
+        if (StringUtils.isEmpty(types) && StringUtils.isEmpty(dirs)) {
+            return null;
+        }
+
+        if (!StringUtils.isEmpty(types)) {
+            List<KeyValueEntity> list = baseQueryService.selectDirsByTypes(types, dirs);
+            if (null == list || list.isEmpty()) {
+                return null;
+            }
+
+            return copeDirs(list, field);
+        }
+
+        return copeCodes(dirs, field);
+    }
+
+    /**
+     * 澶勭悊鐩綍缂栫爜
+     */
+    public static String copeDirs(List<KeyValueEntity> kvs, String field) {
+        List<String> list = new ArrayList<>();
+        for (KeyValueEntity kv : kvs) {
+            String[] dirs = kv.getValue().split(",");
+            for (String dir : dirs) {
+                list.add(String.format("%s like '%s%%'", field, dir));
+            }
+        }
+
+        return "(" + StringHelper.join(list, " or ") + ")";
+    }
 }

--
Gitblit v1.9.3