From 4f01dc77628ad3d80b0399e5b0bfae137967939d Mon Sep 17 00:00:00 2001 From: aitest Date: Thu, 5 Mar 2026 14:23:40 +0900 Subject: [PATCH] Add comprehensive refactor action plan for frontend and backend projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - P0 (Critical): Dependency unification, adapter layer, idempotency, version control - P1 (Important): Legacy cleanup, caching, distributed transactions, pagination优化 - P2 (General): API documentation, performance monitoring, logging optimization Includes: - Detailed action plans with file paths and commands - Priority-based refactor roadmap - Implementation schedule (3-5 weeks) - Risk control guidelines --- refactor-action-plan.md | 476 ++++++++++++++++++++++++++++++++++++++++ refactor-summary.md | 88 ++++++++ 2 files changed, 564 insertions(+) create mode 100644 refactor-action-plan.md create mode 100644 refactor-summary.md diff --git a/refactor-action-plan.md b/refactor-action-plan.md new file mode 100644 index 0000000..66c8dd1 --- /dev/null +++ b/refactor-action-plan.md @@ -0,0 +1,476 @@ +# 前后端项目 - 可执行改造清单 + +## 🎯 改造优先级分类 + +### P0 - 紧急(影响稳定性/核心功能) +### P1 - 重要(影响维护性/扩展性) +### P2 - 一般(性能优化/用户体验) + +--- + +## 📁 前端项目改造清单 + +### P0 - 紧急改造 + +#### 🔴 P0-1: 统一LogicFlow依赖版本 +**风险**: 双命名空间版本并存可能导致冲突 +**文件**: `package.json` +**操作**: +```bash +# 1. 分析当前LogicFlow依赖 +npm list @logicflow/core @logicflow/extension +npm list @helinda-test-logicflow/core @helinda-test-logicflow/extension + +# 2. 确定保留版本(建议:官方版本) +# - 保留: @logicflow/core, @logicflow/extension +# - 移除: @helinda-test-logicflow/* + +# 3. 更新package.json,移除@helinda-test-logicflow依赖 +# 4. 安装官方版本 +npm install @logicflow/core@latest @logicflow/extension@latest + +# 5. 更新所有import语句 +find src -name "*.ts" -o -name "*.vue" | xargs sed -i 's/@helinda-test-logicflow/@logicflow/g' +``` + +**原因**: 降低版本冲突风险,便于后续升级 + +--- + +#### 🔴 P0-2: 添加自定义Node/Edge适配层 +**风险**: LogicFlow主版本升级可能破坏自定义组件 +**文件**: `src/views/plan-simulation-modeling/` +**操作**: +```typescript +// 创建: src/views/plan-simulation-modeling/logicflow-adapter.ts + +export interface LogicFlowComponent { + type: 'node' | 'edge'; + id: string; + properties: Record; +} + +export class LogicFlowAdapter { + // 包装所有自定义Node/Edge + static wrapNode(nodeType: string, config: any): LogicFlowComponent { + return { + type: 'node', + id: `custom-${nodeType}`, + properties: this.normalizeProperties(nodeType, config) + }; + } + + static normalizeProperties(type: string, config: any): Record { + // 版本兼容性处理 + return { + ...config, + _version: '1.0', + _type: type + }; + } +} +``` + +**替换**: +- `src/views/plan-simulation-modeling/components/Diagram.vue` +- 所有自定义node组件 + +**效果**: 解耦LogicFlow版本升级影响 + +--- + +### P1 - 重要改造 + +#### 🟡 P1-1: 清理an-old-version目录 +**风险**: 新旧逻辑混用导致维护困难 +**文件**: `src/views/plan-simulation-modeling/an-old-version/` +**操作**: +```bash +# 1. 确认old版本不再使用 +grep -r "an-old-version" src/ --exclude-dir=node_modules + +# 2. 如果无引用,直接删除 +rm -rf src/views/plan-simulation-modeling/an-old-version/ + +# 3. 更新路由(如果有) +# 移除 router/index.js 中的old-version路由 +``` + +**原因**: 避免新旧逻辑交叉污染 + +--- + +#### 🟡 P1-2: 添加组件单元测试 +**风险**: 修改Graph组件易引入bug +**文件**: `src/views/plan-simulation-modeling/components/` +**操作**: +```bash +# 1. 安装测试工具 +npm install --save-dev vitest @vue/test-utils + +# 2. 创建测试文件 +touch src/views/plan-simulation-modeling/components/__tests__/Diagram.spec.ts +``` + +**测试覆盖**: +- 图形组件渲染 +- 节点/edge拖拽 +- 属性面板更新 + +--- + +#### 🟡 P1-3: 优化API响应数据结构 +**风险**: 前端强依赖后端接口结构 +**文件**: `src/api/` +**操作**: +```typescript +// 创建: src/api/adapters/ +export class ServiceAdapter { + // 适配不同版本的API响应 + static adaptSimProject(response: any): SimProject { + return { + id: response.id || response.projectId, + name: response.name || response.projectName, + // 统一字段映射 + }; + } +} +``` + +**效果**: 解耦前后端接口变更 + +--- + +### P2 - 一般改造 + +#### 🟢 P2-1: 提取公共业务逻辑hooks +**文件**: `src/views/plan-simulation-modeling/components/` +**操作**: +```typescript +// 创建: src/hooks/useGraphOperations.ts +export function useGraphOperations(graph: LogicflowInstance) { + const addNode = (nodeType: string, x: number, y: number) => { + // 统一节点添加逻辑 + }; + + const deleteNode = (nodeId: string) => { + // 统一节点删除逻辑 + }; + + return { addNode, deleteNode }; +} +``` + +**效果**: 代码复用,减少重复逻辑 + +--- + +#### 🟢 P2-2: 优化构建配置 +**文件**: `vite.config.ts`, `package.json` +**操作**: +```typescript +// vite.config.ts +export default defineConfig({ + build: { + chunkSizeWarningLimit: 1000, // 分包大小限制 + rollupOptions: { + output: { + manualChunks: { + 'lodash-vendor': ['lodash-es'], + 'logicflow': ['@logicflow/core', '@logicflow/extension'] + } + } + } + } +}); +``` + +**效果**: 提升首屏加载性能 + +--- + +## 📁 后端项目改造清单 + +### P0 - 紧急改造 + +#### 🔴 P0-1: 添加幂等性控制标识 +**风险**: 重复提交导致数据不一致 +**文件**: 所有Controller层 +**操作**: +```java +// 创建: business-common/src/main/java/.../annotation/Idempotent.java +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Idempotent { + String keyPrefix() default ""; + long timeout() default 10; +} + +// 在关键接口添加,例如: +@Idempotent(keyPrefix = "sim:create", timeout = 30) +@PostMapping("/sim/create") +public Result createSimProject(@RequestBody SimProjectDTO dto) { + // 业务逻辑 +} +``` + +**影响文件**: +- `business-core/main/java/.../sim/controller/SimProjectController.java` +- `business-core/main/java/.../sim/controller/SimController.java` + +--- + +#### 🔴 P0-2: 添加API版本控制 +**风险**: API变更导致前端客户端兼容性问题 +**文件**: `application/src/main/resources/application.yml` +**操作**: +```yaml +# application.yml +spring: + mvc: + pathmatch: + matching-strategy: ant-path-matcher + +# 新建: config-web/pom.xml + + org.springframework.boot + spring-boot-starter-validation + +``` + +**URL版本化**: +- `/v1/api/sim/project` → 现有 +- `/v2/api/sim/project` → 新版本 + +--- + +#### 🔴 P0-3: 完善异常统一处理 +**风险**: 异常信息泄露或格式不统一 +**文件**: `business-common/.../exception/GlobalExceptionHandler.java` +**操作**: +```java +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(Exception.class) + public Result handleGeneralException(Exception e) { + log.error("系统异常", e); + return Result.error("系统繁忙,请稍后重试"); + } + + @ExceptionHandler(ValidationException.class) + public Result handleValidationException(ValidationException e) { + return Result.fail("参数校验失败: " + e.getMessage()); + } + + @ExceptionHandler(BadTimeOverlapException.class) + public Result handleBusinessException(BadTimeOverlapException e) { + return Result.error(e.getMessage()); + } +} +``` + +--- + +### P1 - 重要改造 + +#### 🟡 P1-1: 添加缓存层(Redis) +**风险**: 高频查询导致数据库压力 +**文件**: `business-support/src/main/java/.../simmodel/` +**操作**: +```java +// 添加依赖 + + org.springframework.boot + spring-boot-starter-data-redis + + +// 创建: business-support/src/main/java/.../cache/SimModelCache.java +@Service +public class SimModelCache { + + @Autowired + private RedisTemplate redisTemplate; + + public SimModel getById(Long id) { + String key = "sim: модель:" + id; + SimModel model = (SimModel) redisTemplate.opsForValue().get(key); + if (model == null) { + model = simModelMapper.selectById(id); + redisTemplate.opsForValue().set(key, model, 30, TimeUnit.MINUTES); + } + return model; + } +} +``` + +**影响**: 所有频繁查询的Service层 + +--- + +#### 🟡 P1-2: 添加分布式事务控制 +**风险**: 微服务间数据不一致 +**文件**: `application/pom.xml` +**操作**: +```xml + + io.seata + seata-spring-boot-starter + 1.5.1 + +``` + +**应用范围**: 跨服务业务操作 + +--- + +#### 🟡 P1-3: 优化MyBatis分页查询 +**风险**: 大数据量查询性能问题 +**文件**: `business-support/pom.xml` (已包含PageHelper) +**操作**: +```java +// 需优化的示例 +public PageInfo queryPhmmResult(PageRequest req) { + PageHelper.startPage(req.getPageNum(), req.getPageSize()); + List list = phmmProductionDao.selectList(req); + PageInfo pageInfo = new PageInfo<>(list); + return pageInfo; +} +``` + +**SQL优化**: 添加索引、优化查询条件 + +--- + +### P2 - 一般改造 + +#### 🟢 P2-1: 添加API文档管理 +**文件**: 所有Controller +**操作```java +// 在Controller上统一添加注解 +@Api(tags = "仿真项目管理") +@ApiVersion("v1") +@RestController +@RequestMapping("/v1/api/sim") +public class SimProjectController { + + @ApiOperation("创建仿真项目") + @PostMapping("/project") + public Result create(@RequestBody @Validated SimProjectDTO dto) { + // 业务逻辑 + } +} +``` + +**访问**: http://localhost:8080/swagger-ui.html + +--- + +#### 🟢 P2-2: 添加性能监控指标 +**文件**: `application/pom.xml` +**操作**: +```java +// 添加Micrometer + + org.springframework.boot + spring-boot-starter-actuator + + +// 自定义性能指标 +@Component +public class SimPerformanceMetrics { + + private final MeterRegistry registry; + + public void recordSimulationDuration(long duration) { + registry.timer("simulation.duration") + .record(duration, TimeUnit.MILLISECONDS); + } +} +``` + +--- + +#### 🟢 P2-3: 优化日志结构 +**文件**: `application/src/main/resources/logback-spring.xml` +**操作**: +```xml + + logs/application.log + + logs/application-%d{yyyy-MM-dd}.log + 30 + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + + +``` + +--- + +## 🔧 开发环境配置改造 + +### P1 - 重要 + +#### 🟡 P1-4: 统一开发工具配置 +**文件**: `.editorconfig`, `.prettierrc` +**操作**: +```ini +# .editorconfig +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{ts,js,vue,java}] +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false +``` + +--- + +## 🚀 实施计划建议 + +### 第一阶段(1-2周) +- P0-1: 统一LogicFlow依赖 +- P0-2: 添加Node/Edge适配层 +- P0-3: 添加幂等性控制 + +### 第二阶段(2-3周) +- P1-1: 清理old-version目录 +- P1-2: 添加单元测试 +- P1-3: 优化API响应结构 +- P2-1: 提取公共hooks + +### 第三阶段(1-2周) +- P1-4: 添加缓存层 +- P1-5: 添加分布式事务 +- P1-6: 优化MyBatis分页 + +### 第四阶段(按需) +- P2-2: 添加API文档 +- P2-3: 添加性能监控 +- P2-4: 优化日志结构 + +--- + +## ⚠️ 风险控制 + +1. **每个P0改造必须在测试环境验证** +2. **P1改造建议逐步迭代,分批上线** +3. **P2改造可并行进行,根据资源安排** +4. **所有改造都需要备份当前代码** +5. **改造前先建立基线测试** + +--- + +**建议优先执行: P0-1 → P0-2 → P0-3** +**预计总工作量**: 3-5周(根据团队规模调整) diff --git a/refactor-summary.md b/refactor-summary.md new file mode 100644 index 0000000..fc4214b --- /dev/null +++ b/refactor-summary.md @@ -0,0 +1,88 @@ +# 前后端项目可执行改造清单 + +## 🎯 改造优先级 + +### P0 - 紧急(影响稳定性/核心功能) +### P1 - 重要(影响维护性/扩展性) +### P2 - 一般(性能优化/用户体验) + +--- + +## 📁 前端项目 + +### P0 - 紧急改造 + +#### 🔴 P0-1: 统一LogicFlow依赖版本 +**文件**: `F:\ips\node-test-mod\package.json` +**问题**: 双命名空间版本并存 +**操作**: 统一为官方版本,移除@helinda-test-logicflow依赖 + +#### 🔴 P0-2: 添加LogicFlow组件适配层 +**文件**: `F:\ips\node-test-mod\src\views\plan-simulation-modeling\` +**操作**: 创建adapter模式解耦版本升级影响 + +--- + +## 📁 后端项目 + +### P0 - 紧急改造 + +#### 🔴 P0-1: 添加幂等性控制 +**文件**: `F:\ips\java_test_back\business-core\src\main\java\...\sim\controller\` +**问题**: 重复提交风险 +**操作**: 添加@Idempotent注解和去重逻辑 + +#### 🔴 P0-2: API版本控制 +**文件**: `F:\ips\java_test_back\application\src\main\resources\application.yml` +**问题**: 接口变更兼容性 +**操作**: 实现URL版本化(/v1/api, /v2/api) + +#### 🔴 P0-3: 统一异常处理 +**文件**: `F:\ips\java_test_back\business-common\...\exception\GlobalExceptionHandler.java` +**问题**: 异常信息不统一 +**操作**: 完善全局异常处理器 + +--- + +### P1 - 重要改造 + +#### 🟡 P1-1: 清理old-version目录 +**文件**: `F:\ips\node-test-mod\src\views\plan-simulation-modeling\an-old-version\` + +#### 🟡 P1-2: 添加Redis缓存层 +**文件**: `F:\ips\java_test_back\business-support\` +**问题**: 高频查询压力 +**操作**: 使用Spring Data Redis缓存 + +--- + +## 🚀 实施计划 + +### 第一阶段(1-2周) +- 前端: P0-1, P0-2 +- 后端: P0-1, P0-3 + +### 第二阶段(2-3周) +- 前端: P1-1, P1-2 +- 后端: P1-1, P1-2 + +### 第三阶段(1-2周) +- 后端: P1-4, P1-5, P1-6 + +### 第四阶段(按需) +- P2所有任务 + +--- + +## ⚠️ 注意事项 + +1. 每个P0改造都需要测试环境验证 +2. P1改造建议分批迭代 +3. P2改造可并行进行 +4. 所有改造前必须备份代码 +5. 建立基线测试 + +--- + +**预计工作量**: 3-5周 +**建议**: 优先执行 P0 → P1 → P2