瀏覽代碼

修改鉴权

wangliang 2 年之前
父節點
當前提交
c1de959bae

+ 9 - 0
themis-business/src/main/java/com/qmth/themis/business/service/AuthInfoService.java

@@ -3,6 +3,8 @@ package com.qmth.themis.business.service;
 import com.qmth.boot.core.solar.model.AppInfo;
 import com.qmth.themis.business.enums.AuthEnum;
 
+import java.util.Map;
+
 /**
  * @Description: 授权信息service
  * @Param:
@@ -49,4 +51,11 @@ public interface AuthInfoService {
      * @throws Exception
      */
     public void saveAuthInfo(AppInfo appInfo, AuthEnum authEnum, byte[] file) throws Exception;
+
+    /**
+     * 更新学校启用/禁用
+     *
+     * @param orgCodesMap
+     */
+    public void updateSchoolEnable(Map<String, String> orgCodesMap);
 }

+ 22 - 22
themis-business/src/main/java/com/qmth/themis/business/service/CacheService.java

@@ -169,28 +169,28 @@ public interface CacheService {
      */
     public void removeSysConfigCache(String key);
 
-    /**
-     * 添加鉴权缓存
-     *
-     * @param code
-     * @return
-     */
-    public AuthOrgInfoDto authInfoCache(String code);
-
-    /**
-     * 修改鉴权缓存
-     *
-     * @param code
-     * @return
-     */
-    public AuthOrgInfoDto updateAuthInfoCache(String code);
-
-    /**
-     * 删除鉴权缓存
-     *
-     * @param code
-     */
-    public void removeAuthInfoCache(String code);
+//    /**
+//     * 添加鉴权缓存
+//     *
+//     * @param code
+//     * @return
+//     */
+//    public AuthOrgInfoDto authInfoCache(String code);
+//
+//    /**
+//     * 修改鉴权缓存
+//     *
+//     * @param code
+//     * @return
+//     */
+//    public AuthOrgInfoDto updateAuthInfoCache(String code);
+//
+//    /**
+//     * 删除鉴权缓存
+//     *
+//     * @param code
+//     */
+//    public void removeAuthInfoCache(String code);
 
     /**
      * 添加考试语音缓存

+ 39 - 28
themis-business/src/main/java/com/qmth/themis/business/service/impl/AuthInfoServiceImpl.java

@@ -5,10 +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.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.constant.SystemConstant;
-import com.qmth.themis.business.dao.TBOrgMapper;
-import com.qmth.themis.business.dao.TSAuthMapper;
-import com.qmth.themis.business.dto.AuthOrgInfoDto;
 import com.qmth.themis.business.entity.TBOrg;
 import com.qmth.themis.business.entity.TSAuth;
 import com.qmth.themis.business.enums.AuthEnum;
@@ -52,18 +50,12 @@ public class AuthInfoServiceImpl implements AuthInfoService {
     @Resource
     TSAuthService tsAuthService;
 
-    @Resource
-    TSAuthMapper tsAuthMapper;
-
     @Resource
     CacheService cacheService;
 
     @Resource
     TBOrgService tbOrgService;
 
-    @Resource
-    TBOrgMapper tbOrgMapper;
-
     @Resource
     QrCodeUtil qrCodeUtil;
 
@@ -118,11 +110,11 @@ public class AuthInfoServiceImpl implements AuthInfoService {
      */
     @Override
     public void appHasExpired(String code) {
-        if (Objects.nonNull(code)) {
-            AuthOrgInfoDto authOrgInfoDto = cacheService.authInfoCache(code);
-            if (Objects.isNull(authOrgInfoDto) || (Objects.nonNull(authOrgInfoDto) && authOrgInfoDto.getControl().hasExpired())) {
-                throw new BusinessException(ExceptionResultEnum.AUTH_INFO_ERROR);
-            }
+        TBOrg tbOrg = cacheService.addOrgCodeCache(code);
+        if ((Objects.nonNull(tbOrg) && Objects.nonNull(tbOrg.getEnable()) && tbOrg.getEnable().intValue() == 0)
+                || (Objects.isNull(solarService.getAppInfo()) || solarService.getAppInfo().getControl().hasExpired())
+                || (Objects.isNull(solarService.getAppControl()) || solarService.getAppControl().hasExpired())) {
+            throw new BusinessException(ExceptionResultEnum.AUTH_INFO_ERROR);
         }
     }
 
@@ -168,16 +160,16 @@ 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<TBOrg> tbOrgSet = null;
         if (!CollectionUtils.isEmpty(orgInfoList)) {
             tsAuthList = new ArrayList<>();
-            orgIdsSet = new HashSet<>();
             tbOrgSet = new HashSet<>();
+            orgCodesMap = new HashMap<>();
         }
         boolean oss = qrCodeUtil.getSysDomain().isOss();
         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()));
@@ -187,7 +179,6 @@ public class AuthInfoServiceImpl implements AuthInfoService {
             } else {
                 tsAuthList.add(new TSAuth(o.getId(), solarProperties.getAccessKey(), solarProperties.getAccessSecret(), authEnum, appInfo.getControl().getExpireTime()));
             }
-            cacheService.removeAuthInfoCache(o.getCode());
 
             QueryWrapper<TBOrg> tbOrgQueryWrapper = new QueryWrapper<>();
             tbOrgQueryWrapper.lambda().eq(TBOrg::getCode, o.getCode());
@@ -225,24 +216,44 @@ public class AuthInfoServiceImpl implements AuthInfoService {
             } else {
                 tbOrg.setAccessKey(o.getAccessKey());
                 tbOrg.setAccessSecret(o.getAccessSecret());
-                tbOrg.setLogo(o.getLogoUrl());
-                tbOrgService.saveOrUpdate(tbOrg);
-                cacheService.updateOrgCache(tbOrg.getId());
-                cacheService.updateOrgCodeCache(tbOrg.getCode());
+                tbOrg.setLogo(Objects.nonNull(o.getLogoUrl()) ? o.getLogoUrl() : tbOrg.getLogo());
+                tbOrgSet.add(tbOrg);
             }
         }
 
-        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(tbOrgSet)) {
+                tbOrgService.saveOrUpdateBatch(tbOrgSet);
                 cacheService.removeOrgIdCache();
                 cacheService.removeOrgCodeCache();
-                tbOrgMapper.insertBatch(tbOrgSet);
             }
+
+            AuthInfoService authInfoService = SpringContextHolder.getBean(AuthInfoService.class);
+            authInfoService.updateSchoolEnable(orgCodesMap);
+        }
+    }
+
+    /**
+     * 更新学校启用/禁用
+     *
+     * @param orgCodesMap
+     */
+    public void updateSchoolEnable(Map<String, String> orgCodesMap) {
+        List<TBOrg> tbOrgList = tbOrgService.list();
+        if (!CollectionUtils.isEmpty(tbOrgList)) {
+            for (TBOrg t : tbOrgList) {
+                if (orgCodesMap.containsKey(t.getCode())) {
+                    t.setEnable(1);
+                } else {
+                    t.setEnable(0);
+                }
+            }
+            tbOrgService.saveOrUpdateBatch(tbOrgList);
+            cacheService.removeOrgIdCache();
+            cacheService.removeOrgCodeCache();
         }
     }
 }

+ 33 - 33
themis-business/src/main/java/com/qmth/themis/business/service/impl/CacheServiceImpl.java

@@ -368,39 +368,39 @@ public class CacheServiceImpl implements CacheService {
 
     }
 
-    @Override
-    @Cacheable(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0", unless = "#result == null")
-    public AuthOrgInfoDto authInfoCache(String code) {
-        AppInfo appInfo = solarService.getAppInfo();
-        AuthOrgInfoDto authOrgInfoDto = null;
-        if (Objects.nonNull(appInfo)) {
-            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());
-            }
-        }
-        return authOrgInfoDto;
-    }
-
-    @Override
-    @CachePut(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0", condition = "#result != null")
-    public AuthOrgInfoDto updateAuthInfoCache(String code) {
-        AppInfo appInfo = solarService.getAppInfo();
-        AuthOrgInfoDto authOrgInfoDto = null;
-        if (Objects.nonNull(appInfo)) {
-            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());
-            }
-        }
-        return authOrgInfoDto;
-    }
-
-    @Override
-    @CacheEvict(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0")
-    public void removeAuthInfoCache(String code) {
-
-    }
+//    @Override
+//    @Cacheable(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0", unless = "#result == null")
+//    public AuthOrgInfoDto authInfoCache(String code) {
+//        AppInfo appInfo = solarService.getAppInfo();
+//        AuthOrgInfoDto authOrgInfoDto = null;
+//        if (Objects.nonNull(appInfo)) {
+//            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());
+//            }
+//        }
+//        return authOrgInfoDto;
+//    }
+//
+//    @Override
+//    @CachePut(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0", condition = "#result != null")
+//    public AuthOrgInfoDto updateAuthInfoCache(String code) {
+//        AppInfo appInfo = solarService.getAppInfo();
+//        AuthOrgInfoDto authOrgInfoDto = null;
+//        if (Objects.nonNull(appInfo)) {
+//            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());
+//            }
+//        }
+//        return authOrgInfoDto;
+//    }
+//
+//    @Override
+//    @CacheEvict(value = SystemConstant.AUTH_INFO_CACHE, key = "#p0")
+//    public void removeAuthInfoCache(String code) {
+//
+//    }
 
     /**
      * 添加考试语音缓存

+ 1 - 25
themis-task/src/main/java/com/qmth/themis/task/quartz/MqActivityJob.java

@@ -134,31 +134,6 @@ public class MqActivityJob extends QuartzJobBean {
             }
             teExamService.saveOrUpdateBatch(teExamList);
         }
-
-//        //答案补救
-//        List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.persistedAnswerBatch(null, null, null);
-//        if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
-//            for (TOeExamRecord t : tOeExamRecordList) {
-//                try {
-//                    tOeExamRecordService.saveDataByCachePersistedAnswer(t.getId());
-//                } catch (Exception e) {
-//                    log.error(SystemConstant.LOG_ERROR, e);
-//                }
-//            }
-//        }
-//
-//        //更新考生缓存
-//        List<TEExamStudent> teExamStudentList = teExamStudentService.findAlreadyExamCountZero(null, null, null, null);
-//        if (!CollectionUtils.isEmpty(teExamStudentList)) {
-//            for (TEExamStudent t : teExamStudentList) {
-//                try {
-//                    teExamStudentService.updateExamStudentByCache(t.getId());
-//                } catch (Exception e) {
-//                    log.error(SystemConstant.LOG_ERROR, e);
-//                }
-//            }
-//        }
-
         //修正考试状态
         List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.updateExamStatus();
         if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
@@ -169,6 +144,7 @@ public class MqActivityJob extends QuartzJobBean {
                         TEStudentCacheDto teStudent = cacheService.addStudentAccountCache(examStudentCacheBean.getStudentId());
                         commonService.persisted(t.getId(), teStudent.getId());
                     } catch (Exception e) {
+                        log.error(SystemConstant.LOG_ERROR, e);
                     }
                 }
             }