fix: 修复API测试中发现的问题
## 问题修复 ### 1. 上下文拦截器 - ContextInterceptor: 从HTTP Header提取租户ID和用户ID到ThreadLocal - WebMvcConfig: 注册拦截器到Spring MVC ### 2. 数据库配置 - fund-cust/application.yml: 修复MySQL密码默认值 - fund-proj/application.yml: 修复MySQL密码默认值 ### 3. Gateway配置 - application.yml: 删除空的Sentinel datasource配置 - SentinelRuleConfig: 删除重复的sentinelGatewayFilter Bean ### 4. 数据库表 - requirement.sql: 修复主键列名为id,与BaseEntity保持一致 ### 5. MyBatis-Plus依赖 - fund-cust/pom.xml: 使用mybatis-plus-spring-boot3-starter - fund-proj/pom.xml: 使用mybatis-plus-spring-boot3-starter
This commit is contained in:
parent
6d06a361fe
commit
5ebbb13a51
@ -1,6 +1,6 @@
|
||||
-- 需求工单表
|
||||
CREATE TABLE IF NOT EXISTS `requirement` (
|
||||
`requirement_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键,需求ID',
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键,需求ID',
|
||||
`tenant_id` BIGINT NOT NULL COMMENT '租户ID',
|
||||
`requirement_code` VARCHAR(50) NOT NULL COMMENT '需求编号',
|
||||
`requirement_name` VARCHAR(200) NOT NULL COMMENT '需求名称',
|
||||
@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS `requirement` (
|
||||
`updated_by` BIGINT COMMENT '更新人ID',
|
||||
`updated_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`deleted` TINYINT DEFAULT 0 COMMENT '逻辑删除:0-未删除,1-已删除',
|
||||
PRIMARY KEY (`requirement_id`),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_tenant_code` (`tenant_id`, `requirement_code`),
|
||||
INDEX `idx_tenant` (`tenant_id`),
|
||||
INDEX `idx_project` (`project_id`),
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
package com.fundplatform.common.config;
|
||||
|
||||
import com.fundplatform.common.web.ContextInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* Web MVC配置
|
||||
* 注册拦截器
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private ContextInterceptor contextInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(contextInterceptor)
|
||||
.addPathPatterns("/api/**")
|
||||
.excludePathPatterns("/actuator/**", "/error");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.fundplatform.common.web;
|
||||
|
||||
import com.fundplatform.common.context.TenantContextHolder;
|
||||
import com.fundplatform.common.context.UserContextHolder;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
/**
|
||||
* 租户和用户上下文拦截器
|
||||
* 从HTTP Header中提取租户ID和用户ID,设置到ThreadLocal中
|
||||
*/
|
||||
@Component
|
||||
public class ContextInterceptor implements HandlerInterceptor {
|
||||
|
||||
public static final String HEADER_TENANT_ID = "X-Tenant-Id";
|
||||
public static final String HEADER_USER_ID = "X-User-Id";
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
// 提取租户ID
|
||||
String tenantIdStr = request.getHeader(HEADER_TENANT_ID);
|
||||
if (tenantIdStr != null && !tenantIdStr.isEmpty()) {
|
||||
try {
|
||||
Long tenantId = Long.parseLong(tenantIdStr);
|
||||
TenantContextHolder.setTenantId(tenantId);
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略无效的租户ID
|
||||
}
|
||||
}
|
||||
|
||||
// 提取用户ID
|
||||
String userIdStr = request.getHeader(HEADER_USER_ID);
|
||||
if (userIdStr != null && !userIdStr.isEmpty()) {
|
||||
try {
|
||||
Long userId = Long.parseLong(userIdStr);
|
||||
UserContextHolder.setUserId(userId);
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略无效的用户ID
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
||||
// 清理ThreadLocal,防止内存泄漏
|
||||
TenantContextHolder.clear();
|
||||
UserContextHolder.clear();
|
||||
}
|
||||
}
|
||||
@ -16,7 +16,7 @@ spring:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/fund_cust?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: ${DB_PASSWORD:123456}
|
||||
password: ${DB_PASSWORD:zjf@123456}
|
||||
hikari:
|
||||
maximum-pool-size: 10
|
||||
minimum-idle: 5
|
||||
|
||||
@ -2,13 +2,8 @@ package com.fundplatform.gateway.config;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@ -54,13 +49,4 @@ public class SentinelRuleConfig {
|
||||
// 加载规则
|
||||
GatewayRuleManager.loadRules(rules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sentinel Gateway 过滤器
|
||||
*/
|
||||
@Bean
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public GlobalFilter sentinelGatewayFilter() {
|
||||
return new SentinelGatewayFilter();
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,14 +23,6 @@ spring:
|
||||
dashboard: localhost:8080 # Sentinel Dashboard地址(可选)
|
||||
port: 8719 # Sentinel客户端端口
|
||||
eager: true # 服务启动时立即初始化
|
||||
datasource:
|
||||
# 从Nacos读取规则(可选)
|
||||
# ds1:
|
||||
# nacos:
|
||||
# server-addr: localhost:8848
|
||||
# data-id: sentinel-gateway-rules
|
||||
# group-id: DEFAULT_GROUP
|
||||
# rule-type: gw-flow
|
||||
|
||||
gateway:
|
||||
# 默认限流配置
|
||||
|
||||
@ -16,7 +16,7 @@ spring:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/fund_proj?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: ${DB_PASSWORD:123456}
|
||||
password: ${DB_PASSWORD:zjf@123456}
|
||||
hikari:
|
||||
maximum-pool-size: 10
|
||||
minimum-idle: 5
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user