From 9779dd80f325cb2916009caf2e21a0d3a4cb3d26 Mon Sep 17 00:00:00 2001 From: yinq Date: Thu, 4 Jul 2024 15:54:53 +0800 Subject: [PATCH] =?UTF-8?q?update=20-=20=E8=83=BD=E6=BA=90=E6=95=B4?= =?UTF-8?q?=E7=82=B9=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/BaseMonitorInfo1ServiceImpl.java | 46 ++++++++++++++++--- .../mapper/report/ReportPointDnbMapper.xml | 24 +++++----- 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/op-modules/op-energy/src/main/java/com/op/energy/base/service/impl/BaseMonitorInfo1ServiceImpl.java b/op-modules/op-energy/src/main/java/com/op/energy/base/service/impl/BaseMonitorInfo1ServiceImpl.java index ad994faf5..d1ed9758a 100644 --- a/op-modules/op-energy/src/main/java/com/op/energy/base/service/impl/BaseMonitorInfo1ServiceImpl.java +++ b/op-modules/op-energy/src/main/java/com/op/energy/base/service/impl/BaseMonitorInfo1ServiceImpl.java @@ -107,11 +107,44 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service { @Override @DS("#header.poolName") public int updateBaseMonitorInfo(BaseMonitorInfo baseMonitorInfo) { + // 异常处理:若设备停用则更新所有父级 + if (StringUtils.isNotNull(baseMonitorInfo.getMonitorStatus()) && baseMonitorInfo.getMonitorStatus().equals(1L)){ + this.updateAllBaseMonitorInfo(); + } List baseMonitorInfos = baseMonitorInfoMapper.checkMonitorIdLegal(baseMonitorInfo); - if (baseMonitorInfos.size() > 1) { - throw new ServiceException("计量设备编号重复:" + baseMonitorInfo.getMonitorId()); + if (baseMonitorInfos.size() > 1){ + throw new ServiceException("计量设备编号重复:" + baseMonitorInfo.getMonitorId()); } try { + BaseMonitorInfo newParenMonitorInfo = baseMonitorInfoMapper.selectBaseMonitorInfoByObjid(baseMonitorInfo.getParentId()); + BaseMonitorInfo oldDeptMonitorInfo = selectBaseMonitorInfoByObjid(baseMonitorInfo.getObjid()); + if (StringUtils.isNotNull(newParenMonitorInfo) && StringUtils.isNotNull(oldDeptMonitorInfo)) + { + String newAncestors = newParenMonitorInfo.getAncestors() + "," + oldDeptMonitorInfo.getMonitorId(); + String oldAncestors = oldDeptMonitorInfo.getAncestors(); + baseMonitorInfo.setAncestors(newAncestors); + String[] split = baseMonitorInfo.getAncestors().split(","); + baseMonitorInfo.setGrade(split.length); + + updateMonitorChildren(baseMonitorInfo.getMonitorId(), newAncestors, oldAncestors); + } + + this.insertOrUpdateBaseTypeRelation(baseMonitorInfo.getMonitorId(),baseMonitorInfo.getBuildId(), + baseMonitorInfo.getBusinessId(),baseMonitorInfo.getSubentryId()); + } catch (Exception e) { + e.printStackTrace(); + } + baseMonitorInfo.setUpdateTime(DateUtils.getNowDate()); + baseMonitorInfo.setUpdateBy(SecurityUtils.getUsername()); + return baseMonitorInfoMapper.updateBaseMonitorInfo(baseMonitorInfo); + } + + /** + * 更新所有测控点 + */ + private void updateAllBaseMonitorInfo() { + List monitorInfoList = this.selectBaseMonitorInfoList(new BaseMonitorInfo()); + for (BaseMonitorInfo baseMonitorInfo : monitorInfoList) { BaseMonitorInfo newParenMonitorInfo = baseMonitorInfoMapper.selectBaseMonitorInfoByObjid(baseMonitorInfo.getParentId()); BaseMonitorInfo oldDeptMonitorInfo = selectBaseMonitorInfoByObjid(baseMonitorInfo.getObjid()); if (StringUtils.isNotNull(newParenMonitorInfo) && StringUtils.isNotNull(oldDeptMonitorInfo)) { @@ -126,14 +159,13 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service { this.insertOrUpdateBaseTypeRelation(baseMonitorInfo.getMonitorId(), baseMonitorInfo.getBuildId(), baseMonitorInfo.getBusinessId(), baseMonitorInfo.getSubentryId()); - } catch (Exception e) { - e.printStackTrace(); + baseMonitorInfo.setUpdateTime(DateUtils.getNowDate()); + baseMonitorInfo.setUpdateBy(SecurityUtils.getUsername()); + baseMonitorInfoMapper.updateBaseMonitorInfo(baseMonitorInfo); } - baseMonitorInfo.setUpdateTime(DateUtils.getNowDate()); - baseMonitorInfo.setUpdateBy(SecurityUtils.getUsername()); - return baseMonitorInfoMapper.updateBaseMonitorInfo(baseMonitorInfo); } + /** * 修改子元素关系 * diff --git a/op-modules/op-energy/src/main/resources/mapper/report/ReportPointDnbMapper.xml b/op-modules/op-energy/src/main/resources/mapper/report/ReportPointDnbMapper.xml index 10575ea65..84af652da 100644 --- a/op-modules/op-energy/src/main/resources/mapper/report/ReportPointDnbMapper.xml +++ b/op-modules/op-energy/src/main/resources/mapper/report/ReportPointDnbMapper.xml @@ -121,7 +121,7 @@ select ert.monitor_id, ert.monitor_name, ert.pointTime, sum(isnull(ert.expend,0)) expend from ( - select rpd.monitor_id, m.monitor_name, left(rpd.begin_time, 10) pointTime, rpd.expend + select rpd.monitor_id, m.monitor_name, left(CONVERT(VARCHAR(17), rpd.begin_time, 120), 10) pointTime, rpd.expend from report_point_dnb rpd left join base_monitor_info m on m.monitor_id = rpd.monitor_id @@ -167,7 +167,7 @@ - and left(rpd.begin_time, 10) between #{startDay} and #{endDay} + and left(CONVERT(VARCHAR(17), rpd.begin_time, 120), 10) between #{startDay} and #{endDay} ) ert @@ -178,21 +178,21 @@