Browse Source

fix: 解决卫生表导出内容异常的问题

zhongwei
liwen 5 months ago
parent
commit
09de77d57e
  1. 4
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java
  2. 19
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

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

@ -194,8 +194,8 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
hygieneRecordDetailVO.setCheckList(res); 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 = "D:/" + "/卫生自查表" + SafeProductConstant.DOCX_SUFFIX;
String pdfPath = savePath + "/卫生自查表" + SafeProductConstant.PDF_SUFFIX; String pdfPath = "D:/" + "/卫生自查表" + SafeProductConstant.PDF_SUFFIX;
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, "",response); BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, "",response);
} }

19
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

@ -144,10 +144,10 @@ public class BaseUtil {
} }
} }
// 表格处理 // 表格处理
if (templatePath.equals("template/卫生自查表.docx")) { if ("template/卫生自查表.docx".equals(templatePath)) {
formatHygieneRecordTable(xwpfDocument); formatHygieneRecordTable(xwpfDocument);
} }
if (templatePath.equals("template/车辆检查表.docx")) { if ("template/车辆检查表.docx".equals(templatePath)) {
formatCarCheckRecordTable(xwpfDocument); formatCarCheckRecordTable(xwpfDocument);
} }
} catch (Exception e) { } catch (Exception e) {
@ -225,13 +225,18 @@ public class BaseUtil {
List<XWPFTableRow> rows = table.getRows(); List<XWPFTableRow> rows = table.getRows();
// 第三行到倒数第二行为需合并区域 // 第三行到倒数第二行为需合并区域
for (int row = 3; row < rows.size() - 1;) { for (int row = 3; row < rows.size() - 1;) {
XWPFTableCell startCell = rows.get(row).getCell(0); // 判断责任区和责任人是否完全一致,一致则合并
String startText = startCell.getText(); XWPFTableCell startFirstCell = rows.get(row).getCell(0);
String startFirstText = startFirstCell.getText();
XWPFTableCell startSecondCell = rows.get(row).getCell(1);
String startSecondText = startSecondCell.getText();
int index = row + 1; int index = row + 1;
for (; index < rows.size(); index++) { for (; index < rows.size(); index++) {
XWPFTableCell endCell = rows.get(index).getCell(0); XWPFTableCell endFirstCell = rows.get(index).getCell(0);
String endText = endCell.getText(); String endFirstText = endFirstCell.getText();
if (!startText.equals(endText)) { XWPFTableCell endSecondCell = rows.get(index).getCell(1);
String endSecondText = endSecondCell.getText();
if (!startFirstText.equals(endFirstText) || !startSecondText.equals(endSecondText)) {
break; break;
} }
} }

Loading…
Cancel
Save