diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailImgVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailImgVO.java new file mode 100644 index 0000000..abb312d --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailImgVO.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.safeproduct.vo; + +import cn.afterturn.easypoi.entity.ImageEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +@ApiModel(value = "演练记录表VO类") +public class RehearsalRecordDetailImgVO extends RehearsalRecordDetailVO{ + + @ApiModelProperty("图片列表") + private List images; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailStrVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailStrVO.java new file mode 100644 index 0000000..2a7c8bf --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailStrVO.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.safeproduct.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +@ApiModel(value = "演练记录表VO类") +public class RehearsalRecordDetailStrVO extends RehearsalRecordDetailVO{ + + @ApiModelProperty("图片列表") + private List images; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java index e1d414f..545065f 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalRecordDetailVO.java @@ -55,9 +55,6 @@ public class RehearsalRecordDetailVO { @ApiModelProperty("演练科目") private String subject; - @ApiModelProperty("图片列表") - private List images; - @ApiModelProperty("年份") private String year; diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java index 2b9b50c..4018a62 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java @@ -19,10 +19,13 @@ import com.hnac.hzims.safeproduct.mapper.RehearsalRecordMapper; import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; import com.hnac.hzims.safeproduct.utils.BaseUtil; import com.hnac.hzims.safeproduct.utils.TimeUtils; +import com.hnac.hzims.safeproduct.vo.RehearsalRecordDetailImgVO; +import com.hnac.hzims.safeproduct.vo.RehearsalRecordDetailStrVO; import com.hnac.hzims.safeproduct.vo.RehearsalRecordDetailVO; import com.hnac.hzims.safeproduct.vo.RehearsalRecordlVO; import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.support.Query; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -150,23 +153,6 @@ public class RehearsalRecordServiceImpl extends ServiceImpl list = new ArrayList<>(); - if (StringUtils.isNotEmpty(rehearsalRecordDetailVO.getImgPath())) { - String[] imgArr = rehearsalRecordDetailVO.getImgPath().split(","); - for (String img : imgArr) { - ImageEntity imageEntity = new ImageEntity(BaseUtil.imgToByte(savePath + - BaseUtil.downloadFileByUrl(img, savePath)), 180, 150); - list.add(imageEntity); - } - } else { - // 添加空的ImageEntity,防止数据填入时显示"{{" - ImageEntity imageEntity = new ImageEntity(); - // 设置空字符串,防止空指针报错 - imageEntity.setUrl(""); - list.add(imageEntity); - } - rehearsalRecordDetailVO.setImages(list); // 记录:换行符使用\r\n String standardRecord = rehearsalRecordDetailVO.getRecord().replaceAll("\n", "\r\n"); rehearsalRecordDetailVO.setRecord(standardRecord); @@ -186,7 +172,28 @@ public class RehearsalRecordServiceImpl extends ServiceImpl params = BaseUtil.obj2Map(rehearsalRecordDetailVO); + // 图片 + Map params; + if (StringUtils.isNotEmpty(rehearsalRecordDetailVO.getImgPath())) { + List list = new ArrayList<>(); + RehearsalRecordDetailImgVO imgVO = new RehearsalRecordDetailImgVO(); + BeanUtils.copyProperties(rehearsalRecordDetailVO, imgVO); + String[] imgArr = rehearsalRecordDetailVO.getImgPath().split(","); + for (String img : imgArr) { + ImageEntity imageEntity = new ImageEntity(BaseUtil.imgToByte(savePath + + BaseUtil.downloadFileByUrl(img, savePath)), 180, 150); + list.add(imageEntity); + } + imgVO.setImages(list); + params = BaseUtil.obj2Map(imgVO); + } else { + List list = new ArrayList<>(); + list.add(""); + RehearsalRecordDetailStrVO strVO = new RehearsalRecordDetailStrVO(); + BeanUtils.copyProperties(rehearsalRecordDetailVO, strVO); + strVO.setImages(list); + params = BaseUtil.obj2Map(strVO); + } String templateFile = "template/演练记录表" + SafeProductConstant.DOCX_SUFFIX; String wordPath = savePath + "/演练记录表" + SafeProductConstant.DOCX_SUFFIX; String pdfPath = savePath + "/演练记录表" + SafeProductConstant.PDF_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 3c84c29..da74c7f 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 @@ -119,6 +119,7 @@ public class BaseUtil { XWPFDocument xwpfDocument = null; try { xwpfDocument = WordExportUtil.exportWord07(templatePath, params); + // 超链接处理 if (findName != null && !findName.isEmpty()) { String findText = params.get(findName).toString(); if (findText != null && !findText.isEmpty()) { @@ -142,6 +143,7 @@ public class BaseUtil { } } } + // 表格处理 if (templatePath.equals("template/卫生自查表.docx")) { formatHygieneRecordTable(xwpfDocument); } @@ -151,6 +153,36 @@ public class BaseUtil { return xwpfDocument; } + /** + * 车辆检查表格式处理 + * @param xwpfDocument word文件类 + */ + private static void formatCarCheckRecordTable(XWPFDocument xwpfDocument) { + // 获取文档中所有的表格 + List tableList = xwpfDocument.getTables(); + if (tableList.size() > 0) { + // 循环表格 + for (XWPFTable table : tableList) { + // 获取表格所有行数 + List rows = table.getRows(); + // 第五行到倒数第三行为需合并区域 + for (int row = 5; row < rows.size() - 2;) { + 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); + row = index; + } + } + } + } private static void insertJsonArrayIntoParagraph(JSONArray jsonArray, XWPFParagraph paragraph) throws IOException { for (int i = 0; i < jsonArray.length(); i++) { @@ -175,6 +207,7 @@ public class BaseUtil { } } } + /** * 卫生自查表格式处理 * @param xwpfDocument word文件类 diff --git a/hzims-service/safeproduct/src/main/resources/template/演练记录表.docx b/hzims-service/safeproduct/src/main/resources/template/演练记录表.docx index c83a99c..38209f5 100644 Binary files a/hzims-service/safeproduct/src/main/resources/template/演练记录表.docx and b/hzims-service/safeproduct/src/main/resources/template/演练记录表.docx differ