From 9004d51f5b6096827b5c66b444729cb554997ec4 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期五, 26 九月 2025 14:32:30 +0800
Subject: [PATCH] 原材料订单拆分功能调整v2

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderServiceImpl.java |  418 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 353 insertions(+), 65 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 28495bc..c3b08cb 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
@@ -10,24 +10,25 @@
 import com.alibaba.excel.ExcelWriter;
 import com.alibaba.excel.write.metadata.WriteSheet;
 import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
-import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
 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.Wrappers;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.basic.mapper.IfsInventoryQuantityMapper;
 import com.ruoyi.basic.mapper.StandardProductListMapper;
+import com.ruoyi.basic.mapper.StructureItemParameterMapper;
 import com.ruoyi.basic.pojo.IfsInventoryQuantity;
 import com.ruoyi.basic.pojo.StandardProductList;
+import com.ruoyi.basic.pojo.StructureItemParameter;
 import com.ruoyi.basic.pojo.StructureTestObject;
 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.numgen.NumberGenerator;
 import com.ruoyi.common.utils.*;
+import com.ruoyi.common.utils.api.IfsApiUtils;
 import com.ruoyi.framework.exception.ErrorException;
 import com.ruoyi.inspect.dto.*;
 import com.ruoyi.inspect.mapper.*;
@@ -37,16 +38,12 @@
 import com.ruoyi.inspect.service.InsProductService;
 import com.ruoyi.inspect.service.InsSampleService;
 import com.ruoyi.inspect.vo.InsOrderPrintingVo;
-import com.ruoyi.inspect.vo.SampleDefectsFatherVo;
-import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHours;
-import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHoursTemporary;
-import com.ruoyi.performance.service.AuxiliaryOutputWorkingHoursTemporaryService;
-import com.ruoyi.system.mapper.CustomMapper;
 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;
@@ -87,14 +84,13 @@
     private IfsApiUtils ifsApiUtils;
     private SpotCheckQuarterItemMapper spotCheckQuarterItemMapper;
     private StandardProductListMapper standardProductListMapper;
-    private AuxiliaryOutputWorkingHoursTemporaryService auxiliaryOutputWorkingHoursTemporaryService;
+    private StructureItemParameterMapper structureItemParameterMapper;
 
 
 
     //鑾峰彇妫�楠屼笅鍗曟暟鎹�
     @Override
     public IPage<SampleOrderDto> selectInsOrderParameter(IPage<InsOrder> page, SampleOrderDto sampleOrderDto) {
-        //todo: 鍙湅鎴戝垽鏂叏閮�,涓汉,缁勭粐鐨勬潈闄�
         String laboratory = null;
         // 鍒ゆ柇鏄惁鏄叏閮�
         String isOrderAll = null;
@@ -160,43 +156,9 @@
             spotCheckQuarterItemMapper.updateById(spotCheckQuarterItem);
         }
 
