Jelajahi Sumber

新增系统全局配置表

wangliang 2 tahun lalu
induk
melakukan
6393760e7a

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

@@ -20,6 +20,8 @@ import java.io.File;
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
 import java.util.function.Function;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -97,6 +99,7 @@ public class SystemConstant {
     /**
      * 系统相关
      */
+    public static final String SYS_CONFIG_KEY_CHARSETS = "sys.txt.charset";
     public static final String METHOD = "post";
     public static final int PAGE_SIZE_MIN = 10;
     public static final int PAGE_SIZE_MAX = 1000;
@@ -418,6 +421,8 @@ public class SystemConstant {
 
     public static final String configCache = "config:cache";
 
+    public static final String sysConfigCache = "sys:config:cache";
+
     //    /**
     //     * ehcache配置
     //     */
@@ -719,4 +724,16 @@ public class SystemConstant {
             return null;
         }
     }
+
+    /**
+     * 校验是否是数字
+     *
+     * @param str
+     * @return
+     */
+    public static boolean checkNumber(String str) {
+        Pattern pattern = Pattern.compile("^[0-9]*$");
+        Matcher matcher = pattern.matcher(str.trim());
+        return matcher.matches();
+    }
 }

+ 17 - 0
themis-business/src/main/java/com/qmth/themis/business/dao/SysConfigMapper.java

@@ -0,0 +1,17 @@
+package com.qmth.themis.business.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.themis.business.entity.SysConfig;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @Description: 系统参数 Mapper 接口
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/6/25
+ */
+@Mapper
+public interface SysConfigMapper extends BaseMapper<SysConfig> {
+
+}

+ 85 - 0
themis-business/src/main/java/com/qmth/themis/business/entity/SysConfig.java

@@ -0,0 +1,85 @@
+package com.qmth.themis.business.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.themis.business.base.BaseEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: 系统参数
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/6/25
+ */
+@ApiModel(value = "sys_config", description = "系统参数表")
+public class SysConfig extends BaseEntity {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "机构id")
+    @TableField(value = "org_id")
+    private Long orgId;
+
+    /**
+     * 参数键值
+     */
+    @TableField("config_key")
+    private String configKey;
+
+    /**
+     * 参数名称
+     */
+    @TableField("config_name")
+    private String configName;
+    /**
+     * 参数键值
+     */
+    @TableField("config_value")
+    private String configValue;
+
+    @ApiModelProperty(value = "是否启用,0:停用,1:启用")
+    @TableField(value = "enable")
+    private Integer enable;
+
+    public Long getOrgId() {
+        return orgId;
+    }
+
+    public void setOrgId(Long orgId) {
+        this.orgId = orgId;
+    }
+
+    public String getConfigKey() {
+        return configKey;
+    }
+
+    public void setConfigKey(String configKey) {
+        this.configKey = configKey;
+    }
+
+    public String getConfigName() {
+        return configName;
+    }
+
+    public void setConfigName(String configName) {
+        this.configName = configName;
+    }
+
+    public String getConfigValue() {
+        return configValue;
+    }
+
+    public void setConfigValue(String configValue) {
+        this.configValue = configValue;
+    }
+
+    public Integer getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Integer enable) {
+        this.enable = enable;
+    }
+}

+ 24 - 0
themis-business/src/main/java/com/qmth/themis/business/service/CacheService.java

@@ -2,6 +2,7 @@ package com.qmth.themis.business.service;
 
 import com.qmth.themis.business.dto.AuthDto;
 import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
+import com.qmth.themis.business.entity.SysConfig;
 import com.qmth.themis.business.entity.TBOrg;
 import com.qmth.themis.business.entity.TBUser;
 
@@ -135,4 +136,27 @@ public interface CacheService {
      * @param studentId
      */
     public void removeStudentAccountCache(Long studentId);
+
+    /**
+     * 添加系统参数缓存
+     *
+     * @param key
+     * @return
+     */
+    public SysConfig addSysConfigCache(String key);
+
+    /**
+     * 更新系统参数缓存
+     *
+     * @param key
+     * @return
+     */
+    public SysConfig updateSysConfigCache(String key);
+
+    /**
+     * 删除系统参数缓存
+     *
+     * @param key
+     */
+    public void removeSysConfigCache(String key);
 }

+ 15 - 0
themis-business/src/main/java/com/qmth/themis/business/service/SysConfigService.java

@@ -0,0 +1,15 @@
+package com.qmth.themis.business.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.themis.business.entity.SysConfig;
+
+/**
+ * @Description: 系统参数 服务类
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/6/25
+ */
+public interface SysConfigService extends IService<SysConfig> {
+
+}

+ 38 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/CacheServiceImpl.java

@@ -54,6 +54,9 @@ public class CacheServiceImpl implements CacheService {
     @Resource
     TEStudentService teStudentService;
 
+    @Resource
+    SysConfigService sysConfigService;
+
     /**
      * 添加机构缓存
      *
@@ -300,4 +303,39 @@ public class CacheServiceImpl implements CacheService {
     public void removeStudentAccountCache(Long studentId) {
 
     }
+
+    /**
+     * 添加系统参数缓存
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.sysConfigCache, key = "#p0")
+    public SysConfig addSysConfigCache(String key) {
+        return sysConfigService.getOne(new QueryWrapper<SysConfig>().lambda().eq(SysConfig::getConfigKey, key));
+    }
+
+    /**
+     * 更新系统参数缓存
+     *
+     * @param key
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.sysConfigCache, key = "#p0", condition = "#result != null")
+    public SysConfig updateSysConfigCache(String key) {
+        return sysConfigService.getById(new QueryWrapper<SysConfig>().lambda().eq(SysConfig::getConfigKey, key));
+    }
+
+    /**
+     * 删除系统参数缓存
+     *
+     * @param key
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.sysConfigCache, key = "#p0")
+    public void removeSysConfigCache(String key) {
+
+    }
 }

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

@@ -0,0 +1,19 @@
+package com.qmth.themis.business.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.themis.business.dao.SysConfigMapper;
+import com.qmth.themis.business.entity.SysConfig;
+import com.qmth.themis.business.service.SysConfigService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Description: 系统参数 服务实现类
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/6/25
+ */
+@Service
+public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {
+
+}

+ 6 - 1
themis-business/src/main/java/com/qmth/themis/business/templete/TaskExportCommon.java

@@ -5,9 +5,11 @@ import com.alibaba.fastjson.JSONObject;
 import com.google.gson.Gson;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.entity.SysConfig;
 import com.qmth.themis.business.entity.TBTaskHistory;
 import com.qmth.themis.business.enums.TaskStatusEnum;
 import com.qmth.themis.business.enums.UploadFileEnum;
+import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TBAttachmentService;
 import com.qmth.themis.business.service.TBTaskHistoryService;
 import com.qmth.themis.business.util.OssUtil;
@@ -147,7 +149,10 @@ public class TaskExportCommon {
         InputStream inputStream = null;
         try {
             out = new ByteArrayOutputStream();
-            out.write(txtStr.getBytes(StandardCharsets.UTF_8));
+            CacheService cacheService = SpringContextHolder.getBean(CacheService.class);
+            SysConfig sysConfig = cacheService.addSysConfigCache(SystemConstant.SYS_CONFIG_KEY_CHARSETS);
+            String charsets = Objects.nonNull(sysConfig) ? sysConfig.getConfigValue() : StandardCharsets.UTF_8.toString();
+            out.write(txtStr.getBytes(charsets));
             byte[] bookByteAry = out.toByteArray();
             inputStream = new ByteArrayInputStream(bookByteAry);
             JSONObject json = new JSONObject();

+ 6 - 1
themis-business/src/main/java/com/qmth/themis/business/templete/TaskImportCommon.java

@@ -5,9 +5,11 @@ import com.alibaba.fastjson.JSONObject;
 import com.google.gson.Gson;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.entity.SysConfig;
 import com.qmth.themis.business.entity.TBTaskHistory;
 import com.qmth.themis.business.enums.FieldUniqueEnum;
 import com.qmth.themis.business.enums.TaskStatusEnum;
+import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TBTaskHistoryService;
 import com.qmth.themis.business.util.OssUtil;
 import com.qmth.themis.common.contanst.Constants;
@@ -142,7 +144,10 @@ public class TaskImportCommon {
         InputStream inputStream = null;
         try {
             out = new ByteArrayOutputStream();
-            out.write(txtStr.getBytes(StandardCharsets.UTF_8));
+            CacheService cacheService = SpringContextHolder.getBean(CacheService.class);
+            SysConfig sysConfig = cacheService.addSysConfigCache(SystemConstant.SYS_CONFIG_KEY_CHARSETS);
+            String charsets = Objects.nonNull(sysConfig) ? sysConfig.getConfigValue() : StandardCharsets.UTF_8.toString();
+            out.write(txtStr.getBytes(charsets));
             byte[] bookByteAry = out.toByteArray();
             inputStream = new ByteArrayInputStream(bookByteAry);
             StringJoiner stringJoiner = new StringJoiner("");

+ 6 - 1
themis-business/src/main/java/com/qmth/themis/business/templete/TaskSyncCommon.java

@@ -5,9 +5,11 @@ import com.alibaba.fastjson.JSONObject;
 import com.google.gson.Gson;
 import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.entity.SysConfig;
 import com.qmth.themis.business.entity.TBTaskHistory;
 import com.qmth.themis.business.enums.TaskStatusEnum;
 import com.qmth.themis.business.enums.UploadFileEnum;
+import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TBAttachmentService;
 import com.qmth.themis.business.service.TBTaskHistoryService;
 import com.qmth.themis.business.util.OssUtil;
@@ -92,7 +94,10 @@ public class TaskSyncCommon {
         InputStream inputStream = null;
         try {
             out = new ByteArrayOutputStream();
-            out.write(txtStr.getBytes(StandardCharsets.UTF_8));
+            CacheService cacheService = SpringContextHolder.getBean(CacheService.class);
+            SysConfig sysConfig = cacheService.addSysConfigCache(SystemConstant.SYS_CONFIG_KEY_CHARSETS);
+            String charsets = Objects.nonNull(sysConfig) ? sysConfig.getConfigValue() : StandardCharsets.UTF_8.toString();
+            out.write(txtStr.getBytes(charsets));
             byte[] bookByteAry = out.toByteArray();
             inputStream = new ByteArrayInputStream(bookByteAry);
             JSONObject json = new JSONObject();

+ 7 - 0
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentImportTemplete.java

@@ -85,6 +85,13 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
                                 if (Objects.nonNull(teExamActivityMap) && Objects.isNull(teExamActivityMap.get(examStudentImportDto.getExamActivityCode()))) {
                                     excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[场次]不存在"));
                                 }
+                            } else {
+                                if (Objects.nonNull(examStudentImportDto.getExamActivityCode()) && SystemConstant.checkNumber(examStudentImportDto.getExamActivityCode())) {
+                                    Integer code = Integer.parseInt(examStudentImportDto.getExamActivityCode());
+                                    if (code > 1) {
+                                        excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[随到随考场次不能大于1]"));
+                                    }
+                                }
                             }
                             excelErrorList.addAll(ExcelUtil.checkExcelField(examStudentImportDto, y, i));
                             if (Objects.nonNull(examStudentImportDto.getPassword()) && !Objects.equals(examStudentImportDto.getPassword().trim(), "")) {

+ 5 - 0
themis-business/src/main/resources/mapper/SysConfigMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.qmth.themis.business.dao.SysConfigMapper">
+
+</mapper>