|
|
|
|
@ -859,6 +859,86 @@ public class UserController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/teacher-roster/students")
|
|
|
|
|
@ApiOperation("教师维护名单模式-新增学生档案")
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
public ResultEntity addTeacherRosterStudent(@RequestParam String name,
|
|
|
|
|
@RequestParam String userName,
|
|
|
|
|
@RequestParam String teachingClassId,
|
|
|
|
|
@RequestParam String operatorId) {
|
|
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
|
|
if (!isSchoolTeacher(operator) || !isTeacherRosterMode(operator.getSchoolId())) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无权维护学生名单");
|
|
|
|
|
}
|
|
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
|
|
|
|
if (!isOwnedTeachingClass(teachingClass, operatorId)) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "只能选择自己创建的教学班");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isAnyBlank(StringUtils.trimToNull(name), StringUtils.trimToNull(userName))) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "学生姓名和学号不能为空");
|
|
|
|
|
}
|
|
|
|
|
String normalizedUserName = StringUtils.trim(userName);
|
|
|
|
|
if (userinfoMapper.selectBySchoolIdAndUsername(operator.getSchoolId(), normalizedUserName) != null
|
|
|
|
|
|| userInfoService.existsByUserName(normalizedUserName)) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "账号已存在");
|
|
|
|
|
}
|
|
|
|
|
Userinfo student = new Userinfo();
|
|
|
|
|
student.setUserId(UUID.randomUUID().toString());
|
|
|
|
|
student.setName(StringUtils.trim(name));
|
|
|
|
|
student.setUsername(normalizedUserName);
|
|
|
|
|
student.setPassword("123qwe");
|
|
|
|
|
student.setRole(4);
|
|
|
|
|
student.setTeacherAdmin(false);
|
|
|
|
|
student.setSchoolId(operator.getSchoolId());
|
|
|
|
|
student.setCreateTime(new Date());
|
|
|
|
|
student.setCodeFrom("教师名单添加");
|
|
|
|
|
if (userinfoMapper.insertSelective(student) <= 0) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "新增学生失败");
|
|
|
|
|
}
|
|
|
|
|
teachingClassStudentMapper.exitActiveByStudentUserIdExceptClass(student.getUserId(), teachingClassId);
|
|
|
|
|
upsertActiveTeachingClassMember(teachingClassId, student, null, "TEACHER_ROSTER_MANUAL");
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "新增学生成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/teacher-roster/students/{studentUserId}")
|
|
|
|
|
@ApiOperation("教师维护名单模式-编辑学生档案")
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
public ResultEntity updateTeacherRosterStudent(@PathVariable String studentUserId,
|
|
|
|
|
@RequestParam String name,
|
|
|
|
|
@RequestParam String userName,
|
|
|
|
|
@RequestParam String teachingClassId,
|
|
|
|
|
@RequestParam String operatorId) {
|
|
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
|
|
Userinfo existingStudent = userinfoMapper.selectByPrimaryKey(studentUserId);
|
|
|
|
|
if (!isSchoolTeacher(operator) || !isTeacherRosterMode(operator.getSchoolId())
|
|
|
|
|
|| existingStudent == null || !Integer.valueOf(4).equals(existingStudent.getRole())
|
|
|
|
|
|| !StringUtils.equals(operator.getSchoolId(), existingStudent.getSchoolId())) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无权维护该学生名单");
|
|
|
|
|
}
|
|
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
|
|
|
|
if (!isOwnedTeachingClass(teachingClass, operatorId)) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "只能选择自己创建的教学班");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isAnyBlank(StringUtils.trimToNull(name), StringUtils.trimToNull(userName))) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "学生姓名和学号不能为空");
|
|
|
|
|
}
|
|
|
|
|
String normalizedUserName = StringUtils.trim(userName);
|
|
|
|
|
if (!StringUtils.equals(normalizedUserName, existingStudent.getUsername())
|
|
|
|
|
&& userInfoService.existsByUserName(normalizedUserName)) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "账号已存在");
|
|
|
|
|
}
|
|
|
|
|
Userinfo update = new Userinfo();
|
|
|
|
|
update.setUserId(studentUserId);
|
|
|
|
|
update.setName(StringUtils.trim(name));
|
|
|
|
|
update.setUsername(normalizedUserName);
|
|
|
|
|
if (userinfoMapper.updateByPrimaryKeySelective(update) <= 0) {
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "编辑学生失败");
|
|
|
|
|
}
|
|
|
|
|
teachingClassStudentMapper.exitActiveByStudentUserIdExceptClass(studentUserId, teachingClassId);
|
|
|
|
|
upsertActiveTeachingClassMember(teachingClassId, existingStudent, null, "TEACHER_ROSTER_MANUAL");
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "编辑学生成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询
|
|
|
|
|
@PostMapping("/selectStudent")
|
|
|
|
|
@ApiOperation("学生管理-查询学生账号信息")
|
|
|
|
|
@ -905,9 +985,10 @@ public class UserController {
|
|
|
|
|
if (StringUtils.isNotBlank(schoolClassId)) {
|
|
|
|
|
userInfoList.get(i).setClassName(schoolClass.getClassName());
|
|
|
|
|
} else {
|
|
|
|
|
String schoolClassId1 = userInfoList.get(i).getSchoolClassId();
|
|
|
|
|
schoolClass = schoolClassMapper.selectByPrimaryKey(schoolClassId1);
|
|
|
|
|
userInfoList.get(i).setClassName(schoolClass.getClassName());
|
|
|
|
|
Userinfo student = userInfoList.get(i);
|
|
|
|
|
if (!populateTeacherRosterTeachingClass(student, schoolId)) {
|
|
|
|
|
student.setClassName(safeClassName(student.getSchoolClassId()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
String schoolId1 = userInfoList.get(i).getSchoolId();
|
|
|
|
|
@ -916,9 +997,10 @@ public class UserController {
|
|
|
|
|
if (StringUtils.isNotBlank(schoolClassId)) {
|
|
|
|
|
userInfoList.get(i).setClassName(schoolClass.getClassName());
|
|
|
|
|
} else {
|
|
|
|
|
String schoolClassId1 = userInfoList.get(i).getSchoolClassId();
|
|
|
|
|
schoolClass = schoolClassMapper.selectByPrimaryKey(schoolClassId1);
|
|
|
|
|
userInfoList.get(i).setClassName(schoolClass.getClassName());
|
|
|
|
|
Userinfo student = userInfoList.get(i);
|
|
|
|
|
if (!populateTeacherRosterTeachingClass(student, schoolId1)) {
|
|
|
|
|
student.setClassName(safeClassName(student.getSchoolClassId()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -1499,6 +1581,23 @@ public class UserController {
|
|
|
|
|
return schoolClass == null ? "" : schoolClass.getClassName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean populateTeacherRosterTeachingClass(Userinfo student, String schoolId) {
|
|
|
|
|
if (!isTeacherRosterMode(schoolId) || teachingClassStudentMapper == null || student == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
TeachingClassStudent membership = teachingClassStudentMapper.selectActiveByStudentUserId(student.getUserId());
|
|
|
|
|
if (membership == null || StringUtils.isBlank(membership.getTeachingClassId())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(membership.getTeachingClassId());
|
|
|
|
|
if (teachingClass == null || !"TEACHING".equals(teachingClass.getClassType())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
student.setTeachingClassId(teachingClass.getSchoolClassId());
|
|
|
|
|
student.setClassName(teachingClass.getClassName());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean hasMajorUnderFaculty(String schoolFacultyId) {
|
|
|
|
|
SchoolMajorExample example = new SchoolMajorExample();
|
|
|
|
|
example.createCriteria().andSchoolFacultyIdEqualTo(schoolFacultyId);
|
|
|
|
|
|