feat: 重构ied服务并根据定时间隔采集数据
parent
70b7b0c7a5
commit
b4f6df1914
@ -0,0 +1,102 @@
|
|||||||
|
package com.xydl.cac.iec;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.*;
|
||||||
|
import com.xydl.cac.repository.IcdConfigTypeAttRepository;
|
||||||
|
import com.xydl.cac.repository.IcdConfigTypeInstRepository;
|
||||||
|
import com.xydl.cac.repository.IcdConfigTypeRepository;
|
||||||
|
import com.xydl.cac.repository.RptparamindexRepository;
|
||||||
|
import com.xydl.cac.service.DataService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class IEDService {
|
||||||
|
IcdConfigTypeRepository _configRepository;
|
||||||
|
IcdConfigTypeAttRepository _attRepository;
|
||||||
|
IcdConfigTypeInstRepository _instRepository;
|
||||||
|
RptparamindexRepository _rptparamindexRepository;
|
||||||
|
DataService _dataService;
|
||||||
|
IecClient iecClient;
|
||||||
|
IcdIed ied;
|
||||||
|
String xml;
|
||||||
|
|
||||||
|
public IEDService(IcdConfigTypeRepository configRepository, IcdConfigTypeAttRepository attRepository,
|
||||||
|
IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository,
|
||||||
|
DataService dataService, String xml, IcdIed ied) {
|
||||||
|
_configRepository = configRepository;
|
||||||
|
_attRepository = attRepository;
|
||||||
|
_instRepository = instRepository;
|
||||||
|
_rptparamindexRepository = rptparamindexRepository;
|
||||||
|
_dataService = dataService;
|
||||||
|
this.xml = xml;
|
||||||
|
this.ied = ied;
|
||||||
|
iecClient = new IecClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void connect() throws Exception {
|
||||||
|
iecClient.connect(ied.getIp(), 102, ied.getApTitle(), xml);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect() {
|
||||||
|
iecClient.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void collectAndSave(List<Rptparamindex> rptList) {
|
||||||
|
List<IcdConfigType> configTypeList = _configRepository.findByIcdIedId(ied.getId());
|
||||||
|
if (CollectionUtils.isEmpty(configTypeList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 开始连iec61850采集数据
|
||||||
|
try {
|
||||||
|
log.info("61850开始采集数据, ied=" + ied.getName() + ", ip=" + ied.getIp());
|
||||||
|
this.connect();
|
||||||
|
this.doCollectAndSave(configTypeList, rptList);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("61850采集数据异常, ied=" + ied.getName() + ", ip=" + ied.getIp(), ex);
|
||||||
|
} finally {
|
||||||
|
iecClient.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doCollectAndSave(List<IcdConfigType> configTypeList, List<Rptparamindex> rptList) 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";
|
||||||
|
|
||||||
|
Rptparamindex rpt = this.findRpt(rptList, paramindexOld);
|
||||||
|
if (rpt != null) {
|
||||||
|
this.collectAndSaveValue(paramindexNew, paramindexT, att.getFc(), rpt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectAndSaveValue(String paramindexNew, String paramindexT, String fc, Rptparamindex rpt) throws Exception {
|
||||||
|
String value = iecClient.getValue(paramindexNew, fc);
|
||||||
|
String time = iecClient.getValue(paramindexT, fc);
|
||||||
|
log.info("采集到" + fc + " " + paramindexNew + "=" + value + ", t=" + time);
|
||||||
|
time = time.replace("T", " ").replace("Z", "").replace("z", "");
|
||||||
|
_dataService.insertData(rpt.getTablename(), rpt.getEqmid(), time, rpt.getColname(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rptparamindex findRpt(List<Rptparamindex> rptList, String paramindex) {
|
||||||
|
for (Rptparamindex rpt : rptList) {
|
||||||
|
if (rpt.getParamindex().equals(paramindex)) {
|
||||||
|
return rpt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue