wangliang 2 éve
szülő
commit
37c1781192

+ 56 - 2
themis-admin/src/main/java/com/qmth/themis/admin/api/SysConfigController.java

@@ -1,9 +1,12 @@
 package com.qmth.themis.admin.api;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.common.reflect.TypeToken;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.response.SysConfigBean;
 import com.qmth.themis.business.entity.SysConfig;
+import com.qmth.themis.business.enums.UploadFileEnum;
 import com.qmth.themis.business.service.SysConfigService;
 import com.qmth.themis.business.service.ThemisCacheService;
 import com.qmth.themis.business.util.OssUtil;
@@ -12,9 +15,11 @@ import com.qmth.themis.common.util.GsonUtil;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import io.swagger.annotations.*;
+import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -22,6 +27,12 @@ import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 
 /**
@@ -67,7 +78,7 @@ public class SysConfigController {
         sysConfig.setEditor(1);
         sysConfig.setEnable(true);
         sysConfigService.saveOrUpdate(sysConfig);
-        SystemConstant.updateSysconfig(sysConfig);
+        updateSysconfig(sysConfig);
         return ResultUtil.ok(true);
     }
 
@@ -82,7 +93,50 @@ public class SysConfigController {
 
         sysConfig.setEnable(enable);
         sysConfigService.saveOrUpdate(sysConfig);
-        SystemConstant.updateSysconfig(sysConfig);
+        updateSysconfig(sysConfig);
         return ResultUtil.ok(true);
     }
+
+    /**
+     * 刷新系统参数并写入json文件
+     */
+    public void updateSysconfig(SysConfig sysConfig) {
+        File file = null;
+        try {
+            themisCacheService.updateSysConfigCache(sysConfig.getConfigKey());
+            file = SystemConstant.getFileTempVar(SystemConstant.JSON_PREFIX);
+            JSONObject jsonObject = JSONObject
+                    .parseObject(new String(ossUtil.download(true, UploadFileEnum.client.name() + "/" + SystemConstant.EXAM_CONFIG_FILE_NAME), StandardCharsets.UTF_8));
+            List<SysConfigBean> sysConfigBeanList = null;
+            if (Objects.isNull(jsonObject) || jsonObject.size() == 0) {
+                jsonObject = new JSONObject();
+                sysConfigBeanList = new ArrayList<>();
+            } else {
+                sysConfigBeanList = (List<SysConfigBean>) jsonObject.get(SystemConstant.SYS_CONFIG_LIST);
+                sysConfigBeanList = CollectionUtils.isEmpty(sysConfigBeanList) ? new ArrayList<>() : sysConfigBeanList;
+                sysConfigBeanList = GsonUtil.fromJson(GsonUtil.toJson(sysConfigBeanList), new TypeToken<List<SysConfigBean>>() {
+                }.getType());
+            }
+            SysConfigBean sysConfigBean = GsonUtil.fromJson(GsonUtil.toJson(sysConfig), SysConfigBean.class);
+            sysConfigBeanList.removeIf(e -> Objects.equals(e.getConfigKey(), sysConfigBean.getConfigKey()));
+            if (Objects.nonNull(sysConfigBean.getEnable()) && sysConfigBean.getEnable()) {
+                sysConfigBeanList.add(sysConfigBean);
+            }
+            jsonObject.put(SystemConstant.SYS_CONFIG_LIST, sysConfigBeanList);
+
+            IOUtils.write(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(file));
+            ossUtil.upload(true, UploadFileEnum.client.name() + "/" + SystemConstant.EXAM_CONFIG_FILE_NAME, file);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof BusinessException) {
+                throw new BusinessException(e.getMessage());
+            } else {
+                throw new RuntimeException(e);
+            }
+        } finally {
+            if (Objects.nonNull(file)) {
+                file.delete();
+            }
+        }
+    }
 }

+ 0 - 47
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -1158,51 +1158,4 @@ public class SystemConstant {
         }
         return stringJoiner;
     }
