From 3fdea1ab6ab545de0a25573318ecd838de3be576 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 17 九月 2026 15:54:13 +0800
Subject: [PATCH] feat: 1.检验任务查询优化 2.模板时间和地点保存

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java |  160 ++++++++++++++++++++++++++--------------------------
 1 files changed, 80 insertions(+), 80 deletions(-)

diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
index 568a0ec..614153a 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
@@ -1,6 +1,5 @@
 package com.ruoyi.inspect.service.impl;
 
-import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.excel.EasyExcel;
@@ -11,7 +10,6 @@
 import com.aspose.words.SaveFormat;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@@ -19,21 +17,25 @@
 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.data.Pictures;
 import com.itextpdf.text.BadElementException;
 import com.itextpdf.text.DocumentException;
 import com.itextpdf.text.pdf.PdfContentByte;
 import com.itextpdf.text.pdf.PdfReader;
 import com.itextpdf.text.pdf.PdfStamper;
-import com.ruoyi.basic.dto.IfsInventoryQuantitySupplierDto;
 import com.ruoyi.basic.mapper.IfsInventoryQuantityMapper;
 import com.ruoyi.basic.pojo.IfsInventoryQuantity;
+import com.ruoyi.basic.vo.IfsInventoryQuantityVO;
+import com.ruoyi.common.config.WechatProperty;
 import com.ruoyi.common.constant.InsOrderTypeConstants;
 import com.ruoyi.common.constant.MenuJumpPathConstants;
 import com.ruoyi.common.core.domain.Result;
 import com.ruoyi.common.core.domain.entity.InformationNotification;
-import com.ruoyi.common.config.WechatProperty;
-import com.ruoyi.common.utils.*;
+import com.ruoyi.common.utils.DateImageUtil;
+import com.ruoyi.common.utils.QueryWrappers;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.WxCpUtils;
 import com.ruoyi.common.utils.api.IfsApiUtils;
 import com.ruoyi.framework.exception.ErrorException;
 import com.ruoyi.inspect.dto.InsReportExport;
@@ -42,15 +44,18 @@
 import com.ruoyi.inspect.pojo.*;
 import com.ruoyi.inspect.service.InsOrderService;
 import com.ruoyi.inspect.service.InsReportService;
-import com.ruoyi.inspect.mapper.InsUnqualifiedHandlerMapper;
+import com.ruoyi.inspect.service.RawMaterialOrderService;
+import com.ruoyi.inspect.util.PreserveReportPicturePlaceholderHandler;
 import com.ruoyi.system.mapper.UserMapper;
 import com.ruoyi.system.service.InformationNotificationService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.xwpf.usermodel.*;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -116,6 +121,8 @@
     private IfsApiUtils ifsApiUtils;
     @Resource
     private InsSampleUserMapper insSampleUserMapper;
+    @Autowired
+    private RawMaterialOrderService rawMaterialOrderService;
 
 
     @Override
@@ -518,7 +525,10 @@
 
     @Override
     public int wordInsertUrl(Map<String, Object> map, String url) {
-        XWPFTemplate template = XWPFTemplate.compile(url).render(map);
+        Configure configure = Configure.builder()
+                .setValidErrorHandler(new PreserveReportPicturePlaceholderHandler())
+                .build();
+        XWPFTemplate template = XWPFTemplate.compile(url, configure).render(map);
         try {
             template.writeAndClose(Files.newOutputStream(Paths.get(url)));
         } catch (IOException e) {
@@ -564,6 +574,47 @@
             e.printStackTrace();
         }
         return "/word/zip/output.zip";
+    }
+
+    @Override
+    public void download(Integer id, Integer createOrderUser, HttpServletResponse response) {
+        if (id == null) {
+            throw new ErrorException("鎶ュ憡涓嶈兘涓虹┖");
+        }
+        InsReport report = insReportMapper.selectDownloadableReport(id, createOrderUser);
+        if (report == null) {
+            throw new ErrorException("鎶ュ憡涓嶅瓨鍦ㄣ�佸皻鏈敓鎴愭垨鏃犳潈涓嬭浇");
+        }
+        String reportUrl = StringUtils.isNotBlank(report.getUrlS()) ? report.getUrlS() : report.getUrl();
+        if (StringUtils.isBlank(reportUrl) || !reportUrl.replace('\\', '/').startsWith("/word/")) {
+            throw new ErrorException("鎶ュ憡鏂囦欢涓嶅瓨鍦紝璇疯仈绯荤鐞嗗憳");
+        }
+        Path root = Paths.get(wordUrl).toAbsolutePath().normalize();
+        Path file = root.resolve(reportUrl.replace('\\', '/').substring("/word/".length())).normalize();
+        if (!file.startsWith(root) || !Files.isRegularFile(file)) {
+            throw new ErrorException("鎶ュ憡鏂囦欢涓嶅瓨鍦紝璇疯仈绯荤鐞嗗憳");
+        }
+        try {
+            String filename = file.getFileName().toString();
+            String encodedName = URLEncoder.encode(filename, "UTF-8").replace("+", "%20");
+            response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+            response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedName);
+            response.setHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
+            response.setHeader("download-filename", encodedName);
+            response.setContentLengthLong(Files.size(file));
+            try (InputStream inputStream = Files.newInputStream(file);
+                 OutputStream outputStream = response.getOutputStream()) {
+                byte[] buffer = new byte[8192];
+                int length;
+                while ((length = inputStream.read(buffer)) != -1) {
+                    outputStream.write(buffer, 0, length);
+                }
+                outputStream.flush();
+            }
+        } catch (IOException e) {
+            log.error("涓嬭浇鎶ュ憡澶辫触锛宺eportId={}", id, e);
+            throw new ErrorException("鎶ュ憡涓嬭浇澶辫触");
+        }
     }
 
     //鎵归噺涓婁紶
