CountUtil.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //package com.backendsys.utils;
  2. //
  3. //import com.backendsys.exception.CustException;
  4. //import com.backendsys.utils.response.ResultEnum;
  5. //import org.springframework.beans.factory.annotation.Autowired;
  6. //import org.springframework.data.redis.core.StringRedisTemplate;
  7. //import org.springframework.stereotype.Component;
  8. //
  9. //import java.util.concurrent.TimeUnit;
  10. //
  11. //@Component
  12. //public class CountUtil {
  13. //
  14. // @Autowired
  15. // private StringRedisTemplate stringRedisTemplate;
  16. //
  17. // /**
  18. // * 判断 2分钟内错误 5次,则出现提示
  19. // */
  20. // public void setErrorCount(String key, String tag) {
  21. // Integer timeout = 2;
  22. // String errKey = key + "-" + tag;
  23. // String errValue = stringRedisTemplate.opsForValue().get(errKey);
  24. // if (errValue == null) {
  25. // errValue = "1";
  26. // } else if (Integer.valueOf(errValue) >= 5) {
  27. // throw new CustException("错误次数过多,为账号安全,请等待" + timeout + "分钟后重新尝试", ResultEnum.LOCK_CREDENTIALS.getCode());
  28. // } else {
  29. // errValue = String.valueOf((Integer.valueOf(errValue) + 1));
  30. // }
  31. // stringRedisTemplate.opsForValue().set(errKey, errValue, timeout, TimeUnit.MINUTES);
  32. // }
  33. // /**
  34. // * 判断是否处于 5次的错误状态
  35. // */
  36. // public void checkErrorStatus(String key, String tag) {
  37. // Integer timeout = 2;
  38. // String errKey = key + "-" + tag;
  39. // String errValue = stringRedisTemplate.opsForValue().get(errKey);
  40. // if (errValue != null && Integer.valueOf(errValue) >= 5) {
  41. // throw new CustException("错误次数过多,为账号安全,请等待" + timeout + "分钟后重新尝试", ResultEnum.LOCK_CREDENTIALS.getCode());
  42. // }
  43. // }
  44. //
  45. //}