feat: 增加绑定和查询绑定接口

haikang
huangfeng 1 year ago
parent 4b84f77cf4
commit abcb45858c

@ -3,6 +3,7 @@ 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.BindDetail;
import com.xydl.cac.model.BindingModel;
import com.xydl.cac.model.Response;
import com.xydl.cac.service.ParamBindService;
@ -47,4 +48,18 @@ public class ParamBindController extends BasicController {
return Response.success(result);
}
@PostMapping("bind")
@ApiOperation("绑定")
public Response<String> bind(@Validated @RequestBody BindingModel item) throws Exception {
bindService.bind(item);
return Response.success("OK");
}
@GetMapping("getBind")
@ApiOperation("查询绑定信息")
public Response<BindDetail> getBind(@Validated @NotNull(message = "eqmid不能为空!") @Param("eqmid") Integer eqmid) throws Exception {
BindDetail result = bindService.getBind(eqmid);
return Response.success(result);
}
}

@ -0,0 +1,21 @@
package com.xydl.cac.model;
import com.xydl.cac.entity.Rptparamindex;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
@Data
public class BindDetail {
@ApiModelProperty("eqmid")
Integer eqmid;
@ApiModelProperty("逻辑设备实例的Id")
Integer icdid;
@ApiModelProperty("表字段名")
List<ColumnModel> columnList;
@ApiModelProperty("绑定关系")
List<Rptparamindex> rptList;
}

@ -12,5 +12,5 @@ public class BindingModel {
Integer eqmid;
@NotNull(message = "逻辑设备实例的Id不能为空")
@ApiModelProperty("逻辑设备实例的Id")
Integer bindingId;
Integer icdid;
}

@ -10,6 +10,10 @@ import java.util.List;
@Repository
public interface ModevRepository extends JpaRepository<Modev, Integer>, JpaSpecificationExecutor<Modev> {
List<Modev> findByZsbid(Integer zsbid);
List<Modev> findByZsbidAndName(Integer zsbid,String name);
List<Modev> findByZsbidAndName(Integer zsbid, String name);
List<Modev> findByIcdidAndIdIsNot(Integer icdid, Integer id);
}

@ -3,6 +3,7 @@ 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.BindDetail;
import com.xydl.cac.model.BindingModel;
import java.util.List;
@ -14,4 +15,8 @@ public interface ParamBindService {
List<IcdConfigTypeInst> instList(String iedName);
List<Rptparamindex> preview(BindingModel item) throws Exception;
void bind(BindingModel item) throws Exception;
BindDetail getBind(Integer eqmid) throws Exception;
}

