|
@@ -8,11 +8,11 @@ import com.usky.common.core.util.*;
|
|
|
import com.usky.common.redis.core.RedisHelper;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
-import com.usky.system.RuoYiSystemApplication;
|
|
|
import com.usky.system.domain.*;
|
|
|
import com.usky.system.domain.constants.UserConstants;
|
|
|
import com.usky.system.model.LoginUser;
|
|
|
import com.usky.system.service.enums.UserStatus;
|
|
|
+import com.usky.system.service.util.AsyncManager;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -47,6 +47,9 @@ public class SysLoginService {
|
|
|
@Autowired
|
|
|
private SysTenantService sysTenantService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ AsyncManager asyncManager;
|
|
|
+
|
|
|
|
|
|
public final String LOGIN_QRCODE_VERIFY ="login_qrcode_verify";
|
|
|
|
|
@@ -56,21 +59,22 @@ public class SysLoginService {
|
|
|
* 登录
|
|
|
*/
|
|
|
public LoginUser login(String username, String password, Integer tenantId) {
|
|
|
+
|
|
|
// 用户名或密码为空 错误
|
|
|
if (StringUtils.isAnyBlank(username, password)) {
|
|
|
- recordLogininfor(tenantId,username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
|
|
+ asyncManager.insertLog(tenantId,username,Constants.LOGIN_FAIL, "用户/密码必须填写", null);
|
|
|
throw new BusinessException("用户/密码必须填写");
|
|
|
}
|
|
|
// 密码如果不在指定范围内 错误
|
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
- recordLogininfor(tenantId,username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
|
|
+ asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "用户密码不在指定范围", null);
|
|
|
throw new BusinessException("用户密码不在指定范围");
|
|
|
}
|
|
|
// 用户名不在指定范围内 错误
|
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
|
|
- recordLogininfor(tenantId,username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
|
|
+ asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "用户名不在指定范围", null);
|
|
|
throw new BusinessException("用户名不在指定范围");
|
|
|
}
|
|
|
|
|
@@ -84,17 +88,18 @@ public class SysLoginService {
|
|
|
|
|
|
SysUserVO user = loginUser.getSysUser();
|
|
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
|
|
- recordLogininfor(tenantId,username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
|
|
+ asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除", null);
|
|
|
throw new BusinessException("对不起,您的账号:" + username + " 已被删除");
|
|
|
}
|
|
|
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
|
|
- recordLogininfor(tenantId,username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
|
+ asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员", null);
|
|
|
throw new BusinessException("对不起,您的账号:" + username + " 已停用");
|
|
|
}
|
|
|
if (!SecurityUtils.matchesPassword(password, user.getPassword())) {
|
|
|
- recordLogininfor(tenantId,username, Constants.LOGIN_FAIL, "用户密码错误");
|
|
|
+ asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "用户密码错误", null);
|
|
|
throw new BusinessException("用户不存在/密码错误");
|
|
|
}
|
|
|
+
|
|
|
//判断租户状态是否停用
|
|
|
LambdaQueryWrapper<SysTenant> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.select(SysTenant::getStatus, SysTenant::getDomain)
|
|
@@ -104,14 +109,26 @@ public class SysLoginService {
|
|
|
String status = list.get(0).getStatus();
|
|
|
String domain = list.get(0).getDomain();
|
|
|
if(status.equals("1")){
|
|
|
- recordLogininfor(tenantId,username, Constants.LOGIN_FAIL, "系统已停用,请联系管理员");
|
|
|
+ asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "系统已停用,请联系管理员", null);
|
|
|
throw new BusinessException("对不起,系统已停用,请联系管理员");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 获取部门ID
|
|
|
+ LambdaQueryWrapper<SysUser> deptQueryWrapper = Wrappers.lambdaQuery();
|
|
|
+ deptQueryWrapper.select(SysUser::getDeptId)
|
|
|
+ .eq(SysUser::getDelFlag, 0)
|
|
|
+ .eq(SysUser::getTenantId, tenantId)
|
|
|
+ .and(w -> w.eq(SysUser::getUserName, username).or().eq(SysUser::getPhonenumber, username));
|
|
|
+ SysUser sysUser = sysUserService.getOne(deptQueryWrapper);
|
|
|
+ Integer deptId = 0; // 默认值为0,假设0表示没有部门ID
|
|
|
+ if (sysUser != null) {
|
|
|
+ deptId = sysUser.getDeptId().intValue(); // 将Long转换为Integer
|
|
|
+ }
|
|
|
+
|
|
|
SysPerson sysPerson = sysPersonService.getsysPerson(user.getUserId());
|
|
|
loginUser.setSysPerson(sysPerson);
|
|
|
- recordLogininfor(tenantId,username, Constants.LOGIN_SUCCESS, "登录成功");
|
|
|
+ asyncManager.insertLog(tenantId,username, Constants.LOGIN_SUCCESS, "登录成功", deptId);
|
|
|
return loginUser;
|
|
|
}
|
|
|
|
|
@@ -123,32 +140,32 @@ public class SysLoginService {
|
|
|
if (!StringUtils.isBlank(username) && !StringUtils.isBlank(password)) {
|
|
|
// 用户名或密码为空 错误
|
|
|
if (StringUtils.isAnyBlank(username, password)) {
|
|
|
- recordLogininfor(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户/密码必须填写");
|
|
|
+ asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户/密码必须填写", null);
|
|
|
throw new BusinessException("用户/密码必须填写");
|
|
|
}
|
|
|
|
|
|
// 密码如果不在指定范围内 错误
|
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
- recordLogininfor(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
|
|
+ asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户密码不在指定范围", null);
|
|
|
throw new BusinessException("用户密码不在指定范围");
|
|
|
}
|
|
|
|
|
|
// 用户名不在指定范围内 错误
|
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
|
|
- recordLogininfor(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户名不在指定范围");
|
|
|
+ asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户名不在指定范围", null);
|
|
|
throw new BusinessException("用户名不在指定范围");
|
|
|
}
|
|
|
|
|
|
|
|
|
if (Objects.isNull(loginUser)) {
|
|
|
- recordLogininfor(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户不存在");
|
|
|
+ asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户不存在", null);
|
|
|
throw new BusinessException("用户不存在");
|
|
|
}
|
|
|
|
|
|
if (!SecurityUtils.matchesPassword(password, loginUser.getPassword())) {
|
|
|
- recordLogininfor(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户密码错误");
|
|
|
+ asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户密码错误", null);
|
|
|
throw new BusinessException("用户不存在/密码错误");
|
|
|
}
|
|
|
} else if(!StringUtils.isBlank(phone) && !StringUtils.isBlank(verify)) {
|
|
@@ -176,21 +193,32 @@ public class SysLoginService {
|
|
|
}
|
|
|
|
|
|
if (UserStatus.DELETED.getCode().equals(loginUser.getDelFlag())) {
|
|
|
- recordLogininfor(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
|
|
+ asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "对不起,您的账号已被删除", null);
|
|
|
throw new BusinessException("对不起,您的账号:" + username + " 已被删除");
|
|
|
}
|
|
|
if (UserStatus.DISABLE.getCode().equals(loginUser.getStatus())) {
|
|
|
- recordLogininfor(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
|
+ asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户已停用,请联系管理员", null);
|
|
|
throw new BusinessException("对不起,您的账号:" + loginUser.getUserName() + " 已停用");
|
|
|
}
|
|
|
|
|
|
- recordLogininfor(tenantId,loginUser.getUserName(), Constants.LOGIN_SUCCESS, "登录成功");
|
|
|
+ // 获取部门ID
|
|
|
+ LambdaQueryWrapper<SysUser> deptQueryWrapper = Wrappers.lambdaQuery();
|
|
|
+ deptQueryWrapper.select(SysUser::getDeptId)
|
|
|
+ .eq(SysUser::getDelFlag, 0)
|
|
|
+ .eq(SysUser::getTenantId, tenantId)
|
|
|
+ .and(w -> w.eq(SysUser::getUserName, username).or().eq(SysUser::getPhonenumber, username));
|
|
|
+ SysUser sysUser = sysUserService.getOne(deptQueryWrapper);
|
|
|
+ Integer deptId = 0; // 默认值为0,假设0表示没有部门ID
|
|
|
+ if (sysUser != null) {
|
|
|
+ deptId = sysUser.getDeptId().intValue(); // 将Long转换为Integer
|
|
|
+ }
|
|
|
+ asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_SUCCESS, "登录成功", deptId);
|
|
|
return loginUser;
|
|
|
}
|
|
|
|
|
|
|
|
|
public void logout(Integer tenantId,String loginName) {
|
|
|
- recordLogininfor(tenantId,loginName, Constants.LOGOUT, "退出成功");
|
|
|
+ asyncManager.insertLog(tenantId,loginName, Constants.LOGOUT, "退出成功", null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -216,18 +244,10 @@ public class SysLoginService {
|
|
|
sysUser.setNickName(username);
|
|
|
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
|
|
sysUserService.register(BeanMapperUtils.map(sysUser, SysUser.class));
|
|
|
- recordLogininfor(SecurityUtils.getTenantId(),username, Constants.REGISTER, "注册成功");
|
|
|
+ asyncManager.insertLog(SecurityUtils.getTenantId(),username, Constants.REGISTER, "注册成功", null);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 记录登录信息
|
|
|
- *
|
|
|
- * @param username 用户名
|
|
|
- * @param status 状态
|
|
|
- * @param message 消息内容
|
|
|
- * @return
|
|
|
- */
|
|
|
- public void recordLogininfor(Integer tenantId,String username, String status, String message) {
|
|
|
+ /*public void recordLogininfor(Integer tenantId,String username, String status, String message) {
|
|
|
SysLogininforVO logininfor = new SysLogininforVO();
|
|
|
logininfor.setUserName(username);
|
|
|
logininfor.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
@@ -253,7 +273,7 @@ public class SysLoginService {
|
|
|
}
|
|
|
LOGGER.debug(JsonUtils.toJson(logininfor));
|
|
|
sysLogininforService.insertLogininfor(BeanMapperUtils.map(logininfor, SysLogininfor.class));
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
public String getQrCodeResult(@RequestParam String qrCode){
|
|
@@ -262,7 +282,7 @@ public class SysLoginService {
|
|
|
String result = String.valueOf(o);
|
|
|
return result;
|
|
|
}
|
|
|
- return null;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
|