From 3166624edda4fc938593432b619fa5ad00409f0a Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期二, 03 十一月 2026 16:49:12 +0800
Subject: [PATCH] feat(outsource): 1.支持外协订单按物料属性分流复用原有业务流程 2.修复工时字段空值判断与赋值逻辑

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java |   61 +++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 6 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 5370f98..275e312 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
@@ -35,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;
@@ -48,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;
 
@@ -88,8 +91,10 @@
     private InsUnqualifiedRetestProductMapper insUnqualifiedRetestProductMapper;
     private IfsApiUtils ifsApiUtils;
     private SpotCheckQuarterItemMapper spotCheckQuarterItemMapper;
+    private ApplicationEventPublisher applicationEventPublisher;
     private StandardProductListMapper standardProductListMapper;
     private StructureItemParameterMapper structureItemParameterMapper;
+    private OutsourceOrderFlowService outsourceOrderFlowService;
 
 
     //鑾峰彇妫�楠屼笅鍗曟暟鎹�
@@ -216,6 +221,7 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int addInsOrder(List<SampleProductDto> list, InsOrder insOrder) {
+        initOutsourceOrderSource(insOrder);
         // todo: 涓嬪崟鍒ゆ柇鎶芥牱璁″垝鐨勫敮涓�鎬�
         if (insOrder.getQuarterItemId() != null) {
             Long quarterItemCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
@@ -406,6 +412,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);
+    }
+
     /**
      * 娣诲姞妫�楠岄」
      *
@@ -439,16 +460,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;
@@ -527,6 +548,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) {
+                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);
@@ -534,6 +565,19 @@
         List<Map<Integer, Object>> list2 = insOrderMapper.selectReportModelByOrderId(id, laboratory);
         map.put("reportModel", list2);
         return map;
+    }
+
+    /** 淇濆瓨鍓嶈鍙栫湡瀹為攢鍞鍗曪紝绾犳澶栧崗涓嬪崟鏉ユ簮锛岄伩鍏嶅墠绔紦瀛樺奖鍝嶅疄楠屽鍒嗛厤銆� */
+    private void initOutsourceOrderSource(InsOrder insOrder) {
+        if (insOrder.getIfsInventoryId() == null) {
+            return;
+        }
+        IfsInventoryQuantity quantity = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId());
+        if (quantity == null) {
+            throw new ErrorException("鎵句笉鍒伴攢鍞鍗曚俊鎭�");
+        }
+        insOrder.setTypeSource(outsourceOrderFlowService.resolveTypeSource(
+                quantity.getOrderType(), quantity.getMaterialProp(), insOrder.getTypeSource()));
     }
 
     @Override
@@ -626,8 +670,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()); // 鎺ユ敹鏃ユ湡
@@ -1241,7 +1285,7 @@
         //1.鏍规嵁ifs鍩熻幏鍙栧搴斿簱浣嶉厤缃�
         IfsProperties properties = ifsApiUtils.getPropByContract(one.getContract());
         //2.鍒ゆ柇璁㈠崟绫诲瀷鏄惁涓哄師鏉愭枡
-        if(StringUtils.equals(inventoryQuantity.getOrderType(), OrderType.RAW.getValue())){
+        if(StringUtils.equals(outsourceOrderFlowService.resolve(one.getOrderType(), one.getMaterialProp()), OrderType.RAW.getValue())){
             toLocation = properties.getRawQualifiedLocation();
         }else{
             toLocation = properties.getProductQualifiedLocation();
@@ -1285,6 +1329,11 @@
         return toLocation;
     }
 
+    @Override
+    public Map<String, Object> getInsOrderList(List<Integer> selectOrderIds) {
+        return insOrderMapper.selectOrderInfoByIds(selectOrderIds);
+    }
+
 
     /**
      * 鍏堜慨鏀归噰璐鍗曟壒娆″彿, 鍚庤繘琛岀Щ搴撴搷浣�

--
Gitblit v1.9.3