doum
17 小时以前 4936ba718f4ec2d069a9c28d07215573ed8548aa
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);//获取全部监控点数据
            initReginSensorList(allList);//获取全部监控点数据
        }
        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,64 @@
            }
            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 ) {
        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) {
        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 +338,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 +396,7 @@
            curPage++;
        }
        if(Constants.equalsInteger(req.getWithCameras(),Constants.ONE)){
            initReginCameralList(allList,req.getName());//获取全部监控点数据
            initReginCameralList(allList,req);//获取全部监控点数据
        }
        return  allList;
    }
@@ -343,6 +440,114 @@
                t.setStatusName(p.getStatusName());
                data.add(t);
            }
        }
        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;
    }
@@ -1505,23 +1710,41 @@
    @Override
    public    YearDeviceDataVO yearFightingAdminDeviceData(){
        YearDeviceDataVO data = new YearDeviceDataVO();
        FireStatisticRequest param = new FireStatisticRequest();
        param.setIndexCode("api_fire_statistic");
        BaseResponse<FireStatisticResponse> response = HKService.fireStatistic(param);
        if(response != null && StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE) && response.getData()!=null ) {
            data.setProtectNum(Constants.formatIntegerNum(response.getData().getMaintenanceNum()));
            data.setPlanProtectTotal(Constants.formatIntegerNum(response.getData().getDeviceTotalNum()));
//        FireStatisticRequest param = new FireStatisticRequest();
//        param.setIndexCode("api_fire_statistic");
//        BaseResponse<FireStatisticResponse> response = HKService.fireStatistic(param);
//        if(response != null && StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE) && response.getData()!=null ) {
//            data.setProtectNum(Constants.formatIntegerNum(response.getData().getMaintenanceNum()));
//            data.setPlanProtectTotal(Constants.formatIntegerNum(response.getData().getDeviceTotalNum()));
//        }
//        param = new FireStatisticRequest();
//        param.setIndexCode("api_fire_statistic_month");
//        BaseResponse<FireStatisticResponse> response1 = HKService.fireStatisticMonth(param);
//        if(response1 != null && StringUtils.equals(response1.getCode(), HKConstants.RESPONSE_SUCCEE)
//                && response1.getData()!=null ) {
//            data.setMonthAddNum(Constants.formatIntegerNum(response1.getData().getMaintenanceNumMonth()));
//            data.setMonthTotalNum(Constants.formatIntegerNum(response1.getData().getDeviceTotalNum()));
//        }
        data.setProtectNum(Constants.ZERO);
        data.setPlanProtectTotal(Constants.ZERO);
        data.setMonthAddNum(Constants.ZERO);
        data.setMonthTotalNum(Constants.ZERO);
        BaseResponse<SensorStatusStatisticResponse> response = HKService.sensorStatusStatistic();
        if(response != null && StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)
                && response.getData()!=null ) {
            data.setProtectNum(Constants.formatIntegerNum(response.getData().getSensorMainNum()));
            data.setPlanProtectTotal(Constants.formatIntegerNum(response.getData().getSensorNum()));
            data.setMonthAddNum(Constants.formatIntegerNum(response.getData().getSensorMainMonthNum()));
            data.setMonthTotalNum(Constants.formatIntegerNum(response.getData().getSensorNum()));
        }
        param = new FireStatisticRequest();
        param.setIndexCode("api_fire_statistic_month");
        BaseResponse<FireStatisticResponse> response1 = HKService.fireStatisticMonth(param);
        if(response1 != null && StringUtils.equals(response1.getCode(), HKConstants.RESPONSE_SUCCEE)
                && response1.getData()!=null ) {
            data.setMonthAddNum(Constants.formatIntegerNum(response1.getData().getMaintenanceNumMonth()));
            data.setMonthTotalNum(Constants.formatIntegerNum(response1.getData().getDeviceTotalNum()));
        }
        return data;
    }
    /**
     * 【消防管控】看板-分类和汇总的各状态设备数量
@@ -2373,7 +2596,8 @@
                .selectAs(Platform::getName,PlatformWarnEvent::getPlatformName)
                .leftJoin(Platform.class,Platform::getId,PlatformJob::getPlatformId)
                .eq(PlatformWarnEvent::getIsdeleted,Constants.ZERO)
                .apply("to_days(t.create_date) = to_days(now())")
                //.apply(" to_days(t.create_date) = to_days(now()) ")
                .apply(" ( t.create_date > now() - INTERVAL 10 MINUTE ) ")
                .orderByDesc(PlatformWarnEvent::getCreateDate)
                .last(" limit "+limit)
        );