From 28cf0afe5cb951bf34a60a1ee0f36d38c592a8c0 Mon Sep 17 00:00:00 2001
From: zqy <2522236926@qq.com>
Date: 星期二, 09 十二月 2025 11:10:29 +0800
Subject: [PATCH] 新增搜索 不选模块进行全局搜索 获取每个模块
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/EsSearchController.java | 20 +++
zhang-content/src/main/java/com/ruoyi/service/impl/ZfEconomyServiceImpl.java | 1
ruoyi-framework/pom.xml | 2
zhang-content/src/main/java/com/ruoyi/domain/ModuleSearchResult.java | 39 +++++++
zhang-content/src/main/java/com/ruoyi/service/impl/InterfaceBasedSearchRouter.java | 151 +++++++++++++++++++++++++++---
ruoyi-common/src/main/java/com/ruoyi/common/config/AsyncConfig.java | 23 ++++
zhang-content/src/main/java/com/ruoyi/domain/ZfDoctor.java | 20 +++
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java | 22 ++++
8 files changed, 256 insertions(+), 22 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/EsSearchController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/EsSearchController.java
index 3198f1a..31efa74 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/EsSearchController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/EsSearchController.java
@@ -6,6 +6,8 @@
import com.ruoyi.service.ZfEconomyService;
import com.ruoyi.service.impl.InterfaceBasedSearchRouter;
import com.ruoyi.service.impl.ZfEconomyServiceImpl;
+import com.ruoyi.system.service.ISysMenuService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
@@ -63,9 +65,25 @@
System.out.println("[[[[[["+happenStartTime);
System.out.println("[[[[[["+happenEndTime);
-
+ zfEconomyService.clearAllCache();
return interfaceBasedSearchRouter.routeSearch(moduleCode,companion,happenStartTime,happenEndTime);
}
+ /**
+ * 鏂板鍏ㄦā鍧楁悳绱㈡帴鍙o紙涓嶆寚瀹歮oduleCode锛�
+ */
+ @GetMapping("/companion")
+ public AjaxResult getAllModulesByCompanion(@RequestParam(value = "companion", required = false) String companion,
+ @RequestParam(value = "happenStartTime", required = false)
+ @DateTimeFormat(pattern = "yyyy-MM-dd") Date happenStartTime,
+ @RequestParam(value = "happenEndTime", required = false)
+ @DateTimeFormat(pattern = "yyyy-MM-dd") Date happenEndTime) {
+ System.out.println("鍏ㄦā鍧楁悳绱� - 鍚屼即: " + companion);
+ System.out.println("鍏ㄦā鍧楁悳绱� - 寮�濮嬫椂闂�: " + happenStartTime);
+ System.out.println("鍏ㄦā鍧楁悳绱� - 缁撴潫鏃堕棿: " + happenEndTime);
+ zfEconomyService.clearAllCache();
+ // 浣跨敤null鎴栫┖瀛楃涓茶〃绀哄叏妯″潡鎼滅储
+ return interfaceBasedSearchRouter.routeSearch(null, companion, happenStartTime, happenEndTime);
+ }
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/AsyncConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/AsyncConfig.java
new file mode 100644
index 0000000..b78ec8a
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/AsyncConfig.java
@@ -0,0 +1,23 @@
+package com.ruoyi.common.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.AsyncConfigurer;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
+import org.springframework.core.task.SimpleAsyncTaskExecutor;
+
+import java.util.concurrent.Executor;
+
+@Configuration
+@EnableAsync // 鍚敤寮傛鏀寔
+public class AsyncConfig implements AsyncConfigurer {
+
+ @Override
+ public Executor getAsyncExecutor() {
+ // 1. 鍒涘缓涓�涓熀纭�鐨勫紓姝ヤ换鍔℃墽琛屽櫒
+ SimpleAsyncTaskExecutor delegate = new SimpleAsyncTaskExecutor();
+ // 2. 浣跨敤DelegatingSecurityContextAsyncTaskExecutor杩涜鍖呰
+ // 瀹冧細鑷姩灏嗕富绾跨▼鐨勫畨鍏ㄤ笂涓嬫枃缁戝畾鍒板紓姝ヤ换鍔$殑绾跨▼涓�
+ return new DelegatingSecurityContextAsyncTaskExecutor(delegate);
+ }
+}
diff --git a/ruoyi-framework/pom.xml b/ruoyi-framework/pom.xml
index fae4bce..ea1319b 100644
--- a/ruoyi-framework/pom.xml
+++ b/ruoyi-framework/pom.xml
@@ -76,4 +76,4 @@
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
diff --git a/zhang-content/src/main/java/com/ruoyi/domain/ModuleSearchResult.java b/zhang-content/src/main/java/com/ruoyi/domain/ModuleSearchResult.java
new file mode 100644
index 0000000..8acad81
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/domain/ModuleSearchResult.java
@@ -0,0 +1,39 @@
+package com.ruoyi.domain;
+
+import java.util.List;
+
+public class ModuleSearchResult {
+ private final String moduleCode;
+ private final List<?> data;
+ private final int count;
+ private final long searchTime;
+ private final boolean success;
+ private final String errorMessage;
+
+ private ModuleSearchResult(String moduleCode, String moduleName, List<?> data,
+ int count, long searchTime, boolean success, String errorMessage) {
+ this.moduleCode = moduleCode;
+ this.data = data;
+ this.count = count;
+ this.searchTime = searchTime;
+ this.success = success;
+ this.errorMessage = errorMessage;
+ }
+
+ public static ModuleSearchResult success(String moduleCode, String moduleName,
+ List<?> data, int count, long searchTime) {
+ return new ModuleSearchResult(moduleCode, moduleName, data, count, searchTime, true, null);
+ }
+
+ public static ModuleSearchResult error(String moduleCode, String errorMessage) {
+ return new ModuleSearchResult(moduleCode, null, null, 0, 0, false, errorMessage);
+ }
+
+ // getters...
+ public String getModuleCode() { return moduleCode; }
+ public List<?> getData() { return data; }
+ public int getCount() { return count; }
+ public long getSearchTime() { return searchTime; }
+ public boolean isSuccess() { return success; }
+ public String getErrorMessage() { return errorMessage; }
+}
diff --git a/zhang-content/src/main/java/com/ruoyi/domain/ZfDoctor.java b/zhang-content/src/main/java/com/ruoyi/domain/ZfDoctor.java
index 943de3e..76a3bc6 100644
--- a/zhang-content/src/main/java/com/ruoyi/domain/ZfDoctor.java
+++ b/zhang-content/src/main/java/com/ruoyi/domain/ZfDoctor.java
@@ -14,7 +14,7 @@
/**
* <p>
- *
+ *
* </p>
*
* @author ojq
@@ -97,4 +97,22 @@
private Integer ownData;
private Long shareId;
+
+ /**
+ * 鍙備笌鑰�
+ */
+ private String companion;
+
+
+ /**
+ * 寮�濮嬫椂闂�
+ */
+ @TableField(exist = false)
+ private Date happenStartTime;
+
+ /**
+ * 缁撴潫鏃堕棿
+ */
+ @TableField(exist = false)
+ private Date happenEndTime;
}
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 b4ffc53..91509a9 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
@@ -2,16 +2,19 @@
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysMenu;
+import com.ruoyi.domain.ModuleSearchResult;
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.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+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;
@@ -20,6 +23,7 @@
public class InterfaceBasedSearchRouter {
private final Map<String, ModuleSearchable> moduleSearchMap;
+
/**
* 鑷姩鏀堕泦鎵�鏈夊疄鐜癕oduleSearchable鎺ュ彛鐨凚ean
@@ -39,6 +43,21 @@
log.info("宸叉敞鍐屾悳绱㈡ā鍧�: {}", moduleSearchMap.keySet());
}
+ @Async // 澹版槑姝ゆ柟娉曞紓姝ユ墽琛岋紝灏嗕娇鐢ㄦ垜浠笂闈㈤厤缃殑Executor
+ public CompletableFuture<ModuleSearchResult> searchModuleAsync(String moduleCode, ModuleSearchable service, String companion, Date startTime, Date endTime) {
+ // 灏嗗師鏉ュ湪lambda琛ㄨ揪寮忎腑鐨勬悳绱㈤�昏緫绉诲埌杩欓噷
+ long start = System.currentTimeMillis();
+ try {
+ List<?> data = service.search(companion, startTime, endTime);
+ long searchTime = System.currentTimeMillis() - start;
+ ModuleSearchResult result = ModuleSearchResult.success(moduleCode, service.getModuleName(), data, data.size(), searchTime);
+ return CompletableFuture.completedFuture(result);
+ } catch (Exception e) {
+ log.error("妯″潡[{}]鎼滅储澶辫触: {}", moduleCode, e.getMessage());
+ ModuleSearchResult result = ModuleSearchResult.error(moduleCode, e.getMessage());
+ return CompletableFuture.completedFuture(result);
+ }
+ }
/**
* 閫氱敤鐨勮矾鐢辨悳绱㈣姹傦紙鏀寔涓嶅悓鍙傛暟绫诲瀷锛�
*/
@@ -48,6 +67,12 @@
public AjaxResult routeSearch(String moduleCode, Object... args) {
log.info("璺敱鎼滅储: moduleCode={}, args={}", moduleCode, Arrays.toString(args));
+ // 鍏ㄦā鍧楁悳绱細褰搈oduleCode涓虹┖鎴栫壒瀹氭爣璇嗘椂
+ if (moduleCode == null || moduleCode.isEmpty() || "all".equalsIgnoreCase(moduleCode)) {
+ return searchAllModules(args);
+ }
+
+ // 鍗曚釜妯″潡鎼滅储锛堝師鏈夐�昏緫锛�
ModuleSearchable searchService = moduleSearchMap.get(moduleCode);
if (searchService == null) {
String availableModules = String.join(", ", moduleSearchMap.keySet());
@@ -55,7 +80,6 @@
}
try {
- // 鏍规嵁鍙傛暟鏁伴噺杩涜璺敱
if (args.length == 3) {
return handleFourArgs(searchService, args);
} else {
@@ -67,9 +91,6 @@
}
}
- /**
- * 澶勭悊3涓弬鏁扮殑鎯呭喌锛坈ompanion + happenStartTime + happenEndTime锛�
- */
private AjaxResult handleFourArgs(ModuleSearchable searchService, Object[] args) {
String companion = null;
Date happenStartTime = null;
@@ -108,6 +129,98 @@
return AjaxResult.success("鎼滅储鎴愬姛", result);
}
+
+ /**
+ * 鍏ㄦā鍧楁悳绱細鑾峰彇鎵�鏈夋ā鍧楃殑鏁版嵁骞跺垎绫�
+ */
+ private AjaxResult searchAllModules(Object[] args) {
+ log.info("鎵ц鍏ㄦā鍧楁悳绱紝鍙傛暟鏁伴噺: {}", args.length);
+
+ try {
+ Map<String, Object> result = new LinkedHashMap<>();
+ int totalCount = 0;
+ int successCount = 0;
+
+ // 澶勭悊鎼滅储鍙傛暟
+ String companion = extractCompanion(args);
+ Date happenStartTime = extractStartTime(args);
+ Date happenEndTime = extractEndTime(args);
+
+ System.out.println("鍏ㄦā鍧楁悳绱� ------ 鍚屼即: " + companion);
+ System.out.println("鍏ㄦā鍧楁悳绱� ------ 寮�濮嬫椂闂�: " + happenStartTime);
+ System.out.println("鍏ㄦā鍧楁悳绱� ------ 缁撴潫鏃堕棿: " + happenEndTime);
+
+ // 骞惰澶勭悊鎵�鏈夋ā鍧楁悳绱紙鎻愰珮鎬ц兘锛�
+ List<CompletableFuture<ModuleSearchResult>> futures = moduleSearchMap.entrySet().stream().map(entry ->
+ searchModuleAsync(entry.getKey(),
+ entry.getValue(), companion,
+ happenStartTime, happenEndTime))
+ .collect(Collectors.toList());
+
+
+ // 绛夊緟鎵�鏈夋悳绱㈠畬鎴�
+ CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
+
+ // 鏀堕泦缁撴灉
+ for (CompletableFuture<ModuleSearchResult> future : futures) {
+ ModuleSearchResult moduleResult = future.get();
+ if (moduleResult.isSuccess()) {
+ // 鍒涘缓涓�涓彲鍙樼殑HashMap骞跺~鍏ユ暟鎹�
+ Map<String, Object> resultMap = new HashMap<>();
+ resultMap.put("data", moduleResult.getData());
+ resultMap.put("count", moduleResult.getCount());
+ resultMap.put("searchTime", moduleResult.getSearchTime());
+
+ // 灏嗘瀯寤哄ソ鐨凪ap鏀惧叆鏈�缁堢粨鏋滀腑
+ result.put(moduleResult.getModuleCode(), resultMap);
+
+ successCount++;
+ totalCount += moduleResult.getCount();
+ } else {
+ Map<String, Object> errorInfo = new HashMap<>();
+ errorInfo.put("error", moduleResult.getErrorMessage());
+ errorInfo.put("success", false);
+ result.put(moduleResult.getModuleCode(), errorInfo);
+ }
+ }
+
+ // 鏋勫缓杩斿洖缁撴灉
+ Map<String, Object> finalResult = new LinkedHashMap<>();
+ finalResult.put("totalModules", moduleSearchMap.size());
+ finalResult.put("successModules", successCount);
+ finalResult.put("totalRecords", totalCount);
+ finalResult.put("searchTime", new Date());
+ finalResult.put("modules", result);
+
+ log.info("鍏ㄦā鍧楁悳绱㈠畬鎴�: 鎴愬姛{}/{}涓ā鍧楋紝鎬昏{}鏉¤褰�",
+ successCount, moduleSearchMap.size(), totalCount);
+
+ return AjaxResult.success("鍏ㄦā鍧楁悳绱㈡垚鍔�", finalResult);
+
+ } catch (Exception e) {
+ log.error("鍏ㄦā鍧楁悳绱㈡墽琛屽け璐�", e);
+ return AjaxResult.error("鍏ㄦā鍧楁悳绱㈠け璐�: " + e.getMessage());
+ }
+ }
+
+ /**
+ * 鍗曚釜妯″潡鎼滅储鍖呰鏂规硶
+ */
+ private ModuleSearchResult searchSingleModule(String moduleCode, ModuleSearchable service,
+ String companion, Date startTime, Date endTime) {
+ long start = System.currentTimeMillis();
+ try {
+ List<?> data = service.search(companion, startTime, endTime);
+ long searchTime = System.currentTimeMillis() - start;
+
+ return ModuleSearchResult.success(moduleCode, service.getModuleName(),
+ data, data.size(), searchTime);
+
+ } catch (Exception e) {
+ log.error("妯″潡[{}]鎼滅储澶辫触: {}", moduleCode, e.getMessage());
+ return ModuleSearchResult.error(moduleCode, e.getMessage());
+ }
+ }
//
// /**
// * 鑾峰彇鎵�鏈夊彲鎼滅储鐨勬ā鍧椾俊鎭�
@@ -122,16 +235,22 @@
// }
/**
- * 妫�鏌ユā鍧楁槸鍚︽敮鎸佹悳绱�
+ * 鍙傛暟鎻愬彇杈呭姪鏂规硶
*/
- public boolean supports(String moduleCode) {
- return moduleSearchMap.containsKey(moduleCode);
+ 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;
}
- /**
- * 鑾峰彇妯″潡鏈嶅姟瀹炰緥
- */
- public ModuleSearchable getModuleService(String moduleCode) {
- return moduleSearchMap.get(moduleCode);
+ 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;
}
}
diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java
index 1840a69..d61d9f4 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java
@@ -39,7 +39,7 @@
*/
@Service
@Slf4j
-public class ZfDoctorServiceImpl extends ServiceImpl<ZfDoctorMapper, ZfDoctor> implements ZfDoctorService {
+public class ZfDoctorServiceImpl extends ServiceImpl<ZfDoctorMapper, ZfDoctor> implements ZfDoctorService,ModuleSearchable {
@Resource
ZInfoUserService zInfoUserService;
@@ -465,6 +465,9 @@
.like(StringUtils.isNotEmpty(zfDoctor.getWmedical()), ZfDoctor::getWmedical, zfDoctor.getWmedical())
.like(StringUtils.isNotEmpty(zfDoctor.getCmedical()), ZfDoctor::getCmedical, zfDoctor.getCmedical())
.like(StringUtils.isNotEmpty(zfDoctor.getRemark()), ZfDoctor::getRemark, zfDoctor.getRemark());
+ lqw.like(StringUtils.isNotEmpty(zfDoctor.getCompanion()),ZfDoctor::getCompanion,zfDoctor.getCompanion());
+ lqw.between(zfDoctor.getHappenStartTime() != null && zfDoctor.getHappenEndTime() != null, ZfDoctor::getCreateTime, zfDoctor.getHappenStartTime(), zfDoctor.getHappenEndTime());
+
if (StringUtils.isNotEmpty(zfDoctor.getPrescription())) {
lqw.and(wrapper -> {
wrapper.like(StringUtils.isNotEmpty(zfDoctor.getPrescription()), ZfDoctor::getWmedical, zfDoctor.getPrescription())
@@ -473,6 +476,21 @@
});
}
return lqw;
+ }
+
+ @Override
+ public String getModuleCode() {
+ return "2043";
+ }
+
+ @Override
+ public List<?> search(String companion, Date happenStartTime, Date happenEndTime) {
+
+ ZfDoctor zfDoctor = new ZfDoctor();
+ zfDoctor.setCompanion(companion);
+ zfDoctor.setHappenStartTime(happenStartTime);
+ zfDoctor.setHappenEndTime(happenEndTime);
+ return selectByCondition(zfDoctor);
}
// public LambdaQueryWrapper<ZfDoctor> buildCondition2(List<Long> ids) {
@@ -516,4 +534,4 @@
// }
-}
\ No newline at end of file
+}
diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEconomyServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEconomyServiceImpl.java
index 4ed3f1c..2e7b906 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEconomyServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEconomyServiceImpl.java
@@ -627,7 +627,6 @@
zfEconomy.setCompanion(companion);
zfEconomy.setHappenStartTime(happenStartTime);
zfEconomy.setHappenEndTime(happenEndTime);
- System.out.println("ssssss"+zfEconomy);
return selectByCondition(zfEconomy);
}
--
Gitblit v1.9.1