From 0a3129cb06fcea6677245097715dcc6fa3de65e5 Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期四, 29 十月 2026 14:52:38 +0800
Subject: [PATCH] feat(LIMS): 数据采集清洗验证 + 实时监控预警闭环
---
src/main/java/com/ruoyi/lims/controller/DataInterfaceController.java | 82 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 81 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/ruoyi/lims/controller/DataInterfaceController.java b/src/main/java/com/ruoyi/lims/controller/DataInterfaceController.java
index 025cb71..07fb2c1 100644
--- a/src/main/java/com/ruoyi/lims/controller/DataInterfaceController.java
+++ b/src/main/java/com/ruoyi/lims/controller/DataInterfaceController.java
@@ -16,6 +16,7 @@
import com.ruoyi.lims.service.DataInterfaceService;
import com.ruoyi.lims.service.InterfaceFieldService;
import com.ruoyi.lims.service.InterfaceLogService;
+import com.ruoyi.lims.service.LimsCleanService;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
@@ -48,6 +49,7 @@
private InterfaceFieldService fieldService;
private InterfaceLogService logService;
private DataCollectionService collectionService;
+ private LimsCleanService cleanService;
private static final ObjectMapper JSON = new ObjectMapper();
@@ -222,6 +224,7 @@
List<InterfaceField> fields = fieldService.list(fw);
int saved = 0;
+ Map<String, Object> ret_clean = null;
List<String> warnings = new ArrayList<>();
try {
if (fields.isEmpty()) {
@@ -292,12 +295,30 @@
return AjaxResult.error("鏄犲皠鍐欏叆澶辫触锛�" + shortMsg(e));
}
+ // 閲囬泦鎴愬姛鍚庤嚜鍔ㄦ竻娲楋紙鍙敤 autoClean=false 鍏抽棴锛�
+ if (saved > 0) {
+ try {
+ java.util.List<Long> newIds = new java.util.ArrayList<>();
+ com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<DataCollection> nw =
+ new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<>();
+ nw.eq("clean_status", "pending").orderByDesc("id").last("limit " + saved);
+ for (DataCollection x : collectionService.list(nw)) {
+ newIds.add(x.getId());
+ }
+ if (!newIds.isEmpty()) {
+ Map<String, Object> cr = cleanService.cleanBatch(newIds);
+ ret_clean = cr;
+ }
+ } catch (Exception ignore) {
+ }
+ }
saveLog(di, "manual", requestDesc, rawJson, true, null, System.currentTimeMillis() - start, saved);
Map<String, Object> ret = new LinkedHashMap<>();
ret.put("saved", saved);
ret.put("rawLength", rawJson == null ? 0 : rawJson.length());
ret.put("warnings", warnings);
+ if (ret_clean != null) { ret.put("clean", ret_clean); }
return AjaxResult.success("閲囬泦瀹屾垚锛屽啓鍏� " + saved + " 鏉�", ret);
}
@@ -363,6 +384,26 @@
return AjaxResult.success(logService.page(page, w));
}
+ /**
+ * 渚涘畾鏃朵换鍔¤皟鐢ㄧ殑閲囬泦鍏ュ彛锛堜笉缁� HTTP锛夛紝杩斿洖鎴愬姛鍐欏叆鏉℃暟
+ */
+ public Map<String, Object> collectInternal(Long id, String invokeType) {
+ Map<String, Object> r = new LinkedHashMap<>();
+ AjaxResult ar = collect(id);
+ Object code = ar.get("code");
+ boolean ok = code != null && "200".equals(String.valueOf(code));
+ r.put("ok", ok);
+ r.put("msg", ar.get("msg"));
+ if (!ok) {
+ return r;
+ }
+ Object data = ar.get("data");
+ if (data instanceof Map) {
+ r.put("saved", ((Map<?, ?>) data).get("saved"));
+ r.put("clean", ((Map<?, ?>) data).get("clean"));
+ }
+ return r;
+ }
/* ==================== helpers ==================== */
private String buildHttpUrl(DataInterface di) {
@@ -500,4 +541,43 @@
private static int parseInt(String s, int def) {
try { return Integer.parseInt(s.trim()); } catch (Exception e) { return def; }
}
-}
+
+ /* ==================== 鈶� 鑷姩閲囬泦閰嶇疆 ==================== */
+
+ /**
+ * 寮�鍚�/鍏抽棴鑷姩閲囬泦锛屽苟璁剧疆閲囬泦鍛ㄦ湡锛坈ron锛�
+ */
+ @PostMapping("/autoConfig")
+ @ApiOperation("閰嶇疆鑷姩閲囬泦")
+ public AjaxResult autoConfig(@RequestBody Map<String, Object> body) {
+ Long id = null;
+ try { id = Long.valueOf(String.valueOf(body.get("id"))); } catch (Exception ignore) {}
+ if (id == null) return AjaxResult.error("id 涓嶈兘涓虹┖");
+ DataInterface di = dataInterfaceservice.getById(id);
+ if (di == null) return AjaxResult.error("鎺ュ彛涓嶅瓨鍦�");
+
+ String enabled = body.get("autoEnabled") == null ? "0" : String.valueOf(body.get("autoEnabled"));
+ String cron = body.get("collectCron") == null ? null : String.valueOf(body.get("collectCron"));
+ if ("1".equals(enabled) && (cron == null || cron.trim().isEmpty())) {
+ return AjaxResult.error("寮�鍚嚜鍔ㄩ噰闆嗗繀椤诲~鍐� cron 琛ㄨ揪寮忥紝濡� 0 */5 * * * ?锛堟瘡 5 鍒嗛挓锛�");
+ }
+
+ DataInterface upd = new DataInterface();
+ upd.setId(id);
+ upd.setAutoEnabled(enabled);
+ upd.setCollectCron(cron);
+ dataInterfaceservice.updateById(upd);
+ return AjaxResult.success("1".equals(enabled) ? "宸插紑鍚嚜鍔ㄩ噰闆�" : "宸插叧闂嚜鍔ㄩ噰闆�");
+ }
+
+ /**
+ * 鏌ヨ褰撳墠鍚敤鑷姩閲囬泦鐨勬帴鍙o紙瀹氭椂浠诲姟鐢紝涔熷彲鍓嶇灞曠ず锛�
+ */
+ @GetMapping("/autoList")
+ @ApiOperation("鏌ヨ鍚敤鑷姩閲囬泦鐨勬帴鍙�")
+ public AjaxResult autoList() {
+ com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<DataInterface> w =
+ new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<>();
+ w.eq("auto_enabled", "1").orderByAsc("id");
+ return AjaxResult.success(dataInterfaceservice.list(w));
+ }}
--
Gitblit v1.9.3