Przeglądaj źródła

feat(business): 添加盲注结构导入数据校验功能

- 新增 BlindLevelsValidatorUtils 工具类用于数据校验
- 实现了对盲注结构导入数据的全面校验,包括: - 数据为空校验
  - 字段为空校验
  - 级别编号连续性校验
  - 大盲是小盲两倍校验 - 小盲和大盲递增校验
  - 底注金额合法性校验
  - 持续时间大于零校验
- 优化了数据校验逻辑,提高了校验的准确性和可靠性
- 移除了原有的简陋数据校验逻辑
fugui001 5 miesięcy temu
rodzic
commit
7d80848f79

+ 8 - 41
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/BlindStructuresServiceImpl.java

@@ -6,6 +6,7 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.dromara.business.domain.bo.BlindLevelsBo;
 import org.dromara.business.domain.vo.BlindLevelsImportVo;
 import org.dromara.business.service.IBlindLevelsService;
+import org.dromara.business.utils.BlindLevelsValidatorUtils;
 import org.dromara.common.core.domain.R;
 import org.dromara.common.core.service.UserService;
 import org.dromara.common.core.utils.MapstructUtils;
@@ -135,9 +136,13 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
             }
 
             // 3. 校验数据逻辑(可选)
-       /*     if (!validateData(dataList)) {
-                return R.fail("导入数据校验失败,请检查等级顺序或数值是否正确");
-            }*/
+            BlindLevelsValidatorUtils.ValidationResult validationResult = BlindLevelsValidatorUtils.validateBlindLevels(dataList);
+            if (validationResult.isValid()) {
+                System.out.println("数据校验通过");
+            } else {
+                return R.fail(validationResult.getErrorMessage());
+            }
+
             Long userId = LoginHelper.getUserId();
             add.setCreateUserId(userId);
             // 4. 插入主表
@@ -275,44 +280,6 @@ public class BlindStructuresServiceImpl implements IBlindStructuresService {
     }
 
 
-    public static boolean validateData(List<BlindLevelsImportVo> dataList) {
-        if (dataList == null || dataList.isEmpty()) {
-            return false;
-        }
-
-        return validateDataRecursively(dataList, 0);
-    }
-
-    private static boolean validateDataRecursively(List<BlindLevelsImportVo> dataList, int currentIndex) {
-        if (currentIndex >= dataList.size() - 1) {
-            return true;
-        }
-
-        BlindLevelsImportVo current = dataList.get(currentIndex);
-        BlindLevelsImportVo next = dataList.get(currentIndex + 1);
-
-        // Check if levels are continuous
-        if (current.getLevelNumber() + 1 != next.getLevelNumber()) {
-            System.out.println("Error: Levels are not continuous at index " + currentIndex);
-            return false;
-        }
-
-        // Check if values are increasing
-        if (current.getSmallBlind() >= next.getSmallBlind() ||
-            current.getBigBlind() >= next.getBigBlind() ||
-            current.getAnte() >= next.getAnte()) {
-            System.out.println("Error: Values are not increasing at index " + currentIndex);
-            return false;
-        }
-
-        // Check if upgrade time is positive
-        if (next.getDurationMinutes() <= 0){
-            System.out.println("Error: Upgrade time is not positive at index " + (currentIndex + 1));
-            return false;
-        }
-
-        return validateDataRecursively(dataList, currentIndex + 1);
-    }
 
 
 

+ 96 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/utils/BlindLevelsValidatorUtils.java

@@ -0,0 +1,96 @@
+package org.dromara.business.utils;
+
+import org.dromara.business.domain.vo.BlindLevelsImportVo;
+
+import java.util.List;
+
+/**
+ * 盲注结构导入数据校验工具类
+ */
+public class BlindLevelsValidatorUtils {
+
+
+    public static class ValidationResult {
+        private boolean valid = true;
+        private StringBuilder errorMessage = new StringBuilder();
+
+        public boolean isValid() {
+            return valid;
+        }
+
+        public String getErrorMessage() {
+            return errorMessage.toString();
+        }
+
+        private void addError(String message) {
+            valid = false;
+            errorMessage.append(message).append("\n");
+        }
+    }
+
+    public static ValidationResult validateBlindLevels(List<BlindLevelsImportVo> dataList) {
+        ValidationResult result = new ValidationResult();
+
+        if (dataList == null || dataList.isEmpty()) {
+            result.addError("数据为空");
+            return result;
+        }
+
+        boolean anteStarted = false;
+
+        for (int i = 0; i < dataList.size(); i++) {
+            BlindLevelsImportVo vo = dataList.get(i);
+            int level = i + 1;
+
+            // 检查字段是否为空
+            if (vo.getLevelNumber() == null || vo.getSmallBlind() == null ||
+                vo.getBigBlind() == null || vo.getDurationMinutes() == null) {
+                result.addError("第 " + level + " 行存在空字段");
+                continue;
+            }
+
+            // 级别编号是否连续
+            if (!vo.getLevelNumber().equals((long) level)) {
+                result.addError("第 " + level + " 行级别编号不正确,应为 " + level);
+            }
+
+            // 大盲是否是小盲的两倍
+            if (!vo.getBigBlind().equals(vo.getSmallBlind() * 2)) {
+                result.addError("第 " + level + " 行:大盲金额应为小盲金额的两倍");
+            }
+
+            // 小盲和大盲是否递增
+            if (i > 0) {
+                BlindLevelsImportVo prev = dataList.get(i - 1);
+                if (vo.getSmallBlind() <= prev.getSmallBlind() || vo.getBigBlind() <= prev.getBigBlind()) {
+                    result.addError("第 " + level + " 行:小盲或大盲金额未递增");
+                }
+            }
+
+            // 底注校验
+            if (vo.getAnte() != null) {
+                if (vo.getAnte() < 0) {
+                    result.addError("第 " + level + " 行:底注金额不能为负数");
+                }
+                if (vo.getAnte() > vo.getSmallBlind() / 2) {
+                    result.addError("第 " + level + " 行:底注金额不应超过小盲金额的一半");
+                }
+                anteStarted = true;
+            } else if (anteStarted) {
+                // 如果前面已经有底注,后面不应突然消失(可选)
+                // 可根据实际业务决定是否开启此校验
+                // result.addError("第 " + level + " 行:底注在前面已出现,不应突然消失");
+            }
+
+            // 持续时间校验
+            if (vo.getDurationMinutes() <= 0) {
+                result.addError("第 " + level + " 行:持续时间必须大于 0 分钟");
+            }
+        }
+
+        return result;
+    }
+
+
+
+}