@@ -793,8 +844,9 @@
         stamp.close();
     }
 
-    @Transactional(rollbackFor = Exception.class)
-    public void isRawMaterial(InsOrder insOrder) {
+    @Override
+    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
+    public void isRawMaterial(InsOrder insOrder,Boolean registerInsResults,Boolean hasExemption) {
         IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>()
                 .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId()));
         if (Objects.isNull(one)) {
@@ -808,9 +860,26 @@
         // 鍒ゆ柇鏄惁鏈変笉鍚堟牸
         Long unqualifiedCount = getUnqualifiedCount(insOrder);
 
-        if (count.equals(0L) && unqualifiedCount.equals(0L) && one.getIsFinish().equals(0) && one.getIsSource().equals(1)) {
+        if (count.equals(0L) && unqualifiedCount.equals(0L) && one.getIsFinish().equals(0)
+                && one.getIsSource().equals(1) && Boolean.TRUE.equals(registerInsResults)) {
             // 鍘熸潗鏂欑Щ搴�
-            toLocation = this.moveRawMaterial(one);
+            //濡傛灉鏄媶鍒嗙殑璁㈠崟锛屽垯鎶婃媶鍒嗙殑鎵�鏈夋壒娆¢兘绉诲簱
+            if(one.getIsSplitOrder()==1 && !hasExemption){
+                //鏌ヨ鎷嗗垎璁㈠崟璇︽儏
+                List<IfsInventoryQuantityVO> ifsInventoryQuantityVOS = ifsInventoryQuantityMapper.selectSplitOrderList(one.getPartNo(), one.getLineNo(), one.getReleaseNo(), one.getReceiptNo(), one.getOrderNo());
+                for (IfsInventoryQuantityVO vo : ifsInventoryQuantityVOS) {
+                    //濡傛灉鏈夊鎵樺崟淇℃伅涓斿悎鏍硷紝璧扮櫥璁板悗绉诲簱锛涘鏋滄病鏈夛紝鍒欒蛋鍏嶆锛涗笉鍚堟牸涓嶅仛澶勭悊
+                    if(Objects.isNull(vo.getInsOrderId())){
+                        rawMaterialOrderService.rawOrderRelease(vo.getId(), vo.getPartDesc());
+                    }else if(Objects.equals(vo.getInsOrderId(),insOrder.getId())){
+                        toLocation = insOrderService.moveRawMaterial(vo);
+                    }else if(Objects.nonNull(vo.getInsResult()) && 1 == vo.getInsResult()){
+                        toLocation = insOrderService.moveRawMaterial(vo);
+                    }
+                }
+            }else{
+                toLocation = insOrderService.moveRawMaterial(one);
+            }
         }
 
         // 鍒ゆ柇缁撴潫鐘舵�佷慨鏀瑰悎鏍肩姸鎬�
@@ -895,75 +964,6 @@
             }
         }
         return unqualifiedCount;
