|  | @@ -2,15 +2,19 @@ package com.xunmei.iot.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import cn.hutool.core.date.DateUtil;
 | 
	
		
			
				|  |  |  import cn.hutool.core.util.ObjectUtil;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.constant.SecurityConstants;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.enums.iot.BaseDeviceTypeEnum;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.enums.iot.DeviceTypeEnum;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.utils.NumberUtils;
 | 
	
		
			
				|  |  |  import com.xunmei.iot.dto.webStatisticBoard.BoardAlarmTrendDto;
 | 
	
		
			
				|  |  |  import com.xunmei.iot.dto.webStatisticBoard.BoardDeviceCountByTypeDto;
 | 
	
		
			
				|  |  | +import com.xunmei.iot.dto.webStatisticBoard.BoardDeviceCountDto;
 | 
	
		
			
				|  |  |  import com.xunmei.iot.enums.BoardPeriodEnum;
 | 
	
		
			
				|  |  |  import com.xunmei.iot.mapper.IotWebStatisticBoardMapper;
 | 
	
		
			
				|  |  |  import com.xunmei.iot.service.IIotWebStatisticBoardService;
 | 
	
		
			
				|  |  |  import com.xunmei.iot.vo.webStatisticBoard.*;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.RemoteOrgService;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.domain.SysOrg;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -27,10 +31,36 @@ public class IotWebStatisticBoardServiceImpl implements IIotWebStatisticBoardSer
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      IotWebStatisticBoardMapper iotWebStatisticBoardMapper;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    final List<String> monitorDeviceTypes = Arrays.asList(DeviceTypeEnum.DVS.getCode(), DeviceTypeEnum.MONITOR_CAMERA.getCode(), DeviceTypeEnum.NUMBER_CAMERA.getCode());
 | 
	
		
			
				|  |  | -    final List<String> fireDeviceTypes = Arrays.asList(DeviceTypeEnum.FSU_Smoke.getCode(), DeviceTypeEnum.FSU_Gas.getCode(), DeviceTypeEnum.FSU_TemperatureAndHumidity.getCode());
 | 
	
		
			
				|  |  | -    final List<String> environmentTypes = Arrays.asList(DeviceTypeEnum.FSU_Theft.getCode(), DeviceTypeEnum.FSU_Infrared.getCode(), DeviceTypeEnum.FSU_DoorMagnetic.getCode(),
 | 
	
		
			
				|  |  | -            DeviceTypeEnum.FSU_RollingShutterDoor.getCode(), DeviceTypeEnum.FSU_Water.getCode(), DeviceTypeEnum.FSU_Ups.getCode(), DeviceTypeEnum.FSU_AirConditioner.getCode());
 | 
	
		
			
				|  |  | +    final List<String> monitorDeviceTypes = Arrays.asList(BaseDeviceTypeEnum.Dvs.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.monitor_camera.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.number_camera.getCode());
 | 
	
		
			
				|  |  | +    final List<String> fireDeviceTypes = Arrays.asList(BaseDeviceTypeEnum.FSU_Smoke.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_Gas.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_TemperatureAndHumidity.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Smoke.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Temperature.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Humidity.getCode());
 | 
	
		
			
				|  |  | +    final List<String> environmentTypes = Arrays.asList(BaseDeviceTypeEnum.FSU_Theft.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_Infrared.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_DoorMagnetic.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_Water.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_Ups.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_AirConditioner.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_DoPowerControl.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_DoPowerCollection.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.FSU_DoPowerControlBoxButton.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_DoorSensor.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Infrared.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Soaking.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Displacement.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Broken.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Shock.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Tamper.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Intrusion.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_IMDualIdentification.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_Microwave.getCode(),
 | 
	
		
			
				|  |  | +            BaseDeviceTypeEnum.AlarmHostInput_EmergencyButton.getCode()
 | 
	
		
			
				|  |  | +    );
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      final SimpleDateFormat dayFormat = new SimpleDateFormat("M月d");
 | 
	
		
			
				|  |  |      final SimpleDateFormat monthFormat = new SimpleDateFormat("yy年M月");
 | 
	
	
		
			
				|  | @@ -43,6 +73,7 @@ public class IotWebStatisticBoardServiceImpl implements IIotWebStatisticBoardSer
 | 
	
		
			
				|  |  |          Integer environmentCount = list.stream().filter(i -> environmentTypes.contains(i.getDeviceType())).mapToInt(i -> i.getCount()).sum();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          BoardDeviceCountVo vo = BoardDeviceCountVo.builder()
 | 
	
		
			
				|  |  | +                .orgId(orgId)
 | 
	
		
			
				|  |  |                  .monitorCount(monitorCount)
 | 
	
		
			
				|  |  |                  .fireCount(fireCount)
 | 
	
		
			
				|  |  |                  .environmentCount(environmentCount)
 | 
	
	
		
			
				|  | @@ -57,16 +88,16 @@ public class IotWebStatisticBoardServiceImpl implements IIotWebStatisticBoardSer
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public List<BoardOnlineByTypeVo> deviceOnline(Long orgId) {
 | 
	
		
			
				|  |  | -        List<BoardOnlineByTypeVo> list = iotWebStatisticBoardMapper.deviceOnline(orgId, Arrays.asList(DeviceTypeEnum.DVS.getCode(),
 | 
	
		
			
				|  |  | -                DeviceTypeEnum.ALARM_HOST.getCode(), DeviceTypeEnum.FSU_Gateway.getCode()));
 | 
	
		
			
				|  |  | +        List<BoardOnlineByTypeVo> list = iotWebStatisticBoardMapper.deviceOnline(orgId, Arrays.asList(BaseDeviceTypeEnum.Dvs.getCode(),
 | 
	
		
			
				|  |  | +                BaseDeviceTypeEnum.FSU.getCode(), BaseDeviceTypeEnum.AlarmHost.getCode()));
 | 
	
		
			
				|  |  |          Set<String> hasDataType = list.stream().map(BoardOnlineByTypeVo::getDeviceType).collect(Collectors.toSet());
 | 
	
		
			
				|  |  |          list.addAll(initDeviceOnline().stream().filter(id -> !hasDataType.contains(id.getDeviceType())).collect(Collectors.toList()));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          for (BoardOnlineByTypeVo vo : list) {
 | 
	
		
			
				|  |  |              vo.setOnLineRate(NumberUtils.computeRate(vo.getDeviceCount(), vo.getOnLineCount()));
 | 
	
		
			
				|  |  | -            if (ObjectUtil.isNotEmpty(DeviceTypeEnum.getDescByCode(vo.getDeviceType()))) {
 | 
	
		
			
				|  |  | -                vo.setDeviceTypeName(DeviceTypeEnum.getDescByCode(vo.getDeviceType()));
 | 
	
		
			
				|  |  | -                if (ObjectUtil.equal(vo.getDeviceType(), DeviceTypeEnum.DVS.getCode())) {
 | 
	
		
			
				|  |  | +            if (ObjectUtil.isNotEmpty(BaseDeviceTypeEnum.getDescByCode(vo.getDeviceType()))) {
 | 
	
		
			
				|  |  | +                vo.setDeviceTypeName(BaseDeviceTypeEnum.getDescByCode(vo.getDeviceType()));
 | 
	
		
			
				|  |  | +                if (ObjectUtil.equal(vo.getDeviceType(), BaseDeviceTypeEnum.Dvs.getCode())) {
 | 
	
		
			
				|  |  |                      vo.setDeviceTypeName("监控主机");
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -82,10 +113,9 @@ public class IotWebStatisticBoardServiceImpl implements IIotWebStatisticBoardSer
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private List<BoardOnlineByTypeVo> initDeviceOnline() {
 | 
	
		
			
				|  |  |          List<BoardOnlineByTypeVo> list = new ArrayList<>();
 | 
	
		
			
				|  |  | -        list.add(BoardOnlineByTypeVo.builder().deviceType(DeviceTypeEnum.DVS.getCode()).deviceTypeName("监控主机").deviceCount(0).onLineCount(0).onLineRate(0f).build());
 | 
	
		
			
				|  |  | -        list.add(BoardOnlineByTypeVo.builder().deviceType(DeviceTypeEnum.ALARM_HOST.getCode()).deviceTypeName(DeviceTypeEnum.ALARM_HOST.getDesc()).deviceCount(0).onLineCount(0).onLineRate(0f).build());
 | 
	
		
			
				|  |  | -        list.add(BoardOnlineByTypeVo.builder().deviceType(DeviceTypeEnum.FSU_Gateway.getCode()).deviceTypeName(DeviceTypeEnum.FSU_Gateway.getDesc()).deviceCount(0).onLineCount(0).onLineRate(0f).build());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +        list.add(BoardOnlineByTypeVo.builder().deviceType(BaseDeviceTypeEnum.Dvs.getCode()).deviceTypeName("监控主机").deviceCount(0).onLineCount(0).onLineRate(0f).build());
 | 
	
		
			
				|  |  | +        list.add(BoardOnlineByTypeVo.builder().deviceType(BaseDeviceTypeEnum.AlarmHost.getCode()).deviceTypeName(BaseDeviceTypeEnum.AlarmHost.getDesc()).deviceCount(0).onLineCount(0).onLineRate(0f).build());
 | 
	
		
			
				|  |  | +        list.add(BoardOnlineByTypeVo.builder().deviceType(BaseDeviceTypeEnum.FSU.getCode()).deviceTypeName(BaseDeviceTypeEnum.FSU.getDesc()).deviceCount(0).onLineCount(0).onLineRate(0f).build());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          return list;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -205,8 +235,8 @@ public class IotWebStatisticBoardServiceImpl implements IIotWebStatisticBoardSer
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public BoardAlarmRateVo alarmRate(Long orgId) {
 | 
	
		
			
				|  |  | -        BoardAlarmRateVo vo=iotWebStatisticBoardMapper.alarmRate(orgId);
 | 
	
		
			
				|  |  | -        if(vo==null){
 | 
	
		
			
				|  |  | +        BoardAlarmRateVo vo = iotWebStatisticBoardMapper.alarmRate(orgId);
 | 
	
		
			
				|  |  | +        if (vo == null) {
 | 
	
		
			
				|  |  |              return new BoardAlarmRateVo();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -217,4 +247,49 @@ public class IotWebStatisticBoardServiceImpl implements IIotWebStatisticBoardSer
 | 
	
		
			
				|  |  |      public List<BoardAlarmInfoVo> alarmList(Long orgId) {
 | 
	
		
			
				|  |  |          return iotWebStatisticBoardMapper.alarmList(orgId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public List<BoardDeviceCountVo> deviceCountOfChildren(Long orgId) {
 | 
	
		
			
				|  |  | +        SysOrg sysOrg = orgService.selectOrgById(orgId, SecurityConstants.INNER);
 | 
	
		
			
				|  |  | +        List<SysOrg> children = new ArrayList<>();
 | 
	
		
			
				|  |  | +        if (sysOrg.getType() < 3 || sysOrg.getShortName().endsWith("地区行社") || sysOrg.getType() == 9) {
 | 
	
		
			
				|  |  | +            children = orgService.selectSysOrgByPathAndType(sysOrg.getPath(), 3, SecurityConstants.INNER);
 | 
	
		
			
				|  |  | +        } else if (sysOrg.getType() == 3 || sysOrg.getType() == 4) {
 | 
	
		
			
				|  |  | +            children = orgService.selectSysOrgByPathAndType(sysOrg.getPath(), 4, SecurityConstants.INNER);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            return Collections.emptyList();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        children.add(sysOrg);
 | 
	
		
			
				|  |  | +        List<BoardDeviceCountDto> deviceCountDtos = iotWebStatisticBoardMapper.orgDeviceCount(orgId);
 | 
	
		
			
				|  |  | +        List<BoardDeviceCountVo> vos = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (SysOrg child : children) {
 | 
	
		
			
				|  |  | +            BoardDeviceCountVo vo = BoardDeviceCountVo.builder()
 | 
	
		
			
				|  |  | +                    .orgId(child.getId())
 | 
	
		
			
				|  |  | +                    .environmentCount(0)
 | 
	
		
			
				|  |  | +                    .fireCount(0)
 | 
	
		
			
				|  |  | +                    .monitorCount(0)
 | 
	
		
			
				|  |  | +                    .build();
 | 
	
		
			
				|  |  | +            for (BoardDeviceCountDto deviceCountDto : deviceCountDtos) {
 | 
	
		
			
				|  |  | +                if (ObjectUtil.isEmpty(deviceCountDto.getOrgPath()) || !deviceCountDto.getOrgPath().startsWith(child.getPath())) {
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (monitorDeviceTypes.contains(deviceCountDto.getDeviceType())) {
 | 
	
		
			
				|  |  | +                    vo.setMonitorCount(vo.getMonitorCount() + deviceCountDto.getCount());
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (fireDeviceTypes.contains(deviceCountDto.getDeviceType())) {
 | 
	
		
			
				|  |  | +                    vo.setFireCount(vo.getFireCount() + deviceCountDto.getCount());
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (environmentTypes.contains(deviceCountDto.getDeviceType())) {
 | 
	
		
			
				|  |  | +                    vo.setEnvironmentCount(vo.getEnvironmentCount() + deviceCountDto.getCount());
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (vo.getMonitorCount() > 0 || vo.getFireCount() > 0 || vo.getEnvironmentCount() > 0) {
 | 
	
		
			
				|  |  | +                vos.add(vo);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return vos;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |