TRBasicInfoController.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. package com.qmth.distributed.print.api;
  2. import cn.hutool.core.date.DateUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.deepoove.poi.XWPFTemplate;
  8. import com.google.gson.reflect.TypeToken;
  9. import com.qmth.boot.api.annotation.Aac;
  10. import com.qmth.boot.api.constant.ApiConstant;
  11. import com.qmth.boot.api.exception.ApiException;
  12. import com.qmth.boot.core.rateLimit.annotation.RateLimit;
  13. import com.qmth.distributed.print.business.bean.dto.CourseWeightDetailDto;
  14. import com.qmth.distributed.print.business.bean.dto.CourseWeightDto;
  15. import com.qmth.distributed.print.business.bean.dto.TCUsualScoreDto;
  16. import com.qmth.distributed.print.business.bean.dto.report.*;
  17. import com.qmth.distributed.print.business.bean.result.CourseWeightResult;
  18. import com.qmth.distributed.print.business.bean.result.ScoreResult;
  19. import com.qmth.distributed.print.business.bean.result.report.PaperStructDimensionResult;
  20. import com.qmth.distributed.print.business.bean.result.report.ReportChangeResult;
  21. import com.qmth.distributed.print.business.bean.result.report.ReportResult;
  22. import com.qmth.distributed.print.business.bean.result.report.word.CourseBasicBean;
  23. import com.qmth.distributed.print.business.bean.result.report.word.CourseReportBean;
  24. import com.qmth.distributed.print.business.entity.TCPaperStruct;
  25. import com.qmth.distributed.print.business.entity.TCUsualScore;
  26. import com.qmth.distributed.print.business.entity.TRBasicInfo;
  27. import com.qmth.distributed.print.business.entity.TRExamStudent;
  28. import com.qmth.distributed.print.business.service.*;
  29. import com.qmth.teachcloud.common.annotation.OperationLogDetail;
  30. import com.qmth.teachcloud.common.contant.SystemConstant;
  31. import com.qmth.teachcloud.common.entity.BasicSchool;
  32. import com.qmth.teachcloud.common.entity.SysConfig;
  33. import com.qmth.teachcloud.common.entity.SysUser;
  34. import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
  35. import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
  36. import com.qmth.teachcloud.common.enums.ImportTemplateEnum;
  37. import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
  38. import com.qmth.teachcloud.common.service.CommonCacheService;
  39. import com.qmth.teachcloud.common.service.FileUploadService;
  40. import com.qmth.teachcloud.common.util.*;
  41. import com.qmth.teachcloud.mark.entity.MarkPaper;
  42. import io.swagger.annotations.*;
  43. import org.apache.commons.collections4.CollectionUtils;
  44. import org.apache.commons.io.FileUtils;
  45. import org.slf4j.Logger;
  46. import org.slf4j.LoggerFactory;
  47. import org.springframework.dao.DuplicateKeyException;
  48. import org.springframework.transaction.annotation.Transactional;
  49. import org.springframework.validation.BindingResult;
  50. import org.springframework.web.bind.annotation.*;
  51. import javax.annotation.Resource;
  52. import javax.validation.Valid;
  53. import javax.validation.constraints.Max;
  54. import javax.validation.constraints.Min;
  55. import java.io.File;
  56. import java.io.FileInputStream;
  57. import java.io.IOException;
  58. import java.io.InputStream;
  59. import java.math.BigDecimal;
  60. import java.util.*;
  61. import java.util.stream.Collectors;
  62. /**
  63. * <p>
  64. * 报告基本情况表 前端控制器
  65. * </p>
  66. *
  67. * @author wangliang
  68. * @since 2024-02-18
  69. */
  70. @Api(tags = "课程目标达成度-报告基本情况Controller")
  71. @RestController
  72. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_COURSE_DEGREE)
  73. public class TRBasicInfoController {
  74. private final static Logger log = LoggerFactory.getLogger(TRBasicInfoController.class);
  75. @Resource
  76. PrintCommonService printCommonService;
  77. @Resource
  78. TRBasicInfoService trBasicInfoService;
  79. @Resource
  80. TRExamStudentService trExamStudentService;
  81. @Resource
  82. CommonCacheService commonCacheService;
  83. @Resource
  84. FileUploadService fileUploadService;
  85. @Resource
  86. TCPaperStructService tcPaperStructService;
  87. @Resource
  88. TCUsualScoreService tcUsualScoreService;
  89. @ApiOperation(value = "报告管理列表")
  90. @RequestMapping(value = "/report/list", method = RequestMethod.POST)
  91. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
  92. @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = ScoreResult.class)})
  93. public Result reportList(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
  94. @ApiParam(value = "课程编码") @RequestParam(required = false) String courseCode,
  95. @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
  96. @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
  97. return ResultUtil.ok(printCommonService.scoreList(new Page<>(pageNumber, pageSize), examId, courseCode));
  98. }
  99. @ApiOperation(value = "查看报告")
  100. @RequestMapping(value = "/report/view", method = RequestMethod.POST)
  101. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
  102. @ApiResponses({@ApiResponse(code = 200, message = "查看报告", response = ReportResult.class)})
  103. @Transactional
  104. public Result reportView(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
  105. @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
  106. @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) {
  107. MarkPaper markPaper = printCommonService.getMarkPaper(examId, paperNumber);
  108. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  109. TRBasicInfo trBasicInfo = trBasicInfoService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
  110. CourseWeightResult courseWeightResult = trBasicInfoService.findCourseWeightResultRmi(examId, courseCode);
  111. TCPaperStruct tcPaperStruct = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
  112. if (Objects.nonNull(tcPaperStruct) && Objects.nonNull(tcPaperStruct.getPaperStructDimension())) {
  113. List<PaperStructDimensionResult> paperStructDimensionResultList = GsonUtil.fromJson(tcPaperStruct.getPaperStructDimension(), new TypeToken<List<PaperStructDimensionResult>>() {
  114. }.getType());
  115. for (CourseWeightDto c : courseWeightResult.getSubmitForm()) {
  116. Double score = paperStructDimensionResultList.stream().filter(s -> Objects.equals(s.getCourseTargetName(), c.getCourseTargetName())).mapToDouble(PaperStructDimensionResult::getScore).sum();
  117. Objects.requireNonNull(c.getTotalWeight(), "[" + c.getCourseTargetName() + "]未设置权重");
  118. Objects.requireNonNull(c.getTotalScore(), "[" + c.getCourseTargetName() + "]未设置目标分值");
  119. if (new BigDecimal(score).compareTo(c.getTotalWeight()) == 1) {
  120. trBasicInfoService.clearReportData(examId, courseCode, paperNumber, false);
  121. throw ExceptionResultEnum.ERROR.exception("[" + c.getCourseTargetName() + "]包含的小题总分与权重设置不一致,请到期末成绩--试卷蓝图设置里调整");
  122. }
  123. }
  124. }
  125. if (Objects.isNull(trBasicInfo)) {
  126. trBasicInfo = trBasicInfoService.getReportView(trBasicInfo, markPaper, sysUser.getId(), courseWeightResult);
  127. } else {
  128. ReportCourseEvaluationResultDto reportCourseEvaluationResultDto = Objects.nonNull(trBasicInfo.getCourseEvaluationResult()) ? JSONObject.parseObject(trBasicInfo.getCourseEvaluationResult(), ReportCourseEvaluationResultDto.class) : null;
  129. if (Objects.nonNull(reportCourseEvaluationResultDto.getWeightSettingSign()) && reportCourseEvaluationResultDto.getWeightSettingSign().longValue() != courseWeightResult.getWeightSettingSign().longValue()) {
  130. trBasicInfoService.clearReportData(examId, courseCode, paperNumber, Objects.nonNull(tcPaperStruct) && Objects.nonNull(tcPaperStruct.getDimensionSign()) && tcPaperStruct.getDimensionSign().longValue() != courseWeightResult.getDimensionSign().longValue() ? true : false);
  131. trBasicInfo = trBasicInfoService.getReportView(trBasicInfo, markPaper, sysUser.getId(), courseWeightResult);
  132. } else {
  133. ReportCourseBasicInfoDto reportCourseBasicInfoDto = new ReportCourseBasicInfoDto(trBasicInfo);
  134. ReportCourseEvaluationSpreadDto reportCourseEvaluationSpreadDto = Objects.nonNull(trBasicInfo.getCourseEvaluationSpread()) ? JSONObject.parseObject(trBasicInfo.getCourseEvaluationSpread(), ReportCourseEvaluationSpreadDto.class) : null;
  135. ReportCourseEvaluationResultDetailDto reportCourseEvaluationResultDetailDto = null;
  136. List<TRExamStudent> trExamStudentList = trExamStudentService.list(new QueryWrapper<TRExamStudent>().lambda().eq(TRExamStudent::getrBasicInfoId, trBasicInfo.getId()));
  137. if (!CollectionUtils.isEmpty(trExamStudentList)) {
  138. List<ReportExamStudentDto> examStudentList = new ArrayList<>(trExamStudentList.size());
  139. for (TRExamStudent trExamStudent : trExamStudentList) {
  140. examStudentList.add(new ReportExamStudentDto(trExamStudent));
  141. }
  142. reportCourseEvaluationResultDetailDto = new ReportCourseEvaluationResultDetailDto(examStudentList);
  143. }
  144. trBasicInfo.setReportResult(new ReportResult(new ReportCommonDto(examId, courseCode, markPaper.getCourseName(), paperNumber), reportCourseBasicInfoDto, reportCourseEvaluationSpreadDto, reportCourseEvaluationResultDto, reportCourseEvaluationResultDetailDto));
  145. }
  146. }
  147. trBasicInfo.updateInfo(sysUser.getId());
  148. //课程目标达成评价明细结果-课程目标达成评价值图
  149. trBasicInfoService.saveOrUpdate(trBasicInfo);
  150. return ResultUtil.ok(trBasicInfo.getReportResult());
  151. }
  152. @ApiOperation(value = "保存报告")
  153. @RequestMapping(value = "/report/save", method = RequestMethod.POST)
  154. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UPDATE)
  155. @ApiResponses({@ApiResponse(code = 200, message = "保存报告", response = Object.class)})
  156. @Transactional
  157. public Result reportSave(@ApiParam(value = "保存报告结构", required = true) @Valid @RequestBody TRBasicInfo trBasicInfo, BindingResult bindingResult) {
  158. if (bindingResult.hasErrors()) {
  159. return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
  160. }
  161. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  162. TRBasicInfo trBasicInfoDb = null;
  163. try {
  164. trBasicInfoDb = trBasicInfoService.queryByExamIdAndCourseCodeAndPaperNumber(trBasicInfo.getExamId(), trBasicInfo.getCourseCode(), trBasicInfo.getPaperNumber());
  165. if (Objects.isNull(trBasicInfoDb)) {
  166. trBasicInfoDb = new TRBasicInfo(trBasicInfo, sysUser.getId());
  167. MarkPaper markPaper = printCommonService.getMarkPaper(trBasicInfo.getExamId(), trBasicInfo.getPaperNumber());
  168. trBasicInfoDb = trBasicInfoService.getReportView(trBasicInfoDb, markPaper, sysUser.getId(), trBasicInfoService.findCourseWeightResultRmi(trBasicInfo.getExamId(), trBasicInfo.getCourseCode()));
  169. } else {
  170. trBasicInfoDb.updateInfo(trBasicInfo, sysUser.getId());
  171. }
  172. } catch (Exception e) {
  173. log.error(SystemConstant.LOG_ERROR, e);
  174. if (e instanceof DuplicateKeyException) {
  175. String errorColumn = e.getCause().toString();
  176. String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
  177. throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
  178. } else if (e instanceof ApiException) {
  179. ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
  180. } else {
  181. ResultUtil.error(e.getMessage());
  182. }
  183. }
  184. return ResultUtil.ok(trBasicInfoService.saveOrUpdate(trBasicInfoDb));
  185. }
  186. @ApiOperation(value = "导出报告")
  187. @RequestMapping(value = "/report/export", method = RequestMethod.POST)
  188. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EXPORT)
  189. @ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = Object.class)})
  190. @Aac(rateLimit = @RateLimit(count = 1, period = 1000L))
  191. public void reportExport(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
  192. @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
  193. @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
  194. File txtFileTemp = null, fileTemp = null;
  195. try {
  196. Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
  197. BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
  198. TRBasicInfo trBasicInfo = trBasicInfoService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
  199. Objects.requireNonNull(trBasicInfo, "没有报告信息");
  200. Objects.requireNonNull(trBasicInfo.getCourseEvaluationResult(), "没有课程目标信息");
  201. Objects.requireNonNull(trBasicInfo.getCourseEvaluationResultDetail(), "没有课程考生信息");
  202. CourseWeightResult courseWeightResult = trBasicInfoService.findCourseWeightResultRmi(examId, courseCode);
  203. TCPaperStruct tcPaperStruct = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
  204. if (Objects.nonNull(tcPaperStruct) && Objects.nonNull(tcPaperStruct.getPaperStructDimension())) {
  205. List<PaperStructDimensionResult> paperStructDimensionResultList = GsonUtil.fromJson(tcPaperStruct.getPaperStructDimension(), new TypeToken<List<PaperStructDimensionResult>>() {
  206. }.getType());
  207. for (CourseWeightDto c : courseWeightResult.getSubmitForm()) {
  208. Double score = paperStructDimensionResultList.stream().filter(s -> Objects.equals(s.getCourseTargetName(), c.getCourseTargetName())).mapToDouble(PaperStructDimensionResult::getScore).sum();
  209. Objects.requireNonNull(c.getTotalWeight(), "[" + c.getCourseTargetName() + "]未设置权重");
  210. Objects.requireNonNull(c.getTotalScore(), "[" + c.getCourseTargetName() + "]未设置目标分值");
  211. if (new BigDecimal(score).compareTo(c.getTotalWeight()) == 1) {
  212. trBasicInfoService.clearReportData(examId, courseCode, paperNumber, false);
  213. throw ExceptionResultEnum.ERROR.exception("[" + c.getCourseTargetName() + "]包含的小题总分与权重设置不一致,请到期末成绩--试卷蓝图设置里调整");
  214. }
  215. }
  216. }
  217. ReportCourseEvaluationResultDto reportCourseEvaluationResultDto = JSONObject.parseObject(trBasicInfo.getCourseEvaluationResult(), ReportCourseEvaluationResultDto.class);
  218. if (Objects.nonNull(reportCourseEvaluationResultDto.getWeightSettingSign()) && reportCourseEvaluationResultDto.getWeightSettingSign().longValue() != courseWeightResult.getWeightSettingSign().longValue()) {
  219. printCommonService.getMarkPaper(examId, paperNumber);
  220. trBasicInfoService.clearReportData(examId, courseCode, paperNumber, Objects.nonNull(tcPaperStruct) && Objects.nonNull(tcPaperStruct.getDimensionSign()) && tcPaperStruct.getDimensionSign().longValue() != courseWeightResult.getDimensionSign().longValue() ? true : false);
  221. this.reportView(examId, courseCode, paperNumber);
  222. this.reportExport(examId, courseCode, paperNumber);
  223. } else {
  224. //评价样本的基本信息
  225. String period = Objects.nonNull(trBasicInfo.getPeriod()) ? trBasicInfo.getPeriod() : null;
  226. String credit = Objects.nonNull(trBasicInfo.getCredit()) ? trBasicInfo.getCredit() : null;
  227. period = Objects.nonNull(credit) ? period + "/" + credit : period;
  228. JSONObject jsonObject = JSONObject.parseObject(trBasicInfo.getCourseEvaluationResultDetail());
  229. List<CourseTargetWordDto> courseTargetWordDtoList = JSONArray.parseArray(jsonObject.get("targetWordMap").toString(), CourseTargetWordDto.class);
  230. StringJoiner courseTarget = new StringJoiner("");
  231. courseTargetWordDtoList.stream().peek(s -> {
  232. courseTarget.add(" ").add(s.getTargetName()).add("——").add(s.getGraduationRequirementPoint()).add("\r\n");
  233. }).collect(Collectors.toList());
  234. CourseBasicBean courseBasicBean = new CourseBasicBean(trBasicInfo.getCourseName(),
  235. trBasicInfo.getCourseCode(), null, trBasicInfo.getCourseType(),
  236. period, null, null, trBasicInfo.getDirector(),
  237. DateUtil.format(new Date(trBasicInfo.getCreateTime()), SystemConstant.DEFAULT_DATE_PATTERN),
  238. courseTarget.toString(), reportCourseEvaluationResultDto.getTargetList().size());
  239. CourseReportBean courseReportBean = new CourseReportBean(trBasicInfo.getOpenTime() + "《" + trBasicInfo.getCourseName() + "》", courseBasicBean);
  240. //table1-课程目标目标与毕业要求指标点的对应关系
  241. courseReportBean.setCourseTargetTable1(trBasicInfoService.buildWordTable1(courseTargetWordDtoList));
  242. //table2-课程目标达成评价依据
  243. courseReportBean.setCourseTargetTable2(trBasicInfoService.buildWordTable2(courseTargetWordDtoList));
  244. //table3-课程课后作业考核/评价内容及目标分值
  245. courseReportBean.setCourseTargetTable3(trBasicInfoService.buildWordTable3(courseTargetWordDtoList));
  246. //table4-课程期末考试考核/评价内容及目标分值
  247. courseReportBean.setCourseTargetTable4(trBasicInfoService.buildWordTable4(courseTargetWordDtoList));
  248. //examstudent-课程目标达成评价依据-考生
  249. courseReportBean.setExamStudentTable1(trBasicInfoService.buildWordTable5(trBasicInfo, courseReportBean));
  250. InputStream inputStream = null;
  251. txtFileTemp = SystemConstant.getFileTempVar(SystemConstant.WORD_PREFIX);
  252. SysConfig sysConfig = commonCacheService.addSysConfigCache(schoolId, SystemConstant.SCHOOL_COURSE_DEGREE_TEMPLATE);
  253. if (Objects.isNull(sysConfig)) {
  254. inputStream = FileUtil.getStream("static/" + ImportTemplateEnum.STATIC_COURSE_DEGREE_REPORT.getTemplateName());
  255. } else {
  256. fileTemp = SystemConstant.getFileTempVar(SystemConstant.WORD_PREFIX);
  257. fileTemp = fileUploadService.downloadFile(Long.parseLong(sysConfig.getConfigValue()), fileTemp.getPath());
  258. inputStream = new FileInputStream(fileTemp);
  259. }
  260. FileUtils.copyInputStreamToFile(inputStream, txtFileTemp);
  261. XWPFTemplate template = XWPFTemplate.compile(txtFileTemp.getAbsolutePath()).render(courseReportBean);
  262. template.writeToFile(txtFileTemp.getAbsolutePath());
  263. // 导出
  264. String fileName = Objects.nonNull(basicSchool) ? basicSchool.getName() + "_" + courseReportBean.getTitle1() + "_" + ImportTemplateEnum.STATIC_COURSE_DEGREE_REPORT.getFileName() + SystemConstant.WORD_PREFIX : courseReportBean.getTitle1() + "_" + ImportTemplateEnum.STATIC_COURSE_DEGREE_REPORT.getFileName() + SystemConstant.WORD_PREFIX;
  265. FileUtil.outputFile(ServletUtil.getResponse(), new FileInputStream(txtFileTemp), fileName);
  266. // XWPFTemplate template = XWPFTemplate.compile("/Users/king/git/teachcloud-server/distributed-print/src/main/resources/static/course_degree_report.docx").render(courseReportBean);
  267. // template.writeToFile("/Users/king/Downloads/demo_course_degree_report.docx");
  268. }
  269. } catch (Exception e) {
  270. if (e instanceof ApiException) {
  271. ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
  272. } else {
  273. ResultUtil.error(e.getMessage());
  274. }
  275. } finally {
  276. if (Objects.nonNull(txtFileTemp)) {
  277. txtFileTemp.delete();
  278. }
  279. if (Objects.nonNull(fileTemp)) {
  280. fileTemp.delete();
  281. }
  282. }
  283. }
  284. @ApiOperation(value = "报告发生改变")
  285. @RequestMapping(value = "/report/change", method = RequestMethod.POST)
  286. @ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = Object.class)})
  287. public Result reportDataChange(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
  288. @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
  289. @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
  290. @ApiParam(value = "true:报告,false:成绩管理", required = true) @RequestParam boolean report) throws IOException {
  291. ReportChangeResult reportChangeResult = new ReportChangeResult();
  292. List<TCUsualScore> tcUsualScoreList = tcUsualScoreService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
  293. if (CollectionUtils.isNotEmpty(tcUsualScoreList)) {
  294. Set<String> usualScoreCourseSet = new LinkedHashSet<>();
  295. TCUsualScore tcUsualScore = tcUsualScoreList.get(0);
  296. List<TCUsualScoreDto> tcUsualScoreDtoList = JSONArray.parseArray(tcUsualScore.getScore(), TCUsualScoreDto.class);
  297. List<String> usualScoreList = tcUsualScoreDtoList.stream().map(s -> s.getName()).collect(Collectors.toList());
  298. List<CourseWeightDto> courseWeightDtoList = trBasicInfoService.findCourseWeightDtoRmi(examId, courseCode);
  299. List<String> courseTargetList = new ArrayList<>(courseWeightDtoList.size());
  300. if (CollectionUtils.isNotEmpty(courseWeightDtoList)) {
  301. courseWeightDtoList.stream().peek(e -> {
  302. courseTargetList.add(e.getCourseTargetName());
  303. List<CourseWeightDetailDto> courseWeightDetailDtoList = e.getEvaluationList();
  304. courseWeightDetailDtoList.stream().peek(s -> {
  305. if (Objects.nonNull(s.getEnable()) && s.getEnable() && !Objects.equals(s.getEvaluationName(), SystemConstant.FINAL_SCORE_STR)) {
  306. usualScoreCourseSet.add(s.getEvaluationName());
  307. }
  308. }).collect(Collectors.toList());
  309. }).collect(Collectors.toList());
  310. }
  311. if (CollectionUtils.isNotEmpty(usualScoreList) && CollectionUtils.isNotEmpty(usualScoreCourseSet)) {
  312. List<String> usualScoreCourseList = new ArrayList<>(usualScoreCourseSet);
  313. Collections.sort(usualScoreList);
  314. Collections.sort(usualScoreCourseList);
  315. if (!CollectionUtils.isEqualCollection(usualScoreList, usualScoreCourseList)) {
  316. reportChangeResult.setEvaluationChange(true);
  317. }
  318. }
  319. TRBasicInfo trBasicInfo = trBasicInfoService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
  320. if (Objects.nonNull(trBasicInfo) && Objects.nonNull(trBasicInfo.getCourseEvaluationResultDetail())) {
  321. JSONObject jsonObject = JSONObject.parseObject(trBasicInfo.getCourseEvaluationResultDetail());
  322. List<CourseTargetWordDto> courseTargetWordDtoList = JSONArray.parseArray(jsonObject.get("targetWordMap").toString(), CourseTargetWordDto.class);
  323. List<String> courseTargetDbList = courseTargetWordDtoList.stream().map(s -> s.getTargetName()).collect(Collectors.toList());
  324. if (CollectionUtils.isNotEmpty(courseTargetList) && CollectionUtils.isNotEmpty(courseTargetDbList)) {
  325. Collections.sort(courseTargetList);
  326. Collections.sort(courseTargetDbList);
  327. if (!CollectionUtils.isEqualCollection(courseTargetList, courseTargetDbList)) {
  328. reportChangeResult.setCourseTargetChange(true);
  329. }
  330. }
  331. }
  332. if (!report) {
  333. TCPaperStruct tcPaperStruct = tcPaperStructService.queryByExamIdAndCourseCodeAndPaperNumber(examId, courseCode, paperNumber);
  334. if (Objects.nonNull(tcPaperStruct) && Objects.nonNull(tcPaperStruct.getPaperStructDimension())) {
  335. List<PaperStructDimensionResult> paperStructDimensionResultList = GsonUtil.fromJson(tcPaperStruct.getPaperStructDimension(), new TypeToken<List<PaperStructDimensionResult>>() {
  336. }.getType());
  337. StringJoiner stringJoiner = new StringJoiner("");
  338. for (CourseWeightDto c : courseWeightDtoList) {
  339. Double score = paperStructDimensionResultList.stream().filter(s -> Objects.equals(s.getCourseTargetName(), c.getCourseTargetName())).mapToDouble(PaperStructDimensionResult::getScore).sum();
  340. if (Objects.isNull(c.getTotalWeight())) {
  341. reportChangeResult.setTargetScoreChange(true);
  342. stringJoiner.add("[").add(c.getCourseTargetName()).add("]").add("未设置权重").add("\r\n");
  343. } else if (Objects.isNull(c.getTotalScore())) {
  344. reportChangeResult.setTargetScoreChange(true);
  345. stringJoiner.add("[").add(c.getCourseTargetName()).add("]").add("未设置目标分值").add("\r\n");
  346. } else if (new BigDecimal(score).compareTo(c.getTotalWeight()) == 1) {
  347. reportChangeResult.setTargetScoreChange(true);
  348. stringJoiner.add("[").add(c.getCourseTargetName()).add("]").add("包含的小题总分与权重设置不一致,请到期末成绩--试卷蓝图设置里调整").add("\r\n");
  349. }
  350. }
  351. if (reportChangeResult.isTargetScoreChange()) {
  352. trBasicInfoService.clearReportData(examId, courseCode, paperNumber, false);
  353. reportChangeResult.setTargetScoreChangeStr(stringJoiner.toString());
  354. }
  355. }
  356. }
  357. }
  358. return ResultUtil.ok(reportChangeResult);
  359. }
  360. }