|
|
|
@ -0,0 +1,280 @@
|
|
|
|
|
package com.sztzjy.financial_bigdata.controller.tea;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
import com.sztzjy.financial_bigdata.annotation.AnonymousAccess;
|
|
|
|
|
import com.sztzjy.financial_bigdata.entity.*;
|
|
|
|
|
import com.sztzjy.financial_bigdata.entity.stu_dto.StuUserDto;
|
|
|
|
|
import com.sztzjy.financial_bigdata.mapper.StuClassMapper;
|
|
|
|
|
import com.sztzjy.financial_bigdata.mapper.StuUserMapper;
|
|
|
|
|
import com.sztzjy.financial_bigdata.util.ResultEntity;
|
|
|
|
|
import com.sztzjy.financial_bigdata.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.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author xcj
|
|
|
|
|
* @Date 2024/3/7
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/tea/user")
|
|
|
|
|
@Api(tags = "老师端--用户相关")
|
|
|
|
|
public class UserController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private StuClassMapper classMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private StuUserMapper stuUserMapper;
|
|
|
|
|
/* 添加班级
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/11
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/addClass")
|
|
|
|
|
@ApiOperation("班级管理--添加班级")
|
|
|
|
|
public ResultEntity<HttpStatus> addClass(@RequestBody StuClass stuClass) {
|
|
|
|
|
if (StringUtils.isBlank(stuClass.getClassName())) {
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.BAD_REQUEST, "请填写班级名称");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(stuClass.getSchoolName())) {
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.BAD_REQUEST, "请填写学校名称");
|
|
|
|
|
}
|
|
|
|
|
StuClass stuClass1 = classMapper.selectByPrimaryKey(stuClass.getClassName());
|
|
|
|
|
if (stuClass1 != null) {
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.BAD_REQUEST, "该班级已存在");
|
|
|
|
|
}
|
|
|
|
|
stuClass.setCreateTime(new Date());
|
|
|
|
|
stuClass.setClassId(IdUtil.randomUUID());
|
|
|
|
|
classMapper.insert(stuClass);
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.OK, "新增成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 添加班级
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/11
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/deleteClass")
|
|
|
|
|
@ApiOperation("班级管理--删除班级")
|
|
|
|
|
public ResultEntity<HttpStatus> deleteClass(@ApiParam("班级id") @RequestParam String classId) {
|
|
|
|
|
if (classId == null) {
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.BAD_REQUEST, "缺少主键id");
|
|
|
|
|
}
|
|
|
|
|
classMapper.deleteByPrimaryKey(classId);
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.OK, "删除成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 编辑班级
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/11
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/updateClass")
|
|
|
|
|
@ApiOperation("班级管理--修改班级信息")
|
|
|
|
|
public ResultEntity<HttpStatus> updateClass(@ApiParam("班级id必传") @RequestBody StuClass stuClass) {
|
|
|
|
|
if (StringUtils.isBlank(stuClass.getClassName())) {
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.BAD_REQUEST, "请填写班级名称");
|
|
|
|
|
}
|
|
|
|
|
classMapper.updateByPrimaryKey(stuClass);
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.OK, "修改成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/12
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/selectClassByName")
|
|
|
|
|
@ApiOperation("班级管理--班级管理页面分页查询")
|
|
|
|
|
public ResultEntity<PageInfo<StuClass>> selectClassByName(@ApiParam("班级名称(不传默认查所有)")
|
|
|
|
|
@RequestParam(required = false) String className,
|
|
|
|
|
@RequestParam Integer index,
|
|
|
|
|
@RequestParam Integer size) {
|
|
|
|
|
PageHelper.startPage(index, size);
|
|
|
|
|
StuClassExample example = new StuClassExample();
|
|
|
|
|
if (StringUtils.isNotBlank(className)) {
|
|
|
|
|
example.createCriteria().andClassNameEqualTo(className);
|
|
|
|
|
}
|
|
|
|
|
List<StuClass> stuClasses = classMapper.selectByExample(example);
|
|
|
|
|
return new ResultEntity<PageInfo<StuClass>>(new PageInfo<>(stuClasses));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/12
|
|
|
|
|
*/
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/selectAllClassNameBySchoolId")
|
|
|
|
|
@ApiOperation("班级下拉框")
|
|
|
|
|
public ResultEntity<List<String>> selectAllClassNameBySchoolId(@RequestParam String schoolId) {
|
|
|
|
|
return new ResultEntity<List<String>>(classMapper.selectAllClassNameBySchoolId(schoolId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/12
|
|
|
|
|
*/
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/addStudent")
|
|
|
|
|
@ApiOperation("学生管理--添加学生")
|
|
|
|
|
public ResultEntity<HttpStatus> addStudent(@ApiParam("所属班级(id)、姓名、学号三个必填") @RequestBody StuUser stuUser) {
|
|
|
|
|
if (StringUtils.isBlank(stuUser.getClassId())) {
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.BAD_REQUEST, "请选择班级");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(stuUser.getName())) {
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.BAD_REQUEST, "请输入学生姓名");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(stuUser.getStudentId())) {
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.BAD_REQUEST, "请输入学号");
|
|
|
|
|
}
|
|
|
|
|
stuUser.setRoleId(0);
|
|
|
|
|
stuUser.setPassword("tzs!@#888");
|
|
|
|
|
stuUser.setCreateTime(new Date());
|
|
|
|
|
stuUser.setUserid(IdUtil.randomUUID());
|
|
|
|
|
stuUser.setUsername(stuUser.getStudentId());//同学号
|
|
|
|
|
stuUser.setStatus(0);
|
|
|
|
|
stuUserMapper.insert(stuUser);
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.OK, "新增成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/12
|
|
|
|
|
*/
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/selectStuPage")
|
|
|
|
|
@ApiOperation("学生管理--查询")
|
|
|
|
|
public ResultEntity<PageInfo> selectStuPage(@RequestParam Integer index,
|
|
|
|
|
@RequestParam Integer size,
|
|
|
|
|
@RequestParam String schoolId,
|
|
|
|
|
@RequestParam(required = false) String studentId,
|
|
|
|
|
@RequestParam(required = false) String classId) {
|
|
|
|
|
PageHelper.startPage(index, size);
|
|
|
|
|
StuUserExample stuUserExample = new StuUserExample();
|
|
|
|
|
StuUserExample.Criteria criteria = stuUserExample.createCriteria();
|
|
|
|
|
criteria.andSchoolIdEqualTo(schoolId).andStatusEqualTo(0);
|
|
|
|
|
if (StringUtils.isNotBlank(studentId)) {
|
|
|
|
|
criteria.andStudentIdEqualTo(studentId);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(classId)) {
|
|
|
|
|
criteria.andClassIdEqualTo(classId);
|
|
|
|
|
}
|
|
|
|
|
List<StuUser> stuUsers = stuUserMapper.selectByExample(stuUserExample);
|
|
|
|
|
return new ResultEntity<>(new PageInfo<>(stuUsers));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/12
|
|
|
|
|
*/
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/selectSchoolNameById")
|
|
|
|
|
@ApiOperation("学生管理--学校名称")
|
|
|
|
|
public ResultEntity<String> selectStuPage(@RequestParam String schoolId) {
|
|
|
|
|
return new ResultEntity(stuUserMapper.selectSchoolNameById(schoolId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/12
|
|
|
|
|
*/
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/updateStudent")
|
|
|
|
|
@ApiOperation("学生管理--编辑")
|
|
|
|
|
public ResultEntity<HttpStatus> updateStudent(@ApiParam("学校ID必传") @RequestBody StuUser stuUser) {
|
|
|
|
|
StuUserExample example = new StuUserExample();
|
|
|
|
|
if (StringUtils.isNotBlank(stuUser.getStudentId())) {
|
|
|
|
|
example.createCriteria().andStudentIdEqualTo(stuUser.getStudentId()).andSchoolIdEqualTo(stuUser.getSchoolId());
|
|
|
|
|
}
|
|
|
|
|
List<StuUser> stuUsers = stuUserMapper.selectByExample(example);
|
|
|
|
|
if (!stuUsers.isEmpty()) {
|
|
|
|
|
return new ResultEntity<HttpStatus>(HttpStatus.BAD_REQUEST, "学号重复!");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/12
|
|
|
|
|
*/
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/deleteStudent")
|
|
|
|
|
@ApiOperation("学生管理--删除")
|
|
|
|
|
public ResultEntity<HttpStatus> deleteStudent(@RequestParam String userId) {
|
|
|
|
|
StuUser stuUser = stuUserMapper.selectByPrimaryKey(userId);
|
|
|
|
|
stuUser.setStatus(1);
|
|
|
|
|
stuUserMapper.updateByPrimaryKey(stuUser);
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "删除成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/12
|
|
|
|
|
*/
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/initPassword")
|
|
|
|
|
@ApiOperation("学生管理--初始化密码")
|
|
|
|
|
public ResultEntity<String> initPassword(@RequestParam String userId) {
|
|
|
|
|
StuUser stuUser = stuUserMapper.selectByPrimaryKey(userId);
|
|
|
|
|
stuUser.setPassword("tzs!@#888");
|
|
|
|
|
stuUserMapper.updateByPrimaryKey(stuUser);
|
|
|
|
|
return new ResultEntity<>(HttpStatus.OK, "密码初始化成功!", "tzs!@#888");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author xcj
|
|
|
|
|
* @Date 2024/3/12
|
|
|
|
|
*/
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/exportStu")
|
|
|
|
|
@ApiOperation("学生管理--导出")
|
|
|
|
|
public void exportStu(HttpServletResponse response,
|
|
|
|
|
@ApiParam("按班级导出时传班级ID,默认按学校") @RequestParam(required = false) String classId,
|
|
|
|
|
@RequestParam String schoolId) {
|
|
|
|
|
StuUserExample userTableExample = new StuUserExample();
|
|
|
|
|
StuUserExample.Criteria criteria = userTableExample.createCriteria();
|
|
|
|
|
criteria.andSchoolIdEqualTo(schoolId);
|
|
|
|
|
if (StringUtils.isNotBlank(classId)) {
|
|
|
|
|
criteria.andClassIdEqualTo(classId);
|
|
|
|
|
}
|
|
|
|
|
List<StuUser> userTables = stuUserMapper.selectByExample(userTableExample);
|
|
|
|
|
List<StuUserDto> userDtos = new ArrayList<>();
|
|
|
|
|
for (StuUser userTable : userTables) {
|
|
|
|
|
StuUserDto userDto = new StuUserDto();
|
|
|
|
|
String className = classMapper.selectClassNameByClassId(userTable.getClassId());
|
|
|
|
|
BeanUtils.copyProperties(userTable, userDto);
|
|
|
|
|
userDto.setClassName(className);
|
|
|
|
|
userDtos.add(userDto);
|
|
|
|
|
}
|
|
|
|
|
//导出的表名
|
|
|
|
|
String title = IdUtil.simpleUUID();
|
|
|
|
|
//表中第一行表头字段
|
|
|
|
|
String[] headers = {"院校名称", "班级名称", "学生姓名", "学号", "电话", "邮箱"};
|
|
|
|
|
|
|
|
|
|
//具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型
|
|
|
|
|
List<String> listColumn = Arrays.asList("schoolName", "className", "name", "studentId", "phone", "email");
|
|
|
|
|
try {
|
|
|
|
|
FilePortUtil.exportExcel(response, title, headers, userDtos, listColumn);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@PostMapping("/batchImportStu")
|
|
|
|
|
@ApiOperation("学生管理--批量导入")
|
|
|
|
|
public void batchImportStu() {
|
|
|
|
|
}
|
|
|
|
|
}
|