Commit 772893f379e6cc0e47aecfde189cbbad0e3aef2c

Authored by liujun001
1 parent b5881267

优化签到

Bsth-admin/src/main/java/com/ruoyi/in/controller/SignInController.java
@@ -29,6 +29,7 @@ import java.io.IOException; @@ -29,6 +29,7 @@ import java.io.IOException;
29 import java.text.MessageFormat; 29 import java.text.MessageFormat;
30 import java.util.Date; 30 import java.util.Date;
31 import java.util.List; 31 import java.util.List;
  32 +import java.util.Objects;
32 import java.util.concurrent.TimeUnit; 33 import java.util.concurrent.TimeUnit;
33 34
34 import static com.ruoyi.common.redispre.GlobalRedisPreName.REDIS_SIGN_IN_DRIVER_ALCOHOL_OVERFLOW; 35 import static com.ruoyi.common.redispre.GlobalRedisPreName.REDIS_SIGN_IN_DRIVER_ALCOHOL_OVERFLOW;
@@ -115,26 +116,30 @@ public class SignInController extends BaseController { @@ -115,26 +116,30 @@ public class SignInController extends BaseController {
115 return signInService.addSignIn(signIn); 116 return signInService.addSignIn(signIn);
116 } 117 }
117 118
118 - Integer num = RandomUtils.nextInt(0, 9);  
119 - if (num < 5) { 119 + Integer num = RandomUtils.nextInt(0, 10);
  120 + if (num < 3) {
120 redisCache.setCacheObject(key, num, 5, TimeUnit.MINUTES); 121 redisCache.setCacheObject(key, num, 5, TimeUnit.MINUTES);
121 log.info("[{}] sing method 走新的签到方式 :[{}] ", num, signIn); 122 log.info("[{}] sing method 走新的签到方式 :[{}] ", num, signIn);
  123 + key = StringUtils.join(REDIS_SIGN_IN_DRIVER_ALCOHOL_OVERFLOW, ConstDateUtil.FAST_YYYY_MM_DD.format(new Date()), ":", signIn.getJobCode());
  124 + Integer count = redisCache.getCacheObject(key);
122 try { 125 try {
123 return signInServiceV1.addsignInV1(signIn); 126 return signInServiceV1.addsignInV1(signIn);
124 } catch (Exception e) { 127 } catch (Exception e) {
125 - key = StringUtils.join(REDIS_SIGN_IN_DRIVER_ALCOHOL_OVERFLOW, ConstDateUtil.FAST_YYYY_MM_DD.format(new Date()), ":", signIn.getJobCode()); 128 + if (Objects.isNull(count)) {
  129 + count = 0;
  130 + } else {
  131 + count = count - 1;
  132 + }
126 if (redisCache.hasKey(key)) { 133 if (redisCache.hasKey(key)) {
127 - redisCache.setCacheObject(key, 0, 1, TimeUnit.DAYS); 134 + redisCache.setCacheObject(key, count, 1, TimeUnit.DAYS);
128 } 135 }
129 -  
130 log.error("[{}] sing method 走新的签到方式,签到失败 :[{}]", num, signIn, e); 136 log.error("[{}] sing method 走新的签到方式,签到失败 :[{}]", num, signIn, e);
131 - return AjaxResult.error("签到失败,请再测试一次");  
132 } 137 }
133 138
134 - } else {  
135 - log.info("[{}] sing method old sign :[{}]", num, signIn);  
136 - return signInService.addSignIn(signIn);  
137 } 139 }
  140 +
  141 + log.info("[{}] sing method old sign :[{}]", num, signIn);
  142 + return signInService.addSignIn(signIn);
138 } 143 }
139 144
140 // /** 145 // /**