From 18cb51817380016c4024f9f462ea91b57bfa40f9 Mon Sep 17 00:00:00 2001
From: admin <15939171744@163.com>
Date: 星期五, 07 三月 2025 18:39:37 +0800
Subject: [PATCH] -工单物料配置表

---
 jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java |  163 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 134 insertions(+), 29 deletions(-)

diff --git a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
index 9001f14..1de8f5d 100644
--- a/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
+++ b/jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java
@@ -9,6 +9,7 @@
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.jcdm.common.core.domain.AjaxResult;
 import com.jcdm.framework.websocket.WebSocketUsers;
 import com.jcdm.main.constant.Constants;
@@ -20,6 +21,8 @@
 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
+import com.jcdm.main.da.psConf.domain.DaPsConf;
+import com.jcdm.main.da.psConf.service.IDaPsConfService;
 import com.jcdm.main.da.testDeviceInterfaceTemp.domain.DaTestDeviceInterfaceTemp;
 import com.jcdm.main.da.testDeviceInterfaceTemp.service.IDaTestDeviceInterfaceTempService;
 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
@@ -32,12 +35,14 @@
 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
 import com.kangaroohy.milo.service.MiloService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.annotation.GetMapping;
 
 import javax.websocket.Session;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
@@ -65,7 +70,7 @@
     public static IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService;
 
     public static IDaCellDataService daCellDataService;
-
+    public static IDaPsConfService daPsConfService;
 /*    @Value("${orderLineUrl}")
     private static String orderLineUrl;*/
 
@@ -75,7 +80,8 @@
                              IDaParamCollectionService daParamCollectionService,
                              IOmProductionOrdeInfoService omProductionOrdeInfoService,
                              IDaTestDeviceInterfaceTempService daTestDeviceInterfaceTempService,
-                             IDaCellDataService daCellDataService) {
+                             IDaCellDataService daCellDataService,
+                             IDaPsConfService daPsConfService) {
         OPCUaSubscription.miloService = miloService;
         OPCUaSubscription.daPassingStationCollectionService = daPassingStationCollectionService;
         OPCUaSubscription.collectionParamConfService = collectionParamConfService;
@@ -83,6 +89,7 @@
         OPCUaSubscription.omProductionOrdeInfoService = omProductionOrdeInfoService;
         OPCUaSubscription.daTestDeviceInterfaceTempService = daTestDeviceInterfaceTempService;
         OPCUaSubscription.daCellDataService = daCellDataService;
+        OPCUaSubscription.daPsConfService = daPsConfService;
     }
 
 
@@ -114,16 +121,22 @@
                     Integer scanResult = 11;
                     if (Constants.OP010.equals(device)){
                         //OP010宸ヤ綅鐢佃姱鏉$爜鏍¢獙||OP030宸ヤ綅鐢佃姱鏉$爜鏍¢獙
-                        Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Scaner").getValue();
-                        if (ObjectUtil.isNotNull(value1)){
-                            String keyCode = value1.toString();
-                            log.info("璇诲彇鍒板伐浣峽}鐨凷caner鏁版嵁锛歿}",device,keyCode);
-                            //浠呮牎楠岄暱搴︽槸鍚﹀悎鏍�
-//                                List<KeyCodeCheck> collect = keyCodeCheckService.list().stream().filter(x -> x.getKeyCode().contains(keyCode)).collect(Collectors.toList());
-//                                if (CollUtil.isNotEmpty(collect)){
-//                                    scanResult = 11;
-//                                }
-                        }
+                        //鐢佃姱鎵规鏍¢獙
+//                        Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Scaner").getValue();
+//                        Object value2 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Batch").getValue();
+//                        if (ObjectUtil.isNotNull(value1)&&ObjectUtil.isNotNull(value2)){
+//                            String keyCode = value1.toString();
+//                            String batch = value2.toString();
+//                            log.info("璇诲彇鍒板伐浣峽}鐨凷caner鏁版嵁锛歿} 鏍¢獙鎵规涓猴細{}",device,keyCode,batch);
+//                            //浠呮牎楠岄暱搴︽槸鍚﹀悎鏍�
+////                                List<KeyCodeCheck> collect = keyCodeCheckService.list().stream().filter(x -> x.getKeyCode().contains(keyCode)).collect(Collectors.toList());
+////                                if (CollUtil.isNotEmpty(collect)){
+////                                    scanResult = 11;
+////                                }
+//                            scanResult = batchVerification(keyCode,batch);
+//                        }else {
+//                            scanResult = 12;
+//                        }
                     }else if(Constants.OP030.equals(device)){
                         Object value1 = miloService.readFromOpcUa(thoroughfare + "." + device + ".Scaner").getValue();//鐢佃姱鐮�
                         if (ObjectUtil.isNotNull(value1)){
@@ -154,14 +167,15 @@
                     //OP020 鐢佃姱鎸′綅鏍¢獙
                     if (Constants.OP020.equals(device)){
                         Integer result = 11;
-                        Object cellGearObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellGear").getValue();
-                        if (ObjectUtil.isNull(cellGearObjcet)){
-                            result = 16;//鐢佃姱鎸′綅涓虹┖
-                        }else{
-                            String cellGear = cellGearObjcet.toString();
-                            /*List<String> cellCodeList = readCellCodeList(thoroughfare, device);
-                            result = checkCellGear(thoroughfare, device,cellCodeList,cellGear);//鏍¢獙鐢佃姱鎸′綅鍜岀粍鍒�*/
-                        }
+//                        Object cellGearObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".CellGear").getValue();
+//                        if (ObjectUtil.isNull(cellGearObjcet)){
+//                            result = 11;//濡傛灉鐢佃姱鎸′綅涓虹┖锛屼笉杩涜鎸′綅鏍¢獙
+//                        }else{
+//                            String cellGear = cellGearObjcet.toString();
+//                            List<String> cellCodeList = readCellCodeList(thoroughfare, device);
+//                            result = checkCellGear(thoroughfare, device,cellCodeList,cellGear);//鏍¢獙鐢佃姱鎸′綅鍜岀粍鍒�
+//                            Constants.OLD_CELL_GEAR = cellGear;//鎸′綅璧嬪��
+//                        }
                         miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(result).build());
 
                     }else if (Constants.OP030.equals(device)){
@@ -238,7 +252,7 @@
                                 return;
                             }
 
-                            result = savePassingStation(thoroughfare, device,cellCodeList);//淇濆瓨杩囩珯
+                            //result = savePassingStation(thoroughfare, device,cellCodeList);//淇濆瓨杩囩珯
                             if(result == 21) {
                                 if(Constants.OP020.contains(device)){
                                     if(!cellCode1.isEmpty()){
@@ -287,7 +301,7 @@
                             Object stationStatusObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".StationStatus").getValue();//绔欑姸鎬佸湴鍧�
                             if (ObjectUtil.isNotNull(stationStatusObjcet)){
                                 String stationStatus = stationStatusObjcet.toString();
-                                result = savePassingStation(thoroughfare, device,moduleCode,stationStatus);//淇濆瓨杩囩珯
+                                //result = savePassingStation(thoroughfare, device,moduleCode,stationStatus);//淇濆瓨杩囩珯
                                 if(result == 21) {
                                     result = saveParamCollection(device,moduleCode,stationStatus);//淇濆瓨鍙傛暟锛屽彂閫佸伐鍘侻ES
                                 }
@@ -857,7 +871,7 @@
      */
     private Integer checkCellGear(String thoroughfare, String device,List<String> cellCodeList,String cellGear) throws Exception {
         Integer result = 11;
-
+        String cellSerial = "";
         for(int i = 0; i < cellCodeList.size(); i ++){
             Integer cellStatus = 1;
             String cellCode = cellCodeList.get(i);
@@ -867,20 +881,31 @@
                 if(CollUtil.isNotEmpty(list)){
                     DaCellData daCellData = list.get(0);
                     String cellValue = daCellData.getCellValue();//鏁版嵁搴撲腑鐢佃姱鎸′綅
-                    String cellSerial = daCellData.getCellSerial();//鏁版嵁搴撲腑鐢佃姱缁勫埆
+                    cellSerial = daCellData.getCellSerial();//鏁版嵁搴撲腑鐢佃姱缁勫埆
                     if(!cellValue.isEmpty() && cellValue.equals(cellGear)){
                         cellStatus = 1;
                     }else {
                         cellStatus = 2;
-                        result = 17;//鎸′綅鏍¢獙涓嶅悎鏍�
+                        result = 16;//鎸′綅鏍¢獙涓嶅悎鏍�
+                        log.info("鐢佃姱鎸′綅鏍¢獙涓嶅悎鏍硷細鐢佃姱鐮佷负{}锛孭LC璁剧疆鎸′綅涓簕}锛屽伐鍘侻ES涓嬪彂鎸′綅涓猴細{}",cellCode,cellGear,cellValue);
                     }
                 }else {
                     cellStatus = 2;
-                    result = 17;//鏌ヤ笉鍒拌鏍¢獙鐨勬尅浣�
+                    result = 16;//鏌ヤ笉鍒拌鏍¢獙鐨勬尅浣�
+                    log.info("鐢佃姱鎸′綅鏍¢獙涓嶅悎鏍硷細鐢佃姱鐮佷负{}锛孭LC璁剧疆鎸′綅涓簕}锛屽伐鍘侻ES涓嬪彂鎸′綅涓虹┖锛屾煡璇笉鍒拌鏁版嵁",cellCode,cellGear);
                 }
-                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".CellStatus_"+(i+1)).value(cellStatus).build());
+                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".Cell_Status_"+(i+1)).value(cellStatus).build());
             }
         }
