chenrui
2025-03-20 68897236636f9c54e34bdca52864cb424c2291e5
inspect-server/src/main/java/com/yuanchu/mom/utils/FuSheUtils.java
@@ -1,24 +1,15 @@
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.deepoove.poi.data.*;
import com.deepoove.poi.data.style.*;
import com.deepoove.poi.util.TableTools;
import com.opencsv.CSVReader;
import com.yuanchu.mom.dto.Exceldata;
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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
@@ -32,10 +23,9 @@
import javax.annotation.Resource;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Slf4j
@Component
public class FuSheUtils {
    @Value("${wordUrl}")
@@ -700,7 +690,6 @@
        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 o = map.get(s).toString();
            String[] split = o.split(",");
            Integer s1 = Integer.parseInt(split[split.length - 1]);
@@ -710,6 +699,7 @@
            HashMap<String, Object> o2 = (HashMap<String, Object>) pj.get(result);
            XWPFTable table1 = document.createTable(2, cell);
            table1.setWidth("100%");
            mergeCellsHorizontally(table1, 1, 0, cell - 1);
            mergeCellsHorizontally(table1, 0, 4, cell - 2);
@@ -769,42 +759,43 @@
                    aggregatedMap.get(key).add(item);
                }
            }
            // 初始化行数
            int rowNum = 2;
            for (String s2 : aggregatedMap.keySet()) {
                if (s2.equals("端口") || s2.equals("测试频率(MHZ)")) {
                    continue;
                }
                List<Map<String, Object>> mapList = aggregatedMap.get(s2);
                // 创建一个表格
                XWPFTable table = document.createTable(row, cell);
                table.setWidth("100%");
                int checkItemRowNum = row;
                for (int i = 0; i < checkItemRowNum; i++) {
                    table1.createRow(); // 创建新行
                }
//            XWPFTable table = document.createTable(row, cell);
                //垂直
                mergeCellsVertically(table, 0, 0, row - 1);
                mergeCellsVertically(table, 1, 0, row - 1);
                mergeCellsVertically(table, 2, 0, row - 1);
                mergeCellsVertically(table, 3, 0, row - 1);
                mergeCellsVertically(table, 4, 0, 1);
                mergeCellsVertically(table, cell - 1, 0, 1);
                mergeCellsVertically(table, cell - 1, 2, row - 2);
                mergeCellsVertically(table1, 0, rowNum, rowNum +  checkItemRowNum - 1);
                mergeCellsVertically(table1, 1, rowNum, rowNum +  checkItemRowNum - 1);
                mergeCellsVertically(table1, 2, rowNum, rowNum +  checkItemRowNum - 1);
                mergeCellsVertically(table1, 3, rowNum, rowNum +  checkItemRowNum - 1);
                mergeCellsVertically(table1, 4, rowNum, 1);
                mergeCellsVertically(table1, cell - 1, rowNum, rowNum+1);
                mergeCellsVertically(table1, cell - 1, rowNum+2, rowNum +  checkItemRowNum - 1);
                //水平
                mergeCellsHorizontally(table, 0, 5, cell - 2);
                mergeCellsHorizontally(table, row - 1, 5, cell - 2);
                mergeCellsHorizontally(table1, rowNum, 5, cell - 2);
                mergeCellsHorizontally(table1, rowNum + checkItemRowNum - 1, 5, cell - 2);
                // 设置单元格文本并居中
                XWPFParagraph paragraph = table.getRow(0).getCell(0).getParagraphArray(0);
                XWPFParagraph paragraph = table1.getRow(rowNum).getCell(0).getParagraphArray(0);
                XWPFRun run = paragraph.createRun();
                run.setText(String.valueOf(size));
                XWPFParagraph paragraph1 = table.getRow(0).getCell(1).getParagraphArray(0);
                XWPFParagraph paragraph1 = table1.getRow(rowNum).getCell(1).getParagraphArray(0);
                XWPFRun run1 = paragraph1.createRun();
                run1.setText(s2);
                // 单位
                XWPFParagraph paragraph2 = table.getRow(0).getCell(2).getParagraphArray(0);
                XWPFParagraph paragraph2 = table1.getRow(rowNum).getCell(2).getParagraphArray(0);
                XWPFRun run2 = paragraph2.createRun();
                if (s2.contains("增益")) {
                    run2.setText("dBi");
@@ -819,44 +810,47 @@
                }
                XWPFParagraph paragraph3 = table.getRow(0).getCell(3).getParagraphArray(0);
                // 定义改检查项标准值
                String checkItemStandardStr = "";
                XWPFParagraph paragraph3 = table1.getRow(rowNum).getCell(3).getParagraphArray(0);
                paragraph3.setAlignment(ParagraphAlignment.CENTER);
                XWPFRun run3 = paragraph3.createRun();
                if (bz.get(s2) != null) {
                    run3.setText(bz.get(s2).toString());
                    checkItemStandardStr = bz.get(s2).toString();
                } else run3.setText("");
                XWPFParagraph paragraph4 = table.getRow(0).getCell(4).getParagraphArray(0);
                XWPFParagraph paragraph4 = table1.getRow(rowNum).getCell(4).getParagraphArray(0);
                XWPFRun run4 = paragraph4.createRun();
                run4.setText("频率(MHz)");
                XWPFParagraph paragraph5 = table.getRow(0).getCell(5).getParagraphArray(0);
                XWPFParagraph paragraph5 = table1.getRow(rowNum).getCell(5).getParagraphArray(0);
                paragraph5.setAlignment(ParagraphAlignment.CENTER);
                XWPFRun run5 = paragraph5.createRun();
                run5.setText("端口");
                XWPFParagraph paragraph6 = table.getRow(0).getCell(cell - 1).getParagraphArray(0);
                XWPFParagraph paragraph6 = table1.getRow(rowNum).getCell(cell - 1).getParagraphArray(0);
                XWPFRun run6 = paragraph6.createRun();
                run6.setText("判定");
                XWPFParagraph paragraph7 = table.getRow(1).getCell(cell - 1).getParagraphArray(0);
                XWPFParagraph paragraph7 = table1.getRow(rowNum+1).getCell(cell - 1).getParagraphArray(0);
                XWPFRun run7 = paragraph7.createRun();
                run7.setText("合格");
                XWPFParagraph paragraph8 = table.getRow(row - 1).getCell(4).getParagraphArray(0);
                XWPFParagraph paragraph8 = table1.getRow(rowNum+checkItemRowNum - 1).getCell(4).getParagraphArray(0);
                XWPFRun run8 = paragraph8.createRun();
                run8.setText("平均值");
                XWPFParagraph paragraph9 = table.getRow(row - 1).getCell(cell - 1).getParagraphArray(0);
                XWPFParagraph paragraph9 = table1.getRow(rowNum + checkItemRowNum - 1).getCell(cell - 1).getParagraphArray(0);
                XWPFRun run9 = paragraph9.createRun();
                run9.setText("");
                for (int i = 0; i < collect.size(); i++) {
                for (int i = 0; i < collect.size() - 1; i++) {
                    String s3 = collect.get(i);
                    if (s3.contains("端口") || s3.contains("P")) {
                        XWPFParagraph paragraph10 = table.getRow(1).getCell(5 + i).getParagraphArray(0);
                        XWPFParagraph paragraph10 = table1.getRow(rowNum+1).getCell(5 + i).getParagraphArray(0);
                        XWPFRun run10 = paragraph10.createRun();
                        run10.setText(s3);
                    }
@@ -871,34 +865,100 @@
                int hang = 2;
                Double count = 0.0;
                // 定义 是否合格标记
                boolean passFlag = true;
                // 解析判定条件并解析比较标准值 0 无需判定 1 区间判定 2 小于等于 3 大于等于
                int checkType = 0;
                double firstParam = 0.0;
                double secondParam = 0.0 ;
                checkItemStandardStr = checkItemStandardStr.trim();
                if(checkItemStandardStr.contains("~") ){
                    checkType = 1;
                    String[] params = checkItemStandardStr.split("~");
                    if(null != params && params.length == 2){
                        firstParam = Double.valueOf(params[0]);
                        secondParam = Double.valueOf(params[1]);
                    }
                } else if(checkItemStandardStr.contains("-") && !(checkItemStandardStr.contains("≤") || checkItemStandardStr.contains("≥"))){
                    checkType = 1;
                    String[] params = checkItemStandardStr.split("-");
                    if(null != params && params.length == 2){
                        firstParam = Double.valueOf(params[0]);
                        secondParam = Double.valueOf(params[1]);
                    }
                } else if (checkItemStandardStr.contains("≤")) {
                    checkType = 2;
                    String[] params = checkItemStandardStr.split("≤");
                    if(null != params && params.length == 1){
                        if(params[1].contains("%")){
                            firstParam = Double.valueOf(params[1].substring(0,params[1].length()-1))/100;
                        }else{
                            firstParam = Double.valueOf(params[1]);
                        }
                    }
                }else if(checkItemStandardStr.contains("≥")){
                    checkType = 3;
                    String[] params = checkItemStandardStr.split("≥");
                    if(null != params && params.length == 2){
                        if(params[1].contains("%")){
                            firstParam = Double.valueOf(params[1].substring(0,params[1].length()-1))/100;
                        }else{
                            firstParam = Double.valueOf(params[1]);
                        }
                    }
                }
                for (Integer aDouble : group.keySet()) {
                    List<Map<String, Object>> mapList1 = group.get(aDouble);
                    for (Map<String, Object> stringObjectMap : mapList1) {
                        String port = stringObjectMap.get("端口").toString();
                        for (int i = 5; i < cell - 1; i++) {
                            String text = table.getRow(1).getCell(i).getText();
                            String text = table1.getRow(rowNum+1).getCell(i).getText();
                            if (text.equals(port)) {
                                XWPFParagraph paragraph10 = table.getRow(hang).getCell(i).getParagraphArray(0);
                                XWPFParagraph paragraph10 = table1.getRow(hang+rowNum).getCell(i).getParagraphArray(0);
                                XWPFRun run10 = paragraph10.createRun();
                                count = Double.parseDouble(stringObjectMap.get(s2).toString()) + count;
                                double value = Double.parseDouble(stringObjectMap.get(s2).toString());
                                count = value + count;
                                // 数据判断
                                if(checkType == 1){
                                    if(!(value >= firstParam && value <= secondParam)){
                                        passFlag = false;
                                    }
                                }else if(checkType == 2){
                                    if(value >= firstParam ){
                                        passFlag = false;
                                    }
                                }else if(checkType == 3){
                                    if(value <= firstParam ){
                                        passFlag = false;
                                    }
                                }
                                String project = stringObjectMap.get(s2).toString();
                                run10.setText(project);
                            }
                        }
                    }
                    XWPFParagraph paragraph10 = table.getRow(hang).getCell(4).getParagraphArray(0);
                    XWPFParagraph paragraph10 = table1.getRow(hang+rowNum).getCell(4).getParagraphArray(0);
                    XWPFRun run10 = paragraph10.createRun();
                    run10.setText(String.valueOf(aDouble));
                    hang++;
                }
                // 汇总结果
                if(checkType != 0){
                    XWPFParagraph paragraph10 = table1.getRow(rowNum+2).getCell(cell - 1).getParagraphArray(0);
                    XWPFRun run10 = paragraph10.createRun();
                    if(passFlag){
                        run10.setText(String.valueOf("合格"));
                    }else {
                        run10.setText(String.valueOf("不合格"));
                    }
                }
                XWPFParagraph paragraph11 = table.getRow(row - 1).getCell(5).getParagraphArray(0);
                XWPFParagraph paragraph11 = table1.getRow(rowNum + checkItemRowNum - 1).getCell(5).getParagraphArray(0);
                XWPFRun run11 = paragraph11.createRun();
                double v = count / (Double.parseDouble(s1.toString()) * Double.parseDouble(i1.toString()));
                run11.setText(String.format("%.2f",(double)o2.get(s2)));
                rowNum += checkItemRowNum;
                size++;
            }
        }