添加获取当前用户信息接口
This commit is contained in:
BIN
src/.DS_Store
vendored
Normal file
BIN
src/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
src/main/java/com/yupi/springbootinit/.DS_Store
vendored
Normal file
BIN
src/main/java/com/yupi/springbootinit/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -6,6 +6,7 @@ import com.yupi.springbootinit.model.dto.user.SystemUsersDTO;
|
||||
import com.yupi.springbootinit.model.enums.LoginSceneEnum;
|
||||
import com.yupi.springbootinit.model.vo.user.SystemUsersVO;
|
||||
import com.yupi.springbootinit.service.SystemLoginLogService;
|
||||
import com.yupi.springbootinit.service.SystemUsersService;
|
||||
import com.yupi.springbootinit.service.impl.LoginService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -30,6 +31,9 @@ public class UserController {
|
||||
@Resource
|
||||
private SystemLoginLogService systemLoginLogService;
|
||||
|
||||
@Resource
|
||||
private SystemUsersService systemUsersService;
|
||||
|
||||
// 用户登陆接口
|
||||
@PostMapping("doLogin")
|
||||
public BaseResponse<SystemUsersVO> doLogin(@RequestBody SystemUsersDTO usersDTO) {
|
||||
@@ -71,11 +75,19 @@ public class UserController {
|
||||
return ResultUtils.success(loginService.logout());
|
||||
}
|
||||
|
||||
@GetMapping("/current")
|
||||
public BaseResponse<SystemUsersVO> getCurrentUser() {
|
||||
return ResultUtils.success(systemUsersService.getCurrentUserInfo());
|
||||
}
|
||||
|
||||
@PostMapping("/bigbrother-logout")
|
||||
public BaseResponse<Boolean> bigBrotherLogout(@RequestBody SystemUsersDTO usersDTO){
|
||||
return ResultUtils.success(loginService.bigBrotherLogout(usersDTO));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void recordFailedDoLoginLog(SystemUsersDTO usersDTO, RuntimeException exception) {
|
||||
try {
|
||||
systemLoginLogService.recordDoLoginLog(usersDTO, null, false);
|
||||
|
||||
@@ -50,5 +50,15 @@ public class SystemUsersVO {
|
||||
|
||||
private Byte webAi;
|
||||
|
||||
private Boolean aiReplayEnabled;
|
||||
|
||||
private Boolean crawlEnabled;
|
||||
|
||||
private Boolean bigBrotherEnabled;
|
||||
|
||||
private Boolean aiChatEnabled;
|
||||
|
||||
private Boolean webAiEnabled;
|
||||
|
||||
private Integer points;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package com.yupi.springbootinit.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yupi.springbootinit.model.entity.SystemUsers;
|
||||
import com.yupi.springbootinit.model.vo.user.SystemUsersVO;
|
||||
|
||||
public interface SystemUsersService extends IService<SystemUsers> {
|
||||
|
||||
@@ -26,4 +27,6 @@ public interface SystemUsersService extends IService<SystemUsers> {
|
||||
boolean checkAiCHatLoginRole(Long userId);
|
||||
|
||||
boolean checkWebAILoginRole(Long userId);
|
||||
|
||||
SystemUsersVO getCurrentUserInfo();
|
||||
}
|
||||
|
||||
@@ -106,23 +106,34 @@ public class LoginService {
|
||||
BeanUtil.copyProperties(user, vo);
|
||||
vo.setTokenName(StpUtil.getTokenName());
|
||||
vo.setTokenValue(StpUtil.getTokenValue());
|
||||
vo.setAiExpireTime(systemTenant.getAiExpireTime());
|
||||
fillFeatureInfo(vo, user, systemTenant);
|
||||
return vo;
|
||||
case HOST:
|
||||
BeanUtil.copyProperties(user, vo);
|
||||
vo.setTokenName(StpUtil.getTokenName());
|
||||
vo.setTokenValue(StpUtil.getTokenValue());
|
||||
vo.setExpireTime(systemTenant.getExpireTime());
|
||||
vo.setBrotherExpireTime(systemTenant.getBrotherExpireTime());
|
||||
vo.setAiExpireTime(systemTenant.getAiExpireTime());
|
||||
vo.setCrawl(user.getCrawl());
|
||||
vo.setAiChat(user.getAiChat());
|
||||
vo.setBigBrother(user.getBigBrother());
|
||||
fillFeatureInfo(vo, user, systemTenant);
|
||||
return vo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void fillFeatureInfo(SystemUsersVO vo, SystemUsers user, SystemTenant tenant) {
|
||||
vo.setExpireTime(tenant.getExpireTime());
|
||||
vo.setCrawlExpireTime(tenant.getCrawlExpireTime());
|
||||
vo.setBrotherExpireTime(tenant.getBrotherExpireTime());
|
||||
vo.setAiExpireTime(tenant.getAiExpireTime());
|
||||
vo.setAiReplayEnabled(isEnabled(user.getAiReplay()));
|
||||
vo.setCrawlEnabled(isEnabled(user.getCrawl()));
|
||||
vo.setBigBrotherEnabled(isEnabled(user.getBigBrother()));
|
||||
vo.setAiChatEnabled(isEnabled(user.getAiChat()));
|
||||
vo.setWebAiEnabled(isEnabled(user.getWebAi()));
|
||||
}
|
||||
|
||||
private boolean isEnabled(Byte value) {
|
||||
return value != null && value == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验用户登录信息
|
||||
*
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package com.yupi.springbootinit.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yupi.springbootinit.common.ErrorCode;
|
||||
import com.yupi.springbootinit.exception.BusinessException;
|
||||
import com.yupi.springbootinit.mapper.SystemTenantMapper;
|
||||
import com.yupi.springbootinit.model.entity.SystemTenant;
|
||||
import com.yupi.springbootinit.model.entity.SystemUsers;
|
||||
import com.yupi.springbootinit.service.SystemTenantService;
|
||||
import com.yupi.springbootinit.mapper.SystemUsersMapper;
|
||||
import com.yupi.springbootinit.model.vo.user.SystemUsersVO;
|
||||
import com.yupi.springbootinit.service.SystemUsersService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.yupi.springbootinit.mapper.SystemUsersMapper;
|
||||
import com.yupi.springbootinit.service.SystemUsersService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
/*
|
||||
* @author: ziin
|
||||
@@ -90,5 +91,43 @@ public class SystemUsersServiceImpl extends ServiceImpl<SystemUsersMapper,System
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemUsersVO getCurrentUserInfo() {
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
SystemUsers user = baseMapper.selectById(userId);
|
||||
if (user == null || Boolean.TRUE.equals(user.getDeleted())) {
|
||||
throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "用户不存在");
|
||||
}
|
||||
SystemTenant tenant = systemTenantMapper.selectById(user.getTenantId());
|
||||
if (tenant == null || Boolean.TRUE.equals(tenant.getDeleted())) {
|
||||
throw new BusinessException(ErrorCode.TENANT_NAME_NOT_EXISTS);
|
||||
}
|
||||
return buildSystemUsersVO(user, tenant);
|
||||
}
|
||||
|
||||
private SystemUsersVO buildSystemUsersVO(SystemUsers user, SystemTenant tenant) {
|
||||
SystemUsersVO userVO = new SystemUsersVO();
|
||||
BeanUtil.copyProperties(user, userVO);
|
||||
userVO.setTokenName(StpUtil.getTokenName());
|
||||
userVO.setTokenValue(StpUtil.getTokenValue());
|
||||
userVO.setExpireTime(tenant.getExpireTime());
|
||||
userVO.setCrawlExpireTime(tenant.getCrawlExpireTime());
|
||||
userVO.setBrotherExpireTime(tenant.getBrotherExpireTime());
|
||||
userVO.setAiExpireTime(tenant.getAiExpireTime());
|
||||
fillFeatureEnabled(userVO, user);
|
||||
return userVO;
|
||||
}
|
||||
|
||||
private void fillFeatureEnabled(SystemUsersVO userVO, SystemUsers user) {
|
||||
userVO.setAiReplayEnabled(isEnabled(user.getAiReplay()));
|
||||
userVO.setCrawlEnabled(isEnabled(user.getCrawl()));
|
||||
userVO.setBigBrotherEnabled(isEnabled(user.getBigBrother()));
|
||||
userVO.setAiChatEnabled(isEnabled(user.getAiChat()));
|
||||
userVO.setWebAiEnabled(isEnabled(user.getWebAi()));
|
||||
}
|
||||
|
||||
private boolean isEnabled(Byte value) {
|
||||
return value != null && value == 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BIN
tk-data-user.2026-03-11.0.gz
Normal file
BIN
tk-data-user.2026-03-11.0.gz
Normal file
Binary file not shown.
BIN
tk-data-user.2026-03-12.0.gz
Normal file
BIN
tk-data-user.2026-03-12.0.gz
Normal file
Binary file not shown.
BIN
tk-data-user.2026-03-13.0.gz
Normal file
BIN
tk-data-user.2026-03-13.0.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user