春风项目四线(合箱线、总装线)
懒羊羊
2024-01-18 ee8c6f62e8556fbd3b20912a7bec5d167004d0a5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.jcdm.main.da.opcuaconfig.cert;
 
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
import com.jcdm.main.da.opcuaconfig.client.ClientHandler;
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 lombok.extern.slf4j.Slf4j;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
 
import java.util.*;
import java.util.stream.Collectors;
 
import static com.jcdm.main.da.opcuaconfig.client.ClientHandler.readValues;
 
@Slf4j
public class MethodName {
    private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class);
    public void getSn(String Node, String value) throws Exception {
        log.info(Node+":"+value);
        String[] parts = Node.split("[.]");
        ClientHandler clientHandler=new ClientHandler();
        switch (value) {
            case "0":   //初始
                NodeEntity node= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("0").type("short").build();
                Boolean out=clientHandler.write(node);
                log.info("节点:{},响应结果:{}", node.getIdentifier(),out);
                break;
            case "1":   //请求下发进站状态
                NodeEntity node1= NodeEntity.builder().index(2).identifier(parts[0]+"."+parts[1]+".RecordDataDone").value("11").type("short").build();
                Boolean out1=clientHandler.write(node1);
                log.info("节点:{},响应结果:{}", node1.getIdentifier(),out1);
                break;
            case "2":   //请求记录工位数据
                List<DaCollectionParamConf> b;
                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);
//                });
                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);
                break;
            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;
    }
}