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 ad994faf..d1ed9758 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,14 +107,19 @@ 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)) { + if (StringUtils.isNotNull(newParenMonitorInfo) && StringUtils.isNotNull(oldDeptMonitorInfo)) + { String newAncestors = newParenMonitorInfo.getAncestors() + "," + oldDeptMonitorInfo.getMonitorId(); String oldAncestors = oldDeptMonitorInfo.getAncestors(); baseMonitorInfo.setAncestors(newAncestors); @@ -124,8 +129,8 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service { updateMonitorChildren(baseMonitorInfo.getMonitorId(), newAncestors, oldAncestors); } - this.insertOrUpdateBaseTypeRelation(baseMonitorInfo.getMonitorId(), baseMonitorInfo.getBuildId(), - baseMonitorInfo.getBusinessId(), baseMonitorInfo.getSubentryId()); + this.insertOrUpdateBaseTypeRelation(baseMonitorInfo.getMonitorId(),baseMonitorInfo.getBuildId(), + baseMonitorInfo.getBusinessId(),baseMonitorInfo.getSubentryId()); } catch (Exception e) { e.printStackTrace(); } @@ -134,6 +139,33 @@ public class BaseMonitorInfo1ServiceImpl implements IBaseMonitorInfo1Service { 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)) { + 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()); + baseMonitorInfo.setUpdateTime(DateUtils.getNowDate()); + baseMonitorInfo.setUpdateBy(SecurityUtils.getUsername()); + 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 10575ea6..84af652d 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 @@