diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/HygieneEvaluationExportDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneEvaluationExportVO.java similarity index 79% rename from hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/HygieneEvaluationExportDTO.java rename to hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneEvaluationExportVO.java index 2987b84..5ec081f 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/HygieneEvaluationExportDTO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneEvaluationExportVO.java @@ -1,6 +1,5 @@ -package com.hnac.hzims.safeproduct.dto; +package com.hnac.hzims.safeproduct.vo; -import com.hnac.hzims.safeproduct.vo.HygieneEvaluationPeopleVO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -12,8 +11,8 @@ import java.util.List; * @date 2024-08-20 */ @Data -@ApiModel(value = "卫生考核导出DTO类") -public class HygieneEvaluationExportDTO { +@ApiModel(value = "卫生考核导出VO类") +public class HygieneEvaluationExportVO { @ApiModelProperty(value = "年份") private String year; @@ -51,9 +50,6 @@ public class HygieneEvaluationExportDTO { @ApiModelProperty(value = "第五周结束日") private String fifthWeekEnd; - @ApiModelProperty(value = "备注") - private String remark; - @ApiModelProperty(value = "考核人员列表") - private List evaluationList; + private List evaluationList; } diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneEvaluationPeopleExportVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneEvaluationPeopleExportVO.java new file mode 100644 index 0000000..33ab247 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneEvaluationPeopleExportVO.java @@ -0,0 +1,41 @@ +package com.hnac.hzims.safeproduct.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liwen + * @date 2024-08-22 + */ +@Data +@ApiModel(value = "卫生考核人员导出VO类") +public class HygieneEvaluationPeopleExportVO { + + @ApiModelProperty(value = "单位") + private String unit; + + @ApiModelProperty(value = "负责人") + private String principal; + + @ApiModelProperty(value = "合计分") + private Long sumScore; + + @ApiModelProperty(value = "第一周考核分") + private Long firstWeekScore; + + @ApiModelProperty(value = "第二周考核分") + private Long secondWeekScore; + + @ApiModelProperty(value = "第三周考核分") + private Long thirdWeekScore; + + @ApiModelProperty(value = "第四周考核分") + private Long fourthWeekScore; + + @ApiModelProperty(value = "第五周考核分") + private Long fifthWeekScore; + + @ApiModelProperty(value = "备注") + private String remark; +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java index 30db487..823ae61 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java @@ -1,24 +1,19 @@ package com.hnac.hzims.safeproduct.service.impl; -import cn.afterturn.easypoi.excel.ExcelExportUtil; -import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.hutool.core.date.DatePattern; import cn.hutool.core.util.ObjectUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.safeproduct.constants.SafeProductConstant; -import com.hnac.hzims.safeproduct.dto.HygieneEvaluationExportDTO; +import com.hnac.hzims.safeproduct.vo.HygieneEvaluationExportVO; import com.hnac.hzims.safeproduct.dto.HygieneRecordDTO; import com.hnac.hzims.safeproduct.entity.HygienePlanEntity; import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity; import com.hnac.hzims.safeproduct.entity.HygieneZoneEntity; import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum; -import com.hnac.hzims.safeproduct.hazard.util.ExcelConvertPdf; import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper; import com.hnac.hzims.safeproduct.mapper.HygieneRecordMapper; import com.hnac.hzims.safeproduct.service.IHygieneRecordService; @@ -26,9 +21,6 @@ import com.hnac.hzims.safeproduct.service.IHygieneZoneService; import com.hnac.hzims.safeproduct.utils.BaseUtil; import com.hnac.hzims.safeproduct.vo.*; import com.hnac.hzinfo.exception.HzServiceException; -import com.itextpdf.text.DocumentException; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; @@ -42,14 +34,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; -import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.nio.file.Files; -import java.nio.file.Paths; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.ZoneId; @@ -339,12 +324,11 @@ public class HygieneRecordServiceImpl extends ServiceImpl weekList = page.getWeekList(); weekList.forEach(week -> { @@ -354,52 +338,70 @@ public class HygieneRecordServiceImpl extends ServiceImpl params = BaseUtil.obj2Map(exportDTO); - TemplateExportParams templateParams = new TemplateExportParams("template/卫生考核表.xlsx", true); - // 导出 - try { - String fileName = URLEncoder.encode("卫生考核表.xlsx", "UTF-8"); - response.setHeader("Content-Disposition", "attachment; filename=" + fileName); - response.setContentType("application/vnd.ms-excel;charset=utf-8"); - Workbook workbook = ExcelExportUtil.exportExcel(templateParams, params); - Sheet sheet = workbook.getSheetAt(0); - BaseUtil.mergeCell(0, 0, JSONArray.parseArray(JSON.toJSONString(exportDTO)), "unit").forEach(sheet::addMergedRegion); - BaseUtil.mergeCell(0, 7, JSONArray.parseArray(JSON.toJSONString(exportDTO)), "remark").forEach(sheet::addMergedRegion); - String pdfPath = "D://" + "/卫生考核表" + SafeProductConstant.PDF_SUFFIX; - OutputStream outputStream = Files.newOutputStream(Paths.get(pdfPath)); - ExcelConvertPdf.excelConvertPdf(workbook, outputStream); - BaseUtil.readPdf(response, pdfPath); - } catch (UnsupportedEncodingException e) { - log.error("卫生考核表导出异常-UnsupportedEncodingException:" + e.getMessage()); - } catch (DocumentException e) { - log.error("卫生考核表导出异常-DocumentException:" + e.getMessage()); - } catch (IOException e) { - log.error("卫生考核表导出异常-IOException:" + e.getMessage()); + List evaluationExportList = new ArrayList<>(); + List evaluationList = page.getEvaluationList(); + evaluationList.forEach(x -> { + HygieneEvaluationPeopleExportVO peopleExportVO = new HygieneEvaluationPeopleExportVO(); + peopleExportVO.setUnit(x.getUnit()); + peopleExportVO.setPrincipal(x.getPrincipal()); + peopleExportVO.setSumScore(x.getSumScore()); + peopleExportVO.setRemark(page.getRemark()); + List scoreList = x.getScoreList(); + scoreList.forEach(score -> { + Long weekScore = score.getScore(); + switch (score.getWeekNum()) { + case 1: + peopleExportVO.setFirstWeekScore(weekScore); + break; + case 2: + peopleExportVO.setSecondWeekScore(weekScore); + break; + case 3: + peopleExportVO.setThirdWeekScore(weekScore); + break; + case 4: + peopleExportVO.setFourthWeekScore(weekScore); + break; + case 5: + peopleExportVO.setFifthWeekScore(weekScore); + break; + } + }); + evaluationExportList.add(peopleExportVO); + }); + exportVO.setEvaluationList(evaluationExportList); + Map params = BaseUtil.obj2Map(exportVO); + String templateFile; + if (weekList.size() == 4) { + templateFile = "template/卫生考核表(四周)" + SafeProductConstant.DOCX_SUFFIX; + } else { + templateFile = "template/卫生考核表(五周)" + SafeProductConstant.DOCX_SUFFIX; } + String wordPath = "D:/" + "/卫生考核表" + SafeProductConstant.DOCX_SUFFIX; + String pdfPath = "D:/" + "/卫生考核表" + SafeProductConstant.PDF_SUFFIX; + BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, "",response); } /** diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java index 914c81f..41fe56d 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java @@ -153,6 +153,9 @@ public class BaseUtil { if ("template/车辆检查表.docx".equals(templatePath)) { formatCarCheckRecordTable(xwpfDocument); } + if ("template/卫生考核表(四周).docx".equals(templatePath) || "template/卫生考核表(五周).docx".equals(templatePath)) { + formatHygieneEvaluationTable(xwpfDocument, params); + } } catch (Exception e) { e.printStackTrace(); } @@ -160,6 +163,44 @@ public class BaseUtil { } /** + * 卫生考核表格式处理 + * @param xwpfDocument word文件类 + * @param params 数据参数 + */ + private static void formatHygieneEvaluationTable(XWPFDocument xwpfDocument, Map params) { + // 获取文档中所有的表格 + List tableList = xwpfDocument.getTables(); + if (!tableList.isEmpty()) { + // 循环表格 + for (XWPFTable table : tableList) { + // 获取表格所有行数 + List rows = table.getRows(); + // 第三行到倒数第三行为需合并区域 + for (int row = 3; row < rows.size();) { + XWPFTableCell startCell = rows.get(row).getCell(0); + String startText = startCell.getText(); + int index = row + 1; + for (; index < rows.size(); index++) { + XWPFTableCell endCell = rows.get(index).getCell(0); + String endText = endCell.getText(); + if (!startText.equals(endText)) { + break; + } + } + mergeCellsVertically(table, 0, row, index - 1); + // 判断周数:为五周时,备注在第9列;为四周时,备注在第8列 + if (ObjectUtil.isNotEmpty(params.get("fifthWeekStart"))) { + mergeCellsVertically(table, 8, row, index - 1); + } else { + mergeCellsVertically(table, 7, row, index - 1); + } + row = index; + } + } + } + } + + /** * 车辆检查表格式处理 * @param xwpfDocument word文件类 */ @@ -424,41 +465,4 @@ public class BaseUtil { throw new ServiceException("标准总分值未全部分配"); } } - - /** - * - * @param initRow 起始行数 - * @param initColumn 起始列数 - * @param data 数据 - * @param attribute 合并属性 - * @return 单元格列表 - */ - public static List mergeCell(int initRow, int initColumn, com.alibaba.fastjson.JSONArray data, String attribute) { - List result = Lists.newArrayList(); - String initAttribute = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(data.get(0))).getString(attribute); - int mergeCount = 1; - for (int index = 0; index < data.size(); index++) { - if (index == 0) { - continue; - } - com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(data.get(index))); - if (object.getString(attribute).equals(initAttribute)) { - mergeCount++; - } - else { - if (mergeCount > 1) { - result.add(new CellRangeAddress(initRow, initRow+mergeCount-1, initColumn, initColumn)); - } - initRow = initRow+mergeCount; - initAttribute = object.getString(attribute); - mergeCount = 1; - } - if (index == data.size() -1) { - if (mergeCount > 1) { - result.add(new CellRangeAddress(initRow, initRow + mergeCount-1, initColumn, initColumn)); - } - } - } - return result; - } } diff --git a/hzims-service/safeproduct/src/main/resources/template/卫生考核表(五周).docx b/hzims-service/safeproduct/src/main/resources/template/卫生考核表(五周).docx new file mode 100644 index 0000000..8129688 Binary files /dev/null and b/hzims-service/safeproduct/src/main/resources/template/卫生考核表(五周).docx differ diff --git a/hzims-service/safeproduct/src/main/resources/template/卫生考核表(四周).docx b/hzims-service/safeproduct/src/main/resources/template/卫生考核表(四周).docx new file mode 100644 index 0000000..a91c9f0 Binary files /dev/null and b/hzims-service/safeproduct/src/main/resources/template/卫生考核表(四周).docx differ diff --git a/hzims-service/safeproduct/src/main/resources/template/卫生考核表.xlsx b/hzims-service/safeproduct/src/main/resources/template/卫生考核表.xlsx deleted file mode 100644 index 93b2b21..0000000 Binary files a/hzims-service/safeproduct/src/main/resources/template/卫生考核表.xlsx and /dev/null differ