|
@@ -3,6 +3,7 @@ package fcb.project.manager.base.utils;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import fdage.back.sdk.base.entity.Result;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -40,12 +41,14 @@ public class FcbUtils {
|
|
|
}
|
|
|
long timeStamp = Instant.now().getEpochSecond();
|
|
|
Instant stepOneStart = Instant.now();
|
|
|
- String redisKey = JSON.toJSONString(params) + timeStamp;
|
|
|
+ String redisKey = JSON.toJSONString(params);
|
|
|
if(redisTemplate.hasKey(redisKey)){
|
|
|
log.info("缓存中存在,直接返回");
|
|
|
- Map<String , Object> resultMp = (Map<String, Object>) redisTemplate.opsForValue().get(redisKey);
|
|
|
- return Result.success(resultMp);
|
|
|
-
|
|
|
+ String redisMapStr = (String) redisTemplate.opsForValue().get(redisKey);
|
|
|
+ if(StringUtils.isNotBlank(redisMapStr)){
|
|
|
+ Map<String , Object> resultMp = JSON.parseObject(redisMapStr , Map.class);
|
|
|
+ return Result.success(resultMp);
|
|
|
+ }
|
|
|
}
|
|
|
Instant stepOneEnd = Instant.now();
|
|
|
long stepOneDuration = Duration.between(stepOneStart , stepOneEnd).toMillis();
|
|
@@ -76,8 +79,8 @@ public class FcbUtils {
|
|
|
Map<String , Object> resultMap = new HashMap<>();
|
|
|
resultMap.put("authcode" , md5EncryptionStr);
|
|
|
resultMap.put("timeStamp" , timeStamp);
|
|
|
- //缓存一秒
|
|
|
- redisTemplate.opsForValue().set(redisKey , JSON.toJSONString(resultMap) , 1000 , TimeUnit.MILLISECONDS);
|
|
|
+ //缓存3min
|
|
|
+ redisTemplate.opsForValue().set(redisKey , JSON.toJSONString(resultMap) , 180 , TimeUnit.SECONDS);
|
|
|
Instant stepThreeEnd = Instant.now();
|
|
|
long stepThreeDuration = Duration.between(stepThreeStart , stepThreeEnd).toMillis();
|
|
|
log.info("步骤3耗时:{}" , stepThreeDuration);
|