+
+        //褰撶數鑺尅浣嶅彂鐢熷彉鍖栨椂锛屽苟涓旇�佺殑鎸′綅涓嶄负绌猴紝鍒犻櫎褰撳墠鐢佃姱鎵规
+        if(!Constants.OLD_CELL_GEAR.isEmpty() && !cellGear.equals(Constants.OLD_CELL_GEAR)){
+            if(!cellSerial.isEmpty()){
+                daCellDataService.deleteDaCellDataByCellSerial(cellSerial);
+            }
+            log.info("鐢佃姱鎸′綅鍙戠敓鏀瑰彉锛岃�佺殑鎸′綅涓猴細{}锛屾柊鐨勬尅浣嶄负锛歿}锛屾壒娆″彿涓簕}",Constants.OLD_CELL_GEAR,cellGear,cellSerial);
+        }
+
         return result;
     }
 
@@ -1040,14 +1065,21 @@
     public static String getWorkReportResultFeedback(String productNum,String stationCode,String confirmTime)
     {
         String result = "";
+        String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime;
         try {
-            String url = Constants.FACTORY_EMS_UAT_GET_RUL + "workReportResultFeedback?siteCode="+Constants.FACTORY_EMS_SITE_CODE+"&stationCode="+stationCode+"&productNum="+productNum+"&confirmTime="+confirmTime;
+            log.info("鎵ц宸ュ巶MES鎶ュ伐鏂规硶start锛屽簭鍒楀彿{}宸ヤ綅鍙穥}url{}",productNum,stationCode ,url);
             HttpResponse response = HttpRequest.get(url).execute();
-            HttpRequest httpRequest = HttpRequest.get(url);
+            //HttpRequest httpRequest = HttpRequest.get(url);
             result =  response.body();
+            log.info("鎵ц宸ュ巶MES鎶ュ伐鏂规硶绗竴娆nd锛屽簭鍒楀彿{}宸ヤ綅鍙穥}杩斿洖鏁版嵁{}",productNum,stationCode ,result);
         }catch (Exception e){
             throw new RuntimeException(e);
         }finally {
+            if(result.isEmpty()){
+                HttpResponse response = HttpRequest.get(url).execute();
+                result =  response.body();
+                log.info("鎵ц宸ュ巶MES鎶ュ伐鏂规硶绗簩娆nd锛屽簭鍒楀彿{}宸ヤ綅鍙穥}杩斿洖鏁版嵁{}",productNum,stationCode ,result);
+            }
             return result;
         }
     }
