From 3eb37463a952fb69d586769ca660886b956cb016 Mon Sep 17 00:00:00 2001
From: zqy <2522236926@qq.com>
Date: 星期二, 30 十二月 2025 12:24:40 +0800
Subject: [PATCH] 人物搜索 新加所有家族模块

---
 zhang-content/src/main/java/com/ruoyi/service/impl/InterfaceBasedSearchRouter.java |  349 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 182 insertions(+), 167 deletions(-)

diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/InterfaceBasedSearchRouter.java b/zhang-content/src/main/java/com/ruoyi/service/impl/InterfaceBasedSearchRouter.java
index d6d25ed..e47aa94 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/InterfaceBasedSearchRouter.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/InterfaceBasedSearchRouter.java
@@ -1,20 +1,18 @@
 package com.ruoyi.service.impl;
 
 import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.core.domain.entity.SysMenu;
 import com.ruoyi.domain.ModuleSearchResult;
+import com.ruoyi.domain.PeopleSea;
 import com.ruoyi.service.ModuleSearchable;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
-import javax.annotation.Resource;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -50,54 +48,61 @@
 
     @Async
     public CompletableFuture<ModuleSearchResult> searchModuleAsync(String moduleCode, ModuleSearchable service,
-                                                                   String companion, Date startTime, Date endTime,String hasAttachment) {
+                                                                   String companion, Date startTime, Date endTime,
+                                                                   String hasAttachment) {
         long start = System.currentTimeMillis();
         try {
-            List<?> data = service.search(companion, startTime, endTime,hasAttachment);
+            // 璋冪敤鎼滅储鏂规硶锛岃繑鍥� List<?>
+            List<?> data = service.search(companion, startTime, endTime, hasAttachment);
             long searchTime = System.currentTimeMillis() - start;
+
+            int count = 0;
+            if (data != null) {
+                count = data.size();
+            }
+
+            // 鑾峰彇妯″潡鍚嶇О
+            String moduleName = getModuleName(moduleCode);
+
             ModuleSearchResult result = ModuleSearchResult.success(
-                moduleCode, service.getModuleName(), data, data.size(), searchTime
+                moduleCode, moduleName, data, count, searchTime
             );
             return CompletableFuture.completedFuture(result);
         } catch (Exception e) {
-            log.error("妯″潡[{}]鎼滅储澶辫触: {}", moduleCode, e.getMessage());
-            ModuleSearchResult result = ModuleSearchResult.error(moduleCode, e.getMessage());
+            log.error("妯″潡[{}]鎼滅储澶辫触: {}", moduleCode, e.getMessage(), e);
+            String errorMessage = e.getMessage();
+            if (e.getCause() != null) {
+                errorMessage += " (" + e.getCause().getMessage() + ")";
+            }
+            ModuleSearchResult result = ModuleSearchResult.error(moduleCode, errorMessage);
             return CompletableFuture.completedFuture(result);
         }
     }
 
     /**
-     * 閫氱敤鐨勮矾鐢辨悳绱㈣姹� - 缁熶竴鏁版嵁缁撴瀯鐗�
-     * 鏀寔鍔熻兘锛�
-     * 1. 鍗曚釜妯″潡锛� "module1"
-     * 2. 澶氫釜妯″潡锛� "module1,module2,module3" 锛堥�楀彿鍒嗛殧锛�
-     * 3. 鍏ㄦā鍧楋細   "all" 鎴� null 鎴� 绌哄瓧绗︿覆
-     * 4. 涓嶉�夋ā鍧楋細 鎸囧畾涓虹壒瀹氬�硷紝濡�"none"锛堝彲閫夊姛鑳斤級
-     *
-     * 缁熶竴杩斿洖鏁版嵁缁撴瀯锛�
-     * {
-     *   "success": true,
-     *   "data": {
-     *     "modules": {
-     *       "module1": { "data": [...], "count": 10, "searchTime": 100, "success": true },
-     *       "module2": { "error": "閿欒淇℃伅", "success": false }
-     *     },
-     *     "totalSelectedModules": 2,
-     *     "successModules": 1,
-     *     "errorModules": ["module2"],
-     *     "totalRecords": 10,
-     *     "searchTime": "2023-01-01T00:00:00.000+00:00",
-     *     "message": "鎼滅储瀹屾垚: 鎴愬姛1/2涓ā鍧楋紝鎬昏10鏉¤褰�"
-     *   }
-     * }
+     * 閫氱敤鐨勮矾鐢辨悳绱㈣姹�
      */
-    public AjaxResult routeSearch(String moduleCode, Object... args) {
-        log.info("璺敱鎼滅储: moduleCode={}, args={}", moduleCode, Arrays.toString(args));
+    public AjaxResult routeSearch(PeopleSea peopleS, Integer pageNum, Integer pageSize) {
+        String moduleCode = null;
 
-        // 楠岃瘉鍙傛暟鏁伴噺
-        if (args.length != 4) {
-            return buildErrorResponse("鍙傛暟鏁伴噺閿欒锛岄渶瑕�4涓弬鏁帮紝瀹為檯鏀跺埌: " + args.length, null);
+        // 瀹夊叏澶勭悊 String[] 绫诲瀷鐨� modules
+        if (peopleS != null && peopleS.getModules() != null && peopleS.getModules().length != 0) {
+            String[] modulesArray = peopleS.getModules();
+
+            // 杩囨护鎺夌┖瀛楃涓插拰绌虹櫧瀛楃
+            List<String> validModules = Arrays.stream(modulesArray)
+                .filter(StringUtils::isNotBlank)
+                .map(String::trim)
+                .collect(Collectors.toList());
+
+            if (!validModules.isEmpty()) {
+                // 鐢ㄩ�楀彿杩炴帴鏈夋晥鐨勬ā鍧椾唬鐮�
+                moduleCode = String.join(",", validModules);
+            }
         }
+
+        log.info("璺敱鎼滅储: moduleCode={}, peopleS={}, pageNum={}, pageSize={}",
+            moduleCode, peopleS, pageNum, pageSize);
 
         // 瑙f瀽妯″潡浠g爜
         List<String> targetModules = parseModuleCodes(moduleCode);
@@ -108,14 +113,14 @@
         }
 
         // 缁熶竴澶勭悊锛氬崟涓ā鍧椼�佸涓ā鍧楅兘浣跨敤鍚屾牱鐨勫鐞嗛�昏緫
-        return executeModulesSearch(targetModules, args);
+        return executeModulesSearch(targetModules, peopleS, pageNum, pageSize);
     }
 
     /**
      * 缁熶竴鎵ц妯″潡鎼滅储
-     * 鏃犺鏄崟涓ā鍧楄繕鏄涓ā鍧楋紝閮戒娇鐢ㄧ粺涓�鐨勬暟鎹粨鏋勮繑鍥�
      */
-    private AjaxResult executeModulesSearch(List<String> moduleCodes, Object... args) {
+    private AjaxResult executeModulesSearch(List<String> moduleCodes, PeopleSea peopleS,
+                                            Integer pageNum, Integer pageSize) {
         log.info("鎵ц妯″潡鎼滅储: moduleCodes={}, 妯″潡鏁伴噺={}", moduleCodes, moduleCodes.size());
 
         // 楠岃瘉鎵�鏈夋ā鍧楁槸鍚﹀瓨鍦�
@@ -127,80 +132,133 @@
             String availableModules = String.join(", ", moduleSearchMap.keySet());
             String errorMsg = String.format("浠ヤ笅妯″潡涓嶆敮鎸�: %s銆傚彲鐢ㄦā鍧�: [%s]",
                 invalidModules, availableModules);
-            return buildErrorResponse(errorMsg, moduleCodes);
+            return AjaxResult.error(errorMsg);
         }
 
-        // 鎻愬彇鎼滅储鍙傛暟
-        String companion = extractCompanion(args);
-        Date happenStartTime = extractStartTime(args);
-        Date happenEndTime = extractEndTime(args);
-        String hasAttachment = extractHasAttachment(args);
+        // 鎻愬彇鍙傛暟
+        String companion = extractCompanion(peopleS);
+        Date startTime = extractStartTime(peopleS);
+        Date endTime = extractEndTime(peopleS);
+        String hasAttachment = extractHasAttachment(peopleS);
 
-        // 寮傛骞惰鎼滅储
+        // 璁剧疆鍒嗛〉榛樿鍊�
+        if (pageNum == null || pageNum <= 0) {
+            pageNum = 1;
+        }
+        if (pageSize == null || pageSize <= 0) {
+            pageSize = 10;
+        }
+
+        // 骞跺彂鎼滅储
+
         List<CompletableFuture<ModuleSearchResult>> futures = moduleCodes.stream()
             .map(code -> searchModuleAsync(code, moduleSearchMap.get(code),
-                companion, happenStartTime, happenEndTime,hasAttachment))
+                companion, startTime, endTime, hasAttachment))
             .collect(Collectors.toList());
 
