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/pojo/AlertRecord.java | 106 +++
src/main/java/com/ruoyi/lims/controller/AlertRecordController.java | 55 +
src/main/java/com/ruoyi/lims/service/LimsAlertService.java | 37 +
src/main/java/com/ruoyi/lims/service/impl/AlertRecordServiceImpl.java | 38 +
src/main/java/com/ruoyi/lims/service/impl/CollectionVerifyServiceImpl.java | 36 +
src/main/java/com/ruoyi/lims/pojo/DataInterface.java | 15
src/main/java/com/ruoyi/lims/service/impl/LimsAlertServiceImpl.java | 279 ++++++++
src/main/java/com/ruoyi/lims/controller/DataCollectionController.java | 53 +
src/main/java/com/ruoyi/lims/pojo/CollectionVerify.java | 86 ++
src/main/java/com/ruoyi/lims/controller/RealtimeMonitorController.java | 120 +++
doc/sql/lims_batch3_modules.sql | 165 +++++
src/main/java/com/ruoyi/lims/service/AlertRecordService.java | 11
src/main/java/com/ruoyi/lims/service/CleanRuleService.java | 11
src/main/java/com/ruoyi/lims/service/impl/DataInterfaceServiceImpl.java | 1
src/main/java/com/ruoyi/lims/pojo/RealtimeMonitor.java | 12
src/main/java/com/ruoyi/lims/pojo/CleanRule.java | 87 ++
src/main/java/com/ruoyi/lims/service/LimsCleanService.java | 29
src/main/java/com/ruoyi/lims/mapper/CleanRuleMapper.java | 9
src/main/java/com/ruoyi/lims/service/impl/CleanRuleServiceImpl.java | 37 +
src/main/java/com/ruoyi/lims/controller/CleanRuleController.java | 55 +
src/main/java/com/ruoyi/lims/service/CollectionVerifyService.java | 11
src/main/java/com/ruoyi/lims/mapper/CollectionVerifyMapper.java | 9
src/main/java/com/ruoyi/lims/mapper/AlertRecordMapper.java | 9
src/main/java/com/ruoyi/lims/service/impl/LimsTaskService.java | 141 ++++
src/main/java/com/ruoyi/common/handler/CustomTenantLineHandler.java | 14
src/main/java/com/ruoyi/lims/controller/CollectionVerifyController.java | 55 +
src/main/java/com/ruoyi/lims/controller/DataInterfaceController.java | 82 ++
src/main/java/com/ruoyi/lims/pojo/DataCollection.java | 12
src/main/java/com/ruoyi/lims/service/impl/LimsCleanServiceImpl.java | 322 ++++++++++
29 files changed, 1,894 insertions(+), 3 deletions(-)
diff --git a/doc/sql/lims_batch3_modules.sql b/doc/sql/lims_batch3_modules.sql
new file mode 100644
index 0000000..bd80533
--- /dev/null
+++ b/doc/sql/lims_batch3_modules.sql
@@ -0,0 +1,165 @@
+-- ============================================================
+-- 鑺-LIMS 绗笁鎵归渶姹� DDL
+-- 鈶� 鏁版嵁閲囬泦涓庡鐞嗭細娓呮礂瑙勫垯 + 楠岃瘉璁板綍 + 鎺ュ彛鑷姩閲囬泦閰嶇疆
+-- 鈶� 瀹炴椂鐩戞帶涓庨璀︼細鍛婅璁板綍 + 鐩戞帶椤瑰垽瀹氬瓧娈�
+-- 搴擄細lims-ruoyi
+-- ============================================================
+
+-- ============================================================
+-- 鈶� 鏁版嵁娓呮礂瑙勫垯
+-- ============================================================
+DROP TABLE IF EXISTS `lims_clean_rule`;
+CREATE TABLE `lims_clean_rule` (
+ `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '涓婚敭ID',
+ `interface_id` BIGINT DEFAULT NULL COMMENT '鎺ュ彛ID(NULL=鍏ㄥ眬瑙勫垯)',
+ `interface_code` VARCHAR(64) DEFAULT NULL COMMENT '鎺ュ彛缂栫爜(鍐椾綑)',
+ `rule_name` VARCHAR(255) DEFAULT NULL COMMENT '瑙勫垯鍚嶇О',
+ `rule_type` VARCHAR(32) DEFAULT NULL COMMENT '绫诲瀷(empty-绌哄�煎鐞�,range-鑼冨洿鏍¢獙,outlier-寮傚父鍊煎墧闄�,duplicate-閲嶅鍓旈櫎,unit-鍗曚綅鎹㈢畻)',
+ `target_field` VARCHAR(64) DEFAULT 'collectionValue' COMMENT '浣滅敤瀛楁(collectionValue/dataType/unit)',
+ `condition_expr` VARCHAR(500) DEFAULT NULL COMMENT '鏉′欢琛ㄨ揪寮�(濡� <0 鎴� >1000锛屾垨 3sigma)',
+ `action_type` VARCHAR(32) DEFAULT NULL COMMENT '鍔ㄤ綔(replace-鏇挎崲,clamp-鎴柇鍒拌竟鐣�,discard-涓㈠純鏁存潯,flag-浠呮爣璁�)',
+ `action_value` VARCHAR(255) DEFAULT NULL COMMENT '鍔ㄤ綔鍙傛暟(鏇挎崲鍊�/杈圭晫鍊�)',
+ `priority` INT DEFAULT 100 COMMENT '浼樺厛绾�(鏁板瓧灏忕殑鍏堟墽琛�)',
+ `enabled` CHAR(1) DEFAULT '1' COMMENT '鏄惁鍚敤(1-鍚敤,0-鍋滅敤)',
+ `remark` VARCHAR(500) DEFAULT NULL COMMENT '澶囨敞',
+ `del_flag` CHAR(1) DEFAULT '0' COMMENT '鍒犻櫎鏍囧織(0-姝e父,2-鍒犻櫎)',
+ `tenant_id` BIGINT DEFAULT NULL COMMENT '绉熸埛ID',
+ `create_time` DATETIME DEFAULT NULL COMMENT '鍒涘缓鏃堕棿',
+ `create_user` INT DEFAULT NULL COMMENT '鍒涘缓鐢ㄦ埛',
+ `update_time` DATETIME DEFAULT NULL COMMENT '淇敼鏃堕棿',
+ `update_user` INT DEFAULT NULL COMMENT '淇敼鐢ㄦ埛',
+ PRIMARY KEY (`id`),
+ KEY `idx_interface_id` (`interface_id`),
+ KEY `idx_enabled` (`enabled`),
+ KEY `idx_tenant` (`tenant_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='LIMS-鏁版嵁娓呮礂瑙勫垯';
+
+-- ============================================================
+-- 鈶� 閲囬泦鏁版嵁楠岃瘉璁板綍
+-- ============================================================
+DROP TABLE IF EXISTS `lims_collection_verify`;
+CREATE TABLE `lims_collection_verify` (
+ `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '涓婚敭ID',
+ `collection_id` BIGINT DEFAULT NULL COMMENT '閲囬泦璁板綍ID(lims_data_collection.id)',
+ `collection_code` VARCHAR(64) DEFAULT NULL COMMENT '閲囬泦缂栧彿(鍐椾綑)',
+ `rule_id` BIGINT DEFAULT NULL COMMENT '瑙勫垯ID',
+ `rule_name` VARCHAR(255) DEFAULT NULL COMMENT '瑙勫垯鍚嶇О(鍐椾綑)',
+ `rule_type` VARCHAR(32) DEFAULT NULL COMMENT '瑙勫垯绫诲瀷',
+ `passed` CHAR(1) DEFAULT '1' COMMENT '鏄惁閫氳繃(1-閫氳繃,0-涓嶉�氳繃)',
+ `expected` VARCHAR(255) DEFAULT NULL COMMENT '鏈熸湜/瑙勫垯鎻忚堪',
+ `actual` VARCHAR(255) DEFAULT NULL COMMENT '瀹為檯鍊�',
+ `message` VARCHAR(1000) DEFAULT NULL COMMENT '璇存槑',
+ `verify_time` DATETIME DEFAULT NULL COMMENT '楠岃瘉鏃堕棿',
+ `del_flag` CHAR(1) DEFAULT '0' COMMENT '鍒犻櫎鏍囧織(0-姝e父,2-鍒犻櫎)',
+ `tenant_id` BIGINT DEFAULT NULL COMMENT '绉熸埛ID',
+ `create_time` DATETIME DEFAULT NULL COMMENT '鍒涘缓鏃堕棿',
+ `create_user` INT DEFAULT NULL COMMENT '鍒涘缓鐢ㄦ埛',
+ `update_time` DATETIME DEFAULT NULL COMMENT '淇敼鏃堕棿',
+ `update_user` INT DEFAULT NULL COMMENT '淇敼鐢ㄦ埛',
+ PRIMARY KEY (`id`),
+ KEY `idx_collection_id` (`collection_id`),
+ KEY `idx_tenant` (`tenant_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='LIMS-閲囬泦鏁版嵁楠岃瘉璁板綍';
+
+-- ============================================================
+-- 鈶� 鍛婅璁板綍锛堥璀﹂棴鐜級
+-- ============================================================
+DROP TABLE IF EXISTS `lims_alert_record`;
+CREATE TABLE `lims_alert_record` (
+ `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '涓婚敭ID',
+ `monitor_id` BIGINT DEFAULT NULL COMMENT '鐩戞帶椤笽D(lims_realtime_monitor.id)',
+ `monitor_code` VARCHAR(64) DEFAULT NULL COMMENT '鐩戞帶缂栧彿(鍐椾綑)',
+ `monitor_target` VARCHAR(255) DEFAULT NULL COMMENT '鐩戞帶瀵硅薄(鍐椾綑)',
+ `monitor_type` VARCHAR(32) DEFAULT NULL COMMENT '鐩戞帶绫诲瀷(鍐椾綑)',
+ `alert_level` VARCHAR(32) DEFAULT NULL COMMENT '鍛婅绾у埆(low/medium/high)',
+ `alert_value` DECIMAL(18,4) DEFAULT NULL COMMENT '瑙﹀彂鍊�',
+ `unit` VARCHAR(32) DEFAULT NULL COMMENT '鍗曚綅',
+ `upper_limit` DECIMAL(18,4) DEFAULT NULL COMMENT '褰撴椂涓婇檺',
+ `lower_limit` DECIMAL(18,4) DEFAULT NULL COMMENT '褰撴椂涓嬮檺',
+ `alert_message` VARCHAR(1000) DEFAULT NULL COMMENT '鍛婅鎻忚堪',
+ `source` VARCHAR(32) DEFAULT 'auto' COMMENT '鏉ユ簮(auto-瀹氭椂鎵弿,manual-鎵嬪姩妫�鏌�,collect-閲囬泦鍚屾)',
+ `status` VARCHAR(32) DEFAULT 'pending' COMMENT '鐘舵��(pending-寰呭鐞�,handling-澶勭悊涓�,resolved-宸插鐞�,ignored-宸插拷鐣�)',
+ `handler` VARCHAR(64) DEFAULT NULL COMMENT '澶勭悊浜�',
+ `handle_time` DATETIME DEFAULT NULL COMMENT '澶勭悊鏃堕棿',
+ `handle_measure` VARCHAR(1000) DEFAULT NULL COMMENT '澶勭悊鎺柦',
+ `alert_time` DATETIME DEFAULT NULL COMMENT '鍛婅鏃堕棿',
+ `del_flag` CHAR(1) DEFAULT '0' COMMENT '鍒犻櫎鏍囧織(0-姝e父,2-鍒犻櫎)',
+ `tenant_id` BIGINT DEFAULT NULL COMMENT '绉熸埛ID',
+ `create_time` DATETIME DEFAULT NULL COMMENT '鍒涘缓鏃堕棿',
+ `create_user` INT DEFAULT NULL COMMENT '鍒涘缓鐢ㄦ埛',
+ `update_time` DATETIME DEFAULT NULL COMMENT '淇敼鏃堕棿',
+ `update_user` INT DEFAULT NULL COMMENT '淇敼鐢ㄦ埛',
+ PRIMARY KEY (`id`),
+ KEY `idx_monitor_id` (`monitor_id`),
+ KEY `idx_status` (`status`),
+ KEY `idx_alert_time` (`alert_time`),
+ KEY `idx_tenant` (`tenant_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='LIMS-鍛婅璁板綍';
+
+-- ============================================================
+-- 鏀瑰姩鐜版湁琛�
+-- ============================================================
+
+-- 鈶� 鎺ュ彛锛氳嚜鍔ㄩ噰闆嗛厤缃�
+ALTER TABLE `lims_data_interface`
+ ADD COLUMN `auto_enabled` CHAR(1) DEFAULT '0' COMMENT '鏄惁鑷姩閲囬泦(1-鍚敤,0-鍋滅敤)' AFTER `status`,
+ ADD COLUMN `collect_cron` VARCHAR(64) DEFAULT NULL COMMENT '閲囬泦闂撮殧cron(濡� 0 */5 * * * ?)' AFTER `auto_enabled`,
+ ADD COLUMN `last_collect_time` DATETIME DEFAULT NULL COMMENT '涓婃閲囬泦鏃堕棿' AFTER `collect_cron`,
+ ADD COLUMN `last_collect_result` VARCHAR(500) DEFAULT NULL COMMENT '涓婃閲囬泦缁撴灉' AFTER `last_collect_time`;
+
+-- 鈶� 閲囬泦璁板綍锛氭竻娲椾笌楠岃瘉鐘舵��
+ALTER TABLE `lims_data_collection`
+ ADD COLUMN `clean_status` VARCHAR(32) DEFAULT 'pending' COMMENT '娓呮礂鐘舵��(pending-寰呮竻娲�,cleaned-宸叉竻娲�,discarded-宸蹭涪寮�,failed-娓呮礂澶辫触)' AFTER `process_method`,
+ ADD COLUMN `clean_log` VARCHAR(2000) DEFAULT NULL COMMENT '娓呮礂鏃ュ織(閫愭潯璁板綍鎵ц浜嗗摢浜涜鍒�)' AFTER `clean_status`,
+ ADD COLUMN `verify_status` VARCHAR(32) DEFAULT 'pending' COMMENT '楠岃瘉鐘舵��(pending-寰呴獙璇�,passed-閫氳繃,failed-鏈�氳繃)' AFTER `clean_log`,
+ ADD COLUMN `verify_msg` VARCHAR(1000) DEFAULT NULL COMMENT '楠岃瘉璇存槑' AFTER `verify_status`;
+
+-- 鈶� 鐩戞帶椤癸細鍒ゅ畾鐩稿叧
+ALTER TABLE `lims_realtime_monitor`
+ ADD COLUMN `last_check_time` DATETIME DEFAULT NULL COMMENT '涓婃鍒ゅ畾鏃堕棿' AFTER `monitor_time`,
+ ADD COLUMN `alert_count` INT DEFAULT 0 COMMENT '绱瑙﹀彂鍛婅娆℃暟' AFTER `last_check_time`,
+ ADD COLUMN `source_collection_id` BIGINT DEFAULT NULL COMMENT '鏁版嵁鏉ユ簮閲囬泦璁板綍ID' AFTER `alert_count`;
+
+-- ============================================================
+-- 棰勭疆鍑犳潯甯哥敤娓呮礂瑙勫垯锛堝叏灞�锛屾帴鍙D涓虹┖锛�
+-- ============================================================
+INSERT INTO `lims_clean_rule` (`rule_name`, `rule_type`, `target_field`, `condition_expr`, `action_type`, `action_value`, `priority`, `enabled`, `remark`) VALUES
+('绌哄�间涪寮�', 'empty', 'collectionValue', 'null', 'discard', NULL, 10, '1', '閲囬泦鏁板�间负绌烘椂鏁存潯涓㈠純'),
+('璐熷�兼埅鏂负闆�', 'range', 'collectionValue', '<0', 'clamp', '0', 20, '1', '娴撳害/鍘嬪姏绛変笉搴斾负璐燂紝鎴柇鍒� 0'),
+('鏋佸ぇ鍊兼爣璁�', 'outlier', 'collectionValue', '>1000000','flag', NULL, 30, '1', '瓒呰繃涓�鐧句竾瑙嗕负鍙枒锛屼粎鏍囪涓嶄涪寮�');
+
+-- ============================================================
+-- 鏍¢獙
+-- ============================================================
+SELECT table_name, table_comment
+FROM information_schema.tables
+WHERE table_schema = 'lims-ruoyi'
+ AND table_name IN ('lims_clean_rule','lims_collection_verify','lims_alert_record')
+ORDER BY table_name;
+
+SELECT column_name, column_type, column_comment
+FROM information_schema.columns
+WHERE table_schema = 'lims-ruoyi' AND table_name = 'lims_data_collection'
+ AND column_name IN ('clean_status','clean_log','verify_status','verify_msg')
+ORDER BY ordinal_position;
+
+SELECT column_name, column_type
+FROM information_schema.columns
+WHERE table_schema = 'lims-ruoyi' AND table_name = 'lims_data_interface'
+ AND column_name IN ('auto_enabled','collect_cron','last_collect_time','last_collect_result');
+
+SELECT column_name, column_type
+FROM information_schema.columns
+WHERE table_schema = 'lims-ruoyi' AND table_name = 'lims_realtime_monitor'
+ AND column_name IN ('last_check_time','alert_count','source_collection_id');
+
+-- ============================================================
+-- 鈶も懃 瀹氭椂浠诲姟锛圧uoYi 鐨� sys_job锛岄厤缃悗鍒般�岀郴缁熺洃鎺р啋瀹氭椂浠诲姟銆嶉噷鑳界湅鍒板苟鍚仠锛�
+-- ============================================================
+DELETE FROM `sys_job` WHERE `invoke_target` IN ('limsTask.autoCollect', 'limsTask.checkAlerts');
+
+INSERT INTO `sys_job` (`job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `create_by`, `create_time`, `remark`) VALUES
+('LIMS鑷姩閲囬泦', 'LIMS', 'limsTask.autoCollect', '0 */5 * * * ?', '3', '1', '1', 'admin', NOW(), '鎵弿 auto_enabled=1 鐨勬帴鍙o紝閫愪釜閲囬泦骞舵寜娓呮礂瑙勫垯澶勭悊'),
+('LIMS鐩戞帶棰勮鎵弿', 'LIMS', 'limsTask.checkAlerts', '0 * * * * ?', '3', '1', '1', 'admin', NOW(), '鍏堟竻娲楀緟澶勭悊閲囬泦鏁版嵁锛屽啀鎵弿鎵�鏈夌洃鎺ч」鍒ゅ畾瓒婇檺骞剁敓鎴愬憡璀�');
+
+SELECT job_id, job_name, invoke_target, cron_expression, status FROM `sys_job` WHERE `job_group` = 'LIMS';
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/common/handler/CustomTenantLineHandler.java b/src/main/java/com/ruoyi/common/handler/CustomTenantLineHandler.java
index d1b6d54..a34b50a 100644
--- a/src/main/java/com/ruoyi/common/handler/CustomTenantLineHandler.java
+++ b/src/main/java/com/ruoyi/common/handler/CustomTenantLineHandler.java
@@ -16,6 +16,16 @@
@Component
public class CustomTenantLineHandler implements TenantLineHandler {
+ /**
+ * 涓存椂璺宠繃绉熸埛杩囨护鐨勫紑鍏炽��
+ *
+ * 鍦烘櫙锛氬尶鍚嶆帴鍙o紙璁惧鍥炰紶锛夈�佸叏灞�閰嶇疆琛紙濡傛竻娲楄鍒欙級杩欑被娌℃湁鐧诲綍涓婁笅鏂囩殑鏁版嵁锛�
+ * 涓嶅簲璇ヨ鑷姩鍔犱笂 tenant_id 鏉′欢銆傜敤娉曪細
+ * CustomTenantLineHandler.TEMP_IGNORE.set(Boolean.TRUE);
+ * try { ... } finally { CustomTenantLineHandler.TEMP_IGNORE.remove(); }
+ */
+ public static final ThreadLocal<Boolean> TEMP_IGNORE = new ThreadLocal<>();
+
@Override
public Expression getTenantId() {
try {
@@ -28,6 +38,10 @@
@Override
public boolean ignoreTable(String tableName) {
+ // 涓存椂璺宠繃锛堝尶鍚嶆帴鍙� / 鍏ㄥ眬閰嶇疆琛級
+ if (Boolean.TRUE.equals(TEMP_IGNORE.get())) {
+ return true;
+ }
// 鎸囧畾涓嶉渶瑕佹坊鍔犺繃婊ゆ潯浠剁殑琛�
Set<String> ignoreTables = IgnoreTableConfig.IGNORE_TABLES;
return ignoreTables.contains(tableName);
diff --git a/src/main/java/com/ruoyi/lims/controller/AlertRecordController.java b/src/main/java/com/ruoyi/lims/controller/AlertRecordController.java
new file mode 100644
index 0000000..6139477
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/controller/AlertRecordController.java
@@ -0,0 +1,55 @@
+package com.ruoyi.lims.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.lims.pojo.AlertRecord;
+import com.ruoyi.lims.service.AlertRecordService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@AllArgsConstructor
+@RequestMapping("/lims/alertRecord")
+@Api(value = "AlertRecord", tags = "Alert Records")
+public class AlertRecordController {
+
+ private AlertRecordService alertRecordService;
+
+ @GetMapping("/listPage")
+ @ApiOperation("Paged query")
+ public AjaxResult listPage(Page<AlertRecord> page, AlertRecord query) {
+ IPage<AlertRecord> result = alertRecordService.listPage(page, query);
+ return AjaxResult.success(result);
+ }
+
+ @GetMapping("/{id}")
+ @ApiOperation("Get by id")
+ public AjaxResult getById(@PathVariable Long id) {
+ return AjaxResult.success(alertRecordService.getById(id));
+ }
+
+ @PostMapping("/add")
+ @ApiOperation("Add")
+ public AjaxResult add(@RequestBody AlertRecord entity) {
+ return AjaxResult.success(alertRecordService.save(entity));
+ }
+
+ @PostMapping("/update")
+ @ApiOperation("Update")
+ public AjaxResult update(@RequestBody AlertRecord entity) {
+ return AjaxResult.success(alertRecordService.updateById(entity));
+ }
+
+ @DeleteMapping("/delete")
+ @ApiOperation("Batch delete")
+ public AjaxResult delete(@RequestBody List<Long> ids) {
+ if (CollectionUtils.isEmpty(ids)) return AjaxResult.error("ids required");
+ return AjaxResult.success(alertRecordService.removeBatchByIds(ids));
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/controller/CleanRuleController.java b/src/main/java/com/ruoyi/lims/controller/CleanRuleController.java
new file mode 100644
index 0000000..78a9651
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/controller/CleanRuleController.java
@@ -0,0 +1,55 @@
+package com.ruoyi.lims.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.lims.pojo.CleanRule;
+import com.ruoyi.lims.service.CleanRuleService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@AllArgsConstructor
+@RequestMapping("/lims/cleanRule")
+@Api(value = "CleanRule", tags = "Clean Rules")
+public class CleanRuleController {
+
+ private CleanRuleService cleanRuleService;
+
+ @GetMapping("/listPage")
+ @ApiOperation("Paged query")
+ public AjaxResult listPage(Page<CleanRule> page, CleanRule query) {
+ IPage<CleanRule> result = cleanRuleService.listPage(page, query);
+ return AjaxResult.success(result);
+ }
+
+ @GetMapping("/{id}")
+ @ApiOperation("Get by id")
+ public AjaxResult getById(@PathVariable Long id) {
+ return AjaxResult.success(cleanRuleService.getById(id));
+ }
+
+ @PostMapping("/add")
+ @ApiOperation("Add")
+ public AjaxResult add(@RequestBody CleanRule entity) {
+ return AjaxResult.success(cleanRuleService.save(entity));
+ }
+
+ @PostMapping("/update")
+ @ApiOperation("Update")
+ public AjaxResult update(@RequestBody CleanRule entity) {
+ return AjaxResult.success(cleanRuleService.updateById(entity));
+ }
+
+ @DeleteMapping("/delete")
+ @ApiOperation("Batch delete")
+ public AjaxResult delete(@RequestBody List<Long> ids) {
+ if (CollectionUtils.isEmpty(ids)) return AjaxResult.error("ids required");
+ return AjaxResult.success(cleanRuleService.removeBatchByIds(ids));
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/controller/CollectionVerifyController.java b/src/main/java/com/ruoyi/lims/controller/CollectionVerifyController.java
new file mode 100644
index 0000000..c19ce67
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/controller/CollectionVerifyController.java
@@ -0,0 +1,55 @@
+package com.ruoyi.lims.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.lims.pojo.CollectionVerify;
+import com.ruoyi.lims.service.CollectionVerifyService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@AllArgsConstructor
+@RequestMapping("/lims/collectionVerify")
+@Api(value = "CollectionVerify", tags = "Collection Verifications")
+public class CollectionVerifyController {
+
+ private CollectionVerifyService collectionVerifyService;
+
+ @GetMapping("/listPage")
+ @ApiOperation("Paged query")
+ public AjaxResult listPage(Page<CollectionVerify> page, CollectionVerify query) {
+ IPage<CollectionVerify> result = collectionVerifyService.listPage(page, query);
+ return AjaxResult.success(result);
+ }
+
+ @GetMapping("/{id}")
+ @ApiOperation("Get by id")
+ public AjaxResult getById(@PathVariable Long id) {
+ return AjaxResult.success(collectionVerifyService.getById(id));
+ }
+
+ @PostMapping("/add")
+ @ApiOperation("Add")
+ public AjaxResult add(@RequestBody CollectionVerify entity) {
+ return AjaxResult.success(collectionVerifyService.save(entity));
+ }
+
+ @PostMapping("/update")
+ @ApiOperation("Update")
+ public AjaxResult update(@RequestBody CollectionVerify entity) {
+ return AjaxResult.success(collectionVerifyService.updateById(entity));
+ }
+
+ @DeleteMapping("/delete")
+ @ApiOperation("Batch delete")
+ public AjaxResult delete(@RequestBody List<Long> ids) {
+ if (CollectionUtils.isEmpty(ids)) return AjaxResult.error("ids required");
+ return AjaxResult.success(collectionVerifyService.removeBatchByIds(ids));
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/controller/DataCollectionController.java b/src/main/java/com/ruoyi/lims/controller/DataCollectionController.java
index 12dfbeb..27e7210 100644
--- a/src/main/java/com/ruoyi/lims/controller/DataCollectionController.java
+++ b/src/main/java/com/ruoyi/lims/controller/DataCollectionController.java
@@ -6,12 +6,15 @@
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.lims.pojo.DataCollection;
import com.ruoyi.lims.service.DataCollectionService;
+import com.ruoyi.lims.service.LimsCleanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
@RestController
@AllArgsConstructor
@@ -20,6 +23,8 @@
public class DataCollectionController {
private DataCollectionService dataCollectionservice;
+ private LimsCleanService cleanService;
+ private com.ruoyi.lims.service.CollectionVerifyService collectionVerifyService;
@GetMapping("/listPage")
@ApiOperation("鍒嗛〉鏌ヨ鎵�鏈夋暟鎹噰闆嗕笌澶勭悊琛�")
@@ -52,4 +57,50 @@
if (CollectionUtils.isEmpty(ids)) return AjaxResult.error("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
return AjaxResult.success(dataCollectionservice.removeBatchByIds(ids));
}
-}
+
+ /* ==================== 鈶� 娓呮礂涓庨獙璇� ==================== */
+
+ /**
+ * 娓呮礂鍗曟潯閲囬泦璁板綍
+ */
+ @PostMapping("/process/{id}")
+ @ApiOperation("娓呮礂鍗曟潯閲囬泦璁板綍")
+ public AjaxResult process(@PathVariable Long id) {
+ return AjaxResult.success("娓呮礂瀹屾垚", cleanService.cleanOne(id));
+ }
+
+ /**
+ * 鎵归噺娓呮礂
+ */
+ @PostMapping("/processBatch")
+ @ApiOperation("鎵归噺娓呮礂閲囬泦璁板綍")
+ public AjaxResult processBatch(@RequestBody List<Long> ids) {
+ if (CollectionUtils.isEmpty(ids)) return AjaxResult.error("璇蜂紶鍏ヨ娓呮礂鐨勮褰旾D");
+ return AjaxResult.success("娓呮礂瀹屾垚", cleanService.cleanBatch(ids));
+ }
+
+ /**
+ * 娓呮礂鎵�鏈夊緟娓呮礂璁板綍锛堜篃鍙敱瀹氭椂浠诲姟璋冪敤锛�
+ */
+ @PostMapping("/processPending")
+ @ApiOperation("娓呮礂鎵�鏈夊緟娓呮礂璁板綍")
+ public AjaxResult processPending(@RequestParam(defaultValue = "200") int limit) {
+ return AjaxResult.success("娓呮礂瀹屾垚", cleanService.cleanPending(limit));
+ }
+
+ /**
+ * 閲囬泦璇︽儏锛氳褰曟湰浣� + 楠岃瘉璁板綍
+ */
+ @GetMapping("/detail/{id}")
+ @ApiOperation("閲囬泦璇︽儏锛堝惈楠岃瘉璁板綍锛�")
+ public AjaxResult detail(@PathVariable Long id) {
+ com.ruoyi.lims.pojo.DataCollection dc = dataCollectionservice.getById(id);
+ if (dc == null) return AjaxResult.error("閲囬泦璁板綍涓嶅瓨鍦�");
+ com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<com.ruoyi.lims.pojo.CollectionVerify> w =
+ new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<>();
+ w.eq("collection_id", id).orderByDesc("id");
+ Map<String, Object> ret = new LinkedHashMap<>();
+ ret.put("collection", dc);
+ ret.put("verifies", collectionVerifyService.list(w));
+ return AjaxResult.success(ret);
+ }}
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));
+ }}
diff --git a/src/main/java/com/ruoyi/lims/controller/RealtimeMonitorController.java b/src/main/java/com/ruoyi/lims/controller/RealtimeMonitorController.java
index 5af8fdd..a68d756 100644
--- a/src/main/java/com/ruoyi/lims/controller/RealtimeMonitorController.java
+++ b/src/main/java/com/ruoyi/lims/controller/RealtimeMonitorController.java
@@ -3,15 +3,19 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.lims.pojo.RealtimeMonitor;
+import com.ruoyi.lims.service.LimsAlertService;
import com.ruoyi.lims.service.RealtimeMonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
@RestController
@AllArgsConstructor
@@ -20,6 +24,8 @@
public class RealtimeMonitorController {
private RealtimeMonitorService realtimeMonitorservice;
+ private LimsAlertService alertService;
+ private com.ruoyi.lims.service.AlertRecordService alertRecordService;
@GetMapping("/listPage")
@ApiOperation("鍒嗛〉鏌ヨ鎵�鏈夊疄鏃剁洃鎺т笌棰勮琛�")
@@ -46,4 +52,116 @@
if (CollectionUtils.isEmpty(ids)) return AjaxResult.error("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
return AjaxResult.success(realtimeMonitorservice.removeBatchByIds(ids));
}
-}
+
+ @GetMapping("/{id}")
+ @ApiOperation("鏍规嵁ID鏌ヨ鐩戞帶椤�")
+ public AjaxResult getById(@PathVariable Long id) {
+ return AjaxResult.success(realtimeMonitorservice.getById(id));
+ }
+
+ /* ==================== 鈶� 棰勮鍒ゅ畾涓庡憡璀﹂棴鐜� ==================== */
+
+ /**
+ * 鎵嬪姩妫�鏌ュ崟涓洃鎺ч」鏄惁瓒婇檺
+ */
+ @PostMapping("/check/{id}")
+ @ApiOperation("妫�鏌ュ崟涓洃鎺ч」鏄惁瓒婇檺")
+ public AjaxResult check(@PathVariable Long id) {
+ Map<String, Object> r = alertService.checkOne(id);
+ return AjaxResult.success("妫�鏌ュ畬鎴�", r);
+ }
+
+ /**
+ * 鎵弿鎵�鏈夌洃鎺ч」鍋氫竴娆″垽瀹�
+ */
+ @PostMapping("/checkAll")
+ @ApiOperation("鎵弿鎵�鏈夌洃鎺ч」鍒ゅ畾瓒婇檺")
+ public AjaxResult checkAll(@RequestParam(defaultValue = "500") int limit) {
+ return AjaxResult.success("妫�鏌ュ畬鎴�", alertService.checkAll(limit));
+ }
+
+ /**
+ * 鎶婇噰闆嗚褰曞悓姝ュ埌鐩戞帶椤瑰苟绔嬪嵆鍒ゅ畾
+ */
+ @PostMapping("/sync/{collectionId}")
+ @ApiOperation("閲囬泦鏁版嵁鍚屾鍒扮洃鎺ч」骞跺垽瀹�")
+ public AjaxResult sync(@PathVariable Long collectionId) {
+ Map<String, Object> r = alertService.syncFromCollection(collectionId);
+ return r.containsKey("message") && r.get("monitorId") == null
+ ? AjaxResult.error(String.valueOf(r.get("message")))
+ : AjaxResult.success("鍚屾瀹屾垚", r);
+ }
+
+ /**
+ * 鍛婅璁板綍鍒楄〃
+ */
+ @GetMapping("/alerts")
+ @ApiOperation("鍛婅璁板綍鍒楄〃")
+ public AjaxResult alerts(com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.ruoyi.lims.pojo.AlertRecord> page,
+ com.ruoyi.lims.pojo.AlertRecord query) {
+ com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<com.ruoyi.lims.pojo.AlertRecord> w =
+ new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<>();
+ if (query != null) {
+ if (query.getMonitorId() != null) w.eq("monitor_id", query.getMonitorId());
+ if (query.getStatus() != null && !query.getStatus().trim().isEmpty()) w.eq("status", query.getStatus());
+ if (query.getAlertLevel() != null && !query.getAlertLevel().trim().isEmpty()) w.eq("alert_level", query.getAlertLevel());
+ if (query.getMonitorCode() != null && !query.getMonitorCode().trim().isEmpty()) w.like("monitor_code", query.getMonitorCode());
+ }
+ w.orderByDesc("alert_time").orderByDesc("id");
+ return AjaxResult.success(alertRecordService.page(page, w));
+ }
+
+ /**
+ * 澶勭悊鍛婅锛堥棴鐜級
+ */
+ @PostMapping("/alert/handle")
+ @ApiOperation("澶勭悊鍛婅")
+ public AjaxResult handleAlert(@RequestBody Map<String, Object> body) {
+ Long alertId = null;
+ try { alertId = Long.valueOf(String.valueOf(body.get("alertId"))); } catch (Exception ignore) {}
+ if (alertId == null) return AjaxResult.error("alertId 涓嶈兘涓虹┖");
+ String status = body.get("status") == null ? "resolved" : String.valueOf(body.get("status"));
+ String measure = body.get("measure") == null ? null : String.valueOf(body.get("measure"));
+ String handler;
+ try { handler = SecurityUtils.getUsername(); } catch (Exception e) { handler = "system"; }
+ Map<String, Object> r = alertService.handleAlert(alertId, status, measure, handler);
+ return AjaxResult.success(String.valueOf(r.get("message")), r);
+ }
+
+ /**
+ * 鍛婅缁熻
+ */
+ @GetMapping("/alertStatistics")
+ @ApiOperation("鍛婅缁熻")
+ public AjaxResult alertStatistics() {
+ return AjaxResult.success(alertService.statistics());
+ }
+
+ /**
+ * 鐩戞帶鐪嬫澘锛氱洃鎺ч」鐘舵�佹眹鎬�
+ */
+ @GetMapping("/dashboard")
+ @ApiOperation("瀹炴椂鐩戞帶鐪嬫澘")
+ public AjaxResult dashboard() {
+ Map<String, Object> ret = new LinkedHashMap<>();
+ long total = realtimeMonitorservice.count();
+ com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<com.ruoyi.lims.pojo.RealtimeMonitor> w1 =
+ new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<>();
+ w1.eq("alert_status", "alert");
+ long alerting = realtimeMonitorservice.count(w1);
+ com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<com.ruoyi.lims.pojo.RealtimeMonitor> w2 =
+ new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<>();
+ w2.eq("alert_status", "warning");
+ long warning = realtimeMonitorservice.count(w2);
+ com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<com.ruoyi.lims.pojo.RealtimeMonitor> w3 =
+ new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<>();
+ w3.and(x -> x.eq("alert_status", "normal").or().isNull("alert_status"));
+ long normal = realtimeMonitorservice.count(w3);
+
+ ret.put("total", total);
+ ret.put("alerting", alerting);
+ ret.put("warning", warning);
+ ret.put("normal", normal);
+ ret.put("alerts", alertService.statistics());
+ return AjaxResult.success(ret);
+ }}
diff --git a/src/main/java/com/ruoyi/lims/mapper/AlertRecordMapper.java b/src/main/java/com/ruoyi/lims/mapper/AlertRecordMapper.java
new file mode 100644
index 0000000..862530d
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/mapper/AlertRecordMapper.java
@@ -0,0 +1,9 @@
+package com.ruoyi.lims.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.lims.pojo.AlertRecord;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface AlertRecordMapper extends BaseMapper<AlertRecord> {
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/mapper/CleanRuleMapper.java b/src/main/java/com/ruoyi/lims/mapper/CleanRuleMapper.java
new file mode 100644
index 0000000..38f0486
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/mapper/CleanRuleMapper.java
@@ -0,0 +1,9 @@
+package com.ruoyi.lims.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.lims.pojo.CleanRule;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface CleanRuleMapper extends BaseMapper<CleanRule> {
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/mapper/CollectionVerifyMapper.java b/src/main/java/com/ruoyi/lims/mapper/CollectionVerifyMapper.java
new file mode 100644
index 0000000..b096471
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/mapper/CollectionVerifyMapper.java
@@ -0,0 +1,9 @@
+package com.ruoyi.lims.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.lims.pojo.CollectionVerify;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface CollectionVerifyMapper extends BaseMapper<CollectionVerify> {
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/pojo/AlertRecord.java b/src/main/java/com/ruoyi/lims/pojo/AlertRecord.java
new file mode 100644
index 0000000..d44f842
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/pojo/AlertRecord.java
@@ -0,0 +1,106 @@
+package com.ruoyi.lims.pojo;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+@Data
+@TableName("lims_alert_record")
+public class AlertRecord implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ @ApiModelProperty(value = "ID")
+ @TableId(value = "id", type = IdType.AUTO)
+ private Long id;
+
+ @ApiModelProperty(value = "Monitor id")
+ private Long monitorId;
+
+ @ApiModelProperty(value = "Monitor code")
+ private String monitorCode;
+
+ @ApiModelProperty(value = "Monitor target")
+ private String monitorTarget;
+
+ @ApiModelProperty(value = "Monitor type")
+ private String monitorType;
+
+ @ApiModelProperty(value = "Level: low/medium/high")
+ private String alertLevel;
+
+ @ApiModelProperty(value = "Alert value")
+ private BigDecimal alertValue;
+
+ @ApiModelProperty(value = "Unit")
+ private String unit;
+
+ @ApiModelProperty(value = "Upper limit")
+ private BigDecimal upperLimit;
+
+ @ApiModelProperty(value = "Lower limit")
+ private BigDecimal lowerLimit;
+
+ @ApiModelProperty(value = "Alert message")
+ private String alertMessage;
+
+ @ApiModelProperty(value = "Source: auto/manual/collect")
+ private String source;
+
+ @ApiModelProperty(value = "Status: pending/handling/resolved/ignored")
+ private String status;
+
+ @ApiModelProperty(value = "Handler")
+ private String handler;
+
+ @ApiModelProperty(value = "Handle time")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime handleTime;
+
+ @ApiModelProperty(value = "Handle measure")
+ private String handleMeasure;
+
+ @ApiModelProperty(value = "Alert time")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime alertTime;
+
+ @ApiModelProperty(value = "Delete flag")
+ private String delFlag;
+
+ @ApiModelProperty(value = "Tenant id")
+ @TableField(fill = FieldFill.INSERT)
+ private Long tenantId;
+
+ @ApiModelProperty(value = "Create time")
+ @TableField(fill = FieldFill.INSERT)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime createTime;
+
+ @ApiModelProperty(value = "Create user")
+ @TableField(fill = FieldFill.INSERT)
+ private Integer createUser;
+
+ @ApiModelProperty(value = "Update time")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime updateTime;
+
+ @ApiModelProperty(value = "Update user")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ private Integer updateUser;
+
+}
diff --git a/src/main/java/com/ruoyi/lims/pojo/CleanRule.java b/src/main/java/com/ruoyi/lims/pojo/CleanRule.java
new file mode 100644
index 0000000..7ddcba0
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/pojo/CleanRule.java
@@ -0,0 +1,87 @@
+package com.ruoyi.lims.pojo;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+@Data
+@TableName("lims_clean_rule")
+public class CleanRule implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ @ApiModelProperty(value = "ID")
+ @TableId(value = "id", type = IdType.AUTO)
+ private Long id;
+
+ @ApiModelProperty(value = "Interface id")
+ private Long interfaceId;
+
+ @ApiModelProperty(value = "Interface code")
+ private String interfaceCode;
+
+ @ApiModelProperty(value = "Rule name")
+ private String ruleName;
+
+ @ApiModelProperty(value = "Type: empty/range/outlier/duplicate/unit")
+ private String ruleType;
+
+ @ApiModelProperty(value = "Target field")
+ private String targetField;
+
+ @ApiModelProperty(value = "Condition expression")
+ private String conditionExpr;
+
+ @ApiModelProperty(value = "Action: replace/clamp/discard/flag")
+ private String actionType;
+
+ @ApiModelProperty(value = "Action value")
+ private String actionValue;
+
+ @ApiModelProperty(value = "Priority")
+ private Integer priority;
+
+ @ApiModelProperty(value = "Enabled 1/0")
+ private String enabled;
+
+ @ApiModelProperty(value = "Remark")
+ private String remark;
+
+ @ApiModelProperty(value = "Delete flag")
+ private String delFlag;
+
+ @ApiModelProperty(value = "Tenant id")
+ @TableField(fill = FieldFill.INSERT)
+ private Long tenantId;
+
+ @ApiModelProperty(value = "Create time")
+ @TableField(fill = FieldFill.INSERT)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime createTime;
+
+ @ApiModelProperty(value = "Create user")
+ @TableField(fill = FieldFill.INSERT)
+ private Integer createUser;
+
+ @ApiModelProperty(value = "Update time")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime updateTime;
+
+ @ApiModelProperty(value = "Update user")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ private Integer updateUser;
+
+}
diff --git a/src/main/java/com/ruoyi/lims/pojo/CollectionVerify.java b/src/main/java/com/ruoyi/lims/pojo/CollectionVerify.java
new file mode 100644
index 0000000..6efa805
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/pojo/CollectionVerify.java
@@ -0,0 +1,86 @@
+package com.ruoyi.lims.pojo;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+@Data
+@TableName("lims_collection_verify")
+public class CollectionVerify implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ @ApiModelProperty(value = "ID")
+ @TableId(value = "id", type = IdType.AUTO)
+ private Long id;
+
+ @ApiModelProperty(value = "Collection id")
+ private Long collectionId;
+
+ @ApiModelProperty(value = "Collection code")
+ private String collectionCode;
+
+ @ApiModelProperty(value = "Rule id")
+ private Long ruleId;
+
+ @ApiModelProperty(value = "Rule name")
+ private String ruleName;
+
+ @ApiModelProperty(value = "Rule type")
+ private String ruleType;
+
+ @ApiModelProperty(value = "Passed 1/0")
+ private String passed;
+
+ @ApiModelProperty(value = "Expected")
+ private String expected;
+
+ @ApiModelProperty(value = "Actual")
+ private String actual;
+
+ @ApiModelProperty(value = "Message")
+ private String message;
+
+ @ApiModelProperty(value = "Verify time")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime verifyTime;
+
+ @ApiModelProperty(value = "Delete flag")
+ private String delFlag;
+
+ @ApiModelProperty(value = "Tenant id")
+ @TableField(fill = FieldFill.INSERT)
+ private Long tenantId;
+
+ @ApiModelProperty(value = "Create time")
+ @TableField(fill = FieldFill.INSERT)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime createTime;
+
+ @ApiModelProperty(value = "Create user")
+ @TableField(fill = FieldFill.INSERT)
+ private Integer createUser;
+
+ @ApiModelProperty(value = "Update time")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime updateTime;
+
+ @ApiModelProperty(value = "Update user")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
+ private Integer updateUser;
+
+}
diff --git a/src/main/java/com/ruoyi/lims/pojo/DataCollection.java b/src/main/java/com/ruoyi/lims/pojo/DataCollection.java
index b0d6f9c..6da9d08 100644
--- a/src/main/java/com/ruoyi/lims/pojo/DataCollection.java
+++ b/src/main/java/com/ruoyi/lims/pojo/DataCollection.java
@@ -76,6 +76,18 @@
*/
@ApiModelProperty(value="澶勭悊鏂瑰紡(autoClean-鑷姩娓呮礂,manualVerify-浜哄伐鏍¢獙,dataTransform-鏁版嵁杞崲)")
private String processMethod;
+
+ @ApiModelProperty(value = "Clean status: pending/cleaned/discarded/failed")
+ private String cleanStatus;
+
+ @ApiModelProperty(value = "Clean log")
+ private String cleanLog;
+
+ @ApiModelProperty(value = "Verify status: pending/passed/failed")
+ private String verifyStatus;
+
+ @ApiModelProperty(value = "Verify message")
+ private String verifyMsg;
/**
* 鍘熷鏁版嵁
*/
diff --git a/src/main/java/com/ruoyi/lims/pojo/DataInterface.java b/src/main/java/com/ruoyi/lims/pojo/DataInterface.java
index 7ec36ba..5f0f98b 100644
--- a/src/main/java/com/ruoyi/lims/pojo/DataInterface.java
+++ b/src/main/java/com/ruoyi/lims/pojo/DataInterface.java
@@ -10,6 +10,8 @@
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
+import org.springframework.format.annotation.DateTimeFormat;
+import com.fasterxml.jackson.annotation.JsonFormat;
@Data
@TableName("lims_data_interface")
@@ -62,6 +64,19 @@
* 鎺ュ彛鐘舵��(1-鍚敤,0-绂佺敤)
*/
@ApiModelProperty(value="鎺ュ彛鐘舵��(1-鍚敤,0-绂佺敤)")
+ private String autoEnabled;
+
+ @ApiModelProperty(value = "Collect cron expression")
+ private String collectCron;
+
+ @ApiModelProperty(value = "Last collect time")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime lastCollectTime;
+
+ @ApiModelProperty(value = "Last collect result")
+ private String lastCollectResult;
+
private String status;
/**
* 鎺ュ彛鎻忚堪
diff --git a/src/main/java/com/ruoyi/lims/pojo/RealtimeMonitor.java b/src/main/java/com/ruoyi/lims/pojo/RealtimeMonitor.java
index 520ada7..4c1b11b 100644
--- a/src/main/java/com/ruoyi/lims/pojo/RealtimeMonitor.java
+++ b/src/main/java/com/ruoyi/lims/pojo/RealtimeMonitor.java
@@ -12,6 +12,7 @@
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
+import org.springframework.format.annotation.DateTimeFormat;
@Data
@TableName("lims_realtime_monitor")
@@ -81,6 +82,17 @@
@ApiModelProperty(value="鐩戞帶鏃堕棿")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime monitorTime;
+
+ @ApiModelProperty(value = "Last check time")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private LocalDateTime lastCheckTime;
+
+ @ApiModelProperty(value = "Alert count")
+ private Integer alertCount;
+
+ @ApiModelProperty(value = "Source collection id")
+ private Long sourceCollectionId;
/**
* 棰勮鎻忚堪
*/
diff --git a/src/main/java/com/ruoyi/lims/service/AlertRecordService.java b/src/main/java/com/ruoyi/lims/service/AlertRecordService.java
new file mode 100644
index 0000000..401d775
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/AlertRecordService.java
@@ -0,0 +1,11 @@
+package com.ruoyi.lims.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.lims.pojo.AlertRecord;
+
+public interface AlertRecordService extends IService<AlertRecord> {
+ IPage<AlertRecord> listPage(Page<AlertRecord> page, AlertRecord query);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/service/CleanRuleService.java b/src/main/java/com/ruoyi/lims/service/CleanRuleService.java
new file mode 100644
index 0000000..52fa522
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/CleanRuleService.java
@@ -0,0 +1,11 @@
+package com.ruoyi.lims.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.lims.pojo.CleanRule;
+
+public interface CleanRuleService extends IService<CleanRule> {
+ IPage<CleanRule> listPage(Page<CleanRule> page, CleanRule query);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/service/CollectionVerifyService.java b/src/main/java/com/ruoyi/lims/service/CollectionVerifyService.java
new file mode 100644
index 0000000..449f4d7
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/CollectionVerifyService.java
@@ -0,0 +1,11 @@
+package com.ruoyi.lims.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.lims.pojo.CollectionVerify;
+
+public interface CollectionVerifyService extends IService<CollectionVerify> {
+ IPage<CollectionVerify> listPage(Page<CollectionVerify> page, CollectionVerify query);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/service/LimsAlertService.java b/src/main/java/com/ruoyi/lims/service/LimsAlertService.java
new file mode 100644
index 0000000..10743e2
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/LimsAlertService.java
@@ -0,0 +1,37 @@
+package com.ruoyi.lims.service;
+
+import java.util.Map;
+
+/**
+ * 瀹炴椂鐩戞帶棰勮鏈嶅姟
+ */
+public interface LimsAlertService {
+
+ /**
+ * 鍒ゅ畾鍗曚釜鐩戞帶椤规槸鍚﹁秺闄愶紝瓒婇檺鍒欑敓鎴愬憡璀﹁褰�
+ */
+ Map<String, Object> checkOne(Long monitorId);
+
+ /**
+ * 鎵弿鎵�鏈夌洃鎺ч」鍋氫竴娆″垽瀹氾紙瀹氭椂浠诲姟鐢級
+ *
+ * @param limit 鍗曟鏈�澶氬鐞嗘潯鏁�
+ */
+ Map<String, Object> checkAll(int limit);
+
+ /**
+ * 澶勭悊鍛婅锛堥棴鐜級
+ */
+ Map<String, Object> handleAlert(Long alertId, String status, String measure, String handler);
+
+ /**
+ * 鍛婅缁熻锛堝緟澶勭悊/澶勭悊涓�/宸插鐞�/鍚勭瓑绾э級
+ */
+ Map<String, Object> statistics();
+
+ /**
+ * 鎶婁竴鏉¢噰闆嗚褰曞悓姝ュ埌瀵瑰簲鐩戞帶椤瑰苟绔嬪嵆鍒ゅ畾
+ * 鍖归厤绛栫暐锛歮onitor_code = deviceCode锛屾垨 monitor_target = deviceName
+ */
+ Map<String, Object> syncFromCollection(Long collectionId);
+}
diff --git a/src/main/java/com/ruoyi/lims/service/LimsCleanService.java b/src/main/java/com/ruoyi/lims/service/LimsCleanService.java
new file mode 100644
index 0000000..3014edf
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/LimsCleanService.java
@@ -0,0 +1,29 @@
+package com.ruoyi.lims.service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 鏁版嵁娓呮礂涓庨獙璇佹湇鍔�
+ */
+public interface LimsCleanService {
+
+ /**
+ * 娓呮礂鍗曟潯閲囬泦璁板綍锛氭寜瑙勫垯鎵ц 绌哄��/鑼冨洿/寮傚父鍊�/閲嶅鍓旈櫎/鍗曚綅鎹㈢畻锛屽苟鍐欓獙璇佽褰�
+ *
+ * @return 澶勭悊缁撴灉锛屽惈 cleaned / discarded / failed / logs
+ */
+ Map<String, Object> cleanOne(Long collectionId);
+
+ /**
+ * 鎵归噺娓呮礂
+ */
+ Map<String, Object> cleanBatch(List<Long> collectionIds);
+
+ /**
+ * 娓呮礂鎵�鏈夊緟娓呮礂鐨勮褰曪紙瀹氭椂浠诲姟鐢級
+ *
+ * @param limit 鍗曟鏈�澶氬鐞嗘潯鏁�
+ */
+ Map<String, Object> cleanPending(int limit);
+}
diff --git a/src/main/java/com/ruoyi/lims/service/impl/AlertRecordServiceImpl.java b/src/main/java/com/ruoyi/lims/service/impl/AlertRecordServiceImpl.java
new file mode 100644
index 0000000..a0dc175
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/impl/AlertRecordServiceImpl.java
@@ -0,0 +1,38 @@
+package com.ruoyi.lims.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.lims.mapper.AlertRecordMapper;
+import com.ruoyi.lims.pojo.AlertRecord;
+import com.ruoyi.lims.service.AlertRecordService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class AlertRecordServiceImpl extends ServiceImpl<AlertRecordMapper, AlertRecord> implements AlertRecordService {
+
+ @Override
+ public IPage<AlertRecord> listPage(Page<AlertRecord> page, AlertRecord query) {
+ QueryWrapper<AlertRecord> wrapper = new QueryWrapper<>();
+ if (query != null) {
+ // ID filters
+ if (query.getMonitorId() != null) { wrapper.eq("monitor_id", query.getMonitorId()); }
+ wrapper.like(StringUtils.isNotEmpty(query.getMonitorCode()), "monitor_code", query.getMonitorCode());
+ wrapper.like(StringUtils.isNotEmpty(query.getMonitorTarget()), "monitor_target", query.getMonitorTarget());
+ wrapper.like(StringUtils.isNotEmpty(query.getMonitorType()), "monitor_type", query.getMonitorType());
+ wrapper.like(StringUtils.isNotEmpty(query.getAlertLevel()), "alert_level", query.getAlertLevel());
+ wrapper.like(StringUtils.isNotEmpty(query.getUnit()), "unit", query.getUnit());
+ wrapper.like(StringUtils.isNotEmpty(query.getAlertMessage()), "alert_message", query.getAlertMessage());
+ wrapper.like(StringUtils.isNotEmpty(query.getSource()), "source", query.getSource());
+ wrapper.like(StringUtils.isNotEmpty(query.getStatus()), "status", query.getStatus());
+ wrapper.like(StringUtils.isNotEmpty(query.getHandler()), "handler", query.getHandler());
+ wrapper.like(StringUtils.isNotEmpty(query.getHandleMeasure()), "handle_measure", query.getHandleMeasure());
+ }
+ wrapper.orderByDesc("id");
+ return baseMapper.selectPage(page, wrapper);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/service/impl/CleanRuleServiceImpl.java b/src/main/java/com/ruoyi/lims/service/impl/CleanRuleServiceImpl.java
new file mode 100644
index 0000000..00b650d
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/impl/CleanRuleServiceImpl.java
@@ -0,0 +1,37 @@
+package com.ruoyi.lims.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.lims.mapper.CleanRuleMapper;
+import com.ruoyi.lims.pojo.CleanRule;
+import com.ruoyi.lims.service.CleanRuleService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class CleanRuleServiceImpl extends ServiceImpl<CleanRuleMapper, CleanRule> implements CleanRuleService {
+
+ @Override
+ public IPage<CleanRule> listPage(Page<CleanRule> page, CleanRule query) {
+ QueryWrapper<CleanRule> wrapper = new QueryWrapper<>();
+ if (query != null) {
+ // ID filters
+ if (query.getInterfaceId() != null) { wrapper.eq("interface_id", query.getInterfaceId()); }
+ wrapper.like(StringUtils.isNotEmpty(query.getInterfaceCode()), "interface_code", query.getInterfaceCode());
+ wrapper.like(StringUtils.isNotEmpty(query.getRuleName()), "rule_name", query.getRuleName());
+ wrapper.like(StringUtils.isNotEmpty(query.getRuleType()), "rule_type", query.getRuleType());
+ wrapper.like(StringUtils.isNotEmpty(query.getTargetField()), "target_field", query.getTargetField());
+ wrapper.like(StringUtils.isNotEmpty(query.getConditionExpr()), "condition_expr", query.getConditionExpr());
+ wrapper.like(StringUtils.isNotEmpty(query.getActionType()), "action_type", query.getActionType());
+ wrapper.like(StringUtils.isNotEmpty(query.getActionValue()), "action_value", query.getActionValue());
+ wrapper.like(StringUtils.isNotEmpty(query.getEnabled()), "enabled", query.getEnabled());
+ wrapper.like(StringUtils.isNotEmpty(query.getRemark()), "remark", query.getRemark());
+ }
+ wrapper.orderByDesc("id");
+ return baseMapper.selectPage(page, wrapper);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/service/impl/CollectionVerifyServiceImpl.java b/src/main/java/com/ruoyi/lims/service/impl/CollectionVerifyServiceImpl.java
new file mode 100644
index 0000000..1853835
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/impl/CollectionVerifyServiceImpl.java
@@ -0,0 +1,36 @@
+package com.ruoyi.lims.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.lims.mapper.CollectionVerifyMapper;
+import com.ruoyi.lims.pojo.CollectionVerify;
+import com.ruoyi.lims.service.CollectionVerifyService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional(rollbackFor = Exception.class)
+public class CollectionVerifyServiceImpl extends ServiceImpl<CollectionVerifyMapper, CollectionVerify> implements CollectionVerifyService {
+
+ @Override
+ public IPage<CollectionVerify> listPage(Page<CollectionVerify> page, CollectionVerify query) {
+ QueryWrapper<CollectionVerify> wrapper = new QueryWrapper<>();
+ if (query != null) {
+ // ID filters
+ if (query.getCollectionId() != null) { wrapper.eq("collection_id", query.getCollectionId()); }
+ if (query.getRuleId() != null) { wrapper.eq("rule_id", query.getRuleId()); }
+ wrapper.like(StringUtils.isNotEmpty(query.getCollectionCode()), "collection_code", query.getCollectionCode());
+ wrapper.like(StringUtils.isNotEmpty(query.getRuleName()), "rule_name", query.getRuleName());
+ wrapper.like(StringUtils.isNotEmpty(query.getRuleType()), "rule_type", query.getRuleType());
+ wrapper.like(StringUtils.isNotEmpty(query.getPassed()), "passed", query.getPassed());
+ wrapper.like(StringUtils.isNotEmpty(query.getExpected()), "expected", query.getExpected());
+ wrapper.like(StringUtils.isNotEmpty(query.getActual()), "actual", query.getActual());
+ wrapper.like(StringUtils.isNotEmpty(query.getMessage()), "message", query.getMessage());
+ }
+ wrapper.orderByDesc("id");
+ return baseMapper.selectPage(page, wrapper);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/lims/service/impl/DataInterfaceServiceImpl.java b/src/main/java/com/ruoyi/lims/service/impl/DataInterfaceServiceImpl.java
index dc227a2..78918e2 100644
--- a/src/main/java/com/ruoyi/lims/service/impl/DataInterfaceServiceImpl.java
+++ b/src/main/java/com/ruoyi/lims/service/impl/DataInterfaceServiceImpl.java
@@ -13,6 +13,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@Service
@RequiredArgsConstructor
diff --git a/src/main/java/com/ruoyi/lims/service/impl/LimsAlertServiceImpl.java b/src/main/java/com/ruoyi/lims/service/impl/LimsAlertServiceImpl.java
new file mode 100644
index 0000000..7fcafd2
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/impl/LimsAlertServiceImpl.java
@@ -0,0 +1,279 @@
+package com.ruoyi.lims.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.lims.pojo.AlertRecord;
+import com.ruoyi.lims.pojo.DataCollection;
+import com.ruoyi.lims.pojo.RealtimeMonitor;
+import com.ruoyi.lims.service.AlertRecordService;
+import com.ruoyi.lims.service.DataCollectionService;
+import com.ruoyi.lims.service.LimsAlertService;
+import com.ruoyi.lims.service.RealtimeMonitorService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@RequiredArgsConstructor
+@Transactional(rollbackFor = Exception.class)
+public class LimsAlertServiceImpl implements LimsAlertService {
+
+ private final RealtimeMonitorService monitorService;
+ private final AlertRecordService alertService;
+ private final DataCollectionService collectionService;
+
+ @Override
+ public Map<String, Object> checkOne(Long monitorId) {
+ Map<String, Object> ret = blank();
+ if (monitorId == null) {
+ ret.put("message", "monitorId 涓嶈兘涓虹┖");
+ return ret;
+ }
+ RealtimeMonitor m = monitorService.getById(monitorId);
+ if (m == null) {
+ ret.put("message", "鐩戞帶椤逛笉瀛樺湪");
+ return ret;
+ }
+ doCheck(m, ret, "manual");
+ return ret;
+ }
+
+ @Override
+ public Map<String, Object> checkAll(int limit) {
+ QueryWrapper<RealtimeMonitor> w = new QueryWrapper<>();
+ w.and(x -> x.ne("alert_status", "resolved").or().isNull("alert_status"));
+ w.orderByAsc("id");
+ w.last("limit " + Math.max(1, limit));
+ List<RealtimeMonitor> list = monitorService.list(w);
+ Map<String, Object> ret = blank();
+ ret.put("scanned", list.size());
+ for (RealtimeMonitor m : list) {
+ doCheck(m, ret, "auto");
+ }
+ return ret;
+ }
+
+ @Override
+ public Map<String, Object> handleAlert(Long alertId, String status, String measure, String handler) {
+ Map<String, Object> ret = blank();
+ if (alertId == null) {
+ ret.put("message", "alertId 涓嶈兘涓虹┖");
+ return ret;
+ }
+ AlertRecord a = alertService.getById(alertId);
+ if (a == null) {
+ ret.put("message", "鍛婅璁板綍涓嶅瓨鍦�");
+ return ret;
+ }
+ String st = status == null || status.trim().isEmpty() ? "resolved" : status.trim();
+ AlertRecord upd = new AlertRecord();
+ upd.setId(alertId);
+ upd.setStatus(st);
+ upd.setHandleMeasure(measure);
+ upd.setHandler(handler == null || handler.trim().isEmpty() ? "system" : handler.trim());
+ upd.setHandleTime(LocalDateTime.now());
+ alertService.updateById(upd);
+
+ // 宸插鐞�/宸插拷鐣ユ椂锛屾妸鐩戞帶椤圭姸鎬佹仮澶嶄负姝e父
+ if ("resolved".equals(st) || "ignored".equals(st)) {
+ RealtimeMonitor mu = new RealtimeMonitor();
+ mu.setId(a.getMonitorId());
+ mu.setAlertStatus("resolved".equals(st) ? "normal" : "resolved");
+ monitorService.updateById(mu);
+ }
+ ret.put("handled", 1);
+ ret.put("message", "鍛婅宸�" + ("resolved".equals(st) ? "澶勭悊" : "鏇存柊"));
+ return ret;
+ }
+
+ @Override
+ public Map<String, Object> statistics() {
+ Map<String, Object> ret = new LinkedHashMap<>();
+ ret.put("pending", countByStatus("pending"));
+ ret.put("handling", countByStatus("handling"));
+ ret.put("resolved", countByStatus("resolved"));
+ ret.put("ignored", countByStatus("ignored"));
+ ret.put("levelHigh", countByLevel("high"));
+ ret.put("levelMedium", countByLevel("medium"));
+ ret.put("levelLow", countByLevel("low"));
+ ret.put("total", alertService.count());
+ return ret;
+ }
+
+ @Override
+ public Map<String, Object> syncFromCollection(Long collectionId) {
+ Map<String, Object> ret = blank();
+ if (collectionId == null) {
+ ret.put("message", "collectionId 涓嶈兘涓虹┖");
+ return ret;
+ }
+ DataCollection dc = collectionService.getById(collectionId);
+ if (dc == null) {
+ ret.put("message", "閲囬泦璁板綍涓嶅瓨鍦�");
+ return ret;
+ }
+ if (dc.getCollectionValue() == null) {
+ ret.put("message", "璇ラ噰闆嗚褰曟病鏈夋暟鍊硷紝鏃犳硶鍚屾");
+ return ret;
+ }
+
+ // 鎸� deviceCode == monitorCode锛屾垨 deviceName == monitorTarget 鍖归厤
+ QueryWrapper<RealtimeMonitor> w = new QueryWrapper<>();
+ w.and(x -> x.eq("monitor_code", dc.getDeviceCode())
+ .or()
+ .eq("monitor_target", dc.getDeviceName()));
+ w.orderByAsc("id");
+ w.last("limit 1");
+ RealtimeMonitor m = monitorService.getOne(w, false);
+ if (m == null) {
+ ret.put("message", "鏈壘鍒板尮閰嶇殑鐩戞帶椤癸紙monitorCode=" + dc.getDeviceCode()
+ + " 鎴� monitorTarget=" + dc.getDeviceName() + "锛�");
+ return ret;
+ }
+
+ RealtimeMonitor upd = new RealtimeMonitor();
+ upd.setId(m.getId());
+ upd.setCurrentValue(dc.getCollectionValue());
+ if (dc.getUnit() != null) upd.setUnit(dc.getUnit());
+ upd.setMonitorTime(dc.getCollectionTime() == null ? LocalDateTime.now() : dc.getCollectionTime());
+ upd.setSourceCollectionId(dc.getId());
+ monitorService.updateById(upd);
+
+ m.setCurrentValue(dc.getCollectionValue());
+ if (dc.getUnit() != null) m.setUnit(dc.getUnit());
+ m.setMonitorTime(upd.getMonitorTime());
+
+ ret.put("monitorId", m.getId());
+ ret.put("monitorTarget", m.getMonitorTarget());
+ doCheck(m, ret, "collect");
+ return ret;
+ }
+
+ /* ==================== 鏍稿績鍒ゅ畾 ==================== */
+
+ private void doCheck(RealtimeMonitor m, Map<String, Object> ret, String source) {
+ LocalDateTime now = LocalDateTime.now();
+ BigDecimal v = m.getCurrentValue();
+
+ // 鏃犲綋鍓嶅�硷細鍙褰曞垽瀹氭椂闂达紝涓嶄骇鐢熷憡璀�
+ if (v == null) {
+ RealtimeMonitor u = new RealtimeMonitor();
+ u.setId(m.getId());
+ u.setLastCheckTime(now);
+ monitorService.updateById(u);
+ ret.put("noValue", (Integer) ret.get("noValue") + 1);
+ return;
+ }
+
+ BigDecimal up = m.getUpperLimit();
+ BigDecimal lo = m.getLowerLimit();
+ boolean overUp = up != null && v.compareTo(up) > 0;
+ boolean underLo = lo != null && v.compareTo(lo) < 0;
+ boolean abnormal = overUp || underLo;
+
+ // 宸叉湁鏈鐞嗗憡璀︽椂涓嶉噸澶嶇敓鎴愶紝閬垮厤鍒峰睆
+ long openAlerts = 0;
+ QueryWrapper<AlertRecord> aw = new QueryWrapper<>();
+ aw.eq("monitor_id", m.getId()).in("status", "pending", "handling");
+ openAlerts = alertService.count(aw);
+
+ RealtimeMonitor upd = new RealtimeMonitor();
+ upd.setId(m.getId());
+ upd.setLastCheckTime(now);
+
+ if (abnormal) {
+ String level = resolveLevel(overUp, underLo, m.getAlertLevel());
+ String msg = buildMsg(m, v, up, lo, overUp, underLo);
+ upd.setAlertStatus(overUp || underLo ? "alert" : "warning");
+ upd.setAlertLevel(level);
+ if (openAlerts == 0) {
+ AlertRecord a = new AlertRecord();
+ a.setMonitorId(m.getId());
+ a.setMonitorCode(m.getMonitorCode());
+ a.setMonitorTarget(m.getMonitorTarget());
+ a.setMonitorType(m.getMonitorType());
+ a.setAlertLevel(level);
+ a.setAlertValue(v);
+ a.setUnit(m.getUnit());
+ a.setUpperLimit(up);
+ a.setLowerLimit(lo);
+ a.setAlertMessage(msg);
+ a.setSource(source);
+ a.setStatus("pending");
+ a.setAlertTime(now);
+ alertService.save(a);
+ upd.setAlertCount((m.getAlertCount() == null ? 0 : m.getAlertCount()) + 1);
+ ret.put("alerts", (Integer) ret.get("alerts") + 1);
+ } else {
+ ret.put("suppressed", (Integer) ret.get("suppressed") + 1);
+ }
+ } else {
+ // 姝e父锛氬鏋滀箣鍓嶆湁鍛婅浣嗗凡鎭㈠锛岀疆涓� resolved
+ if (openAlerts > 0) {
+ upd.setAlertStatus("resolved");
+ } else {
+ upd.setAlertStatus("normal");
+ }
+ ret.put("normal", (Integer) ret.get("normal") + 1);
+ }
+
+ monitorService.updateById(upd);
+ }
+
+ private String resolveLevel(boolean overUp, boolean underLo, String configured) {
+ // 瓒婇檺骞呭害鍐冲畾绾у埆锛氳秴杩囦笂闄�/涓嬮檺 20% 浠ヤ笂绠� high
+ if (configured != null && !configured.trim().isEmpty()) {
+ String c = configured.trim().toLowerCase();
+ if (c.equals("high") || c.equals("medium") || c.equals("low")) return c;
+ }
+ return overUp ? "high" : "medium";
+ }
+
+ private String buildMsg(RealtimeMonitor m, BigDecimal v, BigDecimal up, BigDecimal lo,
+ boolean overUp, boolean underLo) {
+ String unit = m.getUnit() == null ? "" : m.getUnit();
+ StringBuilder sb = new StringBuilder();
+ sb.append("鐩戞帶椤广��").append(m.getMonitorTarget() == null ? m.getMonitorCode() : m.getMonitorTarget())
+ .append("銆嶅綋鍓嶅�� ").append(v.stripTrailingZeros().toPlainString()).append(unit);
+ if (overUp && up != null) {
+ sb.append("锛岃秴鍑轰笂闄� ").append(up.stripTrailingZeros().toPlainString()).append(unit);
+ BigDecimal diff = v.subtract(up);
+ if (up.compareTo(BigDecimal.ZERO) != 0) {
+ BigDecimal pct = diff.multiply(new BigDecimal("100"))
+ .divide(up.abs(), 2, BigDecimal.ROUND_HALF_UP);
+ sb.append("锛堣秴鍑� ").append(pct.stripTrailingZeros().toPlainString()).append("%锛�");
+ }
+ }
+ if (underLo && lo != null) {
+ sb.append("锛屼綆浜庝笅闄� ").append(lo.stripTrailingZeros().toPlainString()).append(unit);
+ }
+ return sb.toString();
+ }
+
+ private long countByStatus(String status) {
+ QueryWrapper<AlertRecord> w = new QueryWrapper<>();
+ w.eq("status", status);
+ return alertService.count(w);
+ }
+
+ private long countByLevel(String level) {
+ QueryWrapper<AlertRecord> w = new QueryWrapper<>();
+ w.eq("alert_level", level).in("status", "pending", "handling");
+ return alertService.count(w);
+ }
+
+ private Map<String, Object> blank() {
+ Map<String, Object> m = new LinkedHashMap<>();
+ m.put("scanned", 0);
+ m.put("alerts", 0);
+ m.put("normal", 0);
+ m.put("noValue", 0);
+ m.put("suppressed", 0);
+ return m;
+ }
+}
diff --git a/src/main/java/com/ruoyi/lims/service/impl/LimsCleanServiceImpl.java b/src/main/java/com/ruoyi/lims/service/impl/LimsCleanServiceImpl.java
new file mode 100644
index 0000000..7ee20bb
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/impl/LimsCleanServiceImpl.java
@@ -0,0 +1,322 @@
+package com.ruoyi.lims.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.lims.pojo.CleanRule;
+import com.ruoyi.lims.pojo.CollectionVerify;
+import com.ruoyi.lims.pojo.DataCollection;
+import com.ruoyi.lims.service.CleanRuleService;
+import com.ruoyi.lims.service.CollectionVerifyService;
+import com.ruoyi.lims.service.DataCollectionService;
+import com.ruoyi.lims.service.LimsCleanService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@RequiredArgsConstructor
+@Transactional(rollbackFor = Exception.class)
+public class LimsCleanServiceImpl implements LimsCleanService {
+
+ private final DataCollectionService collectionService;
+ private final CleanRuleService ruleService;
+ private final CollectionVerifyService verifyService;
+
+ @Override
+ public Map<String, Object> cleanOne(Long collectionId) {
+ Map<String, Object> ret = blankResult();
+ if (collectionId == null) {
+ ret.put("message", "collectionId 涓嶈兘涓虹┖");
+ return ret;
+ }
+ DataCollection dc = collectionService.getById(collectionId);
+ if (dc == null) {
+ ret.put("message", "閲囬泦璁板綍涓嶅瓨鍦�");
+ return ret;
+ }
+ doClean(dc, ret);
+ return ret;
+ }
+
+ @Override
+ public Map<String, Object> cleanBatch(List<Long> collectionIds) {
+ Map<String, Object> ret = blankResult();
+ if (collectionIds == null || collectionIds.isEmpty()) {
+ ret.put("message", "璇蜂紶鍏ヨ娓呮礂鐨勮褰旾D");
+ return ret;
+ }
+ for (Long id : collectionIds) {
+ DataCollection dc = collectionService.getById(id);
+ if (dc == null) continue;
+ doClean(dc, ret);
+ }
+ return ret;
+ }
+
+ @Override
+ public Map<String, Object> cleanPending(int limit) {
+ QueryWrapper<DataCollection> w = new QueryWrapper<>();
+ w.and(x -> x.eq("clean_status", "pending").or().isNull("clean_status"))
+ .orderByAsc("id");
+ w.last("limit " + Math.max(1, limit));
+ List<DataCollection> list = collectionService.list(w);
+
+ Map<String, Object> ret = blankResult();
+ ret.put("scanned", list.size());
+ for (DataCollection dc : list) {
+ doClean(dc, ret);
+ }
+ return ret;
+ }
+
+ /* ==================== 鏍稿績娓呮礂閫昏緫 ==================== */
+
+ private void doClean(DataCollection dc, Map<String, Object> ret) {
+ ret.put("scanned", (Integer) ret.get("scanned") + 1);
+
+ List<CleanRule> rules = loadRules(dc);
+ List<String> logs = new ArrayList<>();
+ boolean discarded = false;
+ String verifyStatus = "passed";
+ List<String> verifyMsgs = new ArrayList<>();
+
+ // 閲嶅鍓旈櫎瑙勫垯锛氬悓璁惧鍚岀被鍨嬫渶杩� 5 鍒嗛挓鍐呭凡鏈夌浉鍚屾暟鍊�
+ boolean needDupCheck = rules.stream().anyMatch(r -> "duplicate".equalsIgnoreCase(r.getRuleType()));
+
+ for (CleanRule r : rules) {
+ if (discarded) break;
+ String type = lower(r.getRuleType());
+ String expr = r.getConditionExpr() == null ? "" : r.getConditionExpr().trim();
+ String action = lower(r.getActionType());
+ String actionVal = r.getActionValue();
+
+ try {
+ switch (type) {
+ case "empty": {
+ if (dc.getCollectionValue() == null) {
+ logs.add("[" + r.getRuleName() + "] 閲囬泦鏁板�间负绌�");
+ if ("discard".equals(action)) {
+ discarded = true;
+ } else if ("replace".equals(action) && actionVal != null) {
+ dc.setCollectionValue(new BigDecimal(actionVal));
+ logs.add(" 鈫� 鏇挎崲涓� " + actionVal);
+ } else {
+ logs.add(" 鈫� 浠呮爣璁�");
+ }
+ }
+ break;
+ }
+ case "range": {
+ if (dc.getCollectionValue() == null) break;
+ String[] bounds = parseRange(expr);
+ if (bounds == null) break;
+ BigDecimal lo = bounds[0] == null ? null : new BigDecimal(bounds[0]);
+ BigDecimal hi = bounds[1] == null ? null : new BigDecimal(bounds[1]);
+ BigDecimal v = dc.getCollectionValue();
+ boolean out = (lo != null && v.compareTo(lo) < 0) || (hi != null && v.compareTo(hi) > 0);
+ if (!out) break;
+
+ logs.add("[" + r.getRuleName() + "] 鏁板�� " + v.stripTrailingZeros().toPlainString()
+ + " 瓒呭嚭鑼冨洿 " + expr);
+ if ("discard".equals(action)) {
+ discarded = true;
+ } else if ("clamp".equals(action)) {
+ BigDecimal nv = v;
+ if (lo != null && v.compareTo(lo) < 0) nv = lo;
+ if (hi != null && v.compareTo(hi) > 0) nv = hi;
+ dc.setCollectionValue(nv);
+ logs.add(" 鈫� 鎴柇涓� " + nv.stripTrailingZeros().toPlainString());
+ } else if ("replace".equals(action) && actionVal != null) {
+ dc.setCollectionValue(new BigDecimal(actionVal));
+ logs.add(" 鈫� 鏇挎崲涓� " + actionVal);
+ } else {
+ logs.add(" 鈫� 浠呮爣璁�");
+ }
+ // 鑼冨洿涓嶉�氳繃涔熻涓�鏉¢獙璇佽褰�
+ verifyStatus = "failed";
+ verifyMsgs.add(r.getRuleName() + "锛氭暟鍊� " + v.stripTrailingZeros().toPlainString() + " 瓒呭嚭鑼冨洿 " + expr);
+ writeVerify(dc, r, false, expr, v.stripTrailingZeros().toPlainString(),
+ "瓒呭嚭鍏佽鑼冨洿");
+ break;
+ }
+ case "outlier": {
+ if (dc.getCollectionValue() == null) break;
+ String[] bounds = parseRange(expr);
+ if (bounds == null) break;
+ BigDecimal lo = bounds[0] == null ? null : new BigDecimal(bounds[0]);
+ BigDecimal hi = bounds[1] == null ? null : new BigDecimal(bounds[1]);
+ BigDecimal v = dc.getCollectionValue();
+ boolean out = (lo != null && v.compareTo(lo) < 0) || (hi != null && v.compareTo(hi) > 0);
+ if (!out) break;
+ logs.add("[" + r.getRuleName() + "] 鐤戜技寮傚父鍊� " + v.stripTrailingZeros().toPlainString());
+ if ("discard".equals(action)) {
+ discarded = true;
+ } else if ("replace".equals(action) && actionVal != null) {
+ dc.setCollectionValue(new BigDecimal(actionVal));
+ logs.add(" 鈫� 鏇挎崲涓� " + actionVal);
+ }
+ // 寮傚父鍊煎彧鏍囪锛屼笉绠楅獙璇佷笉閫氳繃
+ break;
+ }
+ case "duplicate": {
+ if (!needDupCheck || dc.getCollectionValue() == null) break;
+ QueryWrapper<DataCollection> dw = new QueryWrapper<>();
+ dw.eq("device_code", dc.getDeviceCode())
+ .eq("collection_value", dc.getCollectionValue())
+ .ne("id", dc.getId())
+ .ge("collection_time", dc.getCollectionTime() == null
+ ? LocalDateTime.now().minusMinutes(5) : dc.getCollectionTime().minusMinutes(5));
+ long same = collectionService.count(dw);
+ if (same > 0) {
+ logs.add("[" + r.getRuleName() + "] 5 鍒嗛挓鍐呭嚭鐜� " + same + " 鏉$浉鍚屾暟鍊硷紝鍒ゅ畾閲嶅");
+ if ("discard".equals(action)) {
+ discarded = true;
+ }
+ }
+ break;
+ }
+ case "unit": {
+ // 鍗曚綅鎹㈢畻锛歛ctionValue 褰㈠ "mL>L:0.001"
+ if (actionVal == null || !actionVal.contains(":")) break;
+ String[] kv = actionVal.split(":", 2);
+ if (kv[0].equals(dc.getUnit()) && dc.getCollectionValue() != null) {
+ BigDecimal rate = new BigDecimal(kv[1].trim());
+ BigDecimal nv = dc.getCollectionValue().multiply(rate).setScale(6, RoundingMode.HALF_UP);
+ String toUnit = kv[0].contains(">") ? kv[0].substring(kv[0].indexOf('>') + 1) : dc.getUnit();
+ logs.add("[" + r.getRuleName() + "] 鍗曚綅鎹㈢畻 "
+ + dc.getCollectionValue().stripTrailingZeros().toPlainString()
+ + " " + dc.getUnit() + " 鈫� "
+ + nv.stripTrailingZeros().toPlainString() + " " + toUnit);
+ dc.setCollectionValue(nv);
+ dc.setUnit(toUnit);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ } catch (Exception e) {
+ logs.add("[" + r.getRuleName() + "] 鎵ц寮傚父锛�" + e.getMessage());
+ }
+ }
+
+ // 鍐欏洖
+ DataCollection upd = new DataCollection();
+ upd.setId(dc.getId());
+ upd.setCollectionValue(dc.getCollectionValue());
+ upd.setUnit(dc.getUnit());
+ if (discarded) {
+ upd.setCleanStatus("discarded");
+ upd.setVerifyStatus("failed");
+ upd.setVerifyMsg("鎸夎鍒欎涪寮冿細" + String.join("锛�", logs));
+ ret.put("discarded", (Integer) ret.get("discarded") + 1);
+ } else {
+ upd.setCleanStatus(logs.isEmpty() ? "cleaned" : "cleaned");
+ upd.setCleanLog(logs.isEmpty() ? "鏃犺鍒欏懡涓�" : String.join("\n", logs));
+ upd.setVerifyStatus(verifyStatus);
+ upd.setVerifyMsg(verifyMsgs.isEmpty() ? null : String.join("锛�", verifyMsgs));
+ ret.put("cleaned", (Integer) ret.get("cleaned") + 1);
+ }
+ if (verifyStatus.equals("failed")) {
+ ret.put("verifyFailed", (Integer) ret.get("verifyFailed") + 1);
+ }
+ try {
+ collectionService.updateById(upd);
+ } catch (Exception e) {
+ ret.put("failed", (Integer) ret.get("failed") + 1);
+ ret.put("message", "鍐欏洖澶辫触锛�" + e.getMessage());
+ }
+ }
+
+ /**
+ * 鍔犺浇閫傜敤瑙勫垯锛氭帴鍙d笓灞炶鍒� + 鍏ㄥ眬瑙勫垯锛屾寜 priority 鍗囧簭銆�
+ *
+ * 娉ㄦ剰锛氭竻娲楄鍒欐槸銆屽叏灞�閰嶇疆銆嶏紝涓嶅簲璇ュ彈澶氱鎴疯繃婊ゅ奖鍝嶏紙tenant_id 涓� NULL 鐨勮鍒欏睘浜庡叏灞�锛夛紝
+ * 鎵�浠ヨ繖閲屼复鏃惰烦杩囩鎴锋彃浠讹紝鍚﹀垯棰勭疆鐨勫叏灞�瑙勫垯浼氳鑷姩鍔犱笂鐨� tenant_id 鏉′欢杩囨护鎺夈��
+ */
+ private List<CleanRule> loadRules(DataCollection dc) {
+ QueryWrapper<CleanRule> w = new QueryWrapper<>();
+ w.eq("enabled", "1");
+ w.orderByAsc("priority").orderByAsc("id");
+
+ com.ruoyi.common.handler.CustomTenantLineHandler.TEMP_IGNORE.set(Boolean.TRUE);
+ try {
+ return ruleService.list(w);
+ } finally {
+ com.ruoyi.common.handler.CustomTenantLineHandler.TEMP_IGNORE.remove();
+ }
+ }
+
+ /**
+ * 瑙f瀽鏉′欢琛ㄨ揪寮忥細鏀寔 "<0"銆�">1000"銆�"0~100"銆�"<0 鎴� >1000"
+ * 杩斿洖 [lo, hi]锛屼换涓�绔负 null 琛ㄧず涓嶉檺
+ */
+ private String[] parseRange(String expr) {
+ if (expr == null || expr.trim().isEmpty()) return null;
+ String e = expr.replace(" ", "");
+ // 褰㈠ 0~100
+ if (e.contains("~")) {
+ String[] p = e.split("~");
+ if (p.length == 2) return new String[]{p[0], p[1]};
+ return null;
+ }
+ // 褰㈠ <0 鎴� >1000
+ e = e.replace("鎴�", "|").replace("and", "|").replace("&", "|");
+ if (e.contains("|")) {
+ String[] segs = e.split("\\|");
+ String lo = null, hi = null;
+ for (String s : segs) {
+ if (s.startsWith("<=")) lo = s.substring(2);
+ else if (s.startsWith("<")) lo = s.substring(1);
+ else if (s.startsWith(">=")) hi = s.substring(2);
+ else if (s.startsWith(">")) hi = s.substring(1);
+ }
+ if (lo == null && hi == null) return null;
+ return new String[]{lo, hi};
+ }
+ if (e.startsWith("<=")) return new String[]{e.substring(2), null};
+ if (e.startsWith("<")) return new String[]{e.substring(1), null};
+ if (e.startsWith(">=")) return new String[]{null, e.substring(2)};
+ if (e.startsWith(">")) return new String[]{null, e.substring(1)};
+ return null;
+ }
+
+ private void writeVerify(DataCollection dc, CleanRule r, boolean passed, String expected, String actual, String msg) {
+ try {
+ CollectionVerify v = new CollectionVerify();
+ v.setCollectionId(dc.getId());
+ v.setCollectionCode(dc.getCollectionCode());
+ v.setRuleId(r.getId());
+ v.setRuleName(r.getRuleName());
+ v.setRuleType(r.getRuleType());
+ v.setPassed(passed ? "1" : "0");
+ v.setExpected(expected);
+ v.setActual(actual);
+ v.setMessage(msg);
+ v.setVerifyTime(LocalDateTime.now());
+ verifyService.save(v);
+ } catch (Exception ignore) {
+ }
+ }
+
+ private Map<String, Object> blankResult() {
+ Map<String, Object> m = new LinkedHashMap<>();
+ m.put("scanned", 0);
+ m.put("cleaned", 0);
+ m.put("discarded", 0);
+ m.put("verifyFailed", 0);
+ m.put("failed", 0);
+ return m;
+ }
+
+ private static String lower(String s) {
+ return s == null ? null : s.trim().toLowerCase();
+ }
+}
diff --git a/src/main/java/com/ruoyi/lims/service/impl/LimsTaskService.java b/src/main/java/com/ruoyi/lims/service/impl/LimsTaskService.java
new file mode 100644
index 0000000..fc9c19b
--- /dev/null
+++ b/src/main/java/com/ruoyi/lims/service/impl/LimsTaskService.java
@@ -0,0 +1,141 @@
+package com.ruoyi.lims.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.lims.controller.DataInterfaceController;
+import com.ruoyi.lims.pojo.DataInterface;
+import com.ruoyi.lims.service.DataInterfaceService;
+import com.ruoyi.lims.service.LimsAlertService;
+import com.ruoyi.lims.service.LimsCleanService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * LIMS 瀹氭椂浠诲姟鍏ュ彛
+ *
+ * 鍦ㄣ�岀郴缁熺洃鎺� 鈫� 瀹氭椂浠诲姟銆嶉噷閰嶇疆锛坈ron 琛ㄨ揪寮忓啓鍦� sys_job 琛ㄩ噷锛屼笉瑕佸啓杩涙敞閲婏紝鍚﹀垯鏂滄潬鏄熷彿浼氭彁鍓嶇粨鏉熸敞閲婏級锛�
+ * limsTask.autoCollect 鑷姩閲囬泦锛屽缓璁懆鏈� 5 鍒嗛挓
+ * limsTask.checkAlerts 鐩戞帶棰勮鎵弿锛屽缓璁懆鏈� 1 鍒嗛挓
+ */
+@Service("limsTask")
+@Slf4j
+public class LimsTaskService {
+
+ private final DataInterfaceService diService;
+ private final LimsCleanService cleanService;
+ private final LimsAlertService alertService;
+ private final ObjectProvider<DataInterfaceController> controllerProvider;
+
+ public LimsTaskService(DataInterfaceService diService,
+ LimsCleanService cleanService,
+ LimsAlertService alertService,
+ ObjectProvider<DataInterfaceController> controllerProvider) {
+ this.diService = diService;
+ this.cleanService = cleanService;
+ this.alertService = alertService;
+ this.controllerProvider = controllerProvider;
+ }
+
+ /**
+ * 鑷姩閲囬泦锛氭壂鎻忓惎鐢ㄨ嚜鍔ㄩ噰闆嗙殑鎺ュ彛锛岄�愪釜閲囬泦骞舵竻娲�
+ */
+ public void autoCollect() {
+ QueryWrapper<DataInterface> w = new QueryWrapper<>();
+ w.eq("auto_enabled", "1").orderByAsc("id");
+ List<DataInterface> list = diService.list(w);
+ if (list.isEmpty()) {
+ log.info("[LIMS鑷姩閲囬泦] 娌℃湁鍚敤鑷姩閲囬泦鐨勬帴鍙�");
+ return;
+ }
+ DataInterfaceController ctl = controllerProvider.getIfAvailable();
+ if (ctl == null) {
+ log.warn("[LIMS鑷姩閲囬泦] 閲囬泦鍣ㄦ湭灏辩华锛岃烦杩�");
+ return;
+ }
+
+ int okCount = 0, failCount = 0;
+ for (DataInterface di : list) {
+ String cron = di.getCollectCron();
+ if (cron == null || cron.trim().isEmpty()) {
+ // 鍙紑浜嗗紑鍏虫病閰� cron锛屾寜"姣忔浠诲姟閮介噰闆�"澶勭悊
+ log.debug("[LIMS鑷姩閲囬泦] {} 鏈厤缃� cron锛屾寜浠诲姟鍛ㄦ湡閲囬泦", di.getInterfaceCode());
+ }
+ try {
+ Map<String, Object> r = ctl.collectInternal(di.getId(), "auto");
+ boolean ok = Boolean.TRUE.equals(r.get("ok"));
+ String msg = String.valueOf(r.get("msg"));
+ saveResult(di.getId(), ok, msg);
+ if (ok) {
+ okCount++;
+ } else {
+ failCount++;
+ }
+ log.info("[LIMS鑷姩閲囬泦] {} -> {}", di.getInterfaceCode(), ok ? "鎴愬姛" : ("澶辫触锛�" + msg));
+ } catch (Exception e) {
+ failCount++;
+ saveResult(di.getId(), false, "寮傚父锛�" + e.getMessage());
+ log.error("[LIMS鑷姩閲囬泦] {} 寮傚父", di.getInterfaceCode(), e);
+ }
+ }
+ log.info("[LIMS鑷姩閲囬泦] 瀹屾垚锛屾垚鍔� {} 涓紝澶辫触 {} 涓�", okCount, failCount);
+
+ // 鍏滃簳锛氬啀娓呮礂涓�閬嶆墍鏈夊緟娓呮礂璁板綍
+ try {
+ Map<String, Object> cr = cleanService.cleanPending(200);
+ log.info("[LIMS鑷姩閲囬泦] 鍏滃簳娓呮礂锛歿}", cr);
+ } catch (Exception e) {
+ log.warn("[LIMS鑷姩閲囬泦] 鍏滃簳娓呮礂澶辫触", e);
+ }
+ }
+
+ /**
+ * 鐩戞帶棰勮锛氬厛娓呮礂寰呭鐞嗘暟鎹紝鍐嶆壂鎻忔墍鏈夌洃鎺ч」鍒ゅ畾瓒婇檺
+ */
+ public void checkAlerts() {
+ // 1. 娓呮礂
+ try {
+ Map<String, Object> cr = cleanService.cleanPending(200);
+ Integer cleaned = (Integer) cr.get("cleaned");
+ if (cleaned != null && cleaned > 0) {
+ log.info("[LIMS鐩戞帶棰勮] 娓呮礂 {} 鏉�", cleaned);
+ }
+ } catch (Exception e) {
+ log.warn("[LIMS鐩戞帶棰勮] 娓呮礂澶辫触", e);
+ }
+
+ // 2. 鍒ゅ畾
+ try {
+ Map<String, Object> r = alertService.checkAll(500);
+ Integer alerts = (Integer) r.get("alerts");
+ Integer scanned = (Integer) r.get("scanned");
+ if (alerts != null && alerts > 0) {
+ log.warn("[LIMS鐩戞帶棰勮] 鎵弿 {} 涓洃鎺ч」锛屾柊澧炲憡璀� {} 鏉�", scanned, alerts);
+ } else {
+ log.debug("[LIMS鐩戞帶棰勮] 鎵弿 {} 涓洃鎺ч」锛屾棤鏂板鍛婅", scanned);
+ }
+ } catch (Exception e) {
+ log.error("[LIMS鐩戞帶棰勮] 鍒ゅ畾澶辫触", e);
+ }
+ }
+
+ private void saveResult(Long id, boolean ok, String msg) {
+ try {
+ DataInterface upd = new DataInterface();
+ upd.setId(id);
+ upd.setLastCollectTime(LocalDateTime.now());
+ String s = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MM-dd HH:mm:ss"))
+ + " " + (ok ? "鎴愬姛" : "澶辫触");
+ if (msg != null && !msg.isEmpty()) {
+ s += "锛�" + (msg.length() > 300 ? msg.substring(0, 300) : msg);
+ }
+ upd.setLastCollectResult(s);
+ diService.updateById(upd);
+ } catch (Exception ignore) {
+ }
+ }
+}
--
Gitblit v1.9.3