diff --git a/src/main/java/com/xydl/cac/controller/ParamBindController.java b/src/main/java/com/xydl/cac/controller/ParamBindController.java index 387b098..be82afa 100644 --- a/src/main/java/com/xydl/cac/controller/ParamBindController.java +++ b/src/main/java/com/xydl/cac/controller/ParamBindController.java @@ -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 bind(@Validated @RequestBody BindingModel item) throws Exception { + bindService.bind(item); + return Response.success("OK"); + } + + @GetMapping("getBind") + @ApiOperation("查询绑定信息") + public Response getBind(@Validated @NotNull(message = "eqmid不能为空!") @Param("eqmid") Integer eqmid) throws Exception { + BindDetail result = bindService.getBind(eqmid); + return Response.success(result); + } + } diff --git a/src/main/java/com/xydl/cac/model/BindDetail.java b/src/main/java/com/xydl/cac/model/BindDetail.java new file mode 100644 index 0000000..1b8197d --- /dev/null +++ b/src/main/java/com/xydl/cac/model/BindDetail.java @@ -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 columnList; + @ApiModelProperty("绑定关系") + List rptList; +} diff --git a/src/main/java/com/xydl/cac/model/BindingModel.java b/src/main/java/com/xydl/cac/model/BindingModel.java index b8b06ae..f04a9f1 100644 --- a/src/main/java/com/xydl/cac/model/BindingModel.java +++ b/src/main/java/com/xydl/cac/model/BindingModel.java @@ -12,5 +12,5 @@ public class BindingModel { Integer eqmid; @NotNull(message = "逻辑设备实例的Id不能为空") @ApiModelProperty("逻辑设备实例的Id") - Integer bindingId; + Integer icdid; } diff --git a/src/main/java/com/xydl/cac/repository/ModevRepository.java b/src/main/java/com/xydl/cac/repository/ModevRepository.java index b75b912..13afcb6 100644 --- a/src/main/java/com/xydl/cac/repository/ModevRepository.java +++ b/src/main/java/com/xydl/cac/repository/ModevRepository.java @@ -10,6 +10,10 @@ import java.util.List; @Repository public interface ModevRepository extends JpaRepository, JpaSpecificationExecutor { + List findByZsbid(Integer zsbid); - List findByZsbidAndName(Integer zsbid,String name); + + List findByZsbidAndName(Integer zsbid, String name); + + List findByIcdidAndIdIsNot(Integer icdid, Integer id); } \ No newline at end of file diff --git a/src/main/java/com/xydl/cac/service/ParamBindService.java b/src/main/java/com/xydl/cac/service/ParamBindService.java index f04fa20..1c3d419 100644 --- a/src/main/java/com/xydl/cac/service/ParamBindService.java +++ b/src/main/java/com/xydl/cac/service/ParamBindService.java @@ -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 instList(String iedName); List preview(BindingModel item) throws Exception; + + void bind(BindingModel item) throws Exception; + + BindDetail getBind(Integer eqmid) throws Exception; } diff --git a/src/main/java/com/xydl/cac/service/impl/ParamBindServiceImpl.java b/src/main/java/com/xydl/cac/service/impl/ParamBindServiceImpl.java index 1b6e3ba..c873528 100644 --- a/src/main/java/com/xydl/cac/service/impl/ParamBindServiceImpl.java +++ b/src/main/java/com/xydl/cac/service/impl/ParamBindServiceImpl.java @@ -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 getTree() throws Exception { @@ -75,14 +83,14 @@ public class ParamBindServiceImpl implements ParamBindService { @Override public List preview(BindingModel item) throws Exception { - Optional optionalInst = instRepository.findById(item.getBindingId()); + Optional 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 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 optionalInst = instRepository.findById(bindingId); + @Override + public void bind(BindingModel item) throws Exception { + Optional optionalInst = instRepository.findById(item.getIcdid()); + if (!optionalInst.isPresent()) { + throw new Exception("未找到该ICD逻辑设备实例, icdid=" + item.getIcdid()); + } + IcdConfigTypeInst inst = optionalInst.get(); + Optional optionalType = typeRepository.findById(inst.getIcdConfigTypeId()); + if (!optionalType.isPresent()) { + throw new Exception("未找到该实例对应的ICD配置类型, icdid=" + item.getIcdid()); + } + IcdConfigType type = optionalType.get(); + + List list = modevRepository.findByIcdidAndIdIsNot(item.getIcdid(), item.getEqmid()); + if (!CollectionUtils.isEmpty(list)) { + throw new Exception("该逻辑设备实例已被" + list.get(0).getName() + "绑定"); + } + Optional 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 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 optionalModevType = modevTypeRepository.findById(modev.getModevtid()); + if (optionalModevType.isPresent()) { + ModevType modevType = optionalModevType.get(); + if (StringUtils.isNotBlank(modevType.getTablename())) { + List columnList = dataService.getDataTableColumns(modevType.getTablename()); + result.setColumnList(columnList); + } + } + if (modev.getIcdid() != null) { + Optional optionalInst = instRepository.findById(modev.getIcdid()); + if (optionalInst.isPresent()) { + IcdConfigTypeInst inst = optionalInst.get(); + Optional optionalType = typeRepository.findById(inst.getIcdConfigTypeId()); + if (optionalType.isPresent()) { + IcdConfigType type = optionalType.get(); + String param = type.getIedName() + type.getLdeviceInst() + "/" + type.getLnClass() + + inst.getInst(); + List rptList = new ArrayList<>(); + List attList = attRepository.findByIcdConfigTypeId(type.getId()); + for (IcdConfigTypeAtt att : attList) { + String paramindex = param + "$" + att.getLastName(); + Rptparamindex rpt = new Rptparamindex(); + Optional 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 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 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()