etms/CODE_FIX_PLAN.md
liyuchen 512d57c5d9 Code fixes: global vars, date API, deprecated SQL, FTL comments
Fixed Issues:
- globalConfig.js: Added const declarations for 10 undeclared regex variables
- globalConfig.js: Fixed getDay() -> getDate() for date comparison
- Removed 16 deprecated SQL definitions from 4 map.xml files
- Cleaned 615+ commented code blocks from 115 FTL templates

Added:
- CODE_FIX_PLAN.md: Detailed fix plan for remaining issues

Remaining (documented in CODE_FIX_PLAN.md):
- 6 async: false AJAX requests to convert
- 120+ SELECT * to optimize
- 6265+ inline styles to refactor
2026-04-16 17:24:37 +08:00

312 lines
7.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# JCDP 项目代码修复方案
> **文档版本**: v1.0
> **创建时间**: 2026-04-16
> **依据**: [CODE_REVIEW_REPORT.md](./CODE_REVIEW_REPORT.md)
---
## 一、修复执行情况
### ✅ 已完成修复
| 序号 | 问题 | 修复文件 | 修复内容 |
|------|------|----------|----------|
| 1 | 全局变量未声明 | `globalConfig.js` | 为 8 个正则变量添加 `const` 声明 |
| 2 | 日期 API 误用 | `globalConfig.js` | `getDay()``getDate()` (第268、271行) |
| 3 | 废弃 SQL 清理 | 4 个 map.xml | 删除 16 个废弃 SQL 定义 |
| 4 | 注释死代码 | 115 个 ftl | 删除 615+ 处注释代码 |
### 📋 待处理问题
| 序号 | 问题 | 优先级 | 说明 |
|------|------|--------|------|
| 1 | 同步 AJAX 请求 | 🟠 严重 | 6 处 `async: false` 需要改为异步 |
| 2 | SELECT * 过多 | 🟡 建议 | 120+ 处可优化为指定字段 |
| 3 | 内联样式过多 | 🟡 建议 | 6265+ 处 style 属性待清理 |
| 4 | 内联事件处理 | 🟡 建议 | 115 处 onclick/onchange 待重构 |
---
## 二、已修复问题详情
### 2.1 全局变量声明修复
**文件**: `asset/js/etms/globalConfig.js`
**修复内容**: 为验证函数中的正则表达式变量添加 `const` 声明
```javascript
// 修复前
validator: function (val) {
isIDCard1 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
isIDCard2 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}[0-9xX]$/;
...
}
// 修复后
validator: function (val) {
const isIDCard1 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
const isIDCard2 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}[0-9xX]$/;
...
}
```
**涉及变量**: `isIDCard1`, `isIDCard2`, `isPostcode`, `isAboveAndEqualZero`, `isPositiveNumber`, `isPositiveInteger`, `isMonthNum`, `moreThanFive`, `isPointNum`, `isEmail`
---
### 2.2 日期 API 修复
**文件**: `asset/js/etms/globalConfig.js` 第 268、271 行
**修复内容**: `getDay()``getDate()`
```javascript
// 修复前
if (dateTime1.getDay() == dateTime2.getDay()) {
tempTime = dateTime2.format("hh:mm");
} else {
if (dateTime1.getDay() - dateTime2.getDay() == 1) {
tempTime = dateTime2.format("昨天 hh:mm");
}
}
// 修复后
if (dateTime1.getDate() == dateTime2.getDate()) {
tempTime = dateTime2.format("hh:mm");
} else {
if (dateTime1.getDate() - dateTime2.getDate() == 1) {
tempTime = dateTime2.format("昨天 hh:mm");
}
}
```
---
### 2.3 废弃 SQL 清理
**修复文件**:
- `chat.map.xml`: 删除 `updatePkgListToOld`
- `et_exam_editexampaper.map.xml`: 删除 `moveOld`
- `et_exam_usertest.map.xml`: 删除 10 个废弃 SQL
- `et_train_outtrain.map.xml`: 删除 2 个废弃 SQL
**清理的废弃 SQL ID**:
- `getExamResultList之前的写法在此备份`
- `truncateExamDetail备份`
- `getPersonDetail备份`
- `getClassDetail备份`
- `getCourseDetail备份`
- `getInstitutionDetail 第二种写法 最慢`
- `getDepartmentDetail 第二种写法 最慢`
- `getPersonDetail第二种写法`
- `getPersonDetail第三种写法 最慢`
- `getClassDetail 第二种写法 最慢`
- `getCourseDetail 第二种写法 最慢`
- `getOutTrainDbList以前的写法备份`
- `getOutTrainPxdjList以前的写法备份`
---
### 2.4 FTL 注释死代码清理
**清理统计**:
- 修改文件: 115 个
- 清理注释: 615+ 处
**高发文件** (Top 10):
| 文件 | 清理数量 |
|------|----------|
| `exampaper_editexampaper.ftl` | 74 处 |
| `examresult_edit.ftl` | 33 处 |
| `exam_edit.ftl` | 37 处 |
| `exampaper_add.ftl` | 29 处 |
| `group_inplan_main.ftl` | 61 处 |
| `group_inplan_bg_group_detail_1.ftl` | 34 处 |
| `group_inplan_bg_group_detail.ftl` | 32 处 |
| `research_project_main_examadd_sg.ftl` | 49 处 |
| `exampaper_import.ftl` | 21 处 |
| `pd_pg_main_assess.ftl` | 20 处 |
---
## 三、待处理问题修复方案
### 3.1 同步 AJAX 请求改造 (🟠 严重)
**问题位置**:
- `globalConfig.js` 第 200 行
- `userprofile/index.js` 第 71、104 行
- `train/uptrain/uptrain.js` 第 176 行
- `train/uptrain/uptrain_edit.js` 第 394 行
- `train/plantodo/assess_audit.js` 第 319 行
- `train/outtrain/out_train_main.js` 第 1209 行
**修复方案示例**:
```javascript
// 修复前 (globalConfig.js)
$.ajax({
type: 'post',
async: false, // 阻塞 UI
url: dictBaseUrl + dictKey,
dataType: 'json',
success: function (result) {
if (result.success) {
window[hdName] = result.data;
res = result.data;
}
}
});
// 修复后 (方案1: Promise + async/await)
async function getDictData(dictKey) {
try {
const result = await $.ajax({
type: 'post',
url: dictBaseUrl + dictKey,
dataType: 'json'
});
if (result.success) {
window[dict_prefix + dictKey] = result.data;
return result.data;
}
return null;
} catch (error) {
console.error('获取字典数据失败:', error);
return null;
}
}
// 修复后 (方案2: 回调函数)
function getDictData(dictKey, callback) {
$.ajax({
type: 'post',
url: dictBaseUrl + dictKey,
dataType: 'json',
success: function (result) {
if (result.success) {
window[dict_prefix + dictKey] = result.data;
callback(result.data);
} else {
callback(null);
}
},
error: function() {
callback(null);
}
});
}
```
**建议优先级**:
1. 优先改造 `globalConfig.js` 中的 `gridColFilter` 函数
2. 然后处理业务模块中的同步请求
3. 最后处理 `out_train_main.js` 等复杂模块
---
### 3.2 SELECT * 优化 (🟡 建议)
**优化原则**:
- 明确列出需要的字段
- 减少网络传输开销
- 提高代码可读性
**示例**:
```xml
<!-- 修复前 -->
<sql id="getFileList">
select * from et_resource_file where 1=1
</sql>
<!-- 修复后 -->
<sql id="getFileList">
select id, name, file_path, file_size, created_by, created_at
from et_resource_file where 1=1
</sql>
```
**建议**: 优先优化高频查询的 SQL
---
### 3.3 内联样式清理 (🟡 建议)
**优化方案**: 提取为 CSS 类
```html
<!-- 修复前 -->
<div class="formTitle" style="height: 86px"><span class="icon icon_menu"></span>
<!-- 修复后 -->
<!-- CSS -->
.form-title {
height: 86px;
}
<!-- HTML -->
<div class="form-title"><span class="icon icon_menu"></span>
```
**建议**:
1. 优先清理高频页面的内联样式
2. 建立公共样式类库
3. 使用 CSS 变量统一管理主题色
---
### 3.4 内联事件重构 (🟡 建议)
**优化方案**: 使用 data 属性 + JS 事件委托
```html
<!-- 修复前 -->
<input name="cbA" id="cbA" type="checkbox" value="A" onclick="checkBox(this)"/>
<!-- 修复后 -->
<!-- HTML -->
<input name="cbA" id="cbA" type="checkbox" value="A" class="checkbox-option"
data-check-action="checkBox"/>
<!-- JavaScript -->
$(document).on('click', '.checkbox-option', function() {
var action = $(this).data('check-action');
if (action && window[action]) {
window[action](this);
}
});
```
---
## 四、后续改进建议
### 4.1 短期 (1个月内)
- [ ] 完成同步 AJAX 改造
- [ ] 引入 ESLint 检查
- [ ] 建立代码格式化规范
### 4.2 中期 (3个月内)
- [ ] 优化高频 SQL 查询
- [ ] 清理内联样式
- [ ] 重构内联事件处理
### 4.3 长期 (持续改进)
- [ ] 引入自动化测试
- [ ] 建立代码质量度量
- [ ] 完善 Code Review 流程
---
## 五、相关文件
- [CODE_REVIEW_GUIDE.md](./CODE_REVIEW_GUIDE.md) - 代码审查标准
- [CODE_REVIEW_REPORT.md](./CODE_REVIEW_REPORT.md) - 代码审查报告
---
*本修复方案由 AI 代码审查专家生成*