# 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