|
|
|
|
@ -1272,26 +1272,56 @@ public class UserController {
|
|
|
|
|
String teachingClassId,
|
|
|
|
|
String operatorId) {
|
|
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
|
|
|
|
if (!isSchoolTeacher(operator) || !isOwnedTeachingClass(teachingClass, operatorId)
|
|
|
|
|
|| !schoolProductConfigService.isTeacherRosterManaged(operator.getSchoolId())) {
|
|
|
|
|
if (!isSchoolTeacher(operator) || !schoolProductConfigService.isTeacherRosterManaged(operator.getSchoolId())) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无权维护该教学班名单");
|
|
|
|
|
}
|
|
|
|
|
if (rows == null || rows.isEmpty()) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "未读取到可导入的学生数据");
|
|
|
|
|
}
|
|
|
|
|
Map<String, SchoolClass> managedClassesByName = new HashMap<>();
|
|
|
|
|
if (StringUtils.isNotBlank(teachingClassId)) {
|
|
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
|
|
|
|
if (!canManageTeachingClass(operator, teachingClass)) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无权维护该教学班名单");
|
|
|
|
|
}
|
|
|
|
|
managedClassesByName.put(teachingClass.getClassName(), teachingClass);
|
|
|
|
|
} else {
|
|
|
|
|
SchoolClassExample example = new SchoolClassExample();
|
|
|
|
|
SchoolClassExample.Criteria criteria = example.createCriteria()
|
|
|
|
|
.andSchoolIdEqualTo(operator.getSchoolId())
|
|
|
|
|
.andClassTypeEqualTo("TEACHING");
|
|
|
|
|
if (!isTeacherAdmin(operator)) {
|
|
|
|
|
criteria.andCreatedByEqualTo(operator.getUserId());
|
|
|
|
|
}
|
|
|
|
|
List<SchoolClass> teachingClasses = schoolClassMapper.selectByExample(example);
|
|
|
|
|
for (SchoolClass teachingClass : teachingClasses == null ? Collections.<SchoolClass>emptyList() : teachingClasses) {
|
|
|
|
|
managedClassesByName.put(teachingClass.getClassName(), teachingClass);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<TeacherRosterImportRecord> importRecords = new ArrayList<>();
|
|
|
|
|
Set<String> usernames = new HashSet<>();
|
|
|
|
|
for (TeacherRosterStudentImportDTO row : rows) {
|
|
|
|
|
String name = row == null ? "" : StringUtils.trimToEmpty(row.getName());
|
|
|
|
|
String username = row == null ? "" : StringUtils.trimToEmpty(row.getUsername());
|
|
|
|
|
if (StringUtils.isBlank(name) || StringUtils.isBlank(username)) {
|
|
|
|
|
String className = row == null ? "" : StringUtils.trimToEmpty(row.getClassName());
|
|
|
|
|
if (StringUtils.isBlank(name) || StringUtils.isBlank(username) || (StringUtils.isBlank(teachingClassId) && StringUtils.isBlank(className))) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "学生姓名或学号无效");
|
|
|
|
|
}
|
|
|
|
|
SchoolClass targetClass = StringUtils.isNotBlank(teachingClassId)
|
|
|
|
|
? managedClassesByName.values().iterator().next()
|
|
|
|
|
: managedClassesByName.get(className);
|
|
|
|
|
if (targetClass == null) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级不存在或无管理权限:" + className);
|
|
|
|
|
}
|
|
|
|
|
if (!usernames.add(username)) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "导入文件中学号重复:" + username);
|
|
|
|
|
}
|
|
|
|
|
Userinfo existingStudent = userinfoMapper.selectBySchoolIdAndUsername(operator.getSchoolId(), username);
|
|
|
|
|
if (existingStudent != null) {
|
|
|
|
|
if (!Integer.valueOf(4).equals(existingStudent.getRole()) || !StringUtils.equals(existingStudent.getName(), name)) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "学号与已有学生信息冲突");
|
|
|
|
|
}
|
|
|
|
|
upsertActiveTeachingClassMember(teachingClassId, existingStudent, null, "TEACHER_ROSTER_IMPORT");
|
|
|
|
|
importRecords.add(new TeacherRosterImportRecord(targetClass.getSchoolClassId(), existingStudent, false));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (userInfoService.existsByUserName(username)) {
|
|
|
|
|
@ -1307,16 +1337,33 @@ public class UserController {
|
|
|
|
|
student.setSchoolId(operator.getSchoolId());
|
|
|
|
|
student.setCreateTime(new Date());
|
|
|
|
|
student.setCodeFrom("教师教学班导入");
|
|
|
|
|
if (userinfoMapper.insertSelective(student) <= 0) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "学生导入失败");
|
|
|
|
|
importRecords.add(new TeacherRosterImportRecord(targetClass.getSchoolClassId(), student, true));
|
|
|
|
|
}
|
|
|
|
|
for (TeacherRosterImportRecord record : importRecords) {
|
|
|
|
|
Userinfo student = record.student;
|
|
|
|
|
if (record.needsInsert && userinfoMapper.insertSelective(student) <= 0) {
|
|
|
|
|
throw new IllegalStateException("学生导入失败");
|
|
|
|
|
}
|
|
|
|
|
upsertActiveTeachingClassMember(teachingClassId, student, null, "TEACHER_ROSTER_IMPORT");
|
|
|
|
|
upsertActiveTeachingClassMember(record.teachingClassId, student, null, "TEACHER_ROSTER_IMPORT");
|
|
|
|
|
}
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "导入成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class TeacherRosterImportRecord {
|
|
|
|
|
private final String teachingClassId;
|
|
|
|
|
private final Userinfo student;
|
|
|
|
|
private final boolean needsInsert;
|
|
|
|
|
|
|
|
|
|
private TeacherRosterImportRecord(String teachingClassId, Userinfo student, boolean needsInsert) {
|
|
|
|
|
this.teachingClassId = teachingClassId;
|
|
|
|
|
this.student = student;
|
|
|
|
|
this.needsInsert = needsInsert;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/teaching-classes/{teachingClassId}/students/import")
|
|
|
|
|
@ApiOperation("教师教学班-导入学生名单")
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public ResultEntity importTeacherRoster(@PathVariable String teachingClassId,
|
|
|
|
|
@RequestParam MultipartFile file,
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
@ -1336,6 +1383,27 @@ public class UserController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/teaching-classes/students/import")
|
|
|
|
|
@ApiOperation("教师教学班-按班级名称导入学生名单")
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public ResultEntity importTeacherRosterByClassName(@RequestParam MultipartFile file,
|
|
|
|
|
HttpServletRequest request) {
|
|
|
|
|
JwtUser user = TokenProvider.getJWTUser(request);
|
|
|
|
|
if (user == null || StringUtils.isBlank(user.getUserId())) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.UNAUTHORIZED, "请先登录");
|
|
|
|
|
}
|
|
|
|
|
if (file == null || file.isEmpty()) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请选择要导入的Excel文件");
|
|
|
|
|
}
|
|
|
|
|
try (InputStream inputStream = file.getInputStream()) {
|
|
|
|
|
List<TeacherRosterStudentImportDTO> rows = EasyExcel.read(inputStream)
|
|
|
|
|
.head(TeacherRosterStudentImportDTO.class).sheet().doReadSync();
|
|
|
|
|
return importTeacherRosterRows(rows, null, user.getUserId());
|
|
|
|
|
} catch (Exception exception) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败", exception.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResultEntity addSchoolClass(String schoolId,
|
|
|
|
|
String schoolFacultyId,
|
|
|
|
|
String schoolMajorId,
|
|
|
|
|
|