From 28cd73a27061f684feda88d2d3e5f26794bbd591 Mon Sep 17 00:00:00 2001 From: yyt <306727702@qq.com> Date: 星期二, 23 一月 2024 10:28:14 +0800 Subject: [PATCH] 更新OPCUA --- jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java | 38 ++++++++++++++++++-------------------- 1 files changed, 18 insertions(+), 20 deletions(-) diff --git a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java index ec82a91..9189ab9 100644 --- a/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java +++ b/jcdm-main/src/main/java/com/jcdm/main/da/opcuaconfig/cert/MethodName.java @@ -6,6 +6,7 @@ import com.jcdm.main.da.opcuaconfig.domain.NodeEntity; import com.jcdm.main.da.opcuaconfig.init.BeanUtils; import com.jcdm.main.da.paramCollection.domain.DaParamCollection; +import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; import lombok.extern.slf4j.Slf4j; import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; @@ -18,6 +19,8 @@ @Slf4j public class MethodName { private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class); + private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class); + private List<DataValue> s=null; public void getSn(String Node, String value) throws Exception { log.info(Node+":"+value); String[] parts = Node.split("[.]"); @@ -38,17 +41,21 @@ DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf(); daCollectionParamConf.setCollectParameterId(parts[0]+"."+parts[1]); b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); - List<String> ids = b.stream().map(e -> e.getCollectParameterId()).collect(Collectors.toList()); - Set<String> de=ListToSet(ids); - List<DataValue> s=readValues(de); -// s.forEach(element->{ -// DaParamCollection Config=new DaParamCollection(); -// String[] q = element.getIdentifier().split("[.]"); -// Config.setParamCode(q[2]); -// Config.setLocationCode(q[1]); -// Config.setParamValue(element.getValue().toString()); -// daParamCollectionService.insertDaParamCollection(Config); -// }); + + List<NodeId> nodeId = b.stream().map(info -> { + NodeId nodeid = new NodeId(2,info.getCollectParameterId()); + return nodeid; + }).collect(Collectors.toList()); + List<DataValue> s=readValues(nodeId); + + for(int i=0;i<nodeId.size();i++) + { + DaParamCollection Config=new DaParamCollection(); + Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]); + Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]); + Config.setParamValue(s.get(i).getValue().getValue().toString()); + daParamCollectionService.insertDaParamCollection(Config); + } NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build(); Boolean out2=clientHandler.write(node2); log.info("鑺傜偣:{},鍝嶅簲缁撴灉:{}", node2.getIdentifier(),out2); @@ -56,14 +63,5 @@ default: break; } - } - - public Set<String> ListToSet(List<String> list) { - Object[] objects = list.toArray();// 杩斿洖Object鏁扮粍 - String[] strings1 = new String[list.size()]; - list.toArray(strings1);// 灏嗚浆鍖栧悗鐨勬暟缁勬斁鍏ュ凡缁忓垱寤哄ソ鐨勫璞′腑 - String[] strings2 = list.toArray(new String[0]);// 灏嗚浆鍖栧悗鐨勬暟缁勮祴缁欐柊瀵硅薄 - Set<String> set = new HashSet<String>(Arrays.asList(strings2)); - return set; } } -- Gitblit v1.9.3