package com.jcdm.main.plcserver.callback;
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.util.StrUtil;
|
import com.jcdm.common.core.domain.BaseEntity;
|
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.da.passingStationCollection.service.impl.DaPassingStationCollectionServiceImpl;
|
import com.jcdm.main.da.tileMatchRules.service.IDaTileMatchRulesService;
|
import com.kangaroohy.milo.model.ReadWriteEntity;
|
import com.kangaroohy.milo.runner.subscription.SubscriptionCallback;
|
import com.kangaroohy.milo.service.MiloService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.ObjectUtils;
|
import org.springframework.stereotype.Component;
|
import java.util.ArrayList;
|
import java.util.Comparator;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Slf4j
|
@Component
|
public class InitCallback implements SubscriptionCallback {
|
|
public static MiloService miloService;
|
|
public IDaCollectionParamConfService collectionParamConfService;
|
|
public IDaParamCollectionService daParamCollectionService;
|
|
public DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl;
|
|
public IDaTileMatchRulesService daTileMatchRulesService;
|
;
|
|
public InitCallback(MiloService miloService,
|
IDaCollectionParamConfService collectionParamConfService,
|
IDaParamCollectionService daParamCollectionService,
|
DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl,
|
IDaTileMatchRulesService daTileMatchRulesService) {
|
InitCallback.miloService = miloService;
|
this.collectionParamConfService = collectionParamConfService;
|
this.daParamCollectionService = daParamCollectionService;
|
this.passingStationCollectionServiceImpl = passingStationCollectionServiceImpl;
|
this.daTileMatchRulesService = daTileMatchRulesService;
|
|
}
|
|
|
@Override
|
public void onSubscribe(String identifier, Object value) {
|
String ecpStr = "";//异常记录标记
|
try {
|
if (null != value) {
|
//BCOP40进站校验
|
if (identifier.equals("CFL4CVT.BCOP040.RecordData") && null != value && "1".equals(value.toString())) {
|
//待添加从过站采集表取sfc_code写入plc的sncode方法
|
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP040.MesRecordDataDone", 11);
|
miloService.writeToOpcByte(entity);
|
}
|
//BCOP40出站校验
|
else if (identifier.equals("CFL4CVT.BCOP040.RecordData") && null != value && "2".equals(value.toString())) {
|
SaveData("CFL4CVT.BCOP40.RecordData");
|
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP040.MesRecordDataDone", 21);
|
miloService.writeToOpcByte(entity);
|
}
|
//BCOP60进站校验
|
else if (identifier.equals("CFL4CVT.BCOP060.RecordData") && null != value && "1".equals(value.toString())) {
|
//待添加从过站采集表取sfc_code写入plc的sncode方法
|
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP060.MesRecordDataDone", 11);
|
miloService.writeToOpcByte(entity);
|
}
|
//BCOP60出站校验
|
else if (identifier.equals("CFL4CVT.BCOP060.RecordData") && null != value && "2".equals(value.toString())) {
|
SaveData("CFL4CVT.BCOP060.RecordData");
|
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP060.MesRecordDataDone", 21);
|
miloService.writeToOpcByte(entity);
|
}
|
//BCOP100进站校验
|
else if (identifier.equals("CFL4CVT.BCOP100.RecordData") && null != value && "1".equals(value.toString())) {
|
//待添加从过站采集表取sfc_code写入plc的sncode方法
|
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP100.MesRecordDataDone", 11);
|
miloService.writeToOpcByte(entity);
|
}
|
//BCOP100出站校验
|
else if (identifier.equals("CFL4CVT.BCOP100.RecordData") && null != value && "2".equals(value.toString())) {
|
SaveData("CFL4CVT.BCOP100.RecordData");
|
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BCOP100.MesRecordDataDone", 21);
|
miloService.writeToOpcByte(entity);
|
}//BP020进站校验
|
else if (identifier.equals("CFL4CVT.BP020.RecordData") && null != value && "1".equals(value.toString())) {
|
//待添加从过站采集表取sfc_code写入plc的sncode方法
|
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BP020.MesRecordDataDone", 11);
|
miloService.writeToOpcByte(entity);
|
}
|
//BP020出站校验
|
else if (identifier.equals("CFL4CVT.BP020.RecordData") && null != value && "2".equals(value.toString())) {
|
SaveData("CFL4CVT.BP020.RecordData");
|
ReadWriteEntity entity = new ReadWriteEntity("CFL4CVT.BP020.MesRecordDataDone", 21);
|
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]);
|
Object value = readWriteEntityList.get(i).getValue();
|
if (ObjectUtils.isNotEmpty(value)) {
|
String string = value.toString();
|
ParamCollection.setParamValue(string);
|
}
|
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);
|
}
|
}
|
}
|
|
|
public void WriteSNCode(String Node) throws Exception {
|
|
|
}
|
}
|