| | |
| | | package com.yuanchu.mom.utils; |
| | | |
| | | import cn.hutool.core.lang.UUID; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.deepoove.poi.config.Configure; |
| | | import com.deepoove.poi.config.ConfigureBuilder; |
| | |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.InsOrderFileMapper; |
| | | import com.yuanchu.mom.mapper.InsOrderMapper; |
| | | import com.yuanchu.mom.mapper.InsSampleMapper; |
| | | import com.yuanchu.mom.pojo.InsOrder; |
| | | import com.yuanchu.mom.pojo.InsOrderFile; |
| | | import com.yuanchu.mom.pojo.InsSample; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.openxml4j.util.ZipSecureFile; |
| | |
| | | InsOrderFileMapper insOrderFileMapper; |
| | | |
| | | @Resource |
| | | InsOrderMapper insOrderMapper; |
| | | InsSampleMapper insSampleMapper; |
| | | |
| | | //近场 |
| | | public void getFuSheWord1(String sonLaboratory, InsOrderFile insOrderFile) { |
| | | //读取excel文件内容 |
| | | String excelFilePath = wordUrl + "/" + insOrderFile.getFileUrl(); // 更新为你的文件路径 |
| | |
| | | Exceldata exceldata = new Exceldata(); |
| | | Map<Integer, Object> project = new HashMap<>(); |
| | | HashMap<String, Object> datas1 = new HashMap<>(); |
| | | Boolean exitLoop=false; |
| | | HashMap<String, Object> biaozhun = new HashMap<>(); |
| | | Boolean exitLoop = false; |
| | | for (int i = 0; i < workbook.getNumberOfSheets(); i++) { |
| | | String s = ""; |
| | | Sheet sheet = workbook.getSheetAt(i); |
| | |
| | | else { |
| | | switch (cell.getCellType()) { |
| | | case STRING: |
| | | if (cell.getColumnIndex()==1) { |
| | | exitLoop=true; |
| | | if (cell.getColumnIndex() == 1) { |
| | | if (cell.getStringCellValue().equals("指标")) { |
| | | for (Cell cell1 : row) { |
| | | switch (cell1.getCellType()) { |
| | | case STRING: |
| | | biaozhun.put(project.get(cell1.getColumnIndex()).toString(), cell1.getStringCellValue()); |
| | | break; |
| | | case NUMERIC: |
| | | System.out.print(cell1.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell1.getBooleanCellValue() + "\t"); |
| | | break; |
| | | case FORMULA: |
| | | System.out.print(cell1.getCellFormula() + "\t"); |
| | | break; |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } |
| | | } |
| | | exitLoop = true; |
| | | break; |
| | | } |
| | | if (StringUtils.isNotEmpty(s)) { |
| | | datas.put(s, list); |
| | | String value = "zss"; |
| | | switch (row.getCell(1).getCellType()){ |
| | | case STRING: |
| | | value = cell.getStringCellValue(); |
| | | break; |
| | | } |
| | | list = new ArrayList<>(); |
| | | s = cell.getStringCellValue(); |
| | | datas.put(s, cell.getStringCellValue()); |
| | | System.out.print(cell.getStringCellValue() + "\t"); |
| | | if (value.equals("zss")){ |
| | | if (StringUtils.isNotEmpty(s)) { |
| | | datas.put(s, list); |
| | | } |
| | | list = new ArrayList<>(); |
| | | s = cell.getStringCellValue(); |
| | | datas.put(s, cell.getStringCellValue()); |
| | | System.out.print(cell.getStringCellValue() + "\t"); |
| | | } |
| | | break; |
| | | case NUMERIC: |
| | | int columnIndex = cell.getColumnIndex(); |
| | | Object o = project.get(columnIndex); |
| | | map.put(o.toString(), cell.getNumericCellValue()); |
| | | System.out.print(cell.getNumericCellValue() + "\t"); |
| | | int columnIndex = cell.getColumnIndex(); |
| | | Object o = project.get(columnIndex); |
| | | map.put(o.toString(), cell.getNumericCellValue()); |
| | | System.out.print(cell.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell.getBooleanCellValue() + "\t"); |
| | |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } |
| | | if (exitLoop){ |
| | | exitLoop=false; |
| | | if (exitLoop) { |
| | | exitLoop = false; |
| | | break; |
| | | } |
| | | if (map.isEmpty()) { |
| | |
| | | } |
| | | } |
| | | } |
| | | list=list.stream().filter(map -> !map.isEmpty()).collect(Collectors.toList()); |
| | | datas.put(s, list); |
| | | map1.put(sheetName, datas); |
| | | datas1.putAll(map1); |
| | |
| | | for (Map<String, Object> number : hashMaps) { |
| | | number.put("端口", s1); |
| | | Double o = (Double) number.get("频率"); |
| | | if (o!=null) { |
| | | if (o != null) { |
| | | floatList.add(o); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | System.out.println(map); |
| | | int size = map.size(); |
| | | for (String s1 : map.keySet()) { |
| | | String o = map.get(s1).toString(); |
| | | List<String> collect = Arrays.stream(o.split(",")).collect(Collectors.toList()); |
| | |
| | | } |
| | | } |
| | | System.out.println(map); |
| | | createWord(sonLaboratory, document, exceldata, map, insOrderFile); |
| | | createWord(sonLaboratory, document, exceldata, map, biaozhun, insOrderFile); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | |
| | | } |
| | | } |
| | | |
| | | //远场 |
| | | public void getFuSheWord2(String sonLaboratory, InsOrderFile insOrderFile) { |
| | | //读取excel文件内容 |
| | | String excelFilePath = wordUrl + "/" + insOrderFile.getFileUrl(); // 更新为你的文件路径 |
| | | String fileEncoding = "GBK"; // 或其他编码格式,如GBK, ISO-8859-1 等 |
| | | Exceldata exceldata = new Exceldata(); |
| | | HashMap<Integer, Object> project = new HashMap<>(); |
| | | HashMap<String, Object> biaozhun = new HashMap<>(); |
| | | HashMap<String, Object> pingjunzhi = new HashMap<>(); |
| | | HashMap<String, Object> datas1 = new HashMap<>(); |
| | | HashMap<String, Object> map2 = new HashMap<>(); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | XWPFDocument document = new XWPFDocument(); |
| | | String jiaodu=""; |
| | | String port=""; |
| | | try (CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(excelFilePath), fileEncoding))) { |
| | | List<String[]> records = reader.readAll(); |
| | | for (int i = 0; i < records.size(); i++) { |
| | | HashMap<String, Object> map1 = new HashMap<>(); |
| | | HashMap<String, Object> pingjun = new HashMap<>(); |
| | | String[] record = records.get(i); |
| | | |
| | | for (int i1 = 0; i1 < record.length; i1++) { |
| | | String value = record[i1]; |
| | | if (i == 0) { |
| | | project.put(i1,value); |
| | | } |
| | | if (i == 1) { |
| | | biaozhun.put(project.get(i1).toString(),value); |
| | | } |
| | | if (i>2) { |
| | | if (i1==0&&StringUtils.isNotEmpty(value)) { |
| | | |
| | | if (map2.size() != 0) { |
| | | map2.put(port, list); |
| | | datas1.put(jiaodu, map2); |
| | | map2 = new HashMap<>(); |
| | | } |
| | | datas1.put(value, ""); |
| | | jiaodu=value; |
| | | } else if (i1 == 1 && StringUtils.isNotEmpty(value)) { |
| | | if (list.size() != 0) { |
| | | map2.put(port, list); |
| | | list = new ArrayList<>(); |
| | | } |
| | | map2.put(value, ""); |
| | | port=value; |
| | | } else if (StringUtils.isNotEmpty(value)) { |
| | | if (value.equals("最大值")||value.equals("最小值")||value.equals("指标")||value.equals("类别")) { |
| | | break; |
| | | } else if (value.equals("平均值")) { |
| | | for (int i2 = 0; i2 < record.length; i2++) { |
| | | String value1 = record[i2]; |
| | | if (value1.equals("平均值")) { |
| | | continue; |
| | | } |
| | | pingjun.put(project.get(i2).toString(),value1); |
| | | } |
| | | break; |
| | | } |
| | | map1.put(project.get(i1).toString(),value); |
| | | } |
| | | } |
| | | System.out.print(value + " "); |
| | | } |
| | | if (map1.size()!=0) { |
| | | list.add(map1); |
| | | } |
| | | if (pingjun.size()!=0) { |
| | | pingjunzhi.put(jiaodu,pingjun); |
| | | } |
| | | if (i==records.size()-1) { |
| | | map2.put(port,list); |
| | | datas1.put(jiaodu,map2); |
| | | } |
| | | System.out.println(); |
| | | } |
| | | System.out.println("-----------------"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | exceldata.setProject(project); |
| | | exceldata.setDataRow(datas1); |
| | | System.out.println(exceldata); |
| | | |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | for (String s : datas1.keySet()) { |
| | | Map<String, List<HashMap<String,Object>>> numbers = (Map<String, List<HashMap<String,Object>>>) datas1.get(s); |
| | | for (String s1 : numbers.keySet()) { |
| | | List<HashMap<String, Object>> hashMaps = numbers.get(s1); |
| | | |
| | | List<Integer> floatList = new ArrayList<>(); |
| | | for (Map<String, Object> number : hashMaps) { |
| | | number.put("端口", s1); |
| | | floatList.add( Integer.parseInt((String) number.get("测试频率(MHZ)"))); |
| | | } |
| | | Integer maxValue = Collections.max(floatList); |
| | | Integer minValue = Collections.min(floatList); |
| | | |
| | | if (map.get(minValue + "-" + maxValue+"-"+s) == null) { |
| | | map.put(minValue + "-" + maxValue+"-"+s, s1); |
| | | } else { |
| | | Object o = map.get(minValue + "-" + maxValue+"-"+s); |
| | | map.put(minValue + "-" + maxValue+"-"+s, s1 + "," + o); |
| | | } |
| | | } |
| | | |
| | | } |
| | | System.out.println(map); |
| | | |
| | | int size = map.size(); |
| | | for (String s1 : map.keySet()) { |
| | | String o = map.get(s1).toString(); |
| | | |
| | | List<String> collect = Arrays.stream(o.split(",")).collect(Collectors.toList()); |
| | | int size1 = -1; |
| | | |
| | | for (String s : datas1.keySet()) { |
| | | Map<String, List<HashMap<String,Object>>> o1 = (Map<String, List<HashMap<String,Object>>>)datas1.get(s); |
| | | for (String s3 : o1.keySet()) { |
| | | List<HashMap<String, Object>> numbers = o1.get(s3); |
| | | for (String s2 : collect) { |
| | | if (s3.equals(s2)) { |
| | | if (numbers.size() > size1) { |
| | | size1 = numbers.size(); |
| | | } |
| | | } |
| | | } |
| | | map.put(s1, o + "," + size1); |
| | | } |
| | | } |
| | | |
| | | } |
| | | System.out.println(map); |
| | | FileInputStream fileInputStream = null; |
| | | Workbook workbook = null; |
| | | |
| | | try { |
| | | createWord2(sonLaboratory,document,exceldata, map,pingjunzhi,biaozhun,insOrderFile); |
| | | fileInputStream = new FileInputStream(new File(excelFilePath)); |
| | | workbook = new XSSFWorkbook(fileInputStream); // 对于 .xlsx 文件 |
| | | XWPFDocument document = new XWPFDocument(); |
| | | for (int i = 0; i < workbook.getNumberOfSheets(); i++) { |
| | | Exceldata exceldata = new Exceldata(); |
| | | HashMap<Integer, Object> project = new HashMap<>(); |
| | | HashMap<String, Object> biaozhun = new HashMap<>(); |
| | | HashMap<String, Object> pingjunzhi = new HashMap<>(); |
| | | HashMap<String, Object> datas1 = new HashMap<>(); |
| | | HashMap<String, Object> map2 = new HashMap<>(); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | String jiaodu = ""; |
| | | String port = ""; |
| | | Integer count = 0; |
| | | Sheet sheet = workbook.getSheetAt(i); |
| | | Boolean biaoji = false; |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | for (Row row : sheet) { |
| | | count++; |
| | | HashMap<String, Object> map1 = new HashMap<>(); |
| | | HashMap<String, Object> pingjun = new HashMap<>(); |
| | | for (Cell cell : row) { |
| | | if (row.getRowNum() == 0) { |
| | | switch (cell.getCellType()) { |
| | | case STRING: |
| | | project.put(cell.getColumnIndex(), cell.getStringCellValue()); |
| | | System.out.print(cell.getStringCellValue() + "\t"); |
| | | break; |
| | | case NUMERIC: |
| | | System.out.print(cell.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell.getBooleanCellValue() + "\t"); |
| | | break; |
| | | case FORMULA: |
| | | System.out.print(cell.getCellFormula() + "\t"); |
| | | break; |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } else if (row.getRowNum() > 2) { |
| | | if (cell.getColumnIndex() == 0 && StringUtils.isNotEmpty(cell.getStringCellValue())) { |
| | | if (map2.size() != 0) { |
| | | map2.put(port, list); |
| | | datas1.put(jiaodu, map2); |
| | | map2 = new HashMap<>(); |
| | | } |
| | | datas1.put(cell.getStringCellValue(), ""); |
| | | jiaodu = cell.getStringCellValue(); |
| | | } else if (cell.getColumnIndex() == 1 && StringUtils.isNotEmpty(cell.getStringCellValue())) { |
| | | if (list.size() != 0) { |
| | | map2.put(port, list); |
| | | list = new ArrayList<>(); |
| | | } |
| | | map2.put(cell.getStringCellValue(), ""); |
| | | port = cell.getStringCellValue(); |
| | | |
| | | } else { |
| | | switch (cell.getCellType()) { |
| | | case STRING: |
| | | String value = cell.getStringCellValue(); |
| | | if (value.equals("avg")) { |
| | | for (Cell cell1 : row) { |
| | | switch (cell1.getCellType()) { |
| | | case STRING: |
| | | |
| | | break; |
| | | case NUMERIC: |
| | | pingjun.put(project.get(cell1.getColumnIndex()).toString(), cell1.getNumericCellValue()); |
| | | System.out.print(cell1.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell1.getBooleanCellValue() + "\t"); |
| | | break; |
| | | case FORMULA: |
| | | String cellFormula = cell1.getCellFormula(); |
| | | Double numericCellValue = cell1.getNumericCellValue(); |
| | | pingjun.put(project.get(cell1.getColumnIndex()).toString(), cell1.getNumericCellValue()); |
| | | System.out.print(cellFormula); |
| | | break; |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | |
| | | } |
| | | } else if (value.equals("指标")) { |
| | | for (Cell cell1 : row) { |
| | | switch (cell1.getCellType()) { |
| | | case STRING: |
| | | biaozhun.put(project.get(cell1.getColumnIndex()).toString(), cell1.getStringCellValue()); |
| | | break; |
| | | case NUMERIC: |
| | | System.out.print(cell1.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell1.getBooleanCellValue() + "\t"); |
| | | break; |
| | | case FORMULA: |
| | | System.out.print(cell1.getCellFormula() + "\t"); |
| | | break; |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } |
| | | } else { |
| | | biaoji = true; |
| | | } |
| | | break; |
| | | case NUMERIC: |
| | | map1.put(project.get(cell.getColumnIndex()).toString(), cell.getNumericCellValue()); |
| | | System.out.print(cell.getNumericCellValue() + "\t"); |
| | | break; |
| | | case BOOLEAN: |
| | | System.out.print(cell.getBooleanCellValue() + "\t"); |
| | | break; |
| | | case FORMULA: |
| | | System.out.print(cell.getCellFormula() + "\t"); |
| | | break; |
| | | default: |
| | | System.out.print("NULL\t"); |
| | | } |
| | | } |
| | | } |
| | | if (biaoji) { |
| | | biaoji = false; |
| | | break; |
| | | } |
| | | } |
| | | if (map1.size() != 0) { |
| | | list.add(map1); |
| | | } |
| | | if (pingjun.size() != 0) { |
| | | pingjunzhi.put(jiaodu, pingjun); |
| | | } |
| | | |
| | | if (count == lastRowNum + 1) { |
| | | map2.put(port, list); |
| | | datas1.put(jiaodu, map2); |
| | | } |
| | | System.out.println(); |
| | | } |
| | | exceldata.setProject(project); |
| | | exceldata.setDataRow(datas1); |
| | | System.out.println(exceldata); |
| | | |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | for (String s : datas1.keySet()) { |
| | | Map<String, List<HashMap<String, Object>>> numbers = (Map<String, List<HashMap<String, Object>>>) datas1.get(s); |
| | | for (String s1 : numbers.keySet()) { |
| | | List<HashMap<String, Object>> hashMaps = numbers.get(s1); |
| | | List<Integer> floatList = new ArrayList<>(); |
| | | for (Map<String, Object> number : hashMaps) { |
| | | number.put("端口", s1); |
| | | Double o = (Double) number.get("测试频率(MHZ)"); |
| | | floatList.add(o.intValue()); |
| | | } |
| | | Integer maxValue = Collections.max(floatList); |
| | | Integer minValue = Collections.min(floatList); |
| | | |
| | | if (map.get(minValue + "-" + maxValue + "-" + s) == null) { |
| | | map.put(minValue + "-" + maxValue + "-" + s, s1); |
| | | } else { |
| | | Object o = map.get(minValue + "-" + maxValue + "-" + s); |
| | | map.put(minValue + "-" + maxValue + "-" + s, s1 + "," + o); |
| | | } |
| | | } |
| | | |
| | | } |
| | | System.out.println(map); |
| | | |
| | | for (String s1 : map.keySet()) { |
| | | String o = map.get(s1).toString(); |
| | | List<String> collect = Arrays.stream(o.split(",")).collect(Collectors.toList()); |
| | | int size1 = -1; |
| | | for (String s : datas1.keySet()) { |
| | | Map<String, List<HashMap<String, Object>>> o1 = (Map<String, List<HashMap<String, Object>>>) datas1.get(s); |
| | | for (String s3 : o1.keySet()) { |
| | | List<HashMap<String, Object>> numbers = o1.get(s3); |
| | | for (String s2 : collect) { |
| | | if (s3.equals(s2)) { |
| | | if (numbers.size() > size1) { |
| | | size1 = numbers.size(); |
| | | } |
| | | } |
| | | } |
| | | map.put(s1, o + "," + size1); |
| | | } |
| | | } |
| | | |
| | | } |
| | | System.out.println(map); |
| | | |
| | | createWord2(sonLaboratory, document, exceldata, map, pingjunzhi, biaozhun, insOrderFile); |
| | | |
| | | } |
| | | // 输出到文件 |
| | | InsSample insSample = insSampleMapper.selectById(insOrderFile.getInsSampleId()); |
| | | String[] split = insOrderFile.getFileName().split("\\."); |
| | | String name = insOrderFile.getFileName().replace("#", "&").substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length())); |
| | | String url = UUID.randomUUID() + "_" + insSample.getSampleCode() + "_" + sonLaboratory + name + "解析的辐射站点报告.docx"; |
| | | url = url.replace("#", "&"); |
| | | FileOutputStream out = new FileOutputStream(wordUrl + "/" + url); |
| | | document.write(out); |
| | | out.close(); |
| | | document.close(); |
| | | InsOrderFile orderFile = new InsOrderFile(); |
| | | orderFile.setInsOrderId(insOrderFile.getInsOrderId()); |
| | | orderFile.setInsSampleId(insOrderFile.getInsSampleId()); |
| | | orderFile.setFileUrl(url); |
| | | orderFile.setType(2); |
| | | orderFile.setFileName(insSample.getSampleCode() + "&" + sonLaboratory + name + "解析的辐射站点报告.docx"); |
| | | orderFile.setSonLaboratory(sonLaboratory); |
| | | insOrderFileMapper.insert(orderFile); |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } finally { |
| | | // 关闭资源 |
| | | try { |
| | | if (workbook != null) { |
| | | workbook.close(); |
| | | } |
| | | if (fileInputStream != null) { |
| | | fileInputStream.close(); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | public void createWord(String sonLaboratory, XWPFDocument document, Exceldata exceldata, HashMap<String, Object> map, InsOrderFile insOrderFile) throws IOException { |
| | | //近场 |
| | | public void createWord(String sonLaboratory, XWPFDocument document, Exceldata exceldata, HashMap<String, Object> map, HashMap<String, Object> bz, InsOrderFile insOrderFile) throws IOException { |
| | | int size = 1; |
| | | XWPFParagraph paragraphs = document.createParagraph(); |
| | | XWPFRun runs = paragraphs.createRun(); |
| | |
| | | paragraph1.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run1 = paragraph1.createRun(); |
| | | run1.setText(s2); |
| | | // 调用方法提取第一个括号内的内容 |
| | | String firstContent = extractFirstContentFromBrackets(s2); |
| | | if (firstContent != null) { |
| | | XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0); |
| | | paragraph2.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run2 = paragraph2.createRun(); |
| | | run2.setText(firstContent); |
| | | // 单位 |
| | | XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0); |
| | | XWPFRun run2 = paragraph2.createRun(); |
| | | if (s2.contains("增益")) { |
| | | run2.setText("dBi"); |
| | | } else if (s2.contains("波瓣宽度") || s2.contains("波束宽度") || s2.contains("下倾角")) { |
| | | run2.setText("°"); |
| | | } else if (s2.contains("前后比") || s2.contains("交叉极化") || s2.contains("旁瓣抑制") || s2.contains("下降") || s2.contains("零点填充") || s2.contains("副瓣电平")) { |
| | | run2.setText("dB"); |
| | | } else if (s2.contains("效率") || s2.contains("扇区占比")) { |
| | | run2.setText("%"); |
| | | } else { |
| | | System.out.println("没有找到括号内的内容。"); |
| | | run2.setText(""); |
| | | } |
| | | XWPFParagraph paragraph3 = table.getRow(0).getCell(3).getParagraphArray(0); |
| | | paragraph3.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run3 = paragraph3.createRun(); |
| | | run3.setText("/"); |
| | | if (bz.get(s2) != null) { |
| | | run3.setText(bz.get(s2).toString()); |
| | | } else run3.setText(""); |
| | | XWPFParagraph paragraph4 = table.getRow(0).getCell(4).getParagraphArray(0); |
| | | paragraph4.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run4 = paragraph4.createRun(); |
| | |
| | | paragraph11.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run11 = paragraph11.createRun(); |
| | | double v = count / (Double.parseDouble(s1.toString()) * Double.parseDouble(i1.toString())); |
| | | run11.setText(String.format("%.2f",v)); |
| | | run11.setText(String.format("%.2f", v)); |
| | | size++; |
| | | } |
| | | } |
| | | // 输出到文件 |
| | | try { |
| | | InsOrder insOrder = insOrderMapper.selectById(insOrderFile.getInsOrderId()); |
| | | InsSample insSample = insSampleMapper.selectById(insOrderFile.getInsSampleId()); |
| | | String[] split = insOrderFile.getFileName().split("\\."); |
| | | String name = insOrderFile.getFileName().substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length())); |
| | | FileOutputStream out = new FileOutputStream(wordUrl + "/" + insOrder.getEntrustCode() + "&" + sonLaboratory + name + "解析的辐射站点报告.docx"); |
| | | String name = insOrderFile.getFileName().replace('#', '&').substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length())); |
| | | String url = UUID.randomUUID() + "_" + insSample.getSampleCode() + "&" + sonLaboratory + name + "解析的辐射站点报告.docx"; |
| | | url.replace("#", "&"); |
| | | FileOutputStream out = new FileOutputStream(wordUrl + "/" + url); |
| | | document.write(out); |
| | | out.close(); |
| | | document.close(); |
| | | InsOrderFile orderFile = new InsOrderFile(); |
| | | orderFile.setInsOrderId(insOrderFile.getInsOrderId()); |
| | | orderFile.setFileUrl(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "解析的辐射站点报告.docx"); |
| | | orderFile.setInsSampleId(insOrderFile.getInsSampleId()); |
| | | orderFile.setFileUrl(url); |
| | | orderFile.setType(2); |
| | | orderFile.setFileName(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "解析的辐射站点报告.docx"); |
| | | orderFile.setFileName(insSample.getSampleCode() + "&" + sonLaboratory + name + "解析的辐射站点报告.docx"); |
| | | orderFile.setSonLaboratory(sonLaboratory); |
| | | insOrderFileMapper.insert(orderFile); |
| | | } catch (IOException e) { |
| | |
| | | } |
| | | } |
| | | |
| | | public void createWord2(String sonLaboratory,XWPFDocument document,Exceldata exceldata, HashMap<String, Object> map,HashMap<String,Object> pj,HashMap<String,Object> bz,InsOrderFile insOrderFile) throws IOException { |
| | | //远场 |
| | | public void createWord2(String sonLaboratory, XWPFDocument document, Exceldata exceldata, HashMap<String, Object> map, HashMap<String, Object> pj, HashMap<String, Object> bz, InsOrderFile insOrderFile) throws IOException { |
| | | int size = 1; |
| | | for (String s : map.keySet()) { |
| | | Map<String, Object> dataRow = exceldata.getDataRow(); |
| | | String result = s.substring(s.lastIndexOf("-") + 1); |
| | | String result1 = s.substring(0,s.lastIndexOf("-")); |
| | | String result1 = s.substring(0, s.lastIndexOf("-")); |
| | | String o = map.get(s).toString(); |
| | | String[] split = o.split(","); |
| | | Integer s1 = Integer.parseInt(split[split.length - 1]); |
| | | Integer i1 = split.length - 1; |
| | | int row = 3 + s1; |
| | | int cell = 6 + i1; |
| | | HashMap<String,Object> o2 =(HashMap<String,Object>) pj.get(result); |
| | | HashMap<String, Object> o2 = (HashMap<String, Object>) pj.get(result); |
| | | |
| | | XWPFTable table1 = document.createTable(2, cell); |
| | | |
| | |
| | | XWPFRun run15 = paragraph15.createRun(); |
| | | run15.setText("标准要求"); |
| | | |
| | | XWPFParagraph paragraph16 = table1.getRow(0).getCell(cell-1).getParagraphArray(0); |
| | | XWPFParagraph paragraph16 = table1.getRow(0).getCell(cell - 1).getParagraphArray(0); |
| | | XWPFRun run16 = paragraph16.createRun(); |
| | | run16.setText("检验结论"); |
| | | |
| | |
| | | |
| | | XWPFParagraph paragraph18 = table1.getRow(1).getCell(0).getParagraphArray(0); |
| | | XWPFRun run18 = paragraph18.createRun(); |
| | | run18.setText("频段: "+result1+"MHz "+"下倾角"+result); |
| | | |
| | | run18.setText("频段: " + result1 + "MHz " + "下倾角" + result); |
| | | |
| | | |
| | | List<String> collect = Arrays.stream(split).collect(Collectors.toList()); |
| | | |
| | | int size1 = 0; |
| | | collect.sort((o1, o21) -> Integer.parseInt(o1.substring((o1.length() - 1))) - Integer.parseInt(o21.substring(o21.length() - 1))); |
| | | |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | |
| | |
| | | |
| | | Map<String, List<Map<String, Object>>> o1 = (Map<String, List<Map<String, Object>>>) dataRow.get(result); |
| | | for (String s2 : collect) { |
| | | if (s2.contains("端口")||s2.contains("P")) { |
| | | if (s2.contains("端口") || s2.contains("P")) { |
| | | List<Map<String, Object>> mapList = o1.get(s2); |
| | | list.addAll(mapList); |
| | | } |
| | |
| | | |
| | | |
| | | for (String s2 : aggregatedMap.keySet()) { |
| | | if (s2.equals("端口")||s2.equals("测试频率(MHZ)")) { |
| | | if (s2.equals("端口") || s2.equals("测试频率(MHZ)")) { |
| | | continue; |
| | | } |
| | | List<Map<String, Object>> mapList = aggregatedMap.get(s2); |
| | |
| | | |
| | | XWPFTable table = document.createTable(row, cell); |
| | | table.setWidth("100%"); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /* // 合并单元格 |
| | | mergeCellsHorizontally(table, 0, 0, 7);*/ |
| | | |
| | | |
| | | //垂直 |
| | | mergeCellsVertically(table, 0, 0, row - 1); |
| | |
| | | XWPFRun run1 = paragraph1.createRun(); |
| | | run1.setText(s2); |
| | | |
| | | // 调用方法提取第一个括号内的内容 |
| | | String firstContent = extractFirstContentFromBrackets(s2); |
| | | if (firstContent != null) { |
| | | XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0); |
| | | XWPFRun run2 = paragraph2.createRun(); |
| | | run2.setText(firstContent); |
| | | // 单位 |
| | | XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0); |
| | | XWPFRun run2 = paragraph2.createRun(); |
| | | if (s2.contains("增益")) { |
| | | run2.setText("dBi"); |
| | | } else if (s2.contains("波瓣宽度") || s2.contains("波束宽度") || s2.contains("下倾角")) { |
| | | run2.setText("°"); |
| | | } else if (s2.contains("前后比") || s2.contains("交叉极化") || s2.contains("旁瓣抑制") || s2.contains("下降") || s2.contains("零点填充") || s2.contains("副瓣电平")) { |
| | | run2.setText("dB"); |
| | | } else if (s2.contains("效率") || s2.contains("扇区占比")) { |
| | | run2.setText("%"); |
| | | } else { |
| | | System.out.println("没有找到括号内的内容。"); |
| | | run2.setText(""); |
| | | } |
| | | |
| | | |
| | | |
| | | XWPFParagraph paragraph3 = table.getRow(0).getCell(3).getParagraphArray(0); |
| | | paragraph3.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run3 = paragraph3.createRun(); |
| | | run3.setText(bz.get(s2).toString()); |
| | | if (bz.get(s2) != null) { |
| | | run3.setText(bz.get(s2).toString()); |
| | | } else run3.setText(""); |
| | | |
| | | |
| | | XWPFParagraph paragraph4 = table.getRow(0).getCell(4).getParagraphArray(0); |
| | | XWPFRun run4 = paragraph4.createRun(); |
| | | run4.setText("频率(MHz)"); |
| | | |
| | | XWPFParagraph paragraph5 = table.getRow(0).getCell(5).getParagraphArray(0); |
| | | paragraph5.setAlignment(ParagraphAlignment.CENTER); |
| | | XWPFRun run5 = paragraph5.createRun(); |
| | | run5.setText("端口"); |
| | | |
| | |
| | | |
| | | for (int i = 0; i < collect.size(); i++) { |
| | | String s3 = collect.get(i); |
| | | if (s3.contains("端口")||s3.contains("P")) { |
| | | if (s3.contains("端口") || s3.contains("P")) { |
| | | XWPFParagraph paragraph10 = table.getRow(1).getCell(5 + i).getParagraphArray(0); |
| | | XWPFRun run10 = paragraph10.createRun(); |
| | | run10.setText(s3); |
| | |
| | | } |
| | | |
| | | Map<Integer, List<Map<String, Object>>> group = mapList.stream() |
| | | .collect(Collectors.groupingBy(item -> Integer.parseInt(item.get("测试频率(MHZ)").toString()) )); |
| | | .collect(Collectors.groupingBy(item -> { |
| | | Double aDouble = (Double) item.get("测试频率(MHZ)"); |
| | | return aDouble.intValue(); |
| | | })); |
| | | |
| | | |
| | | int hang = 2; |
| | |
| | | if (text.equals(port)) { |
| | | XWPFParagraph paragraph10 = table.getRow(hang).getCell(i).getParagraphArray(0); |
| | | XWPFRun run10 = paragraph10.createRun(); |
| | | count=Double.parseDouble(stringObjectMap.get(s2).toString())+count; |
| | | count = Double.parseDouble(stringObjectMap.get(s2).toString()) + count; |
| | | String project = stringObjectMap.get(s2).toString(); |
| | | run10.setText(project); |
| | | } |
| | |
| | | hang++; |
| | | } |
| | | |
| | | XWPFParagraph paragraph11 = table.getRow(row-1).getCell(5).getParagraphArray(0); |
| | | XWPFParagraph paragraph11 = table.getRow(row - 1).getCell(5).getParagraphArray(0); |
| | | XWPFRun run11 = paragraph11.createRun(); |
| | | double v = count / (Double.parseDouble(s1.toString()) * Double.parseDouble(i1.toString())); |
| | | run11.setText(o2.get(s2).toString()); |
| | | run11.setText(String.format("%.2f",(double)o2.get(s2))); |
| | | |
| | | size++; |
| | | } |
| | | } |
| | | |
| | | |
| | | // 输出到文件 |
| | | try { |
| | | InsOrder insOrder = insOrderMapper.selectById(insOrderFile.getInsOrderId()); |
| | | String[] split = insOrderFile.getFileName().split("\\."); |
| | | String name = insOrderFile.getFileName().replace("#","&").substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length())); |
| | | FileOutputStream out = new FileOutputStream(wordUrl + "/" + insOrder.getEntrustCode() + "&" + sonLaboratory + name + "解析的辐射站点报告.docx"); |
| | | document.write(out); |
| | | out.close(); |
| | | document.close(); |
| | | InsOrderFile orderFile = new InsOrderFile(); |
| | | orderFile.setInsOrderId(insOrderFile.getInsOrderId()); |
| | | orderFile.setFileUrl(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "解析的辐射站点报告.docx"); |
| | | orderFile.setType(2); |
| | | orderFile.setFileName(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "解析的辐射站点报告.docx"); |
| | | orderFile.setSonLaboratory(sonLaboratory); |
| | | insOrderFileMapper.insert(orderFile); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | table.getRow(i).getCell(col).getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 提取第一个括号内的内容 |
| | | public static String extractFirstContentFromBrackets(String str) { |
| | | // 定义正则表达式,匹配括号内的内容,同时支持中文和英文括号 |
| | | Pattern pattern = Pattern.compile("\\((.*?)\\)|\\((.*?)\\)"); |
| | | Matcher matcher = pattern.matcher(str); |
| | | |
| | | // 查找第一个匹配的内容 |
| | | if (matcher.find()) { |
| | | // 获取括号内的内容,判断是中文括号还是英文括号 |
| | | return matcher.group(1) != null ? matcher.group(1) : matcher.group(2); |
| | | } |
| | | return null; // 如果没有找到匹配项,则返回null |
| | | } |
| | | |
| | | } |