|
@@ -11,14 +11,27 @@ import com.qmth.distributed.print.business.mapper.TSAuthMapper;
|
|
import com.qmth.distributed.print.business.service.AuthInfoService;
|
|
import com.qmth.distributed.print.business.service.AuthInfoService;
|
|
import com.qmth.distributed.print.business.service.TSAuthService;
|
|
import com.qmth.distributed.print.business.service.TSAuthService;
|
|
import com.qmth.teachcloud.common.bean.dto.AuthOrgInfoDto;
|
|
import com.qmth.teachcloud.common.bean.dto.AuthOrgInfoDto;
|
|
|
|
+import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
|
+import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
|
+import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
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.service.BasicSchoolService;
|
|
import com.qmth.teachcloud.common.service.CommonCacheService;
|
|
import com.qmth.teachcloud.common.service.CommonCacheService;
|
|
|
|
+import com.qmth.teachcloud.common.util.FileStoreUtil;
|
|
|
|
+import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.time.LocalDateTime;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -47,6 +60,18 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
@Resource
|
|
@Resource
|
|
CommonCacheService commonCacheService;
|
|
CommonCacheService commonCacheService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ BasicSchoolService basicSchoolService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ BasicSchoolMapper basicSchoolMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ FileStoreUtil fileStoreUtil;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ DictionaryConfig dictionaryConfig;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 授权信息初始化
|
|
* 授权信息初始化
|
|
*
|
|
*
|
|
@@ -71,9 +96,10 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();
|
|
tsAuthQueryWrapper.lambda().isNotNull(TSAuth::getFile);
|
|
tsAuthQueryWrapper.lambda().isNotNull(TSAuth::getFile);
|
|
List<TSAuth> tsAuthList = tsAuthService.list(tsAuthQueryWrapper);
|
|
List<TSAuth> tsAuthList = tsAuthService.list(tsAuthQueryWrapper);
|
|
- if (Objects.nonNull(tsAuthList) && tsAuthList.size() > 0) {
|
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(tsAuthList)) {
|
|
for (TSAuth t : tsAuthList) {
|
|
for (TSAuth t : tsAuthList) {
|
|
appInfo = solarService.update(t.getFile());
|
|
appInfo = solarService.update(t.getFile());
|
|
|
|
+ log.info("appInfo:{}", JacksonUtil.parseJson(appInfo));
|
|
saveAuthInfo(appInfo, AuthEnum.OFF_LINE, t.getFile());
|
|
saveAuthInfo(appInfo, AuthEnum.OFF_LINE, t.getFile());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -106,7 +132,7 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
* @param licenseData
|
|
* @param licenseData
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public void updateLicense(byte[] licenseData) {
|
|
|
|
|
|
+ public void updateLicense(byte[] licenseData) throws Exception {
|
|
AppInfo appInfo = solarService.update(licenseData);
|
|
AppInfo appInfo = solarService.update(licenseData);
|
|
if (Objects.isNull(appInfo)) {
|
|
if (Objects.isNull(appInfo)) {
|
|
throw ExceptionResultEnum.ERROR.exception("激活失败");
|
|
throw ExceptionResultEnum.ERROR.exception("激活失败");
|
|
@@ -135,14 +161,17 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
* @param authEnum
|
|
* @param authEnum
|
|
*/
|
|
*/
|
|
@Transactional
|
|
@Transactional
|
|
- public void saveAuthInfo(AppInfo appInfo, AuthEnum authEnum, byte[] file) {
|
|
|
|
|
|
+ public void saveAuthInfo(AppInfo appInfo, AuthEnum authEnum, byte[] file) throws Exception {
|
|
List<OrgInfo> orgInfoList = solarService.getOrgList();
|
|
List<OrgInfo> orgInfoList = solarService.getOrgList();
|
|
List<TSAuth> tsAuthList = null;
|
|
List<TSAuth> tsAuthList = null;
|
|
Set<Long> orgIdsSet = null;
|
|
Set<Long> orgIdsSet = null;
|
|
- if (Objects.nonNull(orgInfoList) && orgInfoList.size() > 0) {
|
|
|
|
|
|
+ Set<BasicSchool> basicSchoolSet = null;
|
|
|
|
+ if (!CollectionUtils.isEmpty(orgInfoList)) {
|
|
tsAuthList = new ArrayList<>();
|
|
tsAuthList = new ArrayList<>();
|
|
orgIdsSet = new HashSet<>();
|
|
orgIdsSet = new HashSet<>();
|
|
|
|
+ basicSchoolSet = new HashSet<>();
|
|
}
|
|
}
|
|
|
|
+ boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
for (OrgInfo o : orgInfoList) {
|
|
for (OrgInfo o : orgInfoList) {
|
|
orgIdsSet.add(o.getId());
|
|
orgIdsSet.add(o.getId());
|
|
if (authEnum == AuthEnum.OFF_LINE) {
|
|
if (authEnum == AuthEnum.OFF_LINE) {
|
|
@@ -155,12 +184,46 @@ public class AuthInfoServiceImpl implements AuthInfoService {
|
|
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, appInfo.getControl().getExpireTime()));
|
|
}
|
|
}
|
|
commonCacheService.updateAuthInfoCache(o.getCode());
|
|
commonCacheService.updateAuthInfoCache(o.getCode());
|
|
|
|
+
|
|
|
|
+ QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ basicSchoolQueryWrapper.lambda().eq(BasicSchool::getCode, o.getCode());
|
|
|
|
+ int count = basicSchoolService.count(basicSchoolQueryWrapper);
|
|
|
|
+ if (count == 0) {//不存在则创建学校
|
|
|
|
+ BasicSchool basicSchool = new BasicSchool(o.getCode(), o.getName(), o.getAccessKey(), o.getAccessSecret());
|
|
|
|
+ String filePath = SystemConstant.TEMP_FILES_DIR + File.separator + SystemConstant.getUuid() + ".jpg";
|
|
|
|
+ File logoFile = new File(filePath);
|
|
|
|
+ if (!logoFile.getParentFile().exists()) {
|
|
|
|
+ // 不存在则创建父目录及子文件
|
|
|
|
+ logoFile.getParentFile().mkdirs();
|
|
|
|
+ logoFile.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ SystemConstant.base64ToImage(o.getLogo(), filePath);
|
|
|
|
+ if (oss) {
|
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("");
|
|
|
|
+ stringJoiner.add(UploadFileEnum.FILE.name().toLowerCase()).add(File.separator)
|
|
|
|
+ .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth())).add(File.separator)
|
|
|
|
+ .add(SystemConstant.getUuid()).add(".jpg");
|
|
|
|
+ fileStoreUtil.ossUpload(stringJoiner.toString(), logoFile, DigestUtils.md5Hex(new FileInputStream(logoFile)), UploadFileEnum.FILE.getFssType());
|
|
|
|
+ logoFile.delete();
|
|
|
|
+ basicSchool.setLogo(fileStoreUtil.getPrivateUrl(stringJoiner.toString(), UploadFileEnum.FILE.getFssType()));
|
|
|
|
+ } else {
|
|
|
|
+ basicSchool.setLogo(filePath);
|
|
|
|
+ }
|
|
|
|
+ basicSchoolSet.add(basicSchool);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if (Objects.nonNull(tsAuthList) && tsAuthList.size() > 0 && Objects.nonNull(orgIdsSet) && orgIdsSet.size() > 0) {
|
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(tsAuthList) && !CollectionUtils.isEmpty(orgIdsSet)) {
|
|
QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<TSAuth> tsAuthQueryWrapper = new QueryWrapper<>();
|
|
tsAuthQueryWrapper.lambda().in(TSAuth::getSchoolId, orgIdsSet);
|
|
tsAuthQueryWrapper.lambda().in(TSAuth::getSchoolId, orgIdsSet);
|
|
tsAuthService.remove(tsAuthQueryWrapper);
|
|
tsAuthService.remove(tsAuthQueryWrapper);
|
|
tsAuthMapper.insertBatch(tsAuthList);
|
|
tsAuthMapper.insertBatch(tsAuthList);
|
|
|
|
+
|
|
|
|
+ if (!CollectionUtils.isEmpty(basicSchoolSet)) {
|
|
|
|
+ basicSchoolMapper.insertBatch(basicSchoolSet);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|