From 768498719683f85e5ed19c73eb3d14cdbf420df4 Mon Sep 17 00:00:00 2001
From: admin <15939171744@163.com>
Date: 星期一, 01 七月 2024 14:03:01 +0800
Subject: [PATCH] 绑定小车码,预装总成码,手动工位扫码,拧紧逻辑优化

---
 jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/service/impl/BsFormulaChildInfoServiceImpl.java |  164 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 98 insertions(+), 66 deletions(-)

diff --git a/jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/service/impl/BsFormulaChildInfoServiceImpl.java b/jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/service/impl/BsFormulaChildInfoServiceImpl.java
index b22018a..3221f31 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/service/impl/BsFormulaChildInfoServiceImpl.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/bs/formulaChild/service/impl/BsFormulaChildInfoServiceImpl.java
@@ -11,6 +11,7 @@
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jcdm.common.core.domain.AjaxResult;
 import com.jcdm.common.utils.DateUtils;
@@ -180,10 +181,13 @@
                 .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode())
                 .eq(BsFormulaChildInfo::getOperationType, "2")
         );
-        for (BsFormulaChildInfo formulaChildInfo : infos) {
-            if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())){
-                bsFormulaChildInfos.add(formulaChildInfo);
-                break;
+        List<String> newResultsList = infos.stream().map(s -> s.getCollectData()).collect(Collectors.toList());
+        if(newResultsList.stream().noneMatch(results -> results.equals(bsFormulaChildInfo.getScanBarcode()))){
+            for (BsFormulaChildInfo formulaChildInfo : infos) {
+                if(bsFormulaChildInfo.getScanBarcode().contains(formulaChildInfo.getMaterialCode())) {
+                    bsFormulaChildInfos.add(formulaChildInfo);
+                    break;
+                }
             }
         }
         if(bsFormulaChildInfos.size()>0){
@@ -225,42 +229,44 @@
 ////                return AjaxResult.success("鎵弿鏈畬鎴愶紝绂佹鎷х揣鎿嶄綔锛�");
 //            }
 //        }
-        BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
-        listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
-        listQuery.setProcessesCode(bsFormulaChildInfo.getLocationCode());
-        String paramCode = bsFormulaChildInfo.getTightenTheArray();
-        if(paramCode.contains("N")){
+//        BsFormulaChildInfo listQuery = new BsFormulaChildInfo();
+//        listQuery.setParamCode(bsFormulaChildInfo.getParamCode());
+//        listQuery.setProcessesCode(bsFormulaChildInfo.getLocationCode());
+        String paramData = bsFormulaChildInfo.getTightenTheArray();
+        if(paramData.contains("N")){
             result = "3";
-            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
-            bsFormulaChildInfos.get(0).setResults("NG");
-            bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
-            bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
+//            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
+//            bsFormulaChildInfos.get(0).setResults("NG");
+//            bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
+//            bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
+            this.updateTighteningData(bsFormulaChildInfo,"NG",paramData);
 //            return AjaxResult.success("鎵弿缁撴灉NG,璇烽噸鏂版壂鎻忥紒");
         }else {
-            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
-            if(bsFormulaChildInfos.get(0).getSpareField2()!=null&&bsFormulaChildInfos.get(0).getSpareField3()!=null){
+//            List<BsFormulaChildInfo> bsFormulaChildInfos = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
+            if(bsFormulaChildInfo.getSpareField2()!=null&&bsFormulaChildInfo.getSpareField3()!=null){
                 String tightenArray = bsFormulaChildInfo.getTightenTheArray().replace("[", "").replace("]", "").replace(" ", "");
                 String[] tightenDataParts = tightenArray.split(",");
-                b = TimeUtil.isNumberInRange(Double.parseDouble(tightenDataParts[0]),Double.parseDouble(bsFormulaChildInfos.get(0).getSpareField2()),Double.parseDouble(bsFormulaChildInfos.get(0).getSpareField3()));
+                b = TimeUtil.isNumberInRange(Double.parseDouble(tightenDataParts[0]),Double.parseDouble(bsFormulaChildInfo.getSpareField2()),Double.parseDouble(bsFormulaChildInfo.getSpareField3()));
             }
             if(b){
                 result = "3";
-                bsFormulaChildInfos.get(0).setResults("OK");
-                bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
-                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
-                logger.info("yzUpdateTighteningFormula--鏌ヨ鏉′欢鍙傛暟锛�"+listQuery);
-                logger.info("yzUpdateTighteningFormula--鏌ヨ缁撴灉锛�"+bsFormulaChildInfos.get(0));
-                Integer stepNumber = Integer.valueOf(bsFormulaChildInfos.get(0).getStepSort());
+//                bsFormulaChildInfos.get(0).setResults("OK");
+//                bsFormulaChildInfos.get(0).setCollectData(bsFormulaChildInfo.getTightenTheArray());
+//                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos.get(0));
+                this.updateTighteningData(bsFormulaChildInfo,"OK",paramData);
+//                logger.info("yzUpdateTighteningFormula--鏌ヨ鏉′欢鍙傛暟锛�"+listQuery);
+//                logger.info("yzUpdateTighteningFormula--鏌ヨ缁撴灉锛�"+bsFormulaChildInfos.get(0));
+                Integer stepNumber = Integer.valueOf(bsFormulaChildInfo.getStepSort());
                 try {
                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier("PACK."+bsFormulaChildInfo.getLocationCode()+".MStepNumber").value(stepNumber+1).build());
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
 
-                String spareField4 = bsFormulaChildInfos.get(0).getSpareField4();
+                String spareField4 = bsFormulaChildInfo.getSpareField4();
                 if (spareField4 != null && !spareField4.isEmpty()) {
                     // 鎵ц鎿嶄綔
-                    if(bsFormulaChildInfos.get(0).getSpareField4().equals("1")){
+                    if(bsFormulaChildInfo.getSpareField4().equals("1")){
                         try {
 //                        WebSocketUsers.sendMessageToUserByText(map.get(bsFormulaChildInfo.getLocationCode()), "OUT");
                             result = "2";
@@ -271,16 +277,28 @@
                 }
             }else {
                 result = "3";
-                List<BsFormulaChildInfo> bsFormulaChildInfos1 = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
-                bsFormulaChildInfos1.get(0).setResults("NG");
-                String originalString = bsFormulaChildInfo.getTightenTheArray();
-                String modifiedString = originalString.replaceFirst("OK", "NG");
-                bsFormulaChildInfos1.get(0).setCollectData(modifiedString);
-                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos1.get(0));
+//                List<BsFormulaChildInfo> bsFormulaChildInfos1 = bsFormulaChildInfoMapper.selectBsFormulaChildInfoList(listQuery);
+//                bsFormulaChildInfos1.get(0).setResults("NG");
+//                String originalString = bsFormulaChildInfo.getTightenTheArray();
+                String modifiedString = paramData.replaceFirst("OK", "NG");
+//                bsFormulaChildInfos1.get(0).setCollectData(modifiedString);
+//                bsFormulaChildInfoMapper.updateBsFormulaChildInfo(bsFormulaChildInfos1.get(0));
+                this.updateTighteningData(bsFormulaChildInfo,"NG",modifiedString);
 //                return AjaxResult.success("鎵弿缁撴灉NG,璇烽噸鏂版壂鎻忥紒");
             }
         }
         return AjaxResult.success(result);
+    }
+
+    @Override
+    public AjaxResult updateTighteningData(BsFormulaChildInfo bsFormulaChildInfo,String result,String data) {
+        LambdaUpdateWrapper<BsFormulaChildInfo> updateWrapper = new LambdaUpdateWrapper();
+        updateWrapper.set(BsFormulaChildInfo::getCollectData, data);
+        updateWrapper.set(BsFormulaChildInfo::getResults, result);
+        updateWrapper.eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode());
+        updateWrapper.eq(BsFormulaChildInfo::getParamCode, bsFormulaChildInfo.getParamCode());
+        boolean update = bsFormulaChildInfoService.update(new BsFormulaChildInfo(), updateWrapper);
+        return AjaxResult.success(update);
     }
 
     @Override
@@ -334,14 +352,15 @@
 
     @Override
     public AjaxResult jrmWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
-        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
-                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
-                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
-        for (BsFormulaChildInfo info : list) {
-            info.setCollectData("");
-            info.setResults("");
-            bsFormulaChildInfoService.saveOrUpdate(info);
-        }
+        this.clearCollectDataAndResultsByProcessesCode(bsFormulaChildInfo);
+//        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
+//                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
+//                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
+//        for (BsFormulaChildInfo info : list) {
+//            info.setCollectData("");
+//            info.setResults("");
+//            bsFormulaChildInfoService.saveOrUpdate(info);
+//        }
         String[] split = bsFormulaChildInfo.getProductBarcode().split(",");
         try {
             for (int i = 0; i < split.length; i++) {
@@ -374,14 +393,15 @@
 
     @Override
     public AjaxResult clearWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
-        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
-                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
-                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
-        for (BsFormulaChildInfo info : list) {
-            info.setCollectData("");
-            info.setResults("");
-            bsFormulaChildInfoService.saveOrUpdate(info);
-        }
+//        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
+//                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
+//                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
+//        for (BsFormulaChildInfo info : list) {
+//            info.setCollectData("");
+//            info.setResults("");
+//            bsFormulaChildInfoService.saveOrUpdate(info);
+//        }
+        this.clearCollectDataAndResultsByProcessesCode(bsFormulaChildInfo);
         return AjaxResult.success();
     }
 
@@ -399,6 +419,17 @@
             }
         }
         return AjaxResult.success(result);
+    }
+
+    @Override
+    public AjaxResult clearCollectDataAndResultsByProcessesCode(BsFormulaChildInfo bsFormulaChildInfo) {
+        LambdaUpdateWrapper<BsFormulaChildInfo> updateWrapper = new LambdaUpdateWrapper();
+        updateWrapper.set(BsFormulaChildInfo::getCollectData, "");
+        updateWrapper.set(BsFormulaChildInfo::getResults,"");
+        updateWrapper.eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode());
+        BsFormulaChildInfo info = new BsFormulaChildInfo();
+        boolean update = this.update(info,updateWrapper);
+        return AjaxResult.success(update);
     }
 
     @Override
@@ -522,28 +553,29 @@
 
     @Override
     public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo) {
-        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
-                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
-                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
-        for (BsFormulaChildInfo info : list) {
-            info.setCollectData("");
-            info.setResults("");
-            bsFormulaChildInfoService.saveOrUpdate(info);
-        }
+        this.clearCollectDataAndResultsByProcessesCode(bsFormulaChildInfo);
+//        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
+//                .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getLocationCode())
+//                .eq(BsFormulaChildInfo::getProductCode, bsFormulaChildInfo.getProductCode()));
+//        for (BsFormulaChildInfo info : list) {
+//            info.setCollectData("");
+//            info.setResults("");
+//            bsFormulaChildInfoService.saveOrUpdate(info);
+//        }
         try {
             daParamCollectionService.pushGeelycvMesFeedback(bsFormulaChildInfo.getProductBarcode(), bsFormulaChildInfo.getLocationCode());
-            String barCode = bsFormulaChildInfo.getProductBarcode();
-            String locationCode = bsFormulaChildInfo.getLocationCode();
-
-            if(StringUtils.isNotBlank(locationCode)&&StringUtils.isNotBlank(barCode)){
-                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
-                daPassingStationCollection.setOutRsSign("1");
-                daPassingStationCollection.setOutboundTime(new Date());
-                daPassingStationCollection.setSfcCode(barCode);
-                daPassingStationCollection.setLocationCode(locationCode);
-                int updateDaPassingStation = daPassingStationCollectionService.updateDaPassingStationCollectionBySfcCodeAndLocationCode(daPassingStationCollection);
-                logger.info("鏅�氫汉宸ュ伐浣嶆洿鏂拌繃绔欒褰晆pdateDaPassingStationCollectionBySfcCodeAndLocationCode:鏇存柊浜唟}鏉℃暟鎹�-鏇存柊鏉′欢pack鐮亄}-宸ヤ綅{}",updateDaPassingStation,barCode,locationCode);
-            }
+//            String barCode = bsFormulaChildInfo.getProductBarcode();
+//            String locationCode = bsFormulaChildInfo.getLocationCode();
+//
+//            if(StringUtils.isNotBlank(locationCode)&&StringUtils.isNotBlank(barCode)){
+//                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
+//                daPassingStationCollection.setOutRsSign("1");
+//                daPassingStationCollection.setOutboundTime(new Date());
+//                daPassingStationCollection.setSfcCode(barCode);
+//                daPassingStationCollection.setLocationCode(locationCode);
+//                int updateDaPassingStation = daPassingStationCollectionService.updateDaPassingStationCollectionBySfcCodeAndLocationCode(daPassingStationCollection);
+//                logger.info("鏅�氫汉宸ュ伐浣嶆洿鏂拌繃绔欒褰晆pdateDaPassingStationCollectionBySfcCodeAndLocationCode:鏇存柊浜唟}鏉℃暟鎹�-鏇存柊鏉′欢pack鐮亄}-宸ヤ綅{}",updateDaPassingStation,barCode,locationCode);
+//            }
 
 //            DaPassingStationCollection passingStationCollectionOne = daPassingStationCollectionService.getOne(new LambdaQueryWrapper<DaPassingStationCollection>().eq(DaPassingStationCollection::getSfcCode, barCode).eq(DaPassingStationCollection::getLocationCode, locationCode));
 //            if (passingStationCollectionOne != null) {

--
Gitblit v1.9.3