From e1284aa3b1b400ecebb59126d7110a3bb4a6b000 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期五, 31 十月 2025 15:46:09 +0800
Subject: [PATCH] 原材料报检拆分功能V1

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java |  189 ++++++++++++++++++++++++----------------------
 1 files changed, 99 insertions(+), 90 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 742af90..6d549f7 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
@@ -2,6 +2,10 @@
 
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.write.metadata.WriteSheet;
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
 import com.aspose.words.License;
 import com.aspose.words.SaveFormat;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -21,32 +25,44 @@
 import com.itextpdf.text.pdf.PdfStamper;
 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.core.domain.entity.User;
-import com.ruoyi.common.properties.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;
 import com.ruoyi.inspect.dto.ReportPageDto;
 import com.ruoyi.inspect.mapper.*;
 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.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;
 
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletResponse;
 import java.awt.image.BufferedImage;
 import java.io.*;
+import java.net.URLEncoder;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -65,6 +81,7 @@
  * @createDate 2024-03-17 22:10:02
  */
 @Service
+@Slf4j
 public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport>
         implements InsReportService {
     @Resource
@@ -81,8 +98,7 @@
     private String wordUrl;
     @Value("${file.path}")
     private String imgUrl;
-    @Value("${file.licenseUrl}")
-    private String licenseUrl;
+
     @Resource
     private InsOrderMapper insOrderMapper;
     @Resource
@@ -103,6 +119,8 @@
     private IfsApiUtils ifsApiUtils;
     @Resource
     private InsSampleUserMapper insSampleUserMapper;
+    @Autowired
+    private RawMaterialOrderService rawMaterialOrderService;
 
 
     @Override
@@ -111,9 +129,11 @@
         // todo: 浠呯湅鑷繁
         //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id
         String laboratory = null;
-        Integer createOrderUser = null;
+
+        Integer createOrderUser = reportPageDto.getCreateOrderUser();
         String queryStatus = reportPageDto.getQueryStatus();
         reportPageDto.setQueryStatus(null);
+        reportPageDto.setCreateOrderUser(null);
 
         map.put("body", insReportMapper.pageInsReport(page,
                 QueryWrappers.queryWrappers(reportPageDto),
@@ -185,7 +205,7 @@
         info.setSenderId(submitUserId);    //鍙戦�佷汉
         info.setConsigneeId(userId);     //鏀朵欢浜�
         info.setViewStatus(false);
-        info.setJumpPath("b1-report-preparation");
+        info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION);
         informationNotificationService.addInformationNotification(info);
         //绯荤粺鐢熸垚鎶ュ憡鍦板潃
         String url = insReport.getUrl();
@@ -306,7 +326,7 @@
         info.setSenderId(checkUserId);    //鍙戦�佷汉
         info.setConsigneeId(userId);     //鏀朵欢浜�
         info.setViewStatus(false);
-        info.setJumpPath("b1-report-preparation");
+        info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION);
         informationNotificationService.addInformationNotification(info);
         //绯荤粺鐢熸垚鎶ュ憡鍦板潃
         String url = insReport.getUrl();
@@ -535,12 +555,16 @@
             }
             // 鍘嬬缉涓存椂鏂囦欢澶�
             zipFilePath = wordUrl + "/zip/output.zip";
+            // 鍒ゆ柇zip璺緞鏄惁瀛樺湪
+            File zipDir = new File(wordUrl + "/zip");
+            if(!zipDir.isDirectory()){
+                zipDir.mkdirs();
+            }
             zipDirectory(tempFolderPath, zipFilePath);
 
             // 娓呯悊涓存椂鏂囦欢澶�
             deleteDirectory(tempFolder);
 
-            System.out.println("ZIP鏂囦欢鍒涘缓瀹屾垚锛�");
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -675,13 +699,11 @@
         FileOutputStream os = null;
         try {
             //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃
-//            InputStream is = this.getClass().getResourceAsStream("/lib/license.xml");
-//            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("license.xml");
-            InputStream is = Files.newInputStream(new File(licenseUrl).toPath());
+            InputStream is = new ClassPathResource("/lib/license.xml").getInputStream();
             License license = new License();
             license.setLicense(is);
             if (!license.getIsLicensed()) {
-                System.out.println("License楠岃瘉涓嶉�氳繃...");
+                log.info("License楠岃瘉涓嶉�氳繃...");
                 return null;
             }
             //鐢熸垚涓�涓┖鐨凱DF鏂囦欢
@@ -776,8 +798,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)) {
@@ -791,9 +814,25 @@
         // 鍒ゆ柇鏄惁鏈変笉鍚堟牸
         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) && 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);
+            }
         }
 
         // 鍒ゆ柇缁撴潫鐘舵�佷慨鏀瑰悎鏍肩姸鎬�
@@ -881,75 +920,6 @@
     }
 
     /**
-     * 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;
-    }
-
-    /**
      * 閫�鍥炲埌妫�楠屼换鍔�
      * @param id
      * @return
@@ -979,6 +949,46 @@
                 .set(InsReport::getIsPass, 0));
 
         return false;
+    }
+
+    /**
+     * 鎶ュ憡鎶ヨ〃瀵煎嚭
+     * @param dto
+     * @param response
+     */
+    @Override
+    public void reportAllExport(ReportPageDto dto, HttpServletResponse response) throws UnsupportedEncodingException {
+
+        Integer createOrderUser = dto.getCreateOrderUser();
+        String queryStatus = dto.getQueryStatus();
+        dto.setQueryStatus(null);
+        dto.setCreateOrderUser(null);
+
+        List<InsReportExport> insReportExports = insReportMapper.reportAllExport(QueryWrappers.queryWrappers(dto),
+                SecurityUtils.getUserId().intValue(),
+                queryStatus,
+                createOrderUser);
+
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("UTF-8");
+        // 杩欓噷URLEncoder.encode鍙互闃叉涓枃涔辩爜 褰撶劧鍜宔asyexcel娌℃湁鍏崇郴
+        String fileName = URLEncoder.encode("鎶ュ憡鎶ヨ〃瀵煎嚭", "UTF-8");
+        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
+        try {
+            //鏂板缓ExcelWriter
+            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
+            //鑾峰彇sheet0瀵硅薄
+            WriteSheet mainSheet = EasyExcel.writerSheet(0, "鎶ュ憡鎶ヨ〃瀵煎嚭").head(InsReportExport.class).build();
+
+            //鍚憇heet0鍐欏叆鏁版嵁 浼犲叆绌簂ist杩欐牱鍙鍑鸿〃澶�
+            excelWriter.write(insReportExports, mainSheet);
+            //鍏抽棴娴�
+            excelWriter.finish();
+        } catch (IOException e) {
+            throw new RuntimeException("瀵煎嚭澶辫触");
+        }
+
+
     }
 
 
@@ -1116,11 +1126,11 @@
         FileOutputStream os = null;
         try {
             //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃
-            InputStream is = Files.newInputStream(new File(licenseUrl).toPath());
+            InputStream is = new ClassPathResource("/lib/license.xml").getInputStream();
             License license = new License();
             license.setLicense(is);
             if (!license.getIsLicensed()) {
-                System.out.println("License楠岃瘉涓嶉�氳繃...");
+                log.info("License楠岃瘉涓嶉�氳繃...");
                 return null;
             }
             //鐢熸垚涓�涓┖鐨凱DF鏂囦欢
@@ -1131,7 +1141,6 @@
             //瑕佽浆鎹㈢殑word鏂囦欢
             com.aspose.words.Document doc = new com.aspose.words.Document(wordPath);
             doc.save(os, SaveFormat.PDF);
-            String name = file.getName();
             return file.getName();
         } catch (Exception e) {
             e.printStackTrace();

--
Gitblit v1.9.3