Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6cc16717a5 | |||
| b0e855b0b6 | |||
| c9099f9ef7 | |||
| b275ea6798 | |||
| 2e7e90f411 | |||
| 3eefc074a8 | |||
| 730af827ad | |||
| b6facb0857 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,6 +7,9 @@
|
||||
.idea
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
target
|
||||
|
||||
dist
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* 对外开放 API
|
||||
* <p>
|
||||
* Token 一次消费:每个 token 只能用一次,消费后立即失效
|
||||
* API 文档地址:http://服务地址:9002/doc.html → "对外开放API" 分组
|
||||
* API 文档地址:http://服务地址:32002/doc.html → "对外开放API" 分组
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
||||
@@ -1116,7 +1116,7 @@ export default defineConfig({
|
||||
<!-- 配置项通过 data-* 属性传入 -->
|
||||
<div
|
||||
id="mokee-user-chip"
|
||||
data-api-base="http://127.0.0.1:9000"
|
||||
data-api-base="http://127.0.0.1:32000"
|
||||
data-login-url="http://127.0.0.1:5001/login"
|
||||
data-select-url="http://127.0.0.1:5001/select"
|
||||
></div>
|
||||
@@ -1136,7 +1136,7 @@ export default defineConfig({
|
||||
<br/>
|
||||
<!-- 2. 占位元素(可配置网关地址、登录页、切换系统页) --><br/>
|
||||
<div id="mokee-user-chip"<br/>
|
||||
data-api-base="http://127.0.0.1:9000"<br/>
|
||||
data-api-base="http://127.0.0.1:32000"<br/>
|
||||
data-login-url="http://127.0.0.1:5001/login"<br/>
|
||||
data-select-url="http://127.0.0.1:5001/select"></div><br/>
|
||||
<br/>
|
||||
|
||||
@@ -189,7 +189,7 @@ def init():
|
||||
# ===== 阶段3: 测试系统 =====
|
||||
print("\n===== 阶段3: 测试系统 (test) =====")
|
||||
cur.execute("""INSERT INTO sys_system (system_code, system_name, front_url, backend_url, gateway_url, status, description)
|
||||
VALUES ('test', '测试系统', 'http://127.0.0.1:5001', 'http://127.0.0.1:9000', 'http://127.0.0.1:9000/test', 1, '测试用业务系统')""")
|
||||
VALUES ('test', '测试系统', 'http://127.0.0.1:5001', 'http://127.0.0.1:32000', 'http://127.0.0.1:9000/test', 1, '测试用业务系统')""")
|
||||
conn.commit()
|
||||
test_sid = cur.lastrowid
|
||||
print(f" 系统: id={test_sid}")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
- [项目概览](project-overview.md) — 统一登录网关平台完整信息、架构、状态、已知问题
|
||||
- [2026-07-16 会话-1](session-20260716-1.md) — IconPicker 增加直接上传图片功能
|
||||
- [2026-06-28 会话-1](session-20260628-1.md) — 修复登录后 /open/token 和文件下载接口重复调用
|
||||
- [2026-06-09 会话](session-log.md) — 完整开发过程、决策、Bug修复、待办
|
||||
- [2026-06-10 会话-1](session-20260610-1.md) — 数据库地址变更、前端环境变量整理
|
||||
|
||||
@@ -95,8 +95,8 @@ metadata:
|
||||
|
||||
## 待处理
|
||||
- [x] **PROD 数据库 sys_file 表迁移** — 已完成,QA和PROD结构一致
|
||||
- [ ] 部署前端到PROD(Nginx 10.10.1.160)
|
||||
- [ ] 部署后端到PROD(10.10.1.170)
|
||||
- [ ] 部署前端到PROD(Nginx 10.20.1.160)
|
||||
- [ ] 部署后端到PROD(10.20.1.170)
|
||||
- [ ] 验证头像上传端到端流程
|
||||
- [ ] E-1 Cookie域localhost问题(开发环境限制,暂不处理)
|
||||
- [ ] F-3 bindSystems/unbindSystems Redis同步(低优先级)
|
||||
|
||||
@@ -11,32 +11,32 @@ metadata:
|
||||
# 2026-06-12 第2次会话
|
||||
|
||||
## 会话摘要
|
||||
用户反馈 Vue 前端通过 VPN 访问非常慢(JS/CSS 加载要 1 分钟)。诊断发现根因是 Nginx 代理层(10.10.1.160)丢失了 gzip 压缩,导致 1MB+ 的文件通过 VPN 窄带宽原样传输。用户自行修复。
|
||||
用户反馈 Vue 前端通过 VPN 访问非常慢(JS/CSS 加载要 1 分钟)。诊断发现根因是 Nginx 代理层(10.20.1.160)丢失了 gzip 压缩,导致 1MB+ 的文件通过 VPN 窄带宽原样传输。用户自行修复。
|
||||
|
||||
## 关键操作
|
||||
|
||||
### VPN 网络诊断 — 前端加载慢
|
||||
- **问题现象**: 通过域名 `web.gw.zgitm.com` 访问前端,JS/CSS 加载要 40 秒~1 分钟
|
||||
- **网络拓扑**: 用户电脑(10.10.1.5) → 公网VPN → 阿里云VPN(10.10.1.1) → Nginx代理(10.10.1.160) → 前端服务(10.10.1.170:5001)
|
||||
- **域名解析**: `web.gw.zgitm.com` 和 `login.user.zgitm.com` 均解析到 10.10.1.160
|
||||
- **网络拓扑**: 用户电脑(10.20.1.5) → 公网VPN → 阿里云VPN(10.20.1.1) → Nginx代理(10.20.1.160) → 前端服务(10.20.1.170:5001)
|
||||
- **域名解析**: `web.gw.zgitm.com` 和 `login.user.zgitm.com` 均解析到 10.20.1.160
|
||||
- **实测数据**:
|
||||
|
||||
| 路径 | el.js (1.08MB) 耗时 | gzip |
|
||||
|------|---------------------|------|
|
||||
| 内网 10.1.1.170:5001 | 19ms | ✅ |
|
||||
| VPN直连 10.10.1.170:5001 | 3-10秒 | ✅ |
|
||||
| VPN直连 10.20.1.170:5001 | 3-10秒 | ✅ |
|
||||
| Nginx代理 web.gw.zgitm.com | 20-40秒 | ❌ 丢失 |
|
||||
|
||||
- **根因**: 10.10.1.170 上的 Nginx 返回 gzip 压缩内容,但 10.10.1.160 Nginx 代理时丢失了 gzip 压缩,导致 1MB+ 文件通过窄带宽 VPN 原样传输
|
||||
- **根因**: 10.20.1.170 上的 Nginx 返回 gzip 压缩内容,但 10.20.1.160 Nginx 代理时丢失了 gzip 压缩,导致 1MB+ 文件通过窄带宽 VPN 原样传输
|
||||
- **Ping延迟**: 5-15ms(正常),**不是延迟问题是带宽+压缩问题**
|
||||
- **修复方案**: 在 10.10.1.160 Nginx 配置中添加 `proxy_set_header Accept-Encoding "gzip"` 和/或开启本地 gzip — 用户自行修复
|
||||
- **修复方案**: 在 10.20.1.160 Nginx 配置中添加 `proxy_set_header Accept-Encoding "gzip"` 和/或开启本地 gzip — 用户自行修复
|
||||
|
||||
## 重要信息
|
||||
- VPN 网关: 10.10.1.1(阿里云)
|
||||
- VPN 子网: 10.10.1.x
|
||||
- 前端服务: 10.10.1.170:5001(内网 10.1.1.170:5001)
|
||||
- Nginx 代理: 10.10.1.160
|
||||
- DNS 服务器: 10.10.1.150
|
||||
- VPN 网关: 10.20.1.1(阿里云)
|
||||
- VPN 子网: 10.20.1.x
|
||||
- 前端服务: 10.20.1.170:5001(内网 10.1.1.170:5001)
|
||||
- Nginx 代理: 10.20.1.160
|
||||
- DNS 服务器: 10.20.1.150
|
||||
- 公网 IP: zgitm.com → 8.133.197.85
|
||||
- 生产前端域名: web.gw.zgitm.com, login.user.zgitm.com
|
||||
- Nginx 版本: 160 上是 1.14.1,170 上是 1.30.2
|
||||
|
||||
@@ -16,7 +16,7 @@ metadata:
|
||||
## 关键操作
|
||||
|
||||
### 一、数据库地址变更
|
||||
- MySQL + Redis 地址: `10.10.1.122` → `10.1.1.122`
|
||||
- MySQL + Redis 地址: `10.20.1.122` → `10.1.1.122`
|
||||
- 14个文件全局替换(yml/py/md)
|
||||
|
||||
### 二、前后端字段匹配审计 + Bug修复
|
||||
@@ -68,6 +68,6 @@ MenuList.vue统一用URL传id
|
||||
|
||||
## 重要信息
|
||||
- 数据库: 10.1.1.122:3306
|
||||
- 微服务端口: gateway:9000, auth:9001, admin:9002
|
||||
- 微服务端口: gateway:32000, auth:32001, admin:32002
|
||||
- 前端构建: `npm run build:prod` (跳过vue-tsc类型检查)
|
||||
- Node版本: 服务器Node 18,Vite 5.4兼容
|
||||
|
||||
@@ -31,7 +31,7 @@ metadata:
|
||||
|
||||
## 重要信息
|
||||
- Redis 前缀机制详情见 [[session-20260620-1]] 的 "Redis Key 加统一前缀 GATEWAY:" 章节
|
||||
- Auth 服务(9001)、Admin 服务(9002)、Gateway(9000) 三个服务共享同一个 Redis 实例
|
||||
- Auth 服务(32001)、Admin 服务(32002)、Gateway(32000) 三个服务共享同一个 Redis 实例
|
||||
- 所有 Redis key 操作都必须通过 `RedisUtil.key()` 方法,不能直接拼字符串
|
||||
|
||||
## 待处理
|
||||
|
||||
@@ -16,7 +16,7 @@ metadata:
|
||||
## 关键操作
|
||||
|
||||
### /zgapi/v1/auth/system/list 性能排查
|
||||
- **做了什么**: 完整追踪请求链路:Nginx → Gateway(9000) → TokenAuthFilter → RateLimitFilter → HeaderInjectFilter → ApiPermissionFilter → GatewayController → [HTTP转发] → Auth(9001) → DB/Redis
|
||||
- **做了什么**: 完整追踪请求链路:Nginx → Gateway(32000) → TokenAuthFilter → RateLimitFilter → HeaderInjectFilter → ApiPermissionFilter → GatewayController → [HTTP转发] → Auth(32001) → DB/Redis
|
||||
- **发现的浪费**:
|
||||
1. JWT 签名验证执行了 3 次(TokenAuthFilter + RateLimitFilter + AuthServiceImpl)
|
||||
2. 同一个 Redis key 被查询了 4 次(TokenAuthFilter GET+GETEXPIRE + AuthServiceImpl GET+GETEXPIRE)
|
||||
|
||||
51
memory/session-20260716-1.md
Normal file
51
memory/session-20260716-1.md
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
name: session-20260716-1
|
||||
description: 2026-07-16 第1次会话 — IconPicker 增加直接上传图片功能
|
||||
metadata:
|
||||
type: session
|
||||
date: 2026-07-16
|
||||
sessionNumber: 1
|
||||
startTime: 2026-07-16T00:00:00+08:00
|
||||
---
|
||||
|
||||
# 2026-07-16 第1次会话
|
||||
|
||||
## 会话摘要
|
||||
|
||||
1. IconPicker 增加上传按钮:前端图标选择器"已上传"标签页增加直接上传功能
|
||||
2. 修复 /view 端点 404:后端新增文件预览代理端点,每次请求实时向文件服务器获取 Token 并代理返回图片
|
||||
|
||||
## 关键操作
|
||||
|
||||
### 一、IconPicker 增加上传按钮
|
||||
|
||||
- **做了什么**: 在 IconPicker.vue 的"已上传"标签页头部增加了「上传」按钮,点击后选择图片即自动上传到文件服务(fileType=icon),上传完成自动刷新列表并选中新图标
|
||||
- **涉及文件**: `mokee-gateway-web/src/components/IconPicker.vue`
|
||||
- **结果**: TypeScript 编译通过,IconPicker.vue 无类型错误
|
||||
|
||||
### 二、新增文件预览代理端点 GET /{id}/view
|
||||
|
||||
- **做了什么**: 用户反馈上传图标后 `<img>` 加载 `/zgapi/v1/admin/file/{id}/view` 返回 404,原因是文件迁至外部存储后该端点被移除。本次在 admin 后端重新实现该端点,每次请求自动向文件服务器获取 Token → 下载文件 → 返回给浏览器
|
||||
- **涉及文件**:
|
||||
1. `mokee-gateway-admin/.../config/WebMvcConfig.java` — 新增 `fileServiceRestTemplate` Bean
|
||||
2. `mokee-gateway-admin/.../service/FileService.java` — 新增 `view()` 方法签名
|
||||
3. `mokee-gateway-admin/.../service/impl/FileServiceImpl.java` — 实现核心逻辑:查元信息 → 获取 Token → RestTemplate 代理下载 → 写回 HttpServletResponse
|
||||
4. `mokee-gateway-admin/.../controller/FileController.java` — 新增 `GET /{id}/view` 端点
|
||||
- **结果**: Maven 编译通过,零错误
|
||||
- **设计要点**:
|
||||
- 文件服务 URL 通过 `@Value("${file.service.url:https://file.wg.zgitm.com}")` 注入,可配置
|
||||
- Token 不使用缓存,每次请求实时获取(避免一次消费问题)
|
||||
- 端点不受 `UserContextInterceptor` 拦截(WebMvcConfig 中已排除 `/view` 路径)
|
||||
- 错误时返回纯文本状态(404/502/500),不依赖 JSON 响应结构
|
||||
|
||||
## 重要信息
|
||||
|
||||
- 文件服务 URL: `VITE_FILE_SERVICE_URL` 环境变量,默认 `https://file.wg.zgitm.com`
|
||||
- 上传 API: `POST {FILE_SERVICE}/api/upload`,FormData 包含 `file` + `fileType`
|
||||
- 上传 Token: `POST {FILE_SERVICE}/api/token`,body: `{ systemCode: 'gateway' }`
|
||||
- 图标列表查询: `GET /zgapi/v1/admin/file/list?fileType=icon`
|
||||
- 文件服务直写 `sys_file` 表,admin 后端只做元信息查询
|
||||
|
||||
## 待处理
|
||||
|
||||
- [ ] 通知用户确认前端部署后功能正常
|
||||
@@ -2,4 +2,4 @@ FROM harbor.zgitm.com/library/eclipse-temurin:17-jre
|
||||
WORKDIR /app
|
||||
COPY target/*.jar app.jar
|
||||
EXPOSE 32002
|
||||
ENTRYPOINT ["java","-jar","app.jar"]
|
||||
ENTRYPOINT ["java","-Xms256m","-Xmx512m","-XX:+UseG1GC","-XX:MaxGCPauseMillis=200","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=/app/dump.hprof","-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=Asia/Shanghai","-jar","app.jar"]
|
||||
@@ -18,8 +18,8 @@ public class AdminApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AdminApplication.class, args);
|
||||
System.out.println("========================================");
|
||||
System.out.println(" 业务管理服务启动成功! 端口: 9002");
|
||||
System.out.println(" Knife4j 文档: http://localhost:9002/doc.html");
|
||||
System.out.println(" 业务管理服务启动成功! 端口: 32002");
|
||||
System.out.println(" Knife4j 文档: http://localhost:32002/doc.html");
|
||||
System.out.println("========================================");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
package com.mokee.admin.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* Web MVC 配置 — 注册用户上下文拦截器
|
||||
* Web MVC 配置
|
||||
* <p>
|
||||
* - 注册用户上下文拦截器(文件预览/下载端点不拦截)
|
||||
* - 注册 RestTemplate Bean(用于代理请求文件服务器)
|
||||
*/
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
@@ -20,4 +26,13 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
.addPathPatterns("/zgapi/v1/admin/**") // 仅管理后台接口
|
||||
.excludePathPatterns("/zgapi/v1/admin/file/**/view", "/zgapi/v1/admin/file/**/download"); // 文件预览/下载不拦截
|
||||
}
|
||||
|
||||
/** 文件服务器代理专用 RestTemplate — 较短超时,避免阻塞页面渲染 */
|
||||
@Bean
|
||||
public RestTemplate fileServiceRestTemplate() {
|
||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
factory.setConnectTimeout(5000);
|
||||
factory.setReadTimeout(30000);
|
||||
return new RestTemplate(factory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,11 +114,11 @@ public class DashboardController {
|
||||
|
||||
// 微服务健康状态:用 TCP 端口检测替代 HTTP(快 10 倍)
|
||||
List<Map<String, Object>> services = new ArrayList<>();
|
||||
services.add(checkTcpPort("网关服务 (Gateway)", "127.0.0.1", 9000));
|
||||
services.add(checkTcpPort("认证服务 (Auth)", "127.0.0.1", 9001));
|
||||
// services.add(checkTcpPort("网关服务 (Gateway)", "127.0.0.1", 32000));
|
||||
// services.add(checkTcpPort("认证服务 (Auth)", "127.0.0.1", 32001));
|
||||
Map<String, Object> adminSvc = new LinkedHashMap<>();
|
||||
adminSvc.put("name", "管理服务 (Admin)");
|
||||
adminSvc.put("port", 9002);
|
||||
adminSvc.put("port", 32002);
|
||||
adminSvc.put("status", "UP");
|
||||
adminSvc.put("responseTime", 0);
|
||||
services.add(adminSvc);
|
||||
|
||||
@@ -53,4 +53,15 @@ public class FileController {
|
||||
public Result<SysFile> getById(@PathVariable String id) {
|
||||
return Result.ok(fileService.getMetaById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件预览 — 代理到文件服务器获取图片并返回
|
||||
* <p>
|
||||
* 用于 <img> 标签直接加载。每次请求从文件服务器获取新 Token 后下载文件,
|
||||
* 对前端透明。不走用户上下文拦截器(WebMvcConfig 中已排除)。
|
||||
*/
|
||||
@GetMapping("/{id}/view")
|
||||
public void view(@PathVariable String id, jakarta.servlet.http.HttpServletResponse response) {
|
||||
fileService.view(id, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* 对外开放 API
|
||||
* <p>
|
||||
* Token 一次消费:每个 token 只能用一次,消费后立即失效
|
||||
* API 文档地址:http://服务地址:9002/doc.html → "对外开放API" 分组
|
||||
* API 文档地址:http://服务地址:32002/doc.html → "对外开放API" 分组
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
||||
@@ -25,4 +25,15 @@ public interface FileService {
|
||||
|
||||
/** 查询元信息(不含 file_data) */
|
||||
SysFile getMetaById(String id);
|
||||
|
||||
/**
|
||||
* 代理文件预览 — 从文件服务器获取 Token、下载文件、流式返回给客户端
|
||||
* <p>
|
||||
* 用于 <img> 标签加载场景。每次请求都从文件服务器获取新 Token,
|
||||
* 避免 Token 缓存带来的消费时序问题。
|
||||
*
|
||||
* @param id 文件 ID
|
||||
* @param response HTTP 响应对象(用于设置 Content-Type 和输出流)
|
||||
*/
|
||||
void view(String id, jakarta.servlet.http.HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -7,17 +7,26 @@ import com.mokee.admin.config.UserContextHolder;
|
||||
import com.mokee.admin.mapper.SysFileMapper;
|
||||
import com.mokee.admin.service.FileService;
|
||||
import com.mokee.common.entity.SysFile;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文件服务实现 — 仅提供元信息查询
|
||||
* 文件服务实现
|
||||
* <p>
|
||||
* 文件上传/下载/删除已迁移至外部文件对象存储服务(file.wg.zgitm.com),
|
||||
* 外部服务直接写入 sys_file 表,本服务只做查询。
|
||||
* 外部服务直接写入 sys_file 表,本服务做元信息查询 + 预览代理。
|
||||
*
|
||||
* @author mokee
|
||||
*/
|
||||
@@ -27,6 +36,11 @@ import java.util.List;
|
||||
public class FileServiceImpl implements FileService {
|
||||
|
||||
private final SysFileMapper sysFileMapper;
|
||||
private final RestTemplate fileServiceRestTemplate;
|
||||
|
||||
/** 文件服务器地址 */
|
||||
@Value("${file.service.url:https://file.wg.zgitm.com}")
|
||||
private String fileServiceUrl;
|
||||
|
||||
@Override
|
||||
public IPage<SysFile> page(Integer page, Integer size, String fileType,
|
||||
@@ -72,4 +86,82 @@ public class FileServiceImpl implements FileService {
|
||||
w.select(SysFile.class, f -> !"file_data".equals(f.getColumn()));
|
||||
return sysFileMapper.selectOne(w);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void view(String id, HttpServletResponse response) {
|
||||
// 1. 查文件元信息
|
||||
SysFile file = getMetaById(id);
|
||||
if (file == null) {
|
||||
respondError(response, 404, "文件不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 从文件服务器获取下载 Token
|
||||
String token = fetchDownloadToken();
|
||||
if (token == null) {
|
||||
log.warn("获取文件服务器 Token 失败 — fileId={}", id);
|
||||
respondError(response, 502, "获取下载凭证失败");
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 从文件服务器下载文件二进制数据
|
||||
try {
|
||||
String downloadUrl = fileServiceUrl + "/api/download/" + id + "?token=" + token;
|
||||
ResponseEntity<byte[]> resp = fileServiceRestTemplate.exchange(
|
||||
downloadUrl, HttpMethod.GET, null, byte[].class);
|
||||
|
||||
byte[] body = resp.getBody();
|
||||
if (body == null || (resp.getStatusCode().isError())) {
|
||||
log.warn("文件服务器返回空或错误 — fileId={}, status={}", id, resp.getStatusCode());
|
||||
respondError(response, 502, "文件获取失败");
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 流式返回给客户端
|
||||
response.setContentType(file.getMimeType() != null ? file.getMimeType() : "application/octet-stream");
|
||||
response.setContentLength(body.length);
|
||||
response.getOutputStream().write(body);
|
||||
response.getOutputStream().flush();
|
||||
} catch (IOException e) {
|
||||
log.warn("文件预览流式输出失败 — fileId={}", id, e);
|
||||
respondError(response, 500, "文件输出失败");
|
||||
} catch (Exception e) {
|
||||
log.warn("文件服务器请求失败 — fileId={}", id, e);
|
||||
respondError(response, 502, "文件服务器连接失败");
|
||||
}
|
||||
}
|
||||
|
||||
/** 向文件服务器获取下载 Token */
|
||||
@SuppressWarnings("unchecked")
|
||||
private String fetchDownloadToken() {
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Content-Type", "application/json");
|
||||
HttpEntity<Map<String, String>> request = new HttpEntity<>(
|
||||
Map.of("systemCode", "gateway"), headers);
|
||||
ResponseEntity<Map> resp = fileServiceRestTemplate.postForEntity(
|
||||
fileServiceUrl + "/api/token", request, Map.class);
|
||||
if (resp.getBody() != null && resp.getBody().get("data") instanceof Map) {
|
||||
Map<String, Object> data = (Map<String, Object>) resp.getBody().get("data");
|
||||
Object token = data.get("token");
|
||||
return token != null ? token.toString() : null;
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.warn("获取文件服务 Token 异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 向客户端返回错误 */
|
||||
private void respondError(HttpServletResponse response, int status, String msg) {
|
||||
try {
|
||||
response.setStatus(status);
|
||||
response.setContentType("text/plain;charset=UTF-8");
|
||||
response.getWriter().write(msg);
|
||||
response.getWriter().flush();
|
||||
} catch (IOException ignored) {
|
||||
// 连接可能已断开,忽略
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ FROM harbor.zgitm.com/library/eclipse-temurin:17-jre
|
||||
WORKDIR /app
|
||||
COPY target/*.jar app.jar
|
||||
EXPOSE 32001
|
||||
ENTRYPOINT ["java","-jar","app.jar"]
|
||||
ENTRYPOINT ["java","-Xms256m","-Xmx512m","-XX:+UseG1GC","-XX:MaxGCPauseMillis=200","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=/app/dump.hprof","-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=Asia/Shanghai","-jar","app.jar"]
|
||||
@@ -16,8 +16,8 @@ public class AuthApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AuthApplication.class, args);
|
||||
System.out.println("========================================");
|
||||
System.out.println(" 认证用户服务启动成功! 端口: 9001");
|
||||
System.out.println(" Knife4j 文档: http://localhost:9001/doc.html");
|
||||
System.out.println(" 认证用户服务启动成功! 端口: 32001");
|
||||
System.out.println(" Knife4j 文档: http://localhost:32001/doc.html");
|
||||
System.out.println("========================================");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ FROM harbor.zgitm.com/library/eclipse-temurin:17-jre
|
||||
WORKDIR /app
|
||||
COPY target/*.jar app.jar
|
||||
EXPOSE 32000
|
||||
ENTRYPOINT ["java","-jar","app.jar"]
|
||||
ENTRYPOINT ["java","-Xms256m","-Xmx512m","-XX:+UseG1GC","-XX:MaxGCPauseMillis=200","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=/app/dump.hprof","-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=Asia/Shanghai","-jar","app.jar"]
|
||||
@@ -16,7 +16,7 @@ public class GatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GatewayApplication.class, args);
|
||||
System.out.println("========================================");
|
||||
System.out.println(" 网关服务启动成功! 端口: 9000");
|
||||
System.out.println(" 网关服务启动成功! 端口: 32000");
|
||||
System.out.println("========================================");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ public class GatewayController {
|
||||
private final RestTemplate restTemplate;
|
||||
private final SysSystemMapper sysSystemMapper;
|
||||
|
||||
@Value("${gateway.route.auth-url:http://127.0.0.1:9001}")
|
||||
@Value("${gateway.route.auth-url:http://127.0.0.1:32001}")
|
||||
private String authServiceUrl;
|
||||
|
||||
@Value("${gateway.route.admin-url:http://127.0.0.1:9002}")
|
||||
@Value("${gateway.route.admin-url:http://127.0.0.1:32002}")
|
||||
private String adminServiceUrl;
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,8 +26,8 @@ mybatis-plus:
|
||||
|
||||
gateway:
|
||||
route:
|
||||
auth-url: http://10.10.1.170:9001
|
||||
admin-url: http://10.10.1.170:9002
|
||||
auth-url: http://10.20.1.170:32001
|
||||
admin-url: http://10.20.1.170:32002
|
||||
|
||||
logging:
|
||||
level:
|
||||
|
||||
@@ -26,8 +26,8 @@ mybatis-plus:
|
||||
|
||||
gateway:
|
||||
route:
|
||||
auth-url: http://127.0.0.1:9001
|
||||
admin-url: http://127.0.0.1:9002
|
||||
auth-url: http://127.0.0.1:32001
|
||||
admin-url: http://127.0.0.1:32002
|
||||
|
||||
logging:
|
||||
level:
|
||||
|
||||
4
mokee-gateway-web/Dockerfile
Normal file
4
mokee-gateway-web/Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
||||
FROM harbor.zgitm.com/library/nginx:alpine
|
||||
COPY dist/ /usr/share/nginx/html/
|
||||
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 80
|
||||
@@ -74,7 +74,7 @@
|
||||
-->
|
||||
<div
|
||||
id="mokee-user-chip"
|
||||
data-api-base="http://127.0.0.1:9000"
|
||||
data-api-base="http://127.0.0.1:32000"
|
||||
></div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
52
mokee-gateway-web/nginx/nginx.conf
Normal file
52
mokee-gateway-web/nginx/nginx.conf
Normal file
@@ -0,0 +1,52 @@
|
||||
# ==========================================
|
||||
# Vue 项目 Nginx 配置模板
|
||||
# 配合 Dockerfile.vue 使用
|
||||
# ==========================================
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
# 日志格式
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
# 站点根目录
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# 静态资源长期缓存
|
||||
location /assets/ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Vue Router history 模式支持
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# API 代理(如果有后端代理需求,可在此配置)
|
||||
# location /api/ {
|
||||
# proxy_pass http://backend-server:8080/;
|
||||
# proxy_set_header Host $host;
|
||||
# proxy_set_header X-Real-IP $remote_addr;
|
||||
# }
|
||||
|
||||
# Gzip 压缩
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_comp_level 6;
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
text/xml
|
||||
text/javascript
|
||||
application/json
|
||||
application/javascript
|
||||
application/xml+rss
|
||||
application/x-javascript
|
||||
image/svg+xml;
|
||||
gzip_min_length 1024;
|
||||
gzip_proxied any;
|
||||
}
|
||||
@@ -74,7 +74,7 @@
|
||||
-->
|
||||
<div
|
||||
id="mokee-user-chip"
|
||||
data-api-base="http://127.0.0.1:9000"
|
||||
data-api-base="http://127.0.0.1:32000"
|
||||
></div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
<el-radio-button value="builtin">内置图标</el-radio-button>
|
||||
<el-radio-button value="upload">已上传</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-button v-if="tab === 'upload'" size="small" type="primary" :loading="uploading" @click="triggerUploadIcon">
|
||||
<el-icon><Upload /></el-icon>上传
|
||||
</el-button>
|
||||
<input ref="fileInputRef" type="file" accept="image/*" style="display:none" @change="onIconFileSelected" />
|
||||
<el-input v-model="search" placeholder="搜索..." size="small" clearable style="width:200px" />
|
||||
<span class="count">{{ filtered.length }} 个</span>
|
||||
<el-icon class="close-btn" :size="20" @click="visible = false"><Close /></el-icon>
|
||||
@@ -37,6 +41,11 @@
|
||||
</div>
|
||||
|
||||
<!-- 已上传图标 -->
|
||||
<div v-if="tab === 'upload' && uploading" class="upload-status-bar">
|
||||
<el-icon class="is-loading"><Loading /></el-icon>
|
||||
<span>正在上传图标...</span>
|
||||
<el-progress :percentage="uploadPercent" :stroke-width="6" :show-text="true" style="flex:1;max-width:200px" />
|
||||
</div>
|
||||
<div class="icon-grid uploaded-grid" v-if="tab === 'upload' && filteredUploads.length > 0">
|
||||
<div
|
||||
v-for="item in filteredUploads" :key="item.id"
|
||||
@@ -59,7 +68,8 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ArrowDown, Close } from '@element-plus/icons-vue'
|
||||
import { ArrowDown, Close, Upload, Loading } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import * as Icons from '@element-plus/icons-vue'
|
||||
import request from '@/utils/request'
|
||||
|
||||
@@ -71,6 +81,12 @@ const search = ref('')
|
||||
const tab = ref('builtin')
|
||||
const uploadedIcons = ref<{id:string, fileName:string}[]>([])
|
||||
|
||||
// 上传相关状态
|
||||
const FILE_SERVICE = import.meta.env.VITE_FILE_SERVICE_URL || 'https://file.wg.zgitm.com'
|
||||
const uploading = ref(false)
|
||||
const uploadPercent = ref(0)
|
||||
const fileInputRef = ref<HTMLInputElement>()
|
||||
|
||||
const gatewayUrl = import.meta.env.VITE_GATEWAY_URL || ''
|
||||
|
||||
function isUrl(v: string) { return v && (v.startsWith('http') || v.startsWith('/zgapi')) }
|
||||
@@ -101,6 +117,77 @@ async function fetchUploadedIcons() {
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/** 获取文件服务上传 Token(直调文件服务,不走网关) */
|
||||
let cachedFileToken = ''
|
||||
async function getFileServiceToken(): Promise<string> {
|
||||
if (cachedFileToken) return cachedFileToken
|
||||
try {
|
||||
const axios = (await import('axios')).default
|
||||
const res = await axios.post(`${FILE_SERVICE}/api/token`, { systemCode: 'gateway' }, { timeout: 10000 })
|
||||
const token = res.data?.data?.token || ''
|
||||
if (token) cachedFileToken = token
|
||||
return token
|
||||
} catch { return '' }
|
||||
}
|
||||
|
||||
/** 触发文件选择器 */
|
||||
function triggerUploadIcon() {
|
||||
fileInputRef.value?.click()
|
||||
}
|
||||
|
||||
/** 文件选择后立即上传 */
|
||||
async function onIconFileSelected(e: Event) {
|
||||
const files = (e.target as HTMLInputElement).files
|
||||
if (!files || files.length === 0) return
|
||||
const file = files[0]
|
||||
// 重置 input 以允许重复选择同一文件
|
||||
if (fileInputRef.value) fileInputRef.value.value = ''
|
||||
|
||||
uploading.value = true
|
||||
uploadPercent.value = 0
|
||||
|
||||
try {
|
||||
// 1. 获取上传 Token
|
||||
const token = await getFileServiceToken()
|
||||
if (!token) {
|
||||
ElMessage.error('获取上传 Token 失败')
|
||||
return
|
||||
}
|
||||
|
||||
// 2. 上传到文件服务(指定 fileType=icon)
|
||||
const axios = (await import('axios')).default
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
fd.append('fileType', 'icon')
|
||||
const uploadRes = await axios.post(`${FILE_SERVICE}/api/upload`, fd, {
|
||||
timeout: 120000,
|
||||
headers: { Authorization: 'Bearer ' + token },
|
||||
onUploadProgress: (e: any) => {
|
||||
if (e.total > 0) uploadPercent.value = Math.round((e.loaded / e.total) * 100)
|
||||
},
|
||||
})
|
||||
|
||||
// Token 用完即清
|
||||
cachedFileToken = ''
|
||||
|
||||
// 3. 刷新已上传图标列表
|
||||
await fetchUploadedIcons()
|
||||
|
||||
// 4. 自动选中新上传的图标
|
||||
const fileId = uploadRes.data?.data?.fileId
|
||||
if (fileId) {
|
||||
select(getFileUrl(fileId))
|
||||
}
|
||||
ElMessage.success('图标上传成功')
|
||||
} catch {
|
||||
cachedFileToken = ''
|
||||
ElMessage.error('图标上传失败')
|
||||
} finally {
|
||||
uploading.value = false
|
||||
uploadPercent.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
function select(val: string) {
|
||||
emit('update:modelValue', val)
|
||||
visible.value = false
|
||||
@@ -122,7 +209,7 @@ onMounted(fetchUploadedIcons)
|
||||
.arrow { color: var(--text-muted); flex-shrink: 0; }
|
||||
|
||||
.icon-overlay {
|
||||
position: fixed; inset: 0; z-index: 9000;
|
||||
position: fixed; inset: 0; z-index: 32000;
|
||||
background: rgba(0,0,0,0.35);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
@@ -159,10 +246,21 @@ onMounted(fetchUploadedIcons)
|
||||
/* 触发器中的图片预览 */
|
||||
.trigger-img { width:20px; height:20px; object-fit:contain; border-radius:3px; }
|
||||
|
||||
/* 上传进度条 */
|
||||
.upload-status-bar {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
padding: 12px 20px; margin: 0 20px;
|
||||
background: var(--color-primary-bg, #eef2ff); border-radius: var(--radius-md);
|
||||
font-size: 13px; color: var(--color-primary);
|
||||
}
|
||||
.upload-status-bar .is-loading { animation: spin 1s linear infinite; }
|
||||
|
||||
/* 已上传图标 */
|
||||
.uploaded-grid { grid-template-columns: repeat(8, 1fr); }
|
||||
.upload-icon-thumb { width:48px; height:48px; object-fit:contain; border-radius:var(--radius-sm); }
|
||||
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
|
||||
@media (max-width:960px) {
|
||||
.icon-popup { width:98vw; max-height:90vh; }
|
||||
.icon-grid { grid-template-columns: repeat(6, 1fr); }
|
||||
|
||||
@@ -31,7 +31,7 @@ cur.execute("INSERT INTO sys_user (id, username, password, real_name, email, pho
|
||||
test_sid = uid()
|
||||
gw_sid = uid()
|
||||
cur.execute("INSERT INTO sys_system (id,system_code,system_name,front_url,backend_url,gateway_url,status,description) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",
|
||||
(test_sid, 'test', '测试系统', 'http://127.0.0.1:5001', 'http://127.0.0.1:9000', 'http://127.0.0.1:9000/test', 1, '测试用业务系统'))
|
||||
(test_sid, 'test', '测试系统', 'http://127.0.0.1:5001', 'http://127.0.0.1:32000', 'http://127.0.0.1:9000/test', 1, '测试用业务系统'))
|
||||
cur.execute("INSERT INTO sys_system (id,system_code,system_name,front_url,backend_url,gateway_url,icon,sort_order,status,description,doc_token) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
|
||||
(gw_sid, 'gateway', '网关管理平台', 'http://127.0.0.1:5001', 'http://127.0.0.1:9000', 'http://127.0.0.1:9000/gateway', '', 0, 1, '统一登录网关管理后台', 'gateway1234567890'))
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ ALTER TABLE sys_system MODIFY doc_token VARCHAR(128) DEFAULT NULL;
|
||||
-- 去重约束
|
||||
ALTER TABLE sys_system ADD UNIQUE KEY uk_gateway_url (gateway_url);
|
||||
-- 更新现有数据: 给每个系统一个不同的 gateway_url
|
||||
UPDATE sys_system SET gateway_url = CONCAT('http://127.0.0.1:9000/', system_code) WHERE gateway_url = '';
|
||||
UPDATE sys_system SET gateway_url = CONCAT('http://127.0.0.1:32000/', system_code) WHERE gateway_url = '';
|
||||
|
||||
-- 2. sys_file: 重建为新结构(文件二进制存入数据库)
|
||||
DROP TABLE IF EXISTS sys_file;
|
||||
|
||||
@@ -7,11 +7,11 @@ VALUES (REPLACE(UUID(),'-',''), 'admin', '$2b$10$ffAZHF6lmUuNV6OJITADXeduD5mMTS0
|
||||
|
||||
-- 测试系统
|
||||
INSERT INTO sys_system (id, system_code, system_name, front_url, backend_url, gateway_url, status, description)
|
||||
VALUES (REPLACE(UUID(),'-',''), 'test', '测试系统', 'http://127.0.0.1:5001', 'http://127.0.0.1:9000', 'http://127.0.0.1:9000/test', 1, '测试用业务系统');
|
||||
VALUES (REPLACE(UUID(),'-',''), 'test', '测试系统', 'http://127.0.0.1:5001', 'http://127.0.0.1:32000', 'http://127.0.0.1:32000/test', 1, '测试用业务系统');
|
||||
|
||||
-- Gateway 系统
|
||||
INSERT INTO sys_system (id, system_code, system_name, front_url, backend_url, gateway_url, icon, sort_order, status, description, doc_token)
|
||||
VALUES (REPLACE(UUID(),'-',''), 'gateway', '网关管理平台', 'http://127.0.0.1:5001', 'http://127.0.0.1:9000', 'http://127.0.0.1:9000/gateway', '', 0, 1, '统一登录网关管理后台', 'gateway1234567890');
|
||||
VALUES (REPLACE(UUID(),'-',''), 'gateway', '网关管理平台', 'http://127.0.0.1:5001', 'http://127.0.0.1:32000', 'http://127.0.0.1:32000/gateway', '', 0, 1, '统一登录网关管理后台', 'gateway1234567890');
|
||||
|
||||
-- 查询已插入的ID
|
||||
SELECT id INTO @uid FROM sys_user WHERE username='admin';
|
||||
|
||||
@@ -30,23 +30,23 @@
|
||||
↓
|
||||
[业务系统前端] → [统一登录页面(https://login.user.zgitm.com)]
|
||||
↓
|
||||
[网关服务(9000)] → [认证用户服务(9001)]
|
||||
[网关服务(32000)] → [认证用户服务(32001)]
|
||||
↓ ↓
|
||||
[业务系统后端] ← [业务管理服务(9002)]
|
||||
[业务系统后端] ← [业务管理服务(32002)]
|
||||
↓
|
||||
[MySQL数据库] ← [Redis缓存]
|
||||
```
|
||||
|
||||
### 2.2 微服务拆分与职责
|
||||
|
||||
#### 2.2.1 网关服务(mokee-gateway-gateway)- 端口9000
|
||||
#### 2.2.1 网关服务(mokee-gateway-gateway)- 端口32000
|
||||
- 统一入口:所有业务系统的接口请求和页面访问统一经过网关
|
||||
- 路由转发:根据配置的系统信息,将请求转发到对应的业务系统后端
|
||||
- 身份认证:校验请求中的Token有效性,拦截未登录请求
|
||||
- 信息透传:将用户ID、用户名、角色、岗位、系统ID等信息注入请求头,传递给业务系统后端
|
||||
- 接口鉴权:校验请求接口是否在业务系统的放行列表中
|
||||
|
||||
#### 2.2.2 认证用户服务(mokee-gateway-auth)- 端口9001
|
||||
#### 2.2.2 认证用户服务(mokee-gateway-auth)- 端口32001
|
||||
- 登录认证:处理用户登录请求,验证账号密码,生成Token
|
||||
- 用户管理:维护用户基本信息、用户与系统的绑定关系
|
||||
- 权限管理:维护角色、菜单信息,用户与角色的绑定关系
|
||||
@@ -54,7 +54,7 @@
|
||||
- 基础接口:提供获取用户信息、系统信息、菜单路由等基础接口
|
||||
- 系统选择:登录成功后判断用户绑定系统数量,返回系统列表或直接跳转
|
||||
|
||||
#### 2.2.3 业务管理服务(mokee-gateway-admin)- 端口9002
|
||||
#### 2.2.3 业务管理服务(mokee-gateway-admin)- 端口32002
|
||||
- 系统管理:维护业务系统的基本信息、域名配置、接口放行列表
|
||||
- 数据字典:维护全局通用的数据字典
|
||||
- 日志管理:记录用户登录日志和系统操作日志
|
||||
|
||||
Reference in New Issue
Block a user