From 1c7f1a24f507c5f852445132b56b4e6344928be2 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 30 Jun 2023 16:00:13 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E7=AB=99=E7=82=B9=E9=9B=86=E4=B8=AD?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E5=B1=9E=E6=80=A7=E9=85=8D=E7=BD=AE=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=9B=91=E6=B5=8B=E7=82=B9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StationAttributeController.java | 9 +-- .../station/service/IStationAttributeService.java | 2 +- .../service/impl/StationAttributeServiceImpl.java | 76 +++++++++++++++++----- 3 files changed, 67 insertions(+), 20 deletions(-) diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationAttributeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationAttributeController.java index eede11e..0f6a0d0 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationAttributeController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationAttributeController.java @@ -91,12 +91,13 @@ public class StationAttributeController extends BladeController { return R.status(stationAttributeService.deleteLogic(Func.toLongList(ids))); } - @PutMapping("/bandingMonitor") + @GetMapping("/bandingMonitor") @ApiOperation("根据设备编码更新集中监控监测点绑定") @ApiOperationSupport(order = 4) - public R> bandingMonitor(@ApiParam(value = "设备编码",required = true) String emCode, + public R> bandingMonitor(@ApiParam(value = "站点编码",required = true) String stationCode, + @ApiParam(value = "设备编码",required = true) String emCode, @ApiParam(value = "站点类型",required = true) String stationType, - @ApiParam(value = "设备类型",required = true) String emType) { - return R.data(stationAttributeService.bandingMonitor(emCode,stationType,emType)); + @ApiParam(value = "机组类型",required = true) String setType) { + return R.data(stationAttributeService.bandingMonitor(stationCode,emCode,stationType,setType)); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationAttributeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationAttributeService.java index d3ecdb8..9f0bdff 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationAttributeService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationAttributeService.java @@ -45,5 +45,5 @@ public interface IStationAttributeService extends BaseService bandingMonitor(String emCode,String stationType,String emType); + List bandingMonitor(String stationCode,String emCode,String stationType,String setType); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationAttributeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationAttributeServiceImpl.java index e9dd316..9a60ed7 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationAttributeServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationAttributeServiceImpl.java @@ -209,13 +209,14 @@ public class StationAttributeServiceImpl extends BaseServiceImpl bandingMonitor(String emCode,String stationType,String emType) { + public List bandingMonitor(String stationCode,String emCode,String stationType,String setType) { List result; // 获取集中监控属性配置 List attributes = attributeService.list(Wrappers.lambdaQuery() .eq(FocusAttributeEntity::getDomainId, stationType) - .eq(FocusAttributeEntity::getGroupId, emType) + .eq(FocusAttributeEntity::getGroupId, setType) .eq(FocusAttributeEntity::getStatus, 0) + .orderByAsc(FocusAttributeEntity::getSort) ); // 标识 List signages = attributes.stream().map(FocusAttributeEntity::getSignage).filter(Func::isNotEmpty).collect(Collectors.toList()); @@ -225,19 +226,64 @@ public class StationAttributeServiceImpl extends BaseServiceImpl> deviceChildrenListResult = deviceClient.getRealId(deviceChildrenDTO); - boolean facAttrFlag = deviceChildrenListResult.isSuccess() && CollectionUtil.isNotEmpty(deviceChildrenListResult.getData()); - // 根据集中监控属性配置获取站点集中监控属性配置 - Function convert = focusAttr -> { - StationAttributeVo vo = BeanUtil.copy(focusAttr,StationAttributeVo.class); - if(facAttrFlag) { - List data = deviceChildrenListResult.getData(); - Optional facAttrOptional = data.stream().filter(attr -> focusAttr.getSignage().equals(attr.getSignage())).findAny(); - vo.setMonitorId(facAttrOptional.map(DeviceChildrenVO::getRealId).orElse(null)); - vo.setMonitorName(facAttrOptional.map(DeviceChildrenVO::getName).orElse(null)); - } - return vo; - }; - result = attributes.stream().map(convert).collect(Collectors.toList()); + List modelAttr = deviceChildrenListResult.isSuccess() && CollectionUtil.isNotEmpty(deviceChildrenListResult.getData()) + ? deviceChildrenListResult.getData() : new ArrayList<>(); + // 获取 + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery() + .eq(StationAttributeEntity::getStationId, stationCode) + .eq(StationAttributeEntity::getEmCode, emCode); + List stationAttrList = this.list(queryWrapper); + result = attributes.stream().map(focusAttr -> this.fillFacAttr(modelAttr,focusAttr,stationCode,emCode)) + .map(stationAttr -> this.fillAttrId(stationAttrList,stationAttr)) + .sorted(Comparator.comparing(StationAttributeVo::getSort,Comparator.nullsLast(Integer::compareTo))) + .collect(Collectors.toList()); return result; } + + /** + * 根据请求设备实例物模型属性填充集中监控属性配置采集点 + * @param modelAttr 设备实例物模型属性 + * @param focusAttr 集中监控属性配置 + * @return + */ + private StationAttributeVo fillFacAttr(List modelAttr,FocusAttributeEntity focusAttr,String stationCode,String emCode) { + StationAttributeVo vo = BeanUtil.copy(focusAttr,StationAttributeVo.class); + Optional facAttrOptional = modelAttr.stream().filter(attr -> focusAttr.getSignage().equals(attr.getSignage())).findAny(); + vo.setMonitorId(facAttrOptional.map(DeviceChildrenVO::getRealId).orElse(null)); + vo.setMonitorName(facAttrOptional.map(DeviceChildrenVO::getName).orElse(null)); + vo.setStationId(stationCode); + vo.setEmCode(emCode); + vo.setEnableShow(true); + vo.setId(null); + vo.setCreateUser(null); + vo.setCreateDept(null); + vo.setCreateTime(null); + vo.setUpdateTime(null); + vo.setUpdateUser(null); + return vo; + } + + /** + * 填充属性ID + * @param stationAttrList 已保存进数据库的记录 + * @param stationAttr 填充采集点后的属性模板 + * @return + */ + private StationAttributeVo fillAttrId(List stationAttrList,StationAttributeVo stationAttr) { + if(CollectionUtil.isNotEmpty(stationAttrList)) { + Optional attribute = stationAttrList.stream().filter(sa -> stationAttr.getAttributes().equals(sa.getAttributes())).findAny(); + if(attribute.isPresent()) { + StationAttributeVo result = BeanUtil.copy(attribute.get(),StationAttributeVo.class); + result.setSignage(stationAttr.getSignage()); + result.setSignageName(stationAttr.getSignageName()); + result.setMonitorId(stationAttr.getMonitorId()); + result.setMonitorName(stationAttr.getMonitorName()); + result.setUpdateUser(null); + result.setUpdateTime(null); + return result; + } + stationAttr.setSort(null); + } + return stationAttr; + } }