TCPaperStructController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package com.qmth.distributed.print.api;
  2. import com.google.gson.reflect.TypeToken;
  3. import com.qmth.boot.api.constant.ApiConstant;
  4. import com.qmth.distributed.print.business.bean.dto.CourseWeightDto;
  5. import com.qmth.distributed.print.business.bean.excel.PaperStructDto;
  6. import com.qmth.distributed.print.business.bean.params.report.PaperStructParams;
  7. import com.qmth.distributed.print.business.bean.result.CourseWeightResult;
  8. import com.qmth.distributed.print.business.bean.result.EditResult;
  9. import com.qmth.distributed.print.business.bean.result.report.PaperStructDimensionResult;
  10. import com.qmth.distributed.print.business.entity.TCPaperStruct;
  11. import com.qmth.distributed.print.business.service.TCFinalScoreService;
  12. import com.qmth.distributed.print.business.service.TCPaperStructService;
  13. import com.qmth.distributed.print.business.service.TRBasicInfoService;
  14. import com.qmth.teachcloud.common.annotation.OperationLogDetail;
  15. import com.qmth.teachcloud.common.contant.SystemConstant;
  16. import com.qmth.teachcloud.common.entity.MarkQuestion;
  17. import com.qmth.teachcloud.common.entity.SysUser;
  18. import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
  19. import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
  20. import com.qmth.teachcloud.common.util.*;
  21. import com.qmth.teachcloud.mark.entity.MarkPaper;
  22. import com.qmth.teachcloud.mark.service.MarkPaperService;
  23. import com.qmth.teachcloud.mark.service.MarkQuestionService;
  24. import io.swagger.annotations.*;
  25. import org.apache.commons.collections4.CollectionUtils;
  26. import org.slf4j.Logger;
  27. import org.slf4j.LoggerFactory;
  28. import org.springframework.beans.BeanUtils;
  29. import org.springframework.transaction.annotation.Transactional;
  30. import org.springframework.validation.BindingResult;
  31. import org.springframework.web.bind.annotation.*;
  32. import org.springframework.web.multipart.MultipartFile;
  33. import javax.annotation.Resource;
  34. import javax.validation.Valid;
  35. import java.io.IOException;
  36. import java.math.BigDecimal;
  37. import java.util.ArrayList;
  38. import java.util.List;
  39. import java.util.Objects;
  40. /**
  41. * <p>
  42. * 试卷结构 前端控制器
  43. * </p>
  44. *
  45. * @author wangliang
  46. * @since 2024-02-18
  47. */
  48. @Api(tags = "课程目标达成度-成绩管理-试卷结构Controller")
  49. @RestController
  50. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_COURSE_DEGREE)
  51. public class TCPaperStructController {
  52. private final static Logger log = LoggerFactory.getLogger(TCPaperStructController.class);
  53. @Resource
  54. TCFinalScoreService tcFinalScoreService;
  55. @Resource
  56. MarkQuestionService markQuestionService;
  57. @Resource
  58. TCPaperStructService tcPaperStructService;
  59. @Resource
  60. MarkPaperService markPaperService;
  61. @Resource
  62. RedisUtil redisUtil;
  63. @Resource
  64. TRBasicInfoService trBasicInfoService;
  65. @ApiOperation(value = "导入试卷结构")
  66. @RequestMapping(value = "/final_score/paper_struct/import", method = RequestMethod.POST)
  67. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.IMPORT)
  68. @ApiResponses({@ApiResponse(code = 200, message = "导入成功", response = EditResult.class)})
  69. public Result finalScorePaperStructImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
  70. @ApiParam(value = "考试id", required = true) @RequestParam Long examId,
  71. @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
  72. @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
  73. tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
  74. return ResultUtil.ok(tcPaperStructService.paperStructExcelImport(file, examId, courseCode, paperNumber));
  75. }
  76. @ApiOperation(value = "期末成绩试卷蓝图保存")
  77. @RequestMapping(value = "/final_score/paper_struct/save", method = RequestMethod.POST)
  78. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UPDATE)
  79. @ApiResponses({@ApiResponse(code = 200, message = "试卷蓝图保存", response = Object.class)})
  80. @Transactional
  81. public Result finalScorePaperStructSave(@ApiParam(value = "试卷蓝图结构", required = true) @Valid @RequestBody PaperStructParams paperStructParams, BindingResult bindingResult) throws IOException {
  82. if (bindingResult.hasErrors()) {
  83. return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
  84. }
  85. tcFinalScoreService.getFinalScoreSyncLock(paperStructParams.getExamId(), paperStructParams.getCourseCode(), paperStructParams.getPaperNumber());
  86. CourseWeightResult courseWeightResult = trBasicInfoService.findCourseWeightResultRmi(paperStructParams.getExamId(), paperStructParams.getCourseCode());
  87. for (CourseWeightDto c : courseWeightResult.getSubmitForm()) {
  88. for (PaperStructDimensionResult paperStructDimensionResult : paperStructParams.getPaperStruct()) {
  89. Objects.requireNonNull(paperStructDimensionResult.getMainNumber(), "大题号为空");
  90. Objects.requireNonNull(paperStructDimensionResult.getSubNumber(), "小题号为空");
  91. if (!CollectionUtils.isEmpty(paperStructDimensionResult.getTargetList()) && paperStructDimensionResult.getTargetList().size() > 1) {
  92. throw ExceptionResultEnum.ERROR.exception("一个题只能属于一个目标");
  93. }
  94. }
  95. Double score = paperStructParams.getPaperStruct().stream().filter(s -> Objects.equals(s.getCourseTargetName(), c.getCourseTargetName())).mapToDouble(PaperStructDimensionResult::getScore).sum();
  96. if (new BigDecimal(score).compareTo(c.getTotalWeight()) == 1) {
  97. throw ExceptionResultEnum.ERROR.exception("[" + c.getCourseTargetName() + "]知识点小题总分大于该课程目标分,请重新设置");
  98. }
  99. }
  100. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  101. TCPaperStruct tcPaperStructDb = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(paperStructParams.getExamId(), paperStructParams.getCourseCode(), paperStructParams.getPaperNumber());
  102. if (Objects.isNull(tcPaperStructDb)) {
  103. MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(paperStructParams.getExamId(), paperStructParams.getPaperNumber());
  104. Objects.requireNonNull(markPaper, "未找到科目信息");
  105. tcPaperStructDb = new TCPaperStruct(paperStructParams.getExamId(), paperStructParams.getCourseCode(), markPaper.getCourseName(), paperStructParams.getPaperNumber(), JacksonUtil.parseJson(paperStructParams.getPaperStruct()), sysUser.getId(), courseWeightResult.getDimensionSign());
  106. tcPaperStructService.save(tcPaperStructDb);
  107. } else {
  108. TCPaperStruct tcPaperStructSource = new TCPaperStruct();
  109. BeanUtils.copyProperties(tcPaperStructDb, tcPaperStructSource);
  110. tcPaperStructDb.updateInfo(JacksonUtil.parseJson(paperStructParams.getPaperStruct()), sysUser.getId());
  111. if (!tcPaperStructDb.equals(tcPaperStructSource)) {
  112. if (Objects.nonNull(tcPaperStructDb.getDimensionSign()) && tcPaperStructDb.getDimensionSign().longValue() != courseWeightResult.getDimensionSign().longValue()) {
  113. trBasicInfoService.clearReportData(tcPaperStructDb.getExamId(), tcPaperStructDb.getCourseCode(), tcPaperStructDb.getPaperNumber(), false);
  114. }
  115. tcPaperStructDb.setDimensionSign(courseWeightResult.getDimensionSign());
  116. tcPaperStructService.updateById(tcPaperStructDb);
  117. }
  118. }
  119. return ResultUtil.ok(true);
  120. }
  121. @ApiOperation(value = "期末成绩试卷蓝图查询")
  122. @RequestMapping(value = "/final_score/paper_struct/query", method = RequestMethod.POST)
  123. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
  124. @ApiResponses({@ApiResponse(code = 200, message = "试卷蓝图保存", response = PaperStructDimensionResult.class)})
  125. public Result finalScorePaperStructQuery(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
  126. @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
  127. @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
  128. tcFinalScoreService.getFinalScoreSyncLock(examId, courseCode, paperNumber);
  129. List<PaperStructDimensionResult> paperStructDimensionResultList = null;
  130. TCPaperStruct tcPaperStruct = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
  131. if (Objects.isNull(tcPaperStruct)) {
  132. List<MarkQuestion> markQuestionList = markQuestionService.listQuestionByExamIdAndPaperNumberAndPaperType(examId, paperNumber, null);
  133. if (CollectionUtils.isEmpty(markQuestionList)) {
  134. throw ExceptionResultEnum.ERROR.exception("未找到试卷结构");
  135. }
  136. paperStructDimensionResultList = new ArrayList<>(markQuestionList.size());
  137. for (MarkQuestion markQuestion : markQuestionList) {
  138. paperStructDimensionResultList.add(new PaperStructDimensionResult(markQuestion.getMainNumber(), markQuestion.getSubNumber(), markQuestion.getTotalScore()));
  139. }
  140. } else {
  141. CourseWeightResult courseWeightResult = trBasicInfoService.findCourseWeightResultRmi(examId, courseCode);
  142. if (Objects.nonNull(tcPaperStruct.getDimensionSign()) && tcPaperStruct.getDimensionSign().longValue() != courseWeightResult.getDimensionSign().longValue()) {
  143. trBasicInfoService.clearReportData(examId, courseCode, paperNumber, false);
  144. paperStructDimensionResultList = new ArrayList<>();
  145. if (Objects.nonNull(tcPaperStruct.getPaperStruct())) {
  146. List<PaperStructDto> paperStructDtoList = GsonUtil.fromJson(tcPaperStruct.getPaperStruct(), new TypeToken<List<PaperStructDto>>() {
  147. }.getType());
  148. paperStructDimensionResultList = new ArrayList<>(paperStructDtoList.size());
  149. for (PaperStructDto paperStructDto : paperStructDtoList) {
  150. paperStructDimensionResultList.add(new PaperStructDimensionResult(paperStructDto.getMainNumber(), paperStructDto.getSubNumber(), paperStructDto.getScore()));
  151. }
  152. } else {
  153. return this.finalScorePaperStructQuery(examId, courseCode, paperNumber);
  154. }
  155. } else {
  156. if (Objects.nonNull(tcPaperStruct.getPaperStructDimension())) {
  157. paperStructDimensionResultList = GsonUtil.fromJson(tcPaperStruct.getPaperStructDimension(), new TypeToken<List<PaperStructDimensionResult>>() {
  158. }.getType());
  159. } else if (Objects.nonNull(tcPaperStruct.getPaperStruct())) {
  160. List<PaperStructDto> paperStructDtoList = GsonUtil.fromJson(tcPaperStruct.getPaperStruct(), new TypeToken<List<PaperStructDto>>() {
  161. }.getType());
  162. paperStructDimensionResultList = new ArrayList<>(paperStructDtoList.size());
  163. for (PaperStructDto paperStructDto : paperStructDtoList) {
  164. paperStructDimensionResultList.add(new PaperStructDimensionResult(paperStructDto.getMainNumber(), paperStructDto.getSubNumber(), paperStructDto.getScore()));
  165. }
  166. } else {
  167. return this.finalScorePaperStructQuery(examId, courseCode, paperNumber);
  168. }
  169. }
  170. }
  171. return ResultUtil.ok(paperStructDimensionResultList);
  172. }
  173. }