From 3bd27d6f6892e60658ca39763d9200743932ee36 Mon Sep 17 00:00:00 2001
From: value <z1292839451@163.com>
Date: 星期三, 03 四月 2024 17:03:53 +0800
Subject: [PATCH] 检验报告

---
 inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java |   69 +++++++++++++++++++++++++---------
 1 files changed, 51 insertions(+), 18 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 4f74f80..b370cb7 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
@@ -11,24 +11,33 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.config.Configure;
+import com.deepoove.poi.config.ConfigureBuilder;
 import com.yuanchu.mom.common.GetLook;
 import com.yuanchu.mom.common.PrintChina;
 import com.yuanchu.mom.dto.InsOrderPlanDTO;
 import com.yuanchu.mom.dto.SampleProductDto;
+import com.yuanchu.mom.exception.ErrorException;
 import com.yuanchu.mom.mapper.*;
 import com.yuanchu.mom.pojo.*;
 import com.yuanchu.mom.service.InsOrderPlanService;
 import com.yuanchu.mom.service.InsOrderService;
 import com.yuanchu.mom.service.StandardTemplateService;
+import com.yuanchu.mom.utils.GiveCode;
 import com.yuanchu.mom.utils.QueryWrappers;
 import com.yuanchu.mom.vo.InsOrderPlanVO;
 import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ResourceUtils;
 
+import javax.annotation.Resource;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -36,24 +45,34 @@
  * 妫�楠屼换鍔�-涓氬姟瀹炵幇灞�
  */
 @Service
-@AllArgsConstructor
+//@AllArgsConstructor
 public class InsOrderPlanServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderPlanService {
 
+    @Resource
     private InsSampleMapper insSampleMapper;
-
+    @Resource
     private InsSampleUserMapper insSampleUserMapper;
-
+    @Resource
     private GetLook getLook;
-
+    @Resource
     private InsOrderMapper insOrderMapper;
-
+    @Resource
     private InsOrderService insOrderService;
-
+    @Resource
     private StandardTemplateService standardTemplateService;
-
+    @Resource
     private InsOrderStateMapper insOrderStateMapper;
-
+    @Resource
     private InsProductMapper insProductMapper;
+
+    @Value("${wordUrl}")
+    private String wordUrl;
+
+    @Resource
+    private GiveCode giveCode;
+
+    @Resource
+    private InsReportMapper insReportMapper;
 
     @Override
     public Map<String, Object> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) {
@@ -162,22 +181,36 @@
         insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate().eq(InsOrderState::getInsOrderId, orderId).eq(InsOrderState::getLaboratory, laboratory).set(InsOrderState::getInsTime, LocalDateTime.now()).set(InsOrderState::getInsState, num).set(InsOrderState::getVerifyTell, tell).set(InsOrderState::getVerifyUser, getLook.selectPowerByMethodAndUserId(null).get("userId")));
         List<InsOrderState> insOrderStates = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, orderId));
         long count = insOrderStates.stream().filter(a -> a.getInsState() == 5).count();
-        if (count == insOrderStates.size()) {
-            XWPFTemplate template = XWPFTemplate.compile("template.docx").render(
+        if (count == insOrderStates.size() && num == 5) {
+            InsOrder insOrder = insOrderMapper.selectById(orderId);
+            Map<String, String> user = insProductMapper.selectUserById(insOrder.getUserId());
+            List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId);
+            samples.forEach(System.out::println);
+            InsReport insReport = new InsReport();
+            insReport.setCode(giveCode.giveCode("JCZX/TX-", "ins_report", "-", "yyMMdd"));
+            insReport.setInsOrderId(orderId);
+            String url;
+            try {
+                url = ResourceUtils.getURL("classpath:static/report-template.docx").getPath();
+            } catch (FileNotFoundException e) {
+                throw new ErrorException("鎵句笉鍒版ā鏉挎枃浠�");
+            }
+            XWPFTemplate template = XWPFTemplate.compile(url).render(
                     new HashMap<String, Object>() {{
-                        put("title", "Hi, poi-tl Word妯℃澘寮曟搸");
+                        put("order", insOrder);
+                        put("report", insReport);
+                        put("user", user);
+                        put("samples", samples);
+                        put("sampleSize", samples.size() + samples.get(0).getUnit());
                     }});
             try {
-                template.writeAndClose(new FileOutputStream("output.docx"));
+                String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd_HH_mm_ss")) + ".docx";
+                template.writeAndClose(new FileOutputStream(wordUrl + "/" + name));
+                insReport.setUrl("/word/"+ name);
+                insReportMapper.insert(insReport);
             } catch (IOException e) {
                 throw new RuntimeException(e);
             }
-            List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId));
-            insSamples.forEach(a -> {
-                System.out.println(a);
-                List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getInsSampleId, a.getId()));
-                insProducts.forEach(System.out::println);
-            });
         }
         return 1;
     }

--
Gitblit v1.9.3