|
@@ -5,8 +5,8 @@ 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.common.bean.dto.AuthOrgInfoDto;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
+import com.qmth.teachcloud.common.contant.SpringContextHolder;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
|
import com.qmth.teachcloud.common.entity.SysOrg;
|
|
@@ -14,9 +14,6 @@ import com.qmth.teachcloud.common.entity.TSAuth;
|
|
|
import com.qmth.teachcloud.common.enums.AuthEnum;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
|
-import com.qmth.teachcloud.common.mapper.BasicSchoolMapper;
|
|
|
-import com.qmth.teachcloud.common.mapper.SysOrgMapper;
|
|
|
-import com.qmth.teachcloud.common.mapper.TSAuthMapper;
|
|
|
import com.qmth.teachcloud.common.service.*;
|
|
|
import com.qmth.teachcloud.common.util.FileStoreUtil;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
@@ -52,18 +49,12 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
@Resource
|
|
|
TSAuthService tsAuthService;
|
|
|
|
|
|
- @Resource
|
|
|
- TSAuthMapper tsAuthMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
CommonCacheService commonCacheService;
|
|
|
|
|
|
@Resource
|
|
|
BasicSchoolService basicSchoolService;
|
|
|
|
|
|
- @Resource
|
|
|
- BasicSchoolMapper basicSchoolMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
FileStoreUtil fileStoreUtil;
|
|
|
|
|
@@ -76,9 +67,6 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
@Resource
|
|
|
SysOrgService sysOrgService;
|
|
|
|
|
|
- @Resource
|
|
|
- SysOrgMapper sysOrgMapper;
|
|
|
-
|
|
|
/**
|
|
|
* 授权信息初始化
|
|
|
*
|
|
@@ -94,24 +82,20 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
&& !Objects.equals(solarProperties.getAccessKey().trim(), "")
|
|
|
&& Objects.nonNull(solarProperties.getAccessSecret())
|
|
|
&& !Objects.equals(solarProperties.getAccessSecret().trim(), "")) {//在线激活
|
|
|
- authInfoService.saveAuthInfo(appInfo, AuthEnum.ON_LINE, null);
|
|
|
+// this.authError("不支持在线激活,请联系系统管理员!");
|
|
|
+ log.error("不支持在线激活,请联系系统管理员!");
|
|
|
+ licenseForDb();
|
|
|
} else if (Objects.nonNull(solarProperties.getLicense())
|
|
|
&& !Objects.equals(solarProperties.getLicense().trim(), "")) {//离线激活
|
|
|
- authInfoService.saveAuthInfo(appInfo, AuthEnum.OFF_LINE, null);
|
|
|
+// this.authError("不支持离线激活,请联系系统管理员!");
|
|
|
+ log.error("不支持离线激活,请联系系统管理员!");
|
|
|
+ licenseForDb();
|
|
|
}
|
|
|
} 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());
|
|
|
- authInfoService.saveAuthInfo(appInfo, AuthEnum.OFF_LINE, t.getFile());
|
|
|
- }
|
|
|
- }
|
|
|
+ licenseForDb();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
}
|
|
|
return appInfo;
|
|
|
}
|
|
@@ -124,11 +108,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 = commonCacheService.schoolCache(code);
|
|
|
+ if ((Objects.nonNull(basicSchool) && Objects.nonNull(basicSchool.getEnable()) && basicSchool.getEnable() == false)
|
|
|
+ || (Objects.isNull(solarService.getAppInfo()) || solarService.getAppInfo().getControl().hasExpired())
|
|
|
+ || (Objects.isNull(solarService.getAppControl()) || solarService.getAppControl().hasExpired())) {
|
|
|
+ throw ExceptionResultEnum.AUTH_INFO_ERROR.exception();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -141,7 +125,7 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
public void updateLicense(byte[] licenseData) throws Exception {
|
|
|
AppInfo appInfo = solarService.update(licenseData);
|
|
|
if (Objects.isNull(appInfo)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("激活失败");
|
|
|
+ throw ExceptionResultEnum.AUTH_INFO_ERROR.exception("激活失败");
|
|
|
}
|
|
|
authInfoService.saveAuthInfo(appInfo, AuthEnum.OFF_LINE, licenseData);
|
|
|
}
|
|
@@ -175,6 +159,7 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
List<OrgInfo> orgInfoList = solarService.getOrgList();
|
|
|
List<TSAuth> tsAuthList = null;
|
|
|
Set<Long> orgIdsSet = null;
|
|
|
+ Map<Long, Long> orgIdsMap = null;
|
|
|
Set<BasicSchool> basicSchoolSet = null;
|
|
|
Set<SysOrg> sysOrgSet = null;
|
|
|
if (!CollectionUtils.isEmpty(orgInfoList)) {
|
|
@@ -182,10 +167,12 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
orgIdsSet = new HashSet<>();
|
|
|
basicSchoolSet = new HashSet<>();
|
|
|
sysOrgSet = new HashSet<>();
|
|
|
+ orgIdsMap = new HashMap<>();
|
|
|
}
|
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
for (OrgInfo o : orgInfoList) {
|
|
|
orgIdsSet.add(o.getId());
|
|
|
+ orgIdsMap.put(o.getId(), o.getId());
|
|
|
if (authEnum == AuthEnum.OFF_LINE) {
|
|
|
if (Objects.isNull(file)) {
|
|
|
tsAuthList.add(new TSAuth(o.getId(), solarProperties.getLicense(), authEnum, appInfo.getControl().getExpireTime()));
|
|
@@ -195,10 +182,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());
|
|
|
BasicSchool basicSchool = basicSchoolService.getOne(basicSchoolQueryWrapper);
|
|
@@ -243,20 +226,73 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
|
}
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(tsAuthList) && !CollectionUtils.isEmpty(orgIdsSet)) {
|
|
|
- QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();
|
|
|
- tsAuthQueryWrapper.lambda().in(TSAuth::getSchoolId, orgIdsSet);
|
|
|
- tsAuthService.remove(tsAuthQueryWrapper);
|
|
|
- tsAuthMapper.insertBatch(tsAuthList);
|
|
|
+ tsAuthService.remove(new QueryWrapper<TSAuth>().lambda().ge(TSAuth::getId, 0L));
|
|
|
+ tsAuthService.saveOrUpdateBatch(tsAuthList);
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(basicSchoolSet)) {
|
|
|
+ basicSchoolService.saveOrUpdateBatch(basicSchoolSet);
|
|
|
commonCacheService.removeSchoolIdCache();
|
|
|
commonCacheService.removeSchoolCodeCache();
|
|
|
- basicSchoolMapper.insertBatch(basicSchoolSet);
|
|
|
}
|
|
|
|
|
|
+ AuthInfoService authInfoService = SpringContextHolder.getBean(AuthInfoService.class);
|
|
|
+ authInfoService.updateSchoolEnable(orgIdsMap);
|
|
|
+
|
|
|
if (!CollectionUtils.isEmpty(sysOrgSet)) {
|
|
|
+ sysOrgService.saveOrUpdateBatch(sysOrgSet);
|
|
|
commonCacheService.removeOrgCache();
|
|
|
- sysOrgMapper.insertBatch(sysOrgSet);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 激活失败
|
|
|
+// *
|
|
|
+// * @param message
|
|
|
+// */
|
|
|
+// protected void authError(String message) {
|
|
|
+// List<OrgInfo> orgInfoList = solarService.getOrgList();
|
|
|
+// if (!CollectionUtils.isEmpty(orgInfoList)) {
|
|
|
+// Map<Long, Long> orgIdsMap = orgInfoList.stream().collect(Collectors.toMap(m -> m.getId(), m -> m.getId()));
|
|
|
+// this.updateSchoolEnable(orgIdsMap);
|
|
|
+// }
|
|
|
+// throw ExceptionResultEnum.AUTH_INFO_ERROR.exception(message);
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新学校启用/禁用
|
|
|
+ *
|
|
|
+ * @param orgIdsMap
|
|
|
+ */
|
|
|
+ public void updateSchoolEnable(Map<Long, Long> orgIdsMap) {
|
|
|
+ List<BasicSchool> basicSchoolList = basicSchoolService.list();
|
|
|
+ if (!CollectionUtils.isEmpty(basicSchoolList)) {
|
|
|
+ for (BasicSchool b : basicSchoolList) {
|
|
|
+ if (orgIdsMap.containsKey(b.getId())) {
|
|
|
+ b.setEnable(true);
|
|
|
+ } else {
|
|
|
+ b.setEnable(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ basicSchoolService.saveOrUpdateBatch(basicSchoolList);
|
|
|
+ commonCacheService.removeSchoolIdCache();
|
|
|
+ commonCacheService.removeSchoolCodeCache();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 强制从db更新激活信息
|
|
|
+ *
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public void licenseForDb() 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.OFF_LINE, t.getFile());
|
|
|
}
|
|
|
}
|
|
|
}
|