diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java index 1aeae76..52bee71 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java @@ -47,4 +47,10 @@ public class HygieneRecordDetailVO { @ApiModelProperty("检查信息列表") private List checkList; + + @ApiModelProperty("年份") + private String year; + + @ApiModelProperty("月份") + private String month; } 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 608f1ed..48d21fb 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 @@ -94,7 +94,7 @@ public class HygieneRecordServiceImpl extends ServiceImpl hygienePlanEntity.getStandardScore()) { @@ -122,7 +122,7 @@ public class HygieneRecordServiceImpl extends ServiceImpl hygienePlanEntity.getStandardScore()) { @@ -138,11 +138,11 @@ public class HygieneRecordServiceImpl extends ServiceImpl checkDetailVOList = new ArrayList<>(); - for (int i = 0; i < zoneIds.length ; i++) { + for (int i = 0; i < zoneIds.length; i++) { HygieneZoneDetailVO zoneDetailVO = new HygieneZoneDetailVO(); HygieneZoneEntity hygieneZoneEntity = hygieneZoneService.getById(zoneIds[i]); BeanUtils.copyProperties(hygieneZoneEntity, zoneDetailVO); @@ -169,6 +169,29 @@ public class HygieneRecordServiceImpl extends ServiceImpl checkList = hygieneRecordDetailVO.getCheckList(); + List res = new ArrayList<>(); + checkList.forEach(item -> { + String[] checkItem = item.getCheckItem().split(","); + String[] checkItemScore = item.getCheckItemScore().split(","); + for (int i = 0; i < checkItem.length; i++) { + HygieneZoneDetailVO hygieneZoneDetailVO = new HygieneZoneDetailVO(); + hygieneZoneDetailVO.setZone(item.getZone()); + hygieneZoneDetailVO.setPrincipal(item.getPrincipal()); + hygieneZoneDetailVO.setResult(item.getResult()); + hygieneZoneDetailVO.setScore(item.getScore()); + hygieneZoneDetailVO.setCheckItem(checkItem[i]); + hygieneZoneDetailVO.setCheckItemScore(checkItemScore[i]); + res.add(hygieneZoneDetailVO); + } + }); + // 表头 + String code = hygieneRecordDetailVO.getCode(); + hygieneRecordDetailVO.setYear(code.substring(4, 8)); + hygieneRecordDetailVO.setMonth(code.substring(8, 10)); + hygieneRecordDetailVO.setCheckList(res); Map params = BaseUtil.obj2Map(hygieneRecordDetailVO); String templateFile = "template/卫生自查表" + SafeProductConstant.DOCX_SUFFIX; String wordPath = savePath + "/卫生自查表" + SafeProductConstant.DOCX_SUFFIX; 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 3118280..20028cd 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 @@ -6,6 +6,10 @@ import com.hnac.hzims.safeproduct.constants.SafeProductConstant; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFTable; +import org.apache.poi.xwpf.usermodel.XWPFTableCell; +import org.apache.poi.xwpf.usermodel.XWPFTableRow; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.ObjectUtil; @@ -106,11 +110,15 @@ public class BaseUtil { * 数据写入 * @param templatePath 模板文件路径 * @param params 数据参数 + * @return 文件 */ public static XWPFDocument fillDocument(String templatePath, Map params) { XWPFDocument xwpfDocument = null; try { xwpfDocument = WordExportUtil.exportWord07(templatePath, params); + if (templatePath.equals("template/卫生自查表.docx")) { + formatHygieneRecordTable(xwpfDocument); + } } catch (Exception e) { log.error("数据写入异常: {}", e.getMessage()); e.printStackTrace(); @@ -119,6 +127,60 @@ public class BaseUtil { } /** + * 卫生自查表格式处理 + * @param xwpfDocument word文件类 + */ + private static void formatHygieneRecordTable(XWPFDocument xwpfDocument) { + // 获取文档中所有的表格 + List tableList = xwpfDocument.getTables(); + if (tableList.size() > 0) { + // 循环表格 + for (XWPFTable table : tableList) { + // 获取表格所有行数 + List rows = table.getRows(); + // 第三行到倒数第二行为需合并区域 + for (int row = 3; row < rows.size() - 1;) { + 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); + mergeCellsVertically(table, 1, row, index - 1); + mergeCellsVertically(table, 4, row, index - 1); + mergeCellsVertically(table, 5, row, index - 1); + row = index; + } + } + } + } + + /** + * word单元格行合并 + * @param table 表格 + * @param col 合并行所在列 + * @param startRow 开始行 + * @param endRow 结束行 + */ + public static void mergeCellsVertically(XWPFTable table, int col, int startRow, int endRow) { + for (int i = startRow; i <= endRow; i++) { + XWPFTableCell cell = table.getRow(i).getCell(col); + if (i == startRow) { + // The first merged cell is set with RESTART merge value + cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); + } else { + // Cells which join (merge) the first one, are set with CONTINUE + cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); + } + } + } + + /** * 读取本地pdf,这里设置的是预览 * @param response 响应类 * @param filePath 文件路径 diff --git a/hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx b/hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx index 06133d5..141b2ae 100644 Binary files a/hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx and b/hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx differ