| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.*; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | |
| | | List<InsProductResult2> result2s = insProductResult2Mapper.selectList(Wrappers.<InsProductResult2>lambdaQuery() |
| | | .eq(InsProductResult2::getNum, orderStates.get(0).getNum()) |
| | | .in(InsProductResult2::getInsProductId, insProducts.stream().distinct().map(InsProduct::getId).collect(Collectors.toList()))); |
| | | //List<InsProduct> productList = getInsProduct(sampleId, "电路试验"); |
| | | //根据频点分类 |
| | | Map<String, List<HuTiaoData>> collect = huTiaoData.stream() |
| | | .collect(Collectors.groupingBy(HuTiaoData::getOften, LinkedHashMap::new, Collectors.toList())); |
| | |
| | | List<InsProduct> products1 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("电压驻波比")).collect(Collectors.toList()); |
| | | //查询该样品的同极化隔离度项目id |
| | | List<InsProduct> products2 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("同极化隔离度")).collect(Collectors.toList()); |
| | | //查询该样品的隔离度项目id |
| | | List<InsProduct> products6 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("同列隔离度")).collect(Collectors.toList()); |
| | | //查询该样品的端口间隔离度项目id |
| | | List<InsProduct> products7 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("端口间隔离度")).collect(Collectors.toList()); |
| | | //查询该样品的异极化隔离度项目id |
| | | List<InsProduct> products3 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("异极化隔离度")).collect(Collectors.toList()); |
| | | //查询该样品的幅度偏差项目id |
| | |
| | | String value = entry.getValue().stream().map(tianXianData1 -> "\"" + tianXianData1.getValue() + "\"").collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } else if (entry.getKey().contains("同极化隔离") || entry.getKey().contains("同列隔离")) { |
| | | } else if (entry.getKey().contains("同列隔离")) { |
| | | if (products6.size() <= 0) { |
| | | throw new ErrorException("隔离度项目未找到"); |
| | | } |
| | | insProductResult2.setInsProductId(products6.get(0).getId());//同列隔离 |
| | | insProductResult2.setFrequency(listEntry.getKey());//频段 |
| | | insProductResult2.setAngle("0°");//角度 |
| | | insProductResult2.setNum(orderStates.get(0).getNum());//次数 |
| | | //获取端口 |
| | | String port = entry.getValue().stream().map(TianXianData::getPort).collect(Collectors.joining(",")); |
| | | insProductResult2.setPort(port);//端口 |
| | | //获取检验值 |
| | | String value = entry.getValue().stream().map(tianXianData1 -> "\"" + tianXianData1.getValue() + "\"").collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } else if (entry.getKey().contains("端口间隔离")) { |
| | | if (products7.size() <= 0) { |
| | | throw new ErrorException("端口间隔离项目未找到"); |
| | | } |
| | | insProductResult2.setInsProductId(products7.get(0).getId());//端口间隔离 |
| | | insProductResult2.setFrequency(listEntry.getKey());//频段 |
| | | insProductResult2.setAngle("0°");//角度 |
| | | insProductResult2.setNum(orderStates.get(0).getNum());//次数 |
| | | //获取端口 |
| | | String port = entry.getValue().stream().map(TianXianData::getPort).collect(Collectors.joining(",")); |
| | | insProductResult2.setPort(port);//端口 |
| | | //获取检验值 |
| | | String value = entry.getValue().stream().map(tianXianData1 -> "\"" + tianXianData1.getValue() + "\"").collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } |
| | | else if (entry.getKey().contains("同极化隔离")) { |
| | | if (products2.size() <= 0) { |
| | | throw new ErrorException("同极化隔离项目未找到"); |
| | | } |
| | |
| | | String value = entry.getValue().stream().map(tianXianData1 -> "\"" + tianXianData1.getValue() + "\"").collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } else if (entry.getKey().contains("异极化隔离") || entry.getKey().contains("端口间隔离")) { |
| | | } else if (entry.getKey().contains("异极化隔离")) { |
| | | if (products3.size() <= 0) { |
| | | throw new ErrorException("异极化隔离项目未找到"); |
| | | } |
| | |
| | | insProductResult2Service.saveBatch(filteredList); |
| | | } |
| | | |
| | | //读取csv的文件(无源器件) |
| | | public void readDianLuFile3(Integer sampleId, InsOrderFile insOrderFile) { |
| | | List<InsProductResult2> insProductResult2s = new ArrayList<>(); |
| | | String excelFilePath = wordUrl + "/" + insOrderFile.getFileUrl(); // 更新为你的文件路径 |
| | | List<TianXianData> tianXianData = readExcelData2(excelFilePath); |
| | | //查询检验任务id |
| | | List<InsOrderState> orderStates = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery() |
| | | .eq(InsOrderState::getInsSampleId, sampleId) |
| | | .eq(InsOrderState::getLaboratory, "电路试验")); |
| | | List<InsProduct> products = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getState, 1) |
| | | .eq(InsProduct::getInsSampleId, sampleId)); |
| | | //查询该样品的电压驻波比项目id |
| | | List<InsProduct> products1 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("电压驻波比")).collect(Collectors.toList()); |
| | | //查询该样品的无源器件隔离度项目id |
| | | List<InsProduct> products2 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("无源器件隔离度")).collect(Collectors.toList()); |
| | | //查询该样品的插入损耗项目id |
| | | List<InsProduct> products3 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("插入损耗")).collect(Collectors.toList()); |
| | | //查询该样品的带内波动项目id |
| | | List<InsProduct> products4 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("带内波动")).collect(Collectors.toList()); |
| | | //查询该样品的带外抑制项目id |
| | | List<InsProduct> products5 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("带外抑制")).collect(Collectors.toList()); |
| | | //查询该样品的最大耦合度项目id |
| | | List<InsProduct> products6 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("最大耦合度")).collect(Collectors.toList()); |
| | | //查询该样品的最小耦合度项目id |
| | | List<InsProduct> products7 = products.stream().filter(insProduct -> insProduct.getInspectionItemSubclass().equals("最小耦合度")).collect(Collectors.toList()); |
| | | //获取所有频段,根据频段进行分类 |
| | | Map<String, List<TianXianData>> map = tianXianData.stream().collect(Collectors.groupingBy(TianXianData::frequency, LinkedHashMap::new, Collectors.toList())); |
| | | for (Map.Entry<String, List<TianXianData>> listEntry : map.entrySet()) { |
| | | //获取信息,根据检验项目进行分类 |
| | | Map<String, List<TianXianData>> collect = listEntry.getValue().stream().collect(Collectors.groupingBy(TianXianData::getName, LinkedHashMap::new, Collectors.toList())); |
| | | for (Map.Entry<String, List<TianXianData>> entry : collect.entrySet()) { |
| | | InsProductResult2 insProductResult2 = new InsProductResult2(); |
| | | if (entry.getKey().contains("驻波")) { |
| | | if (products1.size() <= 0) { |
| | | throw new ErrorException("电压驻波比项目未找到"); |
| | | } |
| | | insProductResult2.setInsProductId(products1.get(0).getId());//电压驻波比 |
| | | insProductResult2.setFrequency(listEntry.getKey());//频段 |
| | | insProductResult2.setAngle("0°");//角度 |
| | | insProductResult2.setNum(orderStates.get(0).getNum());//次数 |
| | | //获取端口 |
| | | String port = entry.getValue().stream().map(TianXianData::getPort).collect(Collectors.joining(",")); |
| | | insProductResult2.setPort(port);//端口 |
| | | //获取检验值 |
| | | String value = entry.getValue().stream().map(tianXianData1 -> "\"" + tianXianData1.getValue() + "\"").collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } |
| | | else if (entry.getKey().contains("隔离度")) { |
| | | if (products2.size() <= 0) { |
| | | throw new ErrorException("隔离度项目未找到"); |
| | | } |
| | | insProductResult2.setInsProductId(products2.get(0).getId());//无源器件隔离度 |
| | | insProductResult2.setFrequency(listEntry.getKey());//频段 |
| | | insProductResult2.setAngle("0°");//角度 |
| | | insProductResult2.setNum(orderStates.get(0).getNum());//次数 |
| | | //获取端口 |
| | | String port = entry.getValue().stream().map(TianXianData::getPort).collect(Collectors.joining(",")); |
| | | insProductResult2.setPort(port);//端口 |
| | | //获取检验值 |
| | | String value = entry.getValue().stream().map(tianXianData1 -> "\"" + tianXianData1.getValue() + "\"").collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } |
| | | else if (entry.getKey().contains("插入损耗")) { |
| | | if (products3.size() <= 0) { |
| | | throw new ErrorException("插入损耗项目未找到"); |
| | | } |
| | | insProductResult2.setInsProductId(products3.get(0).getId());//插入损耗 |
| | | insProductResult2.setFrequency(listEntry.getKey());//频段 |
| | | insProductResult2.setAngle("0°");//角度 |
| | | insProductResult2.setNum(orderStates.get(0).getNum());//次数 |
| | | //获取端口 |
| | | String port = entry.getValue().stream().map(TianXianData::getPort).collect(Collectors.joining(",")); |
| | | insProductResult2.setPort(port);//端口 |
| | | //获取检验值 |
| | | String value = entry.getValue().stream().map(tianXianData1 -> "\"" + tianXianData1.getValue() + "\"").collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } |
| | | else if (entry.getKey().contains("带内波动")) { |
| | | if (products4.size() <= 0) { |
| | | throw new ErrorException("带内波动项目未找到"); |
| | | } |
| | | insProductResult2.setInsProductId(products4.get(0).getId());//带内波动 |
| | | insProductResult2.setFrequency(listEntry.getKey());//频段 |
| | | insProductResult2.setAngle("0°");//角度 |
| | | insProductResult2.setNum(orderStates.get(0).getNum());//次数 |
| | | //获取端口 |
| | | String port = entry.getValue().stream().map(TianXianData::getPort).collect(Collectors.joining(",")); |
| | | insProductResult2.setPort(port);//端口 |
| | | //获取检验值 |
| | | String value = entry.getValue().stream().map(tianXianData1 -> "\"" + tianXianData1.getValue() + "\"").collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } |
| | | else if (entry.getKey().contains("带外抑制")) { |
| | | if (products5.size() <= 0) { |
| | | throw new ErrorException("带外抑制项目未找到"); |
| | | } |
| | | insProductResult2.setInsProductId(products5.get(0).getId());//带外抑制 |
| | | insProductResult2.setFrequency(listEntry.getKey());//频段 |
| | | insProductResult2.setAngle("0°");//角度 |
| | | insProductResult2.setNum(orderStates.get(0).getNum());//次数 |
| | | //获取端口 |
| | | String port = entry.getValue().stream().map(TianXianData::getPort).collect(Collectors.joining(",")); |
| | | insProductResult2.setPort(port);//端口 |
| | | //获取检验值 |
| | | String value = entry.getValue().stream().map(tianXianData1 -> "\"" + tianXianData1.getValue() + "\"").collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } |
| | | else if (entry.getKey().contains("耦合度")) { |
| | | if (products6.size() <= 0 || products7.size()<=0) { |
| | | throw new ErrorException("耦合度项目未找到"); |
| | | } |
| | | insProductResult2.setFrequency(listEntry.getKey());//频段 |
| | | insProductResult2.setAngle("0°");//角度 |
| | | insProductResult2.setNum(orderStates.get(0).getNum());//次数 |
| | | //获取端口 |
| | | String port = entry.getValue().stream().map(TianXianData::getPort).collect(Collectors.joining(",")); |
| | | insProductResult2.setPort(port);//端口 |
| | | |
| | | /*最大耦合度*/ |
| | | insProductResult2.setInsProductId(products6.get(0).getId());//最大耦合度 |
| | | //获取检验值 |
| | | String value = entry.getValue().stream().map(tianXianData1 -> { |
| | | String input = tianXianData1.getValue().replace("[", "").replace("]", ""); |
| | | String[] parts = input.split("--"); |
| | | return "\"" + "-"+parts[1] + "\"" ; }).collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | /*最小耦合度*/ |
| | | insProductResult2.setInsProductId(products7.get(0).getId());//最小耦合度 |
| | | String value1 = entry.getValue().stream().map(tianXianData1 -> { |
| | | String input = tianXianData1.getValue().replace("[", "").replace("]", ""); |
| | | String[] parts = input.split("--"); |
| | | return "\"" +parts[0] + "\"" ; }).collect(Collectors.joining(",")); |
| | | insProductResult2.setValue("[[" + value1 + "]]");//值 |
| | | insProductResult2s.add(insProductResult2); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Map<String, List<InsProductResult2>> groupedMap = insProductResult2s.stream() |
| | | .collect(Collectors.groupingBy(item -> item.getInsProductId() + "_" + item.getFrequency())); |
| | | // 过滤出分组后数量等于1的组 |
| | | List<InsProductResult2> filteredList = groupedMap.values().stream() |
| | | .filter(list -> list.size() == 1) |
| | | .flatMap(List::stream) |
| | | .collect(Collectors.toList()); |
| | | for (Map.Entry<String, List<InsProductResult2>> entry : groupedMap.entrySet()) { |
| | | if (entry.getValue().size() > 1) { |
| | | InsProductResult2 result2 = new InsProductResult2(); |
| | | result2.setInsProductId(Integer.parseInt(entry.getKey().split("_")[0])); |
| | | result2.setFrequency(entry.getKey().split("_")[1]); |
| | | result2.setPort(entry.getValue().stream().map(InsProductResult2::getPort).collect(Collectors.joining(","))); |
| | | String value = entry.getValue().stream().map(insProductResult2 -> { |
| | | return insProductResult2.getValue().replace("[[", "").replace("]]", ""); |
| | | }).collect(Collectors.joining(",")); |
| | | result2.setValue("[[" + value + "]]"); |
| | | result2.setAngle("0°"); |
| | | result2.setOften(entry.getValue().stream().map(InsProductResult2::getOften).collect(Collectors.joining(","))); |
| | | filteredList.add(result2); |
| | | } |
| | | } |
| | | insProductResult2Service.saveBatch(filteredList); |
| | | } |
| | | |
| | | |
| | | public static List<HuTiaoData> readExcelData1(String filePath) { |
| | | List<HuTiaoData> dataList = new ArrayList<>(); |