-
-        // 鍒涘缓宸ユ椂鏆傚瓨
-        // 缂撳瓨鏍峰搧id, 缂栧彿map
-        Map<Integer, String> sampleMap = insSamples.stream().collect(Collectors.toMap(InsSample::getId, InsSample::getSampleCode));
-        List<InsProduct> insProductList = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
-                .in(InsProduct::getInsSampleId, ids)
-                .eq(InsProduct::getState, 1));
-        List<AuxiliaryOutputWorkingHoursTemporary> outputWorkingHours = insProductList.stream().map(insProduct -> {
-            AuxiliaryOutputWorkingHoursTemporary auxiliaryOutputWorkingHours = new AuxiliaryOutputWorkingHoursTemporary();
-            auxiliaryOutputWorkingHours.setInspectionItemClass(insProduct.getInspectionItemClass());//妫�娴嬮」鍒嗙被
-            auxiliaryOutputWorkingHours.setInspectionItem(insProduct.getInspectionItem());//妫�娴嬬埗椤�
-            auxiliaryOutputWorkingHours.setInspectionItemSubclass(insProduct.getInspectionItemSubclass());//妫�娴嬪瓙椤�
-            auxiliaryOutputWorkingHours.setSample(sampleMap.get(insProduct.getInsSampleId()));//鏍峰搧缂栧彿
-            auxiliaryOutputWorkingHours.setOrderId(order.getId());//璁㈠崟id
-            auxiliaryOutputWorkingHours.setOrderNo(order.getEntrustCode());//闈炲姞鐝鎵樺崟鍙�
-            auxiliaryOutputWorkingHours.setWorkTime(insProduct.getManHour());//闈炲姞鐝伐鏃�
-            auxiliaryOutputWorkingHours.setAmount(1);//闈炲姞鐝暟閲�
-            auxiliaryOutputWorkingHours.setOutputWorkTime((ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getOvertimeWorkTime()) ? auxiliaryOutputWorkingHours.getOvertimeWorkTime() : BigDecimal.ZERO).add(ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getWorkTime()) ? auxiliaryOutputWorkingHours.getWorkTime() : BigDecimal.ZERO));//浜ч噺宸ユ椂
-            auxiliaryOutputWorkingHours.setManHourGroup(insProduct.getManHourGroup());//宸ユ椂鍒嗙粍
-            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-            DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-            auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//鏃ユ湡
-            LocalDateTime localDateTime = LocalDateTime.now();
-            DateTime parse = DateUtil.parse(localDateTime.format(formatter));
-            auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//鏄熸湡
-            auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//鍛ㄦ
-            auxiliaryOutputWorkingHours.setCheck(userId);//妫�娴嬩汉
-            auxiliaryOutputWorkingHours.setPrice(insProduct.getPrice());//鍗曚环
-            auxiliaryOutputWorkingHours.setSampleId(insProduct.getInsSampleId());//鏍峰搧id
-            auxiliaryOutputWorkingHours.setInsProductId(insProduct.getId());//妫�楠岄」id
-
-            return auxiliaryOutputWorkingHours;
-        }).collect(Collectors.toList());
-        auxiliaryOutputWorkingHoursTemporaryService.saveBatch(outputWorkingHours);
-
         return 1;
     }
+
 
     public static String getWeek(String dayStr) {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -232,6 +194,19 @@
             default:
                 return "鏈煡";
         }
+    }
+
+
+    // 濡傛灉浣犱娇鐢� Java 8+锛屼篃鍙互鐢� Stream API 绠�鍖栦唬鐮侊細
+    public List<StandardProductList> findMissingItemsWithStream(List<StandardProductList> standardList,
+                                                                List<InsProduct> insList) {
+        Set<Integer> insIds = insList.stream()
+                .map(InsProduct::getStructureItemParameterId)
+                .collect(Collectors.toSet());
+
+        return standardList.stream()
+                .filter(product -> !insIds.contains(product.getStructureItemParameterId()))
+                .collect(Collectors.toList());
     }
 
     @Override
@@ -442,6 +417,9 @@
                 if (StringUtils.isBlank(product.getAsk()) || StringUtils.isBlank(product.getTell())) {
                     throw new ErrorException("鏈夋楠岄」鐨勮姹傚�兼垨瑕佹眰鎻忚堪涓虹┖, 璇峰厛鍘绘爣鍑嗗簱閰嶇疆瑕佹眰鍊兼垨瑕佹眰鎻忚堪");
                 }
+                if (StringUtils.isBlank(product.getSonLaboratory())) {
+                    throw new ErrorException("鏈夋楠岄」鐨勭殑瀛愬疄楠屽涓虹粦瀹�, 璇峰厛缁戝畾瀛愬疄楠屽");
+                }
                 insProductMapper.insert(product);
             }
         }
