chore(config): 更新应用配置文件
- 移除 application.properties 中的 spring.profiles.active 配置 - 在 application.yml 中为 deepseek ai 服务添加 api-key 配置 - 保留 base-url 和 chat options 配置不变
This commit is contained in:
@@ -20,5 +20,7 @@ public interface UserConstant {
|
||||
*/
|
||||
String ADMIN_ROLE = "admin";
|
||||
|
||||
String USER_CACHE_KEY = "boss:user:cache:%s";
|
||||
|
||||
// endregion
|
||||
}
|
||||
|
||||
@@ -104,7 +104,13 @@ public class UserController {
|
||||
if (id <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
User user = userService.getById(id);
|
||||
// 先从redis中查找
|
||||
User user = userService.getCacheUser(id);
|
||||
if (user != null) {
|
||||
return ResultUtils.success(user);
|
||||
}
|
||||
// 从数据库中查找
|
||||
user = userService.getById(id);
|
||||
ThrowUtils.throwIf(user == null, ErrorCode.NOT_FOUND_ERROR);
|
||||
return ResultUtils.success(user);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,15 @@ public class UserUpdateRequest implements Serializable {
|
||||
*/
|
||||
private String userAvatar;
|
||||
|
||||
/**
|
||||
* 手机
|
||||
*/
|
||||
private String phone;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 简介
|
||||
*/
|
||||
|
||||
@@ -37,6 +37,15 @@ public class LoginUserVO {
|
||||
*/
|
||||
private String userProfile;
|
||||
|
||||
/*
|
||||
手机
|
||||
*/
|
||||
private String phone;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 用户角色:user/admin
|
||||
*/
|
||||
|
||||
@@ -93,4 +93,12 @@ public interface UserService extends IService<User> {
|
||||
*/
|
||||
QueryWrapper<User> getQueryWrapper(UserQueryRequest userQueryRequest);
|
||||
|
||||
/**
|
||||
* 从redis中获取用户
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
User getCacheUser(long id);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,16 @@ import com.zds.boss.model.enums.UserRoleEnum;
|
||||
import com.zds.boss.model.vo.LoginUserVO;
|
||||
import com.zds.boss.model.vo.UserVO;
|
||||
import com.zds.boss.service.UserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -35,6 +38,10 @@ import java.util.stream.Collectors;
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
||||
implements UserService {
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, User> redisTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* @param userAccount
|
||||
* @param userPassword
|
||||
@@ -130,8 +137,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
||||
log.info("user login failed, userAccount can not match userPassword");
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户名或密码错误");
|
||||
}
|
||||
//保存用户登录态信息
|
||||
request.getSession().setAttribute(UserConstant.USER_LOGIN_STATE, user);
|
||||
String redisKey = String.format(UserConstant.USER_CACHE_KEY, user.getId());
|
||||
redisTemplate.opsForValue().set(redisKey, user, 10, TimeUnit.MINUTES);
|
||||
return getLoginUserVO(user);
|
||||
}
|
||||
|
||||
@@ -261,5 +269,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCacheUser(long id) {
|
||||
String redisKey = String.format(UserConstant.USER_CACHE_KEY, id);
|
||||
User user = redisTemplate.opsForValue().get(redisKey);
|
||||
if (user != null) {
|
||||
return user;
|
||||
}
|
||||
user = this.getById(id);
|
||||
if (user != null) {
|
||||
redisTemplate.opsForValue().set(redisKey, user, 10, TimeUnit.MINUTES);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
|
||||
|
||||
// 创建 axios 实例
|
||||
import type {AxiosInstance, AxiosRequestConfig, AxiosResponse} from "axios";
|
||||
import axios from "axios";
|
||||
|
||||
const apiClient: AxiosInstance = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080/api', // 使用环境变量或默认值
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL || 'http://127.0.0.1:8081/api', // 使用环境变量或默认值
|
||||
timeout: 10000, // 请求超时时间
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user