-
-    /**
-     * 刷新系统参数并写入json文件
-     *
-     * @param sysConfig
-     */
-    public static void updateSysconfig(SysConfig sysConfig) {
-        File file = null;
-        try {
-            OssUtil ossUtil = SpringContextHolder.getBean(OssUtil.class);
-            ThemisCacheService themisCacheService = SpringContextHolder.getBean(ThemisCacheService.class);
-            themisCacheService.updateSysConfigCache(sysConfig.getConfigKey());
-            file = SystemConstant.getFileTempVar(SystemConstant.JSON_PREFIX);
-            JSONObject jsonObject = JSONObject
-                    .parseObject(new String(ossUtil.download(true, UploadFileEnum.client.name() + "/" + SystemConstant.EXAM_CONFIG_FILE_NAME), StandardCharsets.UTF_8));
-            List<SysConfigBean> sysConfigBeanList = null;
-            if (Objects.isNull(jsonObject) || jsonObject.size() == 0) {
-                jsonObject = new JSONObject();
-                sysConfigBeanList = new ArrayList<>();
-            } else {
-                sysConfigBeanList = (List<SysConfigBean>) jsonObject.get(SystemConstant.SYS_CONFIG_LIST);
-                sysConfigBeanList = CollectionUtils.isEmpty(sysConfigBeanList) ? new ArrayList<>() : sysConfigBeanList;
-                sysConfigBeanList = GsonUtil.fromJson(GsonUtil.toJson(sysConfigBeanList), new TypeToken<List<SysConfigBean>>() {
-                }.getType());
-            }
-            SysConfigBean sysConfigBean = GsonUtil.fromJson(GsonUtil.toJson(sysConfig), SysConfigBean.class);
-            sysConfigBeanList.removeIf(e -> Objects.equals(e.getConfigKey(), sysConfigBean.getConfigKey()));
-            if (Objects.nonNull(sysConfigBean.getEnable()) && sysConfigBean.getEnable()) {
-                sysConfigBeanList.add(sysConfigBean);
-            }
-            jsonObject.put(SystemConstant.SYS_CONFIG_LIST, sysConfigBeanList);
-
-            IOUtils.write(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(file));
-            ossUtil.upload(true, UploadFileEnum.client.name() + "/" + SystemConstant.EXAM_CONFIG_FILE_NAME, file);
-        } catch (Exception e) {
-            log.error(SystemConstant.LOG_ERROR, e);
-            if (e instanceof BusinessException) {
-                throw new BusinessException(e.getMessage());
-            } else {
-                throw new RuntimeException(e);
-            }
-        } finally {
-            if (Objects.nonNull(file)) {
-                file.delete();
-            }
-        }
-    }
 }

+ 0 - 4
themis-business/src/main/java/com/qmth/themis/business/service/impl/SysConfigServiceImpl.java

@@ -15,7 +15,6 @@ import org.springframework.util.CollectionUtils;
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 
 /**
  * @Description: 系统参数 服务实现类
@@ -48,9 +47,6 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
             if (!CollectionUtils.isEmpty(sysConfigList)) {
                 for (SysConfig s : sysConfigList) {
                     themisCacheService.updateSysConfigCacheForDb(s.getConfigKey(), s);
-                    if (Objects.nonNull(s.getConfigKey()) && s.getConfigKey().equalsIgnoreCase(SystemConstant.LOGIN_LIMIT)) {
-                        SystemConstant.updateSysconfig(s);
-                    }
                 }
             }
         } catch (Exception e) {

+ 1 - 1
themis-business/src/main/resources/db/init-table-data.sql

@@ -30,7 +30,7 @@ INSERT INTO `sys_config` VALUES (27, NULL, 'tencentcloud.sdk.callbackPwd', '腾
 INSERT INTO `sys_config` VALUES (28, NULL, 'tencentcloud.sdk.callbackTime', '腾讯云sdk_回调时间', '2m', 1, 1, NULL, NULL, NULL, NULL, 1, 0);
 INSERT INTO `sys_config` VALUES (29, NULL, 'tencentcloud.sdk.trtcQueryUrl', '腾讯云sdk_trtc_query_url', 'trtc.tencentcloudapi.com', 1, 1, NULL, NULL, NULL, NULL, 1, 0);
 INSERT INTO `sys_config` VALUES (30, NULL, 'tencentcloud.sdk.trtcRegion', '腾讯云sdk_trtc_region', 'ap-guangzhou', 1, 1, NULL, NULL, NULL, NULL, 1, 0);
-INSERT INTO `sys_config` VALUES (1623606961704583170, NULL, 'login limit', '登录限制', 'true', 1, NULL, 1675933039493, NULL, 1676255759262, NULL, 1, 1);
+INSERT INTO `sys_config` VALUES (1623606961704583170, NULL, 'login limit', '登录限制', 'true', 0, NULL, 1675933039493, NULL, 1676255759262, NULL, 1, 1);
 
 INSERT INTO `t_b_app_version` VALUES (1, 'v1.1.11', 13, 'http://d.maps9.com/wlv3', 'BUG修复', 'ANDROID', 1, NULL, NULL, NULL, NULL);
 INSERT INTO `t_b_app_version` VALUES (2, '1.1.11', 14, 'https://cdn.online-exam.cn/mobile/wap/index.html', 'V1.1.11', 'IOS', 1, NULL, NULL, NULL, NULL);