From 31718a6a2a5f04499137cacf51ca644debc86643 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期一, 08 七月 2024 14:25:58 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java | 186 ++++++++++++++++++++++++++++-----------------
1 files changed, 115 insertions(+), 71 deletions(-)
diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
index 1e188a4..4bb2475 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -39,6 +39,8 @@
import com.yuanchu.mom.vo.SampleVo;
import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.*;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -46,6 +48,7 @@
import javax.annotation.Resource;
import java.io.*;
+import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
@@ -621,30 +624,6 @@
Set<String> delSet = new HashSet<>();
List<ExcelDto> excelDtos = JSON.parseArray(tem, ExcelDto.class);
List<ExcelDto> mcList = new ArrayList<>();
- /* int aaaa = excelDtos.get(excelDtos.size() - 1).getR();//杩欓噷鏄ā鐗堥噷闈㈢殑鎵�鏈夋娴嬮」鐨勯暱搴�,鍏堜互15涓」鐩垎椤�
- int bbbb = 17;
- int cccc = 0;
- for (int p = 0; p < aaaa; p++) {
- if (p % bbbb == 0) {
- for (int y = 0; y < excelDtos.size(); y++) {
- if (y == 0 || y == 1) {
- if (excelDtos.get(y).getV().getMc() != null && excelDtos.get(y).getV().getMc().getCs() != null && excelDtos.get(y).getV().getMc().getRs() != null) {
- mcList.add(excelDtos.get(y));
- }
- } else {
- try {
- excelDtos.get(y + cccc - 2);
- } catch (Exception e) {
- continue;
- }
- if (excelDtos.get(y + cccc - 2).getV().getMc() != null && excelDtos.get(y + cccc - 2).getV().getMc().getCs() != null && excelDtos.get(y + cccc - 2).getV().getMc().getRs() != null) {
- mcList.add(excelDtos.get(y + cccc - 2));
- }
- }
- }
- cccc += 17;
- }
- }*/
excelDtos.forEach(b -> {
if (b.getV().getMc() != null && b.getV().getMc().getCs() != null && b.getV().getMc().getRs() != null) {
mcList.add(b);
@@ -778,7 +757,11 @@
} else if (value.equals("璇曢獙鏂规硶")) {
textRenderData.setText(p.getMethodS());
} else if (value.equals("妫�楠岄」")) {
- textRenderData.setText(p.getInspectionItem() + "&" + p.getInspectionItemEn());
+ if (ObjectUtils.isEmpty(p.getInspectionItemEn())) {
+ textRenderData.setText(p.getInspectionItem());
+ } else {
+ textRenderData.setText(p.getInspectionItem() + "&" + p.getInspectionItemEn());
+ }
} else if (value.equals("妫�楠屽瓙椤�")) {
if (ObjectUtils.isEmpty(p.getInspectionItemSubclassEn())) {
textRenderData.setText(p.getInspectionItemSubclass());
@@ -823,7 +806,6 @@
textRenderData.setText(textRenderData.getText() + "鈭�" + jo1.get("mc"));
}
Style style = new Style();
-// style.setFontFamily(v.get("ff") == null ? "瀹嬩綋" : v.get("ff") + "");
style.setFontFamily("瀹嬩綋");
if (!((v.get("fc") + "").indexOf("rgb") > -1)) {
style.setColor(v.get("fc") == null ? "000000" : (v.get("fc") + "").replace("#", ""));
@@ -838,35 +820,68 @@
if (rowRenderData.getCells().size() != 0) {
rows.add(rowRenderData);
}
+ List<TableRenderData> tables1 = new ArrayList<>();
TableRenderData tableRenderData = new TableRenderData();
- tableRenderData.setRows(rows);
- int countSize = tableRenderData.getRows().get(0).getCells().size();
- for (RowRenderData row : tableRenderData.getRows()) {
- /*for (CellRenderData cell : row.getCells()) {
- System.out.print(cell.getParagraphs().get(0).getContents());
- }
- System.out.println("");*/
- if (row.getCells().size() != countSize) {
- throw new ErrorException("姣忚鍗曞厓鏍间笉鐩哥瓑");
- }
+ tableRenderData.setRows(new ArrayList<>());
+ double totalHeight = 0.0; // 鐢ㄤ簬璺熻釜褰撳墠琛ㄦ牸鐨勬�昏楂�
+ double heightThreshold = 8000.0; // 闃堝�硷紝
+ List<RowRenderData> firstTwoRows = new ArrayList<>(); // 淇濆瓨鍓嶄袱琛屼互渚垮鍒跺埌鏂拌〃鏍�
+ // 淇濆瓨鍓嶄袱琛屼互渚垮鍒跺埌鏂拌〃鏍�
+ if (rows.size() >= 2) {
+ firstTwoRows.add(rows.get(0));
+ firstTwoRows.add(rows.get(1));
}
- TableStyle tableStyle = new TableStyle();
- tableStyle.setColWidths(new int[]{650, 1600, 2000, 750, 2800, 1100, 1100});
- tableStyle.setWidth("10000");
- tableStyle.setAlign(TableRowAlign.CENTER);
- BorderStyle borderStyle = new BorderStyle();
- borderStyle.setColor("000000");
- borderStyle.setType(XWPFTable.XWPFBorderType.THICK);
- borderStyle.setSize(14);
- tableStyle.setLeftBorder(borderStyle);
- tableStyle.setTopBorder(borderStyle);
- tableStyle.setRightBorder(borderStyle);
- tableStyle.setBottomBorder(borderStyle);
- tableRenderData.setTableStyle(tableStyle);
- Map<String, Object> table = new HashMap<>();
- table.put("table", tableRenderData);
- table.put("report", insReport);
- tables.add(table);
+ for (RowRenderData row : rows) {
+ double rowHeight = row.getRowStyle().getHeight(); // 鑾峰彇褰撳墠琛岀殑琛岄珮
+ totalHeight += rowHeight; // 鏇存柊鎬昏楂�
+ if (totalHeight >= heightThreshold) {
+ // 鍒涘缓鏂拌〃鏍煎苟澶嶅埗鍓嶄袱琛�
+ TableRenderData newTableRenderData = new TableRenderData();
+ newTableRenderData.setRows(new ArrayList<>(firstTwoRows));
+ //璁剧疆鏍峰紡
+ TableStyle tableStyle = new TableStyle();
+ tableStyle.setColWidths(new int[]{650, 1600, 2000, 750, 2800, 1100, 1100});
+ tableStyle.setWidth("10000");
+ tableStyle.setAlign(TableRowAlign.CENTER);
+ BorderStyle borderStyle = new BorderStyle();
+ borderStyle.setColor("000000");
+ borderStyle.setType(XWPFTable.XWPFBorderType.THICK);
+ borderStyle.setSize(14);
+ tableStyle.setLeftBorder(borderStyle);
+ tableStyle.setTopBorder(borderStyle);
+ tableStyle.setRightBorder(borderStyle);
+ tableStyle.setBottomBorder(borderStyle);
+ tableRenderData.setTableStyle(tableStyle);
+ newTableRenderData.setTableStyle(tableStyle);
+ tables1.add(tableRenderData);
+ tableRenderData = newTableRenderData;
+ totalHeight = rowHeight;
+ }
+ tableRenderData.getRows().add(row);
+ }
+ if (!tableRenderData.getRows().isEmpty()) {
+ //璁剧疆鏍峰紡
+ TableStyle tableStyle = new TableStyle();
+ tableStyle.setColWidths(new int[]{650, 1600, 2000, 750, 2800, 1100, 1100});
+ tableStyle.setWidth("10000");
+ tableStyle.setAlign(TableRowAlign.CENTER);
+ BorderStyle borderStyle = new BorderStyle();
+ borderStyle.setColor("000000");
+ borderStyle.setType(XWPFTable.XWPFBorderType.THICK);
+ borderStyle.setSize(14);
+ tableStyle.setLeftBorder(borderStyle);
+ tableStyle.setTopBorder(borderStyle);
+ tableStyle.setRightBorder(borderStyle);
+ tableStyle.setBottomBorder(borderStyle);
+ tableRenderData.setTableStyle(tableStyle);
+ tables1.add(tableRenderData);
+ }
+ tables1.forEach(table -> {
+ Map<String, Object> tableMap = new HashMap<>();
+ tableMap.put("table", table);
+ tableMap.put("report", insReport);
+ tables.add(tableMap);
+ });
});
});
String url;
@@ -1219,19 +1234,28 @@
} catch (IOException e) {
throw new RuntimeException(e);
}
- //澶勭悊鍚堝苟鍗曞厓鏍肩殑闂
+ // 澶勭悊鍚堝苟鍗曞厓鏍肩殑闂
String path = wordUrl + "/" + insReport.getCode().replace("/", "") + ".docx";
try {
FileInputStream stream = new FileInputStream(path);
XWPFDocument document = new XWPFDocument(stream);
List<XWPFTable> xwpfTables = document.getTables();
+
for (int i = 1; i < xwpfTables.size() - (deviceList == null ? 1 : 2); i++) {
Set<String> set1 = new HashSet<>();
Map<String, Map<String, Integer>> maps = new HashMap<>();
- for (int j = 0; j < xwpfTables.get(i).getRows().size(); j++) {
- for (int k = 0; k < xwpfTables.get(i).getRows().get(j).getTableCells().size(); k++) {
- if (xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().indexOf("鈭�") > -1) {
- String[] split = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("鈭�");
+
+ XWPFTable table = xwpfTables.get(i);
+ for (int j = 0; j < table.getRows().size(); j++) {
+ XWPFTableRow row = table.getRow(j);
+ if (row == null) continue;
+
+ for (int k = 0; k < row.getTableCells().size(); k++) {
+ XWPFTableCell cell = row.getCell(k);
+ if (cell == null || cell.getText() == null) continue;
+
+ if (cell.getText().indexOf("鈭�") > -1) {
+ String[] split = cell.getText().split("鈭�");
if (set1.add(split[1])) {
Map<String, Integer> map = new HashMap<>();
map.put("sr", j);
@@ -1247,30 +1271,51 @@
map1.put("er", map1.get("er") + 1);
}
}
- String str = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("鈭�")[0];
- xwpfTables.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
- xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setText(str);
- xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
- xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);
+
+ String str = split[0];
+ cell.removeParagraph(0);
+ cell.setText(str);
+ cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
+
+ if (cell.getParagraphArray(0) != null) {
+ cell.getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);
+ }
}
}
}
- List<String> list = new ArrayList<>();
- for (String s : maps.keySet()) {
- list.add(s);
- }
+
+ List<String> list = new ArrayList<>(maps.keySet());
for (int a = list.size() - 1; a >= 0; a--) {
Map<String, Integer> v = maps.get(list.get(a));
for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) {
if (v.get("ec") > v.get("sc")) {
- TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec"));
+ XWPFTableRow row = table.getRow(v.get("sr") + j);
+ if (row != null) {
+ for (int col = v.get("sc"); col <= v.get("ec"); col++) {
+ XWPFTableCell cell = row.getCell(col);
+ if (cell == null) {
+ row.createCell(); // 鍒涘缓鏂扮殑鍗曞厓鏍间互闃茬┖鎸囬拡寮傚父
+ }
+ }
+ TableTools.mergeCellsHorizonal(table, v.get("sr") + j, v.get("sc"), v.get("ec"));
+ }
}
}
if (v.get("er") > v.get("sr")) {
- TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er"));
+ for (int rowIdx = v.get("sr"); rowIdx <= v.get("er"); rowIdx++) {
+ XWPFTableRow row = table.getRow(rowIdx);
+ if (row != null) {
+ XWPFTableCell cell = row.getCell(v.get("sc"));
+ if (cell == null) {
+ row.createCell(); // 鍒涘缓鏂扮殑鍗曞厓鏍间互闃茬┖鎸囬拡寮傚父
+ }
+ }
+ }
+ TableTools.mergeCellsVertically(table, v.get("sc"), v.get("sr"), v.get("er"));
}
}
}
+
FileOutputStream fileOutputStream = new FileOutputStream(path);
document.write(fileOutputStream);
fileOutputStream.close();
@@ -1279,11 +1324,11 @@
} catch (IOException e) {
throw new RuntimeException(e);
}
+ //澶勭悊涓嫳鏂囨崲琛岀殑闂
try {
FileInputStream stream1 = new FileInputStream(path);
XWPFDocument document1 = new XWPFDocument(stream1);
List<XWPFTable> xwpfTables1 = document1.getTables();
- //澶勭悊涓嫳鏂囨崲琛岀殑闂
for (int i = 1; i < xwpfTables1.size() - (deviceList == null ? 1 : 2); i++) {
for (int j = 0; j < xwpfTables1.get(i).getRows().size(); j++) {
for (int k = 0; k < xwpfTables1.get(i).getRows().get(j).getTableCells().size(); k++) {
@@ -1303,7 +1348,6 @@
}
}
}
- //澶勭悊妫�楠岀粨鏋滆法椤电殑闂
FileOutputStream fileOutputStream1 = new FileOutputStream(path);
document1.write(fileOutputStream1);
fileOutputStream1.close();
--
Gitblit v1.9.3