Newer
Older
huludao / src / main / java / com / newfiber / api / pc / service / impl / RegisionStationServiceImpl.java
package com.newfiber.api.pc.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.newfiber.api.config.CameraNodeTree;
import com.newfiber.api.core.commons.CustomException;
import com.newfiber.api.core.commons.ResultCode;
import com.newfiber.api.pc.dao.ConfigCameraRegionCodeMapper;
import com.newfiber.api.pc.dao.RegionStationMapper;
import com.newfiber.api.pc.model.entity.CameraResource;
import com.newfiber.api.pc.model.hikvsion.RegionStation;
import com.newfiber.api.pc.model.vo.CameraRegionCountVo;
import com.newfiber.api.pc.service.CameraResourceService;
import com.newfiber.api.pc.service.RegisionStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @ClassName RegisionStationService
 * @Description TODO
 * @Author 张鸿志
 * @Date 2021年3月4日20:21:14 20:21
 * Version 1.0
 **/
@Service
public class RegisionStationServiceImpl extends ServiceImpl<RegionStationMapper, RegionStation> implements RegisionStationService {

    @Autowired
    private CameraResourceService cameraResourceService;

    @Autowired
    private ConfigCameraRegionCodeMapper configCameraRegionCodeMapper;

    @Override
    public List<RegionStation> queryTreePage() {
        List<RegionStation> regionStations = this.selectList(null);
        List<CameraRegionCountVo> cameraRegionCountVos =  cameraResourceService.queryRegionCount();
        for (RegionStation regionStation : regionStations) {
            regionStation.setTotal(0);
            for (CameraRegionCountVo regionCountVo : cameraRegionCountVos) {
                //将查询出来的类别数量对象中的regionCode与摄像机分类对象中的regionIndexCode比较,如果相同,就将数量添加到该类别下
                if(regionCountVo.getRegionCode().equals(regionStation.getRegionIndexCode())){
                   if(regionCountVo.getStatus().equals(1)){
                       //在线的
                       regionStation.setOnlineCount(regionCountVo.getRegionCount());
                   }else{
                       //不在线的
                       regionStation.setNoOnlineCount(regionCountVo.getRegionCount());
                   }

                   regionStation.setTotal(regionStation.getTotal() + regionCountVo.getRegionCount());
                }
            }
        }
        regionStations.forEach(s -> {
            //如果总数不为null,就进行拼接名称操作
            if(!s.getTotal().equals(0)){
                if(StringUtils.isEmpty(s.getNoOnlineCount())){
                    s.setNoOnlineCount(0);
                }
                if(StringUtils.isEmpty(s.getOnlineCount())){
                    s.setOnlineCount(0);
                }
                s.setName(s.getName() + "(总数:" + s.getTotal() + " 在线:" + s.getOnlineCount() + " 离线:" + s.getNoOnlineCount() + ")");
            }
        });
        CameraNodeTree cameraNodeTree = new CameraNodeTree(regionStations);
        List<RegionStation> buildTree = cameraNodeTree.buildTree();
        return buildTree;
    }

    @Override
    public List<CameraResource> queryCameraResource(String indexCode) {
        if(StringUtils.isEmpty(indexCode)){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        EntityWrapper<CameraResource> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("region_index_code",indexCode);
        //先查询出所有的摄像头资源
        List<CameraResource> cameraResources = cameraResourceService.selectList(entityWrapper);
        //查询自己定义的摄像资源配置,然后替换region_index_code字段
//        List<ConfigCameraRegionCode> configCameraRegionCodes = configCameraRegionCodeMapper.selectList(null);
//        for (CameraResource cameraResource : cameraResources) {
//            for (ConfigCameraRegionCode configCameraRegionCode : configCameraRegionCodes) {
//                if(cameraResource.getIndexCode().equals(configCameraRegionCode.getCameraIndexCode())){
//                    cameraResource.setRegionIndexCode(configCameraRegionCode.getRegionIndexCode());
//                    break;
//                }
//            }
//        }
        //将摄像头资源替换后,只取我们想要indexCode的Regison
        //如果点击的indexCode为水务的code,那么就将其查到的数据填入其他里面
        //List<CameraResource> resourceList = cameraResources.stream().filter(s -> s.getRegionIndexCode().equals(indexCode)).collect(Collectors.toList());
        //System.out.println(JSON.toJSONString(resourceList));
        return cameraResources;
    }
}