@ -1,10 +1,14 @@
package com.xydl.cac.service.impl;
import com.xydl.cac.entity.*;
import com.xydl.cac.model.BindDetail;
import com.xydl.cac.model.BindingModel;
import com.xydl.cac.model.ColumnModel;
import com.xydl.cac.repository.*;
import com.xydl.cac.service.DataService;
import com.xydl.cac.service.ParamBindService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -28,6 +32,8 @@ public class ParamBindServiceImpl implements ParamBindService {
@Resource
ModevRepository modevRepository;
@Resource
ModevTypeRepository modevTypeRepository;
@Resource
IcdConfigTypeRepository typeRepository;
@Resource
IcdConfigTypeInstRepository instRepository;
@ -35,6 +41,8 @@ public class ParamBindServiceImpl implements ParamBindService {
IcdConfigTypeAttRepository attRepository;
@Resource
RptparamindexRepository rptparamindexRepository;
@Resource
DataService dataService;
@Override
public List<Bdz> getTree() throws Exception {
@ -75,14 +83,14 @@ public class ParamBindServiceImpl implements ParamBindService {
@Override
public List<Rptparamindex> preview(BindingModel item) throws Exception {
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(item.getBindingId());
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(item.getIcdid());
if (!optionalInst.isPresent()) {
throw new Exception("未找到该ICD配置类型实例, eqmid=" + item.getEqmid() + ", bindingId=" + item.getBindingId());
throw new Exception("未找到该ICD配置类型实例, eqmid=" + item.getEqmid() + ", icdid=" + item.getIcdid());
}
IcdConfigTypeInst inst = optionalInst.get();
Optional<IcdConfigType> optionalType = typeRepository.findById(inst.getIcdConfigTypeId());
if (!optionalType.isPresent()) {
throw new Exception("未找到该实例对应的ICD配置类型, bindingId=" + item.getBindingId());
throw new Exception("未找到该实例对应的ICD配置类型, icdid=" + item.getIcdid());
}
IcdConfigType type = optionalType.get();
@ -105,15 +113,92 @@ public class ParamBindServiceImpl implements ParamBindService {
return result;
}
private void bindOne(Integer eqmid, Integer bindingId) throws Exception {
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(bindingId);
@Override
public void bind(BindingModel item) throws Exception {
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(item.getIcdid());
if (!optionalInst.isPresent()) {
throw new Exception("未找到该ICD逻辑设备实例, icdid=" + item.getIcdid());
}
IcdConfigTypeInst inst = optionalInst.get();
Optional<IcdConfigType> optionalType = typeRepository.findById(inst.getIcdConfigTypeId());
if (!optionalType.isPresent()) {
throw new Exception("未找到该实例对应的ICD配置类型, icdid=" + item.getIcdid());
}
IcdConfigType type = optionalType.get();
List<Modev> list = modevRepository.findByIcdidAndIdIsNot(item.getIcdid(), item.getEqmid());
if (!CollectionUtils.isEmpty(list)) {
throw new Exception("该逻辑设备实例已被" + list.get(0).getName() + "绑定");
}
Optional<Modev> optionalModev = modevRepository.findById(item.getEqmid());
if (!optionalModev.isPresent()) {
throw new Exception("未找到该监测装置");
}
Modev modev = optionalModev.get();
modev.setIcdid(item.getIcdid());
modevRepository.save(modev);
}
@Override
public BindDetail getBind(Integer eqmid) throws Exception {
Optional<Modev> optionalModev = modevRepository.findById(eqmid);
if (!optionalModev.isPresent()) {
throw new Exception("未找到该监测装置");
}
Modev modev = optionalModev.get();
BindDetail result = new BindDetail();
result.setEqmid(eqmid);
result.setIcdid(optionalModev.get().getIcdid());
Optional<ModevType> optionalModevType = modevTypeRepository.findById(modev.getModevtid());
if (optionalModevType.isPresent()) {
ModevType modevType = optionalModevType.get();
if (StringUtils.isNotBlank(modevType.getTablename())) {
List<ColumnModel> columnList = dataService.getDataTableColumns(modevType.getTablename());
result.setColumnList(columnList);
}
}
if (modev.getIcdid() != null) {
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(modev.getIcdid());
if (optionalInst.isPresent()) {
IcdConfigTypeInst inst = optionalInst.get();
Optional<IcdConfigType> optionalType = typeRepository.findById(inst.getIcdConfigTypeId());
if (optionalType.isPresent()) {
IcdConfigType type = optionalType.get();
String param = type.getIedName() + type.getLdeviceInst() + "/" + type.getLnClass()
+ inst.getInst();
List<Rptparamindex> rptList = new ArrayList<>();
List<IcdConfigTypeAtt> attList = attRepository.findByIcdConfigTypeId(type.getId());
for (IcdConfigTypeAtt att : attList) {
String paramindex = param + "$" + att.getLastName();
Rptparamindex rpt = new Rptparamindex();
Optional<Rptparamindex> optionalRpt = rptparamindexRepository.findById(paramindex);
if (optionalRpt.isPresent()) {
rpt = optionalRpt.get();
} else {
rpt.setParamindex(paramindex);
}
rpt.setTablename(type.getTableName());
rpt.setColname(att.getColName());
rpt.setEqmid(eqmid);
rptList.add(rpt);
}
result.setRptList(rptList);
}
}
}
return result;
}
private void bindOne(Integer eqmid, Integer icdid) throws Exception {
Optional<IcdConfigTypeInst> optionalInst = instRepository.findById(icdid);
if (!optionalInst.isPresent()) {
throw new Exception("未找到该ICD配置类型实例, eqmid=" + eqmid + ", bindingId=" + bindingId);
throw new Exception("未找到该ICD逻辑设备实例, eqmid=" + eqmid + ", icdid=" + icdid);
}
IcdConfigTypeInst inst = optionalInst.get();
Optional<IcdConfigType> optionalType = typeRepository.findById(inst.getIcdConfigTypeId());
if (!optionalType.isPresent()) {
throw new Exception("未找到该实例对应的ICD配置类型, bindingId=" + bindingId);
throw new Exception("未找到该实例对应的ICD配置类型, icdid=" + icdid);
}
IcdConfigType type = optionalType.get();
String param = type.getIedName() + type.getLdeviceInst() + "/" + type.getLnClass()

Loading…
Cancel
Save