123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- //package com.backendsys.utils;
- //
- //import com.backendsys.exception.CustException;
- //import com.backendsys.utils.response.ResultEnum;
- //import org.springframework.beans.factory.annotation.Autowired;
- //import org.springframework.data.redis.core.StringRedisTemplate;
- //import org.springframework.stereotype.Component;
- //
- //import java.util.concurrent.TimeUnit;
- //
- //@Component
- //public class CountUtil {
- //
- // @Autowired
- // private StringRedisTemplate stringRedisTemplate;
- //
- // /**
- // * 判断 2分钟内错误 5次,则出现提示
- // */
- // public void setErrorCount(String key, String tag) {
- // Integer timeout = 2;
- // String errKey = key + "-" + tag;
- // String errValue = stringRedisTemplate.opsForValue().get(errKey);
- // if (errValue == null) {
- // errValue = "1";
- // } else if (Integer.valueOf(errValue) >= 5) {
- // throw new CustException("错误次数过多,为账号安全,请等待" + timeout + "分钟后重新尝试", ResultEnum.LOCK_CREDENTIALS.getCode());
- // } else {
- // errValue = String.valueOf((Integer.valueOf(errValue) + 1));
- // }
- // stringRedisTemplate.opsForValue().set(errKey, errValue, timeout, TimeUnit.MINUTES);
- // }
- // /**
- // * 判断是否处于 5次的错误状态
- // */
- // public void checkErrorStatus(String key, String tag) {
- // Integer timeout = 2;
- // String errKey = key + "-" + tag;
- // String errValue = stringRedisTemplate.opsForValue().get(errKey);
- // if (errValue != null && Integer.valueOf(errValue) >= 5) {
- // throw new CustException("错误次数过多,为账号安全,请等待" + timeout + "分钟后重新尝试", ResultEnum.LOCK_CREDENTIALS.getCode());
- // }
- // }
- //
- //}
|