From bdb4046a1ed5358a94cc9ce846f2a1ec88e5d5ec Mon Sep 17 00:00:00 2001
From: admin <15939171744@163.com>
Date: 星期二, 18 六月 2024 10:51:57 +0800
Subject: [PATCH] -

---
 jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java |  279 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 161 insertions(+), 118 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 1452680..52c039b 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
@@ -24,20 +24,28 @@
 import com.jcdm.main.plcserver.conf.OPCElement;
 import com.jcdm.main.plcserver.util.TimeUtil;
 import com.jcdm.main.restful.factoryMes.service.RestfulService;
+import com.jcdm.main.restful.qingYan.doman.ChildVO;
+import com.jcdm.main.restful.qingYan.doman.ParentVO;
 import com.kangaroohy.milo.model.ReadWriteEntity;
 import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
 import com.kangaroohy.milo.service.MiloService;
+import lombok.extern.slf4j.Slf4j;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.websocket.Session;
 import java.text.SimpleDateFormat;
+import java.time.Instant;
 import java.util.*;
 import java.util.stream.Collectors;
 
-
+@Slf4j
 @Component
 public class OPCUaSubscription implements SubscriptionCallback {
+
+    private static final Logger logger = LoggerFactory.getLogger("sys-user");
 
     public SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
@@ -98,6 +106,7 @@
     @Override
     public void onSubscribe(String identifier, Object value) {
 
+        logger.info("鍦板潃锛�"+identifier+"鍊硷細"+value);
         try {
             if(null != value && Integer.valueOf(value.toString())!= 0) {
                 String[] nodes = identifier.split("[.]");
@@ -172,10 +181,11 @@
                             }
                         }else {
                             //鎵嬪姩宸ヤ綅澶勭悊閫昏緫
-                            WebSocketUsers.sendMessageToUserByText(map.get(device), "IN");
-                            String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
-
-                            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build());
+//                            if (map.containsKey(device)){
+                                WebSocketUsers.sendMessageToUserByText(map.get(device), "IN");
+                                String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
+                                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(11).build());
+//                            }
                         }
 
 
@@ -183,10 +193,10 @@
                         if(automaticList.stream().anyMatch(s -> s.equals(device))){
                             //鑷姩宸ヤ綅
                             //鍑虹珯淇濆瓨鏁版嵁
-                            recordDataDoneValue = outSaveDate(thoroughfare,device);
+                            outSaveDate(thoroughfare,device);
                             //璁板綍鏁版嵁瀹屾垚
-                            String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
-                            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf(recordDataDoneValue)).build());
+                            /*String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
+                            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf(recordDataDoneValue)).build());*/
                         }else {
                             //鎵嬪姩宸ヤ綅
 //                            if(device.contains("OP330")){
@@ -197,6 +207,7 @@
 //                            }
                             if(testList.stream().anyMatch(s -> s.equals(device))){
                                 String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
+                                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
 //                                Object packCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + ".ModuleCode").getValue();
 //                                DaTestDeviceInterface deviceInterfaceOne = null;
 //
@@ -212,7 +223,7 @@
 //                                } else {
 //                                    writeToOpc(RecordDataDoneAddress, (short) 22);
 //                                }
-                                writeToOpc(RecordDataDoneAddress, (short) 21);
+//                                writeToOpc(RecordDataDoneAddress, (short) 21);
                             }
 
 
@@ -235,11 +246,15 @@
                         List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList());
                         String joinedString = String.join(",", collect.toString());
                         WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString));
+                        if(device.contains("270") || device.contains("260")){
+                            logger.info("璇诲彇鍒板伐浣峽}鐨凷caner鏁版嵁锛歿}",device,TightenTheConversionOkNg(joinedString));
+                        }
                     }
                 }
             }
         } catch (Exception e) {
-
+            logger.info("璁㈤槄鏂规硶鎶ラ敊:{}"+e.getMessage());
+            logger.error("璁㈤槄鏂规硶鎶ラ敊",e);
         }
     }
 
@@ -256,67 +271,67 @@
     /**
      * 鍑虹珯淇濆瓨鏁版嵁
      */
