feat: import teacher teaching-class rosters
parent
1c7ae68ffd
commit
e4c5093466
@ -0,0 +1,27 @@
|
||||
package com.sztzjy.linkCommerce.entity.importDto;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
|
||||
public class TeacherRosterStudentImportDTO {
|
||||
@ExcelProperty("姓名")
|
||||
private String name;
|
||||
@ExcelProperty("学号")
|
||||
private String username;
|
||||
@ExcelProperty("性别")
|
||||
private String sex;
|
||||
@ExcelProperty("手机")
|
||||
private String phone;
|
||||
@ExcelProperty("邮箱")
|
||||
private String email;
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getUsername() { return username; }
|
||||
public void setUsername(String username) { this.username = username; }
|
||||
public String getSex() { return sex; }
|
||||
public void setSex(String sex) { this.sex = sex; }
|
||||
public String getPhone() { return phone; }
|
||||
public void setPhone(String phone) { this.phone = phone; }
|
||||
public String getEmail() { return email; }
|
||||
public void setEmail(String email) { this.email = email; }
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package com.sztzjy.linkCommerce.controller.stu;
|
||||
|
||||
import com.sztzjy.linkCommerce.entity.SchoolClass;
|
||||
import com.sztzjy.linkCommerce.entity.TeachingClassStudent;
|
||||
import com.sztzjy.linkCommerce.entity.Userinfo;
|
||||
import com.sztzjy.linkCommerce.entity.importDto.TeacherRosterStudentImportDTO;
|
||||
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper;
|
||||
import com.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper;
|
||||
import com.sztzjy.linkCommerce.mapper.UserinfoMapper;
|
||||
import com.sztzjy.linkCommerce.service.SchoolProductConfigService;
|
||||
import com.sztzjy.linkCommerce.service.UserInfoService;
|
||||
import com.sztzjy.linkCommerce.util.ResultEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class TeacherRosterImportTest {
|
||||
@Test
|
||||
void exposesTeacherRosterImportEndpoint() {
|
||||
assertTrue(Arrays.stream(UserController.class.getDeclaredMethods())
|
||||
.anyMatch(method -> method.isAnnotationPresent(PostMapping.class)
|
||||
&& Arrays.asList(method.getAnnotation(PostMapping.class).value())
|
||||
.contains("/teaching-classes/{teachingClassId}/students/import")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void teacherRosterImportCreatesStudentAndMembershipWithoutAdminClass() {
|
||||
UserController controller = new UserController();
|
||||
controller.userinfoMapper = mock(UserinfoMapper.class);
|
||||
controller.schoolClassMapper = mock(SchoolClassMapper.class);
|
||||
controller.teachingClassStudentMapper = mock(TeachingClassStudentMapper.class);
|
||||
controller.userInfoService = mock(UserInfoService.class);
|
||||
controller.schoolProductConfigService = mock(SchoolProductConfigService.class);
|
||||
|
||||
Userinfo teacher = new Userinfo();
|
||||
teacher.setUserId("teacher-1");
|
||||
teacher.setRole(3);
|
||||
teacher.setSchoolId("school-zj");
|
||||
SchoolClass teachingClass = new SchoolClass();
|
||||
teachingClass.setSchoolClassId("teach-1");
|
||||
teachingClass.setSchoolId("school-zj");
|
||||
teachingClass.setClassType("TEACHING");
|
||||
teachingClass.setCreatedBy("teacher-1");
|
||||
when(controller.userinfoMapper.selectByPrimaryKey("teacher-1")).thenReturn(teacher);
|
||||
when(controller.schoolClassMapper.selectByPrimaryKey("teach-1")).thenReturn(teachingClass);
|
||||
when(controller.schoolProductConfigService.isTeacherRosterManaged("school-zj")).thenReturn(true);
|
||||
when(controller.userInfoService.existsByUserName("20260001")).thenReturn(false);
|
||||
when(controller.userinfoMapper.insertSelective(any(Userinfo.class))).thenReturn(1);
|
||||
|
||||
TeacherRosterStudentImportDTO row = new TeacherRosterStudentImportDTO();
|
||||
row.setName("张三");
|
||||
row.setUsername("20260001");
|
||||
ResultEntity result = controller.importTeacherRosterRows(Collections.singletonList(row), "teach-1", "teacher-1");
|
||||
|
||||
assertEquals(HttpStatus.OK, result.getStatusCode());
|
||||
ArgumentCaptor<TeachingClassStudent> membership = ArgumentCaptor.forClass(TeachingClassStudent.class);
|
||||
verify(controller.teachingClassStudentMapper).insertSelective(membership.capture());
|
||||
assertEquals("teach-1", membership.getValue().getTeachingClassId());
|
||||
assertEquals(null, membership.getValue().getAdminClassId());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue