feat: 增加绑定预览接口

haikang
huangfeng 1 year ago
parent 6223612495
commit 7ff59faf94

@ -2,6 +2,8 @@ package com.xydl.cac.controller;
import com.xydl.cac.entity.Bdz;
import com.xydl.cac.entity.IcdConfigTypeInst;
import com.xydl.cac.entity.Rptparamindex;
import com.xydl.cac.model.BindingModel;
import com.xydl.cac.model.Response;
import com.xydl.cac.service.ParamBindService;
import io.swagger.annotations.Api;
@ -38,4 +40,11 @@ public class ParamBindController extends BasicController {
return Response.success(result);
}
@PostMapping("preview")
@ApiOperation("预览")
public Response<List<Rptparamindex>> preview(@Validated @RequestBody BindingModel item) throws Exception {
List<Rptparamindex> result = bindService.preview(item);
return Response.success(result);
}
}

@ -0,0 +1,46 @@
package com.xydl.cac.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "rptparamindex")
@ApiModel("绑定关系表")
public class Rptparamindex {
@Id
@ApiModelProperty("61850对象参引")
@Column(name = "paramindex")
private String paramindex;
@ApiModelProperty("61850对象id")
@Column(name = "objid")
private Integer objid;
@ApiModelProperty("监测设备id")
@Column(name = "eqmid")
private Integer eqmid;
@Column(name = "tablename")
private String tablename;
@Column(name = "colname")
private String colname;
@Column(name = "phase")
private String phase;
}

@ -0,0 +1,16 @@
package com.xydl.cac.model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class BindingModel {
@NotNull(message = "eqmid不能为空")
@ApiModelProperty("eqmid")
Integer eqmid;
@NotNull(message = "逻辑设备实例的Id不能为空")
@ApiModelProperty("逻辑设备实例的Id")
Integer bindingId;
}

@ -0,0 +1,12 @@
package com.xydl.cac.repository;
import com.xydl.cac.entity.Rptparamindex;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface RptparamindexRepository extends JpaRepository<Rptparamindex, String>, JpaSpecificationExecutor<Rptparamindex> {
}

@ -2,6 +2,8 @@ package com.xydl.cac.service;
import com.xydl.cac.entity.Bdz;
import com.xydl.cac.entity.IcdConfigTypeInst;
import com.xydl.cac.entity.Rptparamindex;
import com.xydl.cac.model.BindingModel;
import java.util.List;
@ -10,4 +12,6 @@ public interface ParamBindService {
List<Bdz> getTree() throws Exception;
List<IcdConfigTypeInst> instList(String iedName);
List<Rptparamindex> preview(BindingModel item) throws Exception;
}

@ -1,6 +1,7 @@
package com.xydl.cac.service.impl;
import com.xydl.cac.entity.*;
import com.xydl.cac.model.BindingModel;
import com.xydl.cac.repository.*;
import com.xydl.cac.service.ParamBindService;
import lombok.extern.slf4j.Slf4j;
@ -11,6 +12,7 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Service
@Slf4j
@ -28,7 +30,11 @@ public class ParamBindServiceImpl implements ParamBindService {
@Resource
IcdConfigTypeRepository typeRepository;
@Resource
IcdConfigTypeInstRepository typeInstRepository;
IcdConfigTypeInstRepository instRepository;
@Resource
IcdConfigTypeAttRepository attRepository;
@Resource
RptparamindexRepository rptparamindexRepository;
@Override
public List<Bdz> getTree() throws Exception {
@ -56,7 +62,7 @@ public class ParamBindServiceImpl implements ParamBindService {
List<IcdConfigTypeInst> result = new ArrayList<>();
List<IcdConfigType> typeList = typeRepository.findByIedName(iedName);
for (IcdConfigType type : typeList) {
List<IcdConfigTypeInst> instList = typeInstRepository.findByIcdConfigTypeId(type.getId());
List<IcdConfigTypeInst> instList = instRepository.findByIcdConfigTypeId(type.getId());
for (IcdConfigTypeInst inst : instList) {
String param = type.getIedName() + type.getLdeviceInst() + "/" + type.getLnClass()
+ inst.getInst();
@ -66,4 +72,64 @@ public class ParamBindServiceImpl implements ParamBindService {
}
return result;
}
@Override
public List<Rptparamindex> preview(BindingModel item) throws Exception {
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(item.getBindingId());
if (!optionalInst.isPresent()) {
throw new Exception("未找到该ICD配置类型实例, eqmid=" + item.getEqmid() + ", bindingId=" + item.getBindingId());
}
IcdConfigTypeInst inst = optionalInst.get();
Optional<IcdConfigType> optionalType = typeRepository.findById(inst.getIcdConfigTypeId());
if (!optionalType.isPresent()) {
throw new Exception("未找到该实例对应的ICD配置类型, bindingId=" + item.getBindingId());
}
IcdConfigType type = optionalType.get();
List<Rptparamindex> result = new ArrayList<>();
String param = type.getIedName() + type.getLdeviceInst() + "/" + type.getLnClass()
+ inst.getInst();
List<IcdConfigTypeAtt> attList = attRepository.findByIcdConfigTypeId(type.getId());
for (IcdConfigTypeAtt att : attList) {
String paramindex = param + "$" + att.getLastName();
Optional<Rptparamindex> optionalRpt = rptparamindexRepository.findById(paramindex);
if (!optionalRpt.isPresent()) {
throw new Exception("未找到该Rptparamindex对象参引=" + paramindex);
}
Rptparamindex rpt = optionalRpt.get();
rpt.setTablename(type.getTableName());
rpt.setColname(att.getColName());
rpt.setEqmid(item.getEqmid());
result.add(rpt);
}
return result;
}
private void bindOne(Integer eqmid, Integer bindingId) throws Exception {
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(bindingId);
if (!optionalInst.isPresent()) {
throw new Exception("未找到该ICD配置类型实例, eqmid=" + eqmid + ", bindingId=" + bindingId);
}
IcdConfigTypeInst inst = optionalInst.get();
Optional<IcdConfigType> optionalType = typeRepository.findById(inst.getIcdConfigTypeId());
if (!optionalType.isPresent()) {
throw new Exception("未找到该实例对应的ICD配置类型, bindingId=" + bindingId);
}
IcdConfigType type = optionalType.get();
String param = type.getIedName() + type.getLdeviceInst() + "/" + type.getLnClass()
+ inst.getInst();
List<IcdConfigTypeAtt> attList = attRepository.findByIcdConfigTypeId(type.getId());
for (IcdConfigTypeAtt att : attList) {
String paramindex = param + "$" + att.getLastName();
Optional<Rptparamindex> optionalRpt = rptparamindexRepository.findById(paramindex);
if (!optionalRpt.isPresent()) {
throw new Exception("未找到该Rptparamindex对象参引=" + paramindex);
}
Rptparamindex rpt = optionalRpt.get();
rpt.setTablename(type.getTableName());
rpt.setColname(att.getColName());
rpt.setEqmid(eqmid);
rptparamindexRepository.save(rpt);
}
}
}

@ -65,7 +65,7 @@ public class IcdXmlUtil {
result.put(key, config);
}
config.addInst(lnInst);
config.addAtt(doName, dai);
config.addAtt(doName, param);
}
}
}

Loading…
Cancel
Save