|
|
package com.sztzjy.linkCommerce.controller.stu;
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.sztzjy.linkCommerce.annotation.AnonymousAccess;
|
|
|
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.entity.importDto.SchoolAdminStudentImportDTO;
|
|
|
import com.sztzjy.linkCommerce.entity.importDto.StudentImportDTO;
|
|
|
import com.sztzjy.linkCommerce.entity.importDto.TeachingClassStudentImportDTO;
|
|
|
import com.sztzjy.linkCommerce.entity.importDto.TeacherRosterStudentImportDTO;
|
|
|
import com.sztzjy.linkCommerce.entity.importDto.TeacherImportDTO;
|
|
|
import com.sztzjy.linkCommerce.mapper.*;
|
|
|
import com.sztzjy.linkCommerce.service.ImportService;
|
|
|
import com.sztzjy.linkCommerce.service.SchoolService;
|
|
|
import com.sztzjy.linkCommerce.service.StudentTeachingClassResolver;
|
|
|
import com.sztzjy.linkCommerce.service.SchoolProductConfigService;
|
|
|
import com.sztzjy.linkCommerce.service.UserInfoService;
|
|
|
import com.sztzjy.linkCommerce.service.ValidateService;
|
|
|
import com.sztzjy.linkCommerce.util.*;
|
|
|
import com.sztzjy.linkCommerce.util.excel.FilePortUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
@Api(tags = "用户管理")
|
|
|
@RequestMapping("api/user")
|
|
|
@RestController
|
|
|
public class UserController {
|
|
|
@Autowired
|
|
|
SchoolService schoolService;
|
|
|
@Autowired
|
|
|
SchoolProductConfigService schoolProductConfigService;
|
|
|
@Autowired
|
|
|
SchoolMapper schoolMapper;
|
|
|
@Autowired
|
|
|
UserinfoMapper userinfoMapper;
|
|
|
@Autowired
|
|
|
SchoolMajorMapper schoolMajorMapper;
|
|
|
@Autowired
|
|
|
SchoolClassMapper schoolClassMapper;
|
|
|
@Autowired
|
|
|
TeachingClassStudentMapper teachingClassStudentMapper;
|
|
|
@Autowired
|
|
|
CptfController cptfController;
|
|
|
@Autowired
|
|
|
Pinyin4jUtil pinyin4jUtil;
|
|
|
@Autowired
|
|
|
UserInfoService userInfoService;
|
|
|
@Autowired
|
|
|
ValidateService validateService;
|
|
|
@Autowired
|
|
|
ImportService importService;
|
|
|
@Autowired(required = false)
|
|
|
StudentTeachingClassResolver studentTeachingClassResolver;
|
|
|
|
|
|
|
|
|
@PostMapping("/addSchool")
|
|
|
@ApiOperation("院校管理-院校新增")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity addSchool(@RequestBody School school) {
|
|
|
//参数校验
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(school.getSchoolName())) {
|
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "院校名称不能为空");
|
|
|
}
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(school.getSchoolGrade())) {
|
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "院校层次不能为空");
|
|
|
}
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(school.getSchoolProvince())) {
|
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "所属省不能为空");
|
|
|
}
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(school.getSchoolCity())) {
|
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "所属城市不能为空");
|
|
|
}
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(school.getSchoolContacts())) {
|
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "院校联系人不能为空");
|
|
|
}
|
|
|
Integer result = schoolService.addSchool(school);
|
|
|
if (result > 0) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "新增成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "新增失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@PostMapping("/updateSchool")
|
|
|
@ApiOperation("院校管理-院校编辑")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity updateSchool(@RequestBody School school) {
|
|
|
|
|
|
Integer result = schoolService.updateSchool(school);
|
|
|
if (result > 0) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "编辑成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "编辑失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@GetMapping("/deleteSchool")
|
|
|
@ApiOperation("院校管理-院校删除")
|
|
|
public ResultEntity deleteSchool(String schoolId) {
|
|
|
|
|
|
Integer result = schoolService.deleteSchool(schoolId);
|
|
|
if (result > 0) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "删除成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.ACCEPTED, "删除失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@GetMapping("/getSchoolList")
|
|
|
@ApiOperation("院校管理-院校列表查询")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<PageInfo<School>> getSchoolList(@ApiParam("当前页") Integer index,
|
|
|
@ApiParam("每页条数") Integer size,
|
|
|
@ApiParam("院校名称") @RequestParam(required = false) String schoolName) {
|
|
|
|
|
|
PageHelper.startPage(index, size);
|
|
|
SchoolExample schoolExample = new SchoolExample();
|
|
|
SchoolExample.Criteria criteria = schoolExample.createCriteria();
|
|
|
|
|
|
if (StringUtils.isNotEmpty(schoolName)) {
|
|
|
criteria.andSchoolNameLike("%" + schoolName + "%");
|
|
|
}
|
|
|
List<School> schools = schoolMapper.selectByExample(schoolExample);
|
|
|
PageInfo<School> schoolPageInfo = new PageInfo<>(schools);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "院校列表查询-查询成功", schoolPageInfo);
|
|
|
}
|
|
|
|
|
|
|
|
|
//*****************************************院系管理*********************************************
|
|
|
//*****************************************院系管理*********************************************
|
|
|
//*****************************************院系管理*********************************************
|
|
|
@Autowired
|
|
|
SchoolFacultyMapper schoolFacultyMapper;
|
|
|
|
|
|
@PostMapping("/addSchoolFaculty")
|
|
|
@ApiOperation("院系管理-添加院系")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity addSchoolFaculty(@ApiParam("学校ID") @RequestParam String schoolId,
|
|
|
@ApiParam("院系名称") @RequestParam String schoolFacultyName,
|
|
|
@ApiParam("联系人") @RequestParam(required = false) String schoolFacultyContact,
|
|
|
@ApiParam("联系人电话") @RequestParam(required = false) String schoolFacultyContactTel,
|
|
|
@ApiParam("联系人地址") @RequestParam(required = false) String schoolFacultyContactAddress,
|
|
|
@RequestParam(required = false) String userId) {
|
|
|
//先根据schoolId进行查询 如果不存在则返回
|
|
|
School school = schoolMapper.selectByPrimaryKey(schoolId);
|
|
|
if (school == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该学校不存在");
|
|
|
}
|
|
|
if (!canManageFaculty(userId, schoolId)) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
//查询该学校下院系下 专业名称是否重复
|
|
|
SchoolFacultyExample schoolFacultyExample = new SchoolFacultyExample();
|
|
|
schoolFacultyExample.createCriteria().andSchoolIdEqualTo(schoolId).andSchoolFacultyNameEqualTo(schoolFacultyName);
|
|
|
List<SchoolFaculty> schoolFaculties = schoolFacultyMapper.selectByExample(schoolFacultyExample);
|
|
|
if (!schoolFaculties.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "院系名称重复");
|
|
|
}
|
|
|
SchoolFaculty schoolFaculty = new SchoolFaculty();
|
|
|
schoolFaculty.setSchoolFacultyId(String.valueOf(UUID.randomUUID()));
|
|
|
schoolFaculty.setSchoolId(schoolId);
|
|
|
schoolFaculty.setSchoolFacultyName(schoolFacultyName);
|
|
|
schoolFaculty.setSchoolFacultyContact(schoolFacultyContact);
|
|
|
schoolFaculty.setSchoolFacultyContactTel(schoolFacultyContactTel);
|
|
|
schoolFaculty.setSchoolFacultyContactAddress(schoolFacultyContactAddress);
|
|
|
schoolFaculty.setCreateTime(new Date());
|
|
|
int insert = schoolFacultyMapper.insert(schoolFaculty);
|
|
|
if (insert == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "新增院系成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "新增院系失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@PostMapping("/seleteSchoolFaculty")
|
|
|
@ApiOperation("院系管理-查询")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<PageInfo<SchoolFacultyDto>> seleteSchoolFaculty(@ApiParam("当前页") @RequestParam Integer index,
|
|
|
@ApiParam("每页条数") @RequestParam Integer size,
|
|
|
@ApiParam("学校ID") @RequestParam(required = false) String schoolId,
|
|
|
@ApiParam("院系名称") @RequestParam(required = false) String schoolFacultyName) {
|
|
|
PageInfo<SchoolFacultyDto> pageInfo = schoolService.seleteSchoolFaculty(index, size, schoolId, schoolFacultyName);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "院系管理-查询成功", pageInfo);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/seleteSchoolFacultyList")
|
|
|
@ApiOperation("院系管理-院系列表查询")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<List<SchoolFaculty>> seleteSchoolFacultyList(@ApiParam("学校ID") @RequestParam String schoolId) {
|
|
|
SchoolFacultyExample schoolFacultyExample = new SchoolFacultyExample();
|
|
|
schoolFacultyExample.createCriteria().andSchoolIdEqualTo(schoolId);
|
|
|
List<SchoolFaculty> schoolFacultyList = schoolFacultyMapper.selectByExample(schoolFacultyExample);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "院系管理-院系列表查询查询", schoolFacultyList);
|
|
|
}
|
|
|
|
|
|
|
|
|
@PostMapping("/deleteSchoolFaculty")
|
|
|
@ApiOperation("院系管理-删除")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity deleteSchoolFaculty(@ApiParam("院系ID") @RequestParam String schoolFacultyId, @RequestParam String userId) {
|
|
|
SchoolFaculty schoolFaculty = schoolFacultyMapper.selectByPrimaryKey(schoolFacultyId);
|
|
|
if (schoolFaculty == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "院系不存在");
|
|
|
}
|
|
|
if (!canManageFaculty(userId, schoolFaculty.getSchoolId())) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
if (hasMajorUnderFaculty(schoolFacultyId)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "院系下存在专业,不能删除");
|
|
|
}
|
|
|
int i = schoolFacultyMapper.deleteByPrimaryKey(schoolFacultyId);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "院系管理-删除成功");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "院系管理-删除失败");
|
|
|
}
|
|
|
|
|
|
@PostMapping("/updateSchoolFaculty")
|
|
|
@ApiOperation("院系管理-编辑")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity updateSchoolFaculty(@RequestBody SchoolFaculty schoolFaculty, @RequestParam String userId) {
|
|
|
if (StringUtils.isBlank(schoolFaculty.getSchoolFacultyId())) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "院系管理-编辑失败-主键ID缺失");
|
|
|
}
|
|
|
SchoolFaculty existing = schoolFacultyMapper.selectByPrimaryKey(schoolFaculty.getSchoolFacultyId());
|
|
|
if (existing == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "院系不存在");
|
|
|
}
|
|
|
if (!canManageFaculty(userId, existing.getSchoolId())) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
int i = schoolFacultyMapper.updateByPrimaryKey(schoolFaculty);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "院系管理-编辑成功");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "院系管理-编辑失败");
|
|
|
}
|
|
|
|
|
|
//*****************************************专业管理*********************************************
|
|
|
//*****************************************专业管理*********************************************
|
|
|
//*****************************************专业管理*********************************************
|
|
|
|
|
|
@PostMapping("/addSchoolMajor")
|
|
|
@ApiOperation("专业管理-添加专业")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity addSchoolMajor(@ApiParam("学校ID") @RequestParam String schoolId,
|
|
|
@ApiParam("院系ID") @RequestParam String schoolFacultyId,
|
|
|
@ApiParam("专业名称") @RequestParam String schoolMajorName,
|
|
|
@ApiParam("联系人") @RequestParam(required = false) String schoolMajorContact,
|
|
|
@ApiParam("联系人电话") @RequestParam(required = false) String schoolMajorContactTel,
|
|
|
@RequestParam(required = false) String userId) {
|
|
|
//先根据schoolId进行查询 如果不存在则返回
|
|
|
School school = schoolMapper.selectByPrimaryKey(schoolId);
|
|
|
if (school == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该学校不存在");
|
|
|
}
|
|
|
if (!canManageMajorStructure(userId, schoolId)) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
//再根据schoolFacultyId查询 如果不存在则返回
|
|
|
SchoolFaculty schoolFaculty = schoolFacultyMapper.selectByPrimaryKey(schoolFacultyId);
|
|
|
if (schoolFaculty == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该院系不存在");
|
|
|
}
|
|
|
//查询该学校下院系下 专业名称是否重复
|
|
|
SchoolMajorExample schoolMajorExample = new SchoolMajorExample();
|
|
|
schoolMajorExample.createCriteria().andSchoolFacultyIdEqualTo(schoolFacultyId).andSchoolMajorNameEqualTo(schoolMajorName);
|
|
|
List<SchoolMajor> schoolMajors = schoolMajorMapper.selectByExample(schoolMajorExample);
|
|
|
if (!schoolMajors.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "专业名称重复");
|
|
|
}
|
|
|
SchoolMajor schoolMajor = new SchoolMajor();
|
|
|
schoolMajor.setSchoolMajorId(String.valueOf(UUID.randomUUID()));
|
|
|
schoolMajor.setSchoolFacultyId(schoolFacultyId);
|
|
|
schoolMajor.setSchoolMajorName(schoolMajorName);
|
|
|
schoolMajor.setSchoolMajorContact(schoolMajorContact);
|
|
|
schoolMajor.setSchoolMajorContactTel(schoolMajorContactTel);
|
|
|
schoolMajor.setCreateTime(new Date());
|
|
|
int insert = schoolMajorMapper.insert(schoolMajor);
|
|
|
if (insert == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "新增专业成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "新增专业失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@PostMapping("/selectSchoolMajor")
|
|
|
@ApiOperation("专业管理-查询")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<PageInfo<SchoolMajorDto>> selectSchoolMajor(@ApiParam("当前页") @RequestParam Integer index,
|
|
|
@ApiParam("每页条数") @RequestParam Integer size,
|
|
|
@ApiParam("学校ID") @RequestParam(required = false) String schoolId,
|
|
|
@ApiParam("院系ID-学校管理员使用") @RequestParam(required = false) String schoolFacultyId,
|
|
|
@ApiParam("专业名称") @RequestParam(required = false) String schoolMajorName) {
|
|
|
PageInfo<SchoolMajorDto> pageInfo = schoolService.seleteSchoolMajor(index, size, schoolId, schoolMajorName, schoolFacultyId);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "专业管理-查询成功", pageInfo);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/selectSchoolMajorList")
|
|
|
@ApiOperation("专业管理-列表查询")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<List<SchoolMajor>> selectSchoolMajorList(@ApiParam("院系ID") @RequestParam String schoolFacultyId) {
|
|
|
if (StringUtils.isBlank(schoolFacultyId)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "院系ID为null");
|
|
|
}
|
|
|
SchoolMajorExample schoolMajorExample = new SchoolMajorExample();
|
|
|
SchoolMajorExample.Criteria criteria = schoolMajorExample.createCriteria();
|
|
|
criteria.andSchoolFacultyIdEqualTo(schoolFacultyId);
|
|
|
List<SchoolMajor> schoolMajorList = schoolMajorMapper.selectByExample(schoolMajorExample);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "专业管理-查询成功", schoolMajorList);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/deleteSchoolMajor")
|
|
|
@ApiOperation("专业管理-删除")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity deleteSchoolMajor(@ApiParam("专业ID") @RequestParam String schoolMajorId, @RequestParam String userId) {
|
|
|
if (!canManageMajor(userId, schoolMajorId)) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
if (hasClassUnderMajor(schoolMajorId)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "专业下存在班级,不能删除");
|
|
|
}
|
|
|
int i = schoolMajorMapper.deleteByPrimaryKey(schoolMajorId);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "专业管理-删除成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "专业管理-删除失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@PostMapping("/updateSchoolMajor")
|
|
|
@ApiOperation("专业管理-编辑")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity updateSchoolMajor(@RequestBody SchoolMajor schoolMajor, @RequestParam(required = false) String userId) {
|
|
|
if (StringUtils.isBlank(schoolMajor.getSchoolMajorId())) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "专业管理-编辑失败-主键ID缺失");
|
|
|
}
|
|
|
if (!canManageMajor(userId, schoolMajor.getSchoolMajorId())) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
int i = schoolMajorMapper.updateByPrimaryKey(schoolMajor);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "专业管理-编辑成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "专业管理-编辑失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//*****************************************班级管理*********************************************
|
|
|
//*****************************************班级管理*********************************************
|
|
|
//*****************************************班级管理*********************************************
|
|
|
|
|
|
|
|
|
@PostMapping("/addSchoolClass")
|
|
|
@ApiOperation("班级管理-添加班级")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity addSchoolClass(@ApiParam("学校ID") @RequestParam String schoolId,
|
|
|
@ApiParam("院系ID") @RequestParam(required = false) String schoolFacultyId,
|
|
|
@ApiParam("专业ID") @RequestParam(required = false) String schoolMajorId,
|
|
|
@ApiParam("班级名称") @RequestParam String className,
|
|
|
@RequestParam(required = false) String userId,
|
|
|
@RequestParam(required = false) String classType,
|
|
|
@RequestParam(required = false) String sourceClassIds,
|
|
|
@RequestParam(required = false, defaultValue = "false") Boolean confirmMultiTeachingClass) {
|
|
|
//先根据schoolId进行查询 如果不存在则返回
|
|
|
School school = schoolMapper.selectByPrimaryKey(schoolId);
|
|
|
if (school == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该学校不存在");
|
|
|
}
|
|
|
String requestedClassType = StringUtils.defaultIfBlank(classType, StringUtils.isBlank(userId) ? "ADMIN" : "TEACHING");
|
|
|
boolean majorManagementEnabled = isMajorManagementEnabled(schoolId);
|
|
|
if (!isAdminClassManagementEnabled(schoolId) && !"TEACHING".equals(requestedClassType)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "当前学校只支持教学班");
|
|
|
}
|
|
|
if (majorManagementEnabled) {
|
|
|
SchoolFaculty schoolFaculty = schoolFacultyMapper.selectByPrimaryKey(schoolFacultyId);
|
|
|
if (schoolFaculty == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该院系不存在");
|
|
|
}
|
|
|
SchoolMajor schoolMajor = schoolMajorMapper.selectByPrimaryKey(schoolMajorId);
|
|
|
if (schoolMajor == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该专业不存在");
|
|
|
}
|
|
|
}
|
|
|
//查询班级名称是否存在
|
|
|
if (!canCreateSchoolClass(userId, schoolId, requestedClassType)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "No permission to add this class type");
|
|
|
}
|
|
|
SchoolClassExample schoolClassExample = new SchoolClassExample();
|
|
|
schoolClassExample.createCriteria().andSchoolIdEqualTo(schoolId).andClassNameEqualTo(className);
|
|
|
List<SchoolClass> schoolClasses = schoolClassMapper.selectByExample(schoolClassExample);
|
|
|
if (!schoolClasses.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级名称重复");
|
|
|
}
|
|
|
SchoolClass schoolClass = new SchoolClass();
|
|
|
schoolClass.setSchoolClassId(String.valueOf(UUID.randomUUID()));
|
|
|
schoolClass.setSchoolMajorId(schoolMajorId);
|
|
|
schoolClass.setClassName(className);
|
|
|
//设置classSn 先获取学校名称
|
|
|
String schoolName = school.getSchoolName();
|
|
|
String schoolNamePY = pinyin4jUtil.convertToPinyin(schoolName);
|
|
|
String classNamePY = pinyin4jUtil.convertToPinyin(className);
|
|
|
schoolClass.setClassSn(schoolNamePY + "_" + classNamePY);
|
|
|
schoolClass.setCreateTime(new Date());
|
|
|
schoolClass.setSchoolId(schoolId);
|
|
|
schoolClass.setCreatedBy(userId);
|
|
|
schoolClass.setClassType(requestedClassType);
|
|
|
schoolClass.setDataSource("LOCAL");
|
|
|
schoolClass.setSourceClassIds(sourceClassIds);
|
|
|
|
|
|
if ("TEACHING".equals(schoolClass.getClassType()) && !Boolean.TRUE.equals(confirmMultiTeachingClass)) {
|
|
|
ResultEntity conflict = buildMultiTeachingClassConflict(
|
|
|
findStudentsByAdminClassIds(parseSourceClassIds(sourceClassIds)), "");
|
|
|
if (conflict != null) {
|
|
|
return conflict;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int insert = schoolClassMapper.insert(schoolClass);
|
|
|
if (insert == 1) {
|
|
|
createTeachingClassMembersFromSourceClasses(schoolClass);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "新增班级成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "新增班级失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@PostMapping("/seleteSchoolClass")
|
|
|
@ApiOperation("班级管理-查询")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<PageInfo<SchoolClassDto>> seleteSchoolClass(@ApiParam("当前页") @RequestParam Integer index,
|
|
|
@ApiParam("每页条数") @RequestParam Integer size,
|
|
|
@ApiParam("学校ID") @RequestParam(required = false) String schoolId,
|
|
|
@ApiParam("专业ID-学校管理员使用") @RequestParam(required = false) String schoolMajorId,
|
|
|
@ApiParam("班级名称") @RequestParam(required = false) String className,
|
|
|
@ApiParam("班级编号") @RequestParam(required = false) String classSn,
|
|
|
@RequestParam(required = false) String operatorId) {
|
|
|
Userinfo operator = StringUtils.isBlank(operatorId) ? null : userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
if (isSchoolTeacher(operator) && isTeacherRosterMode(operator.getSchoolId())) {
|
|
|
PageInfo<SchoolClassDto> pageInfo = schoolService.seleteSchoolClass(index, size, operator.getSchoolId(),
|
|
|
className, classSn, null, operatorId, "TEACHING");
|
|
|
return new ResultEntity<>(HttpStatus.OK, "班级管理-查询成功", pageInfo);
|
|
|
}
|
|
|
PageInfo<SchoolClassDto> pageInfo = schoolService.seleteSchoolClass(index, size, schoolId, className, classSn, schoolMajorId);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "班级管理-查询成功", pageInfo);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/seleteSchoolFacultyNameAndMajorName")
|
|
|
@ApiOperation("班级管理-查询院系名称和专业名称")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<Map<String, String>> seleteSchoolFacultyNameAndMajorName(@RequestParam String schoolMajorId) {
|
|
|
SchoolMajor schoolMajor = schoolMajorMapper.selectByPrimaryKey(schoolMajorId);
|
|
|
String schoolFacultyId = schoolMajor.getSchoolFacultyId();
|
|
|
SchoolFaculty schoolFaculty = schoolFacultyMapper.selectByPrimaryKey(schoolFacultyId);
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put(schoolFaculty.getSchoolFacultyName(), schoolMajor.getSchoolMajorName());
|
|
|
return new ResultEntity<>(HttpStatus.OK, "班级管理-院系名称和专业名称查询成功", map);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/seleteSchoolClassList")
|
|
|
@ApiOperation("班级管理-列表查询")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<List<SchoolClass>> seleteSchoolClassList(@RequestParam String schoolMajorId) {
|
|
|
SchoolClassExample schoolClassExample = new SchoolClassExample();
|
|
|
SchoolClassExample.Criteria criteria = schoolClassExample.createCriteria();
|
|
|
criteria.andSchoolMajorIdEqualTo(schoolMajorId);
|
|
|
List<SchoolClass> schoolClasses = schoolClassMapper.selectByExample(schoolClassExample);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "班级管理-列表查询成功", schoolClasses);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/seleteSchoolClassListBySchoolId")
|
|
|
@ApiOperation("班级管理-列表查询通过学校ID")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<List<SchoolClass>> seleteSchoolClassListBySchoolId(@RequestParam String schoolId) {
|
|
|
SchoolClassExample schoolClassExample = new SchoolClassExample();
|
|
|
SchoolClassExample.Criteria criteria = schoolClassExample.createCriteria();
|
|
|
criteria.andSchoolIdEqualTo(schoolId);
|
|
|
List<SchoolClass> schoolClasses = schoolClassMapper.selectByExample(schoolClassExample);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "班级管理-列表查询通过学校ID查询成功", schoolClasses);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/deleteSchoolClass")
|
|
|
@ApiOperation("班级管理-删除")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity deleteSchoolClass(@ApiParam("班级ID") @RequestParam String schoolClassId, @RequestParam String userId) {
|
|
|
//先查询useriD 是否够权限
|
|
|
Userinfo userInfo = userinfoMapper.selectByPrimaryKey(userId);
|
|
|
if (userInfo == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级管理-删除失败-权限不足");
|
|
|
}
|
|
|
SchoolClass schoolClass = schoolClassMapper.selectByPrimaryKey(schoolClassId);
|
|
|
if (!canModifySchoolClass(userInfo, schoolClass)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级管理-删除失败-权限不足");
|
|
|
}
|
|
|
if (classHasStudents(schoolClass)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级下存在学生,不能删除");
|
|
|
}
|
|
|
int i = schoolClassMapper.deleteByPrimaryKey(schoolClassId);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "班级管理-删除成功");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级管理-删除失败");
|
|
|
}
|
|
|
|
|
|
|
|
|
@PostMapping("/updateSchoolClass")
|
|
|
@ApiOperation("班级管理-编辑")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity updateSchoolClass(@RequestBody SchoolClass schoolClass, @RequestParam String userId) {
|
|
|
if (StringUtils.isBlank(schoolClass.getSchoolClassId())) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级管理-编辑失败-主键ID缺失");
|
|
|
}
|
|
|
//先查询useriD 是否够权限
|
|
|
Userinfo userInfo = userinfoMapper.selectByPrimaryKey(userId);
|
|
|
if (userInfo == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级管理-编辑失败-权限不足");
|
|
|
}
|
|
|
SchoolClass existingClass = schoolClassMapper.selectByPrimaryKey(schoolClass.getSchoolClassId());
|
|
|
if (!canModifySchoolClass(userInfo, existingClass)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级管理-编辑失败-权限不足");
|
|
|
}
|
|
|
schoolClass.setCreatedBy(existingClass.getCreatedBy());
|
|
|
if (isClassOwner(existingClass, userId)) {
|
|
|
schoolClass.setCreatedBy(userId);
|
|
|
}
|
|
|
int i = schoolClassMapper.updateByPrimaryKeySelective(schoolClass);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "班级管理-编辑成功");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级管理-编辑失败");
|
|
|
}
|
|
|
|
|
|
//新增 同步子系统账户
|
|
|
@PostMapping("/addTeacherAccount")
|
|
|
@ApiOperation("教师管理-添加教师账号")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity addTeacherAccount(@ApiParam("学校ID") @RequestParam String schoolId,
|
|
|
@ApiParam("学校名称") @RequestParam String schoolName,
|
|
|
@ApiParam("院系ID") @RequestParam String schoolFacultyId,
|
|
|
@ApiParam("专业ID") @RequestParam String schoolMajorId,
|
|
|
@ApiParam("专业名称") @RequestParam String schoolMajorName,
|
|
|
@ApiParam("教师名称") @RequestParam String name,
|
|
|
@ApiParam("教师工号") @RequestParam String userName,
|
|
|
@ApiParam("电话号码") @RequestParam(required = false) String phone,
|
|
|
@ApiParam("电子邮箱") @RequestParam(required = false) String email,
|
|
|
@RequestParam(required = false) String operatorId) {
|
|
|
//先根据schoolId进行查询 如果不存在则返回
|
|
|
School school = schoolMapper.selectByPrimaryKey(schoolId);
|
|
|
if (school == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该学校不存在");
|
|
|
}
|
|
|
if (!canManageSchoolStructure(operatorId, schoolId)) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
//再根据schoolFacultyId查询 如果不存在则返回
|
|
|
SchoolFaculty schoolFaculty = schoolFacultyMapper.selectByPrimaryKey(schoolFacultyId);
|
|
|
if (schoolFaculty == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该院系不存在");
|
|
|
}
|
|
|
//再根据schoolMajorId查询 如果不存在则返回
|
|
|
SchoolMajor schoolMajor = schoolMajorMapper.selectByPrimaryKey(schoolMajorId);
|
|
|
if (schoolMajor == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该专业不存在");
|
|
|
}
|
|
|
//检查userName是否已经存在
|
|
|
boolean b = userInfoService.existsByUserName(userName);
|
|
|
if (b) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "账号已存在");
|
|
|
}
|
|
|
Userinfo userInfo = new Userinfo();
|
|
|
userInfo.setUserId(UUID.randomUUID().toString());
|
|
|
userInfo.setName(name);
|
|
|
userInfo.setUsername(userName);
|
|
|
userInfo.setPassword("123qwe");
|
|
|
userInfo.setPhone(phone);
|
|
|
userInfo.setEmail(email);
|
|
|
userInfo.setCreateTime(new Date());
|
|
|
userInfo.setRole(3);
|
|
|
userInfo.setSchoolId(schoolId);
|
|
|
userInfo.setSchoolFacultyId(schoolFacultyId);
|
|
|
userInfo.setSchoolMajorId(schoolMajorId);
|
|
|
userInfo.setSchoolClassId(null);
|
|
|
userInfo.setTeacherAdmin(false);
|
|
|
userInfo.setCodeFrom("添加");
|
|
|
|
|
|
int insert = userinfoMapper.insert(userInfo);
|
|
|
if (insert == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "教师管理-添加教师账号成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "教师管理-添加教师账号失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//分页条件查询
|
|
|
@PostMapping("/selectTeacher")
|
|
|
@ApiOperation("教师管理-查询教师账号信息")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<PageInfo<Userinfo>> selectTeacher(@ApiParam("学校ID") @RequestParam(required = false) String schoolId,
|
|
|
@ApiParam("教师名称") @RequestParam(required = false) String name,
|
|
|
@ApiParam("教师工号") @RequestParam(required = false) String userName,
|
|
|
@RequestParam Integer index,
|
|
|
@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);
|
|
|
UserinfoExample userInfoExample = new UserinfoExample();
|
|
|
UserinfoExample.Criteria criteria = userInfoExample.createCriteria();
|
|
|
School school = new School();
|
|
|
if (StringUtils.isNotBlank(schoolId)) {
|
|
|
school = schoolMapper.selectByPrimaryKey(schoolId);
|
|
|
criteria.andSchoolIdEqualTo(schoolId);
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(name)) {
|
|
|
criteria.andNameEqualTo(name);
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(userName)) {
|
|
|
criteria.andUsernameEqualTo(userName);
|
|
|
}
|
|
|
criteria.andRoleEqualTo(3);
|
|
|
List<Userinfo> userInfoList = userinfoMapper.selectByExample(userInfoExample);
|
|
|
for (int i = 0; i < userInfoList.size(); i++) {
|
|
|
if (StringUtils.isNotBlank(schoolId)) {
|
|
|
userInfoList.get(i).setSchoolName(school.getSchoolName());
|
|
|
} else {
|
|
|
String schoolId1 = userInfoList.get(i).getSchoolId();
|
|
|
school = schoolMapper.selectByPrimaryKey(schoolId1);
|
|
|
userInfoList.get(i).setSchoolName(school.getSchoolName());
|
|
|
}
|
|
|
}
|
|
|
markTeachersWithCreatedClasses(userInfoList);
|
|
|
PageInfo<Userinfo> pageInfo = new PageInfo<>(userInfoList);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "查询教师账号信息成功!", pageInfo);
|
|
|
}
|
|
|
|
|
|
//编辑
|
|
|
@PostMapping("/updateTeacher")
|
|
|
@ApiOperation("教师管理-编辑教师账号信息")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity updateTeacher(@RequestBody Userinfo userInfo, @RequestParam(required = false) String operatorId) {
|
|
|
Userinfo existing = userinfoMapper.selectByPrimaryKey(userInfo.getUserId());
|
|
|
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)) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
if (!isPlatformAdmin(operator)) {
|
|
|
userInfo.setTeacherAdmin(false);
|
|
|
}
|
|
|
int i = userinfoMapper.updateByPrimaryKey(userInfo);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "编辑教师账号信息成功!");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "编辑教师账号信息失败!");
|
|
|
}
|
|
|
|
|
|
//初始化密码
|
|
|
@PostMapping("/updateTeacherPassword")
|
|
|
@ApiOperation("教师管理-初始化密码")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity updateTeacher(@RequestParam String userId, @RequestParam(required = false) String operatorId) {
|
|
|
Userinfo userInfo = userinfoMapper.selectByPrimaryKey(userId);
|
|
|
if (userInfo == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "教师账号不存在");
|
|
|
}
|
|
|
if (!canManageSchoolStructure(operatorId, userInfo.getSchoolId())) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
userInfo.setPassword("123qwe");
|
|
|
int i = userinfoMapper.updateByPrimaryKey(userInfo);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "初始化密码成功!");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "初始化密码失败!");
|
|
|
}
|
|
|
|
|
|
//微信绑定 *****
|
|
|
|
|
|
//删除
|
|
|
@PostMapping("/deleteTeacher")
|
|
|
@ApiOperation("教师管理-删除")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity deleteTeacher(@RequestParam String userId, @RequestParam(required = false) String operatorId) {
|
|
|
Userinfo userInfo = userinfoMapper.selectByPrimaryKey(userId);
|
|
|
if (userInfo == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "教师账号不存在");
|
|
|
}
|
|
|
if (!canManageSchoolStructure(operatorId, userInfo.getSchoolId())) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
if (teacherHasCreatedClass(userId)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该教师已创建班级,不允许编辑或删除");
|
|
|
}
|
|
|
int i = userinfoMapper.deleteByPrimaryKey(userId);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "删除成功!");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "删除失败!");
|
|
|
}
|
|
|
|
|
|
//导入 同步子系统账户
|
|
|
@PostMapping("/uploadTeacherUserInfo")
|
|
|
@ApiOperation("教师管理-导入教师账号")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity uploadTeacherUserInfo(@RequestParam MultipartFile file,
|
|
|
@RequestParam(required = false) String operatorId) {
|
|
|
// 基本校验
|
|
|
if (file.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "上传文件不能为空!");
|
|
|
}
|
|
|
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
if (!originalFilename.endsWith(".xls") && !originalFilename.endsWith(".xlsx")) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请上传Excel文件!");
|
|
|
}
|
|
|
if (file.getSize() > 10 * 1024 * 1024) { // 10MB限制
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "文件大小不能超过10MB!");
|
|
|
}
|
|
|
|
|
|
try (InputStream inputStream = file.getInputStream()) {
|
|
|
// 解析Excel
|
|
|
List<TeacherImportDTO> teacherList = EasyExcel.read(inputStream)
|
|
|
.head(TeacherImportDTO.class)
|
|
|
.sheet()
|
|
|
.doReadSync();
|
|
|
|
|
|
// 数据校验
|
|
|
List<String> errorMessages = validateService.validateTeacherData(teacherList);
|
|
|
if (!errorMessages.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败!", errorMessages);
|
|
|
}
|
|
|
for (TeacherImportDTO teacher : teacherList) {
|
|
|
String schoolId = schoolService.selectSchoolIdBySchoolName(teacher.getSchoolName());
|
|
|
if (!canManageSchoolStructure(operatorId, schoolId)) {
|
|
|
return noManagePermission();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 异步处理导入*****
|
|
|
importService.processTeacherImport(teacherList);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "导入成功!");
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败!", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//导出
|
|
|
@PostMapping("/exportTeacherUserInfo")
|
|
|
@ApiOperation("教师管理-导出")
|
|
|
@AnonymousAccess
|
|
|
public void exportTeacherUserInfo(HttpServletResponse response,
|
|
|
@RequestParam String schoolId) {
|
|
|
if (StringUtils.isNotBlank(schoolId)) {
|
|
|
UserinfoExample userInfoExample = new UserinfoExample();
|
|
|
userInfoExample.createCriteria().andSchoolIdEqualTo(schoolId).andRoleEqualTo(3);
|
|
|
List<Userinfo> list = userinfoMapper.selectByExample(userInfoExample);
|
|
|
//导出的表名
|
|
|
String title = "老师账号汇总";
|
|
|
//表中第一行表头字段
|
|
|
String[] headers = {"姓名", "工号", "性别", "手机号", "邮箱"};
|
|
|
|
|
|
//具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型
|
|
|
List<String> listColumn = Arrays.asList("name", "username", "sex", "phone", "email");
|
|
|
try {
|
|
|
FilePortUtil.exportExcel(response, title, headers, list, listColumn);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//*****************************************学生管理*********************************************
|
|
|
//*****************************************学生管理*********************************************
|
|
|
//*****************************************学生管理*********************************************
|
|
|
//新增 *****创建资金账户
|
|
|
@PostMapping("/addStudentAccount")
|
|
|
@ApiOperation("学生管理-添加学生账号")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity addStudentAccount(@ApiParam("学校ID") @RequestParam String schoolId,
|
|
|
@ApiParam("学校名称") @RequestParam String schoolName,
|
|
|
@ApiParam("院系ID") @RequestParam String schoolFacultyId,
|
|
|
@ApiParam("专业ID") @RequestParam String schoolMajorId,
|
|
|
@ApiParam("专业名称") @RequestParam String schoolMajorName,
|
|
|
@ApiParam("班级名称") @RequestParam String schoolClassName,
|
|
|
@ApiParam("班级Id") @RequestParam String schoolClassId,
|
|
|
@ApiParam("学生姓名") @RequestParam String name,
|
|
|
@ApiParam("学号") @RequestParam String userName,
|
|
|
@ApiParam("电话号码") @RequestParam(required = false) String phone,
|
|
|
@ApiParam("电子邮箱") @RequestParam(required = false) String email,
|
|
|
@RequestParam(required = false) String userId) {
|
|
|
//先根据schoolId进行查询 如果不存在则返回
|
|
|
Userinfo operator = StringUtils.isBlank(userId) ? null : userinfoMapper.selectByPrimaryKey(userId);
|
|
|
String effectiveSchoolId = isSchoolTeacher(operator) ? operator.getSchoolId() : schoolId;
|
|
|
School school = schoolMapper.selectByPrimaryKey(effectiveSchoolId);
|
|
|
if (school == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该学校不存在");
|
|
|
}
|
|
|
//再根据schoolFacultyId查询 如果不存在则返回
|
|
|
SchoolFaculty schoolFaculty = schoolFacultyMapper.selectByPrimaryKey(schoolFacultyId);
|
|
|
if (schoolFaculty == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该院系不存在");
|
|
|
}
|
|
|
//再根据schoolMajorId查询 如果不存在则返回
|
|
|
SchoolMajor schoolMajor = schoolMajorMapper.selectByPrimaryKey(schoolMajorId);
|
|
|
if (schoolMajor == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该专业不存在");
|
|
|
}
|
|
|
SchoolClass schoolClass = schoolClassMapper.selectByPrimaryKey(schoolClassId);
|
|
|
if (schoolClass == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该班级不存在");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(userId) && !canOperateClass(userId, schoolClassId)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "只能维护自己创建班级的学生");
|
|
|
}
|
|
|
//检查userName是否已经存在
|
|
|
boolean b = userInfoService.existsByUserName(userName);
|
|
|
if (b) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "账号已存在");
|
|
|
}
|
|
|
Userinfo userInfo = new Userinfo();
|
|
|
userInfo.setUserId(UUID.randomUUID().toString());
|
|
|
userInfo.setName(name);
|
|
|
userInfo.setUsername(userName);
|
|
|
userInfo.setPassword("123qwe");
|
|
|
userInfo.setPhone(phone);
|
|
|
userInfo.setEmail(email);
|
|
|
userInfo.setCreateTime(new Date());
|
|
|
userInfo.setRole(4);
|
|
|
userInfo.setTeacherAdmin(false);
|
|
|
userInfo.setSchoolId(effectiveSchoolId);
|
|
|
userInfo.setSchoolFacultyId(schoolFacultyId);
|
|
|
userInfo.setSchoolMajorId(schoolMajorId);
|
|
|
String adminClassId = "TEACHING".equals(schoolClass.getClassType())
|
|
|
? resolveAdminClassIdForTeachingClass(schoolClass)
|
|
|
: schoolClassId;
|
|
|
userInfo.setSchoolClassId(adminClassId);
|
|
|
userInfo.setCodeFrom("添加");
|
|
|
|
|
|
int insert = userinfoMapper.insert(userInfo);
|
|
|
if (insert == 1) {
|
|
|
if ("TEACHING".equals(schoolClass.getClassType()) && teachingClassStudentMapper != null) {
|
|
|
upsertActiveTeachingClassMember(schoolClassId, userInfo, adminClassId, "MANUAL");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.OK, "学生管理-添加学生账号成功");
|
|
|
} else {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "学生管理-添加学生账号失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@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 (!canManageTeachingClass(operator, teachingClass)) {
|
|
|
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 (!canManageTeachingClass(operator, teachingClass)) {
|
|
|
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, "编辑学生成功");
|
|
|
}
|
|
|
|
|
|
//查询
|
|
|
ResultEntity<PageInfo<Userinfo>> selectStudent(String schoolId,
|
|
|
String schoolClassId,
|
|
|
String name,
|
|
|
String userName,
|
|
|
Integer index,
|
|
|
Integer size) {
|
|
|
return selectStudent(schoolId, schoolClassId, name, userName, index, size, null);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/selectStudent")
|
|
|
@ApiOperation("学生管理-查询学生账号信息")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<PageInfo<Userinfo>> selectStudent(@ApiParam("学校ID") @RequestParam(required = false) String schoolId,
|
|
|
@ApiParam("班级ID") @RequestParam(required = false) String schoolClassId,
|
|
|
@ApiParam("学生姓名") @RequestParam(required = false) String name,
|
|
|
@ApiParam("学生学号") @RequestParam(required = false) String userName,
|
|
|
@RequestParam Integer index,
|
|
|
@RequestParam Integer size,
|
|
|
@RequestParam(required = false) String operatorId) {
|
|
|
Userinfo operator = StringUtils.isBlank(operatorId) ? null : userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
boolean teacherRosterScope = isSchoolTeacher(operator) && isTeacherRosterMode(operator.getSchoolId());
|
|
|
if (teacherRosterScope) {
|
|
|
schoolId = operator.getSchoolId();
|
|
|
}
|
|
|
PageHelper.startPage(index, size);
|
|
|
UserinfoExample userInfoExample = new UserinfoExample();
|
|
|
UserinfoExample.Criteria criteria = userInfoExample.createCriteria();
|
|
|
School school = new School();
|
|
|
SchoolClass schoolClass = new SchoolClass();
|
|
|
if (StringUtils.isNotBlank(schoolId)) {
|
|
|
school = schoolMapper.selectByPrimaryKey(schoolId);
|
|
|
criteria.andSchoolIdEqualTo(schoolId);
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(name)) {
|
|
|
criteria.andNameEqualTo(name);
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(userName)) {
|
|
|
criteria.andUsernameEqualTo(userName);
|
|
|
}
|
|
|
if (teacherRosterScope) {
|
|
|
List<String> managedStudentIds = resolveManagedRosterStudentIds(operator, schoolClassId);
|
|
|
if (managedStudentIds == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无权查看该教学班内的学生");
|
|
|
}
|
|
|
criteria.andUserIdIn(managedStudentIds.isEmpty() ? Collections.singletonList("__empty__") : managedStudentIds);
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(schoolClassId)) {
|
|
|
schoolClass = schoolClassMapper.selectByPrimaryKey(schoolClassId);
|
|
|
if (schoolClass != null && "TEACHING".equals(schoolClass.getClassType()) && teachingClassStudentMapper != null) {
|
|
|
List<TeachingClassStudent> members = teachingClassStudentMapper.selectByTeachingClassId(schoolClassId);
|
|
|
List<String> studentIds = new ArrayList<>();
|
|
|
for (TeachingClassStudent member : members) {
|
|
|
studentIds.add(member.getStudentUserId());
|
|
|
}
|
|
|
criteria.andUserIdIn(studentIds.isEmpty() ? Collections.singletonList("__empty__") : studentIds);
|
|
|
} else {
|
|
|
criteria.andSchoolClassIdEqualTo(schoolClassId);
|
|
|
}
|
|
|
}
|
|
|
criteria.andRoleEqualTo(4);
|
|
|
List<Userinfo> userInfoList = userinfoMapper.selectByExample(userInfoExample);
|
|
|
for (int i = 0; i < userInfoList.size(); i++) {
|
|
|
if (StringUtils.isNotBlank(schoolId)) {
|
|
|
userInfoList.get(i).setSchoolName(school.getSchoolName());
|
|
|
if (StringUtils.isNotBlank(schoolClassId)) {
|
|
|
userInfoList.get(i).setClassName(schoolClass.getClassName());
|
|
|
} else {
|
|
|
Userinfo student = userInfoList.get(i);
|
|
|
if (!populateTeacherRosterTeachingClass(student, schoolId)) {
|
|
|
student.setClassName(safeClassName(student.getSchoolClassId()));
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
String schoolId1 = userInfoList.get(i).getSchoolId();
|
|
|
school = schoolMapper.selectByPrimaryKey(schoolId1);
|
|
|
userInfoList.get(i).setSchoolName(school.getSchoolName());
|
|
|
if (StringUtils.isNotBlank(schoolClassId)) {
|
|
|
userInfoList.get(i).setClassName(schoolClass.getClassName());
|
|
|
} else {
|
|
|
Userinfo student = userInfoList.get(i);
|
|
|
if (!populateTeacherRosterTeachingClass(student, schoolId1)) {
|
|
|
student.setClassName(safeClassName(student.getSchoolClassId()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
PageInfo<Userinfo> pageInfo = new PageInfo<>(userInfoList);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "查询学生账号信息成功!", pageInfo);
|
|
|
}
|
|
|
|
|
|
//编辑
|
|
|
private List<String> resolveManagedRosterStudentIds(Userinfo operator, String teachingClassId) {
|
|
|
if (!isSchoolTeacher(operator) || teachingClassStudentMapper == null) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
List<SchoolClass> teachingClasses;
|
|
|
if (StringUtils.isNotBlank(teachingClassId)) {
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
|
|
if (!canManageTeachingClass(operator, teachingClass)) {
|
|
|
return null;
|
|
|
}
|
|
|
teachingClasses = Collections.singletonList(teachingClass);
|
|
|
} else {
|
|
|
SchoolClassExample example = new SchoolClassExample();
|
|
|
SchoolClassExample.Criteria criteria = example.createCriteria()
|
|
|
.andSchoolIdEqualTo(operator.getSchoolId())
|
|
|
.andClassTypeEqualTo("TEACHING");
|
|
|
if (!isTeacherAdmin(operator)) {
|
|
|
criteria.andCreatedByEqualTo(operator.getUserId());
|
|
|
}
|
|
|
teachingClasses = schoolClassMapper.selectByExample(example);
|
|
|
}
|
|
|
Set<String> studentIds = new LinkedHashSet<>();
|
|
|
for (SchoolClass teachingClass : teachingClasses == null ? Collections.<SchoolClass>emptyList() : teachingClasses) {
|
|
|
List<TeachingClassStudent> members = teachingClassStudentMapper.selectByTeachingClassId(teachingClass.getSchoolClassId());
|
|
|
for (TeachingClassStudent member : members == null ? Collections.<TeachingClassStudent>emptyList() : members) {
|
|
|
if (member != null && StringUtils.isNotBlank(member.getStudentUserId())) {
|
|
|
studentIds.add(member.getStudentUserId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return new ArrayList<>(studentIds);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/updateStudent")
|
|
|
@ApiOperation("学生管理-编辑学生账号信息")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity updateStudent(@RequestBody Userinfo userInfo,
|
|
|
@RequestParam(required = false) String operatorId,
|
|
|
@RequestParam(required = false) String teachingClassId) {
|
|
|
String targetClassId = userInfo.getSchoolClassId();
|
|
|
if (StringUtils.isBlank(targetClassId) && StringUtils.isNotBlank(userInfo.getUserId())) {
|
|
|
Userinfo existing = userinfoMapper.selectByPrimaryKey(userInfo.getUserId());
|
|
|
targetClassId = existing == null ? null : existing.getSchoolClassId();
|
|
|
}
|
|
|
boolean canOperate = StringUtils.isNotBlank(teachingClassId)
|
|
|
? canOperateStudent(operatorId, userInfo.getUserId(), teachingClassId)
|
|
|
: canOperateClass(operatorId, targetClassId);
|
|
|
if (!canOperate) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "只能维护自己创建班级的学生");
|
|
|
}
|
|
|
userInfo.setRole(4);
|
|
|
userInfo.setTeacherAdmin(false);
|
|
|
int i = userinfoMapper.updateByPrimaryKey(userInfo);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "编辑学生账号信息成功!");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "编辑学生账号信息失败!");
|
|
|
}
|
|
|
|
|
|
//删除
|
|
|
@PostMapping("/deleteStudent")
|
|
|
@ApiOperation("学生管理-删除")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity deleteStudent(@RequestParam String userId,
|
|
|
@RequestParam(required = false) String operatorId,
|
|
|
@RequestParam(required = false) String teachingClassId) {
|
|
|
if (!canOperateStudent(operatorId, userId, teachingClassId)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "只能维护自己创建班级的学生");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(teachingClassId)) {
|
|
|
int removed = teachingClassStudentMapper.deleteByStudentUserIdAndTeachingClassId(userId, teachingClassId);
|
|
|
if (removed >= 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "删除成功!");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "删除失败!");
|
|
|
}
|
|
|
int i = userinfoMapper.deleteByPrimaryKey(userId);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "删除成功!");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "删除失败!");
|
|
|
}
|
|
|
|
|
|
//初始化密码
|
|
|
@PostMapping("/updateStudentPassword")
|
|
|
@ApiOperation("学生管理-初始化密码")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity updateStudentPassword(@RequestParam String userId,
|
|
|
@RequestParam(required = false) String operatorId,
|
|
|
@RequestParam(required = false) String teachingClassId) {
|
|
|
if (!canOperateStudent(operatorId, userId, teachingClassId)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "只能维护自己创建班级的学生");
|
|
|
}
|
|
|
Userinfo userInfo = userinfoMapper.selectByPrimaryKey(userId);
|
|
|
userInfo.setPassword("123qwe");
|
|
|
int i = userinfoMapper.updateByPrimaryKey(userInfo);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "初始化密码成功!");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "初始化密码失败!");
|
|
|
}
|
|
|
|
|
|
@PostMapping("/initializeTeachingClassTrainingData")
|
|
|
@ApiOperation("教学班-全班实训数据初始化")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity initializeTeachingClassTrainingData(@RequestParam String teachingClassId,
|
|
|
@RequestParam String operatorId) {
|
|
|
SchoolClass schoolClass = schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
if (!canManageTeachingClass(operator, schoolClass)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无权初始化该教学班");
|
|
|
}
|
|
|
List<TeachingClassStudent> members = teachingClassStudentMapper.selectByTeachingClassId(teachingClassId);
|
|
|
if (members == null) {
|
|
|
members = Collections.emptyList();
|
|
|
}
|
|
|
for (TeachingClassStudent member : members) {
|
|
|
if (member != null && StringUtils.isNotBlank(member.getStudentUserId())) {
|
|
|
cptfController.restartByUserId(member.getStudentUserId());
|
|
|
}
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.OK, "教学班实训数据初始化成功");
|
|
|
}
|
|
|
|
|
|
@PostMapping("/initializeTeachingClassStudentTrainingData")
|
|
|
@ApiOperation("教学班-单个学生实训数据初始化")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity initializeTeachingClassStudentTrainingData(@RequestParam String teachingClassId,
|
|
|
@RequestParam String studentUserId,
|
|
|
@RequestParam String operatorId) {
|
|
|
SchoolClass schoolClass = schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
if (!canManageTeachingClass(operator, schoolClass)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "无权初始化该教学班内的学生");
|
|
|
}
|
|
|
if (teachingClassStudentMapper != null
|
|
|
&& teachingClassStudentMapper.countByStudentUserIdAndTeachingClassId(studentUserId, teachingClassId) <= 0) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "学生不属于该教学班");
|
|
|
}
|
|
|
cptfController.restartByUserId(studentUserId);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "学生实训数据初始化成功");
|
|
|
}
|
|
|
|
|
|
@PostMapping("/uploadTeachingClassStudentMembers")
|
|
|
@ApiOperation("教学班-导入学生成员")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity uploadTeachingClassStudentMembers(@RequestParam MultipartFile file,
|
|
|
@RequestParam String teachingClassId,
|
|
|
@RequestParam String operatorId,
|
|
|
@RequestParam(required = false, defaultValue = "false") Boolean confirmMultiTeachingClass) {
|
|
|
if (file.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "上传文件不能为空!");
|
|
|
}
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
if (StringUtils.isBlank(originalFilename)
|
|
|
|| (!originalFilename.endsWith(".xls") && !originalFilename.endsWith(".xlsx"))) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请上传Excel文件!");
|
|
|
}
|
|
|
if (file.getSize() > 10 * 1024 * 1024) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "文件大小不能超过10MB!");
|
|
|
}
|
|
|
try (InputStream inputStream = file.getInputStream()) {
|
|
|
List<TeachingClassStudentImportDTO> rows = EasyExcel.read(inputStream)
|
|
|
.head(TeachingClassStudentImportDTO.class)
|
|
|
.sheet()
|
|
|
.doReadSync();
|
|
|
return importTeachingClassStudentRows(rows, teachingClassId, operatorId, confirmMultiTeachingClass);
|
|
|
} catch (Exception e) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败!", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@PostMapping("/importTeacherStudents")
|
|
|
@ApiOperation("教师端-批量导入学生账号")
|
|
|
@AnonymousAccess
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public ResultEntity importTeacherStudents(@RequestParam MultipartFile file,
|
|
|
@RequestParam String operatorId) {
|
|
|
ResultEntity fileError = validateTeacherStudentImportFile(file);
|
|
|
if (fileError != null) {
|
|
|
return fileError;
|
|
|
}
|
|
|
try (InputStream inputStream = file.getInputStream()) {
|
|
|
List<SchoolAdminStudentImportDTO> rows = EasyExcel.read(inputStream)
|
|
|
.head(SchoolAdminStudentImportDTO.class)
|
|
|
.sheet()
|
|
|
.doReadSync();
|
|
|
return importTeacherStudentRows(rows, operatorId);
|
|
|
} catch (Exception e) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败:", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ResultEntity importTeacherStudentRows(List<SchoolAdminStudentImportDTO> rows, String operatorId) {
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
if (!isSchoolTeacher(operator)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足");
|
|
|
}
|
|
|
List<String> errors = new ArrayList<>();
|
|
|
List<Userinfo> students = buildTeacherImportStudents(rows, operator, errors);
|
|
|
if (!errors.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败", errors);
|
|
|
}
|
|
|
if (students.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "未读取到可导入的学生数据");
|
|
|
}
|
|
|
for (Userinfo student : students) {
|
|
|
int inserted = userinfoMapper.insertSelective(student);
|
|
|
if (inserted <= 0) {
|
|
|
throw new IllegalStateException("导入失败");
|
|
|
}
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.OK, "导入成功,共 " + students.size() + " 条");
|
|
|
}
|
|
|
|
|
|
ResultEntity importTeacherRosterRows(List<TeacherRosterStudentImportDTO> rows,
|
|
|
String teachingClassId,
|
|
|
String operatorId) {
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
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());
|
|
|
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, "学号与已有学生信息冲突");
|
|
|
}
|
|
|
importRecords.add(new TeacherRosterImportRecord(targetClass.getSchoolClassId(), existingStudent, false));
|
|
|
continue;
|
|
|
}
|
|
|
if (userInfoService.existsByUserName(username)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "学号已被其他学校使用");
|
|
|
}
|
|
|
Userinfo student = new Userinfo();
|
|
|
student.setUserId(UUID.randomUUID().toString());
|
|
|
student.setName(name);
|
|
|
student.setUsername(username);
|
|
|
student.setPassword("123qwe");
|
|
|
student.setRole(4);
|
|
|
student.setTeacherAdmin(false);
|
|
|
student.setSchoolId(operator.getSchoolId());
|
|
|
student.setCreateTime(new Date());
|
|
|
student.setCodeFrom("教师教学班导入");
|
|
|
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(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) {
|
|
|
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, teachingClassId, user.getUserId());
|
|
|
} catch (Exception exception) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败", exception.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@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,
|
|
|
String className,
|
|
|
String userId,
|
|
|
String classType,
|
|
|
String sourceClassIds) {
|
|
|
return addSchoolClass(schoolId, schoolFacultyId, schoolMajorId, className,
|
|
|
userId, classType, sourceClassIds, false);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/uploadTeachingClassByStudentMembers")
|
|
|
@ApiOperation("教学班-导入名单创建教学班")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity uploadTeachingClassByStudentMembers(@RequestParam MultipartFile file,
|
|
|
@RequestParam String schoolId,
|
|
|
@RequestParam String schoolFacultyId,
|
|
|
@RequestParam String schoolMajorId,
|
|
|
@RequestParam String className,
|
|
|
@RequestParam String operatorId,
|
|
|
@RequestParam(required = false) String sourceClassIds,
|
|
|
@RequestParam(required = false, defaultValue = "false") Boolean confirmMultiTeachingClass) {
|
|
|
if (file.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "上传文件不能为空!");
|
|
|
}
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
if (StringUtils.isBlank(originalFilename)
|
|
|
|| (!originalFilename.endsWith(".xls") && !originalFilename.endsWith(".xlsx"))) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请上传Excel文件!");
|
|
|
}
|
|
|
if (file.getSize() > 10 * 1024 * 1024) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "文件大小不能超过10MB!");
|
|
|
}
|
|
|
try (InputStream inputStream = file.getInputStream()) {
|
|
|
List<TeachingClassStudentImportDTO> rows = EasyExcel.read(inputStream)
|
|
|
.head(TeachingClassStudentImportDTO.class)
|
|
|
.sheet()
|
|
|
.doReadSync();
|
|
|
return createTeachingClassByImportRows(rows, schoolId, schoolFacultyId, schoolMajorId, className, operatorId, sourceClassIds, confirmMultiTeachingClass);
|
|
|
} catch (Exception e) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败!", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ResultEntity importTeachingClassStudentRows(List<TeachingClassStudentImportDTO> rows,
|
|
|
String teachingClassId,
|
|
|
String operatorId) {
|
|
|
return importTeachingClassStudentRows(rows, teachingClassId, operatorId, false);
|
|
|
}
|
|
|
|
|
|
ResultEntity importTeachingClassStudentRows(List<TeachingClassStudentImportDTO> rows,
|
|
|
String teachingClassId,
|
|
|
String operatorId,
|
|
|
Boolean confirmMultiTeachingClass) {
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
|
|
if (!isOwnedTeachingClass(teachingClass, operatorId)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "只能导入自己创建教学班的学生");
|
|
|
}
|
|
|
List<String> sourceClassIds = parseSourceClassIds(teachingClass.getSourceClassIds());
|
|
|
SchoolMajor teachingMajor = schoolMajorMapper.selectByPrimaryKey(teachingClass.getSchoolMajorId());
|
|
|
String teachingFacultyId = teachingMajor == null ? null : teachingMajor.getSchoolFacultyId();
|
|
|
List<String> errors = sourceClassIds.isEmpty()
|
|
|
? validateTeachingClassImportRowsByMajor(rows, teachingClass.getSchoolId(), teachingFacultyId, teachingClass.getSchoolMajorId())
|
|
|
: validateTeachingClassStudentRows(rows, teachingClass, sourceClassIds);
|
|
|
if (!errors.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败!", errors);
|
|
|
}
|
|
|
List<Userinfo> studentsToAdd = new ArrayList<>();
|
|
|
for (TeachingClassStudentImportDTO row : rows) {
|
|
|
Userinfo student = sourceClassIds.isEmpty()
|
|
|
? findAdminClassStudent(row, teachingClass.getSchoolId(), teachingFacultyId, teachingClass.getSchoolMajorId())
|
|
|
: findAdminClassStudent(row, teachingClass, sourceClassIds);
|
|
|
if (student == null) {
|
|
|
continue;
|
|
|
}
|
|
|
studentsToAdd.add(student);
|
|
|
}
|
|
|
for (Userinfo student : studentsToAdd) {
|
|
|
upsertActiveTeachingClassMember(teachingClassId, student, student.getSchoolClassId(), "IMPORT");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.OK, "导入成功!");
|
|
|
}
|
|
|
|
|
|
ResultEntity createTeachingClassByImportRows(List<TeachingClassStudentImportDTO> rows,
|
|
|
String schoolId,
|
|
|
String schoolFacultyId,
|
|
|
String schoolMajorId,
|
|
|
String className,
|
|
|
String operatorId) {
|
|
|
return createTeachingClassByImportRows(rows, schoolId, schoolFacultyId, schoolMajorId, className, operatorId, false);
|
|
|
}
|
|
|
|
|
|
ResultEntity createTeachingClassByImportRows(List<TeachingClassStudentImportDTO> rows,
|
|
|
String schoolId,
|
|
|
String schoolFacultyId,
|
|
|
String schoolMajorId,
|
|
|
String className,
|
|
|
String operatorId,
|
|
|
Boolean confirmMultiTeachingClass) {
|
|
|
return createTeachingClassByImportRows(rows, schoolId, schoolFacultyId, schoolMajorId, className, operatorId, null, confirmMultiTeachingClass);
|
|
|
}
|
|
|
|
|
|
ResultEntity createTeachingClassByImportRows(List<TeachingClassStudentImportDTO> rows,
|
|
|
String schoolId,
|
|
|
String schoolFacultyId,
|
|
|
String schoolMajorId,
|
|
|
String className,
|
|
|
String operatorId,
|
|
|
String selectedSourceClassIds,
|
|
|
Boolean confirmMultiTeachingClass) {
|
|
|
School school = schoolMapper.selectByPrimaryKey(schoolId);
|
|
|
if (school == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该学校不存在");
|
|
|
}
|
|
|
SchoolFaculty schoolFaculty = schoolFacultyMapper.selectByPrimaryKey(schoolFacultyId);
|
|
|
if (schoolFaculty == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该院系不存在");
|
|
|
}
|
|
|
SchoolMajor schoolMajor = schoolMajorMapper.selectByPrimaryKey(schoolMajorId);
|
|
|
if (schoolMajor == null) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该专业不存在");
|
|
|
}
|
|
|
if (StringUtils.isBlank(className)) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级名称不能为空");
|
|
|
}
|
|
|
SchoolClassExample duplicateExample = new SchoolClassExample();
|
|
|
duplicateExample.createCriteria().andSchoolIdEqualTo(schoolId).andClassNameEqualTo(className);
|
|
|
if (!schoolClassMapper.selectByExample(duplicateExample).isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "班级名称重复");
|
|
|
}
|
|
|
List<String> selectedSourceClassIdList = parseSourceClassIds(selectedSourceClassIds);
|
|
|
List<String> errors = selectedSourceClassIdList.isEmpty()
|
|
|
? validateTeachingClassImportRowsByMajor(rows, schoolId, schoolFacultyId, schoolMajorId)
|
|
|
: validateTeachingClassImportRowsBySourceClasses(rows, schoolId, schoolFacultyId, schoolMajorId, selectedSourceClassIdList);
|
|
|
if (!errors.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败!", errors);
|
|
|
}
|
|
|
|
|
|
List<Userinfo> importedStudents = new ArrayList<>();
|
|
|
LinkedHashSet<String> sourceClassIds = new LinkedHashSet<>();
|
|
|
SchoolClass importScope = new SchoolClass();
|
|
|
importScope.setSchoolId(schoolId);
|
|
|
for (TeachingClassStudentImportDTO row : rows) {
|
|
|
Userinfo student = selectedSourceClassIdList.isEmpty()
|
|
|
? findAdminClassStudent(row, schoolId, schoolFacultyId, schoolMajorId)
|
|
|
: findAdminClassStudent(row, importScope, selectedSourceClassIdList);
|
|
|
if (student == null) {
|
|
|
continue;
|
|
|
}
|
|
|
importedStudents.add(student);
|
|
|
if (StringUtils.isNotBlank(student.getSchoolClassId())) {
|
|
|
sourceClassIds.add(student.getSchoolClassId());
|
|
|
}
|
|
|
}
|
|
|
if (!selectedSourceClassIdList.isEmpty()) {
|
|
|
sourceClassIds.clear();
|
|
|
sourceClassIds.addAll(selectedSourceClassIdList);
|
|
|
}
|
|
|
|
|
|
SchoolClass teachingClass = new SchoolClass();
|
|
|
teachingClass.setSchoolClassId(UUID.randomUUID().toString());
|
|
|
teachingClass.setSchoolId(schoolId);
|
|
|
teachingClass.setSchoolMajorId(schoolMajorId);
|
|
|
teachingClass.setClassName(className);
|
|
|
teachingClass.setClassSn(pinyin4jUtil.convertToPinyin(school.getSchoolName()) + "_" + pinyin4jUtil.convertToPinyin(className));
|
|
|
teachingClass.setCreateTime(new Date());
|
|
|
teachingClass.setCreatedBy(operatorId);
|
|
|
teachingClass.setClassType("TEACHING");
|
|
|
teachingClass.setDataSource("LOCAL");
|
|
|
teachingClass.setSourceClassIds(String.join(",", sourceClassIds));
|
|
|
int insert = schoolClassMapper.insert(teachingClass);
|
|
|
if (insert != 1) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "新增班级失败");
|
|
|
}
|
|
|
|
|
|
for (Userinfo student : importedStudents) {
|
|
|
upsertActiveTeachingClassMember(teachingClass.getSchoolClassId(), student, student.getSchoolClassId(), "IMPORT_CREATE");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.OK, "导入创建教学班成功");
|
|
|
}
|
|
|
|
|
|
//微信绑定*****
|
|
|
//导入 ***** 创建资金账户
|
|
|
@PostMapping("/uploadStudentUserInfo")
|
|
|
@ApiOperation("学生管理-导入学生账号")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity uploadStudentUserInfo(@RequestParam MultipartFile file) {
|
|
|
// 基本校验
|
|
|
if (file.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "上传文件不能为空!");
|
|
|
}
|
|
|
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
if (!originalFilename.endsWith(".xls") && !originalFilename.endsWith(".xlsx")) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请上传Excel文件!");
|
|
|
}
|
|
|
if (file.getSize() > 10 * 1024 * 1024) { // 10MB限制
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "文件大小不能超过10MB!");
|
|
|
}
|
|
|
|
|
|
try (InputStream inputStream = file.getInputStream()) {
|
|
|
// 解析Excel
|
|
|
List<StudentImportDTO> studentList = EasyExcel.read(inputStream)
|
|
|
.head(StudentImportDTO.class)
|
|
|
.sheet()
|
|
|
.doReadSync();
|
|
|
|
|
|
// 数据校验
|
|
|
List<String> errorMessages = validateService.validateStudentData(studentList);
|
|
|
if (!errorMessages.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败!", errorMessages);
|
|
|
}
|
|
|
|
|
|
// 异步处理导入*****
|
|
|
importService.processStudentImport(studentList);
|
|
|
return new ResultEntity<>(HttpStatus.OK, "导入成功!");
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "数据校验失败!", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//导出
|
|
|
@PostMapping("/exportStudentUserInfo")
|
|
|
@ApiOperation("学生管理-导出")
|
|
|
@AnonymousAccess
|
|
|
public void exportStudentUserInfo(HttpServletResponse response,
|
|
|
@RequestParam String schoolId,
|
|
|
@RequestParam(required = false) String operatorId,
|
|
|
@RequestParam(required = false) String schoolClassId) {
|
|
|
Userinfo operator = StringUtils.isBlank(operatorId) ? null : userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
boolean teacherRosterScope = isSchoolTeacher(operator) && isTeacherRosterMode(operator.getSchoolId());
|
|
|
if (teacherRosterScope) {
|
|
|
schoolId = operator.getSchoolId();
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(schoolId)) {
|
|
|
UserinfoExample userInfoExample = new UserinfoExample();
|
|
|
userInfoExample.createCriteria().andSchoolIdEqualTo(schoolId).andRoleEqualTo(4);
|
|
|
if (teacherRosterScope) {
|
|
|
List<String> managedStudentIds = resolveManagedRosterStudentIds(operator, schoolClassId);
|
|
|
if (managedStudentIds == null) {
|
|
|
response.setStatus(HttpStatus.BAD_REQUEST.value());
|
|
|
return;
|
|
|
}
|
|
|
userInfoExample.getOredCriteria().get(0)
|
|
|
.andUserIdIn(managedStudentIds.isEmpty() ? Collections.singletonList("__empty__") : managedStudentIds);
|
|
|
}
|
|
|
List<Userinfo> list = userinfoMapper.selectByExample(userInfoExample);
|
|
|
//导出的表名
|
|
|
String title = "学生账号汇总";
|
|
|
//表中第一行表头字段
|
|
|
String[] headers = {"姓名", "学号", "性别", "手机号", "邮箱"};
|
|
|
|
|
|
//具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型
|
|
|
List<String> listColumn = Arrays.asList("name", "username", "sex", "phone", "email");
|
|
|
try {
|
|
|
FilePortUtil.exportExcel(response, title, headers, list, listColumn);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//修改密码
|
|
|
@PostMapping("/updatePassword")
|
|
|
@ApiOperation("个人中心-修改密码")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity updatePassword(@RequestParam String userId, @RequestParam String password) {
|
|
|
Userinfo userInfo = userinfoMapper.selectByPrimaryKey(userId);
|
|
|
userInfo.setPassword(password);
|
|
|
int i = userinfoMapper.updateByPrimaryKey(userInfo);
|
|
|
if (i == 1) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "修改密码成功!");
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "修改密码失败!");
|
|
|
}
|
|
|
|
|
|
@PostMapping("/selectPersonInfo")
|
|
|
@ApiOperation("个人中心-查看用户数据")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<Userinfo> selectPersonInfo(@RequestParam String userId) {
|
|
|
Userinfo userInfo = userinfoMapper.selectByPrimaryKey(userId);
|
|
|
String schoolId = userInfo.getSchoolId();
|
|
|
String schoolFacultyId = userInfo.getSchoolFacultyId();
|
|
|
String schoolMajorId = userInfo.getSchoolMajorId();
|
|
|
|
|
|
String schoolName = safeSchoolName(schoolId);
|
|
|
String schoolFacultyName = safeFacultyName(schoolFacultyId);
|
|
|
String schoolMajorName = safeMajorName(schoolMajorId);
|
|
|
|
|
|
userInfo.setSchoolId(schoolName);
|
|
|
userInfo.setSchoolName(schoolName);
|
|
|
userInfo.setSchoolFacultyId(schoolFacultyName);
|
|
|
userInfo.setSchoolMajorId(schoolMajorName);
|
|
|
if (Integer.valueOf(4).equals(userInfo.getRole())) { //查看学生信息
|
|
|
String schoolClassId = userInfo.getSchoolClassId();
|
|
|
String className = safeClassName(schoolClassId);
|
|
|
userInfo.setSchoolClassId(className);
|
|
|
userInfo.setClassName(className);
|
|
|
}
|
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "个人中心-查看用户数据成功!",userInfo);
|
|
|
}
|
|
|
|
|
|
private String safeSchoolName(String schoolId) {
|
|
|
if (StringUtils.isBlank(schoolId)) {
|
|
|
return "";
|
|
|
}
|
|
|
String schoolName = schoolMapper.selectSchoolNameById(schoolId);
|
|
|
return schoolName == null ? "" : schoolName;
|
|
|
}
|
|
|
|
|
|
private String safeFacultyName(String schoolFacultyId) {
|
|
|
if (StringUtils.isBlank(schoolFacultyId)) {
|
|
|
return "";
|
|
|
}
|
|
|
SchoolFaculty schoolFaculty = schoolFacultyMapper.selectByPrimaryKey(schoolFacultyId);
|
|
|
return schoolFaculty == null ? "" : schoolFaculty.getSchoolFacultyName();
|
|
|
}
|
|
|
|
|
|
private String safeMajorName(String schoolMajorId) {
|
|
|
if (StringUtils.isBlank(schoolMajorId)) {
|
|
|
return "";
|
|
|
}
|
|
|
SchoolMajor schoolMajor = schoolMajorMapper.selectByPrimaryKey(schoolMajorId);
|
|
|
return schoolMajor == null ? "" : schoolMajor.getSchoolMajorName();
|
|
|
}
|
|
|
|
|
|
private String safeClassName(String schoolClassId) {
|
|
|
if (StringUtils.isBlank(schoolClassId)) {
|
|
|
return "";
|
|
|
}
|
|
|
SchoolClass schoolClass = schoolClassMapper.selectByPrimaryKey(schoolClassId);
|
|
|
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);
|
|
|
return !schoolMajorMapper.selectByExample(example).isEmpty();
|
|
|
}
|
|
|
|
|
|
private boolean hasClassUnderMajor(String schoolMajorId) {
|
|
|
SchoolClassExample example = new SchoolClassExample();
|
|
|
example.createCriteria().andSchoolMajorIdEqualTo(schoolMajorId);
|
|
|
return !schoolClassMapper.selectByExample(example).isEmpty();
|
|
|
}
|
|
|
|
|
|
private boolean classHasStudents(SchoolClass schoolClass) {
|
|
|
if (schoolClass == null) {
|
|
|
return false;
|
|
|
}
|
|
|
if ("TEACHING".equals(schoolClass.getClassType()) && teachingClassStudentMapper != null) {
|
|
|
return teachingClassStudentMapper.countByTeachingClassId(schoolClass.getSchoolClassId()) > 0;
|
|
|
}
|
|
|
UserinfoExample example = new UserinfoExample();
|
|
|
example.createCriteria().andSchoolClassIdEqualTo(schoolClass.getSchoolClassId()).andRoleEqualTo(4);
|
|
|
return !userinfoMapper.selectByExample(example).isEmpty();
|
|
|
}
|
|
|
|
|
|
private String resolveAdminClassIdForTeachingClass(SchoolClass teachingClass) {
|
|
|
if (StringUtils.isBlank(teachingClass.getSourceClassIds())) {
|
|
|
return teachingClass.getSchoolClassId();
|
|
|
}
|
|
|
String sourceClassIds = teachingClass.getSourceClassIds()
|
|
|
.replace("[", "")
|
|
|
.replace("]", "")
|
|
|
.replace("\"", "");
|
|
|
String[] ids = sourceClassIds.split(",");
|
|
|
return StringUtils.trimToEmpty(ids[0]);
|
|
|
}
|
|
|
|
|
|
private boolean isOwnedTeachingClass(SchoolClass schoolClass, String operatorId) {
|
|
|
return schoolClass != null
|
|
|
&& "TEACHING".equals(schoolClass.getClassType())
|
|
|
&& isClassOwner(schoolClass, operatorId);
|
|
|
}
|
|
|
|
|
|
private boolean canManageTeachingClass(Userinfo operator, SchoolClass teachingClass) {
|
|
|
return isSchoolTeacher(operator)
|
|
|
&& teachingClass != null
|
|
|
&& "TEACHING".equals(teachingClass.getClassType())
|
|
|
&& StringUtils.equals(operator.getSchoolId(), teachingClass.getSchoolId())
|
|
|
&& (isTeacherAdmin(operator) || isClassOwner(teachingClass, operator.getUserId()));
|
|
|
}
|
|
|
|
|
|
private boolean isClassOwner(SchoolClass schoolClass, String userId) {
|
|
|
return schoolClass != null
|
|
|
&& StringUtils.isNotBlank(userId)
|
|
|
&& StringUtils.equals(schoolClass.getCreatedBy(), userId);
|
|
|
}
|
|
|
|
|
|
private boolean isAdminClass(SchoolClass schoolClass) {
|
|
|
return schoolClass != null
|
|
|
&& ("ADMIN".equals(schoolClass.getClassType())
|
|
|
|| (StringUtils.isBlank(schoolClass.getClassType()) && StringUtils.isBlank(schoolClass.getCreatedBy())));
|
|
|
}
|
|
|
|
|
|
private void upsertActiveTeachingClassMember(String teachingClassId,
|
|
|
Userinfo student,
|
|
|
String adminClassId,
|
|
|
String joinReason) {
|
|
|
if (teachingClassStudentMapper == null
|
|
|
|| StringUtils.isBlank(teachingClassId)
|
|
|
|| student == null
|
|
|
|| StringUtils.isBlank(student.getUserId())) {
|
|
|
return;
|
|
|
}
|
|
|
TeachingClassStudent existing = teachingClassStudentMapper
|
|
|
.selectByStudentUserIdAndTeachingClassId(student.getUserId(), teachingClassId);
|
|
|
if (existing != null) {
|
|
|
teachingClassStudentMapper.updateMembershipToActive(
|
|
|
student.getUserId(),
|
|
|
teachingClassId,
|
|
|
adminClassId,
|
|
|
joinReason);
|
|
|
return;
|
|
|
}
|
|
|
TeachingClassStudent member = new TeachingClassStudent();
|
|
|
Date now = new Date();
|
|
|
member.setId(UUID.randomUUID().toString());
|
|
|
member.setTeachingClassId(teachingClassId);
|
|
|
member.setStudentUserId(student.getUserId());
|
|
|
member.setAdminClassId(adminClassId);
|
|
|
member.setStatus("IN_PROGRESS");
|
|
|
member.setJoinReason(joinReason);
|
|
|
member.setJoinTime(now);
|
|
|
member.setCreateTime(now);
|
|
|
teachingClassStudentMapper.insertSelective(member);
|
|
|
}
|
|
|
|
|
|
private boolean canModifySchoolClass(Userinfo operator, SchoolClass schoolClass) {
|
|
|
if (operator == null || schoolClass == null) {
|
|
|
return false;
|
|
|
}
|
|
|
if ("ZHIYUN".equals(schoolClass.getDataSource())) {
|
|
|
return false;
|
|
|
}
|
|
|
if (isPlatformAdmin(operator)) {
|
|
|
return true;
|
|
|
}
|
|
|
if (!Integer.valueOf(3).equals(operator.getRole())) {
|
|
|
return false;
|
|
|
}
|
|
|
if (isAdminClass(schoolClass)) {
|
|
|
return canManageAdminClass(operator, schoolClass);
|
|
|
}
|
|
|
return isClassOwner(schoolClass, operator.getUserId());
|
|
|
}
|
|
|
|
|
|
private ResultEntity buildMultiTeachingClassConflict(List<Userinfo> students, String targetTeachingClassId) {
|
|
|
if (students == null || students.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
List<String> conflicts = new ArrayList<>();
|
|
|
Set<String> studentIds = new HashSet<>();
|
|
|
for (Userinfo student : students) {
|
|
|
if (student == null || StringUtils.isBlank(student.getUserId()) || !studentIds.add(student.getUserId())) {
|
|
|
continue;
|
|
|
}
|
|
|
if (teachingClassStudentMapper.countByStudentUserIdExcludingTeachingClass(
|
|
|
student.getUserId(), StringUtils.trimToEmpty(targetTeachingClassId)) > 0) {
|
|
|
conflicts.add(formatStudentConflict(student));
|
|
|
}
|
|
|
}
|
|
|
if (conflicts.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
return new ResultEntity<>(HttpStatus.CONFLICT, "部分学生已在其他教学班,确认后可继续操作", conflicts);
|
|
|
}
|
|
|
|
|
|
private String formatStudentConflict(Userinfo student) {
|
|
|
String name = StringUtils.defaultIfBlank(student.getName(), "未命名学生");
|
|
|
String username = StringUtils.defaultIfBlank(student.getUsername(), "-");
|
|
|
return name + "(" + username + ")";
|
|
|
}
|
|
|
|
|
|
private List<Userinfo> findStudentsByAdminClassIds(List<String> sourceClassIds) {
|
|
|
if (sourceClassIds == null || sourceClassIds.isEmpty()) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
UserinfoExample example = new UserinfoExample();
|
|
|
example.createCriteria()
|
|
|
.andRoleEqualTo(4)
|
|
|
.andSchoolClassIdIn(sourceClassIds);
|
|
|
List<Userinfo> students = userinfoMapper.selectByExample(example);
|
|
|
return students == null ? Collections.emptyList() : students;
|
|
|
}
|
|
|
|
|
|
private void createTeachingClassMembersFromSourceClasses(SchoolClass teachingClass) {
|
|
|
if (teachingClassStudentMapper == null
|
|
|
|| teachingClass == null
|
|
|
|| !"TEACHING".equals(teachingClass.getClassType())
|
|
|
|| StringUtils.isBlank(teachingClass.getSourceClassIds())) {
|
|
|
return;
|
|
|
}
|
|
|
List<String> sourceClassIds = parseSourceClassIds(teachingClass.getSourceClassIds());
|
|
|
if (sourceClassIds.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
List<Userinfo> students = findStudentsByAdminClassIds(sourceClassIds);
|
|
|
for (Userinfo student : students) {
|
|
|
if (student == null || StringUtils.isBlank(student.getUserId())) {
|
|
|
continue;
|
|
|
}
|
|
|
upsertActiveTeachingClassMember(teachingClass.getSchoolClassId(), student, student.getSchoolClassId(), "ADMIN_CLASS_MERGE");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<String> validateTeachingClassStudentRows(List<TeachingClassStudentImportDTO> rows,
|
|
|
SchoolClass teachingClass,
|
|
|
List<String> sourceClassIds) {
|
|
|
List<String> errors = new ArrayList<>();
|
|
|
if (rows == null || rows.isEmpty()) {
|
|
|
errors.add("Excel中没有数据");
|
|
|
return errors;
|
|
|
}
|
|
|
Set<String> rowKeys = new HashSet<>();
|
|
|
for (int i = 0; i < rows.size(); i++) {
|
|
|
TeachingClassStudentImportDTO row = rows.get(i);
|
|
|
int rowNum = i + 2;
|
|
|
String studentName = row == null ? "" : StringUtils.trimToEmpty(row.getStudentName());
|
|
|
String userName = row == null ? "" : StringUtils.trimToEmpty(row.getUserName());
|
|
|
if (StringUtils.isBlank(studentName)) {
|
|
|
errors.add("第" + rowNum + "行 学生姓名不能为空");
|
|
|
}
|
|
|
if (StringUtils.isBlank(userName)) {
|
|
|
errors.add("第" + rowNum + "行 学号不能为空");
|
|
|
}
|
|
|
if (StringUtils.isBlank(studentName) || StringUtils.isBlank(userName)) {
|
|
|
continue;
|
|
|
}
|
|
|
String rowKey = studentName + "#" + userName;
|
|
|
if (!rowKeys.add(rowKey)) {
|
|
|
errors.add("第" + rowNum + "行 学生姓名和学号重复");
|
|
|
continue;
|
|
|
}
|
|
|
Userinfo student = findAdminClassStudent(row, teachingClass, sourceClassIds);
|
|
|
if (student == null) {
|
|
|
errors.add("第" + rowNum + "行 学生姓名与学号未匹配到来源行政班学生");
|
|
|
}
|
|
|
}
|
|
|
return errors;
|
|
|
}
|
|
|
|
|
|
private Userinfo findAdminClassStudent(TeachingClassStudentImportDTO row,
|
|
|
SchoolClass teachingClass,
|
|
|
List<String> sourceClassIds) {
|
|
|
if (row == null || teachingClass == null || sourceClassIds == null || sourceClassIds.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
UserinfoExample example = new UserinfoExample();
|
|
|
example.createCriteria()
|
|
|
.andRoleEqualTo(4)
|
|
|
.andSchoolIdEqualTo(teachingClass.getSchoolId())
|
|
|
.andNameEqualTo(StringUtils.trimToEmpty(row.getStudentName()))
|
|
|
.andUsernameEqualTo(StringUtils.trimToEmpty(row.getUserName()))
|
|
|
.andSchoolClassIdIn(sourceClassIds);
|
|
|
List<Userinfo> students = userinfoMapper.selectByExample(example);
|
|
|
if (students == null || students.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
return students.get(0);
|
|
|
}
|
|
|
|
|
|
private List<String> validateTeachingClassImportRowsByMajor(List<TeachingClassStudentImportDTO> rows,
|
|
|
String schoolId,
|
|
|
String schoolFacultyId,
|
|
|
String schoolMajorId) {
|
|
|
List<String> errors = new ArrayList<>();
|
|
|
if (rows == null || rows.isEmpty()) {
|
|
|
errors.add("Excel中没有数据");
|
|
|
return errors;
|
|
|
}
|
|
|
Set<String> rowKeys = new HashSet<>();
|
|
|
for (int i = 0; i < rows.size(); i++) {
|
|
|
TeachingClassStudentImportDTO row = rows.get(i);
|
|
|
int rowNum = i + 2;
|
|
|
String studentName = row == null ? "" : StringUtils.trimToEmpty(row.getStudentName());
|
|
|
String userName = row == null ? "" : StringUtils.trimToEmpty(row.getUserName());
|
|
|
if (StringUtils.isBlank(studentName)) {
|
|
|
errors.add("第" + rowNum + "行 学生姓名不能为空");
|
|
|
}
|
|
|
if (StringUtils.isBlank(userName)) {
|
|
|
errors.add("第" + rowNum + "行 学号不能为空");
|
|
|
}
|
|
|
if (StringUtils.isBlank(studentName) || StringUtils.isBlank(userName)) {
|
|
|
continue;
|
|
|
}
|
|
|
String rowKey = studentName + "#" + userName;
|
|
|
if (!rowKeys.add(rowKey)) {
|
|
|
errors.add("第" + rowNum + "行 学生姓名和学号重复");
|
|
|
continue;
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(row.getSchoolClassName())) {
|
|
|
SchoolClass adminClass = findTeacherImportClass(schoolId, schoolMajorId, StringUtils.trimToEmpty(row.getSchoolClassName()));
|
|
|
if (adminClass == null || !"ADMIN".equals(adminClass.getClassType())) {
|
|
|
errors.add("第" + rowNum + "行 未匹配到行政班:" + row.getSchoolClassName());
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
Userinfo student = findAdminClassStudent(row, schoolId, schoolFacultyId, schoolMajorId);
|
|
|
if (student == null) {
|
|
|
errors.add("第" + rowNum + "行 学生姓名与学号未匹配到该专业下的行政班学生");
|
|
|
}
|
|
|
}
|
|
|
return errors;
|
|
|
}
|
|
|
|
|
|
private List<String> validateTeachingClassImportRowsBySourceClasses(List<TeachingClassStudentImportDTO> rows,
|
|
|
String schoolId,
|
|
|
String schoolFacultyId,
|
|
|
String schoolMajorId,
|
|
|
List<String> sourceClassIds) {
|
|
|
List<String> errors = new ArrayList<>();
|
|
|
if (sourceClassIds == null || sourceClassIds.isEmpty()) {
|
|
|
errors.add("请选择来源行政班");
|
|
|
return errors;
|
|
|
}
|
|
|
for (String sourceClassId : sourceClassIds) {
|
|
|
SchoolClass sourceClass = schoolClassMapper.selectByPrimaryKey(sourceClassId);
|
|
|
if (sourceClass == null) {
|
|
|
errors.add("来源行政班不存在");
|
|
|
continue;
|
|
|
}
|
|
|
if (!"ADMIN".equals(sourceClass.getClassType())
|
|
|
|| !schoolId.equals(sourceClass.getSchoolId())
|
|
|
|| !schoolMajorId.equals(sourceClass.getSchoolMajorId())) {
|
|
|
errors.add("来源行政班不属于当前学校和专业");
|
|
|
}
|
|
|
}
|
|
|
if (!errors.isEmpty()) {
|
|
|
return errors;
|
|
|
}
|
|
|
SchoolClass importScope = new SchoolClass();
|
|
|
importScope.setSchoolId(schoolId);
|
|
|
List<String> rowErrors = validateTeachingClassStudentRows(rows, importScope, sourceClassIds);
|
|
|
for (String rowError : rowErrors) {
|
|
|
errors.add(rowError.replace("来源行政班学生", "所选来源行政班学生"));
|
|
|
}
|
|
|
return errors;
|
|
|
}
|
|
|
|
|
|
private Userinfo findAdminClassStudent(TeachingClassStudentImportDTO row,
|
|
|
String schoolId,
|
|
|
String schoolFacultyId,
|
|
|
String schoolMajorId) {
|
|
|
if (row == null) {
|
|
|
return null;
|
|
|
}
|
|
|
UserinfoExample example = new UserinfoExample();
|
|
|
UserinfoExample.Criteria criteria = example.createCriteria()
|
|
|
.andRoleEqualTo(4)
|
|
|
.andSchoolIdEqualTo(schoolId)
|
|
|
.andSchoolFacultyIdEqualTo(schoolFacultyId)
|
|
|
.andSchoolMajorIdEqualTo(schoolMajorId)
|
|
|
.andNameEqualTo(StringUtils.trimToEmpty(row.getStudentName()))
|
|
|
.andUsernameEqualTo(StringUtils.trimToEmpty(row.getUserName()));
|
|
|
if (StringUtils.isNotBlank(row.getSchoolClassName())) {
|
|
|
SchoolClass adminClass = findTeacherImportClass(schoolId, schoolMajorId, StringUtils.trimToEmpty(row.getSchoolClassName()));
|
|
|
criteria.andSchoolClassIdEqualTo(adminClass == null ? "__missing__" : adminClass.getSchoolClassId());
|
|
|
}
|
|
|
List<Userinfo> students = userinfoMapper.selectByExample(example);
|
|
|
if (students == null || students.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
return students.get(0);
|
|
|
}
|
|
|
|
|
|
private ResultEntity validateTeacherStudentImportFile(MultipartFile file) {
|
|
|
if (file == null || file.isEmpty()) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "请选择要导入的Excel文件");
|
|
|
}
|
|
|
String filename = StringUtils.defaultString(file.getOriginalFilename());
|
|
|
if (!StringUtils.endsWithIgnoreCase(filename, ".xls") && !StringUtils.endsWithIgnoreCase(filename, ".xlsx")) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "仅支持xls或xlsx格式文件");
|
|
|
}
|
|
|
if (file.getSize() > 10 * 1024 * 1024) {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "文件大小不能超过10MB");
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
private List<Userinfo> buildTeacherImportStudents(List<SchoolAdminStudentImportDTO> rows,
|
|
|
Userinfo operator,
|
|
|
List<String> errors) {
|
|
|
List<Userinfo> students = new ArrayList<>();
|
|
|
Set<String> usernames = new HashSet<>();
|
|
|
if (rows == null) {
|
|
|
return students;
|
|
|
}
|
|
|
for (int i = 0; i < rows.size(); i++) {
|
|
|
SchoolAdminStudentImportDTO row = rows.get(i);
|
|
|
int rowNumber = i + 2;
|
|
|
if (isBlankTeacherStudentImportRow(row)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
String name = StringUtils.trimToEmpty(row.getName());
|
|
|
String username = StringUtils.trimToEmpty(row.getUsername());
|
|
|
String facultyName = StringUtils.trimToEmpty(row.getSchoolFacultyName());
|
|
|
String majorName = StringUtils.trimToEmpty(row.getSchoolMajorName());
|
|
|
String className = StringUtils.trimToEmpty(row.getSchoolClassName());
|
|
|
String sex = normalizeTeacherImportSex(row.getSex());
|
|
|
|
|
|
if (StringUtils.isBlank(name)) {
|
|
|
errors.add("第" + rowNumber + "行:姓名不能为空");
|
|
|
}
|
|
|
if (StringUtils.isBlank(username)) {
|
|
|
errors.add("第" + rowNumber + "行:学号不能为空");
|
|
|
} else if (!usernames.add(username)) {
|
|
|
errors.add("第" + rowNumber + "行:学号在导入文件中重复");
|
|
|
} else if (userInfoService.existsByUserName(username)) {
|
|
|
errors.add("第" + rowNumber + "行:账号已存在");
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(row.getSex()) && sex == null) {
|
|
|
errors.add("第" + rowNumber + "行:性别请填写男或女");
|
|
|
}
|
|
|
if (StringUtils.isBlank(facultyName)) {
|
|
|
errors.add("第" + rowNumber + "行:所属院系不能为空");
|
|
|
}
|
|
|
if (StringUtils.isBlank(majorName)) {
|
|
|
errors.add("第" + rowNumber + "行:所属专业不能为空");
|
|
|
}
|
|
|
if (StringUtils.isBlank(className)) {
|
|
|
errors.add("第" + rowNumber + "行:所属班级不能为空");
|
|
|
}
|
|
|
|
|
|
SchoolFaculty faculty = StringUtils.isBlank(facultyName) ? null : findTeacherImportFaculty(operator.getSchoolId(), facultyName);
|
|
|
SchoolMajor major = null;
|
|
|
SchoolClass schoolClass = null;
|
|
|
if (StringUtils.isNotBlank(facultyName) && faculty == null) {
|
|
|
errors.add("第" + rowNumber + "行:未找到院系“" + facultyName + "”");
|
|
|
}
|
|
|
if (faculty != null && StringUtils.isNotBlank(majorName)) {
|
|
|
major = findTeacherImportMajor(faculty.getSchoolFacultyId(), majorName);
|
|
|
if (major == null) {
|
|
|
errors.add("第" + rowNumber + "行:院系“" + facultyName + "”下未找到专业“" + majorName + "”");
|
|
|
}
|
|
|
}
|
|
|
if (major != null && StringUtils.isNotBlank(className)) {
|
|
|
schoolClass = findTeacherImportClass(operator.getSchoolId(), major.getSchoolMajorId(), className);
|
|
|
if (schoolClass == null) {
|
|
|
errors.add("第" + rowNumber + "行:专业“" + majorName + "”下未找到班级“" + className + "”");
|
|
|
} else if (!isAdminClass(schoolClass)) {
|
|
|
errors.add("第" + rowNumber + "行:学生账号只能导入行政班");
|
|
|
} else if (!canManageAdminClass(operator, schoolClass)) {
|
|
|
errors.add("第" + rowNumber + "行:只能导入本校行政班");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!hasTeacherImportRowError(errors, rowNumber)) {
|
|
|
Userinfo student = new Userinfo();
|
|
|
student.setUserId(UUID.randomUUID().toString());
|
|
|
student.setName(name);
|
|
|
student.setUsername(username);
|
|
|
student.setPassword("123qwe");
|
|
|
student.setSex(StringUtils.defaultString(sex));
|
|
|
student.setPhone(StringUtils.trimToEmpty(row.getPhone()));
|
|
|
student.setEmail(StringUtils.trimToEmpty(row.getEmail()));
|
|
|
student.setRole(4);
|
|
|
student.setTeacherAdmin(false);
|
|
|
student.setSchoolId(operator.getSchoolId());
|
|
|
student.setSchoolFacultyId(faculty.getSchoolFacultyId());
|
|
|
student.setSchoolMajorId(major.getSchoolMajorId());
|
|
|
student.setSchoolClassId(schoolClass.getSchoolClassId());
|
|
|
student.setCreateTime(new Date());
|
|
|
student.setCodeFrom("Excel导入");
|
|
|
students.add(student);
|
|
|
}
|
|
|
}
|
|
|
return students;
|
|
|
}
|
|
|
|
|
|
private boolean isBlankTeacherStudentImportRow(SchoolAdminStudentImportDTO row) {
|
|
|
if (row == null) {
|
|
|
return true;
|
|
|
}
|
|
|
return StringUtils.isBlank(row.getName())
|
|
|
&& StringUtils.isBlank(row.getUsername())
|
|
|
&& StringUtils.isBlank(row.getSex())
|
|
|
&& StringUtils.isBlank(row.getSchoolFacultyName())
|
|
|
&& StringUtils.isBlank(row.getSchoolMajorName())
|
|
|
&& StringUtils.isBlank(row.getSchoolClassName())
|
|
|
&& StringUtils.isBlank(row.getPhone())
|
|
|
&& StringUtils.isBlank(row.getEmail());
|
|
|
}
|
|
|
|
|
|
private String normalizeTeacherImportSex(String sex) {
|
|
|
String value = StringUtils.trimToEmpty(sex);
|
|
|
if (StringUtils.isBlank(value)) {
|
|
|
return "";
|
|
|
}
|
|
|
if ("1".equals(value) || "男".equals(value) || "男性".equals(value)) {
|
|
|
return "男";
|
|
|
}
|
|
|
if ("2".equals(value) || "女".equals(value) || "女性".equals(value)) {
|
|
|
return "女";
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
private boolean hasTeacherImportRowError(List<String> errors, int rowNumber) {
|
|
|
String prefix = "第" + rowNumber + "行:";
|
|
|
for (String error : errors) {
|
|
|
if (error.startsWith(prefix)) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
private SchoolFaculty findTeacherImportFaculty(String schoolId, String facultyName) {
|
|
|
SchoolFacultyExample example = new SchoolFacultyExample();
|
|
|
example.createCriteria()
|
|
|
.andSchoolIdEqualTo(schoolId)
|
|
|
.andSchoolFacultyNameEqualTo(facultyName);
|
|
|
List<SchoolFaculty> faculties = schoolFacultyMapper.selectByExample(example);
|
|
|
return faculties.isEmpty() ? null : faculties.get(0);
|
|
|
}
|
|
|
|
|
|
private SchoolMajor findTeacherImportMajor(String facultyId, String majorName) {
|
|
|
SchoolMajorExample example = new SchoolMajorExample();
|
|
|
example.createCriteria()
|
|
|
.andSchoolFacultyIdEqualTo(facultyId)
|
|
|
.andSchoolMajorNameEqualTo(majorName);
|
|
|
List<SchoolMajor> majors = schoolMajorMapper.selectByExample(example);
|
|
|
return majors.isEmpty() ? null : majors.get(0);
|
|
|
}
|
|
|
|
|
|
private SchoolClass findTeacherImportClass(String schoolId, String majorId, String className) {
|
|
|
SchoolClassExample example = new SchoolClassExample();
|
|
|
example.createCriteria()
|
|
|
.andSchoolIdEqualTo(schoolId)
|
|
|
.andSchoolMajorIdEqualTo(majorId)
|
|
|
.andClassNameEqualTo(className);
|
|
|
List<SchoolClass> classes = schoolClassMapper.selectByExample(example);
|
|
|
return classes.isEmpty() ? null : classes.get(0);
|
|
|
}
|
|
|
|
|
|
private List<String> parseSourceClassIds(String sourceClassIds) {
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
if (StringUtils.isBlank(sourceClassIds)) {
|
|
|
return ids;
|
|
|
}
|
|
|
for (String sourceClassId : sourceClassIds.split(",")) {
|
|
|
String trimmed = StringUtils.trimToEmpty(sourceClassId);
|
|
|
if (StringUtils.isNotBlank(trimmed) && !ids.contains(trimmed)) {
|
|
|
ids.add(trimmed);
|
|
|
}
|
|
|
}
|
|
|
return ids;
|
|
|
}
|
|
|
|
|
|
private ResultEntity noManagePermission() {
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "权限不足");
|
|
|
}
|
|
|
|
|
|
private boolean isPlatformAdmin(Userinfo userInfo) {
|
|
|
return userInfo != null && Integer.valueOf(1).equals(userInfo.getRole());
|
|
|
}
|
|
|
|
|
|
private boolean canCreateSchoolClass(String operatorId, String schoolId, String classType) {
|
|
|
if (StringUtils.isAnyBlank(operatorId, schoolId, classType)) {
|
|
|
return false;
|
|
|
}
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
if (isPlatformAdmin(operator)) {
|
|
|
return !"ADMIN".equals(classType) || isAdminClassManagementEnabled(schoolId);
|
|
|
}
|
|
|
if (!Integer.valueOf(3).equals(operator == null ? null : operator.getRole())
|
|
|
|| !StringUtils.equals(operator.getSchoolId(), schoolId)) {
|
|
|
return false;
|
|
|
}
|
|
|
if ("TEACHING".equals(classType)) {
|
|
|
return true;
|
|
|
}
|
|
|
if ("ADMIN".equals(classType)) {
|
|
|
return isAdminClassManagementEnabled(schoolId);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
private boolean isTeacherAdmin(Userinfo userInfo) {
|
|
|
return userInfo != null
|
|
|
&& Integer.valueOf(3).equals(userInfo.getRole())
|
|
|
&& Boolean.TRUE.equals(userInfo.getTeacherAdmin());
|
|
|
}
|
|
|
|
|
|
private boolean isSchoolTeacher(Userinfo userInfo) {
|
|
|
return userInfo != null
|
|
|
&& Integer.valueOf(3).equals(userInfo.getRole())
|
|
|
&& StringUtils.isNotBlank(userInfo.getSchoolId());
|
|
|
}
|
|
|
|
|
|
private boolean canManageAdminClass(Userinfo operator, SchoolClass schoolClass) {
|
|
|
if (operator == null || !isAdminClass(schoolClass)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (isPlatformAdmin(operator)) {
|
|
|
return isAdminClassManagementEnabled(schoolClass.getSchoolId());
|
|
|
}
|
|
|
return isSchoolTeacher(operator)
|
|
|
&& StringUtils.equals(operator.getSchoolId(), schoolClass.getSchoolId())
|
|
|
&& isAdminClassManagementEnabled(schoolClass.getSchoolId());
|
|
|
}
|
|
|
|
|
|
private boolean canManageSchoolStructure(String operatorId, String schoolId) {
|
|
|
if (StringUtils.isAnyBlank(operatorId, schoolId)) {
|
|
|
return false;
|
|
|
}
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
if (isPlatformAdmin(operator)) {
|
|
|
return true;
|
|
|
}
|
|
|
return isTeacherAdmin(operator)
|
|
|
&& StringUtils.equals(operator.getSchoolId(), schoolId)
|
|
|
&& !isTeacherRosterMode(schoolId);
|
|
|
}
|
|
|
|
|
|
private boolean canManageFaculty(String operatorId, String schoolId) {
|
|
|
return hasSchoolStructureAuthority(operatorId, schoolId) && isFacultyManagementEnabled(schoolId);
|
|
|
}
|
|
|
|
|
|
private boolean canManageMajorStructure(String operatorId, String schoolId) {
|
|
|
return hasSchoolStructureAuthority(operatorId, schoolId) && isMajorManagementEnabled(schoolId);
|
|
|
}
|
|
|
|
|
|
private boolean hasSchoolStructureAuthority(String operatorId, String schoolId) {
|
|
|
if (StringUtils.isAnyBlank(operatorId, schoolId)) {
|
|
|
return false;
|
|
|
}
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
return isPlatformAdmin(operator)
|
|
|
|| (isTeacherAdmin(operator) && StringUtils.equals(operator.getSchoolId(), schoolId));
|
|
|
}
|
|
|
|
|
|
private boolean isFacultyManagementEnabled(String schoolId) {
|
|
|
return schoolProductConfigService != null && schoolProductConfigService.isFacultyManagementEnabled(schoolId);
|
|
|
}
|
|
|
|
|
|
private boolean isMajorManagementEnabled(String schoolId) {
|
|
|
return schoolProductConfigService != null && schoolProductConfigService.isMajorManagementEnabled(schoolId);
|
|
|
}
|
|
|
|
|
|
private boolean isAdminClassManagementEnabled(String schoolId) {
|
|
|
return schoolProductConfigService != null && schoolProductConfigService.isAdminClassManagementEnabled(schoolId);
|
|
|
}
|
|
|
|
|
|
private boolean isTeacherRosterMode(String schoolId) {
|
|
|
return schoolProductConfigService != null
|
|
|
&& schoolProductConfigService.isTeacherRosterManaged(schoolId);
|
|
|
}
|
|
|
|
|
|
private boolean canManageMajor(String operatorId, String schoolMajorId) {
|
|
|
if (StringUtils.isBlank(schoolMajorId)) {
|
|
|
return false;
|
|
|
}
|
|
|
SchoolMajor major = schoolMajorMapper.selectByPrimaryKey(schoolMajorId);
|
|
|
if (major == null || StringUtils.isBlank(major.getSchoolFacultyId())) {
|
|
|
return false;
|
|
|
}
|
|
|
SchoolFaculty faculty = schoolFacultyMapper.selectByPrimaryKey(major.getSchoolFacultyId());
|
|
|
return faculty != null && canManageMajorStructure(operatorId, faculty.getSchoolId());
|
|
|
}
|
|
|
|
|
|
private boolean teacherHasCreatedClass(String teacherId) {
|
|
|
SchoolClassExample example = new SchoolClassExample();
|
|
|
example.createCriteria().andCreatedByEqualTo(teacherId);
|
|
|
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) {
|
|
|
Userinfo operator = userinfoMapper.selectByPrimaryKey(operatorId);
|
|
|
if (operator == null) {
|
|
|
return false;
|
|
|
}
|
|
|
if (Integer.valueOf(1).equals(operator.getRole())) {
|
|
|
return true;
|
|
|
}
|
|
|
if (!Integer.valueOf(3).equals(operator.getRole())) {
|
|
|
return false;
|
|
|
}
|
|
|
SchoolClass schoolClass = schoolClassMapper.selectByPrimaryKey(schoolClassId);
|
|
|
if (canManageTeachingClass(operator, schoolClass)) {
|
|
|
return true;
|
|
|
}
|
|
|
if (canManageAdminClass(operator, schoolClass)) {
|
|
|
return true;
|
|
|
}
|
|
|
return isClassOwner(schoolClass, operatorId);
|
|
|
}
|
|
|
|
|
|
private boolean canOperateStudent(String operatorId, String studentId) {
|
|
|
return canOperateStudent(operatorId, studentId, null);
|
|
|
}
|
|
|
|
|
|
private boolean canOperateStudent(String operatorId, String studentId, String teachingClassId) {
|
|
|
Userinfo student = userinfoMapper.selectByPrimaryKey(studentId);
|
|
|
if (student == null || !Integer.valueOf(4).equals(student.getRole())) {
|
|
|
return false;
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(teachingClassId)) {
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
|
|
return "TEACHING".equals(teachingClass == null ? null : teachingClass.getClassType())
|
|
|
&& canOperateClass(operatorId, teachingClassId)
|
|
|
&& teachingClassStudentMapper != null
|
|
|
&& teachingClassStudentMapper.countByStudentUserIdAndTeachingClassId(studentId, teachingClassId) > 0;
|
|
|
}
|
|
|
return canOperateClass(operatorId, student.getSchoolClassId());
|
|
|
}
|
|
|
|
|
|
@PostMapping("/selectCurrentTeachingClass")
|
|
|
@ApiOperation("学生-查询当前在读教学班")
|
|
|
@AnonymousAccess
|
|
|
public ResultEntity<SchoolClass> selectCurrentTeachingClass(@RequestParam String userId, HttpServletRequest request) {
|
|
|
try {
|
|
|
JwtUser currentUser = TokenProvider.getJWTUser(request);
|
|
|
if (currentUser != null && currentUser.getRoleId() == 4 && studentTeachingClassResolver != null) {
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(studentTeachingClassResolver.resolveRequired(currentUser));
|
|
|
return new ResultEntity<>(HttpStatus.OK, "查询成功", teachingClass);
|
|
|
}
|
|
|
} catch (RuntimeException ignored) {
|
|
|
// 保留旧版匿名调用的兼容路径。
|
|
|
}
|
|
|
TeachingClassStudent member = teachingClassStudentMapper == null
|
|
|
? null
|
|
|
: teachingClassStudentMapper.selectActiveByStudentUserId(userId);
|
|
|
if (member == null || StringUtils.isBlank(member.getTeachingClassId())) {
|
|
|
return new ResultEntity<>(HttpStatus.OK, "当前学生未分配在读教学班");
|
|
|
}
|
|
|
SchoolClass teachingClass = schoolClassMapper.selectByPrimaryKey(member.getTeachingClassId());
|
|
|
return new ResultEntity<>(HttpStatus.OK, "查询成功", teachingClass);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("开放接口,自动同步学生信息")
|
|
|
@PostMapping("synchronizationStudentInfoByAuto")
|
|
|
@AnonymousAccess
|
|
|
public String synchronizationStudentInfoByAuto(@RequestBody List<ZYUserInfo> studentList) {
|
|
|
// JwtUser user = TokenProvider.getJWTUser(request);
|
|
|
return userInfoService.insertAllByAuto(studentList);
|
|
|
//return new ResultDataEntity(HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|