"...git@gitlab.ruzhoukj.com:wujipeng/practical_train.git" did not exist on "9a033119045984dd3d15cffcf9f93c2bcf309c17"
Commit 8fc878c3 authored by wujipeng's avatar wujipeng
Browse files

Merge remote-tracking branch 'origin/dev-v1.0' into dev-v1.0

parents ebb3cc24 2c6a3954
package com.platform.business.service.impl; package com.platform.business.service.impl;
import com.platform.business.constant.AccountAdminConstants;
import com.platform.business.constant.ExamAdminConstants; import com.platform.business.constant.ExamAdminConstants;
import com.platform.business.mapper.ExamMapper; import com.platform.business.mapper.ExamMapper;
import com.platform.business.model.dto.ExamAdminSaveDTO; import com.platform.business.model.dto.ExamAdminSaveDTO;
import com.platform.business.model.dto.ExamAdminUpdateDTO; import com.platform.business.model.dto.ExamAdminUpdateDTO;
import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.entity.ExamEntity; import com.platform.business.model.entity.ExamEntity;
import com.platform.business.model.entity.ExamStudentEntity; import com.platform.business.model.entity.ExamStudentEntity;
import com.platform.business.model.entity.TheoreticalPaperEntity; import com.platform.business.model.entity.TheoreticalPaperEntity;
...@@ -13,6 +15,7 @@ import com.platform.business.model.vo.ExamAdminClassVO; ...@@ -13,6 +15,7 @@ import com.platform.business.model.vo.ExamAdminClassVO;
import com.platform.business.model.vo.ExamAdminDetailVO; import com.platform.business.model.vo.ExamAdminDetailVO;
import com.platform.business.model.vo.ExamAdminOptionsVO; import com.platform.business.model.vo.ExamAdminOptionsVO;
import com.platform.business.model.vo.ExamAdminStudentOptionVO; import com.platform.business.model.vo.ExamAdminStudentOptionVO;
import com.platform.business.service.BusinessNotificationPublisher;
import com.platform.business.service.ClassAdminService; import com.platform.business.service.ClassAdminService;
import com.platform.business.service.ExamAdminService; import com.platform.business.service.ExamAdminService;
import com.platform.business.service.ExamStudentService; import com.platform.business.service.ExamStudentService;
...@@ -58,6 +61,9 @@ public class ExamAdminServiceImpl implements ExamAdminService { ...@@ -58,6 +61,9 @@ public class ExamAdminServiceImpl implements ExamAdminService {
@Resource @Resource
private ExamStudentService examStudentService; private ExamStudentService examStudentService;
@Resource
private BusinessNotificationPublisher notificationPublisher;
@Override @Override
public List<ClassAdminTreeVO> tree(String keyword) { public List<ClassAdminTreeVO> tree(String keyword) {
return classAdminService.tree(keyword); return classAdminService.tree(keyword);
...@@ -175,9 +181,30 @@ public class ExamAdminServiceImpl implements ExamAdminService { ...@@ -175,9 +181,30 @@ public class ExamAdminServiceImpl implements ExamAdminService {
if (!examStudentService.saveBatch(candidates)) { if (!examStudentService.saveBatch(candidates)) {
throw new BusinessException("应考学员保存失败,请稍后重试"); throw new BusinessException("应考学员保存失败,请稍后重试");
} }
// 考试主表、应考名单和通知发件箱原子提交,教师不会收到创建失败的考试安排。
publishExamNotification(entity, managedClass);
return detail(entity.getId()); return detail(entity.getId());
} }
/** 新建考试只通知该场考试配置的首席考评员和监考教师,消息中心会再次去重。 */
private void publishExamNotification(ExamEntity exam, ExamAdminClassVO managedClass) {
String className = trimToNull(managedClass.getClassName()) == null
? "对应班级" : managedClass.getClassName().trim();
NotificationPublishDTO message = new NotificationPublishDTO();
message.setEventId("exam-created:" + exam.getId());
message.setMessageType("EXAM");
message.setTitle("新的考试安排");
message.setSummary(className + "已创建考试“" + exam.getName() + "”");
message.setContent("管理员已为" + className + "创建考试“" + exam.getName()
+ "”,请及时查看考试时间、地点及职责安排。");
message.setBusinessType("EXAM");
message.setBusinessId(String.valueOf(exam.getId()));
message.setActionUrl("/exam/teacher/scores/exams/" + exam.getId());
message.setPriority("IMPORTANT");
message.setRecipientUserIds(Arrays.asList(exam.getChiefId(), exam.getInvigilationId()));
notificationPublisher.publish(message, null, AccountAdminConstants.ROLE_ADMIN);
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ExamAdminDetailVO update(Integer examId, ExamAdminUpdateDTO request) { public ExamAdminDetailVO update(Integer examId, ExamAdminUpdateDTO request) {
...@@ -441,6 +468,13 @@ public class ExamAdminServiceImpl implements ExamAdminService { ...@@ -441,6 +468,13 @@ public class ExamAdminServiceImpl implements ExamAdminService {
private String normalizeType(String value) { private String normalizeType(String value) {
String type = requireText(value, "考试类型", 8); String type = requireText(value, "考试类型", 8);
// 管理端接口按文档提交“理论/实训”,数据库及下游模块统一保存完整类型名称。
if ("理论".equals(type)) {
return ExamAdminConstants.TYPE_THEORY;
}
if ("实训".equals(type)) {
return ExamAdminConstants.TYPE_PRACTICE;
}
if (!ExamAdminConstants.EXAM_TYPES.contains(type)) { if (!ExamAdminConstants.EXAM_TYPES.contains(type)) {
throw new BusinessException("考试类型只支持理论或实训"); throw new BusinessException("考试类型只支持理论或实训");
} }
......
package com.platform.business.service.impl; package com.platform.business.service.impl;
import com.platform.business.constant.ExamReviewConstants; import com.platform.business.constant.AccountAdminConstants;
import com.platform.business.constant.ExamAdminConstants; import com.platform.business.constant.ExamAdminConstants;
import com.platform.business.constant.ExamReviewConstants;
import com.platform.business.mapper.ExamReviewMapper; import com.platform.business.mapper.ExamReviewMapper;
import com.platform.business.mapper.ExamReviewScoreLogMapper; import com.platform.business.mapper.ExamReviewScoreLogMapper;
import com.platform.business.model.dto.ExamReviewSaveDTO; import com.platform.business.model.dto.ExamReviewSaveDTO;
import com.platform.business.model.dto.ExamReviewScoreItemDTO; import com.platform.business.model.dto.ExamReviewScoreItemDTO;
import com.platform.business.model.dto.ExamReviewStudentQueryDTO; import com.platform.business.model.dto.ExamReviewStudentQueryDTO;
import com.platform.business.model.dto.ExamReviewTaskQueryDTO; import com.platform.business.model.dto.ExamReviewTaskQueryDTO;
import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.entity.ExamEntity; import com.platform.business.model.entity.ExamEntity;
import com.platform.business.model.entity.ExamReviewScoreLogEntity; import com.platform.business.model.entity.ExamReviewScoreLogEntity;
import com.platform.business.model.entity.ExamStudentEntity; import com.platform.business.model.entity.ExamStudentEntity;
...@@ -20,6 +22,7 @@ import com.platform.business.model.vo.ExamReviewRecordVO; ...@@ -20,6 +22,7 @@ import com.platform.business.model.vo.ExamReviewRecordVO;
import com.platform.business.model.vo.ExamReviewScoreSummaryVO; import com.platform.business.model.vo.ExamReviewScoreSummaryVO;
import com.platform.business.model.vo.ExamReviewStudentVO; import com.platform.business.model.vo.ExamReviewStudentVO;
import com.platform.business.model.vo.ExamReviewTaskVO; import com.platform.business.model.vo.ExamReviewTaskVO;
import com.platform.business.service.BusinessNotificationPublisher;
import com.platform.business.service.ExamReviewService; import com.platform.business.service.ExamReviewService;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -53,6 +56,9 @@ public class ExamReviewServiceImpl implements ExamReviewService { ...@@ -53,6 +56,9 @@ public class ExamReviewServiceImpl implements ExamReviewService {
@Resource @Resource
private ExamReviewScoreLogMapper scoreLogMapper; private ExamReviewScoreLogMapper scoreLogMapper;
@Resource
private BusinessNotificationPublisher notificationPublisher;
@Override @Override
public List<ExamReviewTaskVO> queryTasks(ExamReviewTaskQueryDTO query, String teacherId) { public List<ExamReviewTaskVO> queryTasks(ExamReviewTaskQueryDTO query, String teacherId) {
ExamReviewTaskQueryDTO safeQuery = query == null ? new ExamReviewTaskQueryDTO() : query; ExamReviewTaskQueryDTO safeQuery = query == null ? new ExamReviewTaskQueryDTO() : query;
...@@ -239,9 +245,27 @@ public class ExamReviewServiceImpl implements ExamReviewService { ...@@ -239,9 +245,27 @@ public class ExamReviewServiceImpl implements ExamReviewService {
if (examReviewMapper.publishTask(examId) != 1) { if (examReviewMapper.publishTask(examId) != 1) {
throw new BusinessException("阅卷任务发布失败,请稍后重试"); throw new BusinessException("阅卷任务发布失败,请稍后重试");
} }
// 成绩和通知发件箱在同一事务提交,避免管理端收到不存在或尚未发布的成绩消息。
publishScoreNotification(exam, teacherId);
return true; return true;
} }
/** 每次成功发布一批新增成绩后通知全部管理员;补交试卷的后续发布也会产生独立消息。 */
private void publishScoreNotification(ExamEntity exam, String teacherId) {
String examName = trimToNull(exam.getName()) == null ? "未命名考试" : exam.getName().trim();
NotificationPublishDTO message = new NotificationPublishDTO();
message.setMessageType("SCORE");
message.setTitle("考试成绩已发布");
message.setSummary("考试“" + examName + "”的成绩已发布");
message.setContent("教师已完成考试“" + examName + "”的试卷批阅并发布成绩,请进入管理端查看。");
message.setBusinessType("EXAM_SCORE");
message.setBusinessId(String.valueOf(exam.getId()));
message.setActionUrl("/exam/admin/scores/exams/" + exam.getId());
message.setPriority("IMPORTANT");
message.setRecipientRoleNames(Collections.singletonList(AccountAdminConstants.ROLE_ADMIN));
notificationPublisher.publish(message, teacherId, AccountAdminConstants.ROLE_TEACHER);
}
@Override @Override
public List<ExamReviewRecordVO> history(Integer examStudentId, String teacherId) { public List<ExamReviewRecordVO> history(Integer examStudentId, String teacherId) {
// 先做带教师ID的关联校验,避免仅凭考生考试记录ID读取其他教师的评分历史。 // 先做带教师ID的关联校验,避免仅凭考生考试记录ID读取其他教师的评分历史。
......
...@@ -3,6 +3,7 @@ package com.platform.business.service.impl; ...@@ -3,6 +3,7 @@ package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.platform.business.constant.AccountAdminConstants;
import com.platform.business.constant.AttendanceConstants; import com.platform.business.constant.AttendanceConstants;
import com.platform.business.constant.LeaveConstants; import com.platform.business.constant.LeaveConstants;
import com.platform.business.mapper.ClassSubjectAttendanceMapper; import com.platform.business.mapper.ClassSubjectAttendanceMapper;
...@@ -12,6 +13,7 @@ import com.platform.business.mapper.StudentLeaveSubjectMapper; ...@@ -12,6 +13,7 @@ import com.platform.business.mapper.StudentLeaveSubjectMapper;
import com.platform.business.model.dto.LeaveApplyDTO; import com.platform.business.model.dto.LeaveApplyDTO;
import com.platform.business.model.dto.LeaveQueryDTO; import com.platform.business.model.dto.LeaveQueryDTO;
import com.platform.business.model.dto.LeaveReviewDTO; import com.platform.business.model.dto.LeaveReviewDTO;
import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.entity.BsFileEntity; import com.platform.business.model.entity.BsFileEntity;
import com.platform.business.model.entity.ClassSubjectAttendanceEntity; import com.platform.business.model.entity.ClassSubjectAttendanceEntity;
import com.platform.business.model.entity.ClassSubjectEntity; import com.platform.business.model.entity.ClassSubjectEntity;
...@@ -20,6 +22,7 @@ import com.platform.business.model.entity.StudentLeaveApplicationEntity; ...@@ -20,6 +22,7 @@ import com.platform.business.model.entity.StudentLeaveApplicationEntity;
import com.platform.business.model.entity.StudentLeaveSubjectEntity; import com.platform.business.model.entity.StudentLeaveSubjectEntity;
import com.platform.business.model.vo.LeaveApplicationVO; import com.platform.business.model.vo.LeaveApplicationVO;
import com.platform.business.service.BsFileService; import com.platform.business.service.BsFileService;
import com.platform.business.service.BusinessNotificationPublisher;
import com.platform.business.service.ClassStudentService; import com.platform.business.service.ClassStudentService;
import com.platform.business.service.ClassSubjectAttendanceService; import com.platform.business.service.ClassSubjectAttendanceService;
import com.platform.business.service.ClassSubjectService; import com.platform.business.service.ClassSubjectService;
...@@ -31,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -31,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Calendar; import java.util.Calendar;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
...@@ -60,6 +64,8 @@ public class LeaveManagementServiceImpl implements LeaveManagementService { ...@@ -60,6 +64,8 @@ public class LeaveManagementServiceImpl implements LeaveManagementService {
private ClassSubjectAttendanceMapper attendanceMapper; private ClassSubjectAttendanceMapper attendanceMapper;
@Resource @Resource
private BsFileService bsFileService; private BsFileService bsFileService;
@Resource
private BusinessNotificationPublisher notificationPublisher;
@Override @Override
@Transactional @Transactional
...@@ -86,7 +92,9 @@ public class LeaveManagementServiceImpl implements LeaveManagementService { ...@@ -86,7 +92,9 @@ public class LeaveManagementServiceImpl implements LeaveManagementService {
leaveApplicationMapper.insert(leave); leaveApplicationMapper.insert(leave);
saveSubjectRelations(leave.getId(), subjects, now); saveSubjectRelations(leave.getId(), subjects, now);
saveAttachmentRelations(leave.getId(), request.getAttachmentFileIds(), now); saveAttachmentRelations(leave.getId(), request.getAttachmentFileIds(), now);
return requireDetail(leave.getId()); LeaveApplicationVO detail = requireDetail(leave.getId());
publishLeaveApplication(detail, subjects);
return detail;
} }
@Override @Override
...@@ -208,7 +216,83 @@ public class LeaveManagementServiceImpl implements LeaveManagementService { ...@@ -208,7 +216,83 @@ public class LeaveManagementServiceImpl implements LeaveManagementService {
throw new BusinessException("审批期间学员已完成签到,请假审批已取消"); throw new BusinessException("审批期间学员已完成签到,请假审批已取消");
} }
} }
return requireDetail(leaveId); LeaveApplicationVO detail = requireDetail(leaveId);
publishLeaveReview(detail, reviewStatus, approverId, approverRole);
return detail;
}
/**
* 新申请只通知请假时间实际覆盖课程的授课教师。一个申请可能跨多节课或多名教师,
* 因此先按教师ID去重,避免同一教师收到多条内容相同的消息。
*/
void publishLeaveApplication(LeaveApplicationVO leave, List<ClassSubjectEntity> subjects) {
List<String> teacherIds = subjects.stream()
.map(ClassSubjectEntity::getTeacherId)
.filter(id -> !isBlank(id))
.distinct()
.collect(Collectors.toList());
if (teacherIds.isEmpty()) {
throw new BusinessException("请假申请未找到对应授课教师");
}
String studentName = isBlank(leave.getStudentName()) ? "学员" : leave.getStudentName();
NotificationPublishDTO message = new NotificationPublishDTO();
message.setEventId("leave-apply:" + leave.getId());
message.setMessageType("LEAVE");
message.setTitle("新的请假申请");
message.setSummary(studentName + "提交了请假申请");
message.setContent(studentName + "提交了请假申请,请进入教师端请假管理及时处理。");
message.setBusinessType("LEAVE");
message.setBusinessId(leave.getId());
message.setActionUrl("/leave/teacher/" + leave.getId());
message.setPriority("IMPORTANT");
message.setRecipientUserIds(teacherIds);
notificationPublisher.publish(message, leave.getStudentId(), studentName);
}
/**
* 审批结果始终反馈给申请学员;批准时另发一条只含审批意见的管理员消息,
* 防止管理员收到面向学员的“您的请假申请”话术。拒绝时不通知管理员。
*/
void publishLeaveReview(LeaveApplicationVO leave, String reviewStatus,
String approverId, String approverRole) {
boolean approved = LeaveConstants.STATUS_APPROVED.equals(reviewStatus);
String resultName = approved ? "已通过" : "未通过";
String opinion = isBlank(leave.getApprovalOpinion())
? "审批人未填写意见" : leave.getApprovalOpinion();
String senderName = isBlank(leave.getApproverName())
? (LeaveConstants.ROLE_TEACHER.equals(approverRole)
? AccountAdminConstants.ROLE_TEACHER : AccountAdminConstants.ROLE_ADMIN)
: leave.getApproverName();
NotificationPublishDTO studentMessage = new NotificationPublishDTO();
studentMessage.setEventId("leave-review:" + leave.getId() + ":student");
studentMessage.setMessageType("LEAVE");
studentMessage.setTitle("请假审批" + resultName);
studentMessage.setSummary("您的请假申请" + resultName);
studentMessage.setContent("您的请假申请" + resultName + "。审批意见:" + opinion);
studentMessage.setBusinessType("LEAVE");
studentMessage.setBusinessId(leave.getId());
studentMessage.setActionUrl("/leave/student/" + leave.getId());
studentMessage.setPriority(approved ? "NORMAL" : "IMPORTANT");
studentMessage.setRecipientUserIds(Collections.singletonList(leave.getStudentId()));
notificationPublisher.publish(studentMessage, approverId, senderName);
if (approved) {
NotificationPublishDTO adminMessage = new NotificationPublishDTO();
adminMessage.setEventId("leave-review:" + leave.getId() + ":admin");
adminMessage.setMessageType("LEAVE");
adminMessage.setTitle("请假审批意见");
adminMessage.setSummary(opinion);
adminMessage.setContent(opinion);
adminMessage.setBusinessType("LEAVE");
adminMessage.setBusinessId(leave.getId());
adminMessage.setActionUrl("/leave/admin/" + leave.getId());
adminMessage.setPriority("NORMAL");
adminMessage.setRecipientRoleNames(
Collections.singletonList(AccountAdminConstants.ROLE_ADMIN));
notificationPublisher.publish(adminMessage, approverId, senderName);
}
} }
@Override @Override
......
package com.platform.business.service.impl; package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.platform.business.constant.AccountAdminConstants;
import com.platform.business.constant.TeachingPlanConstants; import com.platform.business.constant.TeachingPlanConstants;
import com.platform.business.mapper.TeachingPlanAttachmentMapper; import com.platform.business.mapper.TeachingPlanAttachmentMapper;
import com.platform.business.mapper.TeachingPlanMapper; import com.platform.business.mapper.TeachingPlanMapper;
import com.platform.business.mapper.TeachingPlanStepMapper; import com.platform.business.mapper.TeachingPlanStepMapper;
import com.platform.business.model.dto.TeachingPlanAdminQueryDTO; import com.platform.business.model.dto.TeachingPlanAdminQueryDTO;
import com.platform.business.model.dto.TeachingPlanAdminUpdateDTO; import com.platform.business.model.dto.TeachingPlanAdminUpdateDTO;
import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.dto.TeachingPlanQueryDTO; import com.platform.business.model.dto.TeachingPlanQueryDTO;
import com.platform.business.model.dto.TeachingPlanSaveDTO; import com.platform.business.model.dto.TeachingPlanSaveDTO;
import com.platform.business.model.dto.TeachingPlanStepDTO; import com.platform.business.model.dto.TeachingPlanStepDTO;
...@@ -20,6 +22,7 @@ import com.platform.business.model.vo.TeachingPlanTeacherOptionVO; ...@@ -20,6 +22,7 @@ import com.platform.business.model.vo.TeachingPlanTeacherOptionVO;
import com.platform.business.model.vo.TeachingPlanVO; import com.platform.business.model.vo.TeachingPlanVO;
import com.platform.business.model.vo.TeachingPlanStepVO; import com.platform.business.model.vo.TeachingPlanStepVO;
import com.platform.business.service.BsFileService; import com.platform.business.service.BsFileService;
import com.platform.business.service.BusinessNotificationPublisher;
import com.platform.business.service.TeachingPlanService; import com.platform.business.service.TeachingPlanService;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
...@@ -78,6 +81,9 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -78,6 +81,9 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
@Resource @Resource
private BsFileService bsFileService; private BsFileService bsFileService;
@Resource
private BusinessNotificationPublisher notificationPublisher;
@Override @Override
public List<TeachingPlanVO> list(TeachingPlanQueryDTO query, String teacherId) { public List<TeachingPlanVO> list(TeachingPlanQueryDTO query, String teacherId) {
requireTeacherId(teacherId); requireTeacherId(teacherId);
...@@ -194,6 +200,10 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -194,6 +200,10 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
id, teacherId, current.getStatus(), targetStatus, now) != 1) { id, teacherId, current.getStatus(), targetStatus, now) != 1) {
throw new BusinessException("教案状态已变化,请刷新后重试"); throw new BusinessException("教案状态已变化,请刷新后重试");
} }
// 只有真正进入待审核状态才通知管理员;退回教案切回草稿只是教师本地编辑动作。
if (TeachingPlanConstants.STATUS_PENDING.equals(targetStatus)) {
publishSubmissionNotification(current, teacherId);
}
return detail(id, teacherId); return detail(id, teacherId);
} }
...@@ -320,9 +330,51 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -320,9 +330,51 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
throw new BusinessException("教案状态已变化,请刷新后重试"); throw new BusinessException("教案状态已变化,请刷新后重试");
} }
replaceSteps(id, request.getSteps()); replaceSteps(id, request.getSteps());
// 审核通过即结束消息链路;仅首次退回修正时提醒所属教师,重复保存退回状态不重复推送。
if (TeachingPlanConstants.STATUS_REJECTED.equals(targetStatus)
&& !TeachingPlanConstants.STATUS_REJECTED.equals(current.getStatus())) {
publishCorrectionNotification(current, reviewOpinion, reviewerId, reviewerName);
}
return adminDetail(id); return adminDetail(id);
} }
/**
* 教师提交教案后通知全部管理员。eventId由消息服务生成,因为同一教案退回后可以再次提交,
* 每次成功的状态流转都应形成一条独立审核待办。
*/
private void publishSubmissionNotification(TeachingPlanEntity plan, String teacherId) {
String title = StringUtils.hasText(plan.getTitle()) ? plan.getTitle() : "未命名教案";
NotificationPublishDTO message = new NotificationPublishDTO();
message.setMessageType("TEACHING_PLAN");
message.setTitle("教案待审核");
message.setSummary("教师提交了教案“" + title + "”");
message.setContent("教案“" + title + "”已提交,请进入管理端教案管理完成审核。");
message.setBusinessType("TEACHING_PLAN");
message.setBusinessId(plan.getId());
message.setActionUrl("/teaching/plan/admin/" + plan.getId());
message.setPriority("IMPORTANT");
message.setRecipientRoleNames(Collections.singletonList(AccountAdminConstants.ROLE_ADMIN));
notificationPublisher.publish(message, teacherId, AccountAdminConstants.ROLE_TEACHER);
}
/** 管理员退回教案时只通知教案所属教师,并把审核意见带入正文便于直接修正。 */
private void publishCorrectionNotification(TeachingPlanEntity plan, String reviewOpinion,
String reviewerId, String reviewerName) {
String title = StringUtils.hasText(plan.getTitle()) ? plan.getTitle() : "未命名教案";
String opinion = StringUtils.hasText(reviewOpinion) ? reviewOpinion : "管理员未填写审核意见";
NotificationPublishDTO message = new NotificationPublishDTO();
message.setMessageType("TEACHING_PLAN");
message.setTitle("教案退回修正");
message.setSummary("教案“" + title + "”需要修正");
message.setContent("教案“" + title + "”已退回修正。审核意见:" + opinion);
message.setBusinessType("TEACHING_PLAN");
message.setBusinessId(plan.getId());
message.setActionUrl("/teaching/plan/teacher/" + plan.getId());
message.setPriority("IMPORTANT");
message.setRecipientUserIds(Collections.singletonList(plan.getTeacherId()));
notificationPublisher.publish(message, reviewerId, reviewerName);
}
@Override @Override
public List<TeachingPlanTeacherOptionVO> adminTeacherOptions() { public List<TeachingPlanTeacherOptionVO> adminTeacherOptions() {
return teachingPlanMapper.selectAdminTeacherOptions(); return teachingPlanMapper.selectAdminTeacherOptions();
......
...@@ -4,12 +4,14 @@ import com.platform.business.constant.ExamAdminConstants; ...@@ -4,12 +4,14 @@ import com.platform.business.constant.ExamAdminConstants;
import com.platform.business.mapper.ExamMapper; import com.platform.business.mapper.ExamMapper;
import com.platform.business.model.dto.ExamAdminSaveDTO; import com.platform.business.model.dto.ExamAdminSaveDTO;
import com.platform.business.model.dto.ExamAdminUpdateDTO; import com.platform.business.model.dto.ExamAdminUpdateDTO;
import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.entity.ExamEntity; import com.platform.business.model.entity.ExamEntity;
import com.platform.business.model.entity.ExamStudentEntity; import com.platform.business.model.entity.ExamStudentEntity;
import com.platform.business.model.entity.TheoreticalPaperEntity; import com.platform.business.model.entity.TheoreticalPaperEntity;
import com.platform.business.model.vo.ExamAdminClassVO; import com.platform.business.model.vo.ExamAdminClassVO;
import com.platform.business.model.vo.ExamAdminDetailVO; import com.platform.business.model.vo.ExamAdminDetailVO;
import com.platform.business.service.ClassAdminService; import com.platform.business.service.ClassAdminService;
import com.platform.business.service.BusinessNotificationPublisher;
import com.platform.business.service.ExamStudentService; import com.platform.business.service.ExamStudentService;
import com.platform.business.service.TheoreticalPaperService; import com.platform.business.service.TheoreticalPaperService;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
...@@ -54,6 +56,9 @@ class ExamAdminServiceImplTest { ...@@ -54,6 +56,9 @@ class ExamAdminServiceImplTest {
@Mock @Mock
private ExamStudentService examStudentService; private ExamStudentService examStudentService;
@Mock
private BusinessNotificationPublisher notificationPublisher;
@InjectMocks @InjectMocks
private ExamAdminServiceImpl service; private ExamAdminServiceImpl service;
...@@ -120,6 +125,13 @@ class ExamAdminServiceImplTest { ...@@ -120,6 +125,13 @@ class ExamAdminServiceImplTest {
verify(examStudentService).saveBatch(studentsCaptor.capture()); verify(examStudentService).saveBatch(studentsCaptor.capture());
assertEquals(2, studentsCaptor.getValue().size()); assertEquals(2, studentsCaptor.getValue().size());
assertFalse(studentsCaptor.getValue().get(0).getSubmit()); assertFalse(studentsCaptor.getValue().get(0).getSubmit());
ArgumentCaptor<NotificationPublishDTO> messageCaptor =
ArgumentCaptor.forClass(NotificationPublishDTO.class);
verify(notificationPublisher).publish(messageCaptor.capture(), eq(null), eq("管理员"));
assertEquals(Arrays.asList("teacher-1", "teacher-2"),
messageCaptor.getValue().getRecipientUserIds());
assertEquals("EXAM", messageCaptor.getValue().getMessageType());
} }
@Test @Test
...@@ -271,7 +283,7 @@ class ExamAdminServiceImplTest { ...@@ -271,7 +283,7 @@ class ExamAdminServiceImplTest {
ExamEntity existing = new ExamEntity(); ExamEntity existing = new ExamEntity();
existing.setId(7); existing.setId(7);
existing.setClassId(1); existing.setClassId(1);
existing.setType("实训"); existing.setType(ExamAdminConstants.TYPE_PRACTICE);
existing.setExamTime(Timestamp.valueOf("2099-09-18 09:00:00")); existing.setExamTime(Timestamp.valueOf("2099-09-18 09:00:00"));
existing.setInvigilationId("teacher-2"); existing.setInvigilationId("teacher-2");
existing.setPaperId("paper-1"); existing.setPaperId("paper-1");
......
...@@ -6,6 +6,7 @@ import com.platform.business.mapper.ExamReviewScoreLogMapper; ...@@ -6,6 +6,7 @@ import com.platform.business.mapper.ExamReviewScoreLogMapper;
import com.platform.business.model.dto.ExamReviewSaveDTO; import com.platform.business.model.dto.ExamReviewSaveDTO;
import com.platform.business.model.dto.ExamReviewScoreItemDTO; import com.platform.business.model.dto.ExamReviewScoreItemDTO;
import com.platform.business.model.dto.ExamReviewTaskQueryDTO; import com.platform.business.model.dto.ExamReviewTaskQueryDTO;
import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.entity.ExamEntity; import com.platform.business.model.entity.ExamEntity;
import com.platform.business.model.entity.ExamReviewScoreLogEntity; import com.platform.business.model.entity.ExamReviewScoreLogEntity;
import com.platform.business.model.entity.ExamStudentEntity; import com.platform.business.model.entity.ExamStudentEntity;
...@@ -15,10 +16,12 @@ import com.platform.business.model.vo.ExamReviewTaskVO; ...@@ -15,10 +16,12 @@ import com.platform.business.model.vo.ExamReviewTaskVO;
import com.platform.business.model.vo.ExamReviewPaperVO; import com.platform.business.model.vo.ExamReviewPaperVO;
import com.platform.business.model.vo.ExamReviewPracticeItemVO; import com.platform.business.model.vo.ExamReviewPracticeItemVO;
import com.platform.business.model.vo.ExamReviewStudentVO; import com.platform.business.model.vo.ExamReviewStudentVO;
import com.platform.business.service.BusinessNotificationPublisher;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
...@@ -33,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; ...@@ -33,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyDouble; import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
...@@ -52,6 +56,9 @@ class ExamReviewServiceImplTest { ...@@ -52,6 +56,9 @@ class ExamReviewServiceImplTest {
@Mock @Mock
private ExamReviewScoreLogMapper scoreLogMapper; private ExamReviewScoreLogMapper scoreLogMapper;
@Mock
private BusinessNotificationPublisher notificationPublisher;
@InjectMocks @InjectMocks
private ExamReviewServiceImpl examReviewService; private ExamReviewServiceImpl examReviewService;
...@@ -119,6 +126,7 @@ class ExamReviewServiceImplTest { ...@@ -119,6 +126,7 @@ class ExamReviewServiceImplTest {
void publishShouldRejectWhenSubjectiveQuestionsRemainUnscored() { void publishShouldRejectWhenSubjectiveQuestionsRemainUnscored() {
ExamEntity exam = new ExamEntity(); ExamEntity exam = new ExamEntity();
exam.setId(100); exam.setId(100);
exam.setName("污水处理理论考试");
exam.setMarkFlag(false); exam.setMarkFlag(false);
ExamStudentEntity student = ExamStudentEntity.builder() ExamStudentEntity student = ExamStudentEntity.builder()
.id(10) .id(10)
...@@ -167,6 +175,13 @@ class ExamReviewServiceImplTest { ...@@ -167,6 +175,13 @@ class ExamReviewServiceImplTest {
verify(examReviewMapper).publishStudent(10, 86.5D); verify(examReviewMapper).publishStudent(10, 86.5D);
verify(examReviewMapper).publishTask(100); verify(examReviewMapper).publishTask(100);
verify(scoreLogMapper).insert(any(ExamReviewScoreLogEntity.class)); verify(scoreLogMapper).insert(any(ExamReviewScoreLogEntity.class));
ArgumentCaptor<NotificationPublishDTO> messageCaptor =
ArgumentCaptor.forClass(NotificationPublishDTO.class);
verify(notificationPublisher).publish(
messageCaptor.capture(), eq("teacher-1"), eq("教师"));
assertEquals("SCORE", messageCaptor.getValue().getMessageType());
assertEquals(Collections.singletonList("管理员"),
messageCaptor.getValue().getRecipientRoleNames());
} }
@Test @Test
......
package com.platform.business.service.impl;
import com.platform.business.constant.LeaveConstants;
import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.entity.ClassSubjectEntity;
import com.platform.business.model.vo.LeaveApplicationVO;
import com.platform.business.service.BusinessNotificationPublisher;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Arrays;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/** 请假消息接收范围测试,重点防止审批结果被错误广播给无关角色。 */
@ExtendWith(MockitoExtension.class)
class LeaveManagementNotificationTest {
@Mock
private BusinessNotificationPublisher notificationPublisher;
@InjectMocks
private LeaveManagementServiceImpl service;
@Test
void applicationShouldNotifyOnlyDistinctRelatedTeachers() {
LeaveApplicationVO leave = leave();
ClassSubjectEntity first = subject("teacher-1");
ClassSubjectEntity duplicate = subject("teacher-1");
ClassSubjectEntity second = subject("teacher-2");
service.publishLeaveApplication(leave, Arrays.asList(first, duplicate, second));
ArgumentCaptor<NotificationPublishDTO> messageCaptor =
ArgumentCaptor.forClass(NotificationPublishDTO.class);
verify(notificationPublisher).publish(
messageCaptor.capture(), eq("student-1"), eq("张学员"));
assertEquals(Arrays.asList("teacher-1", "teacher-2"),
messageCaptor.getValue().getRecipientUserIds());
assertNull(messageCaptor.getValue().getRecipientRoleNames());
}
@Test
void reviewShouldSendSeparateAdminOpinionOnlyWhenApproved() {
LeaveApplicationVO leave = leave();
leave.setApproverName("王老师");
leave.setApprovalOpinion("审批意见");
service.publishLeaveReview(
leave, LeaveConstants.STATUS_APPROVED, "teacher-1", LeaveConstants.ROLE_TEACHER);
service.publishLeaveReview(
leave, LeaveConstants.STATUS_REJECTED, "teacher-1", LeaveConstants.ROLE_TEACHER);
ArgumentCaptor<NotificationPublishDTO> messageCaptor =
ArgumentCaptor.forClass(NotificationPublishDTO.class);
verify(notificationPublisher, times(3)).publish(
messageCaptor.capture(), eq("teacher-1"), eq("王老师"));
NotificationPublishDTO approvedStudent = messageCaptor.getAllValues().get(0);
NotificationPublishDTO approvedAdmin = messageCaptor.getAllValues().get(1);
NotificationPublishDTO rejectedStudent = messageCaptor.getAllValues().get(2);
assertEquals(Collections.singletonList("student-1"),
approvedStudent.getRecipientUserIds());
assertNull(approvedStudent.getRecipientRoleNames());
assertEquals(Collections.singletonList("管理员"),
approvedAdmin.getRecipientRoleNames());
assertNull(approvedAdmin.getRecipientUserIds());
assertEquals("审批意见", approvedAdmin.getSummary());
assertEquals("审批意见", approvedAdmin.getContent());
assertEquals(Collections.singletonList("student-1"), rejectedStudent.getRecipientUserIds());
assertNull(rejectedStudent.getRecipientRoleNames());
}
private LeaveApplicationVO leave() {
LeaveApplicationVO leave = new LeaveApplicationVO();
leave.setId("leave-1");
leave.setStudentId("student-1");
leave.setStudentName("张学员");
return leave;
}
private ClassSubjectEntity subject(String teacherId) {
ClassSubjectEntity subject = new ClassSubjectEntity();
subject.setTeacherId(teacherId);
return subject;
}
}
...@@ -6,10 +6,12 @@ import com.platform.business.mapper.TeachingPlanMapper; ...@@ -6,10 +6,12 @@ import com.platform.business.mapper.TeachingPlanMapper;
import com.platform.business.mapper.TeachingPlanStepMapper; import com.platform.business.mapper.TeachingPlanStepMapper;
import com.platform.business.model.dto.TeachingPlanAdminQueryDTO; import com.platform.business.model.dto.TeachingPlanAdminQueryDTO;
import com.platform.business.model.dto.TeachingPlanAdminUpdateDTO; import com.platform.business.model.dto.TeachingPlanAdminUpdateDTO;
import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.entity.TeachingPlanEntity; import com.platform.business.model.entity.TeachingPlanEntity;
import com.platform.business.model.vo.TeachingPlanAttachmentVO; import com.platform.business.model.vo.TeachingPlanAttachmentVO;
import com.platform.business.model.vo.TeachingPlanVO; import com.platform.business.model.vo.TeachingPlanVO;
import com.platform.business.service.BsFileService; import com.platform.business.service.BsFileService;
import com.platform.business.service.BusinessNotificationPublisher;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
...@@ -31,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; ...@@ -31,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
...@@ -51,6 +54,9 @@ class TeachingPlanAdminServiceImplTest { ...@@ -51,6 +54,9 @@ class TeachingPlanAdminServiceImplTest {
@Mock @Mock
private BsFileService bsFileService; private BsFileService bsFileService;
@Mock
private BusinessNotificationPublisher notificationPublisher;
@InjectMocks @InjectMocks
private TeachingPlanServiceImpl teachingPlanService; private TeachingPlanServiceImpl teachingPlanService;
...@@ -129,6 +135,50 @@ class TeachingPlanAdminServiceImplTest { ...@@ -129,6 +135,50 @@ class TeachingPlanAdminServiceImplTest {
verify(teachingPlanMapper, never()).updateAdmin(any()); verify(teachingPlanMapper, never()).updateAdmin(any());
} }
@Test
void adminRejectShouldNotifyOnlyPlanTeacher() {
TeachingPlanEntity pending = new TeachingPlanEntity();
pending.setId("plan-1");
pending.setTeacherId("teacher-1");
pending.setTitle("高处作业安全教案");
pending.setStatus(TeachingPlanConstants.STATUS_PENDING);
when(teachingPlanMapper.selectAdminPlanForUpdate("plan-1")).thenReturn(pending);
when(teachingPlanMapper.updateAdmin(any())).thenReturn(1);
when(teachingPlanMapper.selectAdminDetail("plan-1")).thenReturn(planVo());
when(attachmentMapper.selectByPlanIds(anyList())).thenReturn(Collections.emptyList());
TeachingPlanAdminUpdateDTO request = validRequest();
request.setStatus(TeachingPlanConstants.STATUS_REJECTED);
request.setReviewOpinion("补充安全操作步骤");
teachingPlanService.adminUpdate("plan-1", request, "admin-1", "教务管理员");
ArgumentCaptor<NotificationPublishDTO> messageCaptor =
ArgumentCaptor.forClass(NotificationPublishDTO.class);
verify(notificationPublisher).publish(
messageCaptor.capture(), eq("admin-1"), eq("教务管理员"));
assertEquals(Collections.singletonList("teacher-1"),
messageCaptor.getValue().getRecipientUserIds());
assertTrue(messageCaptor.getValue().getContent().contains("补充安全操作步骤"));
}
@Test
void adminApproveShouldEndFlowWithoutTeacherNotification() {
TeachingPlanEntity pending = new TeachingPlanEntity();
pending.setId("plan-1");
pending.setTeacherId("teacher-1");
pending.setStatus(TeachingPlanConstants.STATUS_PENDING);
when(teachingPlanMapper.selectAdminPlanForUpdate("plan-1")).thenReturn(pending);
when(teachingPlanMapper.updateAdmin(any())).thenReturn(1);
when(teachingPlanMapper.selectAdminDetail("plan-1")).thenReturn(planVo());
when(attachmentMapper.selectByPlanIds(anyList())).thenReturn(Collections.emptyList());
TeachingPlanAdminUpdateDTO request = validRequest();
request.setStatus(TeachingPlanConstants.STATUS_APPROVED);
teachingPlanService.adminUpdate("plan-1", request, "admin-1", "教务管理员");
verify(notificationPublisher, never()).publish(any(), any(), any());
}
@Test @Test
void exportAdminListShouldCreateFilteredExcelWithExpectedHeaders() throws Exception { void exportAdminListShouldCreateFilteredExcelWithExpectedHeaders() throws Exception {
TeachingPlanVO plan = planVo(); TeachingPlanVO plan = planVo();
......
...@@ -5,6 +5,7 @@ import com.platform.business.mapper.TeachingPlanAttachmentMapper; ...@@ -5,6 +5,7 @@ import com.platform.business.mapper.TeachingPlanAttachmentMapper;
import com.platform.business.mapper.TeachingPlanMapper; import com.platform.business.mapper.TeachingPlanMapper;
import com.platform.business.mapper.TeachingPlanStepMapper; import com.platform.business.mapper.TeachingPlanStepMapper;
import com.platform.business.model.dto.TeachingPlanQueryDTO; import com.platform.business.model.dto.TeachingPlanQueryDTO;
import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.dto.TeachingPlanSaveDTO; import com.platform.business.model.dto.TeachingPlanSaveDTO;
import com.platform.business.model.dto.TeachingPlanStatusDTO; import com.platform.business.model.dto.TeachingPlanStatusDTO;
import com.platform.business.model.dto.TeachingPlanStepDTO; import com.platform.business.model.dto.TeachingPlanStepDTO;
...@@ -14,6 +15,7 @@ import com.platform.business.model.entity.TeachingPlanEntity; ...@@ -14,6 +15,7 @@ import com.platform.business.model.entity.TeachingPlanEntity;
import com.platform.business.model.entity.TeachingPlanStepEntity; import com.platform.business.model.entity.TeachingPlanStepEntity;
import com.platform.business.model.vo.TeachingPlanVO; import com.platform.business.model.vo.TeachingPlanVO;
import com.platform.business.service.BsFileService; import com.platform.business.service.BsFileService;
import com.platform.business.service.BusinessNotificationPublisher;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
...@@ -67,6 +69,9 @@ class TeachingPlanServiceImplTest { ...@@ -67,6 +69,9 @@ class TeachingPlanServiceImplTest {
@Mock @Mock
private BsFileService bsFileService; private BsFileService bsFileService;
@Mock
private BusinessNotificationPublisher notificationPublisher;
@InjectMocks @InjectMocks
private TeachingPlanServiceImpl teachingPlanService; private TeachingPlanServiceImpl teachingPlanService;
...@@ -251,6 +256,16 @@ class TeachingPlanServiceImplTest { ...@@ -251,6 +256,16 @@ class TeachingPlanServiceImplTest {
TeachingPlanVO result = teachingPlanService.updateStatus("plan-1", request, TEACHER_ID); TeachingPlanVO result = teachingPlanService.updateStatus("plan-1", request, TEACHER_ID);
assertEquals(targetStatus, result.getStatus()); assertEquals(targetStatus, result.getStatus());
if (TeachingPlanConstants.STATUS_PENDING.equals(targetStatus)) {
ArgumentCaptor<NotificationPublishDTO> messageCaptor =
ArgumentCaptor.forClass(NotificationPublishDTO.class);
verify(notificationPublisher).publish(messageCaptor.capture(), eq(TEACHER_ID), eq("教师"));
assertEquals("TEACHING_PLAN", messageCaptor.getValue().getMessageType());
assertEquals(Collections.singletonList("管理员"),
messageCaptor.getValue().getRecipientRoleNames());
} else {
verify(notificationPublisher, never()).publish(any(), any(), any());
}
} }
@Test @Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment