提交 | 用户 | 时间
|
1b9512
|
1 |
package com.jcdm.main.da.opcuaconfig.init; |
YY |
2 |
|
661da3
|
3 |
import com.jcdm.main.da.collectionParamConf.domain.DaCollectionParamConf; |
YY |
4 |
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService; |
1b9512
|
5 |
import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig; |
ffbba7
|
6 |
import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService; |
661da3
|
7 |
import com.jcdm.main.da.paramCollection.domain.DaParamCollection; |
YY |
8 |
import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService; |
|
9 |
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection; |
|
10 |
import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
|
11 |
import com.kangaroohy.milo.model.ReadWriteEntity; |
1b9512
|
12 |
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback; |
661da3
|
13 |
import com.kangaroohy.milo.service.MiloService; |
1b9512
|
14 |
import org.springframework.beans.factory.annotation.Autowired; |
YY |
15 |
import org.springframework.stereotype.Component; |
ffbba7
|
16 |
import javax.annotation.PostConstruct; |
1b9512
|
17 |
import java.lang.reflect.InvocationTargetException; |
YY |
18 |
import java.lang.reflect.Method; |
661da3
|
19 |
import java.util.ArrayList; |
1b9512
|
20 |
import java.util.List; |
661da3
|
21 |
import java.util.stream.Collectors; |
1b9512
|
22 |
|
YY |
23 |
@Component |
|
24 |
public class TestCallback implements SubscriptionCallback { |
661da3
|
25 |
private IDaParamCollectionService daParamCollectionService = BeanUtils.getBean(IDaParamCollectionService.class); |
YY |
26 |
private IDaOpcuaConfigService daOpcuaConfigService = BeanUtils.getBean(IDaOpcuaConfigService.class); |
|
27 |
private IDaCollectionParamConfService collectionParamConfService = BeanUtils.getBean(IDaCollectionParamConfService.class); |
|
28 |
private MiloService miloService = BeanUtils.getBean(MiloService.class); |
ffbba7
|
29 |
private List<DaOpcuaConfig> b=null; |
661da3
|
30 |
// private CustomRunner customRunner; |
ffbba7
|
31 |
@Override |
1b9512
|
32 |
public void onSubscribe(String identifier, Object value) { |
ffbba7
|
33 |
if (b == null || 0 > b.size()) { |
YY |
34 |
DaOpcuaConfig daOpcuaConfig=new DaOpcuaConfig(); |
|
35 |
daOpcuaConfig.setSubscribe(1L); |
661da3
|
36 |
b=daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig); |
1b9512
|
37 |
} |
ffbba7
|
38 |
//使用Stream API在List<T>中查找元素 |
YY |
39 |
DaOpcuaConfig opcuaConf = b.stream() |
|
40 |
.filter(customer ->identifier.equals(customer.getNode())) |
|
41 |
.findAny() |
|
42 |
.orElse(null); |
|
43 |
try { |
|
44 |
Class<?> clazz = Class.forName(opcuaConf.getrModule()); |
|
45 |
Method method = clazz.getMethod(opcuaConf.getrFunction(), new Class[] { String.class, String.class }); |
|
46 |
method.invoke(clazz.newInstance(),new Object[] { new String(identifier), new String(value.toString()) }); |
|
47 |
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { |
|
48 |
System.out.println("节点"+identifier+"订阅回调失败"); |
|
49 |
e.printStackTrace(); |
|
50 |
} |
|
51 |
} |
661da3
|
52 |
|
YY |
53 |
public void SiteCollection(String Node, String value) throws Exception { |
|
54 |
String[] parts = Node.split("[.]"); |
|
55 |
switch (value) { |
|
56 |
case "0": //初始 |
|
57 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(parts[0]+"."+parts[1]+".RecordDataDone").value(0).build()); |
|
58 |
break; |
|
59 |
case "1": //请求下发进站状态 |
|
60 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(parts[0]+"."+parts[1]+".RecordDataDone").value(11).build()); |
|
61 |
break; |
|
62 |
case "2": //请求记录工位数据 |
|
63 |
List<DaCollectionParamConf> b; |
|
64 |
DaCollectionParamConf daCollectionParamConf=new DaCollectionParamConf(); |
|
65 |
daCollectionParamConf.setCollectParameterId(parts[0]+"."+parts[1]); |
|
66 |
b=collectionParamConfService.selectDaCollectionParamConfList(daCollectionParamConf); |
|
67 |
|
|
68 |
List<String> ids = b.stream().map(e -> e.getCollectParameterId()).collect(Collectors.toList()); |
|
69 |
List<ReadWriteEntity> s=miloService.readFromOpcUa(ids); |
|
70 |
s.forEach(element->{ |
|
71 |
DaParamCollection Config=new DaParamCollection(); |
|
72 |
String[] q = element.getIdentifier().split("[.]"); |
|
73 |
Config.setParamCode(q[2]); |
|
74 |
Config.setLocationCode(q[1]); |
|
75 |
Config.setParamValue(element.getValue().toString()); |
|
76 |
daParamCollectionService.insertDaParamCollection(Config); |
|
77 |
}); |
|
78 |
miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(parts[0]+"."+parts[1]+".RecordDataDone").value(21).build()); |
|
79 |
break; |
|
80 |
default: |
|
81 |
break; |
|
82 |
} |
1b9512
|
83 |
} |
YY |
84 |
} |