Commit 9b5c1b46 authored by 王蔡翾's avatar 王蔡翾
Browse files

bug修复

parent b5d4d905
...@@ -128,7 +128,7 @@ public class EvaluationServiceImpl implements EvaluationService { ...@@ -128,7 +128,7 @@ public class EvaluationServiceImpl implements EvaluationService {
try { try {
taskMapper.insert(task); taskMapper.insert(task);
} catch (DataIntegrityViolationException e) { } catch (DataIntegrityViolationException e) {
// subject_id唯一键负责拦截两个管理员同时发起同一课次的竞争请求。 // active_subject_id唯一键只约束未撤回任务,并拦截两个管理员同时重新发起的竞争请求。
throw new BusinessException("该课次已经发起过评价任务,不能重复发起"); throw new BusinessException("该课次已经发起过评价任务,不能重复发起");
} }
......
...@@ -283,8 +283,9 @@ public class LeaveManagementServiceImpl implements LeaveManagementService { ...@@ -283,8 +283,9 @@ public class LeaveManagementServiceImpl implements LeaveManagementService {
adminMessage.setEventId("leave-review:" + leave.getId() + ":admin"); adminMessage.setEventId("leave-review:" + leave.getId() + ":admin");
adminMessage.setMessageType("LEAVE"); adminMessage.setMessageType("LEAVE");
adminMessage.setTitle("请假审批意见"); adminMessage.setTitle("请假审批意见");
adminMessage.setSummary(opinion); // 管理员只查看审批意见,但仍保留字段标签,避免“同意”等短文本语义不清。
adminMessage.setContent(opinion); adminMessage.setSummary("审批意见:" + opinion);
adminMessage.setContent("审批意见:" + opinion);
adminMessage.setBusinessType("LEAVE"); adminMessage.setBusinessType("LEAVE");
adminMessage.setBusinessId(leave.getId()); adminMessage.setBusinessId(leave.getId());
adminMessage.setActionUrl("/leave/admin/" + leave.getId()); adminMessage.setActionUrl("/leave/admin/" + leave.getId());
......
...@@ -196,7 +196,13 @@ public class StudentCourseServiceImpl implements StudentCourseService { ...@@ -196,7 +196,13 @@ public class StudentCourseServiceImpl implements StudentCourseService {
for (ClassSubjectVO course : courses) { for (ClassSubjectVO course : courses) {
ClassSubjectAttendanceEntity record = attendanceBySubject.get(course.getId()); ClassSubjectAttendanceEntity record = attendanceBySubject.get(course.getId());
ClassSubjectTimeUtils.TimeWindow window = ClassSubjectTimeUtils.resolve(course); ClassSubjectTimeUtils.TimeWindow window = ClassSubjectTimeUtils.resolve(course);
if (now.before(window.getStart())) { /*
* 已批准请假是课程的最终出勤结果,即使课程尚未开始也必须优先展示LEAVE;
* 否则UPCOMING会覆盖请假状态,页面会把该课程误显示为普通签到课程。
*/
if (record != null && AttendanceConstants.STATUS_LEAVE.equals(record.getStatus())) {
course.setStatus(AttendanceConstants.STATUS_LEAVE);
} else if (now.before(window.getStart())) {
course.setStatus("UPCOMING"); course.setStatus("UPCOMING");
} else if (record != null) { } else if (record != null) {
course.setStatus(record.getStatus()); course.setStatus(record.getStatus());
......
...@@ -43,9 +43,8 @@ ...@@ -43,9 +43,8 @@
<if test="keyword != null and keyword != ''"> <if test="keyword != null and keyword != ''">
and (m.title like concat('%', #{keyword}, '%') or m.summary like concat('%', #{keyword}, '%')) and (m.title like concat('%', #{keyword}, '%') or m.summary like concat('%', #{keyword}, '%'))
</if> </if>
<!-- 同一时间范围内优先展示紧急消息,再按创建时间倒序。 --> <!-- 三端共用严格时间倒序;主键用于相同创建时间下稳定分页。 -->
order by case m.priority when 'URGENT' then 0 when 'IMPORTANT' then 1 else 2 end, order by m.created_at desc, m.id desc
m.created_at desc
</select> </select>
<!-- message_id必须和当前user_id同时命中,避免仅凭消息ID越权查看公共正文。 --> <!-- message_id必须和当前user_id同时命中,避免仅凭消息ID越权查看公共正文。 -->
......
...@@ -47,7 +47,17 @@ ...@@ -47,7 +47,17 @@
<if test="startDate != null">and l.end_time &gt;= #{startDate}</if> <if test="startDate != null">and l.end_time &gt;= #{startDate}</if>
<if test="endDate != null">and l.start_time &lt;= #{endDate}</if> <if test="endDate != null">and l.start_time &lt;= #{endDate}</if>
</where> </where>
order by case when l.status = 'PENDING' then 0 else 1 end, l.applied_at desc <choose>
<!-- 学员端严格按提交时间倒序,不能因待审批状态把较旧申请提前。 -->
<when test="studentId != null and studentId != ''">
order by l.applied_at desc, l.id desc
</when>
<!-- 教师和管理员仍保留待审批优先,便于集中处理待办。 -->
<otherwise>
order by case when l.status = 'PENDING' then 0 else 1 end,
l.applied_at desc, l.id desc
</otherwise>
</choose>
</select> </select>
<!-- 修改、撤回和审批前锁定申请,防止并发状态变化。 --> <!-- 修改、撤回和审批前锁定申请,防止并发状态变化。 -->
......
package com.platform.business.mapper;
import com.platform.business.model.dto.LeaveQueryDTO;
import com.platform.business.model.dto.NotificationMessageQueryDTO;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.Configuration;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** 校验学生请假列表与三端消息中心的时间倒序规则。 */
class ListOrderingMapperXmlTest {
@Test
void studentLeaveListShouldOrderOnlyByAppliedTimeDescending() throws Exception {
Configuration configuration = parse("StudentLeaveApplicationMapper");
LeaveQueryDTO query = new LeaveQueryDTO();
query.setStudentId("student-1");
String sql = normalizedSql(configuration,
"StudentLeaveApplicationMapper.queryApplications", query);
assertTrue(sql.contains("order by l.applied_at desc, l.id desc"));
assertFalse(sql.contains("order by case when l.status = 'pending'"));
}
@Test
void messageCenterShouldOrderByCreationTimeBeforeAnyOtherAttribute() throws Exception {
Configuration configuration = parse("NotificationMessageMapper");
String sql = normalizedSql(configuration,
"NotificationMessageMapper.queryUserMessages", new NotificationMessageQueryDTO());
assertTrue(sql.contains("order by m.created_at desc, m.id desc"));
// 优先级仍作为消息展示字段返回,但不能再改变三端列表的时间顺序。
assertFalse(sql.contains("order by case m.priority"));
}
private Configuration parse(String mapperName) throws Exception {
String resource = "com/platform/business/mapper/" + mapperName + ".xml";
Configuration configuration = new Configuration();
try (InputStream input = Resources.getResourceAsStream(resource)) {
new XMLMapperBuilder(input, configuration, resource,
configuration.getSqlFragments()).parse();
}
return configuration;
}
private String normalizedSql(Configuration configuration, String statement, Object parameter) {
return configuration.getMappedStatement("com.platform.business.mapper." + statement)
.getBoundSql(parameter)
.getSql()
.replaceAll("\\s+", " ")
.toLowerCase();
}
}
...@@ -70,7 +70,7 @@ class LeaveManagementNotificationTest { ...@@ -70,7 +70,7 @@ class LeaveManagementNotificationTest {
void reviewShouldSendSeparateAdminOpinionOnlyWhenApproved() { void reviewShouldSendSeparateAdminOpinionOnlyWhenApproved() {
LeaveApplicationVO leave = leave(); LeaveApplicationVO leave = leave();
leave.setApproverName("王老师"); leave.setApproverName("王老师");
leave.setApprovalOpinion("审批意见"); leave.setApprovalOpinion("同意");
service.publishLeaveReview( service.publishLeaveReview(
leave, LeaveConstants.STATUS_APPROVED, "teacher-1", LeaveConstants.ROLE_TEACHER); leave, LeaveConstants.STATUS_APPROVED, "teacher-1", LeaveConstants.ROLE_TEACHER);
...@@ -91,8 +91,8 @@ class LeaveManagementNotificationTest { ...@@ -91,8 +91,8 @@ class LeaveManagementNotificationTest {
assertEquals(Collections.singletonList("管理员"), assertEquals(Collections.singletonList("管理员"),
approvedAdmin.getRecipientRoleNames()); approvedAdmin.getRecipientRoleNames());
assertNull(approvedAdmin.getRecipientUserIds()); assertNull(approvedAdmin.getRecipientUserIds());
assertEquals("审批意见", approvedAdmin.getSummary()); assertEquals("审批意见:同意", approvedAdmin.getSummary());
assertEquals("审批意见", approvedAdmin.getContent()); assertEquals("审批意见:同意", approvedAdmin.getContent());
assertEquals(Collections.singletonList("student-1"), rejectedStudent.getRecipientUserIds()); assertEquals(Collections.singletonList("student-1"), rejectedStudent.getRecipientUserIds());
assertNull(rejectedStudent.getRecipientRoleNames()); assertNull(rejectedStudent.getRecipientRoleNames());
} }
......
...@@ -4,6 +4,7 @@ import com.platform.business.constant.AttendanceConstants; ...@@ -4,6 +4,7 @@ import com.platform.business.constant.AttendanceConstants;
import com.platform.business.model.dto.CourseDateQueryDTO; import com.platform.business.model.dto.CourseDateQueryDTO;
import com.platform.business.model.dto.CourseRangeQueryDTO; import com.platform.business.model.dto.CourseRangeQueryDTO;
import com.platform.business.model.entity.ClassSubjectAttendanceEntity; import com.platform.business.model.entity.ClassSubjectAttendanceEntity;
import com.platform.business.model.vo.CalendarVO;
import com.platform.business.model.vo.ClassSubjectVO; import com.platform.business.model.vo.ClassSubjectVO;
import com.platform.business.model.vo.ClassVO; import com.platform.business.model.vo.ClassVO;
import com.platform.business.service.ClassStudentService; import com.platform.business.service.ClassStudentService;
...@@ -103,6 +104,50 @@ class StudentCourseServiceImplTest { ...@@ -103,6 +104,50 @@ class StudentCourseServiceImplTest {
assertEquals("UPCOMING", days.get(1).getClassSubjectList().get(0).getStatus()); assertEquals("UPCOMING", days.get(1).getClassSubjectList().get(0).getStatus());
} }
@Test
void approvedLeaveShouldOverrideUpcomingCourseStatus() {
Date tomorrow = addDays(startOfDay(new Date()), 1);
ClassSubjectVO leaveCourse = course(2, tomorrow, "08:00-09:00");
ClassSubjectAttendanceEntity leaveRecord = new ClassSubjectAttendanceEntity();
leaveRecord.setSubjectId(2);
leaveRecord.setStatus(AttendanceConstants.STATUS_LEAVE);
when(classStudentService.queryClassIdByUserId("student-1"))
.thenReturn(Collections.singletonList(10));
when(classSubjectService.queryOneself(anyList(), any(), any()))
.thenReturn(Collections.singletonList(leaveCourse));
when(attendanceService.queryByStudentAndRange(eq("student-1"), any(), any()))
.thenReturn(Collections.singletonList(leaveRecord));
when(examStudentService.queryOneself("student-1")).thenReturn(Collections.emptyList());
List<ClassVO> days = service.schedule(range(tomorrow, tomorrow), "student-1");
// 请假是已确定的出勤结果,不能因课程尚未开始而退回UPCOMING标签。
assertEquals(AttendanceConstants.STATUS_LEAVE,
days.get(0).getClassSubjectList().get(0).getStatus());
}
@Test
void todayLeaveCourseShouldNotBeMarkedAsSignedIn() {
CalendarVO course = new CalendarVO();
course.setSubjectId(3);
ClassSubjectAttendanceEntity leaveRecord = new ClassSubjectAttendanceEntity();
leaveRecord.setSubjectId(3);
leaveRecord.setStatus(AttendanceConstants.STATUS_LEAVE);
leaveRecord.setCheckInMethod(AttendanceConstants.METHOD_LEAVE);
when(classStudentService.queryClassIdByUserId("student-1"))
.thenReturn(Collections.singletonList(10));
when(classSubjectService.todayCourse(anyList(), any()))
.thenReturn(Collections.singletonList(course));
when(attendanceService.queryByStudentAndRange(eq("student-1"), any(), any()))
.thenReturn(Collections.singletonList(leaveRecord));
CalendarVO result = service.today("student-1").get(0);
// LEAVE表示未实际到课,标签为请假且isSignIn必须保持false。
assertEquals(AttendanceConstants.STATUS_LEAVE, result.getAttendanceStatus());
assertEquals(Boolean.FALSE, result.getIsSignIn());
}
@Test @Test
void summaryShouldCountUpcomingCourseAsPendingAndUseBoundedAttendanceQuery() { void summaryShouldCountUpcomingCourseAsPendingAndUseBoundedAttendanceQuery() {
Date today = startOfDay(new Date()); Date today = startOfDay(new Date());
......
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