|
|
|
@ -621,7 +621,15 @@ public class UserController {
|
|
|
|
@ApiParam("教师名称") @RequestParam(required = false) String name,
|
|
|
|
@ApiParam("教师名称") @RequestParam(required = false) String name,
|
|
|
|
@ApiParam("教师工号") @RequestParam(required = false) String userName,
|
|
|
|
@ApiParam("教师工号") @RequestParam(required = false) String userName,
|
|
|
|
@RequestParam Integer index,
|
|
|
|
@RequestParam Integer index,
|
|
|
|
@RequestParam Integer size) {
|
|
|
|
@RequestParam Integer size,
|
|
|
|
|
|
|
|
@RequestParam(required = false) String operatorId) {
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(operatorId)) {
|
|
|
|
|
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
|
|
|
|
|
if (!isSchoolTeacher(operator)) {
|
|
|
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无权查询教师账号信息");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
schoolId = operator.getSchoolId();
|
|
|
|
|
|
|
|
}
|
|
|
|
PageHelper.startPage(index, size);
|
|
|
|
PageHelper.startPage(index, size);
|
|
|
|
UserinfoExample userInfoExample = new UserinfoExample();
|
|
|
|
UserinfoExample userInfoExample = new UserinfoExample();
|
|
|
|
UserinfoExample.Criteria criteria = userInfoExample.createCriteria();
|
|
|
|
UserinfoExample.Criteria criteria = userInfoExample.createCriteria();
|
|
|
|
@ -647,6 +655,7 @@ public class UserController {
|
|
|
|
userInfoList.get(i).setSchoolName(school.getSchoolName());
|
|
|
|
userInfoList.get(i).setSchoolName(school.getSchoolName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
markTeachersWithCreatedClasses(userInfoList);
|
|
|
|
PageInfo<Userinfo> pageInfo = new PageInfo<>(userInfoList);
|
|
|
|
PageInfo<Userinfo> pageInfo = new PageInfo<>(userInfoList);
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "查询教师账号信息成功!", pageInfo);
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "查询教师账号信息成功!", pageInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -657,7 +666,13 @@ public class UserController {
|
|
|
|
@AnonymousAccess
|
|
|
|
@AnonymousAccess
|
|
|
|
public ResultEntity updateTeacher(@RequestBody Userinfo userInfo, @RequestParam(required = false) String operatorId) {
|
|
|
|
public ResultEntity updateTeacher(@RequestBody Userinfo userInfo, @RequestParam(required = false) String operatorId) {
|
|
|
|
Userinfo existing = userinfoMapper.selectByPrimaryKey(userInfo.getUserId());
|
|
|
|
Userinfo existing = userinfoMapper.selectByPrimaryKey(userInfo.getUserId());
|
|
|
|
String schoolId = existing == null ? userInfo.getSchoolId() : existing.getSchoolId();
|
|
|
|
if (existing == null || !Integer.valueOf(3).equals(existing.getRole())) {
|
|
|
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "教师账号不存在");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (teacherHasCreatedClass(existing.getUserId())) {
|
|
|
|
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该教师已创建班级,不允许编辑或删除");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String schoolId = existing.getSchoolId();
|
|
|
|
if (!canManageSchoolStructure(operatorId, schoolId)) {
|
|
|
|
if (!canManageSchoolStructure(operatorId, schoolId)) {
|
|
|
|
return noManagePermission();
|
|
|
|
return noManagePermission();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -707,7 +722,7 @@ public class UserController {
|
|
|
|
return noManagePermission();
|
|
|
|
return noManagePermission();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (teacherHasCreatedClass(userId)) {
|
|
|
|
if (teacherHasCreatedClass(userId)) {
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该教师已创建班级,不能删除");
|
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该教师已创建班级,不允许编辑或删除");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int i = userinfoMapper.deleteByPrimaryKey(userId);
|
|
|
|
int i = userinfoMapper.deleteByPrimaryKey(userId);
|
|
|
|
if (i == 1) {
|
|
|
|
if (i == 1) {
|
|
|
|
@ -2227,7 +2242,28 @@ public class UserController {
|
|
|
|
private boolean teacherHasCreatedClass(String teacherId) {
|
|
|
|
private boolean teacherHasCreatedClass(String teacherId) {
|
|
|
|
SchoolClassExample example = new SchoolClassExample();
|
|
|
|
SchoolClassExample example = new SchoolClassExample();
|
|
|
|
example.createCriteria().andCreatedByEqualTo(teacherId);
|
|
|
|
example.createCriteria().andCreatedByEqualTo(teacherId);
|
|
|
|
return !schoolClassMapper.selectByExample(example).isEmpty();
|
|
|
|
List<SchoolClass> classes = schoolClassMapper.selectByExample(example);
|
|
|
|
|
|
|
|
return classes != null && !classes.isEmpty();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void markTeachersWithCreatedClasses(List<Userinfo> teachers) {
|
|
|
|
|
|
|
|
if (teachers == null || teachers.isEmpty()) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> teacherIds = teachers.stream()
|
|
|
|
|
|
|
|
.map(Userinfo::getUserId)
|
|
|
|
|
|
|
|
.filter(StringUtils::isNotBlank)
|
|
|
|
|
|
|
|
.collect(java.util.stream.Collectors.toList());
|
|
|
|
|
|
|
|
if (teacherIds.isEmpty()) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SchoolClassExample example = new SchoolClassExample();
|
|
|
|
|
|
|
|
example.createCriteria().andCreatedByIn(teacherIds);
|
|
|
|
|
|
|
|
Set<String> classOwnerIds = schoolClassMapper.selectByExample(example).stream()
|
|
|
|
|
|
|
|
.map(SchoolClass::getCreatedBy)
|
|
|
|
|
|
|
|
.filter(StringUtils::isNotBlank)
|
|
|
|
|
|
|
|
.collect(java.util.stream.Collectors.toSet());
|
|
|
|
|
|
|
|
teachers.forEach(teacher -> teacher.setHasCreatedClass(classOwnerIds.contains(teacher.getUserId())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean canOperateClass(String operatorId, String schoolClassId) {
|
|
|
|
private boolean canOperateClass(String operatorId, String schoolClassId) {
|
|
|
|
|