@@ -1070,6 +1102,11 @@
             );
             if (CollUtil.isNotEmpty(list)){
                 for(DaCollectionParamConf conf:list){
+                    //1P1S鐢熸垚
+                    if("1P1S".equals(conf.getCollectParameterId())){
+                        String result = get1P1S(sfcCode);
+                        conf.setParamCentral(result);
+                    }
                     ChildVO childVO = new ChildVO();
                     childVO.setItemCode(conf.getCollectParameterId());//鍙傛暟
                     childVO.setItemType(conf.getItemType());
@@ -1096,7 +1133,75 @@
             throw new RuntimeException(e);
         }
     }
+    /**
+     * 鐢熸垚1P1S鐮�
+     * @param sfcCode
+     * @return list
+     */
+    public static String get1P1S(String sfcCode) {
+        String result = "";
+        LocalDate now = LocalDate.now();
+        String supplierCode  = sfcCode.substring(0,3);
+        try {
+            List<DaPsConf> list = daPsConfService.list(new LambdaQueryWrapper<DaPsConf>()
+                    .eq(DaPsConf::getSpareField1, supplierCode)//渚涘簲鍟嗚瘑鍒爜
+                    .eq(DaPsConf::getState,"1"));//鐘舵��
+            if(!list.isEmpty()){
+                String mfCode = list.get(0).getMfCode();//鍘傚晢浠g爜
+                String proTypeCode = list.get(0).getProTypeCode();//浜у搧绫诲瀷浠g爜
+                String batteryTypeCode = list.get(0).getBatteryTypeCode();//鐢垫睜绫诲瀷浠g爜
+                String specificationsCode = list.get(0).getSpecificationsCode();//瑙勬牸浠g爜
+                String traceInfoCode = list.get(0).getTraceInfoCode();//杩芥函淇℃伅浠g爜
+                String oldDateCode = list.get(0).getProDateCode();
+                String proDateCode = Constants.YEARSMAP.get(now.getYear())
+                        + Constants.MONTHSMAP.get(now.getMonthValue())
+                        + Constants.DAYMAP.get(now.getDayOfMonth());//鐢熶骇鏃ユ湡
 
+                String code = "";
+                if(oldDateCode.equals(proDateCode)){
+                    code = list.get(0).getSfcCode();//搴忓垪鍙�
+                }else {
+                    code = "0";
+                }
+                code = StringUtils.leftPad(String.valueOf(Integer.valueOf(code)+1),7, "0");;//搴忓垪鍙�
+                result = mfCode+proTypeCode+batteryTypeCode+specificationsCode+traceInfoCode+proDateCode+code;
+
+                log.info("璇诲彇鍒扮數鑺爜涓猴細{},1P1S鐮佷负锛歿}",sfcCode,result);
+
+                //鏇存柊鏃ユ湡鍜屽簭鍒楀彿
+                LambdaUpdateWrapper<DaPsConf> lambdaUpdateWrapper = new LambdaUpdateWrapper<DaPsConf>();
+                lambdaUpdateWrapper.set(DaPsConf::getProDateCode,proDateCode);//鐢熶骇鏃ユ湡
+                lambdaUpdateWrapper.set(DaPsConf::getSfcCode,code);//搴忓垪鍙�
+                lambdaUpdateWrapper.eq(DaPsConf::getSpareField1,supplierCode);//渚涘簲鍟嗚瘑鍒爜
+                lambdaUpdateWrapper.eq(DaPsConf::getState,"1");//鐘舵��
+                daPsConfService.update(lambdaUpdateWrapper);
+
+            }else{
+                log.info("璇峰厛鍘�1P1S閰嶇疆椤甸潰閰嶇疆瑙勫垯!");
+            }
+            return result;
+        }catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * 鎵规鏍¢獙
+     * @param keyCode,batch
+     * @return list
+     */
+    public Integer batchVerification(String keyCode,String batch){
+        Integer result = 11;
+        List<DaCellData> cellDataList = daCellDataService.list(new LambdaQueryWrapper<DaCellData>()
+                .eq(DaCellData::getGbCellCode, keyCode)
+                .eq(DaCellData::getCellSerial, batch)
+        );
+        if(cellDataList.isEmpty()){
+            result = 13;
+            log.info("鐢佃姱鐮亄} 宸ヤ綅010鏍¢獙鎵规澶辫触锛氭壒娆′负{}",keyCode,batch);
+        }
+        return result;
+    }
 
 
 }

--
Gitblit v1.9.3