| | |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | |
| | | Set<String> models = new HashSet<>(); |
| | | |
| | | AtomicReference<Integer> productSize = new AtomicReference<>(0); |
| | | AtomicReference<Integer> productSize1 = new AtomicReference<>(0); |
| | | AtomicReference<Integer> productSize2 = new AtomicReference<>(0); |
| | | AtomicReference<Integer> productSize3 = new AtomicReference<>(0); |
| | | String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; |
| | | SampleProductDto s = insSample; |
| | | models.add(s.getModel()); |
| | | /*查询标准方法*/ |
| | | standardMethod.addAll(insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, insSample.getId()) |
| | | .eq(InsProduct::getState, 1)).stream().map(InsProduct::getMethodS).distinct().collect(Collectors.toList())); |
| | | .eq(InsProduct::getState, 1)); |
| | | /*查询标准方法*/ |
| | | standardMethod.addAll(insProducts.stream().map(InsProduct::getMethodS).distinct().collect(Collectors.toList())); |
| | | //总数 |
| | | Long productCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId())); |
| | | productSize.set(productSize.get() + Integer.parseInt(productCount + "")); |
| | | //不判定 |
| | | Long productCount1 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId()) |
| | | .eq(InsProduct::getInsResult, 3)); |
| | | // productSize1.set(productSize1.get() + Integer.parseInt(productCount1 + "")); |
| | | productSize1.set(productSize1.get() + Integer.parseInt(0 + "")); |
| | | long productCount = insProducts.size(); |
| | | //不合格 |
| | | Long productCount2 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId()) |
| | | .eq(InsProduct::getInsResult, 0)); |
| | | long productCount2 = insProducts.stream().filter(insProduct -> insProduct.getInsResult() == 0).count(); |
| | | //合格=(不判定+合格) |
| | | long productCount1 = insProducts.stream().filter(insProduct -> insProduct.getInsResult() == 3).count(); |
| | | long productCount3 = productCount1 + insProducts.stream().filter(insProduct -> insProduct.getInsResult() == 1).count(); |
| | | //判断是否有辐射项目 |
| | | List<InsProduct> fusheProducts = insProducts.stream().filter(insProduct -> insProduct.getInspectionItem().equals("辐射试验")).collect(Collectors.toList()); |
| | | if (fusheProducts.size() > 0) { |
| | | for (InsProduct fusheProduct : fusheProducts) { |
| | | List<Long> vValues = new ArrayList<>(); |
| | | String insValue = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery() |
| | | .eq(InsProductResult::getInsProductId, fusheProduct.getId())).get(0).getInsValue(); |
| | | Pattern pattern = Pattern.compile("\"v\":\"(\\d+)\""); |
| | | Matcher matcher = pattern.matcher(insValue); |
| | | while (matcher.find()) { |
| | | vValues.add(Long.parseLong(matcher.group(1))); |
| | | } |
| | | //不合格 |
| | | if (vValues.get(1)!=0){ |
| | | productCount2 = productCount2 - 1 + vValues.get(1); |
| | | } |
| | | //合格 |
| | | if (vValues.get(0)!=0) { |
| | | if (fusheProduct.getInsResult()==1){ |
| | | productCount3 = productCount3 - 1 + vValues.get(0); |
| | | }else productCount3 = productCount3 + vValues.get(0); |
| | | } |
| | | //总数=项目总数-辐射项目数量+辐射具体的(合格+不合格)数量 |
| | | productCount = productCount - 1 + vValues.stream().mapToLong(Long::longValue).sum(); |
| | | } |
| | | } |
| | | productSize.set(productSize.get() + Integer.parseInt(productCount + "")); |
| | | productSize2.set(productSize2.get() + Integer.parseInt(productCount2 + "")); |
| | | //合格 |
| | | Long productCount3 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getInsSampleId, s.getId()) |
| | | .eq(InsProduct::getInsResult, 1)); |
| | | // productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + "")); |
| | | productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + productCount1 + "")); |
| | | productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + "")); |
| | | //将项目按照站点进行分类 |
| | | Map<String, List<InsProduct>> listMap = s.getInsProduct().stream().collect(Collectors.groupingBy(InsProduct::getSonLaboratory)); |
| | | // 创建一个 Map 将站点和项目ID的映射关系 |
| | |
| | | List<Map<String, Object>> tables4 = new ArrayList<>(); |
| | | Integer indexs = 1; |
| | | //判断是否有电路试验,环境试验 |
| | | List<String> strings = insReportDto1.getInsReportDto2s().stream().map(InsReportDto2::getLaboratory).distinct().collect(Collectors.toList()); |
| | | List<String> strings = insReportDto1.getInsReportDto2s().stream() |
| | | .map(InsReportDto2::getLaboratory).distinct().collect(Collectors.toList()); |
| | | if (strings.contains("近场") || strings.contains("远场")) { |
| | | Map<String, String> table = new HashMap<>(); |
| | | table.put("indexs", indexs + ""); |
| | | indexs += 1; |
| | | table.put("term", "辐射方向图参数"); |
| | | table.put("result", "不判定"); |
| | | List<Integer> list = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getState, 1) |
| | | .eq(InsProduct::getInsSampleId, insSample.getId()) |
| | | .eq(InsProduct::getInspectionItem, "辐射试验")).stream() |
| | | .map(InsProduct::getInsResult).distinct().collect(Collectors.toList()); |
| | | if (list.contains(0)) { |
| | | table.put("result", "不合格"); |
| | | } else { |
| | | table.put("result", "合格"); |
| | | } |
| | | tables.add(table); |
| | | /*辐射的试验表*/ |
| | | List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery() |
| | |
| | | Map<String, String> table2 = new HashMap<>(); |
| | | table2.put("indexs", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | table2.put("term", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | table2.put("result", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | List<Integer> list = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getState, 1) |
| | | .eq(InsProduct::getInsSampleId,insSample.getId()) |
| | | .in(InsProduct::getSonLaboratory, strings)).stream() |
| | | .map(InsProduct::getInsResult).distinct().collect(Collectors.toList()); |
| | | if (list.contains(0)) { |
| | | table2.put("result", "不合格"); |
| | | } else { |
| | | table2.put("result", "合格"); |
| | | } |
| | | tables.add(table2); |
| | | |
| | | Map<String, String> table3 = new HashMap<>(); |
| | |
| | | rowRenderData.setRowStyle(rowStyle); |
| | | List<CellRenderData> cells = new ArrayList<>(); |
| | | //列数 |
| | | for (int j = 0; j < 2; j++) { |
| | | for (int j = 0; j < 3; j++) { |
| | | CellRenderData cellRenderData = new CellRenderData(); |
| | | CellStyle cellStyle = new CellStyle(); |
| | | cellStyle.setVertAlign(XWPFTableCell.XWPFVertAlign.CENTER); |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText("试验要求"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //第三列 |
| | | textRenderData.setText("实验结果"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | } else if (j == 1) { |
| | | textRenderData.setText(products.get(i - 1).getTell()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //第三列 |
| | | //获取检验项目和结论 |
| | | InsProduct insProduct = products.get(i - 1); |
| | | textRenderData.setText("经过" + insProduct.getInspectionItemSubclass() + "之后,样品" + (insProduct.getInsResult() == 0 ? "不合格" : "无异常") + "。"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | |
| | | Map<String, Object> table4 = new HashMap<>(); |
| | | table4.put("table4", tableRenderData); |
| | | tables4.add(table4); |
| | | } else { |
| | | } |
| | | else { |
| | | Map<String, String> table = new HashMap<>(); |
| | | table.put("indexs", indexs + ""); |
| | | table.put("term", "电路参数"); |
| | |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | } |
| | | else { |
| | | //如果只有环境试验没有电路试验 |
| | | strings.remove("近场"); |
| | | strings.remove("远场"); |
| | |
| | | Map<String, String> table2 = new HashMap<>(); |
| | | table2.put("indexs", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | table2.put("term", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | table2.put("result", "环境试验:" + String.join("、", strings) + "∑1"); |
| | | List<Integer> list = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getState, 1) |
| | | .eq(InsProduct::getInsSampleId,insSample.getId()) |
| | | .in(InsProduct::getSonLaboratory, strings)).stream() |
| | | .map(InsProduct::getInsResult).distinct().collect(Collectors.toList()); |
| | | if (list.contains(0)) { |
| | | table2.put("result", "不合格"); |
| | | } else { |
| | | table2.put("result", "合格"); |
| | | } |
| | | tables.add(table2); |
| | | |
| | | /*创建环境试验条件表2*(项目数+1)*/ |
| | |
| | | rowRenderData.setRowStyle(rowStyle); |
| | | List<CellRenderData> cells = new ArrayList<>(); |
| | | //列数 |
| | | for (int j = 0; j < 2; j++) { |
| | | for (int j = 0; j < 3; j++) { |
| | | CellRenderData cellRenderData = new CellRenderData(); |
| | | CellStyle cellStyle = new CellStyle(); |
| | | cellStyle.setVertAlign(XWPFTableCell.XWPFVertAlign.CENTER); |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText("试验要求"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //第三列 |
| | | textRenderData.setText("实验结果"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | } else if (j == 1) { |
| | | //第二列 |
| | | textRenderData.setText(products.get(i - 1).getTell()); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | | cellRenderData.setParagraphs(paragraphRenderDataList); |
| | | cells.add(cellRenderData); |
| | | } else { |
| | | //第三列 |
| | | //获取检验项目和结论 |
| | | InsProduct insProduct = products.get(i - 1); |
| | | String shiyanjieguo = "无异常"; |
| | | if (ObjectUtils.isNotNull(insProduct.getInsResult())) { |
| | | shiyanjieguo = insProduct.getInsResult() == 0 ? "不合格" : "无异常"; |
| | | } |
| | | textRenderData.setText("经过" + insProduct.getInspectionItemSubclass() + "之后,样品" + shiyanjieguo + "。"); |
| | | renderData.add(textRenderData); |
| | | paragraphRenderData.setContents(renderData); |
| | | paragraphRenderDataList.add(paragraphRenderData); |
| | |
| | | insOrder.setPhone("/"); |
| | | } |
| | | //检验项目的环境 |
| | | InsProduct insProduct = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery() |
| | | .eq(InsProduct::getState, 1) |
| | | .eq(InsProduct::getInsSampleId, insReportDto1.getSampleId())).get(0); |
| | | InsProduct insProduct = insProducts.get(0); |
| | | String environment = ""; |
| | | environment = (ObjectUtils.isNotEmpty(insProduct.getTemperature()) ? insProduct.getTemperature() + "℃ " : "") + (ObjectUtils.isNotEmpty(insProduct.getHumidity()) ? insProduct.getHumidity() + "%" : ""); |
| | | String finalEnvironment = environment; |
| | |
| | | put("twoCode", Pictures.ofLocal(codePath).create()); |
| | | put("models", finalModelStr.replace(",", "")); |
| | | put("productSize", productSize); |
| | | put("productSize1", productSize1); |
| | | put("productSize2", productSize2); |
| | | put("productSize3", productSize3); |
| | | put("createTime", now.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))); |