浏览代码

新增sop激活

wangliang 1 年之前
父节点
当前提交
56cf3f82c1
共有 22 个文件被更改,包括 952 次插入12 次删除
  1. 5 5
      pom.xml
  2. 71 0
      sop-business/src/main/java/com/qmth/sop/business/bean/result/AppInfoResult.java
  3. 56 0
      sop-business/src/main/java/com/qmth/sop/business/cache/CommonCacheService.java
  4. 119 0
      sop-business/src/main/java/com/qmth/sop/business/cache/impl/CommonCacheServiceImpl.java
  5. 136 0
      sop-business/src/main/java/com/qmth/sop/business/entity/BasicSchool.java
  6. 132 0
      sop-business/src/main/java/com/qmth/sop/business/entity/TSAuth.java
  7. 16 0
      sop-business/src/main/java/com/qmth/sop/business/mapper/BasicSchoolMapper.java
  8. 24 0
      sop-business/src/main/java/com/qmth/sop/business/mapper/TSAuthMapper.java
  9. 16 0
      sop-business/src/main/java/com/qmth/sop/business/service/BasicSchoolService.java
  10. 51 0
      sop-business/src/main/java/com/qmth/sop/business/service/TSAuthService.java
  11. 20 0
      sop-business/src/main/java/com/qmth/sop/business/service/impl/BasicSchoolServiceImpl.java
  12. 191 0
      sop-business/src/main/java/com/qmth/sop/business/service/impl/TSAuthServiceImpl.java
  13. 42 0
      sop-business/src/main/resources/db/install/sop_db.sql
  14. 5 0
      sop-business/src/main/resources/mapper/BasicSchoolMapper.xml
  15. 14 0
      sop-business/src/main/resources/mapper/TSAuthMapper.xml
  16. 4 4
      sop-common/pom.xml
  17. 2 0
      sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java
  18. 3 1
      sop-common/src/main/java/com/qmth/sop/common/enums/AuthEnum.java
  19. 19 0
      sop-server/src/main/java/com/qmth/sop/server/api/BasicSchoolController.java
  20. 19 0
      sop-server/src/main/java/com/qmth/sop/server/api/TSAuthController.java
  21. 5 0
      sop-server/src/main/java/com/qmth/sop/server/start/StartRunning.java
  22. 2 2
      sop-server/src/main/resources/application.properties

+ 5 - 5
pom.xml

@@ -121,11 +121,11 @@
 <!--                <artifactId>tools-poi</artifactId>-->
 <!--                <version>${qmth.boot.version}</version>-->
 <!--            </dependency>-->
-<!--            <dependency>-->
-<!--                <groupId>com.qmth.boot</groupId>-->
-<!--                <artifactId>core-solar</artifactId>-->
-<!--                <version>${qmth.boot.version}</version>-->
-<!--            </dependency>-->
+            <dependency>
+                <groupId>com.qmth.boot</groupId>
+                <artifactId>core-solar</artifactId>
+                <version>${qmth.boot.version}</version>
+            </dependency>
             <dependency>
                 <groupId>com.qmth.boot</groupId>
                 <artifactId>core-logging</artifactId>

+ 71 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/AppInfoResult.java

@@ -0,0 +1,71 @@
+package com.qmth.sop.business.bean.result;
+
+import com.qmth.sop.common.enums.AuthEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description: appinfo result
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2023/2/17
+ */
+public class AppInfoResult implements Serializable {
+
+    @ApiModelProperty(value = "过期时间")
+    Long expireTime;
+
+    @ApiModelProperty(value = "accessKey")
+    String accessKey;
+
+    @ApiModelProperty(value = "accessSecret")
+    String accessSecret;
+
+    @ApiModelProperty(value = "激活模式")
+    AuthEnum authMode;
+
+    public AppInfoResult() {
+
+    }
+
+    public AppInfoResult(Long expireTime, String accessKey, String accessSecret, AuthEnum authMode) {
+        this.expireTime = expireTime;
+        this.accessKey = accessKey;
+        this.accessSecret = accessSecret;
+        this.authMode = authMode;
+    }
+
+    public Long getExpireTime() {
+        return expireTime;
+    }
+
+    public void setExpireTime(Long expireTime) {
+        this.expireTime = expireTime;
+    }
+
+    public String getAccessKey() {
+        return accessKey;
+    }
+
+    public void setAccessKey(String accessKey) {
+        this.accessKey = accessKey;
+    }
+
+    public String getAccessSecret() {
+        return accessSecret;
+    }
+
+    public void setAccessSecret(String accessSecret) {
+        this.accessSecret = accessSecret;
+    }
+
+    public AuthEnum getAuthMode() {
+        return authMode;
+    }
+
+    public void setAuthMode(AuthEnum authMode) {
+        this.authMode = authMode;
+    }
+}

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

@@ -348,4 +348,60 @@ public interface CommonCacheService {
      * @param roleId
      */
     public void removeRoleCache(Long roleId);
+
+    /**
+     * 添加学校缓存
+     *
+     * @param schoolId
+     * @return
+     */
+    public BasicSchool schoolCache(Long schoolId);
+
+    /**
+     * 添加学校缓存
+     *
+     * @param code
+     * @return
+     */
+    public BasicSchool schoolCache(String code);
+
+    /**
+     * 更新学校缓存
+     *
+     * @param schoolId
+     * @return
+     */
+    public BasicSchool updateSchoolCache(Long schoolId);
+
+    /**
+     * 更新学校缓存
+     *
+     * @param code
+     * @return
+     */
+    public BasicSchool updateSchoolCache(String code);
+
+    /**
+     * 删除学校缓存
+     *
+     * @param schoolId
+     */
+    public void removeSchoolCache(Long schoolId);
+
+    /**
+     * 删除学校缓存
+     *
+     * @param code
+     */
+    public void removeSchoolCache(String code);
+
+    /**
+     * 删除学校缓存
+     */
+    public void removeSchoolIdCache();
+
+    /**
+     * 删除学校缓存
+     */
+    public void removeSchoolCodeCache();
 }

+ 119 - 0
sop-business/src/main/java/com/qmth/sop/business/cache/impl/CommonCacheServiceImpl.java