-    }
-
-    /**
-     * ifs绉诲簱鎿嶄綔
-     * @param one
-     * @return
-     */
-    @Override
-    public String moveRawMaterial(IfsInventoryQuantity one) {
-        String toLocation;
-        // 鐧昏閲囪喘妫�楠岀粨鏋淪TD
-        if (one.getIsRegister().equals(0)) {
-            Map<String, Object> resultMap = new HashMap<>();
-            List<Map<String, Object>> resultList = new ArrayList<>();
-            Map<String, Object> map = new HashMap<>();
-            map.put("ORDER_NO", one.getOrderNo()); // 閲囪喘璁㈠崟鍙�
-            map.put("LINE_NO", one.getLineNo()); // 琛屽彿
-            map.put("RELEASE_NO", one.getReleaseNo()); // 涓嬭揪鍙�
-            map.put("RECEIPT_NO", one.getReceiptNo()); // 鎺ユ敹鍙�
-            map.put("PURCH_QTY", one.getQtyToInspect()); // 瑕佹楠岀殑閲囪喘鏁伴噺
-            resultList.add(map);
-            resultMap.put("RECORD_ID", UUID.randomUUID().toString());
-            resultMap.put("SYSCODE", "LIMS");
-            resultMap.put("SYSMODEL", "鐧昏閲囪喘妫�楠岀粨鏋�");
-            resultMap.put("BATCH_INFO", resultList);
-            Result result = ifsApiUtils.getProcurementResults(JSONUtil.toJsonStr(resultMap));
-            if (result.getCode() != 200) {
-                throw new ErrorException("IFS鐧昏閲囪喘妫�楠岀粨鏋滃け璐�: " + result.getMessage());
-            }
-        }
-        insOrderService.updateIfsInventoryQuantity(one.getId());
-        /**
-         * TODO 鍚庣画闇�瑕佽皟鐢↖FS鐨勬帴鍙� 绉诲叆鐨勫簱浣嶅彿 toLocation
-         */
-        // 妫�楠屽悗绉诲簱
-        toLocation = "1301";
-        Map<String, Object> moveResultMap = new HashMap<>();
-        List<Map<String, Object>> moveResultList = new ArrayList<>();
-        Map<String, Object> moveMap = new HashMap<>();
-        moveMap.put("ORDER_NO", one.getOrderNo()); // 閲囪喘璁㈠崟鍙�
-        moveMap.put("LINE_NO", one.getLineNo());
-        moveMap.put("RELEASE_NO", one.getReleaseNo());
-        moveMap.put("RECEIPT_NO", one.getReceiptNo());
-        moveMap.put("PART_NO", one.getPartNo());
-        moveMap.put("QTY", one.getQtyArrived());
-        moveMap.put("LOCATION_NO", one.getLocationNo());
-        moveMap.put("TO_LOCATION_NO", toLocation);
-        moveMap.put("LOT_BATCH_NO", one.getLotBatchNo());
-        moveMap.put("SERIAL_NO", one.getSerialNo());
-        moveMap.put("WAIV_DEV_REJ_NO", one.getWaivDevRejNo());
-        moveMap.put("ENG_CHG_LEVEL", one.getEngChgLevel());
-        moveMap.put("ACTIVITY_SEQ", one.getActivitySeq());
-        moveResultList.add(moveMap);
-        moveResultMap.put("RECORD_ID", UUID.randomUUID().toString());
-        moveResultMap.put("SYSCODE", "LIMS");
-        moveResultMap.put("SYSMODEL", "妫�楠屽悗绉诲簱");
-        moveResultMap.put("BATCH_INFO", moveResultList);
-
-        Result result1 = ifsApiUtils.moveReceipt(JSONUtil.toJsonStr(moveResultMap));
-        // 濡傛灉鏈夊繀椤讳负闆朵欢鎸囧畾鎵瑰彿鎶ラ敊闇�瑕侀噸鏂版彁浜ょЩ搴撲俊鎭幓鎸囧畾鎵瑰彿
-        if (result1.getCode() != 200) {
-            String message = result1.getMessage();
-            if (message.contains("蹇呴』涓洪浂浠�") && message.contains("鎸囧畾鎵瑰彿")) {
-                updaeBatch(one, toLocation);
-            } else {
-                throw new ErrorException("IFS妫�楠屽悗绉诲簱澶辫触: " + result1.getMessage());
-            }
-        }
-        return toLocation;
     }
 
     /**

--
Gitblit v1.9.3