Files
hzdyjs/docs/开发文档/学生考核申请指标数据获取功能开发说明.md
T
2025-08-21 16:24:34 +08:00

325 lines
8.4 KiB
Markdown

# 学生考核申请指标数据获取功能开发说明
## 📋 功能概述
**功能名称**: 学生考核申请指标数据动态获取
**开发时间**: 2025-01-03
**模块**: 学工管理-学生考核管理
**功能描述**: 当学生新增考核申请时,系统根据考核计划ID自动获取关联的指标数据,填入到指标模块中
---
## 🎯 业务需求
### 原始问题
- 学生考核申请表单中的指标模块数据是硬编码的
- 无法根据不同的考核计划动态显示对应的指标
- 指标数据应该来源于考核方案关联指标体系表
### 解决方案
- 根据考核计划ID → 获取考核方案ID → 查询考核方案关联指标体系表
- 动态获取指标数据并填入表单
- 支持不同考核计划显示不同的指标组合
---
## 🏗️ 技术实现
### 1. 数据库关联关系
```
xskh_assessment_schedule (考核计划表)
↓ plan_id
xskh_assessment_plan (考核方案表)
↓ plan_id
xskh_assessment_plan_indicator (考核方案关联指标体系表)
↓ indicator_id
xskh_assessment_indicator (考核指标体系表)
```
### 2. 前端实现
#### 2.1 API接口扩展
**文件**: `web/src/api/xskh/assessmentApplication/assessmentApplication.ts`
```typescript
// 根据考核计划ID获取关联的指标数据
export function getIndicatorsByScheduleId(scheduleId: string | number) {
return request({
url: `/assessment/application/indicators/${scheduleId}`,
method: 'get'
});
}
```
#### 2.2 组件逻辑修改
**文件**: `web/src/views/xskh/assessmentApplication/AssessmentApplicationForm.vue`
**主要修改**:
1. 导入新的API接口
2. 添加`loadIndicatorsByScheduleId`方法
3. 修改`openDialog`方法,新增时调用指标数据获取
4. 修复接口类型定义,添加`fileList`属性
**核心方法**:
```typescript
/** 根据考核计划ID获取关联的指标数据 */
const loadIndicatorsByScheduleId = async (scheduleId: string | number) => {
try {
const response = await getIndicatorsByScheduleId(scheduleId);
if (response.code === 200 && response.data) {
// 将指标数据转换为自评得分列表格式
form.value.selfScoreList = response.data.map((item: any) => ({
id: undefined,
applicationId: undefined,
indicatorId: item.indicatorId,
indicatorName: item.indicatorName,
indicatorCode: item.indicatorCode,
indicatorDescription: item.description,
indicatorMaxScore: item.maxScore,
planMaxScore: item.maxScore, // 使用方案中设置的最高分值
sortOrder: item.sortOrder,
selfScore: 0,
selfRemark: '',
teacherScore: 0,
teacherRemark: ''
}));
}
} catch (error) {
console.error('获取指标数据失败:', error);
form.value.selfScoreList = [];
}
};
```
### 3. 后端实现
#### 3.1 Controller层
**文件**: `backend/ruoyi-modules/ruoyi-xskh/src/main/java/org/dromara/xskh/controller/XskhAssessmentApplicationApprovalController.java`
```java
/**
* 根据考核计划ID获取关联的指标数据
*/
@SaCheckPermission("assessment:application:query")
@GetMapping("/indicators/{scheduleId}")
public R<List<Object>> getIndicatorsByScheduleId(
@NotNull(message = "考核计划ID不能为空") @PathVariable Long scheduleId) {
return R.ok(xskhAssessmentApplicationApprovalService.getIndicatorsByScheduleId(scheduleId));
}
```
#### 3.2 Service层
**文件**: `backend/ruoyi-modules/ruoyi-xskh/src/main/java/org/dromara/xskh/service/IXskhAssessmentApplicationApprovalService.java`
```java
/**
* 根据考核计划ID获取关联的指标数据
*/
List<Object> getIndicatorsByScheduleId(Long scheduleId);
```
**实现类**: `backend/ruoyi-modules/ruoyi-xskh/src/main/java/org/dromara/xskh/service/impl/XskhAssessmentApplicationApprovalServiceImpl.java`
```java
/**
* 根据考核计划ID获取关联的指标数据
*/
@Override
public List<Object> getIndicatorsByScheduleId(Long scheduleId) {
// 1. 根据考核计划ID获取考核方案ID
XskhAssessmentScheduleVo schedule = assessmentScheduleService.queryById(scheduleId);
if (schedule == null) {
return new ArrayList<>();
}
Long planId = schedule.getPlanId();
if (planId == null) {
return new ArrayList<>();
}
// 2. 根据考核方案ID查询关联的指标数据
List<Object> indicators = baseMapper.selectIndicatorsByPlanId(planId);
return indicators;
}
```
#### 3.3 Mapper层
**文件**: `backend/ruoyi-modules/ruoyi-xskh/src/main/java/org/dromara/xskh/mapper/XskhAssessmentApplicationApprovalMapper.java`
```java
/**
* 根据考核方案ID查询关联的指标数据
*/
List<Object> selectIndicatorsByPlanId(Long planId);
```
**XML文件**: `backend/ruoyi-modules/ruoyi-xskh/src/main/resources/mapper/xskh/XskhAssessmentApplicationApprovalMapper.xml`
```xml
<!-- 根据考核方案ID查询关联的指标数据 -->
<select id="selectIndicatorsByPlanId" parameterType="Long" resultType="java.util.Map">
SELECT
i.id as indicatorId,
i.indicator_code as indicatorCode,
i.indicator_name as indicatorName,
i.description,
pi.max_score as maxScore,
pi.weight,
pi.sort_order as sortOrder
FROM xskh_assessment_plan_indicator pi
INNER JOIN xskh_assessment_indicator i ON pi.indicator_id = i.id
WHERE pi.plan_id = #{planId}
AND pi.deleted = 0
AND i.deleted = 0
ORDER BY pi.sort_order ASC, i.sort_order ASC
</select>
```
---
## 🔄 业务流程
### 1. 学生新增考核申请流程
```
1. 学生选择考核计划
2. 系统根据考核计划ID获取考核方案ID
3. 根据考核方案ID查询关联的指标数据
4. 将指标数据转换为表单格式
5. 填入指标模块表格中
6. 学生可以进行自评打分
```
### 2. 数据流转过程
```
前端选择考核计划 → 调用API接口 → 后端查询数据库 → 返回指标数据 → 前端渲染表格
```
---
## 📊 数据结构
### 返回的指标数据结构
```json
{
"code": 200,
"msg": "操作成功",
"data": [
{
"indicatorId": 1,
"indicatorCode": "ZD001",
"indicatorName": "思想道德",
"description": "思想道德表现",
"maxScore": 20.00,
"weight": 1.00,
"sortOrder": 1
},
{
"indicatorId": 2,
"indicatorCode": "ZD002",
"indicatorName": "学习表现",
"description": "学习表现情况",
"maxScore": 30.00,
"weight": 1.00,
"sortOrder": 2
}
]
}
```
### 转换后的表单数据结构
```typescript
{
id: undefined,
applicationId: undefined,
indicatorId: 1,
indicatorName: "思想道德",
indicatorCode: "ZD001",
indicatorDescription: "思想道德表现",
indicatorMaxScore: 20,
planMaxScore: 20,
sortOrder: 1,
selfScore: 0,
selfRemark: "",
teacherScore: 0,
teacherRemark: ""
}
```
---
## 🔐 权限配置
### API权限
- **权限字符**: `assessment:application:query`
- **说明**: 查询考核申请相关数据的权限
- **应用**: 获取指标数据接口
### 菜单权限
- 无需额外配置,复用现有的考核申请查询权限
---
## 🧪 测试验证
### 1. 功能测试
- [ ] 选择不同的考核计划,验证指标数据是否正确获取
- [ ] 验证指标数据的完整性和准确性
- [ ] 验证排序是否正确
- [ ] 验证最高分值是否正确显示
### 2. 异常测试
- [ ] 考核计划不存在的情况
- [ ] 考核方案未关联指标的情况
- [ ] 网络异常的情况
- [ ] 权限不足的情况
### 3. 性能测试
- [ ] 大量指标数据的加载性能
- [ ] 并发访问的性能表现
---
## 📝 注意事项
### 1. 开发注意事项
- 确保数据库表结构正确
- 注意逻辑删除字段的处理
- 保持数据一致性
- 做好异常处理
### 2. 部署注意事项
- 确保数据库脚本已执行
- 检查权限配置是否正确
- 验证API接口是否可访问
### 3. 维护注意事项
- 定期检查指标数据的完整性
- 监控API接口的响应时间
- 及时处理异常情况
---
## 🚀 后续优化
### 1. 功能优化
- 支持指标数据的缓存机制
- 添加指标数据的版本控制
- 支持指标数据的批量导入导出
### 2. 性能优化
- 优化SQL查询性能
- 添加数据库索引
- 实现数据分页加载
### 3. 用户体验优化
- 添加加载状态提示
- 优化错误提示信息
- 支持指标数据的搜索和筛选
---
**📅 开发完成时间**: 2025-01-03
**👨‍💻 开发人员**: 系统开发团队
**📋 文档版本**: v1.0.0