TRBasicInfoController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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.deepoove.poi.data.style.CellStyle;
  9. import com.deepoove.poi.data.style.ParagraphStyle;
  10. import com.deepoove.poi.data.style.RowStyle;
  11. import com.qmth.boot.api.constant.ApiConstant;
  12. import com.qmth.distributed.print.business.bean.dto.report.*;
  13. import com.qmth.distributed.print.business.bean.result.ScoreResult;
  14. import com.qmth.distributed.print.business.bean.result.report.ReportResult;
  15. import com.qmth.distributed.print.business.bean.result.report.word.CourseBasicBean;
  16. import com.qmth.distributed.print.business.bean.result.report.word.CourseReportBean;
  17. import com.qmth.distributed.print.business.entity.TRBasicInfo;
  18. import com.qmth.distributed.print.business.entity.TRExamStudent;
  19. import com.qmth.distributed.print.business.service.PrintCommonService;
  20. import com.qmth.distributed.print.business.service.TRBasicInfoService;
  21. import com.qmth.distributed.print.business.service.TRExamStudentService;
  22. import com.qmth.teachcloud.common.annotation.OperationLogDetail;
  23. import com.qmth.teachcloud.common.contant.SystemConstant;
  24. import com.qmth.teachcloud.common.entity.SysUser;
  25. import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
  26. import com.qmth.teachcloud.common.util.ResultUtil;
  27. import com.qmth.teachcloud.common.util.ServletUtil;
  28. import com.qmth.teachcloud.mark.entity.MarkPaper;
  29. import com.qmth.teachcloud.mark.service.MarkPaperService;
  30. import io.swagger.annotations.*;
  31. import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
  32. import org.apache.poi.xwpf.usermodel.XWPFTableCell;
  33. import org.springframework.transaction.annotation.Transactional;
  34. import org.springframework.util.CollectionUtils;
  35. import org.springframework.validation.BindingResult;
  36. import org.springframework.web.bind.annotation.*;
  37. import javax.annotation.Resource;
  38. import javax.validation.Valid;
  39. import javax.validation.constraints.Max;
  40. import javax.validation.constraints.Min;
  41. import java.io.IOException;
  42. import java.util.*;
  43. /**
  44. * <p>
  45. * 报告基本情况表 前端控制器
  46. * </p>
  47. *
  48. * @author wangliang
  49. * @since 2024-02-18
  50. */
  51. @Api(tags = "课程目标达成度-报告基本情况Controller")
  52. @RestController
  53. @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_COURSE_DEGREE)
  54. public class TRBasicInfoController {
  55. @Resource
  56. PrintCommonService printCommonService;
  57. @Resource
  58. MarkPaperService markPaperService;
  59. @Resource
  60. TRBasicInfoService trBasicInfoService;
  61. @Resource
  62. TRExamStudentService trExamStudentService;
  63. @ApiOperation(value = "报告管理列表")
  64. @RequestMapping(value = "/report/list", method = RequestMethod.POST)
  65. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
  66. @ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = ScoreResult.class)})
  67. public Object reportList(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
  68. @ApiParam(value = "课程编码") @RequestParam(required = false) String courseCode,
  69. @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
  70. @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
  71. return ResultUtil.ok(printCommonService.scoreList(new Page<>(pageNumber, pageSize), examId, courseCode));
  72. }
  73. @ApiOperation(value = "查看报告")
  74. @RequestMapping(value = "/report/view", method = RequestMethod.POST)
  75. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
  76. @ApiResponses({@ApiResponse(code = 200, message = "查看报告", response = ReportResult.class)})
  77. @Transactional
  78. public Object reportView(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
  79. @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
  80. @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) {
  81. MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(examId, paperNumber);
  82. Objects.requireNonNull(markPaper, "未找到科目信息");
  83. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  84. TRBasicInfo trBasicInfo = trBasicInfoService.getOne(new QueryWrapper<TRBasicInfo>().lambda().eq(TRBasicInfo::getExamId, examId).eq(TRBasicInfo::getCourseCode, courseCode).eq(TRBasicInfo::getPaperNumber, paperNumber));
  85. if (Objects.isNull(trBasicInfo)) {
  86. trBasicInfo = trBasicInfoService.getReportView(trBasicInfo, markPaper, sysUser.getId());
  87. } else {
  88. ReportCourseBasicInfoDto reportCourseBasicInfoDto = new ReportCourseBasicInfoDto(trBasicInfo);
  89. ReportCourseEvaluationSpreadDto reportCourseEvaluationSpreadDto = Objects.nonNull(trBasicInfo.getCourseEvaluationSpread()) ? JSONObject.parseObject(trBasicInfo.getCourseEvaluationSpread(), ReportCourseEvaluationSpreadDto.class) : null;
  90. ReportCourseEvaluationResultDto reportCourseEvaluationResultDto = Objects.nonNull(trBasicInfo.getCourseEvaluationResult()) ? JSONObject.parseObject(trBasicInfo.getCourseEvaluationResult(), ReportCourseEvaluationResultDto.class) : null;
  91. ReportCourseEvaluationResultDetailDto reportCourseEvaluationResultDetailDto = null;
  92. List<TRExamStudent> trExamStudentList = trExamStudentService.list(new QueryWrapper<TRExamStudent>().lambda().eq(TRExamStudent::getrBasicInfoId, trBasicInfo.getId()));
  93. if (!CollectionUtils.isEmpty(trExamStudentList)) {
  94. List<ReportExamStudentDto> examStudentList = new ArrayList<>(trExamStudentList.size());
  95. for (TRExamStudent trExamStudent : trExamStudentList) {
  96. examStudentList.add(new ReportExamStudentDto(trExamStudent));
  97. }
  98. reportCourseEvaluationResultDetailDto = new ReportCourseEvaluationResultDetailDto(examStudentList);
  99. }
  100. trBasicInfo.setReportResult(new ReportResult(new ReportCommonDto(examId, courseCode, markPaper.getCourseName(), paperNumber), reportCourseBasicInfoDto, reportCourseEvaluationSpreadDto, reportCourseEvaluationResultDto, reportCourseEvaluationResultDetailDto));
  101. }
  102. trBasicInfo.updateInfo(sysUser.getId());
  103. //课程目标达成评价明细结果-课程目标达成评价值图
  104. trBasicInfoService.saveOrUpdate(trBasicInfo);
  105. return ResultUtil.ok(trBasicInfo.getReportResult());
  106. }
  107. @ApiOperation(value = "保存报告")
  108. @RequestMapping(value = "/report/save", method = RequestMethod.POST)
  109. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UPDATE)
  110. @ApiResponses({@ApiResponse(code = 200, message = "保存报告", response = Object.class)})
  111. @Transactional
  112. public Object reportSave(@ApiParam(value = "保存报告结构", required = true) @Valid @RequestBody TRBasicInfo trBasicInfo, BindingResult bindingResult) {
  113. if (bindingResult.hasErrors()) {
  114. return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
  115. }
  116. SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
  117. TRBasicInfo trBasicInfoDb = trBasicInfoService.getOne(new QueryWrapper<TRBasicInfo>().lambda().eq(TRBasicInfo::getExamId, trBasicInfo.getExamId()).eq(TRBasicInfo::getCourseCode, trBasicInfo.getCourseCode()).eq(TRBasicInfo::getPaperNumber, trBasicInfo.getPaperNumber()));
  118. if (Objects.isNull(trBasicInfoDb)) {
  119. trBasicInfoDb = new TRBasicInfo(trBasicInfo, sysUser.getId());
  120. MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(trBasicInfo.getExamId(), trBasicInfo.getPaperNumber());
  121. Objects.requireNonNull(markPaper, "未找到科目信息");
  122. trBasicInfoDb = trBasicInfoService.getReportView(trBasicInfoDb, markPaper, sysUser.getId());
  123. } else {
  124. trBasicInfoDb.updateInfo(trBasicInfo, sysUser.getId());
  125. }
  126. return ResultUtil.ok(trBasicInfoService.saveOrUpdate(trBasicInfoDb));
  127. }
  128. @ApiOperation(value = "导出报告")
  129. @RequestMapping(value = "/report/export", method = RequestMethod.POST)
  130. @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EXPORT)
  131. @ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = Object.class)})
  132. public void reportExport(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
  133. @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
  134. @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
  135. TRBasicInfo trBasicInfo = trBasicInfoService.getOne(new QueryWrapper<TRBasicInfo>().lambda().eq(TRBasicInfo::getExamId, examId).eq(TRBasicInfo::getCourseCode, courseCode).eq(TRBasicInfo::getPaperNumber, paperNumber));
  136. Objects.requireNonNull(trBasicInfo, "没有报告信息");
  137. Objects.requireNonNull(trBasicInfo.getCourseEvaluationResult(), "没有课程目标信息");
  138. Objects.requireNonNull(trBasicInfo.getCourseEvaluationResultDetail(), "没有课程考生信息");
  139. //评价样本的基本信息
  140. String period = Objects.nonNull(trBasicInfo.getPeriod()) ? trBasicInfo.getPeriod() : null;
  141. String credit = Objects.nonNull(trBasicInfo.getCredit()) ? trBasicInfo.getCredit() : null;
  142. period = Objects.nonNull(credit) ? period + "/" + credit : period;
  143. ReportCourseEvaluationResultDto reportCourseEvaluationResultDto = JSONObject.parseObject(trBasicInfo.getCourseEvaluationResult(), ReportCourseEvaluationResultDto.class);
  144. CourseBasicBean courseBasicBean = new CourseBasicBean(trBasicInfo.getCourseName(),
  145. trBasicInfo.getCourseCode(), null, trBasicInfo.getCourseType(),
  146. period, null, null, trBasicInfo.getDirector(),
  147. DateUtil.format(new Date(trBasicInfo.getCreateTime()), SystemConstant.DEFAULT_DATE_PATTERN),
  148. "测试:我们的目标是没有目标", reportCourseEvaluationResultDto.getTargetList().size());
  149. CourseReportBean courseReportBean = new CourseReportBean(trBasicInfo.getOpenTime() + "《" + trBasicInfo.getCourseName() + "》", courseBasicBean);
  150. JSONObject jsonObject = JSONObject.parseObject(trBasicInfo.getCourseEvaluationResultDetail());
  151. List<CourseTargetWordDto> courseTargetWordDtoList = JSONArray.parseArray(jsonObject.get("targetWordMap").toString(), CourseTargetWordDto.class);
  152. List<CourseTargetWebDto> courseTargetWebDtoList = JSONArray.parseArray(jsonObject.get("targetWebMap").toString(), CourseTargetWebDto.class);
  153. //table1-课程目标目标与毕业要求指标点的对应关系
  154. List<String> header2_1List = new ArrayList<>(Arrays.asList("课程目标", "支撑毕业要求")), header2_2List = new ArrayList<>();
  155. header2_2List.addAll(header2_1List);
  156. header2_1List.add("考核/评价环节及目标分值");
  157. courseReportBean.setCourseTargetTable1(trBasicInfoService.buildWordTable1(courseTargetWordDtoList, header2_1List, header2_2List));
  158. //table2-课程目标达成评价依据
  159. courseReportBean.setCourseTargetTable2(trBasicInfoService.buildWordTable2(courseTargetWordDtoList, courseTargetWebDtoList, header2_1List, header2_2List));
  160. //table3-课程课后作业考核/评价内容及目标分值
  161. courseReportBean.setCourseTargetTable3(trBasicInfoService.buildWordTable3(courseTargetWordDtoList));
  162. //table4-课程期末考试考核/评价内容及目标分值
  163. courseReportBean.setCourseTargetTable4(trBasicInfoService.buildWordTable4(courseTargetWordDtoList));
  164. //examstudent-课程目标达成评价依据-考生
  165. // List<TRExamStudent> trExamStudentList = trExamStudentService.list(new QueryWrapper<TRExamStudent>().lambda().eq(TRExamStudent::getrBasicInfoId, trBasicInfo.getId()));
  166. // if (!CollectionUtils.isEmpty(trExamStudentList)) {
  167. //// List<FinalScoreResult> finalScoreResultList = tcFinalScoreService.examStudentOverview(trBasicInfo.getExamId(), trBasicInfo.getCourseCode(), trBasicInfo.getPaperNumber());//考生成绩
  168. //// Map<String, FinalScoreResult> finalScoreResultMap = finalScoreResultList.stream().collect(Collectors.toMap(FinalScoreResult::getStudentCode, Function.identity(), (dto1, dto2) -> dto1));
  169. //
  170. // List<CellRenderData> examStudent_cells_1 = new ArrayList<>(), examStudent_cells_2 = new ArrayList<>(), examStudent_cells_3 = new ArrayList<>(), examStudent_cells_4 = new ArrayList<>(), examStudent_cells_5 = new ArrayList<>();
  171. // examStudent_cells_1.add(Cells.of("序号").center().create());
  172. // examStudent_cells_1.add(Cells.of("学号").center().create());
  173. // examStudent_cells_1.add(Cells.of("姓名").center().create());
  174. // examStudent_cells_1.add(Cells.of("行政班级").center().create());
  175. // examStudent_cells_2.addAll(examStudent_cells_1);
  176. //
  177. // examStudent_cells_3.add(Cells.of("课程目标考核要素的目标分").center().create());
  178. // examStudent_cells_3.add(Cells.of("").center().create());
  179. // examStudent_cells_3.add(Cells.of("").center().create());
  180. // examStudent_cells_3.add(Cells.of("").center().create());
  181. //
  182. // examStudent_cells_4.add(Cells.of("课程目标考核要素的平均分").center().create());
  183. // examStudent_cells_4.add(Cells.of("").center().create());
  184. // examStudent_cells_4.add(Cells.of("").center().create());
  185. // examStudent_cells_4.add(Cells.of("").center().create());
  186. //
  187. // examStudent_cells_5.add(Cells.of("各课程目标平均分").center().create());
  188. // examStudent_cells_5.add(Cells.of("").center().create());
  189. // examStudent_cells_5.add(Cells.of("").center().create());
  190. // examStudent_cells_5.add(Cells.of("").center().create());
  191. //
  192. // List<ExamStudentTableBean> examStudentTableBeanList = new ArrayList<>();
  193. // int seq5 = 0;
  194. // Map<Long, Integer> targetUsualScoreSizeMap = new HashMap<>();
  195. // trExamStudentList.remove(trExamStudentList.size() - 1);
  196. // TRExamStudent trExamStudentTemp = trExamStudentList.get(0);
  197. //
  198. // //首行
  199. // if (Objects.nonNull(trExamStudentTemp.getResultDetail())) {
  200. // List<ReportExamStudentTargetDto> reportExamStudentTargetDtoList = JSONArray.parseArray(trExamStudentTemp.getResultDetail(), ReportExamStudentTargetDto.class);
  201. // for (ReportExamStudentTargetDto reportExamStudentTargetDto : reportExamStudentTargetDtoList) {
  202. // examStudent_cells_1.add(Cells.of(reportExamStudentTargetDto.getTargetName()).center().create());
  203. // ReportExamStudentUsualScoreDto reportExamStudentUsualScoreDto = reportExamStudentTargetDto.getUsualScore();
  204. // //平常作业
  205. // if (Objects.nonNull(reportExamStudentUsualScoreDto) && !CollectionUtils.isEmpty(reportExamStudentUsualScoreDto.getScoreList())) {
  206. // List<ReportExamStudentUsualScoreObjDto> reportExamStudentUsualScoreObjDtoList = reportExamStudentUsualScoreDto.getScoreList();
  207. // for (ReportExamStudentUsualScoreObjDto reportExamStudentUsualScoreObjDto : reportExamStudentUsualScoreObjDtoList) {
  208. // if (!targetUsualScoreSizeMap.containsKey(reportExamStudentTargetDto.getTargetId())) {
  209. // targetUsualScoreSizeMap.put(reportExamStudentTargetDto.getTargetId(), 1);
  210. // } else {
  211. // Integer size = targetUsualScoreSizeMap.get(reportExamStudentTargetDto.getTargetId());
  212. // targetUsualScoreSizeMap.put(reportExamStudentTargetDto.getTargetId(), size++);
  213. // }
  214. // examStudent_cells_1.add(Cells.of("").center().create());
  215. // //报错暂时去掉,记得恢复
  216. //// examStudent_cells_2.add(Cells.of(reportExamStudentUsualScoreObjDto.getName()).center().create());
  217. // }
  218. // }
  219. // //期末考试
  220. // ReportExamStudentFinalScoreDto reportExamStudentFinalScoreDto = reportExamStudentTargetDto.getFinalScore();
  221. // if (Objects.nonNull(reportExamStudentFinalScoreDto) && !CollectionUtils.isEmpty(reportExamStudentFinalScoreDto.getDimensionList())) {
  222. // examStudent_cells_2.add(Cells.of("期末考试").center().create());
  223. // }
  224. // }
  225. // examStudent_cells_1.add(Cells.of("综合成绩").center().create());
  226. // examStudent_cells_2.add(Cells.of("综合成绩").center().create());
  227. // }
  228. //
  229. // for (int i = 0; i < trExamStudentList.size(); i++) {
  230. // TRExamStudent trExamStudent = trExamStudentList.get(i);
  231. // LinkedMultiValueMap<Long, Map<String, ExamStudentScoreBean>> scoreMap = new LinkedMultiValueMap<>();
  232. // if (Objects.nonNull(trExamStudent.getResultDetail())) {
  233. // List<ReportExamStudentTargetDto> reportExamStudentTargetDtoList = JSONArray.parseArray(trExamStudent.getResultDetail(), ReportExamStudentTargetDto.class);
  234. // for (ReportExamStudentTargetDto reportExamStudentTargetDto : reportExamStudentTargetDtoList) {
  235. // if (Objects.nonNull(reportExamStudentTargetDto)) {
  236. // ReportExamStudentUsualScoreDto reportExamStudentUsualScoreDto = reportExamStudentTargetDto.getUsualScore();
  237. // //平常作业
  238. // if (Objects.nonNull(reportExamStudentUsualScoreDto) && !CollectionUtils.isEmpty(reportExamStudentUsualScoreDto.getScoreList())) {
  239. // List<ReportExamStudentUsualScoreObjDto> reportExamStudentUsualScoreObjDtoList = reportExamStudentUsualScoreDto.getScoreList();
  240. // for (ReportExamStudentUsualScoreObjDto reportExamStudentUsualScoreObjDto : reportExamStudentUsualScoreObjDtoList) {
  241. //// scoreMap.add(reportExamStudentTargetDto.getTargetId(), Collections.singletonMap(reportExamStudentUsualScoreObjDto.getName(), new ExamStudentScoreBean(reportExamStudentUsualScoreObjDto.getScore())));
  242. // }
  243. // }
  244. // //期末考试
  245. // ReportExamStudentFinalScoreDto reportExamStudentFinalScoreDto = reportExamStudentTargetDto.getFinalScore();
  246. // if (Objects.nonNull(reportExamStudentFinalScoreDto) && !CollectionUtils.isEmpty(reportExamStudentFinalScoreDto.getDimensionList())) {
  247. // Double sumScore = reportExamStudentFinalScoreDto.getDimensionList().stream().mapToDouble(DimensionDto::getDimensionScore).sum();
  248. // scoreMap.add(reportExamStudentTargetDto.getTargetId(), Collections.singletonMap("期末考试", new ExamStudentScoreBean(sumScore)));
  249. // }
  250. // }
  251. // }
  252. // seq5 = seq5 + 1;
  253. // examStudentTableBeanList.add(new ExamStudentTableBean(seq5, trExamStudent.getStudentCode(), trExamStudent.getName(), trExamStudent.getAdministrativeClass(), scoreMap, 0.0d));
  254. // }
  255. // }
  256. //
  257. // String title = trBasicInfo.getTeachingObject();
  258. // String sumTitle = "学生共${sum}名";
  259. // sumTitle = sumTitle.replace("${sum}", trExamStudentList.size() + "");
  260. //
  261. // courseReportBean.setExamStudentTitle1(title + sumTitle);
  262. // courseReportBean.setExamStudentTitle2(title + "《" + courseReportBean.getCourseBasicBean().getCourseName() + "》");
  263. //
  264. // RowRenderData[] rowRenderDataExamStudent = new RowRenderData[trExamStudentList.size() + 5];
  265. //
  266. // RowRenderData examStudent_header_1 = new RowRenderData();
  267. // examStudent_header_1.setCells(examStudent_cells_1);
  268. // examStudent_header_1.setRowStyle(this.getHeadRowStyle());
  269. //
  270. // RowRenderData examStudent_header_2 = new RowRenderData();
  271. // examStudent_header_2.setCells(examStudent_cells_2);
  272. // examStudent_header_2.setRowStyle(this.getHeadRowStyle());
  273. //
  274. // for (int i = 0; i < examStudentTableBeanList.size(); i++) {
  275. // ExamStudentTableBean e = examStudentTableBeanList.get(i);
  276. // RowRenderData examStudent_row = new RowRenderData();
  277. // List<CellRenderData> examStudent_cells = new ArrayList<>();
  278. // examStudent_cells.add(Cells.of(e.getNum().toString()).create());
  279. // examStudent_cells.add(Cells.of(e.getStudentCode()).create());
  280. // examStudent_cells.add(Cells.of(e.getName()).create());
  281. // examStudent_cells.add(Cells.of(e.getAdministrativeClass()).create());
  282. //
  283. // String key = null;
  284. // LinkedMultiValueMap<Long, Map<String, ExamStudentScoreBean>> map = e.getMap();
  285. // for (Map.Entry<Long, List<Map<String, ExamStudentScoreBean>>> entry : map.entrySet()) {
  286. // List<Map<String, ExamStudentScoreBean>> list = entry.getValue();
  287. // BigDecimal courseSumAvg = new BigDecimal(0);
  288. // for (int y = 0; y < list.size(); y++) {
  289. // Map<String, ExamStudentScoreBean> m = list.get(y);
  290. // for (Map.Entry<String, ExamStudentScoreBean> entry1 : m.entrySet()) {
  291. // courseSumAvg = courseSumAvg.add(new BigDecimal(entry1.getValue().getScore()));
  292. // entry1.getValue().setAllScore(new BigDecimal(new Random().nextInt(10) + 1).doubleValue());
  293. // key = entry1.getKey();
  294. // examStudent_cells.add(Cells.of(entry1.getValue().getScore().toString()).create());
  295. // }
  296. // if (y == list.size() - 1) {
  297. // courseSumAvg = courseSumAvg.divide(new BigDecimal(list.size()), 2, BigDecimal.ROUND_HALF_UP)
  298. // .setScale(2, BigDecimal.ROUND_HALF_UP);
  299. // list.get(y).get(key).setAvgAllScore(courseSumAvg.doubleValue());
  300. // }
  301. // }
  302. // }
  303. // if (i == examStudentTableBeanList.size() - 1) {
  304. // LinkedMultiValueMap<Long, Map<String, ExamStudentScoreBean>> map1 = e.getMap();
  305. // for (Map.Entry<Long, List<Map<String, ExamStudentScoreBean>>> entry1 : map1.entrySet()) {
  306. // List<Map<String, ExamStudentScoreBean>> list1 = entry1.getValue();
  307. // for (int k = 0; k < list1.size(); k++) {
  308. // Map<String, ExamStudentScoreBean> m = list1.get(k);
  309. // for (Map.Entry<String, ExamStudentScoreBean> entry2 : m.entrySet()) {
  310. // examStudent_cells_3.add(Cells.of(entry2.getValue().getTargetAllAvgScore().toString()).create());
  311. // examStudent_cells_4.add(Cells.of(entry2.getValue().getAllScore().toString()).create());
  312. // }
  313. // }
  314. // examStudent_cells_5.add(Cells.of(list1.get(list1.size() - 1).get(key).getAvgAllScore().toString()).create());
  315. // for (int k = 1; k < list1.size(); k++) {
  316. // examStudent_cells_5.add(Cells.of("").create());
  317. // }
  318. // }
  319. // examStudent_cells_3.add(Cells.of(e.getSumScore().toString()).create());
  320. // examStudent_cells_4.add(Cells.of(e.getSumScore().toString()).create());
  321. // examStudent_cells_5.add(Cells.of("").create());
  322. // }
  323. // examStudent_cells.add(Cells.of(e.getSumScore().toString()).create());
  324. // examStudent_row.setCells(examStudent_cells);
  325. // examStudent_row.setRowStyle(this.getRowStyle());
  326. // rowRenderDataExamStudent[i + 2] = examStudent_row;
  327. // }
  328. //
  329. // rowRenderDataExamStudent[0] = examStudent_header_1;
  330. // rowRenderDataExamStudent[1] = examStudent_header_2;
  331. // RowRenderData examStudent_row3 = new RowRenderData();
  332. // examStudent_row3.setCells(examStudent_cells_3);
  333. // examStudent_row3.setRowStyle(this.getRowStyle());
  334. // RowRenderData examStudent_row4 = new RowRenderData();
  335. // examStudent_row4.setCells(examStudent_cells_4);
  336. // examStudent_row4.setRowStyle(this.getRowStyle());
  337. // RowRenderData examStudent_row5 = new RowRenderData();
  338. // examStudent_row5.setCells(examStudent_cells_5);
  339. // examStudent_row5.setRowStyle(this.getRowStyle());
  340. //
  341. // rowRenderDataExamStudent[rowRenderDataExamStudent.length - 3] = examStudent_row3;
  342. // rowRenderDataExamStudent[rowRenderDataExamStudent.length - 2] = examStudent_row4;
  343. // rowRenderDataExamStudent[rowRenderDataExamStudent.length - 1] = examStudent_row5;
  344. //
  345. // // 表格合并,根据坐标
  346. // MergeCellRule mergeCellRuleExamStudent = MergeCellRule.builder().build();
  347. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(0, 0), MergeCellRule.Grid.of(1, 0)));
  348. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(0, 1), MergeCellRule.Grid.of(1, 1)));
  349. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(0, 2), MergeCellRule.Grid.of(1, 2)));
  350. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(0, 3), MergeCellRule.Grid.of(1, 3)));
  351. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(rowRenderDataExamStudent.length - 3, 0), MergeCellRule.Grid.of(rowRenderDataExamStudent.length - 3, 3)));
  352. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(rowRenderDataExamStudent.length - 2, 0), MergeCellRule.Grid.of(rowRenderDataExamStudent.length - 2, 3)));
  353. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(rowRenderDataExamStudent.length - 1, 0), MergeCellRule.Grid.of(rowRenderDataExamStudent.length - 1, 3)));
  354. //
  355. // //动态扩展列
  356. // AtomicInteger initNum = new AtomicInteger(4);
  357. // targetUsualScoreSizeMap.forEach((k, v) -> {
  358. // int increaseNum = 1;
  359. // while (increaseNum <= v) {
  360. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(0, initNum.get()), MergeCellRule.Grid.of(0, initNum.get() + increaseNum)));
  361. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(rowRenderDataExamStudent.length - 1, initNum.get()), MergeCellRule.Grid.of(rowRenderDataExamStudent.length - 1, initNum.get() + increaseNum)));
  362. // increaseNum++;
  363. // }
  364. // initNum.set(initNum.get() + increaseNum);
  365. // });
  366. // mergeCellRuleExamStudent.getMapping().add(new MergeCellRule.GridRule(MergeCellRule.Grid.of(0, initNum.get()), MergeCellRule.Grid.of(1, initNum.get())));
  367. //
  368. // Tables.TableBuilder tableBuilderExamStudent = Tables.ofPercentWidth("100%");
  369. // for (int i = 0; i < rowRenderDataExamStudent.length; i++) {
  370. // tableBuilderExamStudent.addRow(rowRenderDataExamStudent[i]);
  371. // }
  372. // TableRenderData tableRenderDataExamStudent = tableBuilderExamStudent.mergeRule(mergeCellRuleExamStudent).left().create();
  373. // courseReportBean.setExamStudentTable1(tableRenderDataExamStudent);
  374. // }
  375. XWPFTemplate template = XWPFTemplate.compile("/Users/king/git/teachcloud-server/distributed-print/src/main/resources/static/course_degree_report.docx").render(courseReportBean);
  376. template.writeToFile("/Users/king/Downloads/demo_course_degree_report.docx");
  377. }
  378. /**
  379. * 获取行样式
  380. *
  381. * @return
  382. */
  383. protected RowStyle getRowStyle() {
  384. RowStyle rowStyle = new RowStyle();
  385. ParagraphStyle paragraphStyle = new ParagraphStyle();
  386. paragraphStyle.setAlign(ParagraphAlignment.LEFT);
  387. CellStyle cellStyle = new CellStyle();
  388. cellStyle.setDefaultParagraphStyle(paragraphStyle);
  389. cellStyle.setVertAlign(XWPFTableCell.XWPFVertAlign.CENTER);
  390. rowStyle.setDefaultCellStyle(cellStyle);
  391. return rowStyle;
  392. }
  393. /**
  394. * 获取行样式
  395. *
  396. * @return
  397. */
  398. protected RowStyle getHeadRowStyle() {
  399. RowStyle rowStyle = new RowStyle();
  400. ParagraphStyle paragraphStyle = new ParagraphStyle();
  401. paragraphStyle.setAlign(ParagraphAlignment.CENTER);
  402. CellStyle cellStyle = new CellStyle();
  403. cellStyle.setDefaultParagraphStyle(paragraphStyle);
  404. cellStyle.setBackgroundColor("F2F2F2");
  405. rowStyle.setDefaultCellStyle(cellStyle);
  406. return rowStyle;
  407. }
  408. }