@@ -69,6 +69,9 @@ public class CommonCacheServiceImpl implements CommonCacheService {
     @Resource
     TDTablePropService tdTablePropService;
 
+    @Resource
+    BasicSchoolService basicSchoolService;
+
     /**
      * 添加用户缓存
      *
@@ -643,6 +646,122 @@ public class CommonCacheServiceImpl implements CommonCacheService {
         cacheService.evict(SystemConstant.ROLE_CACHE, String.valueOf(roleId));
     }
 
+    /**
+     * 添加学校缓存
+     *
+     * @param schoolId
+     * @return
+     */
+    @Override
+    public BasicSchool schoolCache(Long schoolId) {
+        return schoolCacheCommon(schoolId);
+    }
+
+    /**
+     * 添加学校缓存
+     *
+     * @param code
+     * @return
+     */
+    @Override
+    public BasicSchool schoolCache(String code) {
+        return schoolCacheCommon(code);
+    }
+
+    /**
+     * 更新学校缓存
+     *
+     * @param schoolId
+     * @return
+     */
+    @Override
+    public BasicSchool updateSchoolCache(Long schoolId) {
+        cacheService.evict(SystemConstant.SCHOOL_CACHE, String.valueOf(schoolId));
+        return schoolCacheCommon(schoolId);
+    }
+
+    /**
+     * 更新学校缓存
+     *
+     * @param code
+     * @return
+     */
+    @Override
+    public BasicSchool updateSchoolCache(String code) {
+        cacheService.evict(SystemConstant.SCHOOL_CODE_CACHE, code);
+        return schoolCacheCommon(code);
+    }
+
+    /**
+     * 删除学校缓存
+     *
+     * @param schoolId
+     */
+    @Override
+    public void removeSchoolCache(Long schoolId) {
+        cacheService.evict(SystemConstant.SCHOOL_CACHE, String.valueOf(schoolId));
+    }
+
+    /**
+     * 删除学校缓存
+     *
+     * @param code
+     */
+    @Override
+    public void removeSchoolCache(String code) {
+        cacheService.evict(SystemConstant.SCHOOL_CODE_CACHE, code);
+    }
+
+    /**
+     * 删除学校缓存
+     */
+    @Override
+    public void removeSchoolIdCache() {
+        cacheService.clear(SystemConstant.SCHOOL_CACHE);
+    }
+
+    /**
+     * 删除学校缓存
+     */
+    @Override
+    public void removeSchoolCodeCache() {
+        cacheService.clear(SystemConstant.SCHOOL_CODE_CACHE);
+    }
+
+    /**
+     * 学校缓存共用
+     *
+     * @param schoolId
+     * @return
+     */
+    protected BasicSchool schoolCacheCommon(Long schoolId) {
+        BasicSchool basicSchool = (BasicSchool) cacheService.get(SystemConstant.SCHOOL_CACHE, String.valueOf(schoolId));
+        if (Objects.isNull(basicSchool)) {
+            basicSchool = basicSchoolService.getById(schoolId);
+            if (Objects.nonNull(basicSchool)) {
+                cacheService.put(SystemConstant.SCHOOL_CACHE, String.valueOf(schoolId), basicSchool);
+            }
+        }
+        return basicSchool;
+    }
+
+    /**
+     * 学校缓存共用
+     *
+     * @param code
+     * @return
+     */
+    protected BasicSchool schoolCacheCommon(String code) {
+        BasicSchool basicSchool = (BasicSchool) cacheService.get(SystemConstant.SCHOOL_CODE_CACHE, code);
+        if (Objects.isNull(basicSchool)) {
+            basicSchool = basicSchoolService.getOne(new QueryWrapper<BasicSchool>().lambda().eq(BasicSchool::getCode, code));
+            if (Objects.nonNull(basicSchool)) {
+                cacheService.put(SystemConstant.SCHOOL_CODE_CACHE, code, basicSchool);
+            }
+        }
+        return basicSchool;
+    }
+
     /**
      * 角色缓存共用
      *

+ 136 - 0
sop-business/src/main/java/com/qmth/sop/business/entity/BasicSchool.java

@@ -0,0 +1,136 @@
+package com.qmth.sop.business.entity;
+
+import com.qmth.sop.common.base.BaseEntity;
+import com.qmth.sop.common.contant.SystemConstant;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 学校表
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+@ApiModel(value = "BasicSchool对象", description = "学校表")
+public class BasicSchool extends BaseEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "学校编码")
+    private String code;
+
+    @ApiModelProperty(value = "域名")
+    private String domainName;
+
+    @ApiModelProperty(value = "学校名称")
+    private String name;
+
+    @ApiModelProperty(value = "是否启用,false:停用,true:启用")
+    private Boolean enable;
+
+    @ApiModelProperty(value = "访问key")
+    private String accessKey;
+
+    @ApiModelProperty(value = "访问秘钥")
+    private String accessSecret;
+
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    @ApiModelProperty(value = "学校logo")
+    private String logo;
+
+
+    public BasicSchool() {
+
+    }
+
+    public BasicSchool(Long id, String code, String name, String accessKey, String accessSecret) {
+        this.code = code;
+        this.domainName = code;
+        this.name = name;
+        this.accessKey = accessKey;
+        this.accessSecret = accessSecret;
+        setId(id);
+        this.enable = true;
+    }
+
+    public BasicSchool(String code, String name, String accessKey, String accessSecret, String logo) {
+        this.code = code;
+        this.domainName = code;
+        this.name = name;
+        this.accessKey = accessKey;
+        this.accessSecret = accessSecret;
+        this.logo = logo;
+        setId(SystemConstant.getDbUuid());
+        this.enable = true;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getDomainName() {
+        return domainName;
+    }
+
+    public void setDomainName(String domainName) {
+        this.domainName = domainName;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+
+    public String getAccessKey() {
+        return accessKey;
+    }
+
+    public void setAccessKey(String accessKey) {
+        this.accessKey = accessKey;
+    }
+
+    public String getAccessSecret() {
+        return accessSecret;
+    }
+
+    public void setAccessSecret(String accessSecret) {
+        this.accessSecret = accessSecret;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public String getLogo() {
+        return logo;
+    }
+
+    public void setLogo(String logo) {
+        this.logo = logo;
+    }
+}

+ 132 - 0
sop-business/src/main/java/com/qmth/sop/business/entity/TSAuth.java

@@ -0,0 +1,132 @@
+package com.qmth.sop.business.entity;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.common.base.BaseEntity;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.AuthEnum;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 激活授权配置表
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+@ApiModel(value="TSAuth对象", description="激活授权配置表")
+public class TSAuth extends BaseEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "学校id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long schoolId;
+
+    @ApiModelProperty(value = "accessKey")
+    private String accessKey;
+
+    @ApiModelProperty(value = "accessSecret")
+    private String accessSecret;
+
+    @ApiModelProperty(value = "离线授权证书")
+    private String description;
+
+    @ApiModelProperty(value = "授权类型")
+    private AuthEnum type;
+
+    @ApiModelProperty(value = "过期时间")
+    private Long expireTime;
+
+    @ApiModelProperty(value = "文件数据")
+    private byte[] file;
+
+    public TSAuth() {
+
+    }
+
+    public TSAuth(Long schoolId, String accessKey, String accessSecret, AuthEnum type, Long expireTime) {
+        setId(SystemConstant.getDbUuid());
+        this.schoolId = schoolId;
+        this.accessKey = accessKey;
+        this.accessSecret = accessSecret;
+        this.type = type;
+        this.expireTime = expireTime;
+    }
+
+    public TSAuth(Long schoolId, String description, AuthEnum type, Long expireTime) {
+        setId(SystemConstant.getDbUuid());
+        this.schoolId = schoolId;
+        this.description = description;
+        this.type = type;
+        this.expireTime = expireTime;
+    }
+
+    public TSAuth(Long schoolId, byte[] file, AuthEnum type, Long expireTime) {
+        setId(SystemConstant.getDbUuid());
+        this.schoolId = schoolId;
+        this.file = file;
+        this.type = type;
+        this.expireTime = expireTime;
+    }
+
+    public Long getSchoolId() {
+        return schoolId;
+    }
+
+    public void setSchoolId(Long schoolId) {
+        this.schoolId = schoolId;
+    }
+
+    public String getAccessKey() {
+        return accessKey;
+    }
+
+    public void setAccessKey(String accessKey) {
+        this.accessKey = accessKey;
+    }
+
+    public String getAccessSecret() {
+        return accessSecret;
+    }
+
+    public void setAccessSecret(String accessSecret) {
+        this.accessSecret = accessSecret;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public AuthEnum getType() {
+        return type;
+    }
+
+    public void setType(AuthEnum type) {
+        this.type = type;
+    }
+
+    public Long getExpireTime() {
+        return expireTime;
+    }
+
+    public void setExpireTime(Long expireTime) {
+        this.expireTime = expireTime;
+    }
+
+    public byte[] getFile() {
+        return file;
+    }
+
+    public void setFile(byte[] file) {
+        this.file = file;
+    }
+}

+ 16 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/BasicSchoolMapper.java

@@ -0,0 +1,16 @@
+package com.qmth.sop.business.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.sop.business.entity.BasicSchool;
+
+/**
+ * <p>
+ * 学校表 Mapper 接口
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+public interface BasicSchoolMapper extends BaseMapper<BasicSchool> {
+
+}

+ 24 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/TSAuthMapper.java

@@ -0,0 +1,24 @@
+package com.qmth.sop.business.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.sop.business.entity.TSAuth;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * <p>
+ * 激活授权配置表 Mapper 接口
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+public interface TSAuthMapper extends BaseMapper<TSAuth> {
+
+    /**
+     * 查询最后激活信息
+     *
+     * @param authEnum
+     * @return
+     */
+    TSAuth lastAuthInfo(@Param("authEnum") String authEnum);
+}

