From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master

---
 jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsMessageConfigValidator.java |   96 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsMessageConfigValidator.java b/jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsMessageConfigValidator.java
new file mode 100644
index 0000000..a71a93e
--- /dev/null
+++ b/jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsMessageConfigValidator.java
@@ -0,0 +1,96 @@
+package jnpf.limsService.impl;
+
+import jnpf.limsEntity.LimsMessageConfigRow;
+import jnpf.limsMapper.LimsMessageConfigMapper;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Service
+@RequiredArgsConstructor
+public class LimsMessageConfigValidator {
+    private static final String CUSTOM_MESSAGE_SOURCE = "6";
+    private static final String IN_SITE_MESSAGE_TYPE = "1";
+
+    private final LimsMessageConfigMapper configMapper;
+
+    public ValidationResult validate(String eventCode) {
+        return validateRows(configMapper.selectByEventCode(eventCode));
+    }
+
+    static ValidationResult validateRows(List<LimsMessageConfigRow> rows) {
+        List<LimsMessageConfigRow> values = rows == null ? Collections.emptyList() : rows;
+        Set<String> configIds = values.stream()
+                .map(LimsMessageConfigRow::getConfigId)
+                .filter(StringUtils::hasText)
+                .collect(Collectors.toCollection(LinkedHashSet::new));
+        if (configIds.isEmpty()) {
+            return ValidationResult.invalid("CONFIG_NOT_FOUND: send config does not exist");
+        }
+        if (configIds.size() != 1) {
+            return ValidationResult.invalid("CONFIG_INVALID: send config code is not unique");
+        }
+
+        LimsMessageConfigRow config = values.get(0);
+        if (!Integer.valueOf(1).equals(config.getConfigEnabled())) {
+            return ValidationResult.invalid("CONFIG_INVALID: send config is disabled");
+        }
+        if (!CUSTOM_MESSAGE_SOURCE.equals(config.getConfigSource())) {
+            return ValidationResult.invalid("CONFIG_INVALID: message source must be 6");
+        }
+
+        List<LimsMessageConfigRow> relations = values.stream()
+                .filter(row -> StringUtils.hasText(row.getRelationId()))
+                .collect(Collectors.toList());
+        if (relations.size() != 1) {
+            return ValidationResult.invalid("CONFIG_INVALID: exactly one template relation is required");
+        }
+
+        LimsMessageConfigRow relation = relations.get(0);
+        if (!Integer.valueOf(1).equals(relation.getRelationEnabled())) {
+            return ValidationResult.invalid("CONFIG_INVALID: template relation is disabled");
+        }
+        if (!IN_SITE_MESSAGE_TYPE.equals(relation.getRelationMessageType())) {
+            return ValidationResult.invalid("CONFIG_INVALID: relation message type must be 1");
+        }
+        if (!StringUtils.hasText(relation.getTemplateId())) {
+            return ValidationResult.invalid("CONFIG_INVALID: related template does not exist");
+        }
+        if (!Integer.valueOf(1).equals(relation.getTemplateEnabled())) {
+            return ValidationResult.invalid("CONFIG_INVALID: message template is disabled");
+        }
+        if (!IN_SITE_MESSAGE_TYPE.equals(relation.getTemplateMessageType())) {
+            return ValidationResult.invalid("CONFIG_INVALID: template message type must be 1");
+        }
+        if (!CUSTOM_MESSAGE_SOURCE.equals(relation.getTemplateSource())) {
+            return ValidationResult.invalid("CONFIG_INVALID: template message source must be 6");
+        }
+        if (!StringUtils.hasText(relation.getMenuUrl())) {
+            return ValidationResult.invalid("CONFIG_INVALID: template menu URL is empty");
+        }
+        return ValidationResult.valid();
+    }
+
+    @Getter
+    @AllArgsConstructor
+    public static class ValidationResult {
+        private final boolean valid;
+        private final String error;
+
+        private static ValidationResult valid() {
+            return new ValidationResult(true, null);
+        }
+
+        private static ValidationResult invalid(String error) {
+            return new ValidationResult(false, error);
+        }
+    }
+}

--
Gitblit v1.8.0