Browse Source

add:导出附件增加超链接(维保记录/会议记录/培训记录/考试记录/演练记录)

zhongwei
ty 8 months ago
parent
commit
e5ff3230be
  1. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java
  2. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarMaintenanceServiceImpl.java
  3. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarUsedRecordServiceImpl.java
  4. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/ConferenceRecordServiceImpl.java
  5. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java
  6. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java
  7. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java
  8. 58
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java

@ -208,7 +208,7 @@ public class CarCheckRecordServiceImpl extends ServiceImpl<CarCheckRecordMapper,
String templateFile = "template/车辆检查表" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/车辆检查表" + SafeProductConstant.DOCX_SUFFIX;
String pdfPath = savePath + "/车辆检查表" + SafeProductConstant.PDF_SUFFIX;
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath,"", response);
}
/**

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarMaintenanceServiceImpl.java

@ -149,7 +149,7 @@ public class CarMaintenanceServiceImpl extends ServiceImpl<CarMaintenanceMapper,
String templateFile = "template/车辆维保记录单" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/车辆维保记录单" + SafeProductConstant.DOCX_SUFFIX;
String pdfPath = savePath + "/车辆维保记录单" + SafeProductConstant.PDF_SUFFIX;
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath,"filePath", response);
}
/**

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarUsedRecordServiceImpl.java

@ -139,7 +139,7 @@ public class CarUsedRecordServiceImpl extends ServiceImpl<CarUsedRecordMapper, C
String templateFile = "template/用车记录单" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/用车记录单" + SafeProductConstant.DOCX_SUFFIX;
String pdfPath = savePath + "/用车记录单" + SafeProductConstant.PDF_SUFFIX;
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, "",response);
}
/**

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/ConferenceRecordServiceImpl.java

@ -126,7 +126,7 @@ public class ConferenceRecordServiceImpl extends ServiceImpl<ConferenceRecordMap
String templateFile = "template/会议记录表" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/会议记录表" + SafeProductConstant.DOCX_SUFFIX;
String pdfPath = savePath + "/会议记录表" + SafeProductConstant.PDF_SUFFIX;
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath,"filePath", response);
}
/**

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

@ -196,7 +196,7 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
String templateFile = "template/卫生自查表" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/卫生自查表" + SafeProductConstant.DOCX_SUFFIX;
String pdfPath = savePath + "/卫生自查表" + SafeProductConstant.PDF_SUFFIX;
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, "",response);
}
/**

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java

@ -170,7 +170,7 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
String templateFile = "template/演练记录表" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/演练记录表" + SafeProductConstant.DOCX_SUFFIX;
String pdfPath = savePath + "/演练记录表" + SafeProductConstant.PDF_SUFFIX;
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, "filePath",response);
}
/**

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java

@ -166,7 +166,7 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
String templateFile = "template/培训记录表" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/培训记录表" + SafeProductConstant.DOCX_SUFFIX;
String pdfPath = savePath + "/培训记录表" + SafeProductConstant.PDF_SUFFIX;
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath,"filePath", response);
}
/**

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

@ -5,10 +5,12 @@ import com.hnac.hzims.common.logs.utils.StringUtils;
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.apache.poi.xwpf.usermodel.*;
import org.json.JSONArray;
import org.json.JSONObject;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.DateUtil;
@ -68,10 +70,10 @@ public class BaseUtil {
* @param pdfPath pdf生成路径
* @param response 响应类
*/
public static void exportDocument(String templateFile, Map<String, Object> params, String wordPath, String pdfPath, HttpServletResponse response) {
public static void exportDocument(String templateFile, Map<String, Object> params, String wordPath, String pdfPath,String findName, HttpServletResponse response) {
try {
List<XWPFDocument> res = new ArrayList<>();
XWPFDocument document = BaseUtil.fillDocument(templateFile, params);
XWPFDocument document = BaseUtil.fillDocument(templateFile, params,findName);
res.add(document);
BaseUtil.exportWord(res, wordPath);
} catch (Exception e) {
@ -112,15 +114,55 @@ public class BaseUtil {
* @param params 数据参数
* @return 文件
*/
public static XWPFDocument fillDocument(String templatePath, Map<String, Object> params) {
public static XWPFDocument fillDocument(String templatePath, Map<String, Object> params, String findName) {
XWPFDocument xwpfDocument = null;
try {
xwpfDocument = WordExportUtil.exportWord07(templatePath, params);
if (StringUtils.isNotEmpty(findName)) {
String findText = params.get(findName).toString();
if (StringUtils.isNotEmpty(findText)) {
JSONArray jsonArray = new JSONArray(findText);
for (XWPFTable table : xwpfDocument.getTables()) {
for (int row = 0; row < table.getNumberOfRows(); row++) {
for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) {
XWPFTableCell cell = table.getRow(row).getCell(col);
for (XWPFParagraph p : cell.getParagraphs()) {
Iterator<XWPFRun> iterator = p.getRuns().iterator();
while (iterator.hasNext()) {
XWPFRun r = iterator.next();
String text = r.getText(0);
if (findText.equals(text)) {
r.setText("", 0); // 清除原有文本
XWPFParagraph paragraph = r.getParagraph();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("name");
String url = jsonObject.getString("url");
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId();
CTHyperlink cLink = paragraph.getCTP().addNewHyperlink();
cLink.setId(id);
CTText ctText = CTText.Factory.newInstance();
ctText.setStringValue(name);
CTR ctr = CTR.Factory.newInstance();
ctr.setTArray(new CTText[]{ctText});
cLink.setRArray(new CTR[]{ctr});
if(i<jsonArray.length()-1) {
paragraph.createRun().addBreak();
}
}
}
}
}
}
}
}
}
}
if (templatePath.equals("template/卫生自查表.docx")) {
formatHygieneRecordTable(xwpfDocument);
}
} catch (Exception e) {
log.error("数据写入异常: {}", e.getMessage());
log.error("数据写入异常: {}",e.getCause().toString()+ e.getStackTrace());
e.printStackTrace();
}
return xwpfDocument;

Loading…
Cancel
Save