From f3cf05b74840f57f632af858ee27aab1d937cab8 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期六, 14 三月 2026 11:47:23 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_宁夏_中盛建材' into dev_宁夏_中盛建材

---
 src/main/java/com/ruoyi/basic/service/impl/BaseParamServiceImpl.java |  157 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 157 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..6cf1af6
--- /dev/null
+++ b/src/main/java/com/ruoyi/basic/service/impl/BaseParamServiceImpl.java
@@ -0,0 +1,157 @@
+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.math.BigDecimal;
+import java.time.LocalDateTime;
+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);
+        }
+        return list;
+    }
+
+    @Override
+    public int addBaseParam(BaseParam baseParam) {
+
+        if (baseParam == null) {
+            throw new RuntimeException("鏂板鍙傛暟涓嶈兘涓虹┖");
+        }
+        // 鍙傛暟鏍¢獙
+        checkBaseParam(baseParam, false);
+        // 鑷姩鐢熸垚paramKey
+        baseParam.setParamKey(generateParamKey());
+        baseParam.setCreateUser(SecurityUtils.getUsername());
+        baseParam.setCreateTime(LocalDateTime.now());
+
+        return baseMapper.insert(baseParam);
+    }
+
+    @Override
+    public int updateBaseParam(BaseParam baseParam) {
+        if (baseParam == null || baseParam.getId() == null) {
+            throw new RuntimeException("淇敼鍙傛暟ID涓嶈兘涓虹┖");
+        }
+        // 鍙傛暟鏍¢獙
+        checkBaseParam(baseParam, true);
+        baseParam.setUpdateUser(SecurityUtils.getUsername());
+        baseParam.setUpdateTime(LocalDateTime.now());
+
+        return baseMapper.updateById(baseParam);
+    }
+
+    /**
+     * 鐢熸垚鍙傛暟鍞竴key
+     */
+    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;
+        }
+        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(鍖洪棿)");
+        }
+
+        // 鍗曞�兼ā寮�
+        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);
+        }
+    }
+
+    @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