You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
257 lines
9.2 KiB
Java
257 lines
9.2 KiB
Java
package com.xydl.cac.service.impl;
|
|
|
|
import com.xydl.cac.entity.*;
|
|
import com.xydl.cac.exception.BusinessException;
|
|
import com.xydl.cac.model.IcdAttUpdateModel;
|
|
import com.xydl.cac.repository.*;
|
|
import com.xydl.cac.service.DataService;
|
|
import com.xydl.cac.service.IcdFileConfigService;
|
|
import com.xydl.cac.util.IcdXmlUtil;
|
|
import com.xydl.cac.util.Md5;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.*;
|
|
|
|
@Service
|
|
@Slf4j
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public class IcdFileConfigServiceImpl implements IcdFileConfigService {
|
|
|
|
@Resource
|
|
IcdFileRepository fileRepository;
|
|
@Resource
|
|
IcdIedRepository iedRepository;
|
|
@Resource
|
|
IcdConfigTypeRepository configRepository;
|
|
@Resource
|
|
IcdConfigTypeAttRepository attRepository;
|
|
@Resource
|
|
IcdConfigTypeInstRepository instRepository;
|
|
@Resource
|
|
private JdbcTemplate jdbcTemplate;
|
|
@Resource
|
|
RptparamindexRepository rptparamindexRepository;
|
|
@Resource
|
|
DataService dataService;
|
|
|
|
@Override
|
|
public void upload(String xml, String filename) throws Exception {
|
|
String md5 = Md5.getMD5Code(xml);
|
|
List<IcdFile> files = fileRepository.findByMd5(md5);
|
|
if (!CollectionUtils.isEmpty(files)) {
|
|
throw new BusinessException("该文件已存在");
|
|
}
|
|
|
|
IcdFile icdFile = IcdXmlUtil.loadIcdType(xml);
|
|
icdFile.setMd5(md5);
|
|
icdFile.setFilename(filename);
|
|
fileRepository.save(icdFile);
|
|
for (IcdIed ied : icdFile.getIedList()) {
|
|
ied.setIcdFileId(icdFile.getId());
|
|
iedRepository.save(ied);
|
|
}
|
|
for (IcdConfigType config : icdFile.getConfigList()) {
|
|
IcdIed ied = this.findIcdIed(icdFile.getIedList(), config.getIedName());
|
|
if (ied != null) {
|
|
config.setIcdIedId(ied.getId());
|
|
}
|
|
configRepository.save(config);
|
|
|
|
attRepository.deleteByIcdConfigTypeId(config.getId());
|
|
if (config.getAttMap() != null) {
|
|
Collection<IcdConfigTypeAtt> attList = config.getAttMap().values();
|
|
for (IcdConfigTypeAtt item : attList) {
|
|
item.setIcdConfigTypeId(config.getId());
|
|
item.buildInsts();
|
|
}
|
|
attRepository.saveAll(attList);
|
|
}
|
|
|
|
instRepository.deleteByIcdConfigTypeId(config.getId());
|
|
if (config.getInstMap() != null) {
|
|
Collection<IcdConfigTypeInst> instList = config.getInstMap().values();
|
|
for (IcdConfigTypeInst item : instList) {
|
|
item.setIcdConfigTypeId(config.getId());
|
|
}
|
|
instRepository.saveAll(instList);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public List<IcdFile> listFile() {
|
|
List<IcdFile> files = fileRepository.findAll();
|
|
for (IcdFile file : files) {
|
|
file.setXml(null);
|
|
}
|
|
return files;
|
|
}
|
|
|
|
private IcdIed findIcdIed(List<IcdIed> list, String name) {
|
|
for (IcdIed ied : list) {
|
|
if (ied.getName().equalsIgnoreCase(name)) {
|
|
return ied;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public List<String> iedList() {
|
|
String sql = "SELECT DISTINCT ied_name FROM icd_config_type";
|
|
List<String> list = jdbcTemplate.queryForList(sql, String.class);
|
|
return list;
|
|
}
|
|
|
|
@Override
|
|
public List<IcdConfigType> list(String iedName) throws Exception {
|
|
List<IcdConfigType> result;
|
|
if (StringUtils.isNotBlank(iedName)) {
|
|
result = configRepository.findByIedName(iedName);
|
|
} else {
|
|
result = configRepository.findAll();
|
|
}
|
|
for (IcdConfigType item : result) {
|
|
List<IcdConfigTypeAtt> atts = attRepository.findByIcdConfigTypeId(item.getId());
|
|
item.setAttList(atts);
|
|
List<IcdConfigTypeInst> insts = instRepository.findByIcdConfigTypeId(item.getId());
|
|
item.setInstList(insts);
|
|
for (IcdConfigTypeInst inst : insts) {
|
|
String param = item.getIedName() + item.getLdeviceInst() + "/" + item.getLnClass()
|
|
+ inst.getInst();
|
|
inst.setParamIndex(param);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
public void update(IcdConfigType item) throws Exception {
|
|
Optional<IcdConfigType> optional = configRepository.findById(item.getId());
|
|
if (!optional.isPresent()) {
|
|
throw new BusinessException("未找到该项");
|
|
}
|
|
IcdConfigType r = optional.get();
|
|
if (r.getTableName() != null && !r.getTableName().equals(item.getTableName())) {
|
|
List<IcdConfigTypeAtt> attList = attRepository.findByIcdConfigTypeId(r.getId());
|
|
for (IcdConfigTypeAtt att : attList) {
|
|
att.setColName(null);
|
|
}
|
|
attRepository.saveAll(attList);
|
|
}
|
|
r.setTableName(item.getTableName());
|
|
configRepository.save(r);
|
|
}
|
|
|
|
@Override
|
|
public void updateAtt(IcdAttUpdateModel model) throws Exception {
|
|
if (CollectionUtils.isEmpty(model.getIdList())) {
|
|
throw new BusinessException("id列表不能为空");
|
|
}
|
|
for (Integer id : model.getIdList()) {
|
|
Optional<IcdConfigTypeAtt> optional = attRepository.findById(id);
|
|
if (!optional.isPresent()) {
|
|
throw new BusinessException("未找到该项" + id);
|
|
}
|
|
IcdConfigTypeAtt r = optional.get();
|
|
r.setColName(model.getColName());
|
|
attRepository.save(r);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void delete(Integer id) {
|
|
instRepository.deleteByIcdConfigTypeId(id);
|
|
attRepository.deleteByIcdConfigTypeId(id);
|
|
configRepository.deleteById(id);
|
|
}
|
|
|
|
@Override
|
|
public void deleteAtt(Integer attid) {
|
|
attRepository.deleteById(attid);
|
|
}
|
|
|
|
@Override
|
|
public void clearAll() {
|
|
dataService.clearAllBind();
|
|
instRepository.deleteAll();
|
|
attRepository.deleteAll();
|
|
configRepository.deleteAll();
|
|
fileRepository.deleteAll();
|
|
iedRepository.deleteAll();
|
|
rptparamindexRepository.deleteAll();
|
|
}
|
|
|
|
@Override
|
|
public List<String> compare61850() {
|
|
List<String> param618List = new ArrayList<>();
|
|
List<Rptparamindex> rptList = rptparamindexRepository.findAll();
|
|
for (Rptparamindex rpt : rptList) {
|
|
param618List.add(rpt.getParamindex());
|
|
}
|
|
|
|
List<String> paramList = new ArrayList<>();
|
|
List<IcdConfigType> typeLIst = configRepository.findAll();
|
|
for (IcdConfigType type : typeLIst) {
|
|
List<IcdConfigTypeInst> instList = instRepository.findByIcdConfigTypeId(type.getId());
|
|
List<IcdConfigTypeAtt> attList = attRepository.findByIcdConfigTypeId(type.getId());
|
|
for (IcdConfigTypeInst inst : instList) {
|
|
String param = type.getIedName() + type.getLdeviceInst() + "/" + type.getLnClass()
|
|
+ inst.getInst();
|
|
for (IcdConfigTypeAtt att : attList) {
|
|
if (att.containInst(inst.getInst())) {
|
|
String paramindex = param + "$" + att.getParam();
|
|
paramList.add(paramindex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
List<String> result = new ArrayList<>();
|
|
for (String str : param618List) {
|
|
if (!paramList.contains(str)) {
|
|
result.add("少了" + str);
|
|
}
|
|
}
|
|
for (String str : paramList) {
|
|
if (!param618List.contains(str)) {
|
|
result.add("多了" + str);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
public void generateParamindex() throws Exception {
|
|
List<IcdConfigType> typeLIst = configRepository.findAll();
|
|
for (IcdConfigType type : typeLIst) {
|
|
List<IcdConfigTypeInst> instList = instRepository.findByIcdConfigTypeId(type.getId());
|
|
List<IcdConfigTypeAtt> attList = attRepository.findByIcdConfigTypeId(type.getId());
|
|
for (IcdConfigTypeInst inst : instList) {
|
|
String param = type.getIedName() + type.getLdeviceInst() + "/" + type.getLnClass()
|
|
+ inst.getInst();
|
|
for (IcdConfigTypeAtt att : attList) {
|
|
if (att.containInst(inst.getInst())) {
|
|
String paramindex = param + "$" + att.getParam();
|
|
List<Rptparamindex> rptList = rptparamindexRepository.findAllByParamindexEquals(paramindex);
|
|
if (CollectionUtils.isEmpty(rptList)) {
|
|
Rptparamindex rpt = Rptparamindex.builder()
|
|
.paramindex(paramindex)
|
|
.objid(0)
|
|
.build();
|
|
rptparamindexRepository.save(rpt);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|