Commit 2c66995a authored by 王蔡翾's avatar 王蔡翾
Browse files

bug修复

parent a8e84103
...@@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test; ...@@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
...@@ -23,13 +24,35 @@ class StudentLearningMapperXmlTest { ...@@ -23,13 +24,35 @@ class StudentLearningMapperXmlTest {
@Test @Test
void studentExamMapperShouldRegisterOnlineExamStatements() throws Exception { void studentExamMapperShouldRegisterOnlineExamStatements() throws Exception {
Configuration configuration = parse("com/platform/business/mapper/StudentExamCenterMapper.xml"); String resource = "com/platform/business/mapper/StudentExamCenterMapper.xml";
Configuration configuration = parse(resource);
assertTrue(configuration.hasStatement( assertTrue(configuration.hasStatement(
"com.platform.business.mapper.StudentExamCenterMapper.selectPage")); "com.platform.business.mapper.StudentExamCenterMapper.selectPage"));
assertTrue(configuration.hasStatement( assertTrue(configuration.hasStatement(
"com.platform.business.mapper.StudentExamCenterMapper.selectAttemptForUpdate")); "com.platform.business.mapper.StudentExamCenterMapper.selectAttemptForUpdate"));
assertTrue(configuration.hasStatement( assertTrue(configuration.hasStatement(
"com.platform.business.mapper.StudentExamCenterMapper.updateAttemptSubmitted")); "com.platform.business.mapper.StudentExamCenterMapper.updateAttemptSubmitted"));
String paperSql = compact(configuration.getMappedStatement(
"com.platform.business.mapper.StudentExamCenterMapper.selectPaperQuestions")
.getBoundSql(Collections.emptyMap()).getSql());
// 答题查询沿用正式试卷题型分组;服务层负责把历史题号转换为连续展示题号。
assertTrue(paperSql.contains("order by case type"));
assertTrue(paperSql.indexOf("case type") < paperSql.indexOf("cast(sequence as unsigned)"));
assertFalse(paperSql.contains("rand()"));
}
@Test
void paperDetailMapperShouldKeepGroupedFixedOrderWithoutRandomization() throws Exception {
Configuration configuration = parse(
"com/platform/business/mapper/TheoreticalPaperDetailMapper.xml");
String sql = compact(configuration.getMappedStatement(
"com.platform.business.mapper.TheoreticalPaperDetailMapper.selectInPaperOrder")
.getBoundSql(Collections.singletonMap("paperId", "paper-1")).getSql());
assertTrue(sql.contains("order by case type"));
assertTrue(sql.contains("cast(sequence as unsigned)"));
assertFalse(sql.contains("rand()"));
} }
@Test @Test
...@@ -73,4 +96,8 @@ class StudentLearningMapperXmlTest { ...@@ -73,4 +96,8 @@ class StudentLearningMapperXmlTest {
return new String(output.toByteArray(), StandardCharsets.UTF_8); return new String(output.toByteArray(), StandardCharsets.UTF_8);
} }
} }
private String compact(String sql) {
return sql.replaceAll("\\s+", " ").trim().toLowerCase();
}
} }
...@@ -220,6 +220,25 @@ class ClassAdminServiceImplTest { ...@@ -220,6 +220,25 @@ class ClassAdminServiceImplTest {
verify(classMapper).selectAdminStudents(9, null); verify(classMapper).selectAdminStudents(9, null);
} }
@Test
void detailCourseShouldCompleteImmediatelyAfterLastScheduleEndTime() {
java.util.Date today = Date.valueOf(LocalDate.now(ClassAdminConstants.BUSINESS_ZONE));
ClassAdminDetailVO detail = baseDetail(10, today, today);
when(classMapper.selectAdminDetail(10)).thenReturn(detail);
ClassAdminCourseVO course = new ClassAdminCourseVO();
course.setFirstDate(today);
course.setLastDate(today);
course.setLastEndTime(new java.util.Date(System.currentTimeMillis() - 60_000L));
when(classMapper.selectAdminCourses(10)).thenReturn(Collections.singletonList(course));
when(classMapper.selectAdminStudents(eq(10), any())).thenReturn(Collections.emptyList());
ClassAdminDetailVO result = service.detail(10);
// 班级当天仍在进行中,但课程结束时刻已过,课程必须立即显示“已完成”。
assertEquals(ClassAdminConstants.STATUS_ENDED, result.getCourses().get(0).getStatus());
assertEquals("已完成", result.getCourses().get(0).getStatusName());
}
@ParameterizedTest @ParameterizedTest
@CsvSource({ @CsvSource({
"2026-08-18,2026-08-19,2026-08-20,UPCOMING", "2026-08-18,2026-08-19,2026-08-20,UPCOMING",
......
...@@ -11,6 +11,7 @@ import com.platform.business.model.dto.NotificationPublishDTO; ...@@ -11,6 +11,7 @@ import com.platform.business.model.dto.NotificationPublishDTO;
import com.platform.business.model.entity.ClassSubjectEntity; import com.platform.business.model.entity.ClassSubjectEntity;
import com.platform.business.model.entity.EvaluationRecordEntity; import com.platform.business.model.entity.EvaluationRecordEntity;
import com.platform.business.model.entity.EvaluationTaskEntity; import com.platform.business.model.entity.EvaluationTaskEntity;
import com.platform.business.model.vo.EvaluationRecordVO;
import com.platform.business.model.vo.EvaluationTaskVO; import com.platform.business.model.vo.EvaluationTaskVO;
import com.platform.business.model.vo.StudentEvaluationTaskVO; import com.platform.business.model.vo.StudentEvaluationTaskVO;
import com.platform.business.service.BusinessNotificationPublisher; import com.platform.business.service.BusinessNotificationPublisher;
...@@ -164,6 +165,35 @@ class EvaluationServiceImplTest { ...@@ -164,6 +165,35 @@ class EvaluationServiceImplTest {
verify(recordMapper).batchInsert(any()); verify(recordMapper).batchInsert(any());
} }
@Test
void revokeShouldNotifySnapshotStudentsWithCurrentStatus() {
EvaluationTaskEntity task = pendingTask();
EvaluationRecordVO first = new EvaluationRecordVO();
first.setStudentId("S1");
EvaluationRecordVO second = new EvaluationRecordVO();
second.setStudentId("S2");
when(taskMapper.expireDueTasks(any(Date.class))).thenReturn(0);
when(taskMapper.selectByIdForUpdate("T1")).thenReturn(task);
when(taskMapper.revokePending(eq("T1"), eq("A1"), any(Date.class))).thenReturn(1);
when(recordMapper.queryTaskRecords("T1", null)).thenReturn(Arrays.asList(first, second));
service.revoke("T1", "A1");
ArgumentCaptor<NotificationPublishDTO> messageCaptor =
ArgumentCaptor.forClass(NotificationPublishDTO.class);
verify(notificationPublisher).publish(messageCaptor.capture(), eq("A1"), eq("管理员"));
NotificationPublishDTO message = messageCaptor.getValue();
assertEquals("evaluation-task-revoked:T1", message.getEventId());
assertEquals("当前新增评价任务已被撤回", message.getSummary());
assertEquals("当前新增评价任务已被撤回", message.getContent());
assertEquals("EVALUATION", message.getBusinessType());
assertEquals("T1", message.getBusinessId());
assertEquals(Arrays.asList("S1", "S2"), message.getRecipientUserIds());
// 撤回任务不再提供跳转地址,也不沿用原任务截止时间作为消息过期时间。
assertNull(message.getActionUrl());
assertNull(message.getExpiresAt());
}
@Test @Test
void submitShouldPersistScoresAndTryToCompleteTask() { void submitShouldPersistScoresAndTryToCompleteTask() {
EvaluationTaskEntity task = pendingTask(); EvaluationTaskEntity task = pendingTask();
......
...@@ -37,6 +37,7 @@ import static org.mockito.ArgumentMatchers.any; ...@@ -37,6 +37,7 @@ 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.ArgumentMatchers.eq;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
...@@ -128,10 +129,19 @@ class ExamAdminServiceImplTest { ...@@ -128,10 +129,19 @@ class ExamAdminServiceImplTest {
ArgumentCaptor<NotificationPublishDTO> messageCaptor = ArgumentCaptor<NotificationPublishDTO> messageCaptor =
ArgumentCaptor.forClass(NotificationPublishDTO.class); ArgumentCaptor.forClass(NotificationPublishDTO.class);
verify(notificationPublisher).publish(messageCaptor.capture(), eq(null), eq("管理员")); verify(notificationPublisher, times(2))
.publish(messageCaptor.capture(), eq(null), eq("管理员"));
NotificationPublishDTO teacherMessage = messageCaptor.getAllValues().get(0);
NotificationPublishDTO studentMessage = messageCaptor.getAllValues().get(1);
assertEquals(Arrays.asList("teacher-1", "teacher-2"), assertEquals(Arrays.asList("teacher-1", "teacher-2"),
messageCaptor.getValue().getRecipientUserIds()); teacherMessage.getRecipientUserIds());
assertEquals("EXAM", messageCaptor.getValue().getMessageType()); assertEquals(Arrays.asList("student-1", "student-2"),
studentMessage.getRecipientUserIds());
assertEquals("EXAM", teacherMessage.getMessageType());
assertEquals("EXAM", studentMessage.getMessageType());
// 教师与学员必须收到各自端的入口,不能把教师批阅地址发送给学员。
assertEquals("/exam/teacher/scores/exams/99", teacherMessage.getActionUrl());
assertEquals("/exam/student/center", studentMessage.getActionUrl());
} }
@Test @Test
......
package com.platform.business.service.impl; package com.platform.business.service.impl;
import com.platform.business.constant.ExamAdminConstants;
import com.platform.business.mapper.StudentExamCenterMapper; import com.platform.business.mapper.StudentExamCenterMapper;
import com.platform.business.model.dto.StudentExamAnswerDTO; import com.platform.business.model.dto.StudentExamAnswerDTO;
import com.platform.business.model.dto.StudentExamCenterQueryDTO; import com.platform.business.model.dto.StudentExamCenterQueryDTO;
...@@ -67,7 +68,7 @@ class StudentExamCenterServiceImplTest { ...@@ -67,7 +68,7 @@ class StudentExamCenterServiceImplTest {
StudentExamCenterQueryDTO query = new StudentExamCenterQueryDTO(); StudentExamCenterQueryDTO query = new StudentExamCenterQueryDTO();
query.setStatus(null); query.setStatus(null);
StudentExamCenterVO.ListItem waiting = new StudentExamCenterVO.ListItem(); StudentExamCenterVO.ListItem waiting = new StudentExamCenterVO.ListItem();
waiting.setType("理论"); waiting.setType(ExamAdminConstants.TYPE_THEORY);
waiting.setExamTime(new Date(System.currentTimeMillis() - 1000)); waiting.setExamTime(new Date(System.currentTimeMillis() - 1000));
waiting.setScore(95D); waiting.setScore(95D);
when(mapper.selectPage(query, "student-1")).thenReturn(Collections.singletonList(waiting)); when(mapper.selectPage(query, "student-1")).thenReturn(Collections.singletonList(waiting));
...@@ -110,7 +111,7 @@ class StudentExamCenterServiceImplTest { ...@@ -110,7 +111,7 @@ class StudentExamCenterServiceImplTest {
} }
@Test @Test
void firstStartShouldGeneratePaperWithJwtStudentIdAndMarkAttemptStarted() { void firstStartShouldUseFixedPaperOrderEvenForLegacyRandomFlag() {
StudentExamCenterVO.Attempt attempt = attempt(false); StudentExamCenterVO.Attempt attempt = attempt(false);
attempt.setPaperId("paper-1"); attempt.setPaperId("paper-1");
when(mapper.selectAttemptForUpdate(1, "student-1")).thenReturn(attempt); when(mapper.selectAttemptForUpdate(1, "student-1")).thenReturn(attempt);
...@@ -118,11 +119,12 @@ class StudentExamCenterServiceImplTest { ...@@ -118,11 +119,12 @@ class StudentExamCenterServiceImplTest {
TheoreticalPaperEntity paper = new TheoreticalPaperEntity(); TheoreticalPaperEntity paper = new TheoreticalPaperEntity();
paper.setSequence("乱序"); paper.setSequence("乱序");
when(paperService.getById("paper-1")).thenReturn(paper); when(paperService.getById("paper-1")).thenReturn(paper);
TheoreticalPaperDetailEntity source = new TheoreticalPaperDetailEntity(); TheoreticalPaperDetailEntity question65 = sourceQuestion("source-65", "65");
source.setId("source-question"); TheoreticalPaperDetailEntity question100 = sourceQuestion("source-100", "100");
source.setProblem("题目"); TheoreticalPaperDetailEntity question104 = sourceQuestion("source-104", "104");
when(paperDetailService.selectDisorderly("paper-1")) TheoreticalPaperDetailEntity question66 = sourceQuestion("source-66", "66");
.thenReturn(Collections.singletonList(source)); when(paperDetailService.selectInPaperOrder("paper-1"))
.thenReturn(Arrays.asList(question65, question100, question104, question66));
when(studentDetailService.saveBatch(anyCollection())).thenReturn(true); when(studentDetailService.saveBatch(anyCollection())).thenReturn(true);
when(mapper.updateAttemptStarted(eq(1), any(), any(), any())).thenReturn(1); when(mapper.updateAttemptStarted(eq(1), any(), any(), any())).thenReturn(1);
when(userService.updateById(any())).thenReturn(true); when(userService.updateById(any())).thenReturn(true);
...@@ -133,20 +135,52 @@ class StudentExamCenterServiceImplTest { ...@@ -133,20 +135,52 @@ class StudentExamCenterServiceImplTest {
ArgumentCaptor<java.util.Collection<TheoreticalPaperStudentDetailEntity>> captor = ArgumentCaptor<java.util.Collection<TheoreticalPaperStudentDetailEntity>> captor =
ArgumentCaptor.forClass(java.util.Collection.class); ArgumentCaptor.forClass(java.util.Collection.class);
verify(studentDetailService).saveBatch(captor.capture()); verify(studentDetailService).saveBatch(captor.capture());
TheoreticalPaperStudentDetailEntity generated = captor.getValue().iterator().next(); List<TheoreticalPaperStudentDetailEntity> generated =
assertEquals("student-1", generated.getStudentId()); new java.util.ArrayList<>(captor.getValue());
assertEquals(10, generated.getExamId()); // 原试卷分组结果保持不变,但个人答题题号必须重新连续生成,不能返回65、100、104、66。
assertNull(generated.getId()); assertEquals(Arrays.asList("1", "2", "3", "4"), generated.stream()
.map(TheoreticalPaperStudentDetailEntity::getSequence)
.collect(java.util.stream.Collectors.toList()));
assertEquals(Arrays.asList("题目65", "题目100", "题目104", "题目66"), generated.stream()
.map(TheoreticalPaperStudentDetailEntity::getProblem)
.collect(java.util.stream.Collectors.toList()));
TheoreticalPaperStudentDetailEntity firstQuestion = generated.get(0);
assertEquals("student-1", firstQuestion.getStudentId());
assertEquals(10, firstQuestion.getExamId());
assertNull(firstQuestion.getId());
} }
@Test @Test
void practicalExamShouldNotEnterTheoryStartFlow() { void practicalExamShouldNotEnterTheoryStartFlow() {
StudentExamCenterVO.Attempt attempt = attempt(false); StudentExamCenterVO.Attempt attempt = attempt(false);
attempt.setExamType("实训"); attempt.setExamType(ExamAdminConstants.TYPE_PRACTICE);
when(mapper.selectAttemptForUpdate(1, "student-1")).thenReturn(attempt); when(mapper.selectAttemptForUpdate(1, "student-1")).thenReturn(attempt);
assertThrows(BusinessException.class, () -> service.start(1, "student-1")); assertThrows(BusinessException.class, () -> service.start(1, "student-1"));
} }
@Test
void paperShouldKeepGroupedOrderAndReturnContinuousSequenceForExistingPaper() {
StudentExamCenterVO.Attempt attempt = attempt(false);
attempt.setStartTime(System.currentTimeMillis() - 1000);
when(mapper.selectAttempt(1, "student-1")).thenReturn(attempt);
List<StudentExamCenterVO.Question> questions = Arrays.asList(
paperQuestion("q-65", "65"),
paperQuestion("q-100", "100"),
paperQuestion("q-104", "104"),
paperQuestion("q-66", "66"));
when(mapper.selectPaperQuestions(10, "student-1")).thenReturn(questions);
StudentExamCenterVO.Paper result = service.paper(1, "student-1");
// 内容顺序沿用Mapper确定的题型分组,展示题号则必须连续,兼容已经开考的旧数据。
assertEquals(Arrays.asList("q-65", "q-100", "q-104", "q-66"),
result.getQuestions().stream().map(StudentExamCenterVO.Question::getId)
.collect(java.util.stream.Collectors.toList()));
assertEquals(Arrays.asList("1", "2", "3", "4"),
result.getQuestions().stream().map(StudentExamCenterVO.Question::getSequence)
.collect(java.util.stream.Collectors.toList()));
}
@Test @Test
void saveAnswerShouldRequireQuestionOwnership() { void saveAnswerShouldRequireQuestionOwnership() {
StudentExamCenterVO.Attempt attempt = attempt(false); StudentExamCenterVO.Attempt attempt = attempt(false);
...@@ -245,7 +279,7 @@ class StudentExamCenterServiceImplTest { ...@@ -245,7 +279,7 @@ class StudentExamCenterServiceImplTest {
attempt.setId(1); attempt.setId(1);
attempt.setExamId(10); attempt.setExamId(10);
attempt.setStudentId("student-1"); attempt.setStudentId("student-1");
attempt.setExamType("理论"); attempt.setExamType(ExamAdminConstants.TYPE_THEORY);
attempt.setExamTime(new Date(System.currentTimeMillis() - 1000)); attempt.setExamTime(new Date(System.currentTimeMillis() - 1000));
attempt.setExamDuration(90); attempt.setExamDuration(90);
attempt.setSubmit(submitted); attempt.setSubmit(submitted);
...@@ -263,4 +297,21 @@ class StudentExamCenterServiceImplTest { ...@@ -263,4 +297,21 @@ class StudentExamCenterServiceImplTest {
question.setScore(score); question.setScore(score);
return question; return question;
} }
/** 构造带历史题号的原试卷题目,用于复现跨题型分组后的跳号数据。 */
private TheoreticalPaperDetailEntity sourceQuestion(String id, String sequence) {
TheoreticalPaperDetailEntity question = new TheoreticalPaperDetailEntity();
question.setId(id);
question.setSequence(sequence);
question.setProblem("题目" + sequence);
return question;
}
/** 构造历史个人试卷题目,sequence用于模拟分组后不连续的旧题号。 */
private StudentExamCenterVO.Question paperQuestion(String id, String sequence) {
StudentExamCenterVO.Question question = new StudentExamCenterVO.Question();
question.setId(id);
question.setSequence(sequence);
return question;
}
} }
package com.platform.business.service.impl; package com.platform.business.service.impl;
import com.platform.business.constant.AttendanceConstants;
import com.platform.business.mapper.StudentHomeMapper; import com.platform.business.mapper.StudentHomeMapper;
import com.platform.business.model.entity.UserEntity; import com.platform.business.model.entity.UserEntity;
import com.platform.business.model.vo.StudentHomeVO; import com.platform.business.model.vo.StudentHomeVO;
...@@ -51,7 +52,7 @@ class StudentHomeServiceImplTest { ...@@ -51,7 +52,7 @@ class StudentHomeServiceImplTest {
course.setSubjectId(1); course.setSubjectId(1);
course.setDate(date("2026-08-19 00:00")); course.setDate(date("2026-08-19 00:00"));
course.setTimeFrame("09:30-10:30"); course.setTimeFrame("09:30-10:30");
when(mapper.selectCourses(eq(10), any(Date.class), any(Date.class))) when(mapper.selectCourses(eq("student-1"), eq(10), any(Date.class), any(Date.class)))
.thenReturn(Collections.singletonList(course)); .thenReturn(Collections.singletonList(course));
List<StudentHomeVO.CourseDay> result = service.nextThreeDayCourses(student); List<StudentHomeVO.CourseDay> result = service.nextThreeDayCourses(student);
...@@ -63,6 +64,23 @@ class StudentHomeServiceImplTest { ...@@ -63,6 +64,23 @@ class StudentHomeServiceImplTest {
assertTrue(result.get(2).getCourses().isEmpty()); assertTrue(result.get(2).getCourses().isEmpty());
} }
@Test
void approvedLeaveShouldOverrideHomeCourseTimeStatus() throws Exception {
StudentHomeVO.Course course = new StudentHomeVO.Course();
course.setSubjectId(2);
course.setDate(date("2026-08-19 00:00"));
course.setTimeFrame("09:30-10:30");
course.setAttendanceStatus(AttendanceConstants.STATUS_LEAVE);
when(mapper.selectCourses(eq("student-1"), eq(10), any(Date.class), any(Date.class)))
.thenReturn(Collections.singletonList(course));
List<StudentHomeVO.CourseDay> result = service.nextThreeDayCourses(student);
// 当前时间为09:00,课程本应为UPCOMING,但已审批请假必须优先返回LEAVE。
assertEquals(AttendanceConstants.STATUS_LEAVE,
result.get(0).getCourses().get(0).getStatus());
}
@Test @Test
void recentScoresShouldMergeSortAndLimitFive() throws Exception { void recentScoresShouldMergeSortAndLimitFive() throws Exception {
when(mapper.selectRecentExamScores("student-1")).thenReturn(Arrays.asList( when(mapper.selectRecentExamScores("student-1")).thenReturn(Arrays.asList(
......
...@@ -9,6 +9,7 @@ import com.platform.business.model.dto.TeachingPlanAdminUpdateDTO; ...@@ -9,6 +9,7 @@ import com.platform.business.model.dto.TeachingPlanAdminUpdateDTO;
import com.platform.business.model.dto.NotificationPublishDTO; 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.TeachingPlanStepVO;
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.business.service.BusinessNotificationPublisher;
...@@ -208,7 +209,14 @@ class TeachingPlanAdminServiceImplTest { ...@@ -208,7 +209,14 @@ class TeachingPlanAdminServiceImplTest {
TeachingPlanVO plan = planVo(); TeachingPlanVO plan = planVo();
plan.setReviewerName("教务管理员"); plan.setReviewerName("教务管理员");
plan.setReviewOpinion("审核通过"); plan.setReviewOpinion("审核通过");
TeachingPlanStepVO step = new TeachingPlanStepVO();
step.setStageName("案例导入");
step.setContent("观看事故案例并识别风险点");
step.setMethod("案例教学");
step.setDurationMinutes(20);
plan.setSteps(Collections.singletonList(step));
when(teachingPlanMapper.selectAdminDetail("plan-1")).thenReturn(plan); when(teachingPlanMapper.selectAdminDetail("plan-1")).thenReturn(plan);
when(stepMapper.selectByPlanId("plan-1")).thenReturn(Collections.singletonList(step));
TeachingPlanAttachmentVO attachment = new TeachingPlanAttachmentVO(); TeachingPlanAttachmentVO attachment = new TeachingPlanAttachmentVO();
attachment.setPlanId("plan-1"); attachment.setPlanId("plan-1");
attachment.setFileName("安全演示.pptx"); attachment.setFileName("安全演示.pptx");
...@@ -222,12 +230,23 @@ class TeachingPlanAdminServiceImplTest { ...@@ -222,12 +230,23 @@ class TeachingPlanAdminServiceImplTest {
assertTrue(response.getHeader("Content-Disposition").contains(".docx")); assertTrue(response.getHeader("Content-Disposition").contains(".docx"));
try (XWPFDocument document = new XWPFDocument( try (XWPFDocument document = new XWPFDocument(
new ByteArrayInputStream(response.getContentAsByteArray()))) { new ByteArrayInputStream(response.getContentAsByteArray()))) {
// B8 模板必须保持“两张表、第一页综合信息、第二页三列教学环节”的固定结构。
assertEquals(2, document.getTables().size());
assertEquals("教 案", document.getParagraphs().get(0).getText());
assertTrue(document.getParagraphs().get(1).getText().contains("授课教师:王老师"));
assertEquals(9, document.getTables().get(0).getRows().size());
assertEquals("教学环节", document.getTables().get(1).getRow(0).getCell(0).getText());
assertEquals("教学内容", document.getTables().get(1).getRow(0).getCell(1).getText());
assertEquals("教学方法", document.getTables().get(1).getRow(0).getCell(2).getText());
assertTrue(document.getTables().get(1).getRow(1).getCell(0).getText()
.contains("案例导入(20分钟)"));
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();
document.getParagraphs().forEach(paragraph -> text.append(paragraph.getText())); document.getParagraphs().forEach(paragraph -> text.append(paragraph.getText()));
document.getTables().forEach(table -> text.append(table.getText())); document.getTables().forEach(table -> text.append(table.getText()));
assertTrue(text.toString().contains("高处作业安全教案")); assertTrue(text.toString().contains("高处作业安全教案"));
assertTrue(text.toString().contains("审核通过")); assertTrue(text.toString().contains("审核通过"));
assertTrue(text.toString().contains("安全演示.pptx")); assertTrue(text.toString().contains("安全演示.pptx"));
assertTrue(text.toString().contains("观看事故案例并识别风险点"));
} }
} }
......
...@@ -55,6 +55,8 @@ class TheoreticalPaperAdminServiceImplTest { ...@@ -55,6 +55,8 @@ class TheoreticalPaperAdminServiceImplTest {
@Test @Test
void manualCreateShouldRecalculateQuestionCountScoreAndCreator() { void manualCreateShouldRecalculateQuestionCountScoreAndCreator() {
TheoreticalPaperManualSaveDTO request = manualRequest("测试试卷"); TheoreticalPaperManualSaveDTO request = manualRequest("测试试卷");
// 兼容旧客户端提交的“乱序”,但正式试卷只能以固定顺序落库。
request.setSequence("乱序");
when(paperMapper.countAdminDuplicateName("测试试卷", null)).thenReturn(0); when(paperMapper.countAdminDuplicateName("测试试卷", null)).thenReturn(0);
when(paperMapper.insert(any(TheoreticalPaperEntity.class))).thenAnswer(invocation -> { when(paperMapper.insert(any(TheoreticalPaperEntity.class))).thenAnswer(invocation -> {
TheoreticalPaperEntity paper = invocation.getArgument(0); TheoreticalPaperEntity paper = invocation.getArgument(0);
...@@ -77,6 +79,7 @@ class TheoreticalPaperAdminServiceImplTest { ...@@ -77,6 +79,7 @@ class TheoreticalPaperAdminServiceImplTest {
assertEquals(2.0D, paperCaptor.getValue().getSum()); assertEquals(2.0D, paperCaptor.getValue().getSum());
assertEquals(1.2D, paperCaptor.getValue().getPassScore()); assertEquals(1.2D, paperCaptor.getValue().getPassScore());
assertEquals("管理员甲", paperCaptor.getValue().getCreateUser()); assertEquals("管理员甲", paperCaptor.getValue().getCreateUser());
assertEquals("顺序", paperCaptor.getValue().getSequence());
assertNull(paperCaptor.getValue().getCreatorId()); assertNull(paperCaptor.getValue().getCreatorId());
assertEquals("DRAFT", paperCaptor.getValue().getStatus()); assertEquals("DRAFT", paperCaptor.getValue().getStatus());
assertEquals("paper-new", result.getId()); assertEquals("paper-new", result.getId());
......
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