From 5418ea7855d16dcc0169d5ed554f7a23c4b55532 Mon Sep 17 00:00:00 2001
From: zqy <2522236926@qq.com>
Date: 星期二, 02 十二月 2025 10:37:12 +0800
Subject: [PATCH] Merge branch 'master' of http://47.93.189.255:8099/r/zhangshi_app_backend

---
 zhang-content/src/main/java/com/ruoyi/service/impl/InterfaceBasedSearchRouter.java |  137 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 137 insertions(+), 0 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
new file mode 100644
index 0000000..b4ffc53
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/InterfaceBasedSearchRouter.java
@@ -0,0 +1,137 @@
+package com.ruoyi.service.impl;
+
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.SysMenu;
+import com.ruoyi.service.ModuleSearchable;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.logging.Log;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class InterfaceBasedSearchRouter {
+
+    private final Map<String, ModuleSearchable> moduleSearchMap;
+
+    /**
+     * 鑷姩鏀堕泦鎵�鏈夊疄鐜癕oduleSearchable鎺ュ彛鐨凚ean
+     */
+    @Autowired
+    public InterfaceBasedSearchRouter(List<ModuleSearchable> searchServices) {
+        this.moduleSearchMap = searchServices.stream()
+            .collect(Collectors.toMap(
+                ModuleSearchable::getModuleCode,
+                Function.identity(),
+                (existing, replacement) -> {
+                    log.warn("鍙戠幇閲嶅鐨勬ā鍧楃紪鐮�: {}, 浣跨敤鍏堟敞鍐岀殑鏈嶅姟", existing.getModuleCode());
+                    return existing;
+                }
+            ));
+
+        log.info("宸叉敞鍐屾悳绱㈡ā鍧�: {}", moduleSearchMap.keySet());
+    }
+
+    /**
+     * 閫氱敤鐨勮矾鐢辨悳绱㈣姹傦紙鏀寔涓嶅悓鍙傛暟绫诲瀷锛�
+     */
+    /**
+     * 閫氱敤鐨勮矾鐢辨悳绱㈣姹�
+     */
+    public AjaxResult routeSearch(String moduleCode, Object... args) {
+        log.info("璺敱鎼滅储: moduleCode={}, args={}", moduleCode, Arrays.toString(args));
+
+        ModuleSearchable searchService = moduleSearchMap.get(moduleCode);
+        if (searchService == null) {
+            String availableModules = String.join(", ", moduleSearchMap.keySet());
+            return AjaxResult.error("涓嶆敮鎸佺殑鎼滅储妯″潡: " + moduleCode + "銆傚彲鐢ㄦā鍧�: [" + availableModules + "]");
+        }
+
+        try {
+            // 鏍规嵁鍙傛暟鏁伴噺杩涜璺敱
+            if (args.length == 3) {
+                return handleFourArgs(searchService, args);
+            } else {
+                return AjaxResult.error("涓嶆敮鎸佺殑鍙傛暟鏁伴噺锛岄渶瑕�3涓弬鏁帮紝瀹為檯鏀跺埌: " + args.length);
+            }
+        } catch (Exception e) {
+            log.error("鎼滅储鎵ц澶辫触: moduleCode={}", moduleCode, e);
+            return AjaxResult.error("鎼滅储鎵ц澶辫触: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 澶勭悊3涓弬鏁扮殑鎯呭喌锛坈ompanion + happenStartTime + happenEndTime锛�
+     */
+    private AjaxResult handleFourArgs(ModuleSearchable searchService, Object[] args) {
+        String companion = null;
+        Date happenStartTime = null;
+        Date happenEndTime = null;
+
+        // 澶勭悊companion鍙傛暟
+        if (args[0] instanceof String) {
+            companion = (String) args[0];
+        } else if (args[0] != null) {
+            companion = args[0].toString();
+        }
+
+        // 澶勭悊鏃堕棿鍙傛暟
+        if (args[1] instanceof Date) {
+            happenStartTime = (Date) args[1];
+        }
+
+        if (args[2] instanceof Date) {
+            happenEndTime = (Date) args[2];
+        }
+
+        // 鍒ゆ柇鎼滅储绫诲瀷
+        boolean hasTimeRange = happenStartTime != null && happenEndTime != null;
+
+        List<?> result;
+        if (hasTimeRange) {
+            // 鏈夋椂闂磋寖鍥达細鎵ц鏃堕棿鑼冨洿鎼滅储
+            log.info("鎵ц鏃堕棿鑼冨洿鎼滅储: companion={}, startTime={}, endTime={}",
+                companion, happenStartTime, happenEndTime);
+            result = searchService.search(companion, happenStartTime, happenEndTime);
+        } else {
+            // 鏃犳椂闂磋寖鍥达細鍙寜companion鎼滅储
+            log.info("鎵цcompanion鎼滅储: companion={}, 鏃堕棿鑼冨洿涓虹┖", companion);
+            result = searchService.search(companion, null, null);
+        }
+
+        return AjaxResult.success("鎼滅储鎴愬姛", result);
+    }
+//
+//    /**
+//     * 鑾峰彇鎵�鏈夊彲鎼滅储鐨勬ā鍧椾俊鎭�
+//     */
+//    public List<SysMenu> getAvailableModules() {
+//        return moduleSearchMap.values().stream()
+//            .map(service -> SysMenu.builder()
+//                .moduleCode(service.getModuleCode())
+//                .moduleName(service.getModuleName())
+//                .build())
+//            .collect(Collectors.toList());
+//    }
+
+    /**
+     * 妫�鏌ユā鍧楁槸鍚︽敮鎸佹悳绱�
+     */
+    public boolean supports(String moduleCode) {
+        return moduleSearchMap.containsKey(moduleCode);
+    }
+
+    /**
+     * 鑾峰彇妯″潡鏈嶅姟瀹炰緥
+     */
+    public ModuleSearchable getModuleService(String moduleCode) {
+        return moduleSearchMap.get(moduleCode);
+    }
+}

--
Gitblit v1.9.1