|
|
|
|
@ -2,11 +2,13 @@ package com.sztzjy.linkCommerce.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.sztzjy.linkCommerce.config.security.JwtUser;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.SchoolClass;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.TaskAllocation;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.TeachingClassStudent;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.TrainingTask;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.TrainingTaskClassConfig;
|
|
|
|
|
import com.sztzjy.linkCommerce.entity.importDto.TrainingTaskImportDTO;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.TaskAllocationMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.TrainingTaskClassConfigMapper;
|
|
|
|
|
import com.sztzjy.linkCommerce.mapper.TrainingTaskMapper;
|
|
|
|
|
@ -220,9 +222,11 @@ class TrainingTaskServiceImplTest {
|
|
|
|
|
service.ensureDefaultTasks("system");
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<TrainingTask> captor = ArgumentCaptor.forClass(TrainingTask.class);
|
|
|
|
|
verify(service.trainingTaskMapper, times(22)).insertSelective(captor.capture());
|
|
|
|
|
verify(service.trainingTaskMapper, times(23)).insertSelective(captor.capture());
|
|
|
|
|
assertFalse(captor.getAllValues().stream().anyMatch(task -> "new-product-survey".equals(task.getTaskKey())));
|
|
|
|
|
assertEquals("product-development-factors", captor.getAllValues().get(0).getTaskKey());
|
|
|
|
|
assertEquals("comprehensive-case-training", captor.getAllValues().get(0).getTaskKey());
|
|
|
|
|
assertEquals("综合实训", captor.getAllValues().get(0).getProjectName());
|
|
|
|
|
assertEquals("综合案例实训", captor.getAllValues().get(0).getTaskName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@ -510,7 +514,7 @@ class TrainingTaskServiceImplTest {
|
|
|
|
|
service.saveClassTask("class-1", "new-product-survey", payload, "teacher-1");
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<TrainingTaskClassConfig> captor = ArgumentCaptor.forClass(TrainingTaskClassConfig.class);
|
|
|
|
|
verify(service.trainingTaskClassConfigMapper, times(24)).insertSelective(captor.capture());
|
|
|
|
|
verify(service.trainingTaskClassConfigMapper, times(25)).insertSelective(captor.capture());
|
|
|
|
|
TrainingTaskClassConfig savedOverride = captor.getAllValues().stream()
|
|
|
|
|
.filter(config -> "new-product-survey".equals(config.getTaskKey()))
|
|
|
|
|
.filter(config -> "Class Name".equals(config.getTaskName()))
|
|
|
|
|
@ -601,6 +605,204 @@ class TrainingTaskServiceImplTest {
|
|
|
|
|
assertEquals(0, result.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentListHidesComprehensiveTrainingUntilTheClassHasPublishedIt() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask legacy = storedTask("task-1", "new-product-survey");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(legacy, comprehensive));
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null))
|
|
|
|
|
.thenReturn(List.of(overrideTask("config-1", "class-1", "new-product-survey"),
|
|
|
|
|
overrideTask("config-2", "class-1", "comprehensive-case-training")));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForStudent("stu-1", true);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("new-product-survey"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentTaskLookupHidesComprehensiveTrainingUntilTheClassHasPublishedIt() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectByTaskKey("comprehensive-case-training")).thenReturn(comprehensive);
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
|
|
|
|
|
TrainingTask result = service.getStudentTaskByTaskKey("comprehensive-case-training", "stu-1");
|
|
|
|
|
|
|
|
|
|
assertNull(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentTaskLookupReturnsComprehensiveTrainingWhenPublishedAndEnabledForTheClass() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectByTaskKey("comprehensive-case-training")).thenReturn(comprehensive);
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectByTeachingClassAndTaskKey("class-1", "comprehensive-case-training"))
|
|
|
|
|
.thenReturn(overrideTask("config-1", "class-1", "comprehensive-case-training"));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("comprehensive-case-training", (byte) 0)));
|
|
|
|
|
|
|
|
|
|
TrainingTask result = service.getStudentTaskByTaskKey("comprehensive-case-training", "stu-1");
|
|
|
|
|
|
|
|
|
|
assertEquals("comprehensive-case-training", result.getTaskKey());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentTaskLookupHidesPublishedComprehensiveTrainingWhenItsClassTaskIsDisabled() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectByTaskKey("comprehensive-case-training")).thenReturn(comprehensive);
|
|
|
|
|
TrainingTaskClassConfig disabled = overrideTask("config-1", "class-1", "comprehensive-case-training");
|
|
|
|
|
disabled.setEnabled(Boolean.FALSE);
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectByTeachingClassAndTaskKey("class-1", "comprehensive-case-training"))
|
|
|
|
|
.thenReturn(disabled);
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("comprehensive-case-training", (byte) 0)));
|
|
|
|
|
|
|
|
|
|
TrainingTask result = service.getStudentTaskByTaskKey("comprehensive-case-training", "stu-1");
|
|
|
|
|
|
|
|
|
|
assertNull(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentListReturnsComprehensiveTrainingWhenPublishedAndEnabledForTheClass() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask legacy = storedTask("task-1", "new-product-survey");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(legacy, comprehensive));
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null))
|
|
|
|
|
.thenReturn(List.of(overrideTask("config-1", "class-1", "new-product-survey"),
|
|
|
|
|
overrideTask("config-2", "class-1", "comprehensive-case-training")));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("new-product-survey", (byte) 0),
|
|
|
|
|
taskAllocation("comprehensive-case-training", (byte) 0)));
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForStudent("stu-1", true);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("new-product-survey", "comprehensive-case-training"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentListHidesComprehensiveTrainingWhenThePublishedKeyIsRemoved() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask legacy = storedTask("task-1", "new-product-survey");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(legacy, comprehensive));
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null))
|
|
|
|
|
.thenReturn(List.of(overrideTask("config-1", "class-1", "new-product-survey"),
|
|
|
|
|
overrideTask("config-2", "class-1", "comprehensive-case-training")));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("new-product-survey", (byte) 0)));
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForStudent("stu-1", true);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("new-product-survey"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentListHidesComprehensiveTrainingWhenItsPublishedAllocationIsDisabled() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask legacy = storedTask("task-1", "new-product-survey");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(legacy, comprehensive));
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null))
|
|
|
|
|
.thenReturn(List.of(overrideTask("config-1", "class-1", "new-product-survey"),
|
|
|
|
|
overrideTask("config-2", "class-1", "comprehensive-case-training")));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("new-product-survey", (byte) 0),
|
|
|
|
|
taskAllocation("comprehensive-case-training", (byte) 1)));
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForStudent("stu-1", true);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("new-product-survey"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void studentListHidesDisabledComprehensiveTrainingWhenDisabledTasksAreRequested() {
|
|
|
|
|
TrainingTaskServiceImpl service = studentTaskService("class-1");
|
|
|
|
|
TrainingTask legacy = storedTask("task-1", "new-product-survey");
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(legacy, comprehensive));
|
|
|
|
|
TrainingTaskClassConfig disabled = overrideTask("config-2", "class-1", "comprehensive-case-training");
|
|
|
|
|
disabled.setEnabled(Boolean.FALSE);
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null))
|
|
|
|
|
.thenReturn(List.of(overrideTask("config-1", "class-1", "new-product-survey"), disabled));
|
|
|
|
|
when(service.taskAllocationMapper.selectByExample(any())).thenReturn(List.of(
|
|
|
|
|
taskAllocation(TaskAllocation.PUBLICATION_MARKER, (byte) 1),
|
|
|
|
|
taskAllocation("new-product-survey", (byte) 0),
|
|
|
|
|
taskAllocation("comprehensive-case-training", (byte) 0)));
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForStudent("stu-1", false);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("new-product-survey"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void teacherClassTaskListIncludesComprehensiveTrainingWithoutPublication() {
|
|
|
|
|
TrainingTaskServiceImpl service = new TrainingTaskServiceImpl();
|
|
|
|
|
service.trainingTaskMapper = mock(TrainingTaskMapper.class);
|
|
|
|
|
service.trainingTaskClassConfigMapper = mock(TrainingTaskClassConfigMapper.class);
|
|
|
|
|
service.schoolClassMapper = mock(SchoolClassMapper.class);
|
|
|
|
|
TrainingTask comprehensive = comprehensiveTrainingTask();
|
|
|
|
|
when(service.trainingTaskMapper.selectList(null, null, null)).thenReturn(List.of(comprehensive));
|
|
|
|
|
when(service.trainingTaskClassConfigMapper.selectListByTeachingClass("class-1", null)).thenReturn(Collections.emptyList());
|
|
|
|
|
SchoolClass schoolClass = teachingClass("class-1", "teacher-1");
|
|
|
|
|
schoolClass.setSchoolId("school-1");
|
|
|
|
|
when(service.schoolClassMapper.selectByPrimaryKey("class-1")).thenReturn(schoolClass);
|
|
|
|
|
JwtUser teacher = new JwtUser();
|
|
|
|
|
teacher.setUserId("teacher-1");
|
|
|
|
|
teacher.setSchoolId("school-1");
|
|
|
|
|
|
|
|
|
|
List<TrainingTask> result = service.listForTeachingClass("class-1", true, teacher);
|
|
|
|
|
|
|
|
|
|
assertEquals(List.of("comprehensive-case-training"), result.stream()
|
|
|
|
|
.map(TrainingTask::getTaskKey)
|
|
|
|
|
.collect(java.util.stream.Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TrainingTaskServiceImpl studentTaskService(String teachingClassId) {
|
|
|
|
|
TrainingTaskServiceImpl service = new TrainingTaskServiceImpl();
|
|
|
|
|
service.trainingTaskMapper = mock(TrainingTaskMapper.class);
|
|
|
|
|
service.trainingTaskClassConfigMapper = mock(TrainingTaskClassConfigMapper.class);
|
|
|
|
|
service.teachingClassStudentMapper = mock(TeachingClassStudentMapper.class);
|
|
|
|
|
service.taskAllocationMapper = mock(TaskAllocationMapper.class);
|
|
|
|
|
TeachingClassStudent membership = new TeachingClassStudent();
|
|
|
|
|
membership.setTeachingClassId(teachingClassId);
|
|
|
|
|
when(service.teachingClassStudentMapper.selectActiveByStudentUserId("stu-1")).thenReturn(membership);
|
|
|
|
|
return service;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TrainingTask comprehensiveTrainingTask() {
|
|
|
|
|
TrainingTask task = storedTask("task-comprehensive", "comprehensive-case-training");
|
|
|
|
|
task.setProjectName("综合实训");
|
|
|
|
|
task.setTaskName("综合案例实训");
|
|
|
|
|
task.setSort(1);
|
|
|
|
|
return task;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TaskAllocation taskAllocation(String module, byte disabledStatus) {
|
|
|
|
|
TaskAllocation allocation = new TaskAllocation();
|
|
|
|
|
allocation.setModule(module);
|
|
|
|
|
allocation.setDisabledStatus(disabledStatus);
|
|
|
|
|
return allocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TrainingTask storedTask(String id, String taskKey) {
|
|
|
|
|
TrainingTask task = new TrainingTask();
|
|
|
|
|
task.setId(id);
|
|
|
|
|
|