春风项目四线(合箱线、总装线)
wujian
2024-01-18 83923ea389a172c1cf3d9cd7a3628d3692e9feaf
提交 | 用户 | 时间
e4c3b0 1 package com.jcdm.main.da.opcuaconfig.cert;
Y 2
3 import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
4 import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
5 import com.jcdm.main.da.opcuaconfig.client.ClientHandler;
6 import com.jcdm.main.da.opcuaconfig.domain.NodeEntity;
7 import com.jcdm.main.da.opcuaconfig.init.BeanUtils;
8 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
9 import lombok.extern.slf4j.Slf4j;
10 import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
11 import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
12
13 import java.util.*;
14 import java.util.stream.Collectors;
15
16 import static com.jcdm.main.da.opcuaconfig.client.ClientHandler.readValues;
17
18 @Slf4j
19 public class MethodName {
20     private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class);
21     public void getSn(String Node, String value) throws Exception {
22         log.info(Node+":"+value);
23         String[] parts = Node.split("[.]");
24         ClientHandler clientHandler=new ClientHandler();
25         switch (value) {
26             case "0":   //初始
27                 NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build();
28                 Boolean out=clientHandler.write(node);
29                 log.info("节点:{},响应结果:{}", node.getIdentifier(),out);
30                 break;
31             case "1":   //请求下发进站状态
32                 NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build();
33                 Boolean out1=clientHandler.write(node1);
34                 log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1);
35                 break;
36             case "2":   //请求记录工位数据
37                 List<DaCollectionParamConf> b;
38                 DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
39                 daCollectionParamConf.setCollectParameterId(parts[0]+"."+parts[1]);
40                 b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
41                 List<String> ids = b.stream().map(e -> e.getCollectParameterId()).collect(Collectors.toList());
42                 Set<String> de=ListToSet(ids);
43                 List<DataValue> s=readValues(de);
44 //                s.forEach(element->{
45 //                    DaParamCollection Config=new DaParamCollection();
46 //                    String[] q = element.getIdentifier().split("[.]");
47 //                    Config.setParamCode(q[2]);
48 //                    Config.setLocationCode(q[1]);
49 //                    Config.setParamValue(element.getValue().toString());
50 //                    daParamCollectionService.insertDaParamCollection(Config);
51 //                });
52                 NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build();
53                 Boolean out2=clientHandler.write(node2);
54                 log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2);
55                 break;
56             default:
57                 break;
58         }
59     }
60
61     public Set<String> ListToSet(List<String> list) {
62         Object[] objects = list.toArray();// 返回Object数组
63         String[] strings1 = new String[list.size()];
64         list.toArray(strings1);// 将转化后的数组放入已经创建好的对象中
65         String[] strings2 = list.toArray(new String[0]);// 将转化后的数组赋给新对象
66         Set<String> set = new HashSet<String>(Arrays.asList(strings2));
67         return set;
68     }
69 }