Kaynağa Gözat

加入sysconfig

wangliang 1 yıl önce
ebeveyn
işleme
62886e9a65

+ 6 - 6
sop-business/src/main/java/com/qmth/sop/business/cache/CommonCacheService.java

@@ -73,28 +73,28 @@ public interface CommonCacheService {
     /**
      * 添加系统参数缓存
      *
-     * @param schoolId
+     * @param orgId
      * @param key
      * @return
      */
-    public SysConfig addSysConfigCache(Long schoolId, String key);
+    public SysConfig addSysConfigCache(Long orgId, String key);
 
     /**
      * 更新系统参数缓存
      *
-     * @param schoolId
+     * @param orgId
      * @param key
      * @return
      */
-    public SysConfig updateSysConfigCache(Long schoolId, String key);
+    public SysConfig updateSysConfigCache(Long orgId, String key);
 
     /**
      * 删除系统参数缓存
      *
-     * @param schoolId
+     * @param orgId
      * @param key
      */
-    public void removeSysConfigCache(Long schoolId, String key);
+    public void removeSysConfigCache(Long orgId, String key);
 
     /**
      * 设置用户session信息

+ 8 - 0
sop-business/src/main/java/com/qmth/sop/business/service/SysConfigService.java

@@ -3,6 +3,8 @@ package com.qmth.sop.business.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.entity.SysConfig;
 
+import java.util.List;
+
 /**
  * <p>
  * 参数表 服务类
@@ -13,4 +15,10 @@ import com.qmth.sop.business.entity.SysConfig;
  */
 public interface SysConfigService extends IService<SysConfig> {
 
+    /**
+     * 查询所有系统配置项
+     *
+     * @return
+     */
+    List<SysConfig> selectAll();
 }

+ 45 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysConfigServiceImpl.java

@@ -1,10 +1,18 @@
 package com.qmth.sop.business.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.sop.business.cache.CommonCacheService;
 import com.qmth.sop.business.entity.SysConfig;
 import com.qmth.sop.business.mapper.SysConfigMapper;
 import com.qmth.sop.business.service.SysConfigService;
+import com.qmth.sop.common.contant.SystemConstant;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Objects;
 
 /**
  * <p>
@@ -17,4 +25,41 @@ import org.springframework.stereotype.Service;
 @Service
 public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {
 
+    @Resource
+    CommonCacheService commonCacheService;
+
+    /**
+     * 查询所有系统配置项
+     *
+     * @return
+     */
+    @Override
+    public List<SysConfig> selectAll() {
+        List<SysConfig> sysConfigList = null;
+        try {
+            String platform = System.getProperties().getProperty(SystemConstant.OS_NAME);
+            sysConfigList = this.list();
+            if (!CollectionUtils.isEmpty(sysConfigList)) {
+                for (SysConfig s : sysConfigList) {
+                    if (s.getConfigKey().contains(SystemConstant.SYS_CONFIG_KEY_CHARSETS)) {
+                        if (Objects.nonNull(platform) && platform.contains(SystemConstant.WINDOWS)) {
+                            if (!Objects.equals(s.getConfigValue(), SystemConstant.CHARSET_GBK)) {
+                                s.setConfigValue(SystemConstant.CHARSET_GBK);
+                                this.updateById(s);
+                            }
+                        } else {
+                            if (!Objects.equals(s.getConfigValue(), StandardCharsets.UTF_8.toString())) {
+                                s.setConfigValue(StandardCharsets.UTF_8.toString());
+                                this.updateById(s);
+                            }
+                        }
+                    }
+                    commonCacheService.updateSysConfigCacheForDb(s.getConfigKey(), s);
+                }
+            }
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+        }
+        return sysConfigList;
+    }
 }

+ 17 - 13
sop-common/src/main/java/com/qmth/sop/common/threadPool/MyThreadPool.java → sop-business/src/main/java/com/qmth/sop/business/threadPool/MyThreadPool.java

@@ -1,13 +1,19 @@
-package com.qmth.sop.common.threadPool;//package com.qmth.themis.business.threadPool;
+package com.qmth.sop.business.threadPool;//package com.qmth.themis.business.threadPool;
 
+import com.qmth.sop.business.cache.CommonCacheService;
+import com.qmth.sop.business.entity.SysConfig;
 import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
