TEStudentController.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.qmth.themis.backend.api;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.google.gson.Gson;
  5. import com.qmth.themis.business.annotation.ApiJsonObject;
  6. import com.qmth.themis.business.annotation.ApiJsonProperty;
  7. import com.qmth.themis.business.config.SystemConfig;
  8. import com.qmth.themis.business.constant.SystemConstant;
  9. import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
  10. import com.qmth.themis.business.dto.response.TEStudentDto;
  11. import com.qmth.themis.business.entity.TBUser;
  12. import com.qmth.themis.business.entity.TEStudent;
  13. import com.qmth.themis.business.entity.TOeExamRecord;
  14. import com.qmth.themis.business.service.TEStudentService;
  15. import com.qmth.themis.business.util.RedisUtil;
  16. import com.qmth.themis.business.util.ServletUtil;
  17. import com.qmth.themis.common.enums.ExceptionResultEnum;
  18. import com.qmth.themis.common.exception.BusinessException;
  19. import com.qmth.themis.common.util.Result;
  20. import com.qmth.themis.common.util.ResultUtil;
  21. import io.swagger.annotations.*;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import org.springframework.web.bind.annotation.*;
  25. import org.springframework.web.multipart.MultipartFile;
  26. import javax.annotation.Resource;
  27. import java.util.Collections;
  28. import java.util.Map;
  29. import java.util.Objects;
  30. /**
  31. * @Description: 学生档案 前端控制器
  32. * @Param:
  33. * @return:
  34. * @Author: wangliang
  35. * @Date: 2020/6/25
  36. */
  37. @Api(tags = "学生档案Controller")
  38. @RestController
  39. @RequestMapping("/${prefix.url.admin}/student")
  40. public class TEStudentController {
  41. @Resource
  42. TEStudentService teStudentService;
  43. @Resource
  44. RedisUtil redisUtil;
  45. @Resource
  46. SystemConfig systemConfig;
  47. @ApiOperation(value = "学生查询接口")
  48. @RequestMapping(value = "/query", method = RequestMethod.POST)
  49. @ApiResponses({@ApiResponse(code = 200, message = "考生信息", response = TEStudentDto.class)})
  50. public Result query(@ApiParam(value = "证件号", required = false) @RequestParam(required = false) String identity, @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name, @ApiParam(value = "是否启用", required = false) @RequestParam(required = false) Integer enable, @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber, @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
  51. TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
  52. IPage<TEStudentDto> teExamStudentIPage = teStudentService.studentQuery(new Page<>(pageNumber, pageSize), identity, name, enable, tbUser.getOrgId());
  53. if (teExamStudentIPage.getRecords() != null && teExamStudentIPage.getRecords().size() > 0) {
  54. for (TEStudentDto dto : teExamStudentIPage.getRecords()) {
  55. if (StringUtils.isNotBlank(dto.getBasePhotoPath())) {
  56. dto.setBasePhotoPath(systemConfig.getProperty("aliyun.oss.publicUrl") + "/" + dto.getBasePhotoPath());
  57. }
  58. }
  59. }
  60. return ResultUtil.ok(teExamStudentIPage);
  61. }
  62. @ApiOperation(value = "学生停用/启用接口")
  63. @RequestMapping(value = "/toggle", method = RequestMethod.POST)
  64. @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
  65. @Transactional
  66. public Result studentToggle(@ApiJsonObject(name = "studentToggle", value = {
  67. @ApiJsonProperty(key = "id", type = "long", example = "1", description = "学生ID"),
  68. @ApiJsonProperty(key = "enable", type = "long", example = "1", description = "是否启用")
  69. }) @ApiParam(value = "学生信息", required = true) @RequestBody Map<String, Object> mapParameter) {
  70. if (Objects.isNull(mapParameter.get("id")) || Objects.equals(mapParameter.get("id"), "")) {
  71. throw new BusinessException(ExceptionResultEnum.STUDENT_ID_IS_NULL);
  72. }
  73. Long id = Long.parseLong(String.valueOf(mapParameter.get("id")));
  74. if (Objects.isNull(mapParameter.get("enable")) || Objects.equals(mapParameter.get("enable"), "")) {
  75. throw new BusinessException(ExceptionResultEnum.ENABLE_IS_NULL);
  76. }
  77. Integer enable = Integer.parseInt(String.valueOf(mapParameter.get("enable")));
  78. TEStudent teStudent = teStudentService.getById(id);
  79. if (Objects.isNull(teStudent)) {
  80. throw new BusinessException(ExceptionResultEnum.STUDENT_NO);
  81. }
  82. TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
  83. teStudent.setEnable(enable);
  84. teStudent.setUpdateId(tbUser.getId());
  85. teStudentService.updateById(teStudent);
  86. Gson gson = new Gson();
  87. TEStudentCacheDto teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
  88. redisUtil.setStudent(teStudent.getId(), teStudentCacheDto);
  89. return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
  90. }
  91. @ApiOperation(value = "学生修改密码接口")
  92. @RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
  93. @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
  94. @Transactional
  95. public Result studentUpdatePwd(@ApiJsonObject(name = "studentUpdatePwd", value = {
  96. @ApiJsonProperty(key = "id", type = "long", example = "1", description = "用户ID"),
  97. @ApiJsonProperty(key = "password", description = "新密码")
  98. }) @ApiParam(value = "学生信息", required = true) @RequestBody Map<String, Object> mapParameter) {
  99. if (Objects.isNull(mapParameter.get("id")) || Objects.equals(mapParameter.get("id"), "")) {
  100. throw new BusinessException(ExceptionResultEnum.STUDENT_ID_IS_NULL);
  101. }
  102. Long id = Long.parseLong(String.valueOf(mapParameter.get("id")));
  103. if (Objects.isNull(mapParameter.get("password")) || Objects.equals(mapParameter.get("password"), "")) {
  104. throw new BusinessException(ExceptionResultEnum.PASSWORD_IS_NULL);
  105. }
  106. String password = String.valueOf(mapParameter.get("password"));
  107. TEStudent teStudent = teStudentService.getById(id);
  108. if (Objects.isNull(teStudent)) {
  109. throw new BusinessException(ExceptionResultEnum.STUDENT_INFO_IS_NULL);
  110. }
  111. TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
  112. teStudent.setPassword(password);
  113. teStudent.setUpdateId(tbUser.getId());
  114. teStudentService.updateById(teStudent);
  115. Gson gson = new Gson();
  116. TEStudentCacheDto teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
  117. redisUtil.setStudent(teStudent.getId(), teStudentCacheDto);
  118. return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
  119. }
  120. @ApiOperation(value = "学生考试记录查询接口")
  121. @RequestMapping(value = "/exam_record/query", method = RequestMethod.POST)
  122. @ApiResponses({@ApiResponse(code = 200, message = "学生考试记录信息", response = TOeExamRecord.class)})
  123. public Result examRecordQuery(@ApiParam(value = "学生ID", required = true) @RequestParam Long studentId, @ApiParam(value = "考试id", required = false) @RequestParam(required = false) Long examId, @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber, @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
  124. if (Objects.isNull(studentId) || Objects.equals(studentId, "")) {
  125. throw new BusinessException(ExceptionResultEnum.STUDENT_ID_IS_NULL);
  126. }
  127. return ResultUtil.ok(teStudentService.studentExamRecordQuery(new Page<>(pageNumber, pageSize), studentId, examId));
  128. }
  129. @ApiOperation(value = "底照上传")
  130. @RequestMapping(value = "/base_photo/upload", method = RequestMethod.POST)
  131. @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
  132. public Result photoUpload(@ApiParam(value = "证件号", required = true) @RequestParam String identity,
  133. @ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
  134. @ApiParam(value = "md5", required = true) @RequestParam String md5) {
  135. if (StringUtils.isBlank(identity)) {
  136. throw new BusinessException("证件号不能为空");
  137. }
  138. if (file == null) {
  139. throw new BusinessException("文件不能为空");
  140. }
  141. if (StringUtils.isBlank(md5)) {
  142. throw new BusinessException("md5不能为空");
  143. }
  144. TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
  145. return ResultUtil.ok(teStudentService.photoUpload(tbUser.getOrgId(), identity, file, md5));
  146. }
  147. }