提交 | 用户 | 时间
|
3e03af
|
1 |
package com.jcdm.main.plcserver.sub; |
C |
2 |
|
|
3 |
|
|
4 |
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; |
|
5 |
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
|
6 |
import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
|
7 |
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
|
8 |
import com.jcdm.main.plcserver.conf.OPCElement; |
|
9 |
import com.kangaroohy.milo.model.ReadWriteEntity; |
|
10 |
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
|
11 |
import com.kangaroohy.milo.service.MiloService; |
|
12 |
import org.springframework.stereotype.Component; |
|
13 |
|
|
14 |
import java.util.ArrayList; |
|
15 |
import java.util.Date; |
|
16 |
import java.util.List; |
|
17 |
import java.util.stream.Collectors; |
|
18 |
|
|
19 |
|
|
20 |
@Component |
|
21 |
public class OPCUaSubscription implements SubscriptionCallback { |
|
22 |
|
|
23 |
public static MiloService miloService; |
|
24 |
|
|
25 |
public IDaCollectionParamConfService collectionParamConfService; |
|
26 |
|
|
27 |
public IDaParamCollectionService daParamCollectionService; |
|
28 |
|
|
29 |
public OPCUaSubscription(MiloService miloService, |
|
30 |
IDaCollectionParamConfService collectionParamConfService, |
|
31 |
IDaParamCollectionService daParamCollectionService) { |
|
32 |
OPCUaSubscription.miloService = miloService; |
|
33 |
this.collectionParamConfService = collectionParamConfService; |
|
34 |
this.daParamCollectionService = daParamCollectionService; |
|
35 |
|
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
@Override |
|
40 |
public void onSubscribe(String identifier, Object value) { |
|
41 |
String ecpStr = "";//异常记录标记 |
|
42 |
try { |
|
43 |
if(null != value) { |
|
44 |
|
|
45 |
//OP010保存请求 |
|
46 |
if (identifier.equals(OPCElement.OP010_SaveRequest) && null != value && "1".equals(value.toString())) { |
755db7
|
47 |
//1、更新工单数据 |
C |
48 |
//2、保存过站采集数据 |
|
49 |
//3、保存参数采集数据 |
3e03af
|
50 |
ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesSaveFeed, 1); |
C |
51 |
miloService.writeToOpcByte(entity); |
|
52 |
} |
|
53 |
//OP010请求检索条码 |
|
54 |
else if (identifier.equals(OPCElement.OP010_CodeCheck) && null != value && "1".equals(value.toString())) { |
|
55 |
ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP010_MesCodeCheckFeed, 1); |
|
56 |
miloService.writeToOpcByte(entity); |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
} catch (Exception e) { |
|
63 |
|
|
64 |
} finally { |
|
65 |
if (!"".equals(ecpStr)) { |
|
66 |
System.out.println(ecpStr + "\r\n"); |
|
67 |
|
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
public void SaveData(String Node) throws Exception { |
|
73 |
/*String[] parts = Node.split("[.]"); |
|
74 |
Object SNCodeObject = miloService.readFromOpcUa(parts[0] + "." + parts[1] + ".Code1").getValue(); |
|
75 |
|
|
76 |
if(null != SNCodeObject) |
|
77 |
{ |
|
78 |
String SNCode = SNCodeObject.toString(); |
|
79 |
List<DaCollectionParamConf> list; |
|
80 |
DaCollectionParamConf daCollectionParamConf = new DaCollectionParamConf(); |
|
81 |
daCollectionParamConf.setGatherAddress(parts[0] + "." + parts[1]); |
|
82 |
list = collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
|
83 |
|
|
84 |
List<String> nodeIdList = list.stream().map(info -> { |
|
85 |
String nodeid = info.getGatherAddress(); |
|
86 |
return nodeid; |
|
87 |
}).collect(Collectors.toList()); |
|
88 |
|
|
89 |
if(!nodeIdList.isEmpty()){ |
|
90 |
List<ReadWriteEntity> readWriteEntityList = miloService.readFromOpcUa(nodeIdList); |
|
91 |
List<DaParamCollection> daParamCollectionlist = new ArrayList<>(); |
|
92 |
for(int i=0;i<nodeIdList.size();i++){ |
|
93 |
DaParamCollection ParamCollection = new DaParamCollection(); |
|
94 |
if(!readWriteEntityList.get(i).getValue().toString().equals("0.0")){ |
|
95 |
ParamCollection.setParamCode(readWriteEntityList.get(i).getIdentifier().toString().split("[.]")[2]); |
|
96 |
ParamCollection.setLocationCode(parts[1]); |
|
97 |
ParamCollection.setParamValue(readWriteEntityList.get(i).getValue().toString()); |
|
98 |
ParamCollection.setSfcCode(SNCode); |
|
99 |
ParamCollection.setParamName(list.get(i).getCollectParameterName()); |
|
100 |
ParamCollection.setParamUpper(list.get(i).getParamUpper()); |
|
101 |
ParamCollection.setParamLower(list.get(i).getParamLower()); |
|
102 |
ParamCollection.setUnit(list.get(i).getCollectParameterUnit()); |
|
103 |
ParamCollection.setState("合格"); |
|
104 |
ParamCollection.setType(list.get(i).getCollectParameterType()); |
|
105 |
ParamCollection.setCollectionTime(new Date()); |
|
106 |
daParamCollectionlist.add(ParamCollection); |
|
107 |
} |
|
108 |
} |
|
109 |
daParamCollectionService.saveBeachDaParamCollection(daParamCollectionlist); |
|
110 |
} |
|
111 |
}*/ |
|
112 |
} |
|
113 |
} |