春风项目四线(合箱线、总装线)
jiang
2024-01-24 2df134deae4601dd7182c1b95a6663ce03785854
提交 | 用户 | 时间
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;
4c41b4 9 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
e4c3b0 10 import lombok.extern.slf4j.Slf4j;
Y 11 import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
12 import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
13
14 import java.util.*;
15 import java.util.stream.Collectors;
16
17 import static com.jcdm.main.da.opcuaconfig.client.ClientHandler.readValues;
18
19 @Slf4j
20 public class MethodName {
21     private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class);
4c41b4 22     private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class);
Y 23     private List<DataValue> s=null;
e4c3b0 24     public void getSn(String Node, String value) throws Exception {
Y 25         log.info(Node+":"+value);
26         String[] parts = Node.split("[.]");
27         ClientHandler clientHandler=new ClientHandler();
28         switch (value) {
29             case "0":   //初始
30                 NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build();
31                 Boolean out=clientHandler.write(node);
32                 log.info("节点:{},响应结果:{}", node.getIdentifier(),out);
33                 break;
34             case "1":   //请求下发进站状态
35                 NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build();
36                 Boolean out1=clientHandler.write(node1);
37                 log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1);
38                 break;
39             case "2":   //请求记录工位数据
40                 List<DaCollectionParamConf> b;
41                 DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf();
42                 daCollectionParamConf.setCollectParameterId(parts[0]+"."+parts[1]);
43                 b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
4c41b4 44
Y 45                 List<NodeId> nodeId = b.stream().map(info -> {
46                     NodeId nodeid = new NodeId(2,info.getCollectParameterId());
47                     return nodeid;
48                 }).collect(Collectors.toList());
49                 List<DataValue> s=readValues(nodeId);
50
51                 for(int i=0;i<nodeId.size();i++)
52                 {
53                     DaParamCollection Config=new DaParamCollection();
54                     Config.setParamCode(nodeId.get(i).getIdentifier().toString().split("[.]")[2]);
55                     Config.setLocationCode(nodeId.get(i).getIdentifier().toString().split("[.]")[1]);
56                     Config.setParamValue(s.get(i).getValue().getValue().toString());
57                     daParamCollectionService.insertDaParamCollection(Config);
58                 }
e4c3b0 59                 NodeEntity node2= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("21").type("short").build();
Y 60                 Boolean out2=clientHandler.write(node2);
61                 log.info("节点:{},响应结果:{}", node2.getIdentifier(),out2);
62                 break;
63             default:
64                 break;
65         }
66     }
67 }