-    public String outSaveDate(String thoroughfare,String device) {
+    public void outSaveDate(String thoroughfare,String device) {
         String snCode = "";
         String result = "";
         String read = thoroughfare + "." + device + ".";
 
         try {
-            if(nullList.stream().noneMatch(s -> s.equals(device))){
+            if(nullList.stream().noneMatch(s -> s.equals(device))){//鍒犻櫎鈥︹�︹�︹�︹�︹�︹�︹�︹�︹�︹�︹�︹�︹�︹�︹�︹�︹�︹�︹��
                 if(moduleCodeList.stream().anyMatch(s -> s.equals(device))){
                     read = read + "ModuleCode";
-                    if(device.equals("OP365")){
-                        try {
-                            saveStationInfo365(thoroughfare,device);
-                        }catch (Exception e){
-                            e.printStackTrace();
-                        }
-                    }
                 }else {
                     read = read + "PACKCode";
                 }
             }
-            snCode = miloService.readFromOpcUa(read).getValue().toString();
-
-            if(null == snCode || "".equals(snCode)){
-                result = "22";
-            }else{
-
-                String workOrderNo = "";
-                String productCode = "";
-                //2銆佷繚瀛樿繃绔欓噰闆嗘暟鎹�
-                Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue();
-                if(orderNumberObject!=null){
-                    workOrderNo = orderNumberObject.toString();
-                }
-
-                Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue();
-                if(productCodeObject!=null){
-                    productCode = productCodeObject.toString();
-                }
-
-                saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode);
-                //3銆佷繚瀛樺弬鏁伴噰闆嗘暟鎹�
-                SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode);
-
-                //濡傛灉鏄湯灏惧伐绔欒鎶ュ伐
-                if(device.equals("OP500")){
-                    RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date()));
-                    //1銆佹洿鏂板伐鍗曚俊鎭�
-                    updateOrderInfo(snCode);
-                }
-                try{
-                    daParamCollectionService.pushGeelycvMesFeedback(snCode,device);
+            if(device.equals("OP365")){
+                try {
+                   saveStationInfo365(thoroughfare,device);
                 }catch (Exception e){
+                    e.printStackTrace();
                 }
-                result = "21";
+            }else {
+                snCode = miloService.readFromOpcUa(read).getValue().toString();
+
+                if(null == snCode || "".equals(snCode)){
+                    String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
+                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf("22")).build());
+                }else{
+
+                    String workOrderNo = "";
+                    String productCode = "";
+                    //2銆佷繚瀛樿繃绔欓噰闆嗘暟鎹�
+                    Object orderNumberObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "WorkOrderNumber").getValue();
+                    if(orderNumberObject!=null){
+                        workOrderNo = orderNumberObject.toString();
+                    }
+
+                    Object productCodeObject = miloService.readFromOpcUa(thoroughfare + "." + device + "." + "ProductType").getValue();
+                    if(productCodeObject!=null){
+                        productCode = productCodeObject.toString();
+                    }
+
+                    saveStationInfo(snCode,thoroughfare,device,workOrderNo,productCode);
+                    //3銆佷繚瀛樺弬鏁伴噰闆嗘暟鎹�
+                    List<DaParamCollection> daParamCollectionList = SaveParamData(snCode,thoroughfare,device,workOrderNo,productCode);
+
+                    //濡傛灉鏄湯灏惧伐绔欒鎶ュ伐
+                    if(device.equals("OP500")){
+                        RestfulService.getWorkReportResultFeedback(snCode,device,format.format(new Date()));
+                        //1銆佹洿鏂板伐鍗曚俊鎭�
+                        updateOrderInfo(snCode);
+                    }
+
+                    try{
+                        daParamCollectionService.automaticWorkstationPushGeelycvMesFeedback(snCode,device,daParamCollectionList);
+                    }catch (Exception e){
+                    }
+                }
 
             }
-
         }catch (Exception e) {
-            System.out.println(e.getMessage());
+            logger.error("鍑虹珯淇濆瓨鏁版嵁寮傚父锛�"+e);
         }
-        return result;
     }
 
 
@@ -354,6 +369,7 @@
      * 淇濆瓨杩囩珯閲囬泦
      */
     public void saveStationInfo(String packCode,String thoroughfare,String device,String workOrderNo,String productCode) throws Exception {
+        logger.info("杩涘叆宸ヤ綅{}-鏂规硶saveStationInfo",device);
         SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
         sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); // CST閫氬父琛ㄧず涓浗鏍囧噯鏃堕棿锛屽嵆涓滃叓鍖�
         String prefix = thoroughfare+"."+device+".";
@@ -372,13 +388,16 @@
         daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//鍑虹珯鏃堕棿
         daPassingStationCollection.setOutRsSign(stationStatus);//鍑虹珯鏄惁鍚堟牸
         daPassingStationCollectionService.insertDaPassingStationCollection(daPassingStationCollection);
+        logger.info("缁撴潫宸ヤ綅{}-鏂规硶saveStationInfo",device);
     }
 
-    public static void SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception {
+    public static List<DaParamCollection> SaveParamData(String packCode,String thoroughfare,String device,String workOrderNo,String productType) throws Exception {
+        logger.info("杩涘叆宸ヤ綅{}-鏂规硶SaveParamData",device);
         List<DaCollectionParamConf> list;
         DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
         daCollectionParamConf.setGatherAddress(thoroughfare+ "." + device);
         list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
+        List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
 
         List<String> nodeIdList = list.stream().map(info -> {
             String nodeid = info.getGatherAddress();
@@ -387,53 +406,51 @@
 
         if(!nodeIdList.isEmpty()){
             List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
-            for (int i = 0; i < readWriteEntityList.size(); i++) {
+            for(int i=0;i<nodeIdList.size();i++){
                 if(readWriteEntityList.get(i).getValue() == null){
                     readWriteEntityList.get(i).setValue(" ");
                 }
-            }
-            List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
-            for(int i=0;i<nodeIdList.size();i++){
-                if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){
-                    String tt = readWriteEntityList.get(i).getValue().toString();
-                    DaParamCollection ParamCollection = new DaParamCollection();
-                    ParamCollection.setParamCode(list.get(i).getCollectParameterId());
-                    ParamCollection.setLocationCode(device);
-                    if(tt.contains("Time")){
-//                        String str = TimeUtil.getTimestamp(TimeUtil.stringProcessing(tt));
-//                        ParamCollection.setParamValue(str);
-                        ParamCollection.setParamValue(TimeUtil.test(TimeUtil.stringProcessing(tt)));
-                    }else {
-                        ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
-                    }
-                    ParamCollection.setSfcCode(packCode);
-                    if(device.contains("OP360")){
-                        String node = nodeIdList.get(i);
-                        Object value = miloService.readFromOpcUa("PACK.OP360.ModuleSNCode"+node.charAt(node.length()-1)).getValue();
-                        if(value!=null){
-                            ParamCollection.setModuleCode(value.toString());
-                        }
-                    }
-                    ParamCollection.setParamName(list.get(i).getCollectParameterName());
-                    ParamCollection.setParamUpper(list.get(i).getParamUpper());
-                    ParamCollection.setParamLower(list.get(i).getParamLower());
-                    ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
-                    //ParamCollection.setState("鍚堟牸");
-                    ParamCollection.setType(list.get(i).getCollectParameterType());
-                    ParamCollection.setCollectionTime(new Date());
-                    ParamCollection.setWorkOrderNo(workOrderNo);
-                    ParamCollection.setProductCode(productType);
-                    daParamCollectionlist.add(ParamCollection);
-//                    daParamCollectionService.insertDaParamCollection(ParamCollection);
+                String paramValue = readWriteEntityList.get(i).getValue().toString();
+                DaParamCollection ParamCollection = new DaParamCollection();
+                ParamCollection.setParamCode(list.get(i).getCollectParameterId());
+                ParamCollection.setLocationCode(device);
+                if(paramValue.contains("Time")){
+                    ParamCollection.setParamValue(TimeUtil.test(TimeUtil.stringProcessing(paramValue)));
+                }else {
+                    ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
                 }
+                ParamCollection.setSfcCode(packCode);
+                if(device.contains("OP360")){
+                    String node = nodeIdList.get(i);
+                    Object value = miloService.readFromOpcUa("PACK.OP360.ModuleSNCode"+node.charAt(node.length()-1)).getValue();
+                    if(value!=null){
+                        ParamCollection.setModuleCode(value.toString());
+                    }
+                }
+                ParamCollection.setParamName(list.get(i).getCollectParameterName());
+                ParamCollection.setParamUpper(list.get(i).getParamUpper());
+                ParamCollection.setParamLower(list.get(i).getParamLower());
+                ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
+                ParamCollection.setType(list.get(i).getCollectParameterType());
+                ParamCollection.setCollectionTime(new Date());
+                ParamCollection.setWorkOrderNo(workOrderNo);
+                ParamCollection.setProductCode(productType);
+                daParamCollectionlist.add(ParamCollection);
             }
-            daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
         }
-        addBaseData(workOrderNo,productType,device,packCode);
-
+        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
+        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(Integer.valueOf("21")).build());
+        logger.info("缁欏伐浣峽}鍐欎簡21",device);
+        daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
+        List<DaParamCollection> baseDataList = addBaseData(workOrderNo,productType,device,packCode);
+        for (int i = 0; i < baseDataList.size(); i++){
+            daParamCollectionlist.add(baseDataList.get(i));
+        }
+        logger.info("缁撴潫宸ヤ綅{}-鏂规硶SaveParamData",device);
+        return daParamCollectionlist;
     }
 
-    public static void addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){
+    public static List<DaParamCollection> addBaseData(String workOrderNo,String productCode,String locationCode,String packCode){
         Map<String, String> map = new HashMap<>();
         map.put("GC", "鍗楁禂宸ュ巶");
         map.put("CXBH", "Pack绾�");
@@ -456,6 +473,7 @@
             confList.add(saveData);
         });
         daParamCollectionService.insertBatch(confList);
+        return confList;
     }
 
     public static void getFactoryOrder(String locationCode){
@@ -500,13 +518,22 @@
             try {
                 value = Float.parseFloat(part); // 灏濊瘯灏嗗瓧绗︿覆杞崲涓烘诞鐐规暟
                 String replacement;
-                if (value == 1f) {
+                if(i<2){
+                    replacement = part;
+                }else{
+                    if (value == 1f) {
+                        replacement = "OK";
+                    } else{
+                        replacement = "NG";
+                    }
+                }
+            /*    if (value == 1f) {
                     replacement = "OK";
                 } else if (value == 2f) {
                     replacement = "NG";
                 } else {
                     replacement = part; // 濡傛灉涓嶆槸1鎴�2锛屽垯淇濇寔涓嶅彉
-                }
+                }*/
                 sb.append(replacement);
                 if (i < parts.length - 1) {
                     sb.append(','); // 娣诲姞閫楀彿锛堥櫎浜嗘渶鍚庝竴涓厓绱狅級
@@ -540,32 +567,48 @@
      * 淇濆瓨杩囩珯閲囬泦
      */
     public void saveStationInfo365(String thoroughfare,String device) throws Exception {
+        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
         String prefix = thoroughfare+"."+device+".";
         List<DaPassingStationCollection> passingStationCollections = new ArrayList<>();
-        String ModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue().toString();
-        String ModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue().toString();
-        String StationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue().toString();
-        String StationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue().toString();
-        String[] modeles = {ModuleCodeA,ModuleCodeB};
-        String[] StationStatus = {StationStatusA,StationStatusB};
+        String ModuleCodeA = "";
+        String ModuleCodeB = "";
+        String StationStatusA = "";
+        String StationStatusB = "";
 
-        String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString();
-        String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString();
-        for (int i = 0; i < 2; i++) {
-            DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
-            String strt = TimeUtil.stringProcessing(startTime);
-            String end = TimeUtil.stringProcessing(stopTime);
-            daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//鍏ョ珯鏃堕棿
-            daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//鍑虹珯鏃堕棿
-            daPassingStationCollection.setSfcCode(modeles[i]);
-            daPassingStationCollection.setLocationCode(device);
-            daPassingStationCollection.setOutRsSign(StationStatus[i]);//鍑虹珯鏄惁鍚堟牸
-            passingStationCollections.add(daPassingStationCollection);
+        Object objectModuleCodeA = miloService.readFromOpcUa(prefix + "ModuleCodeA").getValue();
+        Object objectModuleCodeB = miloService.readFromOpcUa(prefix + "ModuleCodeB").getValue();
+        Object objectStationStatusA = miloService.readFromOpcUa(prefix + "StationStatusA").getValue();
+        Object objectStationStatusB = miloService.readFromOpcUa(prefix + "StationStatusB").getValue();
+
+        if(ObjectUtil.isNotNull(objectModuleCodeA) && ObjectUtil.isNotNull(objectStationStatusA) && ObjectUtil.isNotNull(objectModuleCodeB) && ObjectUtil.isNotNull(objectStationStatusB)){
+            ModuleCodeA = objectModuleCodeA.toString();
+            ModuleCodeB = objectModuleCodeB.toString();
+            StationStatusA = objectStationStatusA.toString();
+            StationStatusB = objectStationStatusB.toString();
+
+            String[] modeles = {ModuleCodeA,ModuleCodeB};
+            String[] StationStatus = {StationStatusA,StationStatusB};
+
+            String startTime = miloService.readFromOpcUa(prefix + "StartTime").getValue().toString();
+            String stopTime = miloService.readFromOpcUa(prefix + "StopTime").getValue().toString();
+            for (int i = 0; i < 2; i++) {
+                DaPassingStationCollection daPassingStationCollection = new DaPassingStationCollection();
+                String strt = TimeUtil.stringProcessing(startTime);
+                String end = TimeUtil.stringProcessing(stopTime);
+                daPassingStationCollection.setInboundTime(format.parse(TimeUtil.test(strt)));//鍏ョ珯鏃堕棿
+                daPassingStationCollection.setOutboundTime(format.parse(TimeUtil.test(end)));//鍑虹珯鏃堕棿
+                daPassingStationCollection.setSfcCode(modeles[i]);
+                daPassingStationCollection.setLocationCode(device);
+                daPassingStationCollection.setOutRsSign(StationStatus[i]);//鍑虹珯鏄惁鍚堟牸
+                passingStationCollections.add(daPassingStationCollection);
+            }
+            daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections);
+            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
+            logger.info("宸ヤ綅{}鍥炲21",device);
+
+        }else {
+            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(22).build());
         }
-        daPassingStationCollectionService.saveBeachDaPassingStationCollection(passingStationCollections);
-        String RecordDataDoneAddress = thoroughfare + "." + device + ".RecordDataDone";
-        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(RecordDataDoneAddress).value(21).build());
-        return;
     }
 
     private static void writeToOpc(String identifier, short value) {

--
Gitblit v1.9.3