| | |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.poi.openxml4j.util.ZipSecureFile; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHMerge; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.mock.web.MockMultipartFile; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | | import java.nio.file.Files; |
| | |
| | | if (inspectionItemSubclass.contains("互调")) { |
| | | aa += (angles + 1) * portRow * often; |
| | | } |
| | | } |
| | | else { |
| | | } else { |
| | | if (inspectionItemSubclass.contains("电压驻波比")) { |
| | | aa += (angles + 1) * portRow; |
| | | } |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | else { |
| | | } else { |
| | | if (insOrderState.getVersion() == 1) { |
| | | //非电调版本(简单版) |
| | | if (inspectionItemSubclass.contains("电压驻波比") && i <= 2 * portRow) { |
| | |
| | | cells.add(cellRenderData); |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | } else { |
| | | //电调版本(复杂版) |
| | | if (inspectionItemSubclass.contains("电压驻波比") && i <= (angles + 1) * portRow) { |
| | | cc = (angles + 1) * portRow; |
| | |
| | | .in(InsProductResult::getInsProductId, productIds)); |
| | | for (InsProductResult insProductResult : insProductResults) { |
| | | List<JSONObject> jsonObjects = JSON.parseArray(insProductResult.getEquipValue(), JSONObject.class); |
| | | for (JSONObject jsonObject : jsonObjects) { |
| | | String value = jsonObject.getString("v"); |
| | | if (value != null && !value.isEmpty()) { |
| | | deviceSet.add(value); |
| | | if (ObjectUtils.isNotEmpty(jsonObjects)) { |
| | | for (JSONObject jsonObject : jsonObjects) { |
| | | String value = jsonObject.getString("v"); |
| | | if (value != null && !value.isEmpty()) { |
| | | deviceSet.add(value); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | if (strings.contains("近场") || strings.contains("远场")) { |
| | | Map<String, String> table = new HashMap<>(); |
| | | table.put("indexs", indexs + ""); |
| | | indexs += 1; |
| | | table.put("term", "辐射方向图参数"); |
| | | table.put("result", "不判定"); |
| | | tables.add(table); |
| | | /*辐射的试验表*/ |
| | | List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery() |
| | | .eq(InsOrderFile::getInsOrderId, orderId) |
| | | .like(InsOrderFile::getFileName, "解析的辐射站点报告") |
| | | .and(wrapper -> wrapper |
| | | .eq(InsOrderFile::getSonLaboratory, "远场") |
| | | .or() |
| | | .eq(InsOrderFile::getSonLaboratory, "近场") |
| | | )); |
| | | if (insOrderFiles.size() > 0) { |
| | | int aa = 0; |
| | | for (InsOrderFile insOrderFile : insOrderFiles) { |
| | | try { |
| | | XWPFDocument circuitParamsDoc = new XWPFDocument(new FileInputStream(wordUrl + "/" + insOrderFile.getFileUrl())); |
| | | // 遍历电路参数文件的所有元素,段落和表格 |
| | | for (IBodyElement element : circuitParamsDoc.getBodyElements()) { |
| | | Map<String, Object> table3 = new HashMap<>(); |
| | | TableRenderData tableData = new TableRenderData(); |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | if (element instanceof XWPFTable) { |
| | | aa += 1; |
| | | XWPFTable tab = (XWPFTable) element; |
| | | List<XWPFTableRow> row = tab.getRows(); |
| | | for (int i = 0; i < row.size(); i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | List<CellRenderData> cells = new ArrayList<>(); |
| | | List<XWPFTableCell> cell = row.get(i).getTableCells(); |
| | | for (int j = 0; j < cell.size(); j++) { |
| | | CellRenderData cellRenderData = new CellRenderData(); |
| | | List<ParagraphRenderData> paragraphRenderDataList = new ArrayList<>(); |
| | | ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); |
| | | List<RenderData> renderData = new ArrayList<>(); |
| | | TextRenderData textRenderData = new TextRenderData(); |
| | | CTTcPr tcPr = cell.get(j).getCTTc().getTcPr(); |
| | | if (tcPr != null) { |
| | | //合并列 |
| | | CTHMerge hMerge = tcPr.getHMerge(); |
| | | if (ObjectUtils.isNotEmpty(hMerge)) { |
| | | if (STMerge.RESTART.equals(hMerge.getVal()) || STMerge.CONTINUE.equals(hMerge.getVal())) { |
| | | int index = j; |
| | | String text = null; |
| | | while (text == null || text.equals("")) { |
| | | if (index < 0) { |
| | | text = "/"; |
| | | } |
| | | text = cell.get(index).getText(); |
| | | index--; |
| | | } |
| | | textRenderData.setText(text + "∑88" + aa + i); |
| | | } |
| | | } |
| | | //合并行 |
| | | CTVMerge vMerge = tcPr.getVMerge(); |
| | | if (ObjectUtils.isNotEmpty(vMerge)) { |
| | | if (STMerge.RESTART.equals(vMerge.getVal()) || STMerge.CONTINUE.equals(vMerge.getVal())) { |
| | | int index = i; |
| | | String text = null; |
| | | while (text == null || text.equals("")) { |
| | | if (index < 0) { |
| | | text = "/"; |
| | | break; |
| | | } |
| | | text = row.get(index).getCell(j).getText(); |
| | | index--; |
| | | } |
| | | if (text.equals("合格")|| text.equals("不合格")){ |
| | | textRenderData.setText(text + "∑25" + aa + j); |
| | | }else { |
| | | textRenderData.setText(text + "∑22" + aa + j); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | textRenderData.setText(cell.get(j).getText()); |
| | | } |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | rowRenderData.setCells(cells); |
| | | rows.add(rowRenderData); |
| | | } |
| | | tableData.setRows(rows); |
| | | table3.put("table3", tableData); |
| | | tables3.add(table3); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (strings.contains("电路试验")) { |
| | | strings.remove("电路试验"); |
| | |
| | | Map<String, Object> table4 = new HashMap<>(); |
| | | table4.put("table4", tableRenderData); |
| | | tables4.add(table4); |
| | | } |
| | | else { |
| | | } else { |
| | | Map<String, String> table = new HashMap<>(); |
| | | table.put("indexs", indexs + ""); |
| | | table.put("term", "电路参数"); |
| | |
| | | for (InsReportDto1 insReportDto1 : insReportDto1s) { |
| | | InsOrderUser insOrderUser = insOrderUserMapper.selectById(insReportDto1.getInsOrderUsersId()); |
| | | InsOrderState orderState = insOrderStateMapper.selectById(insOrderUser.getInsOrderStateId()); |
| | | if (orderState.getLaboratory().equals("电路试验")){ |
| | | if (orderState.getLaboratory().equals("电路试验")) { |
| | | orderState.setNum(insOrderUser.getNum()); |
| | | getWord1(insOrderUser.getTerm(),orderState,insSamples,tables2); |
| | | getWord1(insOrderUser.getTerm(), orderState, insSamples, tables2); |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | } else { |
| | | //如果只有环境试验没有电路试验 |
| | | strings.remove("近场"); |
| | | strings.remove("远场"); |
| | |
| | | environment = (ObjectUtils.isNotEmpty(insProduct.getTemperature()) ? insProduct.getTemperature() + "℃ " : "") + (ObjectUtils.isNotEmpty(insProduct.getHumidity()) ? insProduct.getHumidity() + "%" : ""); |
| | | String finalEnvironment = environment; |
| | | List<SampleProductDto> finalSamples = samples; |
| | | String title3 = ""; |
| | | if (tables3.size() > 0) { |
| | | title3 = "辐射方向图参数"; |
| | | } |
| | | String finalTitle = title3; |
| | | XWPFTemplate template = XWPFTemplate.compile(url, builder.build()).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("order", insOrder); |
| | |
| | | put("deviceList", finalDeviceList); |
| | | put("tables", tables); |
| | | put("tables2", tables2); |
| | | put("title3", finalTitle); |
| | | put("tables3", tables3); |
| | | put("tables4", tables4); |
| | | put("sampleList", sampleList); |
| | |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | // 处理合并单元格的问题 |
| | | String path = wordUrl + "/" + insReport.getCode().replace("/", "") + ".docx"; |
| | | // 处理合并单元格的问题 |
| | | try { |
| | | ZipSecureFile.setMinInflateRatio(0.0001); |
| | | FileInputStream stream = new FileInputStream(path); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 单元格排序, 避免格式错乱 |
| | | List<Map.Entry<String, Map<String, Integer>>> entries = new ArrayList<>(maps.entrySet()); |
| | | entries.sort((o1, o2) -> o1.getValue().get("sc") - o2.getValue().get("sc")); |
| | | |
| | | // 按照顺序添加进集合 |
| | | List<String> list = new ArrayList<>(); |
| | | for (Map.Entry<String, Map<String, Integer>> entry : entries) { |
| | | list.add(entry.getKey()); |
| | | } |
| | | |
| | | 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++) { |
| | |
| | | try { |
| | | TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec")); |
| | | } catch (Exception e) { |
| | | System.out.println("合并出错"); |
| | | } |
| | | } |
| | | } |
| | |
| | | try { |
| | | TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er")); |
| | | } catch (Exception e) { |
| | | System.out.println("合并出错"); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | //电路报告用于总报告的方法 |
| | | private void getWord1(String term, InsOrderState insOrderState,List<InsSample> insSamples,List<Map<String, Object>> tables2){ |
| | | private void getWord1(String term, InsOrderState insOrderState, List<InsSample> insSamples, List<Map<String, Object>> tables2) { |
| | | AtomicInteger lable = new AtomicInteger(1); |
| | | AtomicInteger index = new AtomicInteger(); |
| | | String title = term + "电路参数"; |
| | |
| | | if (inspectionItemSubclass.contains("互调")) { |
| | | aa += (angles + 1) * portRow * often; |
| | | } |
| | | } |
| | | else { |
| | | } else { |
| | | if (inspectionItemSubclass.contains("电压驻波比")) { |
| | | aa += (angles + 1) * portRow; |
| | | } |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } |
| | | else { |
| | | } else { |
| | | if (insOrderState.getVersion() == 1) { |
| | | //非电调版本(简单版) |
| | | if (inspectionItemSubclass.contains("电压驻波比") && i <= 2 * portRow) { |
| | |
| | | cells.add(cellRenderData); |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | } else { |
| | | //电调版本(复杂版) |
| | | if (inspectionItemSubclass.contains("电压驻波比") && i <= (angles + 1) * portRow) { |
| | | cc = (angles + 1) * portRow; |