From 0e5bddf6084d3dfb7bcad7217d4320898416eba3 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期四, 23 十月 2025 16:49:12 +0800
Subject: [PATCH] 拆分原材料和外购成品的业务流程(报检、下单、检验)

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java |  102 ++++++++++++++++++++++++++++----------------------
 1 files changed, 57 insertions(+), 45 deletions(-)

diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
index 976209c..7d550f7 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java
@@ -26,6 +26,7 @@
 import com.ruoyi.common.constant.InsOrderTypeConstants;
 import com.ruoyi.common.core.domain.Result;
 import com.ruoyi.common.core.domain.entity.User;
+import com.ruoyi.common.enums.OrderType;
 import com.ruoyi.common.numgen.NumberGenerator;
 import com.ruoyi.common.utils.*;
 import com.ruoyi.common.utils.api.IfsApiUtils;
@@ -37,12 +38,14 @@
 import com.ruoyi.inspect.service.InsOrderStateService;
 import com.ruoyi.inspect.service.InsProductService;
 import com.ruoyi.inspect.service.InsSampleService;
+import com.ruoyi.inspect.vo.IfsOrderVO;
 import com.ruoyi.inspect.vo.InsOrderPrintingVo;
 import com.ruoyi.system.mapper.UserMapper;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
@@ -309,9 +312,10 @@
                 }
             }
         });
-        //鏄惁涓哄師鏉愭枡涓嬪崟
-        if (insOrder.getTypeSource() != null && insOrder.getTypeSource().equals(1)) {
-            // 鍘熸潗鏂欎笅鍗�: 濮旀墭浜哄氨鏄姤妫�浜�, 鐢熶骇鍗曚綅灏辨槸渚涘簲鍟嗗崟浣�
+
+        //鍘熸潗鏂欎笅鍗曟垨澶栬喘鎴愬搧涓嬪崟
+        if (Objects.nonNull(insOrder.getTypeSource())&&Objects.nonNull(insOrder.getIfsInventoryId())) {
+            // 濮旀墭浜哄氨鏄姤妫�浜�, 鐢熶骇鍗曚綅灏辨槸渚涘簲鍟嗗崟浣�
             IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId());
             Integer declareUserId = ifsInventoryQuantity.getDeclareUserId();
             User user = userMapper.selectById(declareUserId);
@@ -349,47 +353,51 @@
             upInsOrderOfState(insOrder);
 
             // 鍒嗛厤妫�楠屼汉
-            upInsOrder(insOrder.getId(), null, appointed != null ? appointed.toString() : null, SecurityUtils.getUserId().intValue(), "鍘熸潗鏂�");
+            String sonLaboratory = insOrder.getTypeSource().equals(1)?"鍘熸潗鏂�":"鎴愬搧瀹為獙瀹�";
+            upInsOrder(insOrder.getId(), null, appointed != null ? appointed.toString() : null, SecurityUtils.getUserId().intValue(), sonLaboratory);
 
-            // 鏍规嵁闆朵欢鍙峰垽鏂槸鍚︽槸杈呮潗
-            boolean isRaw = false;
-            StructureTestObject productObject = insOrderMapper.selectProductByPartNo(ifsInventoryQuantity.getPartNo());
-            // 鏌ヨ浜у搧
-            if (productObject != null && StrUtil.isNotBlank(productObject.getObjectType()) && productObject.getObjectType().equals("1")) {
-                isRaw = true;
-            } else {
-            // 鏌ヨ瀵硅薄
-                StructureTestObject testObject = insOrderMapper.selectByPartNo(ifsInventoryQuantity.getPartNo());
-                if (testObject != null && StrUtil.isNotBlank(testObject.getObjectType()) && testObject.getObjectType().equals("1")) {
+            //鏄惁涓哄師鏉愭枡涓嬪崟
+            if(insOrder.getTypeSource().equals(1)){
+                // 鏍规嵁闆朵欢鍙峰垽鏂槸鍚︽槸杈呮潗
+                boolean isRaw = false;
+                StructureTestObject productObject = insOrderMapper.selectProductByPartNo(ifsInventoryQuantity.getPartNo());
+                // 鏌ヨ浜у搧
+                if (productObject != null && StrUtil.isNotBlank(productObject.getObjectType()) && productObject.getObjectType().equals("1")) {
                     isRaw = true;
+                } else {
+                // 鏌ヨ瀵硅薄
+                    StructureTestObject testObject = insOrderMapper.selectByPartNo(ifsInventoryQuantity.getPartNo());
+                    if (testObject != null && StrUtil.isNotBlank(testObject.getObjectType()) && testObject.getObjectType().equals("1")) {
+                        isRaw = true;
+                    }
                 }
-            }
 
-            if (isRaw) {
-                // 鑾峰彇褰撳墠瀛e害鐨勫紑濮嬫椂闂村拰缁撴潫鏃堕棿
-                LocalDateTime now = LocalDateTime.now();
-                // 鑾峰彇褰撳墠鏈堜唤
-                int month = now.getMonthValue();
-                // 纭畾褰撳墠瀛e害鐨勫紑濮嬫湀浠�
-                int startMonth = (month - 1) / 3 * 3 + 1;
-                // 鏋勯�犲搴︾殑寮�濮嬫椂闂�
-                LocalDateTime startOfQuarter = LocalDateTime.of(now.getYear(), Month.of(startMonth), 1, 0, 0);
-                // 璁$畻涓嬩竴涓搴︾殑寮�濮嬫椂闂�
-                LocalDateTime startOfNextQuarter = startOfQuarter.plusMonths(3);
-                // 璁$畻褰撳墠瀛e害鐨勭粨鏉熸椂闂�
-                LocalDateTime endOfQuarter = startOfNextQuarter.minusSeconds(1);
+                if (isRaw) {
+                    // 鑾峰彇褰撳墠瀛e害鐨勫紑濮嬫椂闂村拰缁撴潫鏃堕棿
+                    LocalDateTime now = LocalDateTime.now();
+                    // 鑾峰彇褰撳墠鏈堜唤
+                    int month = now.getMonthValue();
+                    // 纭畾褰撳墠瀛e害鐨勫紑濮嬫湀浠�
+                    int startMonth = (month - 1) / 3 * 3 + 1;
+                    // 鏋勯�犲搴︾殑寮�濮嬫椂闂�
+                    LocalDateTime startOfQuarter = LocalDateTime.of(now.getYear(), Month.of(startMonth), 1, 0, 0);
+                    // 璁$畻涓嬩竴涓搴︾殑寮�濮嬫椂闂�
+                    LocalDateTime startOfNextQuarter = startOfQuarter.plusMonths(3);
+                    // 璁$畻褰撳墠瀛e害鐨勭粨鏉熸椂闂�
+                    LocalDateTime endOfQuarter = startOfNextQuarter.minusSeconds(1);
 
-                // 鏍规嵁涓嬪崟鐨勮鏍煎瀷鍙峰垽鏂槸鍚︿负瀛e害棣栨鍑虹幇
-                Integer count = ifsInventoryQuantityMapper.selectIsFirst(insOrder.getPartDetail(),
-                        ifsInventoryQuantity.getSupplierName(),
-                        startOfNextQuarter,
-                        endOfQuarter);
+                    // 鏍规嵁涓嬪崟鐨勮鏍煎瀷鍙峰垽鏂槸鍚︿负瀛e害棣栨鍑虹幇
+                    Integer count = ifsInventoryQuantityMapper.selectIsFirst(insOrder.getPartDetail(),
+                            ifsInventoryQuantity.getSupplierName(),
+                            startOfNextQuarter,
+                            endOfQuarter);
 
-                if(count == 0) {
-                    ifsInventoryQuantity.setIsFirst(1);
-                    ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate()
-                            .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId())
-                            .set(IfsInventoryQuantity::getIsFirst, 1));
+                    if(count == 0) {
+                        ifsInventoryQuantity.setIsFirst(1);
+                        ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate()
+                                .eq(IfsInventoryQuantity::getId, insOrder.getIfsInventoryId())
+                                .set(IfsInventoryQuantity::getIsFirst, 1));
+                    }
                 }
             }
         }
