diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/Constants.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/Constants.java index fad01b2..eceea8d 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/Constants.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/Constants.java @@ -8,7 +8,7 @@ import lombok.NoArgsConstructor; * @Author: py */ public class Constants { - public final static String APP_NAME = "hzims-safeproduct-hx"; + public final static String APP_NAME = "hzims-safeproduct"; /** * 安全生产标准化评审标准 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/controller/RehearsalController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalController.java index 72f5a91..4182137 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalController.java @@ -2,7 +2,6 @@ package com.hnac.hzims.safeproduct.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.common.utils.Condition; import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; import com.hnac.hzims.safeproduct.service.IRehearsalPlanService; diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java index 8bbf0ea..f65f90d 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java @@ -2,7 +2,6 @@ package com.hnac.hzims.safeproduct.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.common.utils.Condition; import com.hnac.hzims.safeproduct.dto.TestDTO; import com.hnac.hzims.safeproduct.dto.TestScoreDTO; import com.hnac.hzims.safeproduct.dto.TrainRecordDTO; 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/service/impl/TestServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java index c40c905..09cc4df 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java @@ -70,7 +70,7 @@ public class TestServiceImpl extends ServiceImpl impleme TestEntity test = getTestByCode(testEntity.getCode()); // 获取姓名数组 String people = test.getPeopleName(); - String[] person = people.split(",|,"); + String[] person = people.split(","); // 新增参考人员成绩数据 List scoreList = getReferenceTestScore(test, person); return R.status(testScoreService.saveBatch(scoreList)); @@ -169,7 +169,7 @@ public class TestServiceImpl extends ServiceImpl impleme boolean removeByIds = testScoreService.removeByIds(scoreIds); // 若删除成功,新增新的考试成绩数据 if (removeByIds) { - String[] person = testEntity.getPeopleName().split(",|,"); + String[] person = testEntity.getPeopleName().split(","); // 新增参考人员成绩数据 List scoreList = getReferenceTestScore(testEntity, person); return testScoreService.saveBatch(scoreList); 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