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);
|
}
|
}*/
|
}
|
}
|