+import javax.annotation.Resource;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ThreadPoolExecutor;
 
@@ -24,8 +30,8 @@ public class MyThreadPool extends ThreadPoolTaskExecutor {
     private MyThreadPool threadPoolTaskExecutor = null;
     static final int cpuNum = Runtime.getRuntime().availableProcessors();
 
-//    @Resource
-//    CommonCacheService commonCacheService;
+    @Resource
+    CommonCacheService commonCacheService;
 
     /**
      * 线程池
@@ -33,18 +39,16 @@ public class MyThreadPool extends ThreadPoolTaskExecutor {
      * @return
      */
     @Bean
-//    @Primary
+    @Primary
     public Executor taskThreadPool() {
-//        SysConfig sysConfigCustomThreadPoolCoreSize = commonCacheService.addSysConfigCache(SystemConstant.CUSTOM_THREAD_POOL_CORE_SIZE);
-//        Optional.ofNullable(sysConfigCustomThreadPoolCoreSize).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置是否自定义线程池大小"));
-//        boolean customThreadPoolCoreSize = Boolean.valueOf(sysConfigCustomThreadPoolCoreSize.getConfigValue());
-//
-//        SysConfig sysConfigThreadPoolCoreSize = commonCacheService.addSysConfigCache(SystemConstant.THREAD_POOL_CORE_SIZE);
-//        Optional.ofNullable(sysConfigThreadPoolCoreSize).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置自定义线程池大小"));
-//        Integer threadPoolCoreSize = Integer.valueOf(sysConfigThreadPoolCoreSize.getConfigValue());
+        SysConfig sysConfigCustomThreadPoolCoreSize = commonCacheService.addSysConfigCache(SystemConstant.CUSTOM_THREAD_POOL_CORE_SIZE);
+        Optional.ofNullable(sysConfigCustomThreadPoolCoreSize).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置是否自定义线程池大小"));
+        boolean customThreadPoolCoreSize = Boolean.valueOf(sysConfigCustomThreadPoolCoreSize.getConfigValue());
+
+        SysConfig sysConfigThreadPoolCoreSize = commonCacheService.addSysConfigCache(SystemConstant.THREAD_POOL_CORE_SIZE);
+        Optional.ofNullable(sysConfigThreadPoolCoreSize).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置自定义线程池大小"));
+        Integer threadPoolCoreSize = Integer.valueOf(sysConfigThreadPoolCoreSize.getConfigValue());
 
-        boolean customThreadPoolCoreSize = false;
-        Integer threadPoolCoreSize = 1;
         if (Objects.isNull(threadPoolTaskExecutor)) {
             log.info("cpuNum:{}", cpuNum);
             threadPoolTaskExecutor = new MyThreadPool();

+ 5 - 5
sop-common/src/main/java/com/qmth/sop/common/base/BasePage.java

@@ -11,7 +11,7 @@ import io.swagger.annotations.ApiModelProperty;
  */
 public class BasePage {
 
-    private Long schoolId;
+    private Long orgId;
 
     @ApiModelProperty(value = "分页页码")
     private Integer pageNumber;
@@ -28,12 +28,12 @@ public class BasePage {
 
     }
 
-    public Long getSchoolId() {
-        return schoolId;
+    public Long getOrgId() {
+        return orgId;
     }
 
-    public void setSchoolId(Long schoolId) {
-        this.schoolId = schoolId;
+    public void setOrgId(Long orgId) {
+        this.orgId = orgId;
     }
 
     public Integer getPageNumber() {

+ 31 - 1
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -17,6 +17,7 @@ public class SystemConstant {
     public static final String CHARSET_NAME = "UTF-8";
     //    public static final String CHARSET_GB2312 = "gb2312";
     public static final Charset CHARSET = Charset.forName(CHARSET_NAME);
+    public static final String CHARSET_GBK = "gbk";
     public static final String SUCCESS = "success";
     public static final String UPDATE_TIME = "updateTime";
     public static final String SESSION = "session:";
@@ -33,8 +34,37 @@ public class SystemConstant {
     public static final String PATH_MATCH = "*";
     public static final String PATH_SUBSTR = "/#";
     public static final String METHOD = "post";
-    public static final String SESSION_ACTIVE = "session.active";
     public static final String PT = "PT";
+    public static final String USER_DIR = "user.dir";
+    public static final String OS_NAME = "os.name";
+    public static final String TMP_DIR = "java.io.tmpdir";
+    public static final String FILE = "file";
+    public static final String SIZE = "size";
+    public static final String HTML_PREFIX = ".html";
+    public static final String JSON_PREFIX = ".json";
+    public static final String ZIP_PREFIX = ".zip";
+    public static final String TXT_PREFIX = ".txt";
+    public static final String WINDOWS = "Windows";
+
+    public static final String SYS_CODE_ENABLE = "sys.code.enable";
+    //    public static final String SYS_MESSAGE_ENABLE = "sys.message.enable";
+//    public static final String SYS_MESSAGE_RESEND_COUNT = "sys.message.resendCount";
+    public static final String SYS_CONFIG_KEY_CHARSETS = "sys.txt.charset";
+    public static final String ADMIN_LOGO_URL = "admin.logo.url";
+    public static final String ATTACHMENT_TYPE = "attachment.type";
+    public static final String ATTACHMENT_LENGTH = "attachment.length";
+    public static final String ATTACHMENT_SIZE = "attachment.size";
+    public static final String THREAD_POOL_CORE_SIZE = "thread.pool.core.size";
+    public static final String CUSTOM_THREAD_POOL_CORE_SIZE = "custom.thread.pool.core.size";
+    public static final String SESSION_ACTIVE = "session.active";
+    public static final String SMS_NORMAL_CODE = "sms.normal.code";
+    public static final String CODE_EXPIRED_TIME = "code.expired.time";
+    public static final String CODE_SEND_INTERVAL = "code.send.interval";
+
+    /**
+     * api前缀
+     */
+    public static final String PREFIX_URL_WIDGET = "/admin/widget";
 
     /**
      * 缓存配置

+ 1 - 1
sop-server/src/main/java/com/qmth/sop/server/ServerApplication.java

@@ -1,8 +1,8 @@
 package com.qmth.sop.server;
 
 import com.qmth.boot.core.security.service.CustomizeAuthorizationService;
+import com.qmth.sop.business.threadPool.MyThreadPool;
 import com.qmth.sop.common.base.CustomizedSqlInjector;
-import com.qmth.sop.common.threadPool.MyThreadPool;
 import com.qmth.sop.server.auth.SopServerAuthenticationService;
 import org.activiti.spring.boot.SecurityAutoConfiguration;
 import org.mybatis.spring.annotation.MapperScan;

+ 7 - 10
sop-server/src/main/java/com/qmth/sop/server/api/TDFormWidgetController.java

@@ -1,19 +1,16 @@
 package com.qmth.sop.server.api;
 
-
+import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.sop.common.contant.SystemConstant;
+import io.swagger.annotations.Api;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-/**
- * <p>
- * 动态表单控件表 前端控制器
- * </p>
- *
- * @author wangliang
- * @since 2023-07-17
- */
+@Api(tags = "系统控件Controller")
 @RestController
-@RequestMapping("/t-dform-widget")
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_WIDGET)
+@Validated
 public class TDFormWidgetController {
 
 }

+ 6 - 7
sop-server/src/main/java/com/qmth/sop/server/start/StartRunning.java

@@ -1,10 +1,13 @@
 package com.qmth.sop.server.start;
 
+import com.qmth.sop.business.service.SysConfigService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
+
 /**
  * @Description: 服务启动时初始化运行,哪个微服务模块需要则拿此模版去用
  * @Param:
@@ -16,17 +19,13 @@ import org.springframework.stereotype.Component;
 public class StartRunning implements CommandLineRunner {
     private final static Logger log = LoggerFactory.getLogger(StartRunning.class);
 
-//    @Resource
-//    AuthInfoService authInfoService;
-//
-//    @Resource
-//    SysConfigService sysConfigService;
+    @Resource
+    SysConfigService sysConfigService;
 
     @Override
     public void run(String... args) throws Exception {
         log.info("服务器启动时执行 start");
-//        sysConfigService.selectAll();
-//        authInfoService.appInfoInit();
+        sysConfigService.selectAll();
         log.info("服务器启动时执行 end");
     }