| | |
| | | import com.deepoove.poi.config.ConfigureBuilder; |
| | | import com.deepoove.poi.data.*; |
| | | import com.deepoove.poi.data.style.*; |
| | | import com.deepoove.poi.data.style.Style; |
| | | import com.deepoove.poi.util.TableTools; |
| | | import com.spire.doc.FileFormat; |
| | | import com.yuanchu.mom.dto.*; |
| | |
| | | import com.yuanchu.mom.mapper.*; |
| | | import com.yuanchu.mom.pojo.*; |
| | | import com.yuanchu.mom.vo.InsProductResult2VO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | 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.docx4j.XmlUtils; |
| | | import org.docx4j.jaxb.Context; |
| | | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; |
| | | import org.docx4j.wml.*; |
| | | import org.docx4j.wml.STBrType; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.xml.bind.JAXBElement; |
| | | import java.io.*; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class WordUtils { |
| | | |
| | |
| | | } |
| | | result2VOS.add(insProductResult2VO1); |
| | | } |
| | | } else { |
| | | } |
| | | else { |
| | | insProductResult2VO.setValue(value.replace("\"", "")); |
| | | result2VOS.add(insProductResult2VO); |
| | | } |
| | |
| | | if (vValues.size() > 0) { |
| | | //不合格 |
| | | if (vValues.get(1) != 0) { |
| | | productCount2 = productCount2 - 1 + vValues.get(1); |
| | | productCount2 = productCount2 + vValues.get(1); |
| | | } |
| | | //合格 |
| | | if (vValues.get(0) != 0) { |
| | | if (fusheProduct.getInsResult() == 1) { |
| | | productCount3 = productCount3 - 1 + vValues.get(0); |
| | | } else productCount3 = productCount3 + vValues.get(0); |
| | | productCount3 = productCount3 + vValues.get(0); |
| | | } |
| | | } |
| | | // 判定是否减掉辐射检验项本身 |
| | | if (fusheProduct.getInsResult() == 1) { |
| | | productCount3 = productCount3 - 1; |
| | | }else if(fusheProduct.getInsResult() == 0){ |
| | | productCount2 = productCount2 - 1; |
| | | } |
| | | //总数=项目总数-辐射项目数量+辐射具体的(合格+不合格)数量 |
| | | productCount = productCount - 1 + vValues.stream().mapToLong(Long::longValue).sum(); |
| | |
| | | for (InsProduct insPro : insProducts) { |
| | | InsProductWordDto insProductWordDto = new InsProductWordDto(); |
| | | insProductWordDto.setIndex(index1+"");//序号 |
| | | insProductWordDto.setTerm(insPro.getInspectionItem()+"-"+insPro.getInspectionItemSubclass());//检验项目 |
| | | if (insPro.getInspectionItem().contains("电路试验")){ |
| | | insProductWordDto.setTerm("电性能参数-"+insPro.getInspectionItemSubclass());//检验项目 |
| | | }else if (insPro.getInspectionItem().contains("辐射试验")){ |
| | | insProductWordDto.setTerm("辐射性能参数"+insPro.getInspectionItemSubclass());//检验项目 |
| | | }else { |
| | | insProductWordDto.setTerm(insPro.getInspectionItem()+"-"+insPro.getInspectionItemSubclass());//检验项目 |
| | | } |
| | | if (ObjectUtils.isNotNull(insPro.getInsResult()) && insPro.getInsResult()==0) { |
| | | insProductWordDto.setResult("不合格");//结论 |
| | | } else { |
| | |
| | | } |
| | | //辐射表格 |
| | | List<Map<String, Object>> tables3 = new ArrayList<>(); |
| | | List<InsOrderFile> insOrderDocFiles = new ArrayList<>();; // 暂存需要合并表单到生成word文件的docx文件 |
| | | // 统计辐射实验表数量 |
| | | int radiationReportNum = 0; |
| | | if (strings.contains("近场") || strings.contains("远场")) { |
| | | /*辐射的试验表*/ |
| | | List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery() |
| | | List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery() |
| | | .eq(InsOrderFile::getInsOrderId, orderId) |
| | | .eq(InsOrderFile::getInsSampleId, insReportDto1.getSampleId()) |
| | | .like(InsOrderFile::getFileName, "解析的辐射站点报告") |
| | |
| | | .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(); |
| | | ParagraphStyle paragraphStyle = new ParagraphStyle(); |
| | | paragraphStyle.setAlign(ParagraphAlignment.CENTER); |
| | | paragraphRenderData.setParagraphStyle(paragraphStyle); |
| | | List<RenderData> renderData = new ArrayList<>(); |
| | | TextRenderData textRenderData = new TextRenderData(); |
| | | Style style = new Style(); |
| | | style.setFontFamily("宋体"); |
| | | style.setColor("000000"); |
| | | textRenderData.setStyle(style); |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | insOrderDocFiles.addAll(insOrderFiles); |
| | | radiationReportNum = insOrderFiles.size(); |
| | | // 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(); |
| | | // ParagraphStyle paragraphStyle = new ParagraphStyle(); |
| | | // paragraphStyle.setAlign(ParagraphAlignment.CENTER); |
| | | // paragraphRenderData.setParagraphStyle(paragraphStyle); |
| | | // List<RenderData> renderData = new ArrayList<>(); |
| | | // TextRenderData textRenderData = new TextRenderData(); |
| | | // Style style = new Style(); |
| | | // style.setFontFamily("宋体"); |
| | | // style.setColor("000000"); |
| | | // textRenderData.setStyle(style); |
| | | // 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(); |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | //辐射的标题 |
| | | String title3 = ""; |
| | | if (tables3.size() > 0) { |
| | | title3 = "辐射方向图参数"; |
| | | if (radiationReportNum > 0) { |
| | | title3 = "辐射性能参数"; |
| | | } |
| | | //环境表格 |
| | | List<Map<String, Object>> tables4 = new ArrayList<>(); |
| | |
| | | if (i % 2 == 0) { |
| | | urlListDto = new UrlListDto(); |
| | | urlListDto.setImageOne(Pictures.ofLocal(imgUrl + "/" + insOrderFiles.get(i).getFileUrl()).create()); |
| | | if (i == insOrderFiles.size() - 1) { |
| | | urlList.add(urlListDto); |
| | | } |
| | | } else { |
| | | urlListDto.setImageTwo(Pictures.ofLocal(imgUrl + "/" + insOrderFiles.get(i).getFileUrl()).create()); |
| | | urlList.add(urlListDto); |
| | | } |
| | | if (i == insOrderFiles.size() - 1) { |
| | | urlList.add(urlListDto); |
| | | } |
| | | |
| | | } |
| | | } |
| | | //样品编号参照上述sampleCode |
| | |
| | | put("insProductList", insProductList); //检验情况一览表 |
| | | put("tables2", tables2); //检测结果 |
| | | put("title3", finalTitle); //检测结果 |
| | | put("tables3", tables3); //检测结果 |
| | | put("tables3", null); //检测结果 |
| | | put("tables4", tables4); //检测结果 |
| | | put("urlList", urlList); //样品照片 |
| | | put("insUsers", insUsers); //检测人员信息 |
| | |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | // //目录更新 |
| | | // try{ |
| | | // com.spire.doc.Document document = new com.spire.doc.Document(); |
| | | // document.loadFromFile(path); |
| | | // // 更新目录 |
| | | // document.updateTableOfContents(); |
| | | // // 保存文档 |
| | | // document.saveToFile(path, FileFormat.Docx); |
| | | // document.close(); |
| | | // } |
| | | // catch (Exception e) { |
| | | // throw new RuntimeException(e); |
| | | // } |
| | | // 更新表单 |
| | | try { |
| | | WordprocessingMLPackage targetDoc = WordprocessingMLPackage.load(new File(path)); |
| | | List<Object> targetContent = targetDoc.getMainDocumentPart().getContent(); |
| | | int targetIndex = findFirstTargetIndex(targetDoc, title3); |
| | | if (targetIndex != -1) { |
| | | List<Object> forms = new ArrayList<>(); |
| | | for (InsOrderFile insOrderFile : insOrderDocFiles) { |
| | | // 加载源文档并提取表单内容(假设为表格) |
| | | WordprocessingMLPackage sourceDoc = WordprocessingMLPackage.load(new File(wordUrl + "/" + insOrderFile.getFileUrl())); |
| | | List<Object> sourceContent = sourceDoc.getMainDocumentPart().getContent(); |
| | | for (Object obj : sourceContent) { |
| | | if (obj instanceof JAXBElement) { // 检查是否为 JAXBElement |
| | | JAXBElement jaxbElement = (JAXBElement)obj; |
| | | Tbl table = (Tbl) XmlUtils.deepCopy(jaxbElement.getValue()); |
| | | targetIndex++; |
| | | // 插入到目标段落之后 |
| | | targetContent.add(targetIndex, table); |
| | | forms.add(table); |
| | | // 插入分页符 |
| | | P paragraphWithPageBreak = Context.getWmlObjectFactory().createP(); |
| | | R run = Context.getWmlObjectFactory().createR(); |
| | | Br br = Context.getWmlObjectFactory().createBr(); |
| | | br.setType(STBrType.PAGE); // 设置分页符类型 |
| | | run.getContent().add(br); |
| | | paragraphWithPageBreak.getContent().add(run); |
| | | targetIndex++; |
| | | targetContent.add(targetIndex, paragraphWithPageBreak); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 保存修改后的文档 |
| | | targetDoc.save(new File(path)); |
| | | com.spire.doc.Document document = new com.spire.doc.Document(); |
| | | document.loadFromFile(path); |
| | | // 更新目录 |
| | | document.updateTableOfContents(); |
| | | // 保存文档 |
| | | document.saveToFile(path, FileFormat.Docx); |
| | | document.close(); |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | //电路报告用于总报告的方法(天线) |
| | | private void getWord1(String term, InsOrderState insOrderState, List<Map<String, Object>> tables2) { |
| | | AtomicInteger lable = new AtomicInteger(1); |
| | | AtomicInteger index = new AtomicInteger(); |
| | | String title = term + "电路参数"; |
| | | String title = term + "电性能参数"; |
| | | InsSample insSample = insSampleMapper.selectById(insOrderState.getInsSampleId()); |
| | | //查询项目 |
| | | List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | |
| | | if (i % 2 == 0) { |
| | | //最差值 |
| | | String value = result2s.get(0).getValue().replaceAll("[\\[\\]\"]", ""); |
| | | String text = value.split(",")[(j - 5) + (i - 1) / 2 * (Math.min(ports, 8))]; |
| | | try { |
| | | textRenderData.setText(value.split(",")[(j - 5) + (i - 1) / 2 * (Math.min(ports, 8))]); |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text))); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | } else if (j % 2 == 0) { |
| | | String value = result2s.get(0).getValue().replaceAll("[\\[\\]\"]", ""); |
| | | try { |
| | | textRenderData.setText(value.split(",")[(j - 6) / 2 + (i - cc - 1) * 4] + "∑5" + i + (j - 6)); |
| | | String text = value.split(",")[(j - 6) / 2 + (i - cc - 1) * 4]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 6)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | } else { |
| | | String value = result2s.get(0).getValue().replaceAll("[\\[\\]\"]", ""); |
| | | try { |
| | | textRenderData.setText(value.split(",")[(j - 5) / 2 + (i - cc - 1) * 4] + "∑5" + i + (j - 5)); |
| | | String text = value.split(",")[(j - 5) / 2 + (i - cc - 1) * 4]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 5)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | } else if (j % 2 == 0) { |
| | | String value = result2s.get(0).getValue().replaceAll("[\\[\\]\"]", ""); |
| | | try { |
| | | textRenderData.setText(value.split(",")[(j - 6) / 2 + (i - (dd == 0 ? cc : dd) - 1) * 4] + "∑5" + i + (j - 6)); |
| | | String text = value.split(",")[(j - 6) / 2 + (i - (dd == 0 ? cc : dd) - 1) * 4]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 6)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | } else { |
| | | String value = result2s.get(0).getValue().replaceAll("[\\[\\]\"]", ""); |
| | | try { |
| | | textRenderData.setText(value.split(",")[(j - 5) / 2 + (i - (dd == 0 ? cc : dd) - 1) * 4] + "∑5" + i + (j - 5)); |
| | | String text = value.split(",")[(j - 5) / 2 + (i - (dd == 0 ? cc : dd) - 1) * 4]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 5)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | } else if (j % 2 == 0) { |
| | | String value = result2s.get(0).getValue().replaceAll("[\\[\\]\"]", ""); |
| | | try { |
| | | textRenderData.setText(value.split(",")[(j - 6) / 2 + (i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) - 1) * 4] + "∑5" + i + (j - 6)); |
| | | String text = value.split(",")[(j - 6) / 2 + (i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) - 1) * 4]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 6)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | } else { |
| | | String value = result2s.get(0).getValue().replaceAll("[\\[\\]\"]", ""); |
| | | try { |
| | | textRenderData.setText(value.split(",")[(j - 5) / 2 + (i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) - 1) * 4] + "∑5" + i + (j - 5)); |
| | | String text = value.split(",")[(j - 5) / 2 + (i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) - 1) * 4]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 5)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | } else if (j % 2 == 0) { |
| | | String value = result2s.get(0).getValue().replaceAll("[\\[\\]\"]", ""); |
| | | try { |
| | | textRenderData.setText(value.split(",")[(j - 6) / 2 + (i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) - 1) * 4] + "∑5" + i + (j - 6)); |
| | | String text = value.split(",")[(j - 6) / 2 + (i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) - 1) * 4]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 6)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | } else { |
| | | String value = result2s.get(0).getValue().replaceAll("[\\[\\]\"]", ""); |
| | | try { |
| | | textRenderData.setText(value.split(",")[(j - 5) / 2 + (i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) - 1) * 4] + "∑5" + i + (j - 5)); |
| | | String text = value.split(",")[(j - 5) / 2 + (i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) - 1) * 4]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 5)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] value = result2s.get((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) / portRow / (angles + 2)).getValue().split("\\],\\["); |
| | | String[] split = value[(i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) - 2) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | try { |
| | | textRenderData.setText(split[((j - 5) + ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) - 1) / (angles + 1) % portRow) * (Math.min(ports, 8)))]); |
| | | String text = split[((j - 5) + ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) - 1) / (angles + 1) % portRow) * (Math.min(ports, 8)))]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text))); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] value = result2s.get(0).getValue().split("\\],\\["); |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | try { |
| | | textRenderData.setText(split[(j - 5) + ((i + (angles - 1)) / (angles + 1) - 1) * (Math.min(ports, 8))]); |
| | | String text = split[(j - 5) + ((i + (angles - 1)) / (angles + 1) - 1) * (Math.min(ports, 8))]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text))); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | if (j % 2 == 0) { |
| | | try { |
| | | textRenderData.setText(split[(j - 6) / 2 + ((i - cc) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)] + "∑5" + i + (j - 6)); |
| | | String text = split[(j - 6) / 2 + ((i - cc) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 6)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | | } else { |
| | | try { |
| | | textRenderData.setText(split[(j - 5) / 2 + ((i - cc) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)] + "∑5" + i + (j - 5)); |
| | | String text = split[(j - 5) / 2 + ((i - cc) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 5)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | if (j % 2 == 0) { |
| | | try { |
| | | textRenderData.setText(split[(j - 6) / 2 + ((i - (dd == 0 ? cc : dd)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)] + "∑5" + i + (j - 6)); |
| | | String text = split[(j - 6) / 2 + ((i - (dd == 0 ? cc : dd)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 6)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | | } else { |
| | | try { |
| | | textRenderData.setText(split[(j - 5) / 2 + ((i - (dd == 0 ? cc : dd)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)] + "∑5" + i + (j - 5)); |
| | | String text = split[(j - 5) / 2 + ((i - (dd == 0 ? cc : dd)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 5)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | if (j % 2 == 0) { |
| | | try { |
| | | textRenderData.setText(split[(j - 6) / 2 + ((i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)] + "∑5" + i + (j - 6)); |
| | | String text = split[(j - 6) / 2 + ((i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 6)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | | } else { |
| | | try { |
| | | textRenderData.setText(split[(j - 5) / 2 + ((i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)] + "∑5" + i + (j - 5)); |
| | | String text = split[(j - 5) / 2 + ((i - (ee == 0 ? ((dd == 0 ? cc : dd)) : ee)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 5)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | if (j % 2 == 0) { |
| | | try { |
| | | textRenderData.setText(split[(j - 6) / 2 + ((i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)] + "∑5" + i + (j - 6)); |
| | | String text = split[(j - 6) / 2 + ((i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 6)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | | } else { |
| | | try { |
| | | textRenderData.setText(split[(j - 5) / 2 + ((i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)] + "∑5" + i + (j - 5)); |
| | | String text = split[(j - 5) / 2 + ((i - (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff)) / (angles + 2)) * (ports > 8 ? 4 : (ports + 1) / 2)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑5" + i + (j - 5)); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] value = result2s.get((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg)) / portRow / (angles + 2)).getValue().split("\\],\\["); |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | try { |
| | | textRenderData.setText(split[((j - 5) + ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) - 1) / (angles + 1) % portRow) * (Math.min(ports, 8)))]); |
| | | String text = split[((j - 5) + ((i - (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) - 1) / (angles + 1) % portRow) * (Math.min(ports, 8)))]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text))); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | //最差值 |
| | | String[] value = result2s.get(0).getValue().split("\\],\\["); |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | textRenderData.setText(split[0] + "∑7" + i); |
| | | String text = split[0]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑7" + i); |
| | | } |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | |
| | | //最差值 |
| | | String[] value = result2s.get(0).getValue().split("\\],\\["); |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | textRenderData.setText(split[0] + "∑7" + i); |
| | | String text = split[0]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text)) + "∑7" + i); |
| | | } |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | |
| | | String[] value = result2s.get(0).getValue().split("\\],\\["); |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | try { |
| | | textRenderData.setText(split[(j - 5) + ((i - (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn)) / (angles + 2)) * Math.min(length, 8)]); |
| | | String text = split[(j - 5) + ((i - (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn)) / (angles + 2)) * Math.min(length, 8)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text))); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] value = result2s.get(0).getValue().split("\\],\\["); |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | try { |
| | | textRenderData.setText(split[(j - 5) + ((i - (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp)) / (angles + 2)) * Math.min(length, 8)]); |
| | | String text = split[(j - 5) + ((i - (pp == 0 ? (nn == 0 ? (mm == 0 ? (hh == 0 ? (gg == 0 ? (ff == 0 ? (ee == 0 ? ((dd == 0 ? cc : dd)) : ee) : ff) : gg) : hh) : mm) : nn) : pp)) / (angles + 2)) * Math.min(length, 8)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text))); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] value = result2s.get(0).getValue().split("\\],\\["); |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | try { |
| | | textRenderData.setText(split[(j - 5) + ((i - rr) / (angles + 2)) * Math.min(length, 8)]); |
| | | String text = split[(j - 5) + ((i - rr) / (angles + 2)) * Math.min(length, 8)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text))); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | String[] value = result2s.get(0).getValue().split("\\],\\["); |
| | | String[] split = value[(i + (angles - 1)) % (angles + 1)].replaceAll("[\\[\\]\"]", "").split(","); |
| | | try { |
| | | textRenderData.setText(split[(j - 5) + ((i - ss) / (angles + 2)) * Math.min(length, 8)]); |
| | | String text = split[(j - 5) + ((i - ss) / (angles + 2)) * Math.min(length, 8)]; |
| | | textRenderData.setText(String.format("%.2f",Double.parseDouble(text))); |
| | | } catch (Exception e) { |
| | | textRenderData.setText(""); |
| | | } |
| | |
| | | //电路报告用于总报告的方法(无源器件) |
| | | private void getWord2(String term, InsOrderState insOrderState, List<Map<String, Object>> tables2) { |
| | | AtomicInteger index = new AtomicInteger(); |
| | | String title = term + "电路参数"; |
| | | String title = term + "电性能参数"; |
| | | //查询样品 |
| | | InsSample insSample = insSampleMapper.selectById(insOrderState.getInsSampleId()); |
| | | //查询项目 |
| | |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | Set<String> itemSet = new HashSet<>(); |
| | | //表格的行数 |
| | | for (int i = 0; i < result2VOS.size()+1; i++) { |
| | | for (int i = 0; i < result2VOS.size(); i++) { |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | RowStyle rowStyle = new RowStyle(); |
| | | rowStyle.setHeight(40); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 查找文本首次出现行 |
| | | private int findFirstTargetIndex(WordprocessingMLPackage targetDoc,String textStr){ |
| | | int targetIndex = -1; |
| | | if(StringUtils.isEmpty(textStr)){ |
| | | return targetIndex; |
| | | } |
| | | try { |
| | | List<Object> targetContent = targetDoc.getMainDocumentPart().getContent(); |
| | | // 查找目标段落 |
| | | for (int i = 0; i < targetContent.size(); i++) { |
| | | Object obj = targetContent.get(i); |
| | | if (obj instanceof P) { |
| | | P paragraph = (P) obj; |
| | | for (Object runObj : paragraph.getContent()) { |
| | | if (runObj instanceof R) { |
| | | R run = (R) runObj; |
| | | for (Object textObj : run.getContent()) { |
| | | if (textObj instanceof JAXBElement) { |
| | | JAXBElement jaxbElement = (JAXBElement) textObj; |
| | | if(jaxbElement.getValue() instanceof Text){ |
| | | Text text = (Text) jaxbElement.getValue(); |
| | | if (text.getValue().contains(textStr)) { |
| | | targetIndex = i; |
| | | return targetIndex; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("findFirstTargetIndex<<<<<<<<<<:{}",e.getMessage()); |
| | | }finally { |
| | | return targetIndex; |
| | | } |
| | | } |
| | | } |