130 lines
5.5 KiB
Java
130 lines
5.5 KiB
Java
package com.yupi.springbootinit.controller;
|
|
|
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import com.yupi.springbootinit.common.BaseResponse;
|
|
import com.yupi.springbootinit.common.ErrorCode;
|
|
import com.yupi.springbootinit.common.ResultUtils;
|
|
import com.yupi.springbootinit.exception.BusinessException;
|
|
import com.yupi.springbootinit.model.dto.user.SystemUsersDTO;
|
|
import com.yupi.springbootinit.model.entity.SystemUsers;
|
|
import com.yupi.springbootinit.model.enums.CommonStatusEnum;
|
|
import com.yupi.springbootinit.model.vo.user.SystemUsersVO;
|
|
import com.yupi.springbootinit.service.SystemUsersService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
/*
|
|
* @author: ziin
|
|
* @date: 2025/6/11 19:50
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/user")
|
|
@Slf4j
|
|
@CrossOrigin
|
|
public class UserController {
|
|
|
|
|
|
@Resource
|
|
private SystemUsersService usersService;
|
|
|
|
// 用户登陆接口
|
|
@PostMapping("doLogin")
|
|
public BaseResponse<SystemUsersVO> doLogin(@RequestBody SystemUsersDTO usersDTO) {
|
|
SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId());
|
|
if (user == null) {
|
|
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
}
|
|
if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) {
|
|
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
}
|
|
|
|
if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) {
|
|
throw new BusinessException(ErrorCode.USER_DISABLE);
|
|
}
|
|
if (usersService.isExpired(usersDTO.getTenantId())){
|
|
throw new BusinessException(ErrorCode.PACKAGE_EXPIRED);
|
|
}
|
|
if (!usersService.checkCrawlRole(user.getId())){
|
|
throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED);
|
|
}
|
|
Long second = usersService.getTenantExpiredTime(usersDTO.getTenantId());
|
|
SystemUsersVO systemUsersVO = new SystemUsersVO();
|
|
BeanUtil.copyProperties(user, systemUsersVO);
|
|
// 赋予用户 Id
|
|
StpUtil.login(user.getId(),"host");
|
|
// 设置 token 有效期为当前日期和套餐有效期的差值
|
|
StpUtil.renewTimeout(second);
|
|
systemUsersVO.setTokenName(StpUtil.getTokenName());
|
|
systemUsersVO.setTokenValue(StpUtil.getTokenValue());
|
|
return ResultUtils.success(systemUsersVO);
|
|
}
|
|
|
|
// 用户登陆接口
|
|
@PostMapping("bigbrother-doLogin")
|
|
public BaseResponse<SystemUsersVO> bigBrotherDoLogin(@RequestBody SystemUsersDTO usersDTO) {
|
|
SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId());
|
|
if (user == null) {
|
|
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
}
|
|
if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) {
|
|
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
}
|
|
|
|
if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) {
|
|
throw new BusinessException(ErrorCode.USER_DISABLE);
|
|
}
|
|
if (usersService.isExpired(usersDTO.getTenantId())){
|
|
throw new BusinessException(ErrorCode.PACKAGE_EXPIRED);
|
|
}
|
|
if (!usersService.checkbigBrotherlRole(user.getId())){
|
|
throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED);
|
|
}
|
|
Long second = usersService.getTenantExpiredTime(usersDTO.getTenantId());
|
|
SystemUsersVO systemUsersVO = new SystemUsersVO();
|
|
BeanUtil.copyProperties(user, systemUsersVO);
|
|
// 赋予用户 Id
|
|
StpUtil.login(user.getId(),"bigbrother");
|
|
// 设置 token 有效期为当前日期和套餐有效期的差值
|
|
StpUtil.renewTimeout(second);
|
|
systemUsersVO.setTokenName(StpUtil.getTokenName());
|
|
systemUsersVO.setTokenValue(StpUtil.getTokenValue());
|
|
return ResultUtils.success(systemUsersVO);
|
|
}
|
|
|
|
// 用户登陆接口
|
|
@PostMapping("aiChat-doLogin")
|
|
public BaseResponse<SystemUsersVO> aiChatDoLogin(@RequestBody SystemUsersDTO usersDTO) {
|
|
SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername(),usersDTO.getTenantId());
|
|
if (user == null) {
|
|
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
}
|
|
if (!usersService.isPasswordMatch(usersDTO.getPassword(), user.getPassword())) {
|
|
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
|
}
|
|
|
|
if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) {
|
|
throw new BusinessException(ErrorCode.USER_DISABLE);
|
|
}
|
|
if (usersService.isExpired(usersDTO.getTenantId())){
|
|
throw new BusinessException(ErrorCode.PACKAGE_EXPIRED);
|
|
}
|
|
if (!usersService.checkAiCHatLoginRole(user.getId())){
|
|
throw new BusinessException(ErrorCode.LOGIN_NOW_ALLOWED);
|
|
}
|
|
Long second = usersService.getTenantExpiredTime(usersDTO.getTenantId());
|
|
SystemUsersVO systemUsersVO = new SystemUsersVO();
|
|
BeanUtil.copyProperties(user, systemUsersVO);
|
|
// 赋予用户 Id
|
|
StpUtil.login(user.getId(),"aiChat");
|
|
// 设置 token 有效期为当前日期和套餐有效期的差值
|
|
StpUtil.renewTimeout(second);
|
|
systemUsersVO.setTokenName(StpUtil.getTokenName());
|
|
systemUsersVO.setTokenValue(StpUtil.getTokenValue());
|
|
return ResultUtils.success(systemUsersVO);
|
|
}
|
|
}
|