@@ -513,9 +521,10 @@
     @Override
     public Map<String, Object> getInsOrderAndSample(Integer id, String laboratory) {
         Map<String, Object> map = new HashMap<>();
-        InsOrder insOrder = insOrderMapper.selectById(id);
+//        InsOrder insOrder = insOrderMapper.selectById(id);
+        IfsOrderVO ifsOrderVO = insOrderMapper.selectOrderInfoById(id);
         List<SampleProductDto> list = insSampleMapper.getInsOrderAndSample(id, laboratory);
-        map.put("insOrder", insOrder);
+        map.put("insOrder", ifsOrderVO);
         map.put("sampleProduct", list);
         //鏌ヨ鎵�鏈夎褰曟ā鐗堝幓閲�
         List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(id, laboratory);
@@ -1149,12 +1158,14 @@
 
     /**
      * ifs绉诲簱鎿嶄綔
-     * @param one
+     * @param inventoryQuantity
      * @return
      */
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public String moveRawMaterial(IfsInventoryQuantity one) {
+    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
+    public String moveRawMaterial(IfsInventoryQuantity inventoryQuantity) {
+        //鏌ヨifs璁㈠崟璇︽儏
+        IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectById(inventoryQuantity.getId());
         String toLocation;
         // 鐧昏閲囪喘妫�楠岀粨鏋淪TD
         if (one.getIsRegister().equals(0)) {
@@ -1175,7 +1186,7 @@
             if (result.getCode() != 200) {
                 throw new ErrorException("IFS鐧昏閲囪喘妫�楠岀粨鏋滃け璐�: " + result.getMessage());
             }
-            //濡傛灉鏄媶鍒嗚鍗曪紝鍒欏皢鍚屼竴鎺ュ彈鍙风殑璁㈠崟鏍囪宸茬櫥璁版帴鏀�
+            //濡傛灉鏄媶鍒嗚鍗曪紝鍒欏皢鍚屼竴鎺ユ敹鍙风殑璁㈠崟鏍囪宸茬櫥璁版牎楠�
             if(one.getIsSplitOrder()==1){
                 //鏌ヨ鍏朵綑鎷嗗垎鐨勮鍗�
                 List<IfsInventoryQuantity> quantityList = ifsInventoryQuantityMapper.selectList(Wrappers.<IfsInventoryQuantity>lambdaQuery()
@@ -1202,7 +1213,8 @@
          * TODO 鍚庣画闇�瑕佽皟鐢↖FS鐨勬帴鍙� 绉诲叆鐨勫簱浣嶅彿 toLocation
          */
         // 妫�楠屽悗绉诲簱
-        toLocation = "1301";
+        //1301:鍘熸潗鏂欏悎鏍煎簱锛孋P-02-001:鎴愬搧搴�
+        toLocation = StringUtils.equals(inventoryQuantity.getOrderType(), OrderType.RAW.getValue())?"1301":"CP-02-001";
         Map<String, Object> moveResultMap = new HashMap<>();
         List<Map<String, Object>> moveResultList = new ArrayList<>();
         Map<String, Object> moveMap = new HashMap<>();

--
Gitblit v1.9.3