@ -1,32 +1,35 @@
package com.ruoyi.business.service.impl ;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.time.LocalTime ;
import java.time.ZoneOffset ;
import java.time.format.DateTimeFormatter ;
import java.util.* ;
import java.util.stream.Collectors ;
import com.ruoyi.business.domain.HwAlarmInfo ;
import com.ruoyi.business.domain.HwDevice ;
import com.ruoyi.business.domain.HwMonitorUnit ;
import com.ruoyi.business.domain.VO.* ;
import com.ruoyi.business.mapper.HwAlarmInfoMapper ;
import com.ruoyi.business.mapper.HwDeviceMapper ;
import com.ruoyi.business.mapper.HwElectronicFenceMapper ;
import com.ruoyi.business.mapper.HwMonitorUnitMapper ;
import com.ruoyi.business.service.IHwMonitorUnitService ;
import com.ruoyi.common.core.constant.TdEngineConstants ;
import com.ruoyi.common.core.domain.R ;
import com.ruoyi.common.core.exception.ServiceException ;
import com.ruoyi.common.core.utils.DateUtils ;
import com.ruoyi.common.core.utils.NumberUtils ;
import com.ruoyi.common.core.utils.StringUtils ;
import com.ruoyi.common.security.utils.SecurityUtils ;
import com.ruoyi.system.api.domain.SysUser ;
import com.ruoyi.system.api.model.LoginUser ;
import com.ruoyi.common.datascope.annotation.DataScope ;
import com.ruoyi.tdengine.api.RemoteTdEngineService ;
import com.ruoyi.tdengine.api.domain.DeviceStatus ;
import com.ruoyi.tdengine.api.domain.TdSelectDto ;
import com.ruoyi.tdengine.api.domain.TdSuperTableSelectVo ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import com.ruoyi.business.mapper.HwMonitorUnitMapper ;
import com.ruoyi.business.domain.HwMonitorUnit ;
import com.ruoyi.business.service.IHwMonitorUnitService ;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.time.LocalTime ;
import java.time.ZoneOffset ;
import java.time.format.DateTimeFormatter ;
import java.util.* ;
import java.util.stream.Collectors ;
/ * *
* 监 控 单 元 Service 业 务 层 处 理
@ -35,8 +38,7 @@ import com.ruoyi.business.service.IHwMonitorUnitService;
* @date 2023 - 0 8 - 31
* /
@Service
public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService
{
public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService {
@Autowired
private HwMonitorUnitMapper hwMonitorUnitMapper ;
@Autowired
@ -45,9 +47,8 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService
private RemoteTdEngineService remoteTdEgineService ;
@Autowired
private HwDeviceMapper hwDeviceMapper ;
@Autowired
private HwAlarmInfoMapper hwAlarmInfoMapper ;
/ * *
* 查 询 监 控 单 元
@ -56,106 +57,106 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService
* @return 监 控 单 元
* /
@Override
public HwMonitorUnit selectHwMonitorUnitByMonitorUnitId ( Long monitorUnitId )
{
public HwMonitorUnit selectHwMonitorUnitByMonitorUnitId ( Long monitorUnitId ) {
return hwMonitorUnitMapper . selectHwMonitorUnitByMonitorUnitId ( monitorUnitId ) ;
}
/ * *
* 查 询 区 域 数 量 站 场 景 区 总 数 百 分 比
* * /
* /
@Override
public List < HwMonitorUnitVo > selectMonitorPercentage ( ) {
// HwMonitorUnit queryMonitorUnit = new HwMonitorUnit();
// List<HwMonitorUnit> list = hwMonitorUnitMapper.selectHwMonitorUnitListJoinScene(queryMonitorUnit);
// Map<Long, List<HwMonitorUnit>> monitorUnitMap = list.stream()
// .collect(Collectors.groupingBy(HwMonitorUnit::getSceneId));
// List<HwMonitorUnitVo> monitorUnitVoList = new ArrayList<>();
//
//
// Set<Long> keys = monitorUnitMap.keySet();
// for(Long key:keys){
// Integer value = monitorUnitMap.get(key);
// System.out.println(key+"\t"+value);
// }
List < HwMonitorUnitVo > list = hwMonitorUnitMapper . selectMonitorPercentage ( ) ;
List < HwMonitorUnitVo > hwScenes = hwMonitorUnitMapper . selectSceneNameById ( ) ;
int count = hwScenes . size ( ) ;
if ( list . size ( ) < = hwScenes . size ( ) ) {
count = list . size ( ) ;
}
for ( int i = 0 ; i < count ; i + + ) {
for ( int j = 0 ; j < count ; j + + ) {
if ( list . get ( i ) . getSceneId ( ) . equals ( hwScenes . get ( i ) . getSceneId ( ) ) ) {
list . get ( i ) . setSceneName ( hwScenes . get ( i ) . getSceneName ( ) ) ;
list . stream ( ) . forEach ( l - > {
for ( int i = 0 ; i < hwScenes . size ( ) ; i + + ) {
if ( l . getSceneId ( ) . equals ( hwScenes . get ( i ) . getSceneId ( ) ) ) {
l . setSceneName ( hwScenes . get ( i ) . getSceneName ( ) ) ;
}
}
}
} ) ;
Integer value = 0 ;
//
Integer sums = 0 ;
if ( list . size ( ) > 5 ) {
for ( int i = 4 ; i < list . size ( ) ; i + + ) {
if ( list . get ( i ) . sum = = null ) {
list . get ( i ) . sum = 0 ;
}
value = value + list . get ( i ) . sum ;
}
}
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
if ( list . get ( i ) . sum = = null ) {
// if (list.size() > 5) {
// for (int i = 4; i < list.size(); i++) {//这是剩下的总数
// if (list.get(i).sum == null) {
// list.get(i).sum = 0;
// }
// value = value + list.get(i).sum;
// }
// }
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
if ( list . get ( i ) . sum = = null ) {
list . get ( i ) . sum = 0 ;
}
sums = sums + list . get ( i ) . sum ;
sums = sums + list . get ( i ) . sum ;
}
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
list . get ( i ) . setPercentage ( ( double ) ( list . get ( i ) . getSum ( ) / sums ) ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
HwMonitorUnitVo hwMonitorUnitVo = list . get ( i ) ;
hwMonitorUnitVo . setPercentage ( NumberUtils . getPercentage ( list . get ( i ) . getSum ( ) , sums ) ) ;
Long sceneId = hwMonitorUnitVo . getSceneId ( ) ;
HwAlarmInfo queryAlarmInfo = new HwAlarmInfo ( ) ;
queryAlarmInfo . setSceneId ( sceneId ) ;
List < HwAlarmInfo > alarmInfos = hwAlarmInfoMapper . selectHwAlarmInfoList ( queryAlarmInfo ) ;
Integer alarmInfoSize = alarmInfos = = null ? 0 : alarmInfos . size ( ) ;
hwMonitorUnitVo . setErr ( alarmInfoSize ) ;
}
HwMonitorUnitVo hwMonitorUnitVo = new HwMonitorUnitVo ( ) ;
hwMonitorUnitVo . setSceneName ( "其他" ) ;
hwMonitorUnitVo . setSum ( value ) ;
if ( list . size ( ) > 5 ) {
list . add ( 5 , hwMonitorUnitVo ) ;
return list . subList ( 0 , 5 ) ;
}
else {
return list ;
}
// HwMonitorUnitVo hwMonitorUnitVo = new HwMonitorUnitVo();
// hwMonitorUnitVo.setSceneName("其他");
// hwMonitorUnitVo.setSum(value);
// if (list.size() > 5) {
// list.add(5, hwMonitorUnitVo);
// return list.subList(0, 5);
// } else {
// return list;
// }
return list ;
}
//获取总的设备数量与监控单元数量
@Override
public AllNumsVo selectAllNums ( ) {
public AllNumsVo selectAllNums ( Long sceneId ) {
//监控单元
String monitor = hwMonitorUnitMapper . selectSubSetNums ( ) ;
String integer = hwMonitorUnitMapper . selectDeviceNums ( ) ;
System . out . println ( monitor + " dsaas " + integer ) ;
Integer monitor1 = 0 ;
Integer monitor2 = 0 ;
Integer monitor = hwMonitorUnitMapper . selectSubSetNums ( sceneId ) = = null ? 0
: hwMonitorUnitMapper . selectSubSetNums ( sceneId ) ;
Integer integer = hwMonitorUnitMapper . selectDeviceNums ( sceneId ) = = null ? 0
: hwMonitorUnitMapper . selectDeviceNums ( sceneId ) ;
AllNumsVo vo = new AllNumsVo ( ) ;
if ( monitor = = null ) {
monitor1 = 0 ;
}
else {
monitor1 = Integer . valueOf ( monitor ) ;
}
if ( integer = = null ) {
monitor2 = 0 ;
}
else {
monitor2 = Integer . valueOf ( integer ) ;
}
vo . setSubSum ( monitor1 ) ;
vo . setSum ( monitor2 ) ;
vo . setSubSum ( monitor ) ;
vo . setSum ( integer ) ;
return vo ;
}
@Override
public List < AllNumsVo > selectSenceAllNums ( ) {
List < AllNumsVo > allNumsVos = hwMonitorUnitMapper . selectAllNums ( ) ;
List < AllNumsVo > allNums = hwMonitorUnitMapper . selectsum ( ) ;
for ( int i = 0 ; i < allNums . size ( ) ; i + + ) {
for ( int j = 0 ; j < allNums . size ( ) ; j + + ) {
if ( allNums . get ( i ) . getSceneId ( ) . equals ( allNumsVos . get ( i ) . getSceneId ( ) ) ) {
allNums . get ( i ) . setSubSum ( allNumsVos . get ( i ) . getSubSum ( ) ) ;
}
}
}
return allNums ;
}
// @Override
// public List<AllNumsVo> selectSenceAllNums() {
// List<AllNumsVo> allNumsVos = hwMonitorUnitMapper.selectAllNums();
// List<AllNumsVo> allNums = hwMonitorUnitMapper.selectsum();
// for (int i = 0; i < allNums.size(); i++) {
// for (int j = 0; j < allNums.size(); j++) {
// if (allNums.get(i).getSceneId().equals(allNumsVos.get(i).getSceneId())) {
// allNums.get(i).setSubSum(allNumsVos.get(i).getSubSum());
// }
// }
// }
// return allNums;
// }
@Override
public List < HwMonitorUnit > selectLimitSubMonitorUnit ( ) {
@ -165,8 +166,8 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService
}
@Override
public List < AlarmStatsVo > selectAlarmStats ( ) {
return hwMonitorUnitMapper . selectAlarmStats ( ) ;
public List < AlarmStatsVo > selectAlarmStats ( Long sceneId ) {
return hwMonitorUnitMapper . selectAlarmStats ( sceneId ) ;
}
@ -177,155 +178,72 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService
* @return 监 控 单 元
* /
@Override
public List < HwMonitorUnit > selectHwMonitorUnitList ( HwMonitorUnit hwMonitorUnit )
{
public List < HwMonitorUnit > selectHwMonitorUnitList ( HwMonitorUnit hwMonitorUnit ) {
return hwMonitorUnitMapper . selectHwMonitorUnitList ( hwMonitorUnit ) ;
}
@Override
public SubDeviceSumVo selectSubDeviceSum ( Long sceneId ) {
int SubSum = hwMonitorUnitMapper . selectSubDeviceSum ( sceneId ) ;
List < HwDevice > hwDevices = hwDeviceMapper . selectDeviceNum ( sceneId ) ;
int onlineDevice = 0 ;
for ( int i = 0 ; i < hwDevices . size ( ) ; i + + ) {
if ( hwDevices . get ( i ) . getActiveStatus ( ) . equals ( "1" ) & & hwDevices . get ( i ) . getDeviceStatus ( ) . equals ( "1" ) ) {
onlineDevice = onlineDevice + 1 ;
}
}
AllNumsVo numsVo = selectAllNums ( sceneId ) ;
int onlineDeviceNum = hwDeviceMapper . getOnlineDeviceNum ( sceneId ) ;
SubDeviceSumVo subDeviceSumVo = new SubDeviceSumVo ( ) ;
subDeviceSumVo . setSubSum ( String. valueOf ( SubSum ) ) ;
subDeviceSumVo . setDeviceNum ( String. valueOf ( hwDevices . size ( ) ) ) ;
subDeviceSumVo . setOnlineDeviceNum ( String. valueOf ( onlineDevice ) ) ;
subDeviceSumVo . setSubSum ( numsVo . getSubSum ( ) ) ; //监控单元数量
subDeviceSumVo . setDeviceNum ( numsVo . getSum ( ) ) ; //设备数量
subDeviceSumVo . setOnlineDeviceNum ( onlineDeviceNum ) ; //在线设备数量
return subDeviceSumVo ;
}
//todo 电子围栏
@Override
public Integer selectElectronicNum ( Long sceneId ) {
List < Long > longs = hwMonitorUnitMapper . selectEleInScene ( sceneId ) ;
return null ;
}
@Override
public HwMonitorUnit selectHwmonitorUnitSub ( Long monitorUnitId ) {
return hwMonitorUnitMapper . selectHwMonitorUnitByMonitorUnitId ( monitorUnitId ) ;
return hwMonitorUnitMapper . selectHwMonitorUnitByMonitorUnitId ( monitorUnitId ) ;
}
//todo SysDeptServiceImpl类中的递归方法recursionFn(以实现)
@Override
// 加一个begintime参数, endtime参数 stream时间戳 从开始时间0点开始, 结束时间23.59.59结束
public Map < Object , Integer > selectTdengine ( String beginTime , String endTime , Long sceneId ) {
DeviceStatus queryDeviceStatus = new DeviceStatus ( ) ;
Map < String , Object > params = queryDeviceStatus . getParams ( ) ;
DateTimeFormatter ofPattern = DateTimeFormatter . ofPattern ( "yyyy-MM-dd" , Locale . CHINA ) ;
System . out . println ( ofPattern ) ;
LocalDate parse = LocalDate . parse ( beginTime , ofPattern ) ;
long begintime = parse . atStartOfDay ( ) . toInstant ( ZoneOffset . of ( "+8" ) ) . toEpochMilli ( ) ;
DateTimeFormatter ofPattern1 = DateTimeFormatter . ofPattern ( "yyyy-MM-dd" , Locale . CHINA ) ;
LocalDate parse1 = LocalDate . parse ( endTime , ofPattern ) ;
long endtime = LocalDateTime . of ( parse1 , LocalTime . MAX ) . toInstant ( ZoneOffset . of ( "+8" ) ) . toEpochMilli ( ) ;
params . put ( "beginTime" , begintime ) ;
params . put ( "endTime" , endtime ) ;
queryDeviceStatus . setParams ( params ) ;
if ( sceneId ! = null ) {
queryDeviceStatus . setSceneId ( sceneId ) ;
public List < HwMonitorUnit > selectTreeList ( List < HwMonitorUnit > hwMonitorUnits ) {
List < HwMonitorUnit > returnList = new ArrayList < > ( ) ;
List < Long > tempList = hwMonitorUnits . stream ( ) . map ( HwMonitorUnit : : getMonitorUnitId ) . collect ( Collectors . toList ( ) ) ;
List < HwMonitorUnit > treeList = new ArrayList < > ( ) ;
for ( HwMonitorUnit hwMonitorUnit : hwMonitorUnits ) {
if ( ! tempList . contains ( hwMonitorUnit . getParentId ( ) ) )
recursionFn ( hwMonitorUnits , hwMonitorUnit ) ;
returnList . add ( hwMonitorUnit ) ;
}
int sum = 0 ;
int values [ ] = new int [ 10 ] ;
Map < Object , Integer > valuesMap = new HashMap < > ( ) ;
//todo 使用id(以解决)
//map key时间戳, value List<DeviceStatus> 对象
R < ? > r = remoteTdEgineService . getOnlineDevicesGroupByDay ( queryDeviceStatus ) ;
Map < Long , List < DeviceStatus > > deviceStatusMap = ( Map < Long , List < DeviceStatus > > ) r . getData ( ) ;
List < DeviceStatus > list = ( List < DeviceStatus > ) remoteTdEgineService . getOnlineDevicesGroupByDay ( queryDeviceStatus ) ;
Set < Long > longs = deviceStatusMap . keySet ( ) ;
for ( Object key : longs ) {
List < DeviceStatus > deviceStatuses = deviceStatusMap . get ( key ) ;
for ( int i = 0 ; i < deviceStatuses . size ( ) ; i + + ) {
if ( deviceStatuses . get ( i ) . getDeviceType ( ) = = 1 ) {
sum = sum + hwMonitorUnitMapper . selectReleatedDeviceIdNums ( list . get ( i ) . getDeviceId ( ) ) ;
}
else {
sum = sum + 1 ;
}
valuesMap . put ( key , sum ) ;
for ( int i = 0 ; i < returnList . size ( ) ; i + + ) {
if ( returnList . get ( i ) . getParentId ( ) = = null ) {
treeList . add ( returnList . get ( i ) ) ;
}
}
return valuesMap ;
//设备类型==网关 根据releated_device_id = 网关设备设备id查询个数
//网关子设备数+非网关设备数( getDeviceType()! =1)
return treeList ;
}
@Override
public R < Map < String , Map < String , Object > > > selectLatestDataByTags ( Long monitorUnitId ) {
//
R < Map < String , Map < String , Object > > > latestDataByTags = new R < Map < String , Map < String , Object > > > ( ) ;
List < HwDevice > hwDevices = hwDeviceMapper . selectDeviceByMonitorId ( monitorUnitId ) ;
TdSelectDto tdSelectDto = new TdSelectDto ( ) ;
for ( int i = 0 ; i < hwDevices . size ( ) ; i + + ) {
tdSelectDto . setDatabaseName ( TdEngineConstants . PLATFORM_DB_NAME ) ;
tdSelectDto . setTableName ( TdEngineConstants . getDeviceDataTableName ( hwDevices . get ( i ) . getDeviceId ( ) ) ) ;
tdSelectDto . setTagsName ( hwDevices . get ( i ) . getDeviceCode ( ) ) ;
latestDataByTags = remoteTdEgineService . getLatestDataByTags ( tdSelectDto ) ;
}
return latestDataByTags ;
}
//todo SysDeptServiceImpl类中的递归方法recursionFn(以实现)
@Override
public List < HwMonitorUnit > selectTreeList ( List < HwMonitorUnit > hwMonitorUnits ) {
List < HwMonitorUnit > returnList = new ArrayList < > ( ) ;
List < Long > tempList = hwMonitorUnits . stream ( ) . map ( HwMonitorUnit : : getMonitorUnitId ) . collect ( Collectors . toList ( ) ) ;
List < HwMonitorUnit > treeList = new ArrayList < > ( ) ;
for ( HwMonitorUnit hwMonitorUnit : hwMonitorUnits ) {
if ( ! tempList . contains ( hwMonitorUnit . getParentId ( ) ) )
recursionFn ( hwMonitorUnits , hwMonitorUnit ) ;
returnList . add ( hwMonitorUnit ) ;
}
for ( int i = 0 ; i < returnList . size ( ) ; i + + ) {
if ( returnList . get ( i ) . getParentId ( ) = = null ) {
treeList . add ( returnList . get ( i ) ) ;
}
}
return treeList ;
}
private void recursionFn ( List < HwMonitorUnit > list , HwMonitorUnit t )
{
private void recursionFn ( List < HwMonitorUnit > list , HwMonitorUnit t ) {
// 得到子节点列表
List < HwMonitorUnit > childList = getChildList ( list , t ) ;
t . setChild ( childList ) ;
for ( HwMonitorUnit tChild : childList )
{
if ( hasChild ( list , tChild ) )
{
for ( HwMonitorUnit tChild : childList ) {
if ( hasChild ( list , tChild ) ) {
recursionFn ( list , tChild ) ;
}
}
}
private List < HwMonitorUnit > getChildList ( List < HwMonitorUnit > list , HwMonitorUnit t )
{
private List < HwMonitorUnit > getChildList ( List < HwMonitorUnit > list , HwMonitorUnit t ) {
List < HwMonitorUnit > tlist = new ArrayList < HwMonitorUnit > ( ) ;
Iterator < HwMonitorUnit > it = list . iterator ( ) ;
while ( it . hasNext ( ) )
{
while ( it . hasNext ( ) ) {
HwMonitorUnit n = ( HwMonitorUnit ) it . next ( ) ;
if ( StringUtils . isNotNull ( n . getParentId ( ) ) & & n . getParentId ( ) . longValue ( ) = = t . getMonitorUnitId ( ) . longValue ( ) )
{
if ( StringUtils . isNotNull ( n . getParentId ( ) ) & & n . getParentId ( ) . longValue ( ) = = t . getMonitorUnitId ( ) . longValue ( ) ) {
tlist . add ( n ) ;
}
}
return tlist ;
}
private boolean hasChild ( List < HwMonitorUnit > list , HwMonitorUnit t )
{
private boolean hasChild ( List < HwMonitorUnit > list , HwMonitorUnit t ) {
return getChildList ( list , t ) . size ( ) > 0 ? true : false ;
}
@ -336,32 +254,10 @@ public List<HwMonitorUnit> selectTreeList(List<HwMonitorUnit> hwMonitorUnits) {
* @return 结 果
* /
@Override
public int insertHwMonitorUnit ( HwMonitorUnit hwMonitorUnit )
{
//少一个离线报警规则 todo
//根据父级监控单元id查询是否关联了设备, 若关联则不能添加
if (
hwMonitorUnitMapper . selectDeviceRelevancyMontiorUnit ( hwMonitorUnit . getParentId ( ) ) = = 0
& & hwMonitorUnitMapper . selectElectronicFenceRelevancyMonitorUnit ( hwMonitorUnit . getParentId ( ) ) = = 0
) { //如果是无父级的监控单元, 后台赋null, 前端赋null会报错
if ( hwMonitorUnit . getParentId ( ) = = 0 ) {
hwMonitorUnit . setParentId ( null ) ;
}
//如果该监控单元拥有父级监控单元,则场景继承其父级监控单元
else if ( hwMonitorUnit . getParentId ( ) ! = 0 & & hwMonitorUnit . getParentId ( ) ! = null ) {
hwMonitorUnit . setSceneId (
hwMonitorUnitMapper . selectHwMonitorUnitByMonitorUnitId (
hwMonitorUnit . getParentId ( ) ) . getSceneId ( ) ) ;
}
LoginUser loginUser = SecurityUtils . getLoginUser ( ) ;
SysUser sysUser = loginUser . getSysUser ( ) ;
hwMonitorUnit . setTenantId ( sysUser . getTenantId ( ) ) ;
hwMonitorUnit . setCreateTime ( DateUtils . getNowDate ( ) ) ;
return hwMonitorUnitMapper . insertHwMonitorUnit ( hwMonitorUnit ) ;
}
return 0 ;
public int insertHwMonitorUnit ( HwMonitorUnit hwMonitorUnit ) {
this . checkRelatedDevices ( hwMonitorUnit ) ;
hwMonitorUnit . setCreateTime ( DateUtils . getNowDate ( ) ) ;
return hwMonitorUnitMapper . insertHwMonitorUnit ( hwMonitorUnit ) ;
}
/ * *
@ -371,8 +267,8 @@ public List<HwMonitorUnit> selectTreeList(List<HwMonitorUnit> hwMonitorUnits) {
* @return 结 果
* /
@Override
public int updateHwMonitorUnit ( HwMonitorUnit hwMonitorUnit )
{
public int updateHwMonitorUnit ( HwMonitorUnit hwMonitorUnit ) {
this . checkRelatedDevices ( hwMonitorUnit ) ;
hwMonitorUnit . setUpdateTime ( DateUtils . getNowDate ( ) ) ;
return hwMonitorUnitMapper . updateHwMonitorUnit ( hwMonitorUnit ) ;
}
@ -384,18 +280,7 @@ public List<HwMonitorUnit> selectTreeList(List<HwMonitorUnit> hwMonitorUnits) {
* @return 结 果
* /
@Override
public int deleteHwMonitorUnitByMonitorUnitIds ( Long [ ] monitorUnitIds )
{
//先查询是否有子集, 如果有返回error 如果没有则逻辑删除
for ( Long monitorUnitId : monitorUnitIds ) {
if ( hwMonitorUnitMapper . selectIsParent ( monitorUnitId ) ! = 0 ) {
return 0 ;
}
else {
hwMonitorUnitMapper . deleteHwMonitorUnitByMonitorUnitId ( monitorUnitId ) ;
return 1 ;
}
}
public int deleteHwMonitorUnitByMonitorUnitIds ( Long [ ] monitorUnitIds ) {
return hwMonitorUnitMapper . deleteHwMonitorUnitByMonitorUnitIds ( monitorUnitIds ) ;
}
@ -406,38 +291,118 @@ public List<HwMonitorUnit> selectTreeList(List<HwMonitorUnit> hwMonitorUnits) {
* @return 结 果
* /
@Override
public int deleteHwMonitorUnitByMonitorUnitId ( Long monitorUnitId )
{
public int deleteHwMonitorUnitByMonitorUnitId ( Long monitorUnitId ) {
return hwMonitorUnitMapper . deleteHwMonitorUnitByMonitorUnitId ( monitorUnitId ) ;
}
/ * *
* 查 询 监 控 单 元 树 结 构 信 息
*
* @param hwMonitorUnit 监 控 单 元 信 息
* @return 监 控 单 元 树 信 息 集 合
* /
@Override
public int getMonitorIsRelevancy ( Long monitorUnitId ) {
if ( hwMonitorUnitMapper . selectDeviceRelevancyMontiorUnit ( monitorUnitId ) = = 0
& & hwMonitorUnitMapper . selectElectronicFenceRelevancyMonitorUnit ( monitorUnitId ) = = 0
) {
return 1 ;
@DataScope ( tenantAlias = "hmu" )
public List < TreeSelectVo > selectMonitorTreeList ( HwMonitorUnit hwMonitorUnit ) {
List < HwMonitorUnit > hwMonitorUnits = this . selectHwMonitorUnitList ( hwMonitorUnit ) ;
return buildMonitorUnitTreeSelect ( hwMonitorUnits ) ;
}
/ * *
* 构 建 前 端 所 需 要 下 拉 树 结 构
*
* @param hwMonitorUnits 监 控 单 元 列 表
* @return 下 拉 树 结 构 列 表
* /
@Override
public List < TreeSelectVo > buildMonitorUnitTreeSelect ( List < HwMonitorUnit > hwMonitorUnits ) {
List < HwMonitorUnit > monitorUnitTrees = buildMonitorUnitTree ( hwMonitorUnits ) ;
return monitorUnitTrees . stream ( ) . map ( TreeSelectVo : : new ) . collect ( Collectors . toList ( ) ) ;
}
/ * *
* 构 建 前 端 所 需 要 树 结 构
*
* @param hwMonitorUnits 监 控 单 元 列 表
* @return 树 结 构 列 表
* /
@Override
public List < HwMonitorUnit > buildMonitorUnitTree ( List < HwMonitorUnit > hwMonitorUnits ) {
List < HwMonitorUnit > returnList = new ArrayList < HwMonitorUnit > ( ) ;
List < Long > tempList = hwMonitorUnits . stream ( ) . map ( HwMonitorUnit : : getMonitorUnitId ) . collect ( Collectors . toList ( ) ) ;
for ( HwMonitorUnit monitorUnit : hwMonitorUnits ) {
// 如果是顶级节点, 遍历该父节点的所有子节点
if ( ! tempList . contains ( monitorUnit . getParentId ( ) ) ) {
recursionFn1 ( hwMonitorUnits , monitorUnit ) ;
returnList . add ( monitorUnit ) ;
}
}
if ( returnList . isEmpty ( ) ) {
returnList = hwMonitorUnits ;
}
return 0 ;
return returnList ;
}
}
//remoteTdEngineSevice.getOnlineDevicesGroupByDay方法获取
// 参数实例:
// // params.put("beginTime", beginTime);
//// params.put("endTime", endTime);
//// queryDeviceStatus.setParams(params);
//// if (sceneId != null) {
//// queryDeviceStatus.setSceneId(sceneId);
//// }
//
// 这是IDEA参数传的参数Content-Type: application/json
// {
// "params": { "beginTime":1666666666666,"endTime":1766666666666 }
//
// }
//
// 如果在IDEA测试可以{
// "params": {"databaseName":"db_scene_1","superTableName":"st_ds_1",
// "beginTime":1666666666666,"endTime":1766666666666 }
// }
/ * *
* 递 归 列 表
* /
private void recursionFn1 ( List < HwMonitorUnit > list , HwMonitorUnit t ) {
// 得到子节点列表
List < HwMonitorUnit > childList = getChildList1 ( list , t ) ;
t . setChildren ( childList ) ;
for ( HwMonitorUnit tChild : childList ) {
if ( hasChild1 ( list , tChild ) ) {
recursionFn1 ( list , tChild ) ;
}
}
}
/ * *
* 得 到 子 节 点 列 表
* /
private List < HwMonitorUnit > getChildList1 ( List < HwMonitorUnit > list , HwMonitorUnit t ) {
List < HwMonitorUnit > tlist = new ArrayList < HwMonitorUnit > ( ) ;
Iterator < HwMonitorUnit > it = list . iterator ( ) ;
while ( it . hasNext ( ) ) {
HwMonitorUnit n = ( HwMonitorUnit ) it . next ( ) ;
if ( StringUtils . isNotNull ( n . getParentId ( ) ) & & n . getParentId ( ) . longValue ( ) = = t . getMonitorUnitId ( ) . longValue ( ) ) {
tlist . add ( n ) ;
}
}
return tlist ;
}
/ * *
* 判 断 是 否 有 子 节 点
* /
private boolean hasChild1 ( List < HwMonitorUnit > list , HwMonitorUnit t ) {
return getChildList1 ( list , t ) . size ( ) > 0 ? true : false ;
}
/ * *
* 查 询 监 控 单 元 列 表 , Join 监 控 单 元 类 型 , 租 户 和 场 景
*
* @param hwMonitorUnit 监 控 单 元
* @return 监 控 单 元
* /
@Override
@DataScope ( tenantAlias = "hmu" )
public List < HwMonitorUnit > selectHwMonitorUnitJoinList ( HwMonitorUnit hwMonitorUnit ) {
return hwMonitorUnitMapper . selectHwMonitorUnitJoinList ( hwMonitorUnit ) ;
}
private void checkRelatedDevices ( HwMonitorUnit hwMonitorUnit ) {
HwDevice queryDevice = new HwDevice ( ) ;
if ( hwMonitorUnit . getParentId ( ) ! = null ) {
queryDevice . setMonitorUnitId ( hwMonitorUnit . getParentId ( ) ) ;
List < HwDevice > devices = hwDeviceMapper . selectHwDeviceList ( queryDevice ) ;
if ( devices ! = null & & ! devices . isEmpty ( ) ) {
throw new ServiceException ( "此父级单元已关联设备,请重新选择" ) ;
}
}
}
}