Commit 71818d8ddf1fb496616093daccb84da34fcda33f

Authored by liujun001
1 parent f22dd4a4

优化签到流程

Bsth-admin/src/main/java/com/ruoyi/in/controller/SignInController.java
... ... @@ -7,15 +7,18 @@ import com.ruoyi.common.core.page.TableDataInfo;
7 7 import com.ruoyi.common.core.redis.RedisCache;
8 8 import com.ruoyi.common.enums.BusinessType;
9 9 import com.ruoyi.common.exception.file.FileUploadException;
  10 +import com.ruoyi.common.utils.StringUtils;
10 11 import com.ruoyi.common.utils.poi.ExcelUtil;
11 12 import com.ruoyi.in.domain.SignIn;
12 13 import com.ruoyi.in.service.ISignInService;
13 14 import com.ruoyi.in.service.SignInServiceV1;
14 15 import com.ruoyi.pojo.response.SignInResponseVo;
  16 +import com.ruoyi.utils.ConstDateUtil;
15 17 import io.swagger.annotations.Api;
16 18 import io.swagger.annotations.ApiOperation;
17 19 import io.swagger.annotations.ApiParam;
18 20 import lombok.extern.slf4j.Slf4j;
  21 +import org.apache.commons.lang3.RandomUtils;
19 22 import org.springframework.beans.factory.annotation.Autowired;
20 23 import org.springframework.validation.annotation.Validated;
21 24 import org.springframework.web.bind.annotation.*;
... ... @@ -23,7 +26,13 @@ import org.springframework.web.bind.annotation.*;
23 26 import javax.servlet.http.HttpServletRequest;
24 27 import javax.servlet.http.HttpServletResponse;
25 28 import java.io.IOException;
  29 +import java.text.MessageFormat;
  30 +import java.util.Date;
26 31 import java.util.List;
  32 +import java.util.Objects;
  33 +import java.util.concurrent.TimeUnit;
  34 +
  35 +import static com.ruoyi.common.redispre.GlobalRedisPreName.REDIS_SIGN_IN_DRIVER_ALCOHOL_OVERFLOW;
27 36  
28 37 /**
29 38 * 签到Controller
... ... @@ -101,36 +110,36 @@ public class SignInController extends BaseController {
101 110 @PostMapping("/newAdd")
102 111 @ApiOperation("新增签到(设备传入)")
103 112 public AjaxResult addSignIn(@ApiParam @RequestBody @Validated SignIn signIn) throws FileUploadException, IOException {
104   -// String key = MessageFormat.format("sign:assignment:{0}", signIn.getJobCode());
105   -// if (redisCache.hasKey(key)) {
106   -// log.info(" sing method old sign :[{}]", signIn);
107   -// return signInService.addSignIn(signIn);
108   -// }
109   -//
110   -// Integer num = RandomUtils.nextInt(0, 10);
111   -// if (num < 3) {
112   -// redisCache.setCacheObject(key, num, 5, TimeUnit.MINUTES);
113   -// log.info("[{}] sing method 走新的签到方式 :[{}] ", num, signIn);
114   -// key = StringUtils.join(REDIS_SIGN_IN_DRIVER_ALCOHOL_OVERFLOW, ConstDateUtil.FAST_YYYY_MM_DD.format(new Date()), ":", signIn.getJobCode());
115   -// Integer count = redisCache.getCacheObject(key);
116   -// try {
  113 + String key = MessageFormat.format("sign:assignment:{0}", signIn.getJobCode());
  114 + if (redisCache.hasKey(key)) {
  115 + log.info(" sing method old sign :[{}]", signIn);
  116 + return signInService.addSignIn(signIn);
  117 + }
  118 +
  119 + Integer num = RandomUtils.nextInt(0, 10);
  120 + if (num < 6) {
  121 + redisCache.setCacheObject(key, num, 5, TimeUnit.MINUTES);
  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);
  125 + try {
117 126 return signInServiceV1.addsignInV1(signIn);
118   -// } catch (Exception e) {
119   -// if (Objects.isNull(count) || count < 1) {
120   -// count = 0;
121   -// } else {
122   -// count = count - 1;
123   -// }
124   -// if (redisCache.hasKey(key)) {
125   -// redisCache.setCacheObject(key, count, 1, TimeUnit.DAYS);
126   -// }
127   -// log.error("[{}] sing method 走新的签到方式,签到失败 :[{}]", num, signIn, e);
128   -// }
129   -//
130   -// }
131   -
132   -// log.info("[{}] sing method old sign :[{}]", num, signIn);
133   -// return signInService.addSignIn(signIn);
  127 + } catch (Exception e) {
  128 + if (Objects.isNull(count) || count < 1) {
  129 + count = 0;
  130 + } else {
  131 + count = count - 1;
  132 + }
  133 + if (redisCache.hasKey(key)) {
  134 + redisCache.setCacheObject(key, count, 1, TimeUnit.DAYS);
  135 + }
  136 + log.error("[{}] sing method 走新的签到方式,签到失败 :[{}]", num, signIn, e);
  137 + }
  138 +
  139 + }
  140 +
  141 + log.info("[{}] sing method old sign :[{}]", num, signIn);
  142 + return signInService.addSignIn(signIn);
134 143 }
135 144  
136 145 // /**
... ...