Browse Source

Merge remote-tracking branch 'origin/prod-20240506' into prod-20240506

zhongwei
yang_shj 7 months ago
parent
commit
f57b56e994
  1. 5
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java
  2. 19
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

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

@ -161,7 +161,10 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
} }
} else { } else {
// 添加空的ImageEntity,防止数据填入时显示"{{" // 添加空的ImageEntity,防止数据填入时显示"{{"
list.add(new ImageEntity()); ImageEntity imageEntity = new ImageEntity();
// 设置空字符串,防止空指针报错
imageEntity.setUrl("");
list.add(imageEntity);
} }
rehearsalRecordDetailVO.setImages(list); rehearsalRecordDetailVO.setImages(list);
// 记录:换行符使用\r\n // 记录:换行符使用\r\n

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

@ -128,19 +128,22 @@ public class BaseUtil {
for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) { for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) {
XWPFTableCell cell = table.getRow(row).getCell(col); XWPFTableCell cell = table.getRow(row).getCell(col);
for (XWPFParagraph p : cell.getParagraphs()) { for (XWPFParagraph p : cell.getParagraphs()) {
Iterator<XWPFRun> iterator = p.getRuns().iterator(); for (int index = 0; index < p.getRuns().size(); index++) {
while (iterator.hasNext()) { XWPFRun run = p.getRuns().get(index);
XWPFRun r = iterator.next(); String text = run.getText(0);
String text = r.getText(0);
if (findText.equals(text)) { if (findText.equals(text)) {
r.setText("", 0); // 清除原有文本 run.setText("", 0); // 清除原有文本
XWPFParagraph paragraph = r.getParagraph(); XWPFParagraph paragraph = run.getParagraph();
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("name"); String name = jsonObject.getString("name");
String url = jsonObject.getString("url"); String url = jsonObject.getString("url");
url = URLEncoder.encode(url, "UTF-8"); // url编码格式化
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId(); String encodeName = URLEncoder.encode(name, "UTF-8").replaceAll("\\+", "%20");
String prefixString = url.substring(0, url.lastIndexOf("/") + 1);
String encodeUrl = prefixString + encodeName;
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(encodeUrl,
XWPFRelation.HYPERLINK.getRelation()).getId();
CTHyperlink cLink = paragraph.getCTP().addNewHyperlink(); CTHyperlink cLink = paragraph.getCTP().addNewHyperlink();
cLink.setId(id); cLink.setId(id);
CTText ctText = CTText.Factory.newInstance(); CTText ctText = CTText.Factory.newInstance();

Loading…
Cancel
Save