@@ -493,7 +471,7 @@
             }
             // 鐢熸垚缂栧彿
             String no = numberGenerator.generateNumberWithPrefix(3,
-                    "JCZX/ZB-" + code + LimsDateUtil.resetDate(LocalDateTime.now()),
+                    "JCZX/NS-" + code + LimsDateUtil.resetDate(LocalDateTime.now()),
                     InsOrder::getEntrustCode);
             // 鍒ゆ柇鏄惁鏄搴︽楠�, 鏄搴︽楠屽彇娑堝師鏉愭枡瀛e害妫�楠屼笅鍗�
             if (InsOrderTypeConstants.QUARTERLY_TEST.equals(order.getOrderType())) {
@@ -570,12 +548,9 @@
      * @return
      */
     @Override
-    public void getIfsOrder() {
-        HashMap<String, Object> map = new HashMap<>();
-        map.put("LOCATION_NO","1302");
-        map.put("STATE_DB","To be Inspected");
+    public void getIfsOrder(Map<String, Object> map,Boolean isSplitOrder) {
         List<Map<String, Object>> inventory = ifsApiUtils.getInventory(JSONUtil.toJsonStr(map));
-        if(inventory.size() == 0) {
+        if(inventory.isEmpty()) {
             return;
         }
         // 杩涜淇濆瓨
@@ -646,7 +621,7 @@
             ifsInventoryQuantity.setIsSource(1);
             ifsInventoryQuantity.setState(0);
 
-            IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>()
+            Long count = ifsInventoryQuantityMapper.selectCount(new LambdaQueryWrapper<IfsInventoryQuantity>()
                     .eq(IfsInventoryQuantity::getOrderNo, ifsInventoryQuantity.getOrderNo())
                     .eq(IfsInventoryQuantity::getLineNo, ifsInventoryQuantity.getLineNo())
                     .eq(IfsInventoryQuantity::getReleaseNo, ifsInventoryQuantity.getReleaseNo())
@@ -658,9 +633,11 @@
                     .eq(IfsInventoryQuantity::getWaivDevRejNo, ifsInventoryQuantity.getWaivDevRejNo())
                     .eq(IfsInventoryQuantity::getActivitySeq, ifsInventoryQuantity.getActivitySeq())
             );
-            if(Objects.isNull(one)) {
-
+            if(count == 0) {
                 ifsInventoryQuantity.setIsFirst(0);
+                if(isSplitOrder){
+                    ifsInventoryQuantity.setIsSplitOrder(1);
+                }
                 // 鏌ヨ浜т笟閾炬娴嬫暟鎹�
                 String industryChainAttrFields = IndustryChainUtils.getIndustryChainAttrFields(ifsInventoryQuantity.getOrderNo(),
                         ifsInventoryQuantity.getLineNo(),
@@ -743,7 +720,7 @@
      * @param id
      */
     @Transactional
-    public void updateIfsInventoryQuantity(Integer id) {
+    public void updateIfsInventoryQuantity(Long id) {
         ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate()
                 .set(IfsInventoryQuantity::getIsRegister, 1)
                 .eq(IfsInventoryQuantity::getId, id));
@@ -899,6 +876,10 @@
 
         // 淇敼妫�楠岄」
         for (SampleProductDto sampleProductDto : insOrderUpdateDto.getSampleProduct()) {
+            insSampleService.update(Wrappers.<InsSample>lambdaUpdate()
+                    .eq(InsSample::getId, sampleProductDto.getId())
+                    .set(InsSample::getSpecialStandardMethod, sampleProductDto.getSpecialStandardMethod()));
+
             insProductService.updateBatchById(sampleProductDto.getInsProduct());
         }
 
@@ -934,7 +915,8 @@
         // 鏌ヨ鏍囧噯鏍�
         List<StandardProductList> standardProductLists = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
                 .eq(StandardProductList::getStandardMethodListId, insProduct.getStandardMethodListId())
-                .eq(StandardProductList::getTree, tree));
+                .eq(StandardProductList::getTree, tree)
+                .orderByAsc(StandardProductList::getSort));
         for (StandardProductList standardProductList : standardProductLists) {
             standardProductList.setId(null);
         }
@@ -959,6 +941,7 @@
                 product.setCreateUser(null);
                 product.setUpdateTime(null);
                 product.setUpdateUser(null);
+                product.setSection(null);
                 product.setInsSampleId(omitOrderProductDto.getInsSampleId());
                 if (StringUtils.isBlank(product.getCableTag())) {
                     product.setCableTag(null);
@@ -983,16 +966,21 @@
      */
     @Override
     public void rawAllInsOrderExport(SampleOrderDto sampleOrderDto, HttpServletResponse response) {
-        //鍒ゆ柇鍏ㄩ儴,涓汉,缁勭粐鐨勬潈闄�
-        //todo:浠呯湅鎴戣幏鍙栧綋鍓嶄汉鎵�灞炲疄楠屽id
-        String laboratory = null;
-        // 鍒ゆ柇鏄惁鏄叏閮�
-        String isOrderAll = null;
-        if (sampleOrderDto.getState() != null && sampleOrderDto.getState() == -2) {
-            isOrderAll = "1";
-            sampleOrderDto.setState(null);
+        List<SampleOrderDto> sampleOrderDtoList = new ArrayList<>();
+        if (StringUtils.isNotBlank(sampleOrderDto.getIds())) {
+            List<String> orderIds = StrUtil.split(sampleOrderDto.getIds(), ",");
+            sampleOrderDtoList = insOrderMapper.getInsOrderExportByIds(orderIds);
+        } else {
+            String laboratory = null;
+            // 鍒ゆ柇鏄惁鏄叏閮�
+            String isOrderAll = null;
+            if (sampleOrderDto.getState() != null && sampleOrderDto.getState() == -2) {
+                isOrderAll = "1";
+                sampleOrderDto.setState(null);
+            }
+            sampleOrderDto.setIds(null);
+            sampleOrderDtoList = insOrderMapper.rawAllInsOrderExport(QueryWrappers.queryWrappers(sampleOrderDto), laboratory, isOrderAll);
         }
-        List<SampleOrderDto> sampleOrderDtoList = insOrderMapper.rawAllInsOrderExport(QueryWrappers.queryWrappers(sampleOrderDto), laboratory, isOrderAll);
 
         // 鍒ゆ柇鏄惁鏄笉鍚堟牸, 涓嶅悎鏍兼煡璇笉鍚堟牸椤�
         for (SampleOrderDto orderDto : sampleOrderDtoList) {
@@ -1025,6 +1013,306 @@
         }
     }
 
+    /**
+     * 淇敼鏍峰搧鍨嬪彿
+     * @param insSample
+     */
+    @Override
+    public void updateSampleModel(InsSample insSample) {
+        // 鍒ゆ柇褰撳墠璁㈠崟鏄惁鐢熸垚浜嗘姤鍛�, 鐢熸垚浜嗘姤鍛婁笉鑳戒慨鏀瑰崟鍙�
+        Long count = insReportMapper.selectCount(Wrappers.<InsReport>lambdaQuery()
+                .eq(InsReport::getInsOrderId, insSample.getInsOrderId()));
+        if (count > 0 ) {
+            throw new ErrorException("褰撳墠璁㈠崟宸茬粡鐢熸垚浜嗘姤鍛婁笉鑳戒慨鏀圭紪鍙�");
+        }
+
+        insSampleService.update(Wrappers.<InsSample>lambdaUpdate()
+                .eq(InsSample::getId, insSample.getId())
+                .set(InsSample::getModel, insSample.getModel()));
+    }
+
+    /**
+     * 鏌ヨ褰撳墠鏃堕棿鏄惁娌℃湁璇ユ娴嬮」鐨勬娊鏍疯鍒�
+     * @param sampleList
+     * @param insOrder
+     * @return
+     */
+    @Override
+    public Result judgeNotSpotCheckOrder(List<SampleProductDto> sampleList, InsOrder insOrder) {
+        // todo: 涓嬪崟鍒ゆ柇鎶芥牱璁″垝鐨勫敮涓�鎬�
+        if (insOrder.getQuarterItemId() != null) {
+            Long quarterItemCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
+                    .eq(InsOrder::getQuarterItemId, insOrder.getQuarterItemId())
+                    .notIn(InsOrder::getState, -1 ,2 ,3));
+            if (quarterItemCount > 0) {
+                throw new ErrorException("璇ユ娊鏍疯鍒掑凡琚粦瀹氳繃");
+            }
+        }
+
+        // 鍒ゆ柇鏄惁鏄娊鏍锋娴�
+        if (insOrder.getOrderType().equals(InsOrderTypeConstants.SPOT_CHECK)) {
+            Set<String> monthMessageSet = new HashSet<>();
+            Set<String> quarterMessageSet = new HashSet<>();
+            Set<String> yearMessageSet = new HashSet<>();
+
+            String formatTime = "yyyy-MM-dd HH:mm:ss";
+            // 鏌ヨ褰撳墠鎵�鏈夋牱鍝佺殑妫�楠岄」
+            for (SampleProductDto sampleProductDto : sampleList) {
+                List<StandardProductList> standardProductList = getProductTreeBySampleId(sampleProductDto.getId());
+
+                Set<Integer> insIds = sampleProductDto.getInsProduct().stream()
+                        .map(InsProduct::getStructureItemParameterId)
+                        .collect(Collectors.toSet());
+
+                List<StandardProductList> productLists = standardProductList.stream()
+                        .filter(product -> !insIds.contains(product.getStructureItemParameterId()))
+                        .collect(Collectors.toList());
+
+                // 鏌ヨ妫�楠岄」鍩虹琛�, 鏌ヨ鏄惁鏈夋湀搴�, 瀛e害, 骞村害鐨勬楠岄」
+                List<StructureItemParameter> itemParameterList = structureItemParameterMapper.selectList(Wrappers.<StructureItemParameter>lambdaQuery()
+                        .in(StructureItemParameter::getId, productLists.stream().map(StandardProductList::getStructureItemParameterId).collect(Collectors.toList())));
+
+                for (StructureItemParameter item : itemParameterList) {
+                    if (StringUtils.isNotBlank(item.getSpotCheckType())) {
+                        switch (item.getSpotCheckType()) {
+                            case "1": // 鏈堝害
+                                // 鏌ヨ褰撴湀鏄惁鏈夎妫�娴嬮」鐨勬娊鏍疯鍒�
+                                // 褰撴湀寮�濮嬫椂闂�
+                                DateTime monthStart = DateUtil.beginOfMonth(DateUtil.date());
+                                String monthStartTime = monthStart.toString(formatTime);
+                                // 褰撴湀缁撴潫鏃堕棿
+                                DateTime monthEnd = DateUtil.endOfMonth(DateUtil.date());
+                                String monthEndTime = monthEnd.toString(formatTime);
+                                Integer count = insOrderMapper.selectNotSpotCheckOrder(item.getId(), monthStartTime, monthEndTime);
+                                if (count == 0) {
+                                    String monthMessage = item.getInspectionItemClass() +
+                                            item.getInspectionItem() +
+                                            item.getInspectionItemSubclass();
+                                    monthMessageSet.add(monthMessage);
+                                }
+                                break;
+                            case "2": // 瀛e害
+                                DateTime quarterStart = DateUtil.beginOfQuarter(DateUtil.date());
+                                String quarterStartTime = quarterStart.toString(formatTime);
+                                // 褰撴湀缁撴潫鏃堕棿
+                                DateTime quarterEnd = DateUtil.endOfQuarter(DateUtil.date());
+                                String quarterEndTime = quarterEnd.toString(formatTime);
+                                Integer quarterCount = insOrderMapper.selectNotSpotCheckOrder(item.getId(), quarterStartTime, quarterEndTime);
+                                if (quarterCount == 0) {
+                                    String quarterMessage = item.getInspectionItemClass() +
+                                            item.getInspectionItem() +
+                                            item.getInspectionItemSubclass();
+                                    quarterMessageSet.add(quarterMessage);
+                                }
+
+                                break;
+                            case "3": // 骞村害
+                                DateTime yearStart = DateUtil.beginOfQuarter(DateUtil.date());
+                                String yearStartTime = yearStart.toString(formatTime);
+                                // 褰撴湀缁撴潫鏃堕棿
+                                DateTime yearEnd = DateUtil.endOfQuarter(DateUtil.date());
+                                String yearEndTime = yearEnd.toString(formatTime);
+                                Integer yearCount = insOrderMapper.selectNotSpotCheckOrder(item.getId(), yearStartTime, yearEndTime);
+                                if (yearCount == 0) {
+                                    String yearMessage = item.getInspectionItemClass() +
+                                            item.getInspectionItem() +
+                                            item.getInspectionItemSubclass();
+                                    yearMessageSet.add(yearMessage);
+                                }
+
+                                break;
+                        }
+                    }
+                }
+            }
+
+            String message = "";
+            if (CollectionUtils.isNotEmpty(monthMessageSet)) {
+                message += StrUtil.format("<p>妫�楠岄」<span style=\"color: red\">{}</span>褰撴湀杩樻湭杩涜鎶芥牱妫�娴�, 璇锋煡鐪嬫槸鍚﹂渶瑕佹坊鍔犲綋鍓嶆楠岄」</p>", CollUtil.join(monthMessageSet, ", "));
+            }
+
+            if (CollectionUtils.isNotEmpty(quarterMessageSet)) {
+                message += StrUtil.format("<p>妫�楠岄」<span style=\"color: red\">{}</span>褰撳墠瀛e害杩樻湭杩涜鎶芥牱妫�娴�, 璇风湅鏄惁闇�瑕佹坊鍔犲綋鍓嶆楠岄」</p>", CollUtil.join(quarterMessageSet, ", "));
+            }
+
+            if (CollectionUtils.isNotEmpty(yearMessageSet)) {
+                message += StrUtil.format("<p>妫�楠岄」<span style=\"color: red\">{}</span>浠婂勾杩樻湭杩涜鎶芥牱妫�娴�, 璇风湅鏄惁闇�瑕佹坊鍔犲綋鍓嶆楠岄」</p>", CollUtil.join(yearMessageSet, ", "));
+            }
+
+            if (StringUtils.isNotBlank(message)) {
+                return Result.success(false, message);
+            }
+        }
+        return Result.success(true);
+
+    }
+
+
+    /**
+     * ifs绉诲簱鎿嶄綔
+     * @param inventoryQuantity
+     * @return
+     */
+    @Override
+    @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)) {
+            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());
+            }
+            //濡傛灉鏄媶鍒嗚鍗曪紝鍒欏皢鍚屼竴鎺ユ敹鍙风殑璁㈠崟鏍囪宸茬櫥璁版牎楠�
+            if(one.getIsSplitOrder()==1){
+                //鏌ヨ鍏朵綑鎷嗗垎鐨勮鍗�
+                List<IfsInventoryQuantity> quantityList = ifsInventoryQuantityMapper.selectList(Wrappers.<IfsInventoryQuantity>lambdaQuery()
+                        .eq(IfsInventoryQuantity::getOrderNo, one.getOrderNo())
+                        .eq(IfsInventoryQuantity::getPartNo, one.getPartNo())
+                        .eq(IfsInventoryQuantity::getLineNo, one.getLineNo())
+                        .eq(IfsInventoryQuantity::getReleaseNo, one.getReleaseNo())
+                        .eq(IfsInventoryQuantity::getReceiptNo, one.getReceiptNo())
+                        .eq(IfsInventoryQuantity::getIsSplitOrder, 1)
+                );
+                if(Objects.nonNull(quantityList) && !quantityList.isEmpty()){
+                    //淇敼閲囪喘璁㈠崟鐧昏鐘舵��
+                    List<Long> ids = quantityList.stream().map(IfsInventoryQuantity::getId).collect(Collectors.toList());
+                    ifsInventoryQuantityMapper.update(null,Wrappers.<IfsInventoryQuantity>lambdaUpdate()
+                            .set(IfsInventoryQuantity::getIsRegister,1)
+                            .in(IfsInventoryQuantity::getId, ids)
+                    );
+                }
+            }else{
+                this.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.getPurQtyInStore());
+        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 one
+     * @param toLocation
+     */
+    private void updaeBatch(IfsInventoryQuantity one, String toLocation) {
+        if (one.getIsUpdateBatch().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("PART_NO", one.getPartNo()); //闆朵欢鍙�
+            map.put("CONFIGURATION_ID", one.getConfigurationId()); // 閰嶇疆鏍囪瘑
+            map.put("LOCATION_NO", one.getLocationNo()); // 搴撲綅鍙�
+            map.put("LOT_BATCH_NO", one.getLotBatchNo());// 鎵规鍙�
+            map.put("NEW_LOT_BATCH_NO", one.getUpdateBatchNo()); // 鐩爣鎵规鍙�
+            map.put("SERIAL_NO", one.getSerialNo()); // 搴忓垪鍙�
+            map.put("ENG_CHG_LEVEL", one.getEngChgLevel()); // 鐗堟湰鍙�
+            map.put("WAIV_DEV_REJ_NO", one.getWaivDevRejNo()); // wdr鍙�
+            map.put("ACTIVITY_SEQ", one.getActivitySeq()); // 娲诲姩搴忓彿
+            map.put("QTY_TO_CHANGE", one.getQtyArrived()); // 鍙樻洿鏁伴噺
+            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.updateMoveReceiptLot(JSONUtil.toJsonStr(resultMap));
+
+            if (result.getCode() != 200) {
+                throw new ErrorException("IFS淇敼鎵规鍙峰け璐�: " + result.getMessage());
+            }
+            ifsInventoryQuantityMapper.update(null, Wrappers.<IfsInventoryQuantity>lambdaUpdate()
+                    .set(IfsInventoryQuantity::getIsUpdateBatch, 1)
+                    .eq(IfsInventoryQuantity::getId, one.getId()));
+        }
+
+        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.getUpdateBatchNo());
+        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) {
+            throw new ErrorException("IFS妫�楠屽悗绉诲簱澶辫触: " + result1.getMessage());
+        }
+
+    }
+
+
 }
 
 

--
Gitblit v1.9.3