| | |
| | | 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.TableStyle; |
| | | import com.deepoove.poi.render.Render; |
| | | import com.spire.doc.Table; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.InsOrderPlanDTO; |
| | |
| | | import java.io.FileNotFoundException; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | |
| | | List<SampleProductDto> list = JSON.parseArray(JSON.toJSONString(map.get("sampleProduct")), SampleProductDto.class); |
| | | for (SampleProductDto samples : list) { |
| | | if (BeanUtil.isEmpty(samples.getInsProduct())) continue; |
| | | for (InsProduct product : samples.getInsProduct()) { |
| | | if (product.getTemplateId() == null) { |
| | | product.setTemplate(new ArrayList<>()); |
| | | continue; |
| | | } |
| | | if (set.add(product.getTemplateId())) { |
| | | map2.put(product.getTemplateId(), standardTemplateService.getStandTempThingById(product.getTemplateId()) + ""); |
| | | } |
| | | String thing = map2.get(product.getTemplateId()); |
| | | if (StrUtil.isNotEmpty(thing)) { |
| | | JSONObject sheet = JSON.parseObject(JSON.toJSONString(JSON.parseArray(JSON.toJSONString(JSON.parseObject(thing).get("data"))).get(0))); |
| | | JSONObject config = JSON.parseObject(JSON.toJSONString(sheet.get("config"))); |
| | | List<JSONObject> cellData = JSON.parseArray(JSON.toJSONString(sheet.get("celldata")), JSONObject.class); |
| | | List<JSONObject> tableData = new ArrayList<>(); |
| | | Map<String, Object> style = new HashMap<>(); |
| | | // style.put("borderInfo", config.get("borderInfo")); |
| | | style.put("rowlen", config.get("rowlen")); |
| | | style.put("columnlen", config.get("columnlen")); |
| | | int r = -1; |
| | | if (BeanUtil.isNotEmpty(cellData)) { |
| | | for (JSONObject o : cellData) { |
| | | JSONObject v = JSON.parseObject(JSON.toJSONString(o.get("v"))); |
| | | if (BeanUtil.isNotEmpty(v.get("ps"))) { |
| | | JSONObject ps = JSON.parseObject(JSON.toJSONString(v.get("ps"))); |
| | | if (ps.get("value").equals("检验项") && v.get("v").equals(product.getInspectionItem())) { |
| | | tableData.add(o); |
| | | r = Integer.parseInt(o.get("r") + ""); |
| | | continue; |
| | | } |
| | | } |
| | | if (tableData.size() > 0) { |
| | | if ((Integer.parseInt(o.get("r") + "") == r + 1 || Integer.parseInt(o.get("r") + "") == r) && !(o.get("v") + "").equals("{\"ht\":\"0\"}")) { |
| | | r = Integer.parseInt(o.get("r") + ""); |
| | | tableData.add(o); |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | product.setTemplate(tableData); |
| | | product.setStyle(style); |
| | | } |
| | | } |
| | | getTemplateThing(set, map2, samples); |
| | | } |
| | | map.put("sampleProduct", list); |
| | | return map; |
| | |
| | | InsOrder insOrder = insOrderMapper.selectById(orderId); |
| | | Map<String, String> user = insProductMapper.selectUserById(insOrder.getUserId()); |
| | | List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId); |
| | | samples.forEach(System.out::println); |
| | | Set<Integer> set = new HashSet<>(); |
| | | Map<Integer, String> map2 = new HashMap<>(); |
| | | samples.forEach(a->{ |
| | | getTemplateThing(set, map2, a); |
| | | TableRenderData tableRenderData = new TableRenderData(); |
| | | TableStyle tableStyle = new TableStyle(); |
| | | tableStyle.setWidth("14.63"); |
| | | tableRenderData.setTableStyle(tableStyle); |
| | | a.getInsProduct().forEach(b->{ |
| | | System.out.println(b.getTemplate()); |
| | | System.out.println(b.getStyle()); |
| | | RowRenderData rowRenderData = new RowRenderData(); |
| | | CellRenderData cellRenderData = new CellRenderData(); |
| | | for (JSONObject jo1 : b.getTemplate()) { |
| | | ParagraphRenderData paragraphRenderData = new ParagraphRenderData(); |
| | | List<RenderData> contents = new ArrayList<>(); |
| | | /*if(Integer.parseInt(jo1.get("r")+"") == r){ |
| | | if(Integer.parseInt(jo1.get("r")+"") == c){ |
| | | JSONObject jo2 = JSONObject.parseObject(JSONObject.toJSONString(jo1.get("v"))); |
| | | TextRenderData textRenderData = new TextRenderData(); |
| | | textRenderData.setText(jo2.get("v")+""); |
| | | contents.add(textRenderData); |
| | | paragraphRenderData.setContents(contents); |
| | | } |
| | | }else if (Integer.parseInt(jo1.get("r")+"") > r){ |
| | | }*/ |
| | | } |
| | | }); |
| | | }); |
| | | InsReport insReport = new InsReport(); |
| | | insReport.setCode(giveCode.giveCode("JCZX/TX-", "ins_report", "-", "yyMMdd")); |
| | | insReport.setInsOrderId(orderId); |
| | |
| | | }}); |
| | | try { |
| | | String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd_HH_mm_ss")) + ".docx"; |
| | | template.writeAndClose(new FileOutputStream(wordUrl + "/" + name)); |
| | | template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); |
| | | insReport.setUrl("/word/"+ name); |
| | | insReportMapper.insert(insReport); |
| | | } catch (IOException e) { |
| | |
| | | return 1; |
| | | } |
| | | |
| | | private void getTemplateThing(Set<Integer> set, Map<Integer, String> map2, SampleProductDto a) { |
| | | for (InsProduct product : a.getInsProduct()) { |
| | | if (product.getTemplateId() == null) { |
| | | product.setTemplate(new ArrayList<>()); |
| | | continue; |
| | | } |
| | | if (set.add(product.getTemplateId())) { |
| | | map2.put(product.getTemplateId(), standardTemplateService.getStandTempThingById(product.getTemplateId()) + ""); |
| | | } |
| | | String thing = map2.get(product.getTemplateId()); |
| | | if (StrUtil.isNotEmpty(thing)) { |
| | | JSONObject sheet = JSON.parseObject(JSON.toJSONString(JSON.parseArray(JSON.toJSONString(JSON.parseObject(thing).get("data"))).get(0))); |
| | | JSONObject config = JSON.parseObject(JSON.toJSONString(sheet.get("config"))); |
| | | List<JSONObject> cellData = JSON.parseArray(JSON.toJSONString(sheet.get("celldata")), JSONObject.class); |
| | | List<JSONObject> tableData = new ArrayList<>(); |
| | | Map<String, Object> style = new HashMap<>(); |
| | | style.put("rowlen", config.get("rowlen")); |
| | | style.put("columnlen", config.get("columnlen")); |
| | | int r = -1; |
| | | if (BeanUtil.isNotEmpty(cellData)) { |
| | | for (JSONObject o : cellData) { |
| | | JSONObject v = JSON.parseObject(JSON.toJSONString(o.get("v"))); |
| | | if (BeanUtil.isNotEmpty(v.get("ps"))) { |
| | | JSONObject ps = JSON.parseObject(JSON.toJSONString(v.get("ps"))); |
| | | if (ps.get("value").equals("检验项") && v.get("v").equals(product.getInspectionItem())) { |
| | | tableData.add(o); |
| | | r = Integer.parseInt(o.get("r") + ""); |
| | | continue; |
| | | } |
| | | } |
| | | if (tableData.size() > 0) { |
| | | if ((Integer.parseInt(o.get("r") + "") == r + 1 || Integer.parseInt(o.get("r") + "") == r) && !(o.get("v") + "").equals("{\"ht\":\"0\"}")) { |
| | | r = Integer.parseInt(o.get("r") + ""); |
| | | tableData.add(o); |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | product.setTemplate(tableData); |
| | | product.setStyle(style); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public int submitPlan(Integer orderId, String laboratory) { |
| | | List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId)); |