From 14999b3d001b6eff1220f7a6701c0796eee1089c Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期六, 14 三月 2026 15:57:17 +0800
Subject: [PATCH] feat: 工序绑定参数列表
---
src/main/java/com/ruoyi/basic/service/impl/BaseParamServiceImpl.java | 125 ++++++++++++++++++++++-------------------
1 files changed, 67 insertions(+), 58 deletions(-)
diff --git a/src/main/java/com/ruoyi/basic/service/impl/BaseParamServiceImpl.java b/src/main/java/com/ruoyi/basic/service/impl/BaseParamServiceImpl.java
index 6cf1af6..10cc41e 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/BaseParamServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/BaseParamServiceImpl.java
@@ -11,8 +11,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
-import java.math.BigDecimal;
import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -41,21 +41,31 @@
if (list == null || list.isEmpty()) {
return new ArrayList<>(0);
}
+
+ // 澶勭悊鏃ユ湡鏍煎紡灞曠ず
+ list.forEach(item -> {
+ if (Integer.valueOf(4).equals(item.getParamType()) && StringUtils.isNotEmpty(item.getParamFormat())) {
+ item.setParamFormat(toUpperCasePattern(item.getParamFormat()));
+ }
+ });
+
return list;
}
@Override
public int addBaseParam(BaseParam baseParam) {
-
if (baseParam == null) {
throw new RuntimeException("鏂板鍙傛暟涓嶈兘涓虹┖");
}
// 鍙傛暟鏍¢獙
- checkBaseParam(baseParam, false);
+ checkBaseParam(baseParam);
// 鑷姩鐢熸垚paramKey
baseParam.setParamKey(generateParamKey());
baseParam.setCreateUser(SecurityUtils.getUsername());
baseParam.setCreateTime(LocalDateTime.now());
+ // 璁剧疆榛樿鍊�
+ if (baseParam.getIsRequired() == null) baseParam.setIsRequired(0);
+ if (baseParam.getValueMode() == null) baseParam.setValueMode(1);
return baseMapper.insert(baseParam);
}
@@ -66,7 +76,7 @@
throw new RuntimeException("淇敼鍙傛暟ID涓嶈兘涓虹┖");
}
// 鍙傛暟鏍¢獙
- checkBaseParam(baseParam, true);
+ checkBaseParam(baseParam);
baseParam.setUpdateUser(SecurityUtils.getUsername());
baseParam.setUpdateTime(LocalDateTime.now());
@@ -74,76 +84,76 @@
}
/**
- * 鐢熸垚鍙傛暟鍞竴key
+ * 鍙傛暟瀹氫箟鍚堟硶鏍¢獙
+ */
+ private void checkBaseParam(BaseParam baseParam) {
+ if (StringUtils.isEmpty(baseParam.getParamName())) {
+ throw new RuntimeException("鍙傛暟鍚嶇О涓嶈兘涓虹┖");
+ }
+
+ // 绫诲瀷鏍¢獙 (1:鏁板瓧, 2:鏂囨湰, 3:涓嬫媺閫夋嫨, 4:鏃ユ湡鏃堕棿)
+ List<Integer> validTypes = Arrays.asList(1, 2, 3, 4);
+ if (baseParam.getParamType() == null || !validTypes.contains(baseParam.getParamType())) {
+ throw new RuntimeException("闈炴硶鍙傛暟绫诲瀷");
+ }
+
+ // 濡傛灉鏄棩鏈熺被鍨嬶紝鏍¢獙鏃ユ湡鏍煎紡閰嶇疆
+ if (Integer.valueOf(4).equals(baseParam.getParamType())) {
+ if (StringUtils.isEmpty(baseParam.getParamFormat())) {
+ throw new RuntimeException("鏃ユ湡绫诲瀷蹇呴』閰嶇疆鍙傛暟鏍煎紡(濡�: yyyy-MM-dd)");
+ }
+ try {
+ String standardPattern = normalizePattern(baseParam.getParamFormat());
+ DateTimeFormatter.ofPattern(standardPattern);
+ baseParam.setParamFormat(standardPattern);
+ } catch (Exception e) {
+ throw new RuntimeException("鏃ユ湡鏍煎紡闈炴硶: " + baseParam.getParamFormat());
+ }
+ }
+ }
+
+ /**
+ * 鐢熸垚鍙傛暟鍞竴key (PARAM_XXX)
*/
private String generateParamKey() {
String prefix = "PARAM_";
- // 鏌ヨ褰撳墠鏈�澶ey
LambdaQueryWrapper<BaseParam> wrapper = new LambdaQueryWrapper<>();
wrapper.select(BaseParam::getParamKey)
.likeRight(BaseParam::getParamKey, prefix)
.orderByDesc(BaseParam::getParamKey)
.last("limit 1");
+
BaseParam last = baseMapper.selectOne(wrapper);
int nextNum = 1;
- if (last != null) {
- String lastKey = last.getParamKey();
- String numStr = lastKey.replace(prefix, "");
- nextNum = Integer.parseInt(numStr) + 1;
+ if (last != null && StringUtils.isNotEmpty(last.getParamKey())) {
+ try {
+ String numStr = last.getParamKey().replace(prefix, "");
+ nextNum = Integer.parseInt(numStr) + 1;
+ } catch (Exception e) {
+ log.error("瑙f瀽ParamKey寮傚父", e);
+ }
}
return prefix + String.format("%04d", nextNum);
}
/**
- * 鍙傛暟鍚堟硶鎬ф牎楠�
+ * 鏃ユ湡鏍煎紡鍖�
*/
- private void checkBaseParam(BaseParam baseParam, boolean isUpdate) {
- if (baseParam == null) {
- throw new RuntimeException("鍙傛暟瀵硅薄涓嶈兘涓虹┖");
- }
- if (StringUtils.isEmpty(baseParam.getParamName())) {
- throw new RuntimeException("鍙傛暟鍚嶇О涓嶈兘涓虹┖");
- }
- if (baseParam.getParamType() == null ||
- !(baseParam.getParamType() == 1 || baseParam.getParamType() == 2)) {
- throw new RuntimeException("鍙傛暟绫诲瀷蹇呴』涓�1(鏁板瓧)鎴�2(鏂囨湰)");
- }
- if (baseParam.getValueMode() == null ||
- !(baseParam.getValueMode() == 1 || baseParam.getValueMode() == 2)) {
- throw new RuntimeException("鍊兼ā寮忓繀椤讳负1(鍗曞��)鎴�2(鍖洪棿)");
- }
+ private String normalizePattern(String pattern) {
+ if (StringUtils.isEmpty(pattern)) return "yyyy-MM-dd";
+ return pattern.replace("YYYY", "yyyy")
+ .replace("DD", "dd")
+ .replace("SS", "ss");
+ }
- // 鍗曞�兼ā寮�
- if (baseParam.getValueMode() == 1) {
- if (StringUtils.isEmpty(baseParam.getDefaultValue())) {
- throw new RuntimeException("鍗曞�煎弬鏁伴粯璁ゅ�间笉鑳戒负绌�");
- }
- if (baseParam.getParamType() == 1) {
- try {
- new BigDecimal(baseParam.getDefaultValue());
- } catch (Exception e) {
- throw new RuntimeException("榛樿鍊煎繀椤讳负鏁板瓧");
- }
- }
-
- baseParam.setDefaultMin(null);
- baseParam.setDefaultMax(null);
- }
-
- // 鍖洪棿妯″紡
- if (baseParam.getValueMode() == 2) {
- if (baseParam.getParamType() != 1) {
- throw new RuntimeException("鍙湁鏁板瓧绫诲瀷鎵嶈兘浣跨敤鍖洪棿妯″紡");
- }
- if (baseParam.getDefaultMin() == null || baseParam.getDefaultMax() == null) {
- throw new RuntimeException("鍖洪棿鍙傛暟鏈�灏忓�煎拰鏈�澶у�间笉鑳戒负绌�");
- }
- if (baseParam.getDefaultMin().compareTo(baseParam.getDefaultMax()) > 0) {
- throw new RuntimeException("鏈�灏忓�间笉鑳藉ぇ浜庢渶澶у��");
- }
-
- baseParam.setDefaultValue(null);
- }
+ /**
+ * 杞崲涓哄叏澶у啓鏄剧ず
+ */
+ private String toUpperCasePattern(String pattern) {
+ if (StringUtils.isEmpty(pattern)) return "";
+ return pattern.replace("yyyy", "YYYY")
+ .replace("dd", "DD")
+ .replace("ss", "SS");
}
@Override
@@ -151,7 +161,6 @@
if (ids == null || ids.length == 0) {
throw new RuntimeException("鍒犻櫎ID涓嶈兘涓虹┖");
}
-
return baseMapper.deleteBatchIds(Arrays.asList(ids));
}
}
--
Gitblit v1.9.3