You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
457 lines
22 KiB
Java
457 lines
22 KiB
Java
|
4 months ago
|
package com.sztzjy.linkCommerce.controller.schooladmin;
|
||
|
|
|
||
|
|
import com.github.pagehelper.PageHelper;
|
||
|
|
import com.github.pagehelper.PageInfo;
|
||
|
|
import com.sztzjy.linkCommerce.config.security.JwtUser;
|
||
|
|
import com.sztzjy.linkCommerce.config.security.TokenProvider;
|
||
|
|
import com.sztzjy.linkCommerce.entity.*;
|
||
|
|
import com.sztzjy.linkCommerce.entity.dto.SchoolClassDto;
|
||
|
|
import com.sztzjy.linkCommerce.entity.dto.SchoolFacultyDto;
|
||
|
|
import com.sztzjy.linkCommerce.entity.dto.SchoolMajorDto;
|
||
|
|
import com.sztzjy.linkCommerce.mapper.*;
|
||
|
|
import com.sztzjy.linkCommerce.service.SchoolAdminService;
|
||
|
|
import com.sztzjy.linkCommerce.service.SchoolService;
|
||
|
|
import com.sztzjy.linkCommerce.service.UserInfoService;
|
||
|
|
import com.sztzjy.linkCommerce.util.ResultEntity;
|
||
|
|
import io.swagger.annotations.Api;
|
||
|
|
import io.swagger.annotations.ApiOperation;
|
||
|
|
import org.apache.commons.lang3.StringUtils;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.http.HttpStatus;
|
||
|
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
|
||
|
|
import javax.servlet.http.HttpServletRequest;
|
||
|
|
import java.util.Date;
|
||
|
|
import java.util.UUID;
|
||
|
|
|
||
|
|
@Api(tags = "学校管理员管理")
|
||
|
|
@RequestMapping("api/school-admin")
|
||
|
|
@RestController
|
||
|
|
public class SchoolAdminController {
|
||
|
|
@Autowired
|
||
|
|
private SchoolAdminService schoolAdminService;
|
||
|
|
@Autowired
|
||
|
|
private SchoolService schoolService;
|
||
|
|
@Autowired
|
||
|
|
private UserInfoService userInfoService;
|
||
|
|
@Autowired
|
||
|
|
private SchoolMapper schoolMapper;
|
||
|
|
@Autowired
|
||
|
|
private SchoolFacultyMapper schoolFacultyMapper;
|
||
|
|
@Autowired
|
||
|
|
private SchoolMajorMapper schoolMajorMapper;
|
||
|
|
@Autowired
|
||
|
|
private SchoolClassMapper schoolClassMapper;
|
||
|
|
@Autowired
|
||
|
|
private UserinfoMapper userinfoMapper;
|
||
|
|
@Autowired
|
||
|
|
private TaskAllocationMapper taskAllocationMapper;
|
||
|
|
|
||
|
|
@GetMapping("/school")
|
||
|
|
@ApiOperation("学校管理员-当前学校详情")
|
||
|
|
public ResultEntity<School> getSchool(HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
School school = schoolMapper.selectByPrimaryKey(schoolId);
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "查询成功", school);
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/school")
|
||
|
|
@ApiOperation("学校管理员-编辑当前学校")
|
||
|
|
public ResultEntity updateSchool(@RequestBody School school, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
school.setSchoolId(schoolId);
|
||
|
|
int count = schoolMapper.updateByPrimaryKeySelective(school);
|
||
|
|
return writeResult(count, "编辑成功", "编辑失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/faculties")
|
||
|
|
@ApiOperation("学校管理员-院系列表")
|
||
|
|
public ResultEntity<PageInfo<SchoolFacultyDto>> listFaculties(@RequestParam Integer index,
|
||
|
|
@RequestParam Integer size,
|
||
|
|
@RequestParam(required = false) String schoolFacultyName,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
PageInfo<SchoolFacultyDto> pageInfo = schoolService.seleteSchoolFaculty(index, size, schoolId, schoolFacultyName);
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "查询成功", pageInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/faculties")
|
||
|
|
@ApiOperation("学校管理员-新增院系")
|
||
|
|
public ResultEntity addFaculty(@RequestBody SchoolFaculty faculty, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
if (StringUtils.isBlank(faculty.getSchoolFacultyName())) {
|
||
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "院系名称不能为空");
|
||
|
|
}
|
||
|
|
faculty.setSchoolFacultyId(UUID.randomUUID().toString());
|
||
|
|
faculty.setSchoolId(schoolId);
|
||
|
|
faculty.setCreateTime(new Date());
|
||
|
|
int count = schoolFacultyMapper.insertSelective(faculty);
|
||
|
|
return writeResult(count, "新增成功", "新增失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/faculties/{id}")
|
||
|
|
@ApiOperation("学校管理员-编辑院系")
|
||
|
|
public ResultEntity updateFaculty(@PathVariable String id,
|
||
|
|
@RequestBody SchoolFaculty faculty,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
SchoolFaculty existing = requireFaculty(id, schoolId);
|
||
|
|
faculty.setSchoolFacultyId(existing.getSchoolFacultyId());
|
||
|
|
faculty.setSchoolId(schoolId);
|
||
|
|
int count = schoolFacultyMapper.updateByPrimaryKeySelective(faculty);
|
||
|
|
return writeResult(count, "编辑成功", "编辑失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@DeleteMapping("/faculties/{id}")
|
||
|
|
@ApiOperation("学校管理员-删除院系")
|
||
|
|
public ResultEntity deleteFaculty(@PathVariable String id, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
requireFaculty(id, schoolId);
|
||
|
|
if (hasMajorInFaculty(id) || hasUserByFaculty(id)) {
|
||
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "院系下存在专业或用户,不能删除");
|
||
|
|
}
|
||
|
|
int count = schoolFacultyMapper.deleteByPrimaryKey(id);
|
||
|
|
return writeResult(count, "删除成功", "删除失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/majors")
|
||
|
|
@ApiOperation("学校管理员-专业列表")
|
||
|
|
public ResultEntity<PageInfo<SchoolMajorDto>> listMajors(@RequestParam Integer index,
|
||
|
|
@RequestParam Integer size,
|
||
|
|
@RequestParam(required = false) String schoolMajorName,
|
||
|
|
@RequestParam(required = false) String schoolFacultyId,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
if (StringUtils.isNotBlank(schoolFacultyId)) {
|
||
|
|
requireFaculty(schoolFacultyId, schoolId);
|
||
|
|
}
|
||
|
|
PageInfo<SchoolMajorDto> pageInfo = schoolService.seleteSchoolMajor(index, size, schoolId, schoolMajorName, schoolFacultyId);
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "查询成功", pageInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/majors")
|
||
|
|
@ApiOperation("学校管理员-新增专业")
|
||
|
|
public ResultEntity addMajor(@RequestBody SchoolMajor major, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
if (StringUtils.isBlank(major.getSchoolMajorName())) {
|
||
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "专业名称不能为空");
|
||
|
|
}
|
||
|
|
requireFaculty(major.getSchoolFacultyId(), schoolId);
|
||
|
|
major.setSchoolMajorId(UUID.randomUUID().toString());
|
||
|
|
major.setCreateTime(new Date());
|
||
|
|
int count = schoolMajorMapper.insertSelective(major);
|
||
|
|
return writeResult(count, "新增成功", "新增失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/majors/{id}")
|
||
|
|
@ApiOperation("学校管理员-编辑专业")
|
||
|
|
public ResultEntity updateMajor(@PathVariable String id,
|
||
|
|
@RequestBody SchoolMajor major,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
requireMajor(id, schoolId);
|
||
|
|
if (StringUtils.isNotBlank(major.getSchoolFacultyId())) {
|
||
|
|
requireFaculty(major.getSchoolFacultyId(), schoolId);
|
||
|
|
}
|
||
|
|
major.setSchoolMajorId(id);
|
||
|
|
int count = schoolMajorMapper.updateByPrimaryKeySelective(major);
|
||
|
|
return writeResult(count, "编辑成功", "编辑失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@DeleteMapping("/majors/{id}")
|
||
|
|
@ApiOperation("学校管理员-删除专业")
|
||
|
|
public ResultEntity deleteMajor(@PathVariable String id, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
requireMajor(id, schoolId);
|
||
|
|
if (hasClassInMajor(id) || hasUserByMajor(id)) {
|
||
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "专业下存在班级或用户,不能删除");
|
||
|
|
}
|
||
|
|
int count = schoolMajorMapper.deleteByPrimaryKey(id);
|
||
|
|
return writeResult(count, "删除成功", "删除失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/classes")
|
||
|
|
@ApiOperation("学校管理员-班级列表")
|
||
|
|
public ResultEntity<PageInfo<SchoolClassDto>> listClasses(@RequestParam Integer index,
|
||
|
|
@RequestParam Integer size,
|
||
|
|
@RequestParam(required = false) String className,
|
||
|
|
@RequestParam(required = false) String classSn,
|
||
|
|
@RequestParam(required = false) String schoolMajorId,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
if (StringUtils.isNotBlank(schoolMajorId)) {
|
||
|
|
requireMajor(schoolMajorId, schoolId);
|
||
|
|
}
|
||
|
|
PageInfo<SchoolClassDto> pageInfo = schoolService.seleteSchoolClass(index, size, schoolId, className, classSn, schoolMajorId);
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "查询成功", pageInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/classes")
|
||
|
|
@ApiOperation("学校管理员-新增班级")
|
||
|
|
public ResultEntity addClass(@RequestBody SchoolClass schoolClass, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
if (StringUtils.isBlank(schoolClass.getClassName())) {
|
||
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级名称不能为空");
|
||
|
|
}
|
||
|
|
requireMajor(schoolClass.getSchoolMajorId(), schoolId);
|
||
|
|
schoolClass.setSchoolClassId(UUID.randomUUID().toString());
|
||
|
|
schoolClass.setSchoolId(schoolId);
|
||
|
|
schoolClass.setCreateTime(new Date());
|
||
|
|
int count = schoolClassMapper.insertSelective(schoolClass);
|
||
|
|
return writeResult(count, "新增成功", "新增失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/classes/{id}")
|
||
|
|
@ApiOperation("学校管理员-编辑班级")
|
||
|
|
public ResultEntity updateClass(@PathVariable String id,
|
||
|
|
@RequestBody SchoolClass schoolClass,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
requireClass(id, schoolId);
|
||
|
|
if (StringUtils.isNotBlank(schoolClass.getSchoolMajorId())) {
|
||
|
|
requireMajor(schoolClass.getSchoolMajorId(), schoolId);
|
||
|
|
}
|
||
|
|
schoolClass.setSchoolClassId(id);
|
||
|
|
schoolClass.setSchoolId(schoolId);
|
||
|
|
int count = schoolClassMapper.updateByPrimaryKeySelective(schoolClass);
|
||
|
|
return writeResult(count, "编辑成功", "编辑失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@DeleteMapping("/classes/{id}")
|
||
|
|
@ApiOperation("学校管理员-删除班级")
|
||
|
|
public ResultEntity deleteClass(@PathVariable String id, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
requireClass(id, schoolId);
|
||
|
|
if (hasStudentInClass(id) || hasTaskInClass(id, schoolId)) {
|
||
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "班级下存在学生或任务,不能删除");
|
||
|
|
}
|
||
|
|
int count = schoolClassMapper.deleteByPrimaryKey(id);
|
||
|
|
return writeResult(count, "删除成功", "删除失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/teachers")
|
||
|
|
@ApiOperation("学校管理员-教师列表")
|
||
|
|
public ResultEntity<PageInfo<Userinfo>> listTeachers(@RequestParam Integer index,
|
||
|
|
@RequestParam Integer size,
|
||
|
|
@RequestParam(required = false) String name,
|
||
|
|
@RequestParam(required = false) String username,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
PageInfo<Userinfo> pageInfo = listUsers(index, size, schoolId, 3, name, username, null);
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "查询成功", pageInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/teachers")
|
||
|
|
@ApiOperation("学校管理员-新增教师")
|
||
|
|
public ResultEntity addTeacher(@RequestBody Userinfo teacher, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
if (StringUtils.isBlank(teacher.getUsername()) || StringUtils.isBlank(teacher.getName())) {
|
||
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "教师姓名和工号不能为空");
|
||
|
|
}
|
||
|
|
if (userInfoService.existsByUserName(teacher.getUsername())) {
|
||
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "账号已存在");
|
||
|
|
}
|
||
|
|
teacher.setUserId(UUID.randomUUID().toString());
|
||
|
|
if (StringUtils.isBlank(teacher.getPassword())) {
|
||
|
|
teacher.setPassword("123qwe");
|
||
|
|
}
|
||
|
|
teacher.setCreateTime(new Date());
|
||
|
|
schoolAdminService.prepareTeacherForSave(teacher, schoolId);
|
||
|
|
int count = userinfoMapper.insertSelective(teacher);
|
||
|
|
return writeResult(count, "新增成功", "新增失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/teachers/{id}")
|
||
|
|
@ApiOperation("学校管理员-编辑教师")
|
||
|
|
public ResultEntity updateTeacher(@PathVariable String id,
|
||
|
|
@RequestBody Userinfo teacher,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
requireUser(id, schoolId, 3);
|
||
|
|
teacher.setUserId(id);
|
||
|
|
schoolAdminService.prepareTeacherForSave(teacher, schoolId);
|
||
|
|
int count = userinfoMapper.updateByPrimaryKeySelective(teacher);
|
||
|
|
return writeResult(count, "编辑成功", "编辑失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@DeleteMapping("/teachers/{id}")
|
||
|
|
@ApiOperation("学校管理员-删除教师")
|
||
|
|
public ResultEntity deleteTeacher(@PathVariable String id, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
requireUser(id, schoolId, 3);
|
||
|
|
int count = userinfoMapper.deleteByPrimaryKey(id);
|
||
|
|
return writeResult(count, "删除成功", "删除失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@GetMapping("/students")
|
||
|
|
@ApiOperation("学校管理员-学生列表")
|
||
|
|
public ResultEntity<PageInfo<Userinfo>> listStudents(@RequestParam Integer index,
|
||
|
|
@RequestParam Integer size,
|
||
|
|
@RequestParam(required = false) String name,
|
||
|
|
@RequestParam(required = false) String username,
|
||
|
|
@RequestParam(required = false) String schoolClassId,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
if (StringUtils.isNotBlank(schoolClassId)) {
|
||
|
|
requireClass(schoolClassId, schoolId);
|
||
|
|
}
|
||
|
|
PageInfo<Userinfo> pageInfo = listUsers(index, size, schoolId, 4, name, username, schoolClassId);
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, "查询成功", pageInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
@PostMapping("/students")
|
||
|
|
@ApiOperation("学校管理员-新增学生")
|
||
|
|
public ResultEntity addStudent(@RequestBody Userinfo student, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
if (StringUtils.isBlank(student.getUsername()) || StringUtils.isBlank(student.getName())) {
|
||
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "学生姓名和学号不能为空");
|
||
|
|
}
|
||
|
|
if (userInfoService.existsByUserName(student.getUsername())) {
|
||
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "账号已存在");
|
||
|
|
}
|
||
|
|
if (StringUtils.isNotBlank(student.getSchoolClassId())) {
|
||
|
|
requireClass(student.getSchoolClassId(), schoolId);
|
||
|
|
}
|
||
|
|
student.setUserId(UUID.randomUUID().toString());
|
||
|
|
if (StringUtils.isBlank(student.getPassword())) {
|
||
|
|
student.setPassword("123qwe");
|
||
|
|
}
|
||
|
|
student.setCreateTime(new Date());
|
||
|
|
schoolAdminService.prepareStudentForSave(student, schoolId);
|
||
|
|
int count = userinfoMapper.insertSelective(student);
|
||
|
|
return writeResult(count, "新增成功", "新增失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@PutMapping("/students/{id}")
|
||
|
|
@ApiOperation("学校管理员-编辑学生")
|
||
|
|
public ResultEntity updateStudent(@PathVariable String id,
|
||
|
|
@RequestBody Userinfo student,
|
||
|
|
HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
requireUser(id, schoolId, 4);
|
||
|
|
if (StringUtils.isNotBlank(student.getSchoolClassId())) {
|
||
|
|
requireClass(student.getSchoolClassId(), schoolId);
|
||
|
|
}
|
||
|
|
student.setUserId(id);
|
||
|
|
schoolAdminService.prepareStudentForSave(student, schoolId);
|
||
|
|
int count = userinfoMapper.updateByPrimaryKeySelective(student);
|
||
|
|
return writeResult(count, "编辑成功", "编辑失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
@DeleteMapping("/students/{id}")
|
||
|
|
@ApiOperation("学校管理员-删除学生")
|
||
|
|
public ResultEntity deleteStudent(@PathVariable String id, HttpServletRequest request) {
|
||
|
|
String schoolId = currentSchoolId(request);
|
||
|
|
requireUser(id, schoolId, 4);
|
||
|
|
int count = userinfoMapper.deleteByPrimaryKey(id);
|
||
|
|
return writeResult(count, "删除成功", "删除失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
private String currentSchoolId(HttpServletRequest request) {
|
||
|
|
JwtUser user = TokenProvider.getJWTUser(request);
|
||
|
|
return schoolAdminService.requireSchoolAdmin(user);
|
||
|
|
}
|
||
|
|
|
||
|
|
private ResultEntity writeResult(int count, String success, String fail) {
|
||
|
|
if (count > 0) {
|
||
|
|
return new ResultEntity<>(HttpStatus.OK, success);
|
||
|
|
}
|
||
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, fail);
|
||
|
|
}
|
||
|
|
|
||
|
|
private SchoolFaculty requireFaculty(String facultyId, String schoolId) {
|
||
|
|
if (StringUtils.isBlank(facultyId)) {
|
||
|
|
throw new IllegalArgumentException("院系ID不能为空");
|
||
|
|
}
|
||
|
|
SchoolFaculty faculty = schoolFacultyMapper.selectByPrimaryKey(facultyId);
|
||
|
|
if (faculty == null || !schoolId.equals(faculty.getSchoolId())) {
|
||
|
|
throw new IllegalArgumentException("院系不存在或无权限");
|
||
|
|
}
|
||
|
|
return faculty;
|
||
|
|
}
|
||
|
|
|
||
|
|
private SchoolMajor requireMajor(String majorId, String schoolId) {
|
||
|
|
if (StringUtils.isBlank(majorId)) {
|
||
|
|
throw new IllegalArgumentException("专业ID不能为空");
|
||
|
|
}
|
||
|
|
SchoolMajor major = schoolMajorMapper.selectByPrimaryKey(majorId);
|
||
|
|
if (major == null) {
|
||
|
|
throw new IllegalArgumentException("专业不存在");
|
||
|
|
}
|
||
|
|
requireFaculty(major.getSchoolFacultyId(), schoolId);
|
||
|
|
return major;
|
||
|
|
}
|
||
|
|
|
||
|
|
private SchoolClass requireClass(String classId, String schoolId) {
|
||
|
|
if (StringUtils.isBlank(classId)) {
|
||
|
|
throw new IllegalArgumentException("班级ID不能为空");
|
||
|
|
}
|
||
|
|
SchoolClass schoolClass = schoolClassMapper.selectByPrimaryKey(classId);
|
||
|
|
if (schoolClass == null || !schoolId.equals(schoolClass.getSchoolId())) {
|
||
|
|
throw new IllegalArgumentException("班级不存在或无权限");
|
||
|
|
}
|
||
|
|
return schoolClass;
|
||
|
|
}
|
||
|
|
|
||
|
|
private Userinfo requireUser(String userId, String schoolId, int role) {
|
||
|
|
Userinfo userinfo = userinfoMapper.selectByPrimaryKey(userId);
|
||
|
|
if (userinfo == null || !schoolId.equals(userinfo.getSchoolId()) || userinfo.getRole() == null || userinfo.getRole() != role) {
|
||
|
|
throw new IllegalArgumentException("用户不存在或无权限");
|
||
|
|
}
|
||
|
|
return userinfo;
|
||
|
|
}
|
||
|
|
|
||
|
|
private PageInfo<Userinfo> listUsers(Integer index, Integer size, String schoolId, int role, String name, String username, String classId) {
|
||
|
|
PageHelper.startPage(index, size);
|
||
|
|
UserinfoExample example = new UserinfoExample();
|
||
|
|
UserinfoExample.Criteria criteria = example.createCriteria();
|
||
|
|
criteria.andSchoolIdEqualTo(schoolId).andRoleEqualTo(role);
|
||
|
|
if (StringUtils.isNotBlank(name)) {
|
||
|
|
criteria.andNameLike("%" + name + "%");
|
||
|
|
}
|
||
|
|
if (StringUtils.isNotBlank(username)) {
|
||
|
|
criteria.andUsernameLike("%" + username + "%");
|
||
|
|
}
|
||
|
|
if (StringUtils.isNotBlank(classId)) {
|
||
|
|
criteria.andSchoolClassIdEqualTo(classId);
|
||
|
|
}
|
||
|
|
return new PageInfo<>(userinfoMapper.selectByExample(example));
|
||
|
|
}
|
||
|
|
|
||
|
|
private boolean hasMajorInFaculty(String facultyId) {
|
||
|
|
SchoolMajorExample example = new SchoolMajorExample();
|
||
|
|
example.createCriteria().andSchoolFacultyIdEqualTo(facultyId);
|
||
|
|
return schoolMajorMapper.countByExample(example) > 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
private boolean hasClassInMajor(String majorId) {
|
||
|
|
SchoolClassExample example = new SchoolClassExample();
|
||
|
|
example.createCriteria().andSchoolMajorIdEqualTo(majorId);
|
||
|
|
return schoolClassMapper.countByExample(example) > 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
private boolean hasStudentInClass(String classId) {
|
||
|
|
UserinfoExample example = new UserinfoExample();
|
||
|
|
example.createCriteria().andSchoolClassIdEqualTo(classId).andRoleEqualTo(4);
|
||
|
|
return userinfoMapper.countByExample(example) > 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
private boolean hasTaskInClass(String classId, String schoolId) {
|
||
|
|
TaskAllocationExample example = new TaskAllocationExample();
|
||
|
|
example.createCriteria().andClassIdEqualTo(classId).andSchoolIdEqualTo(schoolId);
|
||
|
|
return taskAllocationMapper.countByExample(example) > 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
private boolean hasUserByFaculty(String facultyId) {
|
||
|
|
UserinfoExample example = new UserinfoExample();
|
||
|
|
example.createCriteria().andSchoolFacultyIdEqualTo(facultyId);
|
||
|
|
return userinfoMapper.countByExample(example) > 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
private boolean hasUserByMajor(String majorId) {
|
||
|
|
UserinfoExample example = new UserinfoExample();
|
||
|
|
example.createCriteria().andSchoolMajorIdEqualTo(majorId);
|
||
|
|
return userinfoMapper.countByExample(example) > 0;
|
||
|
|
}
|
||
|
|
}
|