Browse Source

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

zhongwei
yang_shj 6 months ago
parent
commit
f57b56e994
  1. 5
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java
  2. 21
      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 {
// 添加空的ImageEntity,防止数据填入时显示"{{"
list.add(new ImageEntity());
ImageEntity imageEntity = new ImageEntity();
// 设置空字符串,防止空指针报错
imageEntity.setUrl("");
list.add(imageEntity);
}
rehearsalRecordDetailVO.setImages(list);
// 记录:换行符使用\r\n

21
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++) {
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);
for (int index = 0; index < p.getRuns().size(); index++) {
XWPFRun run = p.getRuns().get(index);
String text = run.getText(0);
if (findText.equals(text)) {
r.setText("", 0); // 清除原有文本
XWPFParagraph paragraph = r.getParagraph();
run.setText("", 0); // 清除原有文本
XWPFParagraph paragraph = run.getParagraph();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("name");
String url = jsonObject.getString("url");
url = URLEncoder.encode(url, "UTF-8");
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(url, XWPFRelation.HYPERLINK.getRelation()).getId();
// url编码格式化
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();
cLink.setId(id);
CTText ctText = CTText.Factory.newInstance();
@ -148,7 +151,7 @@ public class BaseUtil {
CTR ctr = CTR.Factory.newInstance();
ctr.setTArray(new CTText[]{ctText});
cLink.setRArray(new CTR[]{ctr});
if (i<jsonArray.length()-1) {
if (i < jsonArray.length() - 1) {
paragraph.createRun().addBreak();
}
}

Loading…
Cancel
Save