doum
8 小时以前 cef5f19b9dbe6487942086c9e8896eac40b21e4f
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/thrid/BoardServiceImpl.java
@@ -45,8 +45,10 @@
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@@ -95,6 +97,9 @@
    private PlatformDeviceMapper platformDeviceMapper;
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private RedisTemplate<String,Object> stringRedisTemplate;
    @Value("${debug_model}")
    private Boolean isDebug;
    /**
@@ -216,6 +221,32 @@
     */
    @Override
    public List<PageRegionInfoResponse> getRegionTree(CarmeraListVO req){
        List<PageRegionInfoResponse> allList =null;
        if(req.getRefresh() == 0){
            //默认取缓存数据
            allList =   (List<PageRegionInfoResponse>) stringRedisTemplate.opsForValue().get(Constants.RedisKeys.HK_REGIONS_TREE);
        }
        if(allList!=null && allList.size()>0){
            return allList;
        }
        allList =  getAllRegionList();
        if(allList==null && allList.size()==0){
            return  allList;
        }
        if(Constants.equalsInteger(req.getWithCameras(),Constants.ONE)){
            initReginCameralList(allList,req );//获取全部监控点数据
        }else  if(Constants.equalsInteger(req.getWithCameras(),Constants.TWO)){
            initReginCameralList(allList,req );//获取全部监控点数据
            initReginFireDeviveList(allList, req);//获取全部监控点数据
            initReginSensorList(allList,req);//获取全部监控点数据
        }
        List<PageRegionInfoResponse> data = new RegionTreeVO(allList).buildTree();
        //加入缓存
        stringRedisTemplate.opsForValue().set(Constants.RedisKeys.HK_REGIONS_TREE,data);
        return  data;
    }
    private List<PageRegionInfoResponse> getAllRegionList() {
        List<PageRegionInfoResponse> allList = new ArrayList<>();
        boolean hasNext = true;
        int curTotal = 0;
@@ -242,13 +273,66 @@
            }
            curPage++;
        }
        if(Constants.equalsInteger(req.getWithCameras(),Constants.ONE)){
            initReginCameralList(allList,req.getName());//获取全部监控点数据
        }
        List<PageRegionInfoResponse> data = new RegionTreeVO(allList).buildTree();
        return  data;
        return allList;
    }
    private void initReginCameralList(List<PageRegionInfoResponse> allList,String name) {
    private void initReginFireDeviveList(List<PageRegionInfoResponse> allList,CarmeraListVO req) {
        String name =req.getName();
        List<CarmeraListVO> carmeraListVOList = fireDeviceList();
        if(carmeraListVOList!=null && carmeraListVOList.size()>0){
            for(PageRegionInfoResponse p : allList){
                for(CarmeraListVO c : carmeraListVOList){
                    if(StringUtils.equals(p.getIndexCode(),c.getReginCode()) ){
                        if(p.getDeviceList()==null){
                            p.setDeviceList(new ArrayList<>());
                        }
                        p.getDeviceList().add(c);
                    }
                }
            }
        }
    }
    private void initReginSensorList(List<PageRegionInfoResponse> allList,CarmeraListVO req) {
        String name =req.getName();
        List<CarmeraListVO> carmeraListVOList = sensorList();
        if(carmeraListVOList!=null && carmeraListVOList.size()>0){
            for(PageRegionInfoResponse p : allList){
                for(CarmeraListVO c : carmeraListVOList){
                    if(StringUtils.equals(p.getIndexCode(),c.getReginCode())){
                        if(p.getSensorList()==null){
                            p.setSensorList(new ArrayList<>());
                        }
                        p.getSensorList().add(c);
                    }
                }
            }
        }
    }
    @PostConstruct
    public void cacheRegionAndDeviceData(){
        log.error("===============缓存海康平台区域设备信息======开始============");
        try {
            CarmeraListVO param  =new CarmeraListVO();
            param.setWithCameras(2);
            param.setRefresh(1);
            List<PageRegionInfoResponse>  resultTree = getRegionTree(param);
            List<PageRegionInfoResponse>  result = getAllRegionList();
            List<CarmeraListVO> carmeraListVOList = initAllReginCameralList(result);
            List<CarmeraListVO> sensorList = sensorList();
            List<CarmeraListVO> fireDeviceList = fireDeviceList();
            stringRedisTemplate.opsForValue().set(Constants.RedisKeys.HK_REGIONS_TREE,resultTree);
            stringRedisTemplate.opsForValue().set(Constants.RedisKeys.HK_REGIONS,result);//平铺区域列表
            stringRedisTemplate.opsForValue().set(Constants.RedisKeys.HK_CAMERAS,carmeraListVOList);//所有监控点数据
            stringRedisTemplate.opsForValue().set(Constants.RedisKeys.HK_FIRE_DEVICE,fireDeviceList);//所有消防设备数据
            stringRedisTemplate.opsForValue().set(Constants.RedisKeys.HK_SENSOR,sensorList);//所有传感器
            log.error("===============缓存海康平台区域设备信息======成功============");
        }catch (Exception e){
            e.printStackTrace();
            log.error("===============缓存海康平台区域设备信息失败==================");
        }
    }
    private void initReginCameralList(List<PageRegionInfoResponse> allList,CarmeraListVO req) {
        String name = req.getName();
        CarmeraListVO re = new CarmeraListVO();
        re.setName(name);
        List<CarmeraListVO> carmeraListVOList = cameraList(re);
@@ -256,15 +340,30 @@
            for(PageRegionInfoResponse p : allList){
                for(CarmeraListVO c : carmeraListVOList){
                    if(StringUtils.equals(p.getIndexCode(),c.getReginCode())
                            && (StringUtils.contains(c.getName(),name) ||StringUtils.isBlank(name))){
                            && (StringUtils.isBlank(name) || StringUtils.contains(c.getName(),name))){
                        if(p.getCarmeraList()==null){
                            p.setCarmeraList(new ArrayList<>());
                        }
                        c.setRegionName(p.getName());
                        p.getCarmeraList().add(c);
                    }
                }
            }
        }
    }
    private  List<CarmeraListVO> initAllReginCameralList(List<PageRegionInfoResponse> allList ) {
        CarmeraListVO re = new CarmeraListVO();
        List<CarmeraListVO> carmeraListVOList = cameraList(re);
        if(carmeraListVOList!=null && carmeraListVOList.size()>0){
            for(PageRegionInfoResponse p : allList){
                for(CarmeraListVO c : carmeraListVOList){
                    if(StringUtils.equals(p.getIndexCode(),c.getReginCode())){
                        c.setRegionName(p.getName());
                    }
                }
            }
        }
        return  carmeraListVOList;
    }
    /**
     * 获取区域树形结构数据
@@ -299,7 +398,7 @@
            curPage++;
        }
        if(Constants.equalsInteger(req.getWithCameras(),Constants.ONE)){
            initReginCameralList(allList,req.getName());//获取全部监控点数据
            initReginCameralList(allList,req);//获取全部监控点数据
        }
        return  allList;
    }
@@ -346,6 +445,114 @@
        }
        return  data;
    }
    public  List<CarmeraListVO> sensorList(){
        List<SensorStatusListResponse> allList = new ArrayList<>();
        boolean hasNext = true;
        int curTotal = 0;
        int curPage = 1;
        while (hasNext){
            //分页遍历循环查询所有门禁设备数据
            SensorStatusListRequest param = new SensorStatusListRequest();
            param.setRegionIndexCode("-1");
            param.setIncludeSubNode(1);
            param.setPageSize(100);
            param.setPageNo(curPage);
            BaseResponse<BaseListPageResponse<SensorStatusListResponse>> response = HKService.sensorStatusSearch(param);
            if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
            }
            BaseListPageResponse<SensorStatusListResponse> r = response.getData();
            curTotal += 100;
            if(curTotal >= r.getTotal()){
                hasNext = false;
            }
            if(r.getList() == null || r.getList().size()==0){
                hasNext =false;
            }else{
                allList.addAll(r.getList());
            }
            curPage++;
        }
        List<CarmeraListVO> data = new ArrayList<>();
        for(SensorStatusListResponse p : allList){
                CarmeraListVO t = new CarmeraListVO();
                t.setIndexCode(p.getIndexCode());
                t.setReginCode(p.getRegionIndexCode());
                t.setName(p.getCn());
                t.setStatus(p.getUnitStatus());
                t.setRegionName(p.getRegionName());
                 //0:未注册 1:正常 2: 修复中 3:异常状态
                if(t.getStatus()!=null && t.getStatus() == 0){
                    t.setStatusName("未注册");
                }
                if(t.getStatus()!=null && t.getStatus() == 1){
                    t.setStatusName("正常");
                }
                if(t.getStatus()!=null && t.getStatus() == 2){
                    t.setStatusName("修复中");
                }
                if(t.getStatus()!=null && t.getStatus() == 3){
                    t.setStatusName("异常状态");
                }
                data.add(t);
        }
        return  data;
    }
    public  List<CarmeraListVO> fireDeviceList(){
        List<FireDeviceStatusListResponse> allList = new ArrayList<>();
        boolean hasNext = true;
        int curTotal = 0;
        int curPage = 1;
        while (hasNext){
            //分页遍历循环查询所有门禁设备数据
            FireDeviceStatuslListRequest param = new FireDeviceStatuslListRequest();
            param.setRegionIndexCode("-1");
            param.setPageSize(100);
            param.setIncludeSubNode(1);
            param.setPageNo(curPage);
            BaseResponse<BaseListPageResponse<FireDeviceStatusListResponse>> response = HKService.fireDeviceStatusSearch(param);
            if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,海康同步数据失败~");
            }
            BaseListPageResponse<FireDeviceStatusListResponse> r = response.getData();
            curTotal += 100;
            if(curTotal >= r.getTotal()){
                hasNext = false;
            }
            if(r.getList() == null || r.getList().size()==0){
                hasNext =false;
            }else{
                allList.addAll(r.getList());
            }
            curPage++;
        }
        List<CarmeraListVO> data = new ArrayList<>();
        for(FireDeviceStatusListResponse p : allList){
                CarmeraListVO t = new CarmeraListVO();
                t.setIndexCode(p.getIndexCode());
                t.setReginCode(p.getRegionIndexCode());
                t.setName(p.getCn());
                t.setStatus(p.getUnitStatus());
                t.setRegionName(p.getRegionName());
                 //0:未注册 1:正常 2: 修复中 3:异常状态
                if(t.getStatus()!=null && t.getStatus() == 0){
                    t.setStatusName("未注册");
                }
                if(t.getStatus()!=null && t.getStatus() == 1){
                    t.setStatusName("正常");
                }
                if(t.getStatus()!=null && t.getStatus() == 2){
                    t.setStatusName("修复中");
                }
                if(t.getStatus()!=null && t.getStatus() == 3){
                    t.setStatusName("异常状态");
                }
                data.add(t);
        }
        return  data;
    }
    @Override
    public    List<PageFireChannelInfoResponse> fireChannelList(){
        List<PageFireChannelInfoResponse> allList = new ArrayList<>();