春风项目四线(合箱线、总装线)
cl
2024-03-05 755db77a25f447ec0571c0fe8c12e5fae7c75ee8
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.jcdm.main.plcserver.sub;
 
 
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf;
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
import com.jcdm.main.plcserver.conf.OPCElement;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
import com.kangaroohy.milo.service.MiloService;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
 
@Component
public class OPCUaSubscription implements SubscriptionCallback {
 
    public static MiloService miloService;
 
    public IDaCollectionParamConfService collectionParamConfService;
 
    public IDaParamCollectionService daParamCollectionService;
 
    public OPCUaSubscription(MiloService miloService,
                             IDaCollectionParamConfService collectionParamConfService,
                             IDaParamCollectionService daParamCollectionService) {
        OPCUaSubscription.miloService = miloService;
        this.collectionParamConfService = collectionParamConfService;
        this.daParamCollectionService = daParamCollectionService;
 
    }
 
 
    @Override
    public void onSubscribe(String identifier, Object value) {
        String ecpStr = "";//异常记录标记
        try {
            if(null != value) {
 
                //OP010保存请求
                if (identifier.equals(OPCElement.OP010_SaveRequest) && null != value && "1".equals(value.toString())) {
                    //1、更新工单数据
                    //2、保存过站采集数据
                    //3、保存参数采集数据
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesSaveFeed, 1);
                    miloService.writeToOpcByte(entity);
                }
                //OP010请求检索条码
                else if (identifier.equals(OPCElement.OP010_CodeCheck) && null != value && "1".equals(value.toString())) {
                    ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesCodeCheckFeed, 1);
                    miloService.writeToOpcByte(entity);
                }
            }
 
 
 
        } catch (Exception e) {
 
        } finally {
            if (!"".equals(ecpStr)) {
                System.out.println(ecpStr + "\r\n");
 
            }
        }
    }
 
    public void SaveData(String Node) throws Exception {
        /*String[] parts = Node.split("[.]");
        Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue();
 
        if(null != SNCodeObject)
        {
            String SNCode = SNCodeObject.toString();
            List<DaCollectionParamConf> list;
            DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf();
            daCollectionParamConf.setGatherAddress(parts[0] + "." + parts[1]);
            list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf);
 
            List<String> nodeIdList = list.stream().map(info -> {
                String nodeid = info.getGatherAddress();
                return nodeid;
            }).collect(Collectors.toList());
 
            if(!nodeIdList.isEmpty()){
                List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList);
                List<DaParamCollection> daParamCollectionlist = new ArrayList<>();
                for(int i=0;i<nodeIdList.size();i++){
                    DaParamCollection ParamCollection = new DaParamCollection();
                    if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){
                        ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]);
                        ParamCollection.setLocationCode(parts[1]);
                        ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString());
                        ParamCollection.setSfcCode(SNCode);
                        ParamCollection.setParamName(list.get(i).getCollectParameterName());
                        ParamCollection.setParamUpper(list.get(i).getParamUpper());
                        ParamCollection.setParamLower(list.get(i).getParamLower());
                        ParamCollection.setUnit(list.get(i).getCollectParameterUnit());
                        ParamCollection.setState("合格");
                        ParamCollection.setType(list.get(i).getCollectParameterType());
                        ParamCollection.setCollectionTime(new Date());
                        daParamCollectionlist.add(ParamCollection);
                    }
                }
                daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist);
            }
        }*/
    }
}