-        // 绛夊緟鎵�鏈夋悳绱㈠畬鎴�
+        // 绛夊緟瀹屾垚
         CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
 
-        // 鏀堕泦缁撴灉
-        Map<String, Object> modulesResult = new LinkedHashMap<>();
-        int successCount = 0;
-        int totalCount = 0;
-        List<String> errorModules = new ArrayList<>();
-
-        for (int i = 0; i < futures.size(); i++) {
+        // 鍚堝苟鏁版嵁
+        List<Object> allData = new ArrayList<>();
+        for (CompletableFuture<ModuleSearchResult> future : futures) {
             try {
-                ModuleSearchResult moduleResult = futures.get(i).get();
-                String moduleCode = moduleCodes.get(i);
-
-                if (moduleResult.isSuccess()) {
-                    Map<String, Object> moduleData = new HashMap<>();
-                    moduleData.put("data", moduleResult.getData());
-                    moduleData.put("count", moduleResult.getCount());
-                    moduleData.put("searchTime", moduleResult.getSearchTime());
-                    moduleData.put("success", true);
-
-                    modulesResult.put(moduleCode, moduleData);
-
-                    successCount++;
-                    totalCount += moduleResult.getCount();
-                } else {
-                    Map<String, Object> errorInfo = new HashMap<>();
-                    errorInfo.put("error", moduleResult.getErrorMessage());
-                    errorInfo.put("success", false);
-                    errorInfo.put("moduleName", getModuleName(moduleCode));
-                    modulesResult.put(moduleCode, errorInfo);
-                    errorModules.add(moduleCode);
+                ModuleSearchResult result = future.get();
+                if (result.isSuccess() && result.getData() != null) {
+                    allData.addAll(result.getData());
                 }
             } catch (Exception e) {
-                log.error("鑾峰彇妯″潡[{}]鎼滅储缁撴灉澶辫触", moduleCodes.get(i), e);
-                String moduleCode = moduleCodes.get(i);
-                Map<String, Object> errorInfo = new HashMap<>();
-                errorInfo.put("error", "鑾峰彇缁撴灉寮傚父: " + e.getMessage());
-                errorInfo.put("success", false);
-                errorInfo.put("moduleName", getModuleName(moduleCode));
-                modulesResult.put(moduleCode, errorInfo);
-                errorModules.add(moduleCode);
+                // 璁板綍閿欒浣嗙户缁鐞嗗叾浠栨ā鍧�
+                log.error("鑾峰彇妯″潡鎼滅储缁撴灉澶辫触", e);
             }
         }
 
-        // 鏋勫缓鏈�缁堣繑鍥炵粨鏋�
-        Map<String, Object> finalResult = new LinkedHashMap<>();
-        finalResult.put("modules", modulesResult);
-        finalResult.put("totalSelectedModules", moduleCodes.size());
-        finalResult.put("successModules", successCount);
-        finalResult.put("errorModules", errorModules);
-        finalResult.put("totalRecords", totalCount);
-        finalResult.put("searchTime", new Date());
+        // 瀵规暟鎹繘琛屾帓搴忥紙濡傛灉闇�瑕侊級
+        sortData(allData);
 
-        // 鏋勫缓娑堟伅
-        String message = buildSuccessMessage(moduleCodes.size(), successCount, errorModules, totalCount);
-        finalResult.put("message", message);
+        // 鍒嗛〉
+        int startIndex = (pageNum - 1) * pageSize;
+        List<Object> paginatedData = allData.stream()
+            .skip(startIndex)
+            .limit(pageSize)
+            .collect(Collectors.toList());
 
-        return AjaxResult.success(message, finalResult);
+        // 杩斿洖缁撴灉
+        Map<String, Object> data = new HashMap<>();
+        data.put("list", paginatedData);
+        data.put("total", allData.size());
+        data.put("pageNum", pageNum);
+        data.put("pageSize", pageSize);
+
+        return AjaxResult.success(data);
+    }
+
+    /**
+     * 瀵规暟鎹繘琛屾帓搴�
+     * 榛樿鎸夊垱寤烘椂闂撮檷搴忔帓鍒�
+     */
+    private void sortData(List<Object> allData) {
+        if (CollectionUtils.isEmpty(allData)) {
+            return;
+        }
+
+        // 濡傛灉鏁版嵁鏄� Map 绫诲瀷锛屽皾璇曟寜 createTime 鎺掑簭
+        if (allData.get(0) instanceof Map) {
+            allData.sort((a, b) -> {
+                Map<String, Object> mapA = (Map<String, Object>) a;
+                Map<String, Object> mapB = (Map<String, Object>) b;
+
+                Object timeA = mapA.get("createTime");
+                Object timeB = mapB.get("createTime");
+
+                if (timeA instanceof Date && timeB instanceof Date) {
+                    // 闄嶅簭鎺掑垪锛氭渶鏂扮殑鍦ㄥ墠
+                    return ((Date) timeB).compareTo((Date) timeA);
+                } else if (timeA instanceof String && timeB instanceof String) {
+                    // 濡傛灉鏃堕棿鏄瓧绗︿覆锛屽皾璇曡В鏋�
+                    try {
+                        Date dateA = parseDate((String) timeA);
+                        Date dateB = parseDate((String) timeB);
+                        if (dateA != null && dateB != null) {
+                            return dateB.compareTo(dateA);
+                        }
+                    } catch (Exception e) {
+                        // 瑙f瀽澶辫触锛屼笉鎺掑簭
+                    }
+                }
+                return 0;
+            });
+        }
+    }
+
+    /**
+     * 瑙f瀽鏃ユ湡瀛楃涓�
+     */
+    private Date parseDate(String dateStr) {
+        if (dateStr == null || dateStr.isEmpty()) {
+            return null;
+        }
+
+        try {
+            // 灏濊瘯甯歌鐨勬棩鏈熸牸寮�
+            String[] formats = {
+                "yyyy-MM-dd'T'HH:mm:ss.SSSXXX",
+                "yyyy-MM-dd HH:mm:ss",
+                "yyyy-MM-dd"
+            };
+
+            for (String format : formats) {
+                try {
+                    return new java.text.SimpleDateFormat(format).parse(dateStr);
+                } catch (Exception e) {
+                    // 缁х画灏濊瘯涓嬩竴涓牸寮�
+                }
+            }
+        } catch (Exception e) {
+            log.warn("鏃犳硶瑙f瀽鏃ユ湡瀛楃涓�: {}", dateStr, e);
+        }
+
+        return null;
     }
 
     /**
@@ -212,52 +270,38 @@
     }
 
     /**
-     * 鏋勫缓鎴愬姛娑堟伅
+     * 瀹夊叏鐨勫弬鏁版彁鍙栨柟娉�
      */
-    private String buildSuccessMessage(int totalSelected, int successCount,
-                                       List<String> errorModules, int totalRecords) {
-        if (errorModules.isEmpty()) {
-            if (totalSelected == 1) {
-                return String.format("鎼滅储鎴愬姛: 鎵惧埌%s鏉¤褰�", totalRecords);
-            } else {
-                return String.format("鎼滅储瀹屾垚: 鎴愬姛%s/%s涓ā鍧楋紝鎬昏%s鏉¤褰�",
-                    successCount, totalSelected, totalRecords);
-            }
-        } else {
-            return String.format("鎼滅储瀹屾垚: 鎴愬姛%s/%s涓ā鍧楋紝鎬昏%s鏉¤褰曪紝澶辫触妯″潡: %s",
-                successCount, totalSelected, totalRecords, errorModules);
+    private String extractCompanion(PeopleSea peopleS) {
+        if (peopleS == null) {
+            return "";
         }
+        return peopleS.getPeoples() == null ? "" : peopleS.getPeoples().trim();
     }
 
-    /**
-     * 鏋勫缓閿欒鍝嶅簲
-     */
-    private AjaxResult buildErrorResponse(String errorMessage, List<String> moduleCodes) {
-        Map<String, Object> errorData = new HashMap<>();
-        errorData.put("message", errorMessage);
-        errorData.put("success", false);
-
-        if (moduleCodes != null) {
-            errorData.put("selectedModules", moduleCodes);
+    private Date extractStartTime(PeopleSea peopleS) {
+        if (peopleS == null) {
+            return null;
         }
+        return peopleS.getStartTime();
+    }
 
-        errorData.put("totalSelectedModules", moduleCodes != null ? moduleCodes.size() : 0);
-        errorData.put("successModules", 0);
-        errorData.put("errorModules", moduleCodes != null ? moduleCodes : Collections.emptyList());
-        errorData.put("totalRecords", 0);
-        errorData.put("searchTime", new Date());
+    private Date extractEndTime(PeopleSea peopleS) {
+        if (peopleS == null) {
+            return null;
+        }
+        return peopleS.getEndTime();
+    }
 
-        return AjaxResult.error(errorMessage, errorData);
+    private String extractHasAttachment(PeopleSea peopleS) {
+        if (peopleS == null) {
+            return "";
+        }
+        return peopleS.getHasAttachment() == null ? "" : peopleS.getHasAttachment().trim();
     }
 
     /**
      * 瑙f瀽妯″潡浠g爜
-     * 鏀寔澶氱鏍煎紡锛�
-     * 1. 绌�/绌虹櫧/null -> 鍏ㄦā鍧楁悳绱�
-     * 2. "all" -> 鍏ㄦā鍧楁悳绱�
-     * 3. 鍗曚釜妯″潡 -> 杩斿洖鍗曚釜妯″潡
-     * 4. 閫楀彿鍒嗛殧鐨勫涓ā鍧� -> 杩斿洖妯″潡鍒楄〃
-     * 5. 鍏朵粬鐗规畩鏍囪瘑锛堝"none"锛�-> 杩斿洖绌哄垪琛ㄨ〃绀轰笉閫夋ā鍧�
      */
     private List<String> parseModuleCodes(String moduleCode) {
         if (StringUtils.isBlank(moduleCode)) {
@@ -272,7 +316,7 @@
             return new ArrayList<>(moduleSearchMap.keySet());
         }
 
-        // 澶勭悊涓嶉�夋ā鍧楃殑鎯呭喌锛堝彲閫夋墿灞曪級
+        // 澶勭悊涓嶉�夋ā鍧楃殑鎯呭喌
         if ("none".equalsIgnoreCase(trimmedCode) || "null".equalsIgnoreCase(trimmedCode)) {
             return Collections.emptyList();
         }
@@ -291,18 +335,14 @@
     }
 
     /**
-     * 涓嶉�夋ā鍧楃殑澶勭悊閫昏緫 - 浣跨敤缁熶竴鏁版嵁缁撴瀯
+     * 涓嶉�夋ā鍧楃殑澶勭悊閫昏緫
      */
     private AjaxResult handleNoModuleSelected() {
         Map<String, Object> result = new LinkedHashMap<>();
-        result.put("modules", Collections.emptyMap());
-        result.put("totalSelectedModules", 0);
-        result.put("successModules", 0);
-        result.put("errorModules", Collections.emptyList());
-        result.put("totalRecords", 0);
-        result.put("searchTime", new Date());
-        result.put("message", "鏈�夋嫨鎼滅储妯″潡");
-        result.put("availableModules", new ArrayList<>(moduleSearchMap.keySet()));
+        result.put("list", Collections.emptyList());
+        result.put("total", 0);
+        result.put("pageNum", 1);
+        result.put("pageSize", 10);
 
         return AjaxResult.success("鏈�夋嫨鎼滅储妯″潡锛岃閫夋嫨瑕佹悳绱㈢殑妯″潡", result);
     }
@@ -354,29 +394,4 @@
         return moduleSearchMap.containsKey(trimmedCode) ||
             ALL_MODULES_FLAG.equalsIgnoreCase(trimmedCode);
     }
-
-    /**
-     * 鍙傛暟鎻愬彇杈呭姪鏂规硶
-     */
-    private String extractCompanion(Object[] args) {
-        if (args.length > 0 && args[0] instanceof String) {
-            return (String) args[0];
-        } else if (args.length > 0 && args[0] != null) {
-            return args[0].toString();
-        }
-        return null;
-    }
-
-    private Date extractStartTime(Object[] args) {
-        return (args.length > 1 && args[1] instanceof Date) ? (Date) args[1] : null;
-    }
-
-    private Date extractEndTime(Object[] args) {
-        return (args.length > 2 && args[2] instanceof Date) ? (Date) args[2] : null;
-    }
-
-    private String extractHasAttachment(Object[] args) {
-        return (args.length > 3 && args[3] instanceof String) ? (String) args[3] : null;
-
-}
 }

--
Gitblit v1.9.1