InspectionItemPlanConclusionController.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.ym.mec.web.controller;
  2. import com.ym.mec.biz.dal.dao.InspectionItemPlanDao;
  3. import com.ym.mec.biz.dal.entity.InspectionItemPlan;
  4. import com.ym.mec.biz.service.InspectionItemPlanConclusionService;
  5. import com.ym.mec.common.controller.BaseController;
  6. import com.ym.mec.common.entity.HttpResponseResult;
  7. import com.ym.mec.util.date.DateUtil;
  8. import com.ym.mec.util.excel.POIUtil;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiImplicitParam;
  11. import io.swagger.annotations.ApiImplicitParams;
  12. import io.swagger.annotations.ApiOperation;
  13. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  14. import org.apache.poi.ss.util.CellRangeAddress;
  15. import org.apache.poi.ss.util.CellRangeAddressList;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.security.access.prepost.PreAuthorize;
  18. import org.springframework.web.bind.annotation.*;
  19. import javax.servlet.http.HttpServletResponse;
  20. import java.io.IOException;
  21. import java.io.OutputStream;
  22. import java.util.*;
  23. @Api(tags = "巡查结果")
  24. @RequestMapping("inspectionItemPlanConclusion")
  25. @RestController
  26. public class InspectionItemPlanConclusionController extends BaseController {
  27. @Autowired
  28. private InspectionItemPlanConclusionService InspectionItemPlanConclusionService;
  29. @Autowired
  30. private InspectionItemPlanDao inspectionItemPlanDao;
  31. @ApiOperation(value = "获取日程的巡查结果")
  32. @GetMapping("/getPlanConclusion")
  33. @PreAuthorize("@pcs.hasPermissions('inspectionItemPlanConclusion/getPlanConclusion')")
  34. @ApiImplicitParams({@ApiImplicitParam(name = "planId", value = "日程id", required = true, dataType = "int")})
  35. public HttpResponseResult<List<Map<String, String>>> getPlanConclusion(Long planId) {
  36. return succeed(InspectionItemPlanConclusionService.getPlanConclusion(planId));
  37. }
  38. @ApiOperation(value = "导出日程的巡查结果")
  39. @GetMapping("/exportPlanConclusion")
  40. @PreAuthorize("@pcs.hasPermissions('inspectionItemPlanConclusion/exportPlanConclusion')")
  41. @ApiImplicitParams({@ApiImplicitParam(name = "planId", value = "日程id", required = true, dataType = "int")})
  42. public void exportPlanConclusion(Long planId, HttpServletResponse response) throws Exception {
  43. List<Map<String, String>> conclusions = InspectionItemPlanConclusionService.getPlanConclusion(planId);
  44. if (conclusions.size() <= 0) {
  45. response.setStatus(200);
  46. response.setContentType("Content-Type: application/json;charset=UTF-8");
  47. response.getOutputStream().write("{\"data\": null, \"code\": 500, \"status\": false, \"msg\": \"没有可导出的记录\"}".getBytes());
  48. response.flushBuffer();
  49. return;
  50. }
  51. OutputStream outputStream = response.getOutputStream();
  52. try {
  53. conclusions.forEach(conclusionMap -> {
  54. conclusionMap.forEach((key, val) -> {
  55. if (val.equals("1")) {
  56. conclusionMap.put(key, "√");
  57. } else if (val.equals("0")) {
  58. conclusionMap.put(key, "×");
  59. }
  60. });
  61. });
  62. List<String> bodyList = new LinkedList<>();
  63. conclusions.get(0).forEach((key, vak) -> {
  64. bodyList.add(key);
  65. });
  66. InspectionItemPlan planInfo = inspectionItemPlanDao.getPlanInfo(planId);
  67. String dateTime = DateUtil.dateToString(planInfo.getPlanStart(), "yyyy-MM-dd") + " " + DateUtil.dateToString(planInfo.getPlanStart(), "HH:mm") + "~" + DateUtil.dateToString(planInfo.getPlanEnd(), "HH:mm");
  68. String[] header = {"所属分部", planInfo.getOrganName(), "", "合作单位", planInfo.getCooperationName(), "", "巡查乐团", planInfo.getMusicGroupName(), "", "", "", "", "", "", "", ""};
  69. String[] header1 = {"乐团主管", planInfo.getRealName(), "", "巡查时间", dateTime, "", "提交时间", DateUtil.dateToString(planInfo.getSubmitedTime(), "yyyy-MM-dd HH:mm"), "", "", "", "", "", "", ""};
  70. String[] header2 = {"处理方式", planInfo.getMemo(), "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
  71. String[] header3 = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
  72. String[] header4 = {"巡查项目", "课前管理", "", "", "", "", "课中管理", "", "", "", "", "", "", "课后管理", "", ""};
  73. String[] header5 = {"", "老师是否提前准备板书(本课内容、作业)", "老师是否佩戴工牌", "老师是否仪容仪表整洁", "老师是否携带乐器", "老师是否携带教学资料、设备", "老师是否合理安排学员座位", "乐器箱包、书包是否摆放整齐", "课堂纪律是否保持良好", "老师是否全程站立教学", "老师是否全程使用节拍器或教学音频", "未发现私换乐器", "老师是否将上课照片/视频发送到声部群", "老师是否保持教室环境卫生", "老师是否关好所有电源、门窗", "老师是否有序组织学员放学"};
  74. List<String[]> headers = new LinkedList<>();
  75. headers.add(header);
  76. headers.add(header1);
  77. headers.add(header2);
  78. headers.add(header3);
  79. headers.add(header4);
  80. headers.add(header5);
  81. String[] body = bodyList.toArray(new String[bodyList.size()]);
  82. HSSFWorkbook workbook = POIUtil.multipleHeaderExportExcel(headers, body, conclusions);
  83. //合并单元格处理
  84. CellRangeAddressList cellRangeAddressList = new CellRangeAddressList();
  85. cellRangeAddressList.addCellRangeAddress(0, 1, 0, 2);
  86. cellRangeAddressList.addCellRangeAddress(0, 4, 0, 5);
  87. cellRangeAddressList.addCellRangeAddress(0, 7, 0, 8);
  88. cellRangeAddressList.addCellRangeAddress(1, 1, 1, 2);
  89. cellRangeAddressList.addCellRangeAddress(1, 4, 1, 5);
  90. cellRangeAddressList.addCellRangeAddress(1, 7, 1, 8);
  91. cellRangeAddressList.addCellRangeAddress(2, 1, 2, 2);
  92. cellRangeAddressList.addCellRangeAddress(2, 3, 2, 8);
  93. cellRangeAddressList.addCellRangeAddress(3, 0, 3, 15);
  94. cellRangeAddressList.addCellRangeAddress(4, 0, 5, 0);
  95. cellRangeAddressList.addCellRangeAddress(4, 1, 4, 5);
  96. cellRangeAddressList.addCellRangeAddress(4, 6, 4, 12);
  97. cellRangeAddressList.addCellRangeAddress(4, 13, 4, 15);
  98. for (CellRangeAddress cellRangeAddress : cellRangeAddressList.getCellRangeAddresses()) {
  99. workbook.getSheetAt(0).addMergedRegion(cellRangeAddress);
  100. }
  101. response.setContentType("application/octet-stream");
  102. response.setHeader("Content-Disposition", "attachment;filename=conclusion-" + DateUtil.getDate(new Date()) + ".xls");
  103. response.flushBuffer();
  104. outputStream = response.getOutputStream();
  105. workbook.write(outputStream);
  106. outputStream.flush();
  107. } catch (Exception e) {
  108. e.printStackTrace();
  109. } finally {
  110. if (outputStream != null) {
  111. try {
  112. outputStream.close();
  113. } catch (IOException e) {
  114. e.printStackTrace();
  115. }
  116. }
  117. }
  118. }
  119. }