| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * 检验任务-业务实现层 |
| | |
| | | Set<Integer> set = new HashSet<>(); |
| | | Map<Integer, String> map2 = new HashMap<>(); |
| | | List<Map<String, Object>> tables = new ArrayList<>(); |
| | | Set<String> standardMethod = new HashSet<>(); |
| | | Set<String> deviceSet = new HashSet<>(); |
| | | samples.forEach(a -> { |
| | | Set<String> templateSet = new HashSet<>(); |
| | | getTemplateThing(set, map2, a); |
| | | AtomicInteger index = new AtomicInteger(); |
| | | a.getInsProduct().forEach(b -> { |
| | | a.getInsProduct().forEach(b->{ |
| | | String[] split = b.getMethod().replaceAll("]", "").replaceAll("\\[","").replaceAll("\"","").split(","); |
| | | standardMethod.addAll(Arrays.asList(split)); |
| | | if(b.getInsProductResult()!=null){ |
| | | if(b.getInsProductResult().getEquipValue()!=null&& !Objects.equals(b.getInsProductResult().getEquipValue(), "")){ |
| | | deviceSet.add(b.getInsProductResult().getEquipValue()); |
| | | } |
| | | } |
| | | if (b.getTemplate().size() == 0) { |
| | | return; |
| | | } |
| | | templateSet.add(JSON.toJSONString(b.getTemplate())); |
| | | }); |
| | | AtomicInteger index = new AtomicInteger(); |
| | | templateSet.forEach(tem->{ |
| | | Set<Integer> set2 = new HashSet<>(); |
| | | List<RowRenderData> rows = new ArrayList<>(); |
| | | List<TextRenderData> text = new ArrayList<>(); |
| | | RowRenderData rowRenderData; |
| | | Set<String> delSet = new HashSet<>(); |
| | | String pr = null; |
| | | for (JSONObject jo1 : b.getTemplate()) { |
| | | List<JSONObject> temp = JSON.parseArray(tem, JSONObject.class); |
| | | Map<String, InsProduct> pMap = new HashMap<>(); |
| | | Set<String> delRSet = new HashSet<>(); |
| | | for (JSONObject jo1 : temp) { |
| | | JSONObject v = JSON.parseObject(JSON.toJSONString(jo1.get("v"))); |
| | | if (v.get("ps") != null) { |
| | | if ("检验值".equals(JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value") + "") || "设备".equals(JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value") + "")) { |
| | | delSet.add(jo1.get("c") + ""); |
| | | } |
| | | if ("检验子项".equals(JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value") + "")) { |
| | | if (v.get("v").equals(b.getInspectionItemSubclass())) { |
| | | pr = jo1.get("r") + ""; |
| | | int count2 = 0; |
| | | for (InsProduct p : a.getInsProduct()) { |
| | | if(v.get("v").equals(p.getInspectionItemSubclass())){ |
| | | pMap.put(jo1.get("r")+"", p); |
| | | break; |
| | | }else{ |
| | | count2++; |
| | | } |
| | | } |
| | | if(count2 == a.getInsProduct().size()){ |
| | | delRSet.add(jo1.get("r")+""); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | for (int i = 0; i < b.getTemplate().size(); i++) { |
| | | JSONObject jo1 = b.getTemplate().get(i); |
| | | for (int i = 0; i < temp.size(); i++) { |
| | | JSONObject jo1 = temp.get(i); |
| | | if (delRSet.stream().anyMatch(e -> e.equals(jo1.get("r") + ""))) { |
| | | continue; |
| | | } |
| | | if (delSet.stream().anyMatch(e -> e.equals(jo1.get("c") + ""))) { |
| | | continue; |
| | | } |
| | |
| | | } |
| | | } |
| | | JSONObject v = JSON.parseObject(JSON.toJSONString(jo1.get("v"))); |
| | | if (pr.equals(jo1.get("r") + "") && v.get("ps") != null) { |
| | | if (JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value").equals("要求值")) { |
| | | textRenderData.setText(b.getAsk()); |
| | | } else if (JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value").equals("单位")) { |
| | | textRenderData.setText(b.getUnit()); |
| | | } else if (JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value").equals("结论")) { |
| | | switch (b.getInsResult()) { |
| | | InsProduct p = pMap.get(jo1.get("r") + ""); |
| | | if (p!=null && v.get("ps") != null) { |
| | | String value = JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value") + ""; |
| | | if (value.equals("要求值")) { |
| | | textRenderData.setText(p.getAsk()); |
| | | } else if (value.equals("单位")) { |
| | | textRenderData.setText(p.getUnit()); |
| | | } else if (value.equals("结论")) { |
| | | switch (p.getInsResult()) { |
| | | case 1: |
| | | textRenderData.setText("√"); |
| | | break; |
| | |
| | | textRenderData.setText("-"); |
| | | break; |
| | | } |
| | | } else if (JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value").equals("序号")) { |
| | | } else if (value.equals("序号")) { |
| | | index.getAndIncrement(); |
| | | textRenderData.setText(index + ""); |
| | | } else if (JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value").equals("计算值")) { |
| | | JSONArray jsonArray = JSON.parseArray(b.getInsProductResult().getComValue()); |
| | | textRenderData.setText((JSON.parseObject(JSON.toJSONString(jsonArray.get(0))).get("v") + "").equals("") ? "-" : JSON.parseObject(JSON.toJSONString(jsonArray.get(0))).get("v") + ""); |
| | | } else if (JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value").equals("最终值")) { |
| | | textRenderData.setText(b.getLastValue()); |
| | | } else if (value.equals("计算值")) { |
| | | JSONArray jsonArray = JSON.parseArray(p.getInsProductResult().getComValue()); |
| | | textRenderData.setText((JSON.parseObject(JSON.toJSONString(jsonArray.get(0))).get("v") + "").equals("") ? "/" : JSON.parseObject(JSON.toJSONString(jsonArray.get(0))).get("v") + ""); |
| | | } else if (value.equals("最终值")) { |
| | | textRenderData.setText(p.getLastValue()); |
| | | } else if (value.equals("样品编号")) { |
| | | textRenderData.setText(a.getSampleCode()); |
| | | } else if (value.equals("样品型号")) { |
| | | textRenderData.setText(a.getModel()); |
| | | } else if (value.equals("样品名称")) { |
| | | textRenderData.setText(a.getSample()); |
| | | } else { |
| | | textRenderData.setText(v.get("v") == null ? "" : v.get("v") + ""); |
| | | } |
| | | } else if ((!pr.equals(jo1.get("r") + "")) && v.get("ps") != null) { |
| | | if (JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value").equals("最终值")) { |
| | | textRenderData.setText(b.getLastValue()); |
| | | } else if (JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value").equals("结论")) { |
| | | switch (b.getInsResult()) { |
| | | } else if (p==null && v.get("ps") != null) { |
| | | String value = JSON.parseObject(JSON.toJSONString(v.get("ps"))).get("value") + ""; |
| | | p = pMap.get(pMap.keySet().iterator().next()); |
| | | if (value.equals("最终值")) { |
| | | textRenderData.setText(p.getLastValue()); |
| | | } else if (value.equals("结论")) { |
| | | switch (p.getInsResult()) { |
| | | case 1: |
| | | textRenderData.setText("✔"); |
| | | break; |
| | |
| | | textRenderData.setText("-"); |
| | | break; |
| | | } |
| | | } else if (value.equals("样品编号")) { |
| | | textRenderData.setText(a.getSampleCode()); |
| | | } else if (value.equals("样品型号")) { |
| | | textRenderData.setText(a.getModel()); |
| | | } else if (value.equals("样品名称")) { |
| | | textRenderData.setText(a.getSample()); |
| | | } else { |
| | | textRenderData.setText(v.get("v") == null ? "" : v.get("v") + ""); |
| | | } |
| | |
| | | style.setColor(v.get("fc") == null ? "000000" : (v.get("fc") + "").replace("#", "")); |
| | | textRenderData.setStyle(style); |
| | | text.add(textRenderData); |
| | | if (i == b.getTemplate().size() - 1) { |
| | | if (i == temp.size() - 1) { |
| | | TextRenderData[] text2 = text.toArray(new TextRenderData[0]); |
| | | rowRenderData = Rows.of(text2).rowAtleastHeight(1).center().create(); |
| | | rows.add(rowRenderData); |
| | |
| | | TableRenderData tableRenderData = new TableRenderData(); |
| | | tableRenderData.setRows(rows); |
| | | TableStyle tableStyle = new TableStyle(); |
| | | JSONObject styleJo = JSON.parseObject(JSON.toJSONString(b.getStyle().get("columnlen"))); |
| | | /*JSONObject styleJo = JSON.parseObject(JSON.toJSONString(b.getStyle().get("columnlen"))); |
| | | List<Integer> colLen = new ArrayList<>(); |
| | | int colSize = rows.get(0).getCells().size(); |
| | | int colOne = Integer.parseInt(b.getTemplate().get(0).get("r") + ""); |
| | |
| | | int i1 = Integer.parseInt(styleJo.get(i + "") + ""); |
| | | colLen.add(pxToCm(i1)); |
| | | } |
| | | } |
| | | }*/ |
| | | // tableStyle.setColWidths(ArrayUtils.toPrimitive(colLen.toArray(new Integer[0]))); |
| | | tableStyle.setAlign(TableRowAlign.CENTER); |
| | | tableStyle.setWidth(XWPFTable.DEFAULT_PERCENTAGE_WIDTH); |
| | |
| | | }); |
| | | String url; |
| | | try { |
| | | url = ResourceUtils.getURL("classpath:static/template-table.docx").getPath(); |
| | | url = ResourceUtils.getURL("classpath:static/report-template.docx").getPath(); |
| | | } catch (FileNotFoundException e) { |
| | | throw new ErrorException("找不到模板文件"); |
| | | } |
| | | StringBuilder standardMethod2 = new StringBuilder(); |
| | | for (String s : standardMethod) { |
| | | standardMethod2.append("、").append(s); |
| | | } |
| | | standardMethod2.replace(0, 1,""); |
| | | tables.forEach(table->{ |
| | | table.put("tableSize", tables.size() + 1); |
| | | }); |
| | | List<Map<String, String>> deviceList = insOrderMapper.selectDeviceList(deviceSet); |
| | | ConfigureBuilder builder = Configure.builder(); |
| | | builder.useSpringEL(true); |
| | | XWPFTemplate template = XWPFTemplate.compile(url, builder.build()).render( |
| | |
| | | put("order", insOrder); |
| | | put("report", insReport); |
| | | put("user", user); |
| | | put("samples", samples); |
| | | // put("samples", samples); |
| | | put("sampleSize", samples.size() + samples.get(0).getUnit()); |
| | | put("tables", tables); |
| | | put("tableSize", tables.size() + 1); |
| | | put("standardMethod", standardMethod2); |
| | | put("deviceList", deviceList); |
| | | }}); |
| | | try { |
| | | String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd_HH_mm_ss")) + ".docx"; |