From f3862f0f7387f97e642167c5cda98f7e10fc3065 Mon Sep 17 00:00:00 2001
From: cl <418351270@qq.com>
Date: 星期四, 01 八月 2024 08:20:52 +0800
Subject: [PATCH] 修改采集参数

---
 jcdm-main/src/main/java/com/jcdm/main/plcserver/sub/OPCUaSubscription.java |   65 +++++++++++++++++++++++++++++++-
 1 files changed, 62 insertions(+), 3 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 60c0d5a..b6b30da 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
@@ -104,6 +104,7 @@
             if (Constants.RECORD_DATA.equals(tab)) {  //鍑哄叆绔�
                 if (Constants.ONE.equals(valueString)) {//鍏ョ珯
                     Integer recordDataDone = 11;
+                    miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StartTime").value(new Date()).build());
                     miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build());
                 } else if(Constants.TWO.equals(valueString)){//鍑虹珯
                     Integer result = 21;
@@ -135,7 +136,6 @@
                 }
             }else if (Constants.RECORD_SN.equals(tab)){//璇锋眰浜у搧搴忓垪鍙�
                 if (Constants.ONE.equals(valueString)){
-                    Integer result = 11;
                     //杩涚珯PLC缁欎骇鍝佺被鍨嬶紝MES璇诲彇浜у搧绫诲瀷
                     Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//浜у搧绫诲瀷
                     if (ObjectUtil.isNotNull(productTypeObjcet)){
@@ -146,10 +146,22 @@
                             receivingWorkOrders(thoroughfare, device,materialCode);
                         });
                     }else{
-                        result = 12;
+                        miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(12).build());
                     }
-                    miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(result).build());
+
                 }
+            }else if(Constants.SCREW.equals(tab)){
+                List<String> list = new ArrayList<>();
+                String[] suffixes = {"Torque", "Angle", "TorqueResult", "AngleResult"};
+
+                for (String suffix : suffixes) {
+                    String string = thoroughfare + "." + device + "." + suffix;
+                    list.add(string);
+                }
+                List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list);
+                List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList());
+                String joinedString = String.join(",", collect.toString());
+                WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString));
             }
         }catch (Exception e) {
             log.error(e.getMessage());
@@ -334,6 +346,7 @@
             if(!productNum.isEmpty() && !orderNum.isEmpty()){
                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build());
                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build());
+                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(11).build());
             }
 
         } catch (Exception e) {
@@ -384,4 +397,50 @@
             throw new RuntimeException(e);
         }
     }
+
+    public static String TightenTheConversionOkNg(String param){
+        // 鍘婚櫎棣栧熬鐨勬柟鎷彿锛岀劧鍚庢寜鐓ч�楀彿鍒嗗壊瀛楃涓�
+        String[] parts = param.substring(1, param.length() - 1).split(",");
+
+        // 鍒涘缓涓�涓柊鐨凷tringBuilder鏉ユ瀯寤烘浛鎹㈠悗鐨勫瓧绗︿覆
+        StringBuilder sb = new StringBuilder();
+        sb.append('['); // 娣诲姞宸︽柟鎷彿
+
+        for (int i = 0; i < parts.length; i++) {
+            String part = parts[i].trim(); // 鍘婚櫎鍙兘鐨勭┖鏍�
+            float value;
+            try {
+                value = Float.parseFloat(part); // 灏濊瘯灏嗗瓧绗︿覆杞崲涓烘诞鐐规暟
+                String replacement;
+                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(','); // 娣诲姞閫楀彿锛堥櫎浜嗘渶鍚庝竴涓厓绱狅級
+                }
+            } catch (NumberFormatException e) {
+                // 濡傛灉杞崲澶辫触锛屽垯淇濇寔鍘熸牱锛堟垨杩涜鍏朵粬閿欒澶勭悊锛�
+                sb.append(part);
+                if (i < parts.length - 1) {
+                    sb.append(',');
+                }
+            }
+        }
+        sb.append(']'); // 娣诲姞鍙虫柟鎷彿
+        return sb.toString();
+    }
 }

--
Gitblit v1.9.3