From 91acbe8b56194bbd834b1169b5578de8a5ed442c Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期六, 14 三月 2026 17:53:10 +0800
Subject: [PATCH] fix: BOM产品查询调整、重命名字段
---
src/main/java/com/ruoyi/basic/service/impl/BaseParamServiceImpl.java | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 166 insertions(+), 0 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
new file mode 100644
index 0000000..10cc41e
--- /dev/null
+++ b/src/main/java/com/ruoyi/basic/service/impl/BaseParamServiceImpl.java
@@ -0,0 +1,166 @@
+package com.ruoyi.basic.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.mapper.BaseParamMapper;
+import com.ruoyi.basic.pojo.BaseParam;
+import com.ruoyi.basic.service.BaseParamService;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * <br>
+ * 鍩虹鍙傛暟瀹氫箟鎺ュ彛瀹炵幇绫�
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/13 16:41
+ */
+@Slf4j
+@Service
+@Api("鍩虹鍙傛暟瀹氫箟鎺ュ彛瀹炵幇绫�")
+public class BaseParamServiceImpl extends ServiceImpl<BaseParamMapper, BaseParam> implements BaseParamService {
+
+ @Override
+ public List<BaseParam> baseParamList(BaseParam baseParam) {
+ LambdaQueryWrapper<BaseParam> queryWrapper = new LambdaQueryWrapper<>();
+ if (StringUtils.isNotEmpty(baseParam.getParamName())) {
+ queryWrapper.like(BaseParam::getParamName, baseParam.getParamName());
+ }
+ List<BaseParam> list = list(queryWrapper);
+ 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);
+ // 鑷姩鐢熸垚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);
+ }
+
+ @Override
+ public int updateBaseParam(BaseParam baseParam) {
+ if (baseParam == null || baseParam.getId() == null) {
+ throw new RuntimeException("淇敼鍙傛暟ID涓嶈兘涓虹┖");
+ }
+ // 鍙傛暟鏍¢獙
+ checkBaseParam(baseParam);
+ baseParam.setUpdateUser(SecurityUtils.getUsername());
+ baseParam.setUpdateTime(LocalDateTime.now());
+
+ return baseMapper.updateById(baseParam);
+ }
+
+ /**
+ * 鍙傛暟瀹氫箟鍚堟硶鏍¢獙
+ */
+ 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_";
+ 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 && 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 String normalizePattern(String pattern) {
+ if (StringUtils.isEmpty(pattern)) return "yyyy-MM-dd";
+ return pattern.replace("YYYY", "yyyy")
+ .replace("DD", "dd")
+ .replace("SS", "ss");
+ }
+
+ /**
+ * 杞崲涓哄叏澶у啓鏄剧ず
+ */
+ private String toUpperCasePattern(String pattern) {
+ if (StringUtils.isEmpty(pattern)) return "";
+ return pattern.replace("yyyy", "YYYY")
+ .replace("dd", "DD")
+ .replace("ss", "SS");
+ }
+
+ @Override
+ public int deleteBaseParamByIds(Long[] ids) {
+ if (ids == null || ids.length == 0) {
+ throw new RuntimeException("鍒犻櫎ID涓嶈兘涓虹┖");
+ }
+ return baseMapper.deleteBatchIds(Arrays.asList(ids));
+ }
+}
--
Gitblit v1.9.3