|
@@ -1,11 +1,11 @@
|
|
|
package com.qmth.teachcloud.exchange.common.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.qmth.boot.core.cache.service.CacheService;
|
|
|
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.teachcloud.exchange.common.bean.dto.AuthOrgInfoDto;
|
|
|
import com.qmth.teachcloud.exchange.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.exchange.common.contant.SpringContextHolder;
|
|
|
import com.qmth.teachcloud.exchange.common.contant.SystemConstant;
|
|
@@ -14,11 +14,8 @@ import com.qmth.teachcloud.exchange.common.entity.TSAuth;
|
|
|
import com.qmth.teachcloud.exchange.common.enums.AuthEnum;
|
|
|
import com.qmth.teachcloud.exchange.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.exchange.common.enums.UploadFileEnum;
|
|
|
-import com.qmth.teachcloud.exchange.common.mapper.BasicSchoolMapper;
|
|
|
-import com.qmth.teachcloud.exchange.common.mapper.TSAuthMapper;
|
|
|
import com.qmth.teachcloud.exchange.common.service.AuthInfoService;
|
|
|
import com.qmth.teachcloud.exchange.common.service.BasicSchoolService;
|
|
|
-import com.qmth.teachcloud.exchange.common.service.CommonCacheService;
|
|
|
import com.qmth.teachcloud.exchange.common.service.TSAuthService;
|
|
|
import com.qmth.teachcloud.exchange.common.util.FileStoreUtil;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
@@ -54,24 +51,18 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
@Resource
|
|
|
TSAuthService tsAuthService;
|
|
|
|
|
|
- @Resource
|
|
|
- TSAuthMapper tsAuthMapper;
|
|
|
-
|
|
|
- @Resource
|
|
|
- CommonCacheService commonCacheService;
|
|
|
-
|
|
|
@Resource
|
|
|
BasicSchoolService basicSchoolService;
|
|
|
|
|
|
- @Resource
|
|
|
- BasicSchoolMapper basicSchoolMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
FileStoreUtil fileStoreUtil;
|
|
|
|
|
|
@Resource
|
|
|
DictionaryConfig dictionaryConfig;
|
|
|
|
|
|
+ @Resource
|
|
|
+ CacheService cacheService;
|
|
|
+
|
|
|
/**
|
|
|
* 授权信息初始化
|
|
|
*
|
|
@@ -118,11 +109,11 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
*/
|
|
|
@Override
|
|
|
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();
|
|
|
- }
|
|
|
+ BasicSchool basicSchool = (BasicSchool) cacheService.get(SystemConstant.SCHOOL_CODE_CACHE, code);
|
|
|
+ if ((Objects.nonNull(basicSchool) && Objects.nonNull(basicSchool.getEnable()) && !basicSchool.getEnable())
|
|
|
+ || (Objects.isNull(solarService.getAppInfo()) || solarService.getAppInfo().getControl().hasExpired())
|
|
|
+ || (Objects.isNull(solarService.getAppControl()) || solarService.getAppControl().hasExpired())) {
|
|
|
+ throw ExceptionResultEnum.AUTH_INFO_ERROR.exception();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -169,16 +160,22 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
public void saveAuthInfo(AppInfo appInfo, AuthEnum authEnum, byte[] file) throws Exception {
|
|
|
List<OrgInfo> orgInfoList = solarService.getOrgList();
|
|
|
List<TSAuth> tsAuthList = null;
|
|
|
- Set<Long> orgIdsSet = null;
|
|
|
+ Map<String, String> orgCodesMap = null;
|
|
|
Set<BasicSchool> basicSchoolSet = null;
|
|
|
if (!CollectionUtils.isEmpty(orgInfoList)) {
|
|
|
tsAuthList = new ArrayList<>();
|
|
|
- orgIdsSet = new HashSet<>();
|
|
|
+ orgCodesMap = new HashMap<>();
|
|
|
basicSchoolSet = new HashSet<>();
|
|
|
}
|
|
|
- boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
+ String config = null;
|
|
|
+ if (Objects.nonNull(dictionaryConfig.fssPublicDomain())) {
|
|
|
+ config = dictionaryConfig.fssPublicDomain().getConfig();
|
|
|
+ } else if (Objects.nonNull(dictionaryConfig.fssPrivateDomain())) {
|
|
|
+ config = dictionaryConfig.fssPrivateDomain().getConfig();
|
|
|
+ }
|
|
|
+ boolean oss = Objects.nonNull(config) && (config.startsWith(SystemConstant.OSS) || config.startsWith(SystemConstant.OSS.toUpperCase())) ? true : false;
|
|
|
for (OrgInfo o : orgInfoList) {
|
|
|
- orgIdsSet.add(o.getId());
|
|
|
+ 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()));
|
|
@@ -188,9 +185,6 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
} else {
|
|
|
tsAuthList.add(new TSAuth(o.getId(), solarProperties.getAccessKey(), solarProperties.getAccessSecret(), authEnum, appInfo.getControl().getExpireTime()));
|
|
|
}
|
|
|
- if (Objects.isNull(commonCacheService.updateAuthInfoCache(o.getCode()))) {
|
|
|
- commonCacheService.removeAuthInfoCache(o.getCode());
|
|
|
- }
|
|
|
|
|
|
QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
|
|
|
basicSchoolQueryWrapper.lambda().eq(BasicSchool::getCode, o.getCode());
|
|
@@ -198,7 +192,7 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
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"))) {
|
|
|
- String filePath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + SystemConstant.getUuid() + ".jpg";
|
|
|
+ String filePath = dictionaryConfig.fssPublicDomain().getConfig() + File.separator + SystemConstant.getUuid() + ".jpg";
|
|
|
File logoFile = new File(filePath);
|
|
|
if (!logoFile.getParentFile().exists()) {
|
|
|
// 不存在则创建父目录及子文件
|
|
@@ -222,23 +216,51 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
basicSchool.setLogo(filePath);
|
|
|
}
|
|
|
} else {
|
|
|
- basicSchool.setLogo(o.getLogo());
|
|
|
+ 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(orgIdsSet)) {
|
|
|
- QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();
|
|
|
- tsAuthQueryWrapper.lambda().in(TSAuth::getSchoolId, orgIdsSet);
|
|
|
- tsAuthService.remove(tsAuthQueryWrapper);
|
|
|
- tsAuthMapper.insertBatch(tsAuthList);
|
|
|
+ if (!CollectionUtils.isEmpty(tsAuthList) && !CollectionUtils.isEmpty(orgCodesMap)) {
|
|
|
+ tsAuthService.remove(new QueryWrapper<TSAuth>().lambda().ge(TSAuth::getId, 0L));
|
|
|
+ tsAuthService.saveOrUpdateBatch(tsAuthList);
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(basicSchoolSet)) {
|
|
|
- commonCacheService.removeSchoolIdCache();
|
|
|
- commonCacheService.removeSchoolCodeCache();
|
|
|
- basicSchoolMapper.insertBatch(basicSchoolSet);
|
|
|
+ basicSchoolService.saveOrUpdateBatch(basicSchoolSet);
|
|
|
+ cacheService.clear(SystemConstant.SCHOOL_CACHE);
|
|
|
+ cacheService.clear(SystemConstant.SCHOOL_CODE_CACHE);
|
|
|
+ }
|
|
|
+
|
|
|
+ AuthInfoService authInfoService = SpringContextHolder.getBean(AuthInfoService.class);
|
|
|
+ authInfoService.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);
|
|
|
+ }
|
|
|
+ cacheService.put(SystemConstant.SCHOOL_CACHE, String.valueOf(b.getId()), b);
|
|
|
+ cacheService.put(SystemConstant.SCHOOL_CODE_CACHE, b.getCode(), b);
|
|
|
}
|
|
|
+ basicSchoolService.saveOrUpdateBatch(basicSchoolList);
|
|
|
}
|
|
|
}
|
|
|
}
|