feat: 增加定时任务采集iec61850数据
parent
b9a9e2259c
commit
cb4d2fc1e8
@ -0,0 +1,101 @@
|
||||
package com.xydl.cac.task;
|
||||
|
||||
import com.xydl.cac.entity.*;
|
||||
import com.xydl.cac.iec.IecClient;
|
||||
import com.xydl.cac.repository.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class Client61850Task {
|
||||
|
||||
@Resource
|
||||
IcdFileRepository fileRepository;
|
||||
@Resource
|
||||
IcdIedRepository iedRepository;
|
||||
@Resource
|
||||
IcdConfigTypeRepository configRepository;
|
||||
@Resource
|
||||
IcdConfigTypeAttRepository attRepository;
|
||||
@Resource
|
||||
IcdConfigTypeInstRepository instRepository;
|
||||
@Resource
|
||||
RptparamindexRepository rptparamindexRepository;
|
||||
|
||||
@Scheduled(cron = "0 30 * * * ?")
|
||||
public void collectAll() {
|
||||
List<IcdFile> icdFileList = fileRepository.findAll();
|
||||
if (!CollectionUtils.isEmpty(icdFileList)) {
|
||||
for (IcdFile icdFile : icdFileList) {
|
||||
this.collectIcdFile(icdFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void collectIcdFile(IcdFile icdFile) {
|
||||
List<IcdIed> iedList = iedRepository.findByIcdFileId(icdFile.getId());
|
||||
if (!CollectionUtils.isEmpty(iedList)) {
|
||||
for (IcdIed ied : iedList) {
|
||||
this.collectIed(icdFile.getXml(), ied);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void collectIed(String xml, IcdIed ied) {
|
||||
List<IcdConfigType> configTypeList = configRepository.findByIcdIedId(ied.getId());
|
||||
if (CollectionUtils.isEmpty(configTypeList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 开始连iec61850采集数据
|
||||
IecClient iecClient = new IecClient();
|
||||
try {
|
||||
iecClient.connect(ied.getIp(), 102, ied.getApTitle(), xml);
|
||||
this.collectIedValue(configTypeList, iecClient);
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.error("61850采集数据异常, ied=" + ied.getName() + ", ip=" + ied.getIp(), ex);
|
||||
} finally {
|
||||
iecClient.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private void collectIedValue(List<IcdConfigType> configTypeList, IecClient iecClient) throws Exception {
|
||||
for (IcdConfigType configType : configTypeList) {
|
||||
List<IcdConfigTypeInst> instList = instRepository.findByIcdConfigTypeId(configType.getId());
|
||||
List<IcdConfigTypeAtt> attList = attRepository.findByIcdConfigTypeId(configType.getId());
|
||||
for (IcdConfigTypeInst inst : instList) {
|
||||
String param = configType.getIedName() + configType.getLdeviceInst() + "/" + configType.getLnClass()
|
||||
+ inst.getInst();
|
||||
for (IcdConfigTypeAtt att : attList) {
|
||||
if (att.containInst(inst.getInst())) {
|
||||
String paramindexOld = param + "$" + att.getParam();
|
||||
String paramindexNew = param + "." + att.getDoName() + "." + att.getLastName().replace("$", ".");
|
||||
String paramindexT = param + "." + att.getDoName() + ".t";
|
||||
|
||||
List<Rptparamindex> rptList = rptparamindexRepository.findAllByParamindexEqualsAndEqmidIsNotNullAndTablenameIsNotNullAndColnameIsNotNull(paramindexOld);
|
||||
if (!CollectionUtils.isEmpty(rptList)) {
|
||||
this.getOneValue(paramindexNew, paramindexT, att.getFc(), rptList.get(0), iecClient);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getOneValue(String paramindexNew, String paramindexT, String fc, Rptparamindex rpt, IecClient iecClient) throws Exception {
|
||||
|
||||
String value = iecClient.getValue(paramindexNew, fc);
|
||||
log.info(paramindexNew + "=" + value);
|
||||
|
||||
String time = iecClient.getValue(paramindexT, fc);
|
||||
log.info(paramindexT + "=" + time);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue