From d28a5401ac1e2995ec6de12a81395aa5d05b040a Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 05 十一月 2026 10:17:49 +0800
Subject: [PATCH] refactor(order): 提取外协判断方法并还原原下单

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java |   88 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 74 insertions(+), 14 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 4c474ec..3123929 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
@@ -25,6 +25,7 @@
 import com.ruoyi.basic.pojo.StandardProductList;
 import com.ruoyi.basic.pojo.StructureItemParameter;
 import com.ruoyi.basic.pojo.StructureTestObject;
+import com.ruoyi.common.config.ifs.IfsProperties;
 import com.ruoyi.common.constant.InsOrderTypeConstants;
 import com.ruoyi.common.core.domain.Result;
 import com.ruoyi.common.core.domain.entity.User;
@@ -34,12 +35,14 @@
 import com.ruoyi.common.utils.api.IfsApiUtils;
 import com.ruoyi.framework.exception.ErrorException;
 import com.ruoyi.inspect.dto.*;
+import com.ruoyi.inspect.event.InsOrderDeletingEvent;
 import com.ruoyi.inspect.mapper.*;
 import com.ruoyi.inspect.pojo.*;
 import com.ruoyi.inspect.service.InsOrderService;
 import com.ruoyi.inspect.service.InsOrderStateService;
 import com.ruoyi.inspect.service.InsProductService;
 import com.ruoyi.inspect.service.InsSampleService;
+import com.ruoyi.inspect.service.OutsourceOrderFlowService;
 import com.ruoyi.inspect.vo.IfsOrderVO;
 import com.ruoyi.inspect.vo.InsOrderPrintingVo;
 import com.ruoyi.system.mapper.UserMapper;
@@ -47,6 +50,7 @@
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -87,8 +91,10 @@
     private InsUnqualifiedRetestProductMapper insUnqualifiedRetestProductMapper;
     private IfsApiUtils ifsApiUtils;
     private SpotCheckQuarterItemMapper spotCheckQuarterItemMapper;
+    private ApplicationEventPublisher applicationEventPublisher;
     private StandardProductListMapper standardProductListMapper;
     private StructureItemParameterMapper structureItemParameterMapper;
+    private OutsourceOrderFlowService outsourceOrderFlowService;
 
 
     //鑾峰彇妫�楠屼笅鍗曟暟鎹�
@@ -224,6 +230,16 @@
                 throw new ErrorException("璇ユ娊鏍疯鍒掑凡琚粦瀹氳繃");
             }
         }
+        IfsInventoryQuantity ifsInventoryQuantity = null;
+        if (insOrder.getIfsInventoryId() != null) {
+            ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId());
+            if (ifsInventoryQuantity != null) {
+                insOrder.setTypeSource(outsourceOrderFlowService.resolveTypeSource(
+                        ifsInventoryQuantity.getOrderType(), ifsInventoryQuantity.getMaterialProp(), insOrder.getTypeSource()));
+            } else if (insOrder.getTypeSource() != null) {
+                throw new ErrorException("鎵句笉鍒伴攢鍞鍗曚俊鎭�");
+            }
+        }
         insOrder.setState(0);
 
         LocalDate appointed = insOrder.getAppointed();
@@ -315,9 +331,8 @@
         });
 
         //鍘熸潗鏂欎笅鍗曟垨澶栬喘鎴愬搧涓嬪崟
-        if (Objects.nonNull(insOrder.getTypeSource()) && Objects.nonNull(insOrder.getIfsInventoryId())) {
+        if (insOrder.getTypeSource() != null && ifsInventoryQuantity != null) {
             // 濮旀墭浜哄氨鏄姤妫�浜�, 鐢熶骇鍗曚綅灏辨槸渚涘簲鍟嗗崟浣�
-            IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId());
             Integer declareUserId = ifsInventoryQuantity.getDeclareUserId();
             User user = userMapper.selectById(declareUserId);
             if (user == null) {
@@ -405,6 +420,21 @@
         return insOrder.getId();
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean deleteReturnedOrder(Integer insOrderId) {
+        InsOrder order = insOrderMapper.selectById(insOrderId);
+        if (order == null) {
+            throw new ErrorException("鎴愬搧璁㈠崟涓嶅瓨鍦�");
+        }
+        if (!(Integer.valueOf(2).equals(order.getState()) || Integer.valueOf(3).equals(order.getState()))) {
+            throw new ErrorException("鍙湁閫�鍥炴垨鎾ら攢璁㈠崟鎵嶈兘鍒犻櫎");
+        }
+        Integer operatorId = SecurityUtils.getUserId().intValue();
+        applicationEventPublisher.publishEvent(new InsOrderDeletingEvent(insOrderId, operatorId, LocalDateTime.now()));
+        return removeById(insOrderId);
+    }
+
     /**
      * 娣诲姞妫�楠岄」
      *
@@ -438,16 +468,16 @@
     @Override
     public Map<String, Object> getInsOrder(Integer id) {
         Map<String, Object> map = new HashMap<>();
-        InsOrder insOrder = insOrderMapper.selectById(id);
+        IfsOrderVO ifsOrderVO = insOrderMapper.selectOrderInfoById(id);
         List<SampleProductDto> list;
         // 鍒ゆ柇鏄惁鏄繘鍘傛姤鍛婂厤妫�
-        if (insOrder.getIsExemption().equals(1)) {
+        if (ifsOrderVO.getIsExemption().equals(1)) {
             list = insSampleMapper.selectExemptionByOrderId(id);
         } else {
             list = insSampleMapper.selectSampleProductListByOrderId2(id);
         }
         Map<String, Object> map1 = insSampleMapper.selectInsOrder(id);
-        map.put("insOrder", insOrder);
+        map.put("insOrder", ifsOrderVO);
         map.put("sampleProduct", list);
         map.put("insOrderTemplate", map1);
         return map;
@@ -526,6 +556,16 @@
         Map<String, Object> map = new HashMap<>();
 //        InsOrder insOrder = insOrderMapper.selectById(id);
         IfsOrderVO ifsOrderVO = insOrderMapper.selectOrderInfoById(id);
+        // 璇︽儏鍚屾椂杩斿洖鏈夋晥澶勭悊娴佺▼锛屼緵妫�娴嬮〉闈㈢粺涓�閫夋嫨甯冨眬鍙婃牎楠岃鍒欍��
+        if (ifsOrderVO != null) {
+            ifsOrderVO.setFlowOrderType(ifsOrderVO.getIfsOrderType());
+            if (ifsOrderVO.getIfsInventoryId() != null && outsourceOrderFlowService.isOutsource(ifsOrderVO.getIfsOrderType())) {
+                IfsInventoryQuantity quantity = ifsInventoryQuantityMapper.selectById(ifsOrderVO.getIfsInventoryId());
+                if (quantity != null) {
+                    ifsOrderVO.setFlowOrderType(outsourceOrderFlowService.resolve(quantity.getOrderType(), quantity.getMaterialProp()));
+                }
+            }
+        }
         List<SampleProductDto> list = insSampleMapper.getInsOrderAndSample(id, laboratory);
         map.put("insOrder", ifsOrderVO);
         map.put("sampleProduct", list);
@@ -561,7 +601,7 @@
      */
     @Override
     public void getIfsOrder(Map<String, Object> map, Boolean isSplitOrder) {
-        List<Map<String, Object>> inventory = ifsApiUtils.getInventory(JSONUtil.toJsonStr(map));
+        List<Map<String, Object>> inventory = ifsApiUtils.getInventory(map);
         if (inventory.isEmpty()) {
             return;
         }
@@ -625,8 +665,8 @@
             if (map1.get("APPROVED_DATE") != null) {
                 ifsInventoryQuantity.setApprovedDate(LocalDateTime.parse(map1.get("APPROVED_DATE").toString(), dateTimeFormatter)); // 瀹℃壒鏃ユ湡
             }
-            ifsInventoryQuantity.setReqCeater(map1.get("REQ_CEATER") == null ? "" : map1.get("REQ_CEATER").toString()); // 閲囪喘鐢宠鍒涘缓浜�
-            ifsInventoryQuantity.setReqCeaterName(map1.get("REQ_CEATER_NAME") == null ? "" : map1.get("REQ_CEATER_NAME").toString()); // 閲囪喘鐢宠鍒涘缓浜哄悕绉�
+            ifsInventoryQuantity.setReqCeater(map1.get("REQ_CREATER") == null ? "" : map1.get("REQ_CREATER").toString()); // 閲囪喘鐢宠鍒涘缓浜�
+            ifsInventoryQuantity.setReqCeaterName(map1.get("REQ_CREATER_NAME") == null ? "" : map1.get("REQ_CREATER_NAME").toString()); // 閲囪喘鐢宠鍒涘缓浜哄悕绉�
             ifsInventoryQuantity.setLineRemarks(map1.get("LINE_REMARKS") == null ? "" : map1.get("LINE_REMARKS").toString()); // 閲囪喘璁㈠崟琛屽娉�
             ifsInventoryQuantity.setBuyUnitMeas(map1.get("BUY_UNIT_MEAS") == null ? "" : map1.get("BUY_UNIT_MEAS").toString()); // 閲囪喘鍗曚綅
             ifsInventoryQuantity.setReceiverDate(LocalDateTime.now()); // 鎺ユ敹鏃ユ湡
@@ -807,6 +847,8 @@
         ifsInventoryQuantity.setIsCopper(1);
         ifsInventoryQuantity.setIsQuarter(0);
         ifsInventoryQuantity.setInspectStatus(0);
+        ifsInventoryQuantity.setOrderType(OrderType.RAW.getValue());
+        ifsInventoryQuantity.setMaterialProp("01Cu");
 
         ifsInventoryQuantity.setQtyArrived(insOrder.getQtyArrived());
         ifsInventoryQuantity.setBuyUnitMeas(insOrder.getBuyUnitMeas());
@@ -1188,6 +1230,9 @@
     public String moveRawMaterial(IfsInventoryQuantity inventoryQuantity) {
         //鏌ヨifs璁㈠崟璇︽儏
         IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectById(inventoryQuantity.getId());
+        String flowOrderType = outsourceOrderFlowService.isOutsource(one.getOrderType())
+                ? outsourceOrderFlowService.resolve(one.getOrderType(), one.getMaterialProp())
+                : inventoryQuantity.getOrderType();
         String toLocation;
         // 鐧昏閲囪喘妫�楠岀粨鏋淪TD
         if (one.getIsRegister().equals(0)) {
@@ -1204,7 +1249,7 @@
             resultMap.put("SYSCODE", "LIMS");
             resultMap.put("SYSMODEL", "鐧昏閲囪喘妫�楠岀粨鏋�");
             resultMap.put("BATCH_INFO", resultList);
-            Result result = ifsApiUtils.getProcurementResults(JSONUtil.toJsonStr(resultMap));
+            Result result = ifsApiUtils.getProcurementResults(one.getContract(),JSONUtil.toJsonStr(resultMap));
             if (result.getCode() != 200) {
                 throw new ErrorException("IFS鐧昏閲囪喘妫�楠岀粨鏋滃け璐�: " + result.getMessage());
             }
@@ -1235,8 +1280,14 @@
          * TODO 鍚庣画闇�瑕佽皟鐢↖FS鐨勬帴鍙� 绉诲叆鐨勫簱浣嶅彿 toLocation
          */
         // 妫�楠屽悗绉诲簱
-        //1301:鍘熸潗鏂欏悎鏍煎簱锛孋P-02-001:鎴愬搧搴�
-        toLocation = StringUtils.equals(inventoryQuantity.getOrderType(), OrderType.RAW.getValue()) ? "1301" : "CP-02-001";
+        //1.鏍规嵁ifs鍩熻幏鍙栧搴斿簱浣嶉厤缃�
+        IfsProperties properties = ifsApiUtils.getPropByContract(one.getContract());
+        //2.鍒ゆ柇璁㈠崟绫诲瀷鏄惁涓哄師鏉愭枡
+        if(StringUtils.equals(flowOrderType, OrderType.RAW.getValue())){
+            toLocation = properties.getRawQualifiedLocation();
+        }else{
+            toLocation = properties.getProductQualifiedLocation();
+        }
         Map<String, Object> moveResultMap = new HashMap<>();
         List<Map<String, Object>> moveResultList = new ArrayList<>();
         Map<String, Object> moveMap = new HashMap<>();
@@ -1259,7 +1310,7 @@
         moveResultMap.put("SYSMODEL", "妫�楠屽悗绉诲簱");
         moveResultMap.put("BATCH_INFO", moveResultList);
 
-        Result result1 = ifsApiUtils.moveReceipt(JSONUtil.toJsonStr(moveResultMap));
+        Result result1 = ifsApiUtils.moveReceipt(one.getContract(),JSONUtil.toJsonStr(moveResultMap));
         // 濡傛灉鏈夊繀椤讳负闆朵欢鎸囧畾鎵瑰彿鎶ラ敊闇�瑕侀噸鏂版彁浜ょЩ搴撲俊鎭幓鎸囧畾鎵瑰彿
         if (result1.getCode() != 200) {
             String message = result1.getMessage();
@@ -1269,7 +1320,16 @@
                 throw new ErrorException("IFS妫�楠屽悗绉诲簱澶辫触: " + result1.getMessage());
             }
         }
+        // 淇敼ifs璁㈠崟鏁版嵁涓哄凡妫�楠�
+        ifsInventoryQuantityMapper.update(null, new LambdaUpdateWrapper<IfsInventoryQuantity>()
+                .set(IfsInventoryQuantity::getState, 2)
+                .eq(IfsInventoryQuantity::getId, inventoryQuantity.getId()));
         return toLocation;
+    }
+
+    @Override
+    public Map<String, Object> getInsOrderList(List<Integer> selectOrderIds) {
+        return insOrderMapper.selectOrderInfoByIds(selectOrderIds);
     }
 
 
@@ -1305,7 +1365,7 @@
             resultMap.put("SYSMODEL", "淇敼閲囪喘璁㈠崟鎵规鍙�");
             resultMap.put("BATCH_INFO", resultList);
 
-            Result result = ifsApiUtils.updateMoveReceiptLot(JSONUtil.toJsonStr(resultMap));
+            Result result = ifsApiUtils.updateMoveReceiptLot(one.getContract(),JSONUtil.toJsonStr(resultMap));
 
             if (result.getCode() != 200) {
                 throw new ErrorException("IFS淇敼鎵规鍙峰け璐�: " + result.getMessage());
@@ -1337,7 +1397,7 @@
         moveResultMap.put("SYSMODEL", "妫�楠屽悗绉诲簱");
         moveResultMap.put("BATCH_INFO", moveResultList);
 
-        Result result1 = ifsApiUtils.moveReceipt(JSONUtil.toJsonStr(moveResultMap));
+        Result result1 = ifsApiUtils.moveReceipt(one.getContract(),JSONUtil.toJsonStr(moveResultMap));
         if (result1.getCode() != 200) {
             throw new ErrorException("IFS妫�楠屽悗绉诲簱澶辫触: " + result1.getMessage());
         }

--
Gitblit v1.9.3