+ 16 - 0
sop-business/src/main/java/com/qmth/sop/business/service/BasicSchoolService.java

@@ -0,0 +1,16 @@
+package com.qmth.sop.business.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.sop.business.entity.BasicSchool;
+
+/**
+ * <p>
+ * 学校表 服务类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+public interface BasicSchoolService extends IService<BasicSchool> {
+
+}

+ 51 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TSAuthService.java

@@ -0,0 +1,51 @@
+package com.qmth.sop.business.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.boot.core.solar.model.AppInfo;
+import com.qmth.sop.business.entity.TSAuth;
+import com.qmth.sop.common.enums.AuthEnum;
+
+import java.util.Map;
+
+/**
+ * <p>
+ * 激活授权配置表 服务类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+public interface TSAuthService extends IService<TSAuth> {
+
+    /**
+     * 授权信息初始化
+     *
+     * @return
+     */
+    AppInfo appInfoInit();
+
+    /**
+     * 保存授权信息
+     *
+     * @param appInfo
+     * @param authEnum
+     * @param file
+     * @throws Exception
+     */
+    public void saveAuthInfo(AppInfo appInfo, AuthEnum authEnum, byte[] file) throws Exception;
+
+    /**
+     * 更新学校启用/禁用
+     *
+     * @param orgCodesMap
+     */
+    public void updateSchoolEnable(Map<String, String> orgCodesMap);
+
+    /**
+     * 查询最后激活信息
+     *
+     * @param authEnum
+     * @return
+     */
+    TSAuth lastAuthInfo(AuthEnum authEnum);
+}

+ 20 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/BasicSchoolServiceImpl.java

@@ -0,0 +1,20 @@
+package com.qmth.sop.business.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.sop.business.entity.BasicSchool;
+import com.qmth.sop.business.mapper.BasicSchoolMapper;
+import com.qmth.sop.business.service.BasicSchoolService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 学校表 服务实现类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+@Service
+public class BasicSchoolServiceImpl extends ServiceImpl<BasicSchoolMapper, BasicSchool> implements BasicSchoolService {
+
+}

+ 191 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TSAuthServiceImpl.java

@@ -0,0 +1,191 @@
+package com.qmth.sop.business.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.core.solar.config.SolarProperties;
+import com.qmth.boot.core.solar.model.AppInfo;
+import com.qmth.boot.core.solar.model.OrgInfo;
+import com.qmth.boot.core.solar.service.SolarService;
+import com.qmth.sop.business.cache.CommonCacheService;
+import com.qmth.sop.business.entity.BasicSchool;
+import com.qmth.sop.business.entity.TSAuth;
+import com.qmth.sop.business.mapper.TSAuthMapper;
+import com.qmth.sop.business.service.BasicSchoolService;
+import com.qmth.sop.business.service.TSAuthService;
+import com.qmth.sop.common.contant.SpringContextHolder;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.AuthEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.util.*;
+
+/**
+ * <p>
+ * 激活授权配置表 服务实现类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+@Service
+public class TSAuthServiceImpl extends ServiceImpl<TSAuthMapper, TSAuth> implements TSAuthService {
+    private final static Logger log = LoggerFactory.getLogger(TSAuthServiceImpl.class);
+
+    @Resource
+    SolarProperties solarProperties;
+
+    @Resource
+    SolarService solarService;
+
+    @Resource
+    CommonCacheService commonCacheService;
+
+    @Resource
+    BasicSchoolService basicSchoolService;
+
+    /**
+     * 授权信息初始化
+     *
+     * @return
+     */
+    @Override
+    public AppInfo appInfoInit() {
+        AppInfo appInfo = null;
+        try {
+            TSAuthService tsAuthService = SpringContextHolder.getBean(TSAuthService.class);
+            appInfo = solarService.getAppInfo();
+            if (Objects.nonNull(appInfo) && Objects.nonNull(solarProperties)) {
+                if (Objects.nonNull(solarProperties.getAccessKey())
+                        && !Objects.equals(solarProperties.getAccessKey().trim(), "")
+                        && Objects.nonNull(solarProperties.getAccessSecret())
+                        && !Objects.equals(solarProperties.getAccessSecret().trim(), "")) {//在线激活
+                    tsAuthService.saveAuthInfo(appInfo, AuthEnum.ON_LINE, null);
+                } else if (Objects.nonNull(solarProperties.getLicense())
+                        && !Objects.equals(solarProperties.getLicense().trim(), "")) {//离线激活
+                    tsAuthService.saveAuthInfo(appInfo, AuthEnum.OFF_LINE, null);
+                }
+            } else {
+                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 = solarService.update(t.getFile());
+                        tsAuthService.saveAuthInfo(appInfo, AuthEnum.OFF_LINE, t.getFile());
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+        }
+        return appInfo;
+    }
+
+    /**
+     * 保存鉴权信息
+     *
+     * @param appInfo
+     * @param authEnum
+     * @param file
+     * @throws Exception
+     */
+    @Override
+    @Transactional
+    public void saveAuthInfo(AppInfo appInfo, AuthEnum authEnum, byte[] file) throws Exception {
+        List<OrgInfo> orgInfoList = solarService.getOrgList();
+        List<TSAuth> tsAuthList = null;
+        Map<String, String> orgCodesMap = null;
+        Set<BasicSchool> basicSchoolSet = null;
+        TSAuthService tsAuthService = SpringContextHolder.getBean(TSAuthService.class);
+        if (!CollectionUtils.isEmpty(orgInfoList)) {
+            tsAuthList = new ArrayList<>();
+            basicSchoolSet = new HashSet<>();
+            orgCodesMap = new HashMap<>();
+        }
+
+        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, expireTime));
+                } else {
+                    tsAuthList.add(new TSAuth(o.getId(), file, authEnum, expireTime));
+                }
+            } else {
+                tsAuthList.add(new TSAuth(o.getId(), solarProperties.getAccessKey(), solarProperties.getAccessSecret(), authEnum, expireTime));
+            }
+            QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
+            basicSchoolQueryWrapper.lambda().eq(BasicSchool::getCode, o.getCode());
+            BasicSchool basicSchool = basicSchoolService.getOne(basicSchoolQueryWrapper);
+            if (Objects.isNull(basicSchool)) {//不存在则创建学校
+                basicSchool = new BasicSchool(o.getId(), o.getCode(), o.getName(), o.getAccessKey(), o.getAccessSecret());
+                if (Objects.nonNull(o.getLogo()) && (!o.getLogo().startsWith("https:") || !o.getLogo().startsWith("http"))) {
+                    basicSchool.setLogo("data:image/png;base64," + o.getLogo());
+                } else {
+                    basicSchool.setLogo(o.getLogoUrl());
+                }
+                basicSchoolSet.add(basicSchool);
+            } else {
+                basicSchool.setAccessKey(o.getAccessKey());
+                basicSchool.setAccessSecret(o.getAccessSecret());
+                basicSchool.setLogo(Objects.nonNull(o.getLogoUrl()) ? o.getLogoUrl() : basicSchool.getLogo());
+                basicSchoolSet.add(basicSchool);
+            }
+        }
+
+        if (!CollectionUtils.isEmpty(tsAuthList) && !CollectionUtils.isEmpty(orgCodesMap)) {
+            tsAuthService.remove(new QueryWrapper<TSAuth>().lambda().ge(TSAuth::getId, 0L));
+            tsAuthService.saveOrUpdateBatch(tsAuthList);
+
+            if (!CollectionUtils.isEmpty(basicSchoolSet)) {
+                basicSchoolService.saveOrUpdateBatch(basicSchoolSet);
+                commonCacheService.removeSchoolIdCache();
+                commonCacheService.removeSchoolCodeCache();
+            }
+
+            tsAuthService.updateSchoolEnable(orgCodesMap);
+        }
+    }
+
+    /**
+     * 更新学校启用/禁用
+     *
+     * @param orgCodesMap
+     */
+    @Override
+    public void updateSchoolEnable(Map<String, String> orgCodesMap) {
+        List<BasicSchool> basicSchoolList = basicSchoolService.list();
+        if (!CollectionUtils.isEmpty(basicSchoolList)) {
+            for (BasicSchool b : basicSchoolList) {
+                if (orgCodesMap.containsKey(b.getCode())) {
+                    b.setEnable(true);
+                } else {
+                    b.setEnable(false);
+                }
+            }
+            basicSchoolService.saveOrUpdateBatch(basicSchoolList);
+            commonCacheService.removeSchoolIdCache();
+            commonCacheService.removeSchoolCodeCache();
+        }
+    }
+
+    /**
+     * 查询最后激活信息
+     *
+     * @param authEnum
+     * @return
+     */
+    @Override
+    public TSAuth lastAuthInfo(AuthEnum authEnum) {
+        return this.baseMapper.lastAuthInfo(Objects.nonNull(authEnum) ? authEnum.name() : null);
+    }
+}

+ 42 - 0
sop-business/src/main/resources/db/install/sop_db.sql

@@ -19,6 +19,28 @@ CREATE TABLE `basic_attachment` (
                                     PRIMARY KEY (`id`) USING BTREE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='所有附件记录表';
 
+-- ----------------------------
+-- Table structure for basic_school
+-- ----------------------------
+DROP TABLE IF EXISTS `basic_school`;
+CREATE TABLE `basic_school` (
+                                `id` bigint NOT NULL COMMENT '主键',
+                                `code` varchar(20) NOT NULL COMMENT '学校编码',
+                                `domain_name` varchar(20) DEFAULT NULL COMMENT '域名',
+                                `name` varchar(100) DEFAULT NULL COMMENT '学校名称',
+                                `enable` tinyint NOT NULL DEFAULT '1' COMMENT '是否启用,false:停用,true:启用',
+                                `access_key` varchar(50) DEFAULT NULL COMMENT '访问key',
+                                `access_secret` varchar(50) DEFAULT NULL COMMENT '访问秘钥',
+                                `remark` text COMMENT '备注',
+                                `create_id` bigint DEFAULT NULL COMMENT '创建人',
+                                `create_time` bigint DEFAULT NULL COMMENT '创建时间',
+                                `update_id` bigint DEFAULT NULL COMMENT '更新人',
+                                `update_time` bigint DEFAULT NULL COMMENT '更新时间',
+                                `logo` mediumtext COMMENT '学校logo',
+                                PRIMARY KEY (`id`) USING BTREE,
+                                UNIQUE KEY `code` (`code`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='学校表';
+
 -- ----------------------------
 -- Table structure for basic_sms_message
 -- ----------------------------
@@ -1719,3 +1741,23 @@ CREATE TABLE `t_g_error` (
                              `create_time` bigint DEFAULT NULL COMMENT '创建时间',
                              PRIMARY KEY (`id`) USING BTREE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='全局异常错误信息表';
+
+-- ----------------------------
+-- Table structure for t_s_auth
+-- ----------------------------
+DROP TABLE IF EXISTS `t_s_auth`;
+CREATE TABLE `t_s_auth` (
+                            `id` bigint NOT NULL COMMENT '主键',
+                            `school_id` bigint DEFAULT NULL COMMENT '学校id',
+                            `access_key` varchar(255) DEFAULT NULL COMMENT 'accessKey',
+                            `access_secret` varchar(255) DEFAULT NULL COMMENT 'accessSecret',
+                            `description` text COMMENT '离线授权证书',
+                            `type` varchar(16) NOT NULL COMMENT '授权类型',
+                            `create_id` bigint DEFAULT NULL COMMENT '创建人',
+                            `create_time` bigint DEFAULT NULL COMMENT '创建时间',
+                            `update_id` bigint DEFAULT NULL COMMENT '更新人',
+                            `update_time` bigint DEFAULT NULL COMMENT '更新时间',
+                            `expire_time` bigint DEFAULT NULL COMMENT '过期时间',
+                            `file` mediumblob COMMENT '文件数据',
+                            PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='激活授权配置表';

+ 5 - 0
sop-business/src/main/resources/mapper/BasicSchoolMapper.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.sop.business.mapper.BasicSchoolMapper">
+
+</mapper>

+ 14 - 0
sop-business/src/main/resources/mapper/TSAuthMapper.xml

@@ -0,0 +1,14 @@
+<?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.sop.business.mapper.TSAuthMapper">
+
+    <select id="lastAuthInfo" resultType="com.qmth.sop.business.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>

+ 4 - 4
sop-common/pom.xml

@@ -42,10 +42,10 @@
 <!--            <groupId>com.qmth.boot</groupId>-->
 <!--            <artifactId>tools-poi</artifactId>-->
 <!--        </dependency>-->
-<!--        <dependency>-->
-<!--            <groupId>com.qmth.boot</groupId>-->
-<!--            <artifactId>core-solar</artifactId>-->
-<!--        </dependency>-->
+        <dependency>
+            <groupId>com.qmth.boot</groupId>
+            <artifactId>core-solar</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>easyexcel</artifactId>

+ 2 - 0
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -139,6 +139,8 @@ public class SystemConstant {
     public static final String TABLE_PROP_CACHE = "table:prop:cache";
     public static final String ROLE_CACHE = "role:cache";
     public static final String USER_MENU_CACHE = "user:menu:cache";
+    public static final String SCHOOL_CACHE = "school:cache";
+    public static final String SCHOOL_CODE_CACHE = "school:code:cache";
 
     /**
      * 鉴权

+ 3 - 1
sop-common/src/main/java/com/qmth/sop/common/enums/AuthEnum.java

@@ -13,7 +13,9 @@ public enum AuthEnum {
 
     ON_LINE("在线激活"),
 
-    OFF_LINE("离线激活");
+    OFF_LINE("离线激活"),
+
+    NON_ACTIVATED("未激活");
 
     AuthEnum(String title) {
         this.title = title;

+ 19 - 0
sop-server/src/main/java/com/qmth/sop/server/api/BasicSchoolController.java

@@ -0,0 +1,19 @@
+package com.qmth.sop.server.api;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * 学校表 前端控制器
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+@RestController
+@RequestMapping("/basic-school")
+public class BasicSchoolController {
+
+}

+ 19 - 0
sop-server/src/main/java/com/qmth/sop/server/api/TSAuthController.java

@@ -0,0 +1,19 @@
+package com.qmth.sop.server.api;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * 激活授权配置表 前端控制器
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-08-07
+ */
+@RestController
+@RequestMapping("/t-sauth")
+public class TSAuthController {
+
+}

+ 5 - 0
sop-server/src/main/java/com/qmth/sop/server/start/StartRunning.java

@@ -2,6 +2,7 @@ package com.qmth.sop.server.start;
 
 import com.qmth.sop.business.activiti.service.ActivitiService;
 import com.qmth.sop.business.service.SysConfigService;
+import com.qmth.sop.business.service.TSAuthService;
 import com.qmth.sop.common.enums.TFCustomTypeEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,11 +29,15 @@ public class StartRunning implements CommandLineRunner {
     @Resource
     ActivitiService activitiService;
 
+    @Resource
+    TSAuthService tsAuthService;
+
     @Override
     public void run(String... args) throws Exception {
         log.info("服务器启动时执行 start");
         sysConfigService.selectAll();
         activitiService.createDeployment(Arrays.asList(TFCustomTypeEnum.OFFICE_SOP_FLOW));
+        tsAuthService.appInfoInit();
         log.info("服务器启动时执行 end");
     }
 

+ 2 - 2
sop-server/src/main/resources/application.properties

@@ -84,7 +84,7 @@ spring.jackson.time-zone=GMT+8
 com.qmth.logging.root-level=info
 com.qmth.logging.file-path=/Users/king/Downloads/sop-server.log
 
-#com.qmth.solar.access-key=274f823e5f59410f8b3bb6edcd8e2b6e
-#com.qmth.solar.access-secret=y7AO6W0TOdTF8HpWBwGHbp3wfIHsmUKr
+com.qmth.solar.access-key=9ed64a57627845118913229ad578939b
+com.qmth.solar.access-secret=0qtqPS9S3DnjR043nuszsrUttl6ufqvc
 
 com.qmth.sms.server=https://solar.qmth.com.cn