he2802 1 vuosi sitten
vanhempi
commit
e1e4b89cd1

+ 16 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserLoginErrorServiceImpl.java

@@ -1,12 +1,16 @@
 package com.zhongzheng.modules.user.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.common.utils.ip.IpUtils;
 import com.zhongzheng.modules.exam.domain.ExamKnowledge;
+import com.zhongzheng.modules.system.service.ISysConfigService;
 import com.zhongzheng.modules.user.bo.UserLoginErrorAddBo;
 import com.zhongzheng.modules.user.bo.UserLoginErrorEditBo;
 import com.zhongzheng.modules.user.bo.UserLoginErrorQueryBo;
@@ -14,6 +18,7 @@ import com.zhongzheng.modules.user.domain.UserLoginError;
 import com.zhongzheng.modules.user.mapper.UserLoginErrorMapper;
 import com.zhongzheng.modules.user.service.IUserLoginErrorService;
 import com.zhongzheng.modules.user.vo.UserLoginErrorVo;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -34,6 +39,9 @@ import java.util.stream.Collectors;
 @Service
 public class UserLoginErrorServiceImpl extends ServiceImpl<UserLoginErrorMapper, UserLoginError> implements IUserLoginErrorService {
 
+    @Autowired
+    private ISysConfigService configService;
+
     @Override
     public UserLoginErrorVo queryById(Long id){
         UserLoginError db = this.baseMapper.selectById(id);
@@ -94,9 +102,15 @@ public class UserLoginErrorServiceImpl extends ServiceImpl<UserLoginErrorMapper,
         lqwExam.eq(UserLoginError::getLoginAccount, loginAccount);
         lqwExam.eq(UserLoginError::getDate, DateUtils.getTodayZeroTime());
         Integer count = baseMapper.selectCount(lqwExam);
-        if(count>=5){
-        //    throw new CustomException("今天你的错误次数已超过5次,请明天再登录");
+        String jsonStr = configService.selectConfigByKey("home.header");
+        JSONObject objectJson = JSON.parseObject(jsonStr);
+        if(Validator.isNotEmpty(objectJson)&&objectJson.containsKey("loginLimit")){
+            Integer maxCount = objectJson.getInteger("loginLimit");
+            if(maxCount>0&&count>=maxCount){
+                throw new CustomException("今天你的错误次数已超过"+maxCount+"次,请明天再登录");
+            }
         }
+
         return true;
     }