feat: 增加定时任务采集iec61850数据

iec104
huangfeng 8 months ago
parent b9a9e2259c
commit cb4d2fc1e8

@ -11,5 +11,5 @@ import java.util.List;
@Repository
public interface IcdIedRepository extends JpaRepository<IcdIed, Integer>, JpaSpecificationExecutor<IcdIed> {
List<IcdIed> findByIcdFileId(String fileId);
List<IcdIed> findByIcdFileId(Integer fileId);
}

@ -14,4 +14,7 @@ public interface RptparamindexRepository extends JpaRepository<Rptparamindex, St
List<Rptparamindex> findAllByEqmid(Integer eqmid);
List<Rptparamindex> findAllByParamindexStartingWith(String param);
List<Rptparamindex> findAllByParamindexEqualsAndEqmidIsNotNullAndTablenameIsNotNullAndColnameIsNotNull(String paramindex);
}

@ -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);
}
}

@ -63,8 +63,10 @@ public class I2syncTask {
// 同步一个类型
private void syncOneConfig(I2syncConfig config) throws Exception {
log.info("I2syncTask.syncOneConfig " + config.getTypeName());
List<I2syncField> fieldList = i2syncService.listFieldConfig(config.getTableName());
if (CollectionUtils.isEmpty(fieldList)) {
log.info("该类型未配置同步字段.");
return;
}
List<ModevTypePoint> points = new ArrayList<>();

Loading…
Cancel
Save