deason 2 жил өмнө
parent
commit
b0a45431d2

+ 29 - 33
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java

@@ -30,6 +30,7 @@ import cn.com.qmth.examcloud.core.basic.service.cache.SystemPropertyCache;
 import cn.com.qmth.examcloud.core.basic.service.impl.OrgServiceImpl;
 import cn.com.qmth.examcloud.reports.commons.bean.AdminOperateReport;
 import cn.com.qmth.examcloud.reports.commons.util.ReportsUtil;
+import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
@@ -69,13 +70,8 @@ import javax.imageio.ImageIO;
 import javax.persistence.criteria.Predicate;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
 import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -93,8 +89,8 @@ import java.util.stream.Stream;
 @Api(tags = "机构相关接口")
 @RequestMapping("${$rmp.ctr.basic}/org")
 public class OrgController extends ControllerSupport {
-	
-	private final static long LOG_FILE_CACHE_AGE=2592000L;
+
+    private final static long LOG_FILE_CACHE_AGE = 2592000L;
 
     @Autowired
     OrgCache orgCache;
@@ -660,7 +656,7 @@ public class OrgController extends ControllerSupport {
     public Map<String, String> getOrgPropertiesByGroupWithCache(@PathVariable Long orgId,
                                                                 @PathVariable String propertyGroupId) {
 
-        String redisKey = "PROPERTIES_BY_GROUP:" + orgId + ":" + propertyGroupId;
+        String redisKey = CacheConstants.CACHE_B_ORG_PROP_LIST + orgId + ":" + propertyGroupId;
         @SuppressWarnings("unchecked")
         Map<String, String> properties = redisClient.get(redisKey, Map.class);
         if (null != properties) {
@@ -732,10 +728,10 @@ public class OrgController extends ControllerSupport {
             env.setRootOrgId(orgEntity.getId().toString());
             env.setRootOrgDomain(orgEntity.getDomainName());
             env.setExt1(propertyGroupId);
-            pi = FileStorageUtil.saveFile("orgPropertiesByOrgId", env, file, null,0L);
-            
+            pi = FileStorageUtil.saveFile("orgPropertiesByOrgId", env, file, null, 0L);
+
             urlList.add(pi.getUrl());
-            pi = FileStorageUtil.saveFile("orgPropertiesByOrgDomain", env, file, null,0L);
+            pi = FileStorageUtil.saveFile("orgPropertiesByOrgDomain", env, file, null, 0L);
             urlList.add(pi.getUrl());
 
             return urlList;
@@ -1132,7 +1128,7 @@ public class OrgController extends ControllerSupport {
         if (CollectionUtils.isNotEmpty(relatedPropertyGroupIdList)) {
             for (String propertyGroupId : relatedPropertyGroupIdList) {
                 // 删除缓存
-                String redisKey = "PROPERTIES_BY_GROUP:" + orgId + ":" + propertyGroupId;
+                String redisKey = CacheConstants.CACHE_B_ORG_PROP_LIST + orgId + ":" + propertyGroupId;
                 redisClient.delete(redisKey);
 
                 // 上传upyun
@@ -1366,7 +1362,7 @@ public class OrgController extends ControllerSupport {
         FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
         env.setFileSuffix(fileSuffix);
         env.setRootOrgId(orgEntity.getRootId().toString());
-        YunPathInfo pi = FileStorageUtil.saveFile("orgLogo", env, storeLocation, null,LOG_FILE_CACHE_AGE);
+        YunPathInfo pi = FileStorageUtil.saveFile("orgLogo", env, storeLocation, null, LOG_FILE_CACHE_AGE);
         String url = pi.getUrl();
 
         OrgPropertyEntity logoFileUrlEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,
@@ -1382,27 +1378,27 @@ public class OrgController extends ControllerSupport {
         ReportsUtil.report(new AdminOperateReport(accessUser.getRootOrgId(), accessUser.getUserId(), AdminOperateType.TYPE2.getDesc(), null));
         return url;
     }
-    
+
     private void checkPicSize(File image) throws FileNotFoundException, IOException {
-    	BufferedImage sourceImg =ImageIO.read(new FileInputStream(image));
-    	int w=sourceImg.getWidth();
-    	int h=sourceImg.getHeight();
-    	BigDecimal bw = new BigDecimal(w);
-    	BigDecimal bh = new BigDecimal(h);
-    	double ret = bw.divide(bh,1, BigDecimal.ROUND_HALF_UP).doubleValue();
-    	if(ret!=1.5) {
-    		throw new StatusException("图片宽高比例必须是3:2");
-    	}
-    	if(w<1200||w>2000) {
-    		throw new StatusException("图片宽度必须在1200px-2000px");
-    	}
+        BufferedImage sourceImg = ImageIO.read(new FileInputStream(image));
+        int w = sourceImg.getWidth();
+        int h = sourceImg.getHeight();
+        BigDecimal bw = new BigDecimal(w);
+        BigDecimal bh = new BigDecimal(h);
+        double ret = bw.divide(bh, 1, BigDecimal.ROUND_HALF_UP).doubleValue();
+        if (ret != 1.5) {
+            throw new StatusException("图片宽高比例必须是3:2");
+        }
+        if (w < 1200 || w > 2000) {
+            throw new StatusException("图片宽度必须在1200px-2000px");
+        }
     }
-    
+
     @ApiOperation(value = "导入考生端登录界面图片")
     @PostMapping("importClientBgPicture/{orgId}")
     @Transactional
     public String importClientBgPicture(@PathVariable Long orgId, HttpServletRequest request,
-                             @RequestParam CommonsMultipartFile file) throws IOException {
+                                        @RequestParam CommonsMultipartFile file) throws IOException {
 
         OrgEntity orgEntity = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
         if (null == orgEntity) {
@@ -1415,7 +1411,7 @@ public class OrgController extends ControllerSupport {
         File storeLocation = fileItem.getStoreLocation();
         String name = file.getOriginalFilename();
 
-        if (1*1024*1024 < storeLocation.length()) {
+        if (1 * 1024 * 1024 < storeLocation.length()) {
             throw new StatusException("140082", "文件过大");
         }
 
@@ -1439,7 +1435,7 @@ public class OrgController extends ControllerSupport {
         FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
         env.setFileSuffix(fileSuffix);
         env.setRootOrgId(orgEntity.getRootId().toString());
-        YunPathInfo pi = FileStorageUtil.saveFile("client_bg_picture", env, storeLocation, null,LOG_FILE_CACHE_AGE);
+        YunPathInfo pi = FileStorageUtil.saveFile("client_bg_picture", env, storeLocation, null, LOG_FILE_CACHE_AGE);
         String url = pi.getUrl();
 
         OrgPropertyEntity logoFileUrlEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,
@@ -1472,7 +1468,7 @@ public class OrgController extends ControllerSupport {
         File storeLocation = fileItem.getStoreLocation();
         String name = file.getOriginalFilename();
 
-        if ( 2048*1024 < storeLocation.length()) {
+        if (2048 * 1024 < storeLocation.length()) {
             throw new StatusException("140082", "文件过大");
         }
 
@@ -1620,7 +1616,7 @@ public class OrgController extends ControllerSupport {
         FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
         env.setFileSuffix(fileSuffix);
         env.setRootOrgId(orgEntity.getRootId().toString());
-        YunPathInfo pi = FileStorageUtil.saveFile("orgLogo", env, storeLocation, null,LOG_FILE_CACHE_AGE);
+        YunPathInfo pi = FileStorageUtil.saveFile("orgLogo", env, storeLocation, null, LOG_FILE_CACHE_AGE);
         String url = pi.getUrl();
 
         OrgPropertyEntity logoFileUrlEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,

+ 4 - 5
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/GeetestSessionImpl.java

@@ -6,6 +6,7 @@
 package cn.com.qmth.examcloud.core.basic.service.impl;
 
 import cn.com.qmth.examcloud.starters.greetest.service.GeetestSessionManager;
+import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -16,26 +17,24 @@ import org.springframework.stereotype.Service;
 @Service
 public class GeetestSessionImpl implements GeetestSessionManager {
 
-    private static final String CACHE_KEY_GEETEST = "B_GEETEST:GT_%s";// 极验“验证码”缓存KEY
-
     @Autowired
     private RedisClient redisClient;
 
     @Override
     public void setSession(String key, Boolean status) {
-        final String cacheKeyGeetest = String.format(CACHE_KEY_GEETEST, key);
+        final String cacheKeyGeetest = CacheConstants.CACHE_B_GEETEST_STATUS + key;
         redisClient.set(cacheKeyGeetest, status, 60);// N秒
     }
 
     @Override
     public Boolean getSession(String key) {
-        final String cacheKeyGeetest = String.format(CACHE_KEY_GEETEST, key);
+        final String cacheKeyGeetest = CacheConstants.CACHE_B_GEETEST_STATUS + key;
         return redisClient.get(cacheKeyGeetest, Boolean.class);
     }
 
     @Override
     public void removeSession(String key) {
-        final String cacheKeyGeetest = String.format(CACHE_KEY_GEETEST, key);
+        final String cacheKeyGeetest = CacheConstants.CACHE_B_GEETEST_STATUS + key;
         redisClient.delete(cacheKeyGeetest);
     }
 

+ 3 - 4
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/UserDataRuleServiceImpl.java

@@ -19,6 +19,7 @@ import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
 import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamMapsReq;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamMapsResp;
+import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -38,8 +39,6 @@ public class UserDataRuleServiceImpl implements UserDataRuleService {
 
     private static final Logger LOG = LoggerFactory.getLogger(UserDataRuleServiceImpl.class);
 
-    private static final String DATA_RULE_CACHE_KEY = "$DATA_RULE:%s_%s";//“数据权限”的缓存KEY规则
-
     private static final int DATA_RULE_CACHE_TIMEOUT = 600;// 过期时间(秒)
 
     private static final long DEFAULT_ID = -1L;// 为-1时,代表“全部”
@@ -418,7 +417,7 @@ public class UserDataRuleServiceImpl implements UserDataRuleService {
             throw new StatusException("400400", "权限类型不能为空!");
         }
 
-        String cacheKey = String.format(DATA_RULE_CACHE_KEY, userId, type.name());
+        String cacheKey = CacheConstants.CACHE_B_DATA_RULE + userId + "_" + type.name();
         UserDataRuleCacheBean cacheBean = redisClient.get(cacheKey, UserDataRuleCacheBean.class);
         if (cacheBean != null) {
             return cacheBean;
@@ -448,7 +447,7 @@ public class UserDataRuleServiceImpl implements UserDataRuleService {
     }
 
     private void clearUserDataRuleCache(Long userId, DataRuleType type) {
-        String cacheKey = String.format(DATA_RULE_CACHE_KEY, userId, type.name());
+        String cacheKey = CacheConstants.CACHE_B_DATA_RULE + userId + "_" + type.name();
         redisClient.delete(cacheKey);
     }
 

+ 6 - 11
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/VerifyCodeServiceImpl.java

@@ -17,6 +17,7 @@ import cn.com.qmth.examcloud.reports.commons.bean.OnlineStudentReport;
 import cn.com.qmth.examcloud.reports.commons.bean.OperateReport;
 import cn.com.qmth.examcloud.reports.commons.enums.OperateContent;
 import cn.com.qmth.examcloud.reports.commons.util.ReportsUtil;
+import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang3.StringUtils;
@@ -33,12 +34,6 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
 
     private static final Logger LOG = LoggerFactory.getLogger(VerifyCodeServiceImpl.class);
 
-    private static final String CACHE_KEY_VERIFY_CODE = "B_VERIFY_CODE:%s_%s";// “验证码”缓存KEY
-
-    private static final String CACHE_KEY_VERIFY_CODE_LIMIT = "B_VERIFY_CODE_LIMIT:%s_%s";// “验证码限流”缓存KEY
-
-    private static final String CACHE_KEY_VERIFY_CODE_RESOURCE = "B_VERIFY_CODE_RESOURCE:%s";// “验证码资源标识”缓存KEY
-
     @Autowired
     private LoginRuleService loginRuleService;
 
@@ -98,7 +93,7 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
      */
     @Override
     public String verifyCodeGenerate(Long rootOrgId, String accountValue) {
-        final String cacheKeyVerifyCodeLimit = String.format(CACHE_KEY_VERIFY_CODE_LIMIT, rootOrgId, accountValue);
+        final String cacheKeyVerifyCodeLimit = CacheConstants.CACHE_B_VERIFY_CODE_LIMIT + rootOrgId + "_" + accountValue;
         Boolean limit = redisClient.get(cacheKeyVerifyCodeLimit, Boolean.class);
         if (limit != null) {
             throw new StatusException("500", "操作太频繁,请稍后重试!");
@@ -115,7 +110,7 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
         cacheBean.setUuid(uuid);
         cacheBean.setVerifyCode(result.getResult());
 
-        final String cacheKeyVerifyCode = String.format(CACHE_KEY_VERIFY_CODE, rootOrgId, accountValue);
+        final String cacheKeyVerifyCode = CacheConstants.CACHE_B_VERIFY_CODE + rootOrgId + "_" + accountValue;
         redisClient.set(cacheKeyVerifyCode, cacheBean, 60);// N秒
 
         return uuid + base64;
@@ -150,13 +145,13 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
             throw new StatusException("403002", "当前机构登录被禁用");
         }
 
-        final String cacheKeyVerifyCode = String.format(CACHE_KEY_VERIFY_CODE, info.getRootOrgId(), info.getAccountValue());
+        final String cacheKeyVerifyCode = CacheConstants.CACHE_B_VERIFY_CODE + info.getRootOrgId() + "_" + info.getAccountValue();
         VerifyCodeCacheBean cacheBean = redisClient.get(cacheKeyVerifyCode, VerifyCodeCacheBean.class);
         if (cacheBean == null) {
             throw new StatusException("400", "验证码错误或已过期,请重试!");
         }
 
-        final String cacheKeyVerifyCodeResource = String.format(CACHE_KEY_VERIFY_CODE_RESOURCE, cacheBean.getUuid());
+        final String cacheKeyVerifyCodeResource = CacheConstants.CACHE_B_VERIFY_CODE_RESOURCE + cacheBean.getUuid();
         Boolean resource = redisClient.get(cacheKeyVerifyCodeResource, Boolean.class);
         if (resource == null) {
             LOG.warn(String.format("accountValue = %s, uuid = %s, Real uuid = %s", info.getAccountValue(), info.getUuid(), cacheBean.getUuid()));
@@ -199,7 +194,7 @@ public class VerifyCodeServiceImpl implements VerifyCodeService {
             return;
         }
 
-        final String cacheKeyVerifyCodeResource = String.format(CACHE_KEY_VERIFY_CODE_RESOURCE, uuid);
+        final String cacheKeyVerifyCodeResource = CacheConstants.CACHE_B_VERIFY_CODE_RESOURCE + uuid;
         redisClient.set(cacheKeyVerifyCodeResource, true, 60);// N秒
     }