Sfoglia il codice sorgente

激活BUG修复和新增txt动态编码

wangliang 2 anni fa
parent
commit
94cd1bc234

+ 1 - 0
distributed-print-business/src/main/resources/db/2、init-table-data.sql

@@ -785,6 +785,7 @@ INSERT INTO `sys_config` VALUES (36, NULL, NULL, 'sms.audit.overdue.code', '审
 INSERT INTO `sys_config` VALUES (37, NULL, NULL, 'sms.audit.reject.code', '审核驳回通知', 'SMS_237206063', NULL, 1, 14, 1, NULL, NULL, NULL);
 INSERT INTO `sys_config` VALUES (38, NULL, NULL, 'sms.upload.structure.code', '试卷结构推送通知', 'SMS_237201068', NULL, 1, 15, 1, NULL, NULL, NULL);
 INSERT INTO `sys_config` VALUES (39, NULL, NULL, 'sms.audit.copy.user.code', '用户', 'SMS_237206065', NULL, 1, 16, 1, NULL, NULL, NULL);
+INSERT INTO `sys_config` VALUES (40, NULL, NULL, 'sys.txt.charset', 'txt文件编码', 'gbk', NULL, 1, 1, 1, NULL, NULL, NULL);
 
 INSERT INTO `sys_role` VALUES (1, NULL, NULL, '系统管理员', 1, 'ADMIN', NULL, NULL, NULL, NULL, 1, NULL, NULL);
 INSERT INTO `sys_role` VALUES (2, NULL, NULL, '教务处老师', 1, 'OFFICE_TEACHER', NULL, NULL, NULL, NULL, 1, 'ANALYSIS', '系统内置');

+ 1 - 1
teachcloud-common-api/src/main/java/com/qmth/teachcloud/common/api/api/TSAuthController.java

@@ -98,7 +98,7 @@ public class TSAuthController {
     @ApiOperation(value = "查询激活信息")
     @ApiResponses({@ApiResponse(code = 200, message = "授权配置信息", response = Long.class)})
     @RequestMapping(value = "/select", method = RequestMethod.POST)
-    public Result select() {
+    public Result select() throws Exception {
         return ResultUtil.ok(authInfoService.selectAuthInfo());
     }
 }

+ 10 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -7,6 +7,7 @@ import com.qmth.teachcloud.common.annotation.DBVerify;
 import com.qmth.teachcloud.common.bean.result.DBVerifyResult;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.entity.BasicSchool;
+import com.qmth.teachcloud.common.entity.SysConfig;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.LocalCatalogEnum;
@@ -28,7 +29,6 @@ import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -135,6 +135,7 @@ public class SystemConstant {
     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 SYS_PDF_SIZE_LIST = "sys.pdf.size.list";
     public static final String ADMIN_LOGO_URL = "admin.logo.url";
     public static final String ATTACHMENT_TYPE = "attachment.type";
@@ -956,7 +957,14 @@ public class SystemConstant {
 
             String txtDirName = stringJoiner.toString();
             txtFileTemp = SystemConstant.getFileTempVar(SystemConstant.TXT_PREFIX);
-            IOUtils.write(message.getBytes(StandardCharsets.UTF_8), new FileOutputStream(txtFileTemp));
+
+            String charset = SystemConstant.CHARSET_NAME;
+            CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
+            SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.SYS_CONFIG_KEY_CHARSETS);
+            if (Objects.nonNull(sysConfig) && StringUtils.isNotBlank(sysConfig.getConfigValue())) {
+                charset = sysConfig.getConfigValue();
+            }
+            IOUtils.write(message.getBytes(charset), new FileOutputStream(txtFileTemp));
 
             String txtFileMd5 = DigestUtils.md5Hex(new FileInputStream(txtFileTemp));
             if (oss || (!oss && dictionaryConfig.fssPrivateDomain().getConfig().startsWith(SystemConstant.START_PARENT))) {

+ 8 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/mapper/TSAuthMapper.java

@@ -2,6 +2,7 @@ package com.qmth.teachcloud.common.mapper;
 
 import com.qmth.teachcloud.common.base.CustomBaseMapper;
 import com.qmth.teachcloud.common.entity.TSAuth;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * <p>
@@ -13,4 +14,11 @@ import com.qmth.teachcloud.common.entity.TSAuth;
  */
 public interface TSAuthMapper extends CustomBaseMapper<TSAuth> {
 
+    /**
+     * 查询最后激活信息
+     *
+     * @param authEnum
+     * @return
+     */
+    TSAuth lastAuthInfo(@Param("authEnum") String authEnum);
 }

+ 1 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/AuthInfoService.java

@@ -52,7 +52,7 @@ public interface AuthInfoService {
      *
      * @return
      */
-    AppInfoResult selectAuthInfo();
+    AppInfoResult selectAuthInfo() throws Exception;
 
     /**
      * 保存授权信息

+ 8 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/TSAuthService.java

@@ -2,6 +2,7 @@ package com.qmth.teachcloud.common.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.teachcloud.common.entity.TSAuth;
+import com.qmth.teachcloud.common.enums.AuthEnum;
 
 /**
  * <p>
@@ -13,4 +14,11 @@ import com.qmth.teachcloud.common.entity.TSAuth;
  */
 public interface TSAuthService extends IService<TSAuth> {
 
+    /**
+     * 查询最后激活信息
+     *
+     * @param authEnum
+     * @return
+     */
+    TSAuth lastAuthInfo(AuthEnum authEnum);
 }

+ 34 - 32
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/AuthInfoServiceImpl.java

@@ -155,21 +155,26 @@ public class AuthInfoServiceImpl implements AuthInfoService {
      * @return
      */
     @Override
-    public AppInfoResult selectAuthInfo() {
+    public AppInfoResult selectAuthInfo() throws Exception {
         Long expireTime = null;
         AppInfo appInfo = solarService.getAppInfo();
-        String accessKey = solarProperties.getAccessKey();
-        String accessSecret = solarProperties.getAccessSecret();
-        if (Objects.nonNull(appInfo) && Objects.nonNull(appInfo.getControl())) {
-            expireTime = Objects.nonNull(appInfo.getControl().getExpireTime()) ? appInfo.getControl().getExpireTime() : -1;
-        }
-        AuthEnum authEnum = AuthEnum.NON_ACTIVATED;
-        if (Objects.nonNull(accessKey) && Objects.nonNull(accessSecret)) {
-            authEnum = AuthEnum.ON_LINE;
-        } else if (Objects.nonNull(expireTime)) {
-            authEnum = AuthEnum.OFF_LINE;
+        if (Objects.isNull(appInfo)) {//说明未激活,从数据库取最后激活记录
+            TSAuth tsAuth = licenseForDb(AuthEnum.OFF_LINE);
+            return new AppInfoResult(tsAuth.getExpireTime(), tsAuth.getAccessKey(), tsAuth.getAccessSecret(), tsAuth.getType());
+        } else {
+            String accessKey = solarProperties.getAccessKey();
+            String accessSecret = solarProperties.getAccessSecret();
+            if (Objects.nonNull(appInfo) && Objects.nonNull(appInfo.getControl())) {
+                expireTime = Objects.nonNull(appInfo.getControl().getExpireTime()) ? appInfo.getControl().getExpireTime() : -1;
+            }
+            AuthEnum authEnum = AuthEnum.NON_ACTIVATED;
+            if (Objects.nonNull(accessKey) && Objects.nonNull(accessSecret)) {
+                authEnum = AuthEnum.ON_LINE;
+            } else if (Objects.nonNull(expireTime)) {
+                authEnum = AuthEnum.OFF_LINE;
+            }
+            return new AppInfoResult(expireTime, accessKey, accessSecret, authEnum);
         }
-        return new AppInfoResult(expireTime, accessKey, accessSecret, authEnum);
     }
 
     /**
@@ -201,16 +206,20 @@ public class AuthInfoServiceImpl implements AuthInfoService {
             stringJoiner.add(dictionaryConfig.fssPublicDomain().getConfig()).add(File.separator);
         }
         stringJoiner = SystemConstant.getDirName(stringJoiner, UploadFileEnum.FILE, true);
+        Long expireTime = null;
+        if (Objects.nonNull(appInfo) && Objects.nonNull(appInfo.getControl())) {
+            expireTime = Objects.nonNull(appInfo.getControl().getExpireTime()) ? appInfo.getControl().getExpireTime() : -1;
+        }
         for (OrgInfo o : orgInfoList) {
             orgCodesMap.put(o.getCode(), o.getCode());
             if (authEnum == AuthEnum.OFF_LINE) {
                 if (Objects.isNull(file)) {
-                    tsAuthList.add(new TSAuth(o.getId(), solarProperties.getLicense(), authEnum, appInfo.getControl().getExpireTime()));
+                    tsAuthList.add(new TSAuth(o.getId(), solarProperties.getLicense(), authEnum, expireTime));
                 } else {
-                    tsAuthList.add(new TSAuth(o.getId(), file, authEnum, appInfo.getControl().getExpireTime()));
+                    tsAuthList.add(new TSAuth(o.getId(), file, authEnum, expireTime));
                 }
             } else {
-                tsAuthList.add(new TSAuth(o.getId(), solarProperties.getAccessKey(), solarProperties.getAccessSecret(), authEnum, appInfo.getControl().getExpireTime()));
+                tsAuthList.add(new TSAuth(o.getId(), solarProperties.getAccessKey(), solarProperties.getAccessSecret(), authEnum, expireTime));
             }
             QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
             basicSchoolQueryWrapper.lambda().eq(BasicSchool::getCode, o.getCode());
@@ -322,25 +331,18 @@ public class AuthInfoServiceImpl implements AuthInfoService {
      * @param authEnum
      * @throws Exception
      */
-    public void licenseForDb(AuthEnum authEnum) throws Exception {
-        QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();
-        tsAuthQueryWrapper.lambda().isNotNull(TSAuth::getFile);
-        List<TSAuth> tsAuthList = tsAuthService.list(tsAuthQueryWrapper);
-        if (!CollectionUtils.isEmpty(tsAuthList)) {
-            for (TSAuth t : tsAuthList) {
-                AppInfo appInfo = solarService.update(t.getFile());
-                authInfoService.saveAuthInfo(appInfo, authEnum, t.getFile());
-            }
+    public TSAuth licenseForDb(AuthEnum authEnum) throws Exception {
+        TSAuth tsAuth = tsAuthService.lastAuthInfo(authEnum);
+        if (Objects.nonNull(tsAuth)) {
+            AppInfo appInfo = solarService.update(tsAuth.getFile());
+            authInfoService.saveAuthInfo(appInfo, authEnum, tsAuth.getFile());
         } else {
-            tsAuthQueryWrapper = new QueryWrapper<>();
-            tsAuthQueryWrapper.lambda().isNotNull(TSAuth::getAccessKey).isNotNull(TSAuth::getAccessSecret);
-            tsAuthList = tsAuthService.list(tsAuthQueryWrapper);
-            if (!CollectionUtils.isEmpty(tsAuthList)) {
-                for (TSAuth t : tsAuthList) {
-                    AppInfo appInfo = solarService.update(t.getAccessKey(), t.getAccessSecret());
-                    authInfoService.saveAuthInfo(appInfo, AuthEnum.ON_LINE, null);
-                }
+            tsAuth = tsAuthService.lastAuthInfo(AuthEnum.ON_LINE);
+            if (Objects.nonNull(tsAuth)) {
+                AppInfo appInfo = solarService.update(tsAuth.getAccessKey(), tsAuth.getAccessSecret());
+                authInfoService.saveAuthInfo(appInfo, AuthEnum.ON_LINE, null);
             }
         }
+        return tsAuth;
     }
 }

+ 11 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TSAuthServiceImpl.java

@@ -2,10 +2,14 @@ package com.qmth.teachcloud.common.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.teachcloud.common.entity.TSAuth;
+import com.qmth.teachcloud.common.enums.AuthEnum;
 import com.qmth.teachcloud.common.mapper.TSAuthMapper;
 import com.qmth.teachcloud.common.service.TSAuthService;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.Objects;
+
 /**
  * <p>
  * 激活授权配置表 服务实现类
@@ -17,4 +21,11 @@ import org.springframework.stereotype.Service;
 @Service
 public class TSAuthServiceImpl extends ServiceImpl<TSAuthMapper, TSAuth> implements TSAuthService {
 
+    @Resource
+    TSAuthMapper tsAuthMapper;
+
+    @Override
+    public TSAuth lastAuthInfo(AuthEnum authEnum) {
+        return tsAuthMapper.lastAuthInfo(Objects.nonNull(authEnum) ? authEnum.name() : null);
+    }
 }

+ 9 - 0
teachcloud-common/src/main/resources/mapper/TSAuthMapper.xml

@@ -2,4 +2,13 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.teachcloud.common.mapper.TSAuthMapper">
 
+    <select id="lastAuthInfo" resultType="com.qmth.teachcloud.common.entity.TSAuth">
+        SELECT t.* FROM t_s_auth t
+        <where>
+            <if test="authEnum != null and authEnum != ''">
+                and t.type = #{authEnum}
+            </if>
+        </where>
+        limit 1;
+    </select>
 </mapper>

+ 2 - 1
teachcloud-report-business/src/main/resources/db/2、init-table-data.sql

@@ -385,4 +385,5 @@ INSERT INTO `sys_config` VALUES (22, NULL, NULL, 'teachcloud.report.login.url',
 INSERT INTO `sys_config` VALUES (23, NULL, NULL, 'teachcloud.print.host.url', '分布式印刷地址', 'http://127.0.0.1:7400', NULL, 1, 1, 1, NULL, NULL, NULL);
 INSERT INTO `sys_config` VALUES (24, NULL, NULL, 'teachcloud.print.open.callback.pwd', '分布式印刷回调密码', '123456', NULL, 1, 1, 1, NULL, NULL, NULL);
 INSERT INTO `sys_config` VALUES (25, NULL, NULL, 'sms.sign.name', '短信签名', '逸教云', NULL, 1, 1, 1, NULL, NULL, NULL);
-INSERT INTO `sys_config` VALUES (26, NULL, NULL, 'sms.tpl.code', '登录短信验证码', 'SMS_147416565', NULL, 1, 2, 1, NULL, NULL, NULL);
+INSERT INTO `sys_config` VALUES (26, NULL, NULL, 'sms.tpl.code', '登录短信验证码', 'SMS_147416565', NULL, 1, 2, 1, NULL, NULL, NULL);
+INSERT INTO `sys_config` VALUES (27, NULL, NULL, 'sys.txt.charset', 'txt文件编码', 'gbk', NULL, 1, 1, 1, NULL, NULL, NULL);