From 217f2eb09985a80f5d972a6fa1205806756711e1 Mon Sep 17 00:00:00 2001
From: 李林 <z1292839451@163.com>
Date: 星期二, 09 四月 2024 18:05:20 +0800
Subject: [PATCH] 报告生成
---
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java | 129 +++++++++++++++++++++++++++---------------
1 files changed, 83 insertions(+), 46 deletions(-)
diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
index eea8eed..b04240e 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -13,6 +13,10 @@
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;
@@ -36,6 +40,8 @@
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.*;
@@ -121,50 +127,7 @@
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;
@@ -263,7 +226,35 @@
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);
@@ -283,7 +274,7 @@
}});
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) {
@@ -293,6 +284,52 @@
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));
--
Gitblit v1.9.3