|
|
@@ -1,24 +1,35 @@
|
|
|
package com.ruoyi.user.service.impl;
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
|
+import cn.dev33.satoken.secure.BCrypt;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.ruoyi.clock.domain.vo.EmployeeVo;
|
|
|
+import com.ruoyi.clock.service.IEmployeeService;
|
|
|
+import com.ruoyi.common.constant.Constants;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.enums.ExceptionEnum;
|
|
|
+import com.ruoyi.common.enums.UserStatus;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.exception.user.UserException;
|
|
|
+import com.ruoyi.common.utils.MessageUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
import com.ruoyi.common.core.domain.PageQuery;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.ruoyi.common.utils.redis.RedisUtils;
|
|
|
import com.ruoyi.user.domain.UserThirdIdentity;
|
|
|
import com.ruoyi.user.domain.bo.UserThirdIdentityBo;
|
|
|
import com.ruoyi.user.mapper.UserThirdIdentityMapper;
|
|
|
import com.ruoyi.user.service.IUserThirdIdentityService;
|
|
|
+import com.ruoyi.weixin.domain.WxEmployeeDto;
|
|
|
import com.ruoyi.weixin.domain.WxUserDto;
|
|
|
import com.ruoyi.weixin.service.WxMsgService;
|
|
|
import com.ruoyi.weixin.service.WxUserService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.user.domain.bo.UserBo;
|
|
|
@@ -32,6 +43,7 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* 小程序用户管理Service业务层处理
|
|
|
@@ -41,12 +53,15 @@ import java.util.Collection;
|
|
|
*/
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class UserServiceImpl implements IUserService {
|
|
|
|
|
|
private final UserMapper baseMapper;
|
|
|
|
|
|
private final WxUserService wxUserService;
|
|
|
|
|
|
+ private final IEmployeeService employeeService;
|
|
|
+
|
|
|
private final UserThirdIdentityMapper userThirdIdentityMapper;
|
|
|
|
|
|
/**
|
|
|
@@ -232,4 +247,42 @@ public class UserServiceImpl implements IUserService {
|
|
|
}
|
|
|
return obj;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public EmployeeVo login(WxEmployeeDto wxEmployeeDto) {
|
|
|
+ String username = wxEmployeeDto.getUsername();
|
|
|
+ String password = wxEmployeeDto.getPassword();
|
|
|
+ EmployeeVo user = loadUserByUsername(username);
|
|
|
+ Integer errorNumber = RedisUtils.getCacheObject(Constants.LOGIN_ERROR + username);
|
|
|
+ if (!BCrypt.checkpw(password, user.getPassword())) {
|
|
|
+ // 是否第一次
|
|
|
+ errorNumber = ObjectUtil.isNull(errorNumber) ? 1 : errorNumber + 1;
|
|
|
+ // 达到规定错误次数 则锁定登录
|
|
|
+ if (errorNumber.equals(Constants.LOGIN_ERROR_NUMBER)) {
|
|
|
+ RedisUtils.setCacheObject(Constants.LOGIN_ERROR + username, errorNumber, Constants.LOGIN_ERROR_LIMIT_TIME, TimeUnit.MINUTES);
|
|
|
+ throw new UserException("user.password.retry.limit.exceed", Constants.LOGIN_ERROR_LIMIT_TIME);
|
|
|
+ } else {
|
|
|
+ // 未达到规定错误次数 则递增
|
|
|
+ RedisUtils.setCacheObject(Constants.LOGIN_ERROR + username, errorNumber);
|
|
|
+ throw new UserException("user.password.retry.limit.count", errorNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ private EmployeeVo loadUserByUsername(String username) {
|
|
|
+ EmployeeVo user = employeeService.selectUserByUserName(username);
|
|
|
+ if (ObjectUtil.isNull(user)) {
|
|
|
+ log.info("登录用户:{} 不存在.", username);
|
|
|
+ throw new UserException("user.not.exists", username);
|
|
|
+ } else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
|
|
+ log.info("登录用户:{} 已被删除.", username);
|
|
|
+ throw new UserException("user.password.delete", username);
|
|
|
+ } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
|
|
+ log.info("登录用户:{} 已被停用.", username);
|
|
|
+ throw new UserException("user.blocked", username);
|
|
|
+ }
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
}
|