From 00b0ec55e1b0eef82b3a31166e8273ecea776568 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期六, 19 十月 2024 14:34:51 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/system/service/impl/ConfigServiceImpl.java |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/system/service/impl/ConfigServiceImpl.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/system/service/impl/ConfigServiceImpl.java
index 29230e8..2f65707 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/system/service/impl/ConfigServiceImpl.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/system/service/impl/ConfigServiceImpl.java
@@ -8,7 +8,6 @@
 import com.zy.acs.manager.system.enums.ConfigType;
 import com.zy.acs.manager.system.mapper.ConfigMapper;
 import com.zy.acs.manager.system.service.ConfigService;
-import com.zy.acs.framework.exception.CoolException;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
@@ -57,4 +56,48 @@
         }
     }
 
+    @Override
+    public <T> boolean setVal(String key, T val) {
+        List<Config> list = this.list(new LambdaQueryWrapper<Config>().eq(Config::getFlag, key));
+        Config config = list.stream().findFirst().orElse(null);
+        if (config == null) {
+            return false;
+        }
+        ConfigType configType = ConfigType.query(config.getType());
+        switch (configType) {
+            case BOOLEAN:
+                if (!(val instanceof Boolean)) {
+                    throw new IllegalArgumentException("Expected Boolean value for key: " + key);
+                }
+                config.setVal((Boolean) val ? "TRUE" : "FALSE");
+                break;
+            case NUMBER:
+                if (val instanceof Integer || val instanceof Short || val instanceof Long || val instanceof Double) {
+                    config.setVal(String.valueOf(val));
+                } else {
+                    throw new IllegalArgumentException("Expected a numeric value for key: " + key);
+                }
+                break;
+            case STRING:
+                if (!(val instanceof String)) {
+                    throw new IllegalArgumentException("Expected a String value for key: " + key);
+                }
+                config.setVal((String) val);
+                break;
+            case JSON:
+                config.setVal(GsonUtils.toJson(val));
+                break;
+            case DATE:
+                if (!(val instanceof Date)) {
+                    throw new IllegalArgumentException("Expected a Date value for key: " + key);
+                }
+                config.setVal(DateUtils.convert((Date) val));
+                break;
+            default:
+                throw new UnsupportedOperationException("Unsupported ConfigType: " + configType);
+        }
+
+        return this.updateById(config);
+    }
+
 }

--
Gitblit v1.9.1