fix(xg): 操行分修改改为更新待审核记录,录入页保留审核中状态

同一月份再次修改不再因唯一约束失败,刷新后仍能看到待审分数。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
“wuzhen”andCursor committed 2026-11-24 15:24:33 +08:00
1 parent fcb695664b
commit 7f9d3830ad
7 files changed
+189 -58

No files matched your search

@@ -55,6 +55,21 @@ public class XgConductScoreClassStudentVo {
*/
private XgConductScoreDetailVo existingScore;
/**
* 待审核记录ID。有值表示该月修改已提交、尚未审核
*/
private Long pendingAuditId;
/**
* 待审核的新分数
*/
private BigDecimal pendingScore;
/**
* 待审核的新备注
*/
private String pendingRemark;
/**
* 创建者
*/
@@ -112,4 +112,11 @@ public interface IXgConductScoreAuditService {
*/
Boolean batchInsertAudits(List<XgConductScoreAudit> auditList);
/**
* 保存一条待审核记录。该学生当月已有记录时更新原记录并重新置为待审核,避免唯一约束导致再次提交失败。
*
* @param audit 待审核记录
*/
void saveOrUpdatePending(XgConductScoreAudit audit);
}
@@ -1,12 +1,13 @@
package org.dromara.xg.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.dao.DuplicateKeyException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.ObjectUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -289,6 +290,77 @@ public class XgConductScoreAuditServiceImpl implements IXgConductScoreAuditServi
return true;
}
/**
* 同一学生、学年、学期、月份只保留一条未删除审核记录。
* 待审核时覆盖新分数;已通过或已驳回时清空审核信息并重新置为待审核。
*/
@Override
public void saveOrUpdatePending(XgConductScoreAudit audit) {
if (audit.getDeleted() == null) {
audit.setDeleted(0);
}
validEntityBeforeSave(audit);
try {
XgConductScoreAudit existing = findPeriodAudit(audit);
if (existing == null) {
xgConductScoreAuditMapper.insert(audit);
return;
}
reopenPending(existing.getId(), audit);
} catch (DuplicateKeyException ex) {
XgConductScoreAudit existing = findPeriodAudit(audit);
if (existing == null) {
throw ex;
}
reopenPending(existing.getId(), audit);
}
}
private XgConductScoreAudit findPeriodAudit(XgConductScoreAudit audit) {
LambdaQueryWrapper<XgConductScoreAudit> lqw = Wrappers.lambdaQuery();
lqw.eq(XgConductScoreAudit::getStudentId, audit.getStudentId())
.eq(XgConductScoreAudit::getAcademicYear, audit.getAcademicYear())
.eq(XgConductScoreAudit::getSemester, audit.getSemester())
.eq(XgConductScoreAudit::getMonth, audit.getMonth())
.eq(XgConductScoreAudit::getDeleted, 0)
.orderByAsc(XgConductScoreAudit::getAuditStatus)
.orderByDesc(XgConductScoreAudit::getId)
.last("LIMIT 1");
return xgConductScoreAuditMapper.selectOne(lqw);
}
private void reopenPending(Long auditId, XgConductScoreAudit audit) {
Date now = new Date();
LambdaUpdateWrapper<XgConductScoreAudit> update = Wrappers.lambdaUpdate();
update.eq(XgConductScoreAudit::getId, auditId)
.set(XgConductScoreAudit::getClassId, audit.getClassId())
.set(XgConductScoreAudit::getOldScore, audit.getOldScore())
.set(XgConductScoreAudit::getNewScore, audit.getNewScore())
.set(XgConductScoreAudit::getApplyUserId, audit.getApplyUserId())
.set(XgConductScoreAudit::getApplyUserName, audit.getApplyUserName())
.set(XgConductScoreAudit::getApplyTime, audit.getApplyTime() != null ? audit.getApplyTime() : now)
.set(XgConductScoreAudit::getApplyReason, audit.getApplyReason())
.set(XgConductScoreAudit::getAuditStatus, 0)
.set(XgConductScoreAudit::getUpdateBy, audit.getApplyUserId())
.set(XgConductScoreAudit::getUpdateTime, now);
// 备注和审核人允许为空,显式写成 SQL,避免更新策略把 null 丢掉
if (audit.getOldRemark() == null) {
update.setSql("old_remark = null");
} else {
update.set(XgConductScoreAudit::getOldRemark, audit.getOldRemark());
}
if (audit.getNewRemark() == null) {
update.setSql("new_remark = null");
} else {
update.set(XgConductScoreAudit::getNewRemark, audit.getNewRemark());
}
update.setSql("audit_user_id = null")
.setSql("audit_user_name = null")
.setSql("audit_time = null")
.setSql("audit_remark = null");
xgConductScoreAuditMapper.update(null, update);
}
/**
* 保存前的数据校验
*/
@@ -409,8 +409,10 @@ public class XgConductScoreServiceImpl implements IXgConductScoreService {
List<String> failList = new ArrayList<>();
int successCount = 0;
int failCount = 0;
List<XgConductScoreAudit> auditList = new ArrayList<>();
String applyUserName = StringUtils.blankToDefault(LoginHelper.getNickname(), LoginHelper.getUsername());
if (StringUtils.isBlank(applyUserName)) {
applyUserName = "班主任";
}
for (var item : bo.getScores()) {
try {
@@ -440,9 +442,9 @@ public class XgConductScoreServiceImpl implements IXgConductScoreService {
continue;
}
// 检查是否有实际的修改(分数或备注不同)
boolean hasScoreChange = !item.getScore().equals(existingRecord.getScore());
boolean hasRemarkChange = !ObjectUtils.equals(item.getRemark(), existingRecord.getRemark());
// compareTo 按数值比较,避免 85 和 85.00 被当成不同分数
boolean hasScoreChange = !scoreEquals(item.getScore(), existingRecord.getScore());
boolean hasRemarkChange = !remarkEquals(item.getRemark(), existingRecord.getRemark());
if (!hasScoreChange && !hasRemarkChange) {
failList.add("学生ID:" + item.getStudentId() + " - 无实际修改内容");
@@ -450,7 +452,7 @@ public class XgConductScoreServiceImpl implements IXgConductScoreService {
continue;
}
// 创建审核记录
// 创建审核记录。已有当月审核时更新原记录,不再新增,避免唯一约束冲突
XgConductScoreAudit audit = new XgConductScoreAudit();
audit.setTenantId(tenantId);
audit.setStudentId(item.getStudentId());
@@ -463,14 +465,14 @@ public class XgConductScoreServiceImpl implements IXgConductScoreService {
audit.setNewScore(item.getScore());
audit.setNewRemark(item.getRemark());
audit.setApplyUserId(teacherId);
audit.setApplyUserName(LoginHelper.getUsername());
audit.setApplyUserName(applyUserName);
audit.setApplyTime(new Date());
audit.setApplyReason("班主任修改操行分");
audit.setAuditStatus(0); // 待审核
audit.setAuditStatus(0);
audit.setDeleted(0);
audit.setCreateBy(teacherId);
audit.setCreateTime(new Date());
auditList.add(audit);
auditService.saveOrUpdatePending(audit);
successCount++;
} catch (Exception e) {
@@ -480,11 +482,6 @@ public class XgConductScoreServiceImpl implements IXgConductScoreService {
}
}
// 批量提交审核
if (!auditList.isEmpty()) {
auditService.batchInsertAudits(auditList);
}
XgConductScoreBatchResultVo result = new XgConductScoreBatchResultVo();
result.setSuccessCount(successCount);
result.setFailCount(failCount);
@@ -556,6 +553,13 @@ public class XgConductScoreServiceImpl implements IXgConductScoreService {
existingScore.setScore(BigDecimal.valueOf(((Number) row.get("existing_score")).doubleValue()));
}
existingScore.setRemark((String) row.get("existing_remark"));
if (row.get("pending_audit_id") != null) {
studentVo.setPendingAuditId(((Number) row.get("pending_audit_id")).longValue());
if (row.get("pending_score") != null) {
studentVo.setPendingScore(new BigDecimal(row.get("pending_score").toString()));
}
studentVo.setPendingRemark(row.get("pending_remark") == null ? null : row.get("pending_remark").toString());
}
if (row.get("existing_create_time") instanceof java.time.LocalDateTime) {
existingScore
.setCreateTime(DateUtils.toDate((java.time.LocalDateTime) row.get("existing_create_time")));
@@ -699,6 +703,17 @@ public class XgConductScoreServiceImpl implements IXgConductScoreService {
* @param teacherId 班主任ID
* @return 是否有权限
*/
private boolean scoreEquals(BigDecimal left, BigDecimal right) {
if (left == null || right == null) {
return left == right;
}
return left.compareTo(right) == 0;
}
private boolean remarkEquals(String left, String right) {
return StringUtils.trimToEmpty(left).equals(StringUtils.trimToEmpty(right));
}
@Override
public boolean checkTeacherPermission(Long classId, Long teacherId) {
return baseMapper.checkTeacherClass(teacherId, classId);
@@ -326,7 +326,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
cs_current.id AS score_id,
cs_current.score AS existing_score,
cs_current.remark AS existing_remark,
cs_current.create_time AS existing_create_time
cs_current.create_time AS existing_create_time,
au.id AS pending_audit_id,
au.new_score AS pending_score,
au.new_remark AS pending_remark
FROM (
SELECT
c.id AS class_id,
@@ -347,6 +350,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND cs_current.semester = #{semester}
AND cs_current.month = #{month}
AND cs_current.deleted = 0
LEFT JOIN xg_conduct_score_audit au ON s.id = au.student_id
AND au.academic_year = #{academicYear}
AND au.semester = #{semester}
AND au.month = #{month}
AND au.deleted = 0
AND au.audit_status = 0
LEFT JOIN (
SELECT
cs_inner.student_id,
@@ -47,6 +47,7 @@
| 接口名称 | 请求方式 | 路径 | 权限字符 | 功能描述 |
| -------- | -------- | ---- | -------- | -------- |
| 批量录入操行分 | POST | /api/xg/conduct-score/batch | xg:conduct:score:batchAdd | 批量保存操行分 |
| 批量提交修改审核 | POST | /api/xg/conduct-score/batch-update | xg:conductScore:batchUpdate | 已录入分数的修改只写审核表,审核通过后才改正式分数 |
| 班主任班级学生 | GET | /api/xg/conduct-score/class-students | xg:conduct:score:classStudents | 获取班主任班级学生列表 |
| 学期平均分统计 | GET | /api/xg/conduct-score/semester-average | xg:conduct:score:semester | 查询学期平均分 |
| 导出学期统计 | GET | /api/xg/conduct-score/export-semester | xg:conduct:score:export | 导出学期统计数据 |
@@ -165,6 +166,18 @@
}
```
### 2.1 批量提交修改审核
#### 接口信息
- **请求方式**: POST
- **接口路径**: `/api/xg/conduct-score/batch-update`
- **权限字符**: `xg:conductScore:batchUpdate`
- **接口描述**: 班主任修改已录入的操行分。正式分数不变,生成或更新待审核记录,管理员审核通过后才写入正式表。
同一学生、同一学年、学期、月份只保留一条未删除审核记录。当月没有审核记录时新增;已经是待审核时覆盖新分数和新备注;已经通过或驳回时,清空原审核人并把该记录重新置为待审核。
班级学生列表会返回 `pendingAuditId`、`pendingScore`、`pendingRemark`。录入页据此在刷新后显示「审核中」,正式分数仍是 `existingScore.score`。
### 3. 班主任班级学生列表
#### 接口信息
@@ -215,6 +228,9 @@
"remark": "表现良好",
"createTime": "2024-09-01 09:00:00"
},
"pendingAuditId": 1234567890123456790,
"pendingScore": 86.00,
"pendingRemark": "更正分数",
"lastScore": 90.00,
"lastMonth": 8
}
@@ -290,9 +290,12 @@
<el-input v-model="scope.row.remark" size="small" placeholder="输入备注(可选)" maxlength="500" show-word-limit />
</template>
</el-table-column>
<el-table-column v-if="columns[6].visible" key="status" label="状态" align="center" width="120">
<el-table-column v-if="columns[6].visible" key="status" label="状态" align="center" width="140">
<template #default="scope">
<el-tag :type="getStudentStatusTagType(scope.row)" size="small">{{ getStudentStatus(scope.row) }}</el-tag>
<div v-if="scope.row.pendingAuditId" style="margin-top: 2px; font-size: 12px; line-height: 1.2; color: #e6a23c">
待审 {{ Number(scope.row.pendingScore) }}
</div>
</template>
</el-table-column>
<el-table-column v-if="columns[7].visible" key="lastScore" label="上月分数" align="center" width="100">
@@ -522,15 +525,17 @@ const getStudentStatus = (student) => {
}
if (hasExistingScore && hasCurrentScore) {
// 比较分数和备注是否变化
// 比较分数和备注是否变化。未保存的改动显示待审核;已提交且尚未审完显示审核中
const scoreChanged = Number(student.score) !== Number(student.existingScore.score);
const remarkChanged = String(student.remark || '').trim() !== String(student.existingScore.remark || '').trim();
if (scoreChanged || remarkChanged) {
return '待审核';
} else {
return '已录入';
}
if (student.pendingAuditId !== null && student.pendingAuditId !== undefined && student.pendingAuditId !== '') {
return '审核中';
}
return '已录入';
}
return '未录入';
@@ -547,6 +552,7 @@ const getStudentStatusTagType = (student) => {
case '已录入':
return 'success';
case '待审核':
case '审核中':
return 'warning';
default:
return 'info';
@@ -772,17 +778,11 @@ const handleSaveAll = () => {
type: auditStudents.length > 0 ? 'warning' : 'success',
dangerouslyUseHTMLString: true
}).then(() => {
// 分批处理直接保存和审核
if (directSaveStudents.length > 0) {
saveBatchData(directSaveStudents, 'add');
}
if (auditStudents.length > 0) {
saveBatchData(auditStudents, 'update');
}
submitScoreBatches(directSaveStudents, auditStudents);
});
};
const saveBatchData = async (students, operationType = 'add') => {
const saveBatchData = async (students, operationType = 'add', refresh = true) => {
try {
const batchData = {
academicYear: queryParams.academicYear,
@@ -817,7 +817,9 @@ const saveBatchData = async (students, operationType = 'add') => {
}
}
getList();
if (refresh) {
await getList();
}
} catch (error) {
console.error('保存数据失败:', error);
const operationName = operationType === 'update' ? '提交审核' : '保存';
@@ -825,6 +827,18 @@ const saveBatchData = async (students, operationType = 'add') => {
}
};
const submitScoreBatches = async (directStudents, auditStudents) => {
const jobs = [];
if (directStudents.length > 0) {
jobs.push(saveBatchData(directStudents, 'add', false));
}
if (auditStudents.length > 0) {
jobs.push(saveBatchData(auditStudents, 'update', false));
}
await Promise.allSettled(jobs);
await getList();
};
// 批量录入弹窗数据与确认保存
const batchModalVisible = ref(false);
const batchModalForm = reactive({
@@ -888,34 +902,17 @@ const confirmBatchModalSave = () => {
batchModalVisible.value = false;
// 分批处理
if (directSaveStudents.length > 0) {
const directSaveData = directSaveStudents.map((stu) => ({
studentId: stu.studentId,
score: batchModalForm.score,
remark: batchModalForm.remark || ''
}));
saveBatchData(directSaveData, 'add');
}
if (auditStudents.length > 0) {
const auditData = auditStudents.map((stu) => ({
studentId: stu.studentId,
score: batchModalForm.score,
remark: batchModalForm.remark || ''
}));
saveBatchData(auditData, 'update');
}
// 显示操作结果
let message = '批量操作完成:';
if (directSaveStudents.length > 0) {
message += `保存 ${directSaveStudents.length} 个学生`;
}
if (auditStudents.length > 0) {
message += `${directSaveStudents.length > 0 ? ',' : ''}提交 ${auditStudents.length} 个修改学生审核`;
}
ElMessage.success(message);
const directSaveData = directSaveStudents.map((stu) => ({
studentId: stu.studentId,
score: batchModalForm.score,
remark: batchModalForm.remark || ''
}));
const auditData = auditStudents.map((stu) => ({
studentId: stu.studentId,
score: batchModalForm.score,
remark: batchModalForm.remark || ''
}));
submitScoreBatches(directSaveData, auditData);
};
const handleRefresh = () => {