Forráskód Böngészése

加入系统授权配置

wangliang 3 éve
szülő
commit
8be8faafc2

+ 19 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TSAuth.java

@@ -42,6 +42,9 @@ public class TSAuth extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "过期时间")
     private Long expireTime;
 
+    @ApiModelProperty(value = "文件数据")
+    private byte[] file;
+
     public TSAuth() {
 
     }
@@ -63,6 +66,22 @@ public class TSAuth extends BaseEntity implements Serializable {
         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 byte[] getFile() {
+        return file;
+    }
+
+    public void setFile(byte[] file) {
+        this.file = file;
+    }
+
     public Long getExpireTime() {
         return expireTime;
     }

+ 9 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/AuthInfoService.java

@@ -21,7 +21,14 @@ public interface AuthInfoService {
     /**
      * app是否过期
      *
-     * @param schoolId
+     * @param code
      */
-    void appHasExpired(Long schoolId);
+    void appHasExpired(String code);
+
+    /**
+     * 离线激活
+     *
+     * @param licenseData
+     */
+    void updateLicense(byte[] licenseData);
 }

+ 37 - 9
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/AuthInfoServiceImpl.java

@@ -58,10 +58,20 @@ public class AuthInfoServiceImpl implements AuthInfoService {
                         && !Objects.equals(solarProperties.getAccessKey().trim(), "")
                         && Objects.nonNull(solarProperties.getAccessSecret())
                         && !Objects.equals(solarProperties.getAccessSecret().trim(), "")) {//在线激活
-                    saveAuthInfo(appInfo, AuthEnum.ON_LINE);
+                    saveAuthInfo(appInfo, AuthEnum.ON_LINE, null);
                 } else if (Objects.nonNull(solarProperties.getLicense())
                         && !Objects.equals(solarProperties.getLicense().trim(), "")) {//离线激活
-                    saveAuthInfo(appInfo, AuthEnum.OFF_LINE);
+                    saveAuthInfo(appInfo, AuthEnum.OFF_LINE, null);
+                }
+            } else {
+                QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();
+                tsAuthQueryWrapper.lambda().isNotNull(TSAuth::getFile);
+                List<TSAuth> tsAuthList = tsAuthService.list(tsAuthQueryWrapper);
+                if (Objects.nonNull(tsAuthList) && tsAuthList.size() > 0) {
+                    for (TSAuth t : tsAuthList) {
+                        appInfo = solarService.update(t.getFile());
+                        saveAuthInfo(appInfo, AuthEnum.OFF_LINE, t.getFile());
+                    }
                 }
             }
         } catch (Exception e) {
@@ -73,19 +83,33 @@ public class AuthInfoServiceImpl implements AuthInfoService {
     /**
      * app是否过期
      *
-     * @param schoolId
+     * @param code
      * @return
      */
     @Override
-    public void appHasExpired(Long schoolId) {
-        if (Objects.nonNull(schoolId)) {
-            AuthOrgInfoDto authOrgInfoDto = commonCacheService.authInfoCache(schoolId);
+    public void appHasExpired(String code) {
+        if (Objects.nonNull(code)) {
+            AuthOrgInfoDto authOrgInfoDto = commonCacheService.authInfoCache(code);
             if (Objects.isNull(authOrgInfoDto) || (Objects.nonNull(authOrgInfoDto) && authOrgInfoDto.getControl().hasExpired())) {
                 throw ExceptionResultEnum.AUTH_INFO_ERROR.exception();
             }
         }
     }
 
+    /**
+     * 离线激活
+     *
+     * @param licenseData
+     */
+    @Override
+    public void updateLicense(byte[] licenseData) {
+        AppInfo appInfo = solarService.update(licenseData);
+        if (Objects.isNull(appInfo)) {
+            throw ExceptionResultEnum.ERROR.exception("激活失败");
+        }
+        saveAuthInfo(appInfo, AuthEnum.OFF_LINE, licenseData);
+    }
+
     /**
      * 保存鉴权信息
      *
@@ -93,7 +117,7 @@ public class AuthInfoServiceImpl implements AuthInfoService {
      * @param authEnum
      */
     @Transactional
-    protected void saveAuthInfo(AppInfo appInfo, AuthEnum authEnum) {
+    protected void saveAuthInfo(AppInfo appInfo, AuthEnum authEnum, byte[] file) {
         List<OrgInfo> orgInfoList = solarService.getOrgList();
         List<TSAuth> tsAuthList = null;
         Set<Long> orgIdsSet = null;
@@ -104,11 +128,15 @@ public class AuthInfoServiceImpl implements AuthInfoService {
         for (OrgInfo o : orgInfoList) {
             orgIdsSet.add(o.getId());
             if (authEnum == AuthEnum.OFF_LINE) {
-                tsAuthList.add(new TSAuth(o.getId(), solarProperties.getLicense(), authEnum, appInfo.getControl().getExpireTime()));
+                if (Objects.isNull(file)) {
+                    tsAuthList.add(new TSAuth(o.getId(), solarProperties.getLicense(), authEnum, appInfo.getControl().getExpireTime()));
+                } else {
+                    tsAuthList.add(new TSAuth(o.getId(), file, authEnum, appInfo.getControl().getExpireTime()));
+                }
             } else {
                 tsAuthList.add(new TSAuth(o.getId(), solarProperties.getAccessKey(), solarProperties.getAccessSecret(), authEnum, appInfo.getControl().getExpireTime()));
             }
-            commonCacheService.updateAuthInfoCache(o.getId());
+            commonCacheService.updateAuthInfoCache(o.getCode());
         }
         if (Objects.nonNull(tsAuthList) && tsAuthList.size() > 0 && Objects.nonNull(orgIdsSet) && orgIdsSet.size() > 0) {
             QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();

+ 46 - 4
distributed-print/src/main/java/com/qmth/distributed/print/api/TSAuthController.java

@@ -3,22 +3,30 @@ package com.qmth.distributed.print.api;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.core.solar.crypto.AppLicenseUtil;
 import com.qmth.distributed.print.business.bean.dto.TSAuthDto;
+import com.qmth.distributed.print.business.service.AuthInfoService;
+import com.qmth.teachcloud.common.bean.dto.AuthOrgInfoDto;
 import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.entity.BasicSchool;
+import com.qmth.teachcloud.common.service.CommonCacheService;
+import com.qmth.teachcloud.common.util.Result;
+import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.common.util.ServletUtil;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
+import io.swagger.annotations.*;
 import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Objects;
 
 /**
  * <p>
@@ -35,6 +43,12 @@ import java.io.ByteArrayInputStream;
 public class TSAuthController {
     private final static Logger log = LoggerFactory.getLogger(TSAuthController.class);
 
+    @Resource
+    AuthInfoService authInfoService;
+
+    @Resource
+    CommonCacheService commonCacheService;
+
     @ApiOperation(value = "导出硬件信息")
     @ApiResponses({@ApiResponse(code = 200, message = "导出硬件信息", response = TSAuthDto.class)})
     @RequestMapping(value = "/export/device/info", method = RequestMethod.POST)
@@ -47,4 +61,32 @@ public class TSAuthController {
             log.error(SystemConstant.LOG_ERROR, e);
         }
     }
+
+    @ApiOperation(value = "离线激活")
+    @ApiResponses({@ApiResponse(code = 200, message = "授权配置信息", response = TSAuthDto.class)})
+    @RequestMapping(value = "/offline/activation", method = RequestMethod.POST)
+    public Result offlineActivation(@ApiParam(value = "上传文件", required = true) @RequestParam(required = true) MultipartFile file) {
+        try {
+            authInfoService.updateLicense(file.getBytes());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return ResultUtil.ok(true);
+    }
+
+    @ApiOperation(value = "查询激活信息")
+    @ApiResponses({@ApiResponse(code = 200, message = "授权配置信息", response = TSAuthDto.class)})
+    @RequestMapping(value = "/select", method = RequestMethod.POST)
+    public Result select() {
+        Long schoolId = SystemConstant.getHeadOrUserSchoolId();
+        Long expireTime = null;
+        if (Objects.nonNull(schoolId)) {
+            BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
+            AuthOrgInfoDto authOrgInfoDto = commonCacheService.authInfoCache(basicSchool.getCode());
+            if (Objects.nonNull(authOrgInfoDto) && Objects.nonNull(authOrgInfoDto.getControl())) {
+                expireTime = authOrgInfoDto.getControl().getExpireTime();
+            }
+        }
+        return ResultUtil.ok(expireTime);
+    }
 }

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/auth/DistributedPrintAuthenticationService.java

@@ -121,7 +121,7 @@ public class DistributedPrintAuthenticationService implements AuthorizationServi
             return true;
         }
         if (Objects.nonNull(authBean.getSchool())) {
-            authInfoService.appHasExpired(authBean.getSchool().getId());
+            authInfoService.appHasExpired(authBean.getSchool().getCode());
         }
         //系统公用接口不拦截
         Set<String> sysUrls = commonCacheService.privilegeUrlCache(PrivilegePropertyEnum.SYS, SystemConstant.getHeadOrUserSchoolId());

+ 6 - 6
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/CommonCacheService.java

@@ -278,23 +278,23 @@ public interface CommonCacheService {
     /**
      * 添加鉴权缓存
      *
-     * @param id
+     * @param code
      * @return
      */
-    public AuthOrgInfoDto authInfoCache(Long id);
+    public AuthOrgInfoDto authInfoCache(String code);
 
     /**
      * 修改鉴权缓存
      *
-     * @param id
+     * @param code
      * @return
      */
-    public AuthOrgInfoDto updateAuthInfoCache(Long id);
+    public AuthOrgInfoDto updateAuthInfoCache(String code);
 
     /**
      * 删除鉴权缓存
      *
-     * @param id
+     * @param code
      */
-    public void removeAuthInfoCache(Long id);
+    public void removeAuthInfoCache(String code);
 }

+ 5 - 5
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/CommonCacheServiceImpl.java

@@ -439,11 +439,11 @@ public class CommonCacheServiceImpl implements CommonCacheService {
 
     @Override
     @Cacheable(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0", unless = "#result == null")
-    public AuthOrgInfoDto authInfoCache(Long id) {
+    public AuthOrgInfoDto authInfoCache(String code) {
         AppInfo appInfo = solarService.getAppInfo();
         AuthOrgInfoDto authOrgInfoDto = null;
         if (Objects.nonNull(appInfo)) {
-            List<OrgInfo> orgInfoList = solarService.getOrgList().stream().filter(s -> s.getId().longValue() == id.longValue()).collect(Collectors.toList());
+            List<OrgInfo> orgInfoList = solarService.getOrgList().stream().filter(s -> Objects.equals(s.getCode(), code)).collect(Collectors.toList());
             if (Objects.nonNull(orgInfoList) && orgInfoList.size() > 0) {
                 authOrgInfoDto = new AuthOrgInfoDto(orgInfoList.get(0), appInfo.getControl());
             }
@@ -453,11 +453,11 @@ public class CommonCacheServiceImpl implements CommonCacheService {
 
     @Override
     @CachePut(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0", unless = "#result == null")
-    public AuthOrgInfoDto updateAuthInfoCache(Long id) {
+    public AuthOrgInfoDto updateAuthInfoCache(String code) {
         AppInfo appInfo = solarService.getAppInfo();
         AuthOrgInfoDto authOrgInfoDto = null;
         if (Objects.nonNull(appInfo)) {
-            List<OrgInfo> orgInfoList = solarService.getOrgList().stream().filter(s -> s.getId().longValue() == id.longValue()).collect(Collectors.toList());
+            List<OrgInfo> orgInfoList = solarService.getOrgList().stream().filter(s -> Objects.equals(s.getCode(), code)).collect(Collectors.toList());
             if (Objects.nonNull(orgInfoList) && orgInfoList.size() > 0) {
                 authOrgInfoDto = new AuthOrgInfoDto(orgInfoList.get(0), appInfo.getControl());
             }
@@ -467,7 +467,7 @@ public class CommonCacheServiceImpl implements CommonCacheService {
 
     @Override
     @CacheEvict(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0")
-    public void removeAuthInfoCache(Long id) {
+    public void removeAuthInfoCache(String code) {
 
     }
 }