Browse Source

fix: 解决卫生自查表格式不一致的问题

zhongwei
liwen 10 months ago
parent
commit
5b3c5538db
  1. 6
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java
  2. 33
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java
  3. 62
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java
  4. BIN
      hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx

6
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java

@ -47,4 +47,10 @@ public class HygieneRecordDetailVO {
@ApiModelProperty("检查信息列表") @ApiModelProperty("检查信息列表")
private List<HygieneZoneDetailVO> checkList; private List<HygieneZoneDetailVO> checkList;
@ApiModelProperty("年份")
private String year;
@ApiModelProperty("月份")
private String month;
} }

33
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java

@ -94,7 +94,7 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
hygieneRecordEntity.setWeekNum(weekNum); hygieneRecordEntity.setWeekNum(weekNum);
// 综合评分判断 // 综合评分判断
HygienePlanEntity hygienePlanEntity = hygienePlanMapper.selectById(hygieneRecordEntity.getHygienePlanId()); HygienePlanEntity hygienePlanEntity = hygienePlanMapper.selectById(hygieneRecordEntity.getHygienePlanId());
String[] scores = hygieneRecordEntity.getComprehensiveScore().split(",|,"); String[] scores = hygieneRecordEntity.getComprehensiveScore().split(",");
for (String score : scores) { for (String score : scores) {
int sc = Integer.parseInt(score); int sc = Integer.parseInt(score);
if (sc > hygienePlanEntity.getStandardScore()) { if (sc > hygienePlanEntity.getStandardScore()) {
@ -122,7 +122,7 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
hygieneRecordEntity.setWeekNum(weekNum); hygieneRecordEntity.setWeekNum(weekNum);
// 综合评分判断 // 综合评分判断
HygienePlanEntity hygienePlanEntity = hygienePlanMapper.selectById(hygieneRecordEntity.getHygienePlanId()); HygienePlanEntity hygienePlanEntity = hygienePlanMapper.selectById(hygieneRecordEntity.getHygienePlanId());
String[] scores = hygieneRecordEntity.getComprehensiveScore().split(",|,"); String[] scores = hygieneRecordEntity.getComprehensiveScore().split(",");
for (String score : scores) { for (String score : scores) {
int sc = Integer.parseInt(score); int sc = Integer.parseInt(score);
if (sc > hygienePlanEntity.getStandardScore()) { if (sc > hygienePlanEntity.getStandardScore()) {
@ -138,9 +138,9 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
@Override @Override
public HygieneRecordDetailVO getRecordDetail(Long id) { public HygieneRecordDetailVO getRecordDetail(Long id) {
HygieneRecordDetailVO recordDetailVO = baseMapper.getRecordDetail(id); HygieneRecordDetailVO recordDetailVO = baseMapper.getRecordDetail(id);
String[] zoneIds = recordDetailVO.getHygieneZoneIds().split(",|,"); String[] zoneIds = recordDetailVO.getHygieneZoneIds().split(",");
String[] results = recordDetailVO.getCheckResult().split(",|,"); String[] results = recordDetailVO.getCheckResult().split(",");
String[] scores = recordDetailVO.getComprehensiveScore().split(",|,"); String[] scores = recordDetailVO.getComprehensiveScore().split(",");
List<HygieneZoneDetailVO> checkDetailVOList = new ArrayList<>(); List<HygieneZoneDetailVO> checkDetailVOList = new ArrayList<>();
for (int i = 0; i < zoneIds.length; i++) { for (int i = 0; i < zoneIds.length; i++) {
HygieneZoneDetailVO zoneDetailVO = new HygieneZoneDetailVO(); HygieneZoneDetailVO zoneDetailVO = new HygieneZoneDetailVO();
@ -169,6 +169,29 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
@Override @Override
public void exportHygieneRecordData(Long id, HttpServletResponse response) { public void exportHygieneRecordData(Long id, HttpServletResponse response) {
HygieneRecordDetailVO hygieneRecordDetailVO = this.getRecordDetail(id); HygieneRecordDetailVO hygieneRecordDetailVO = this.getRecordDetail(id);
// 数据处理
// 检查项
List<HygieneZoneDetailVO> checkList = hygieneRecordDetailVO.getCheckList();
List<HygieneZoneDetailVO> 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<String, Object> params = BaseUtil.obj2Map(hygieneRecordDetailVO); Map<String, Object> params = BaseUtil.obj2Map(hygieneRecordDetailVO);
String templateFile = "template/卫生自查表" + SafeProductConstant.DOCX_SUFFIX; String templateFile = "template/卫生自查表" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/卫生自查表" + SafeProductConstant.DOCX_SUFFIX; String wordPath = savePath + "/卫生自查表" + SafeProductConstant.DOCX_SUFFIX;

62
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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument; 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.log.exception.ServiceException;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
@ -106,11 +110,15 @@ public class BaseUtil {
* 数据写入 * 数据写入
* @param templatePath 模板文件路径 * @param templatePath 模板文件路径
* @param params 数据参数 * @param params 数据参数
* @return 文件
*/ */
public static XWPFDocument fillDocument(String templatePath, Map<String, Object> params) { public static XWPFDocument fillDocument(String templatePath, Map<String, Object> params) {
XWPFDocument xwpfDocument = null; XWPFDocument xwpfDocument = null;
try { try {
xwpfDocument = WordExportUtil.exportWord07(templatePath, params); xwpfDocument = WordExportUtil.exportWord07(templatePath, params);
if (templatePath.equals("template/卫生自查表.docx")) {
formatHygieneRecordTable(xwpfDocument);
}
} catch (Exception e) { } catch (Exception e) {
log.error("数据写入异常: {}", e.getMessage()); log.error("数据写入异常: {}", e.getMessage());
e.printStackTrace(); e.printStackTrace();
@ -119,6 +127,60 @@ public class BaseUtil {
} }
/** /**
* 卫生自查表格式处理
* @param xwpfDocument word文件类
*/
private static void formatHygieneRecordTable(XWPFDocument xwpfDocument) {
// 获取文档中所有的表格
List<XWPFTable> tableList = xwpfDocument.getTables();
if (tableList.size() > 0) {
// 循环表格
for (XWPFTable table : tableList) {
// 获取表格所有行数
List<XWPFTableRow> 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,这里设置的是预览 * 读取本地pdf,这里设置的是预览
* @param response 响应类 * @param response 响应类
* @param filePath 文件路径 * @param filePath 文件路径

BIN
hzims-service/safeproduct/src/main/resources/template/卫生自查表.docx

Binary file not shown.
Loading…
Cancel
Save