fuliqi
2024-10-23 d74864fb938883b9c2b69abaf8b3ff740f03d930
数据中心各种在线率优化
2个文件已修改
371 ■■■■ 已修改文件
ycl-pojo/src/main/java/com/ycl/platform/domain/query/DataCenterQuery.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-server/src/main/java/com/ycl/platform/service/impl/DataCenterServiceImpl.java 368 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-pojo/src/main/java/com/ycl/platform/domain/query/DataCenterQuery.java
@@ -40,7 +40,8 @@
    /** 1 视频 2 车辆 3 人脸 */
    private Integer deviceType;
    /** 下拉框 */
    private Integer option;
    public void setTime() {
        if (Objects.nonNull(this.date)) {
ycl-server/src/main/java/com/ycl/platform/service/impl/DataCenterServiceImpl.java
@@ -1,5 +1,6 @@
package com.ycl.platform.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.github.pagehelper.Page;
@@ -20,12 +21,14 @@
import com.ycl.system.page.PageUtil;
import com.ycl.utils.DateUtils;
import com.ycl.utils.MongoUtil;
import constant.ApiConstants;
import constant.CheckConstants;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.bson.Document;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.*;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.TextCriteria;
@@ -69,15 +72,24 @@
    public Result videoPointOnlineRate(DataCenterQuery params) {
        List<String> likeFileds = Arrays.asList("name", "no", "ip");
        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null);
        System.out.println("查询条件"+query.toString());
        //查视频设备
        query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*"));
        //下拉框在线情况查询条件
        if(params.getOption()!=null) {
            query.addCriteria(Criteria.where("online").is(params.getOption()));
        }
        // 通过pingOnline字段排序,为false的排在前面
        query.with(Sort.by(Sort.Order.asc("pingOnline")));
        //分页数量
        long total = mongoTemplate.count(query, TMonitorResult.class);
        MongoUtil.setPage(query, params, TIME_FIELD);
        List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class);
        resultList.forEach(item -> {
            if (null != item.getPingOnline() && item.getPingOnline()) {
            if(item.getPingOnline() ==null){
                item.setPingOnlineStr("未知");
            } else if (item.getPingOnline()) {
                item.setPingOnlineStr("在线");
            } else {
            } else if(!item.getPingOnline()){
                item.setPingOnlineStr("离线");
            }
            if(1== item.getOnline() ){
@@ -90,13 +102,59 @@
        });
        params.setDeptTag(-1);
        params.setDeviceType(1);
        // 统计设备数量
        Integer distinctCount = pointMapper.distinctCount(params);
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getSiteOnline)
                .between(CheckIndexVideo::getCreateTime,  params.getStartTime(),  params.getEndTime())
                .list();
        //卡片统计
        int totalCount =0;
        int onlineCount =0;
        int offlineCount =0;
        int unknownCount =0;
        //构建条件
        List<Criteria> criteriaList = new ArrayList<>();
        // 添加固定条件
        criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*"));
        criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime()));
        // 根据dataType动态添加条件
        if (params.getDataType() == 1) {
            criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE));
        } else if (params.getDataType() == 2) {
            criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE));
        }
        // 构建match操作
        MatchOperation match = Aggregation.match(
                new Criteria().andOperator(criteriaList.toArray(new Criteria[0]))
        );
        GroupOperation group = Aggregation.group()
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount");
        // 将匹配阶段和分组阶段组合起来
        Aggregation aggregation = Aggregation.newAggregation(match, group);
        // 执行聚合查询
        AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称
        for (Map<String, Object> result : results.getMappedResults()) {
            offlineCount =(Integer) result.getOrDefault("offlineCount",0L);
            unknownCount =(Integer) result.getOrDefault("unknownCount",0L);
            onlineCount = (Integer) result.getOrDefault("onlineCount",0L);
            totalCount = offlineCount + unknownCount + onlineCount;
        }
        /** 查询当天在线率 */
        // 创建一个QueryWrapper实例
        QueryWrapper<CheckIndexVideo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(CheckIndexVideo::getSiteOnline) // 选择要查询的字段
                .between(CheckIndexVideo::getCreateTime, params.getStartTime(), params.getEndTime()); // 设置时间范围条件
        if (params.getDataType() == 0) {
            //区县
            queryWrapper.lambda().eq(CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_County);
        }else if(params.getDataType() == 1){
            //省厅
            queryWrapper.lambda().eq(CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province);
        }else if(params.getDataType() == 2){
            //公安部
            queryWrapper.lambda().eq(CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Dept);
        }
        // 使用QueryWrapper执行查询
        List<CheckIndexVideo> videoList = checkIndexVideoService.getBaseMapper().selectList(queryWrapper);
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getSiteOnline).reduce(BigDecimal.ZERO, BigDecimal::add);
@@ -104,7 +162,7 @@
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate)));
        map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate)));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }
@@ -119,14 +177,25 @@
    public Result deptVideoPointOnlineRate(DataCenterQuery params) {
        List<String> likeFileds = Arrays.asList("name", "no", "ip");
        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null);
        //查视频设备
        query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*"));
        query.addCriteria(Criteria.where("deptTag").is(Boolean.TRUE));
        //下拉框在线情况查询条件
        if(params.getOption()!=null) {
            query.addCriteria(Criteria.where("online").is(params.getOption()));
        }
        // 通过pingOnline字段排序,为false的排在前面
        query.with(Sort.by(Sort.Order.asc("pingOnline")));
        //分页数量
        long total = mongoTemplate.count(query, TMonitorResult.class);
        MongoUtil.setPage(query, params, TIME_FIELD);
        List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class);
        resultList.forEach(item -> {
            if (null != item.getPingOnline() && item.getPingOnline()) {
            if(item.getPingOnline() ==null){
                item.setPingOnlineStr("未知");
            } else if (item.getPingOnline()) {
                item.setPingOnlineStr("在线");
            } else {
            } else if(!item.getPingOnline()){
                item.setPingOnlineStr("离线");
            }
            if (1 == item.getOnline()) {
@@ -138,10 +207,43 @@
            }
        });
        // 统计设备数量
        //卡片统计
        int totalCount =0;
        int onlineCount =0;
        int offlineCount =0;
        int unknownCount =0;
        //构建条件
        List<Criteria> criteriaList = new ArrayList<>();
        // 添加固定条件
        criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*"));
        criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime()));
        // 根据dataType动态添加条件
        if (params.getDataType() == 1) {
            criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE));
        } else if (params.getDataType() == 2) {
            criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE));
        }
        // 构建match操作
        MatchOperation match = Aggregation.match(
                new Criteria().andOperator(criteriaList.toArray(new Criteria[0]))
        );
        GroupOperation group = Aggregation.group()
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount");
        // 将匹配阶段和分组阶段组合起来
        Aggregation aggregation = Aggregation.newAggregation(match, group);
        // 执行聚合查询
        AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称
        for (Map<String, Object> result : results.getMappedResults()) {
            offlineCount =(Integer) result.getOrDefault("offlineCount",0L);
            unknownCount =(Integer) result.getOrDefault("unknownCount",0L);
            onlineCount = (Integer) result.getOrDefault("onlineCount",0L);
            totalCount = offlineCount + unknownCount + onlineCount;
        }
        params.setDeptTag(1);
        params.setDeviceType(1);
        Integer distinctCount = pointMapper.distinctCount(params);
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getMinistrySiteOnline)
                .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province)
@@ -154,7 +256,7 @@
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate)));
        map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate)));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }
@@ -169,18 +271,27 @@
    public Result videoImportantPointOnlineRate(DataCenterQuery params) {
        List<String> likeFileds = Arrays.asList("name", "no", "ip");
        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null);
        //查视频设备
        query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*"));
        query.addCriteria(Criteria.where("importantTag").is(Boolean.TRUE));
        //下拉框在线情况查询条件
        if(params.getOption()!=null) {
            query.addCriteria(Criteria.where("online").is(params.getOption()));
        }
        // 通过pingOnline字段排序,为false的排在前面
        query.with(Sort.by(Sort.Order.asc("pingOnline")));
        //分页数量
        long total = mongoTemplate.count(query, TMonitorResult.class);
        MongoUtil.setPage(query, params, TIME_FIELD);
        List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class);
        params.setDeptTag(3);
        params.setDeviceType(1);
        // 统计设备数量
        Integer distinctCount = pointMapper.distinctCount(params);
        resultList.forEach(item -> {
            if (null != item.getPingOnline() && item.getPingOnline()) {
            if(item.getPingOnline() ==null){
                item.setPingOnlineStr("未知");
            } else if (item.getPingOnline()) {
                item.setPingOnlineStr("在线");
            } else {
            } else if(!item.getPingOnline()){
                item.setPingOnlineStr("离线");
            }
            if (1 == item.getOnline()) {
@@ -191,11 +302,46 @@
                item.setOnlineStr("未知");
            }
        });
        Date now = new Date();
        // 统计设备数量
        //卡片统计
        int totalCount =0;
        int onlineCount =0;
        int offlineCount =0;
        int unknownCount =0;
        //构建条件
        List<Criteria> criteriaList = new ArrayList<>();
        // 添加固定条件
        criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*"));
        criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime()));
        // 根据dataType动态添加条件
        if (params.getDataType() == 1) {
            criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE));
        } else if (params.getDataType() == 2) {
            criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE));
        }
        // 构建match操作
        MatchOperation match = Aggregation.match(
                new Criteria().andOperator(criteriaList.toArray(new Criteria[0]))
        );
        GroupOperation group = Aggregation.group()
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount");
        // 将匹配阶段和分组阶段组合起来
        Aggregation aggregation = Aggregation.newAggregation(match, group);
        // 执行聚合查询
        AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称
        for (Map<String, Object> result : results.getMappedResults()) {
            offlineCount =(Integer) result.getOrDefault("offlineCount",0L);
            unknownCount =(Integer) result.getOrDefault("unknownCount",0L);
            onlineCount = (Integer) result.getOrDefault("onlineCount",0L);
            totalCount = offlineCount + unknownCount + onlineCount;
        }
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getKeySiteOnline)
                .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .between(CheckIndexVideo::getCreateTime, params.getStartTime(),  params.getEndTime())
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
@@ -204,7 +350,7 @@
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate)));
        map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate)));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }
@@ -219,6 +365,15 @@
    public Result videoImportantPointImageOnlineRate(DataCenterQuery params) {
        List<String> likeFileds = Arrays.asList("name", "no", "ip");
        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null);
        //查视频设备
        query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*"));
        query.addCriteria(Criteria.where("importantCommandImageTag").is(Boolean.TRUE));
        //下拉框在线情况查询条件
        if(params.getOption()!=null) {
            query.addCriteria(Criteria.where("online").is(params.getOption()));
        }
        // 通过pingOnline字段排序,为false的排在前面
        query.with(Sort.by(Sort.Order.asc("pingOnline")));
        //分页数量
        long total = mongoTemplate.count(query, TMonitorResult.class);
        MongoUtil.setPage(query, params, TIME_FIELD);
@@ -226,12 +381,12 @@
        params.setDeptTag(4);
        params.setDeviceType(1);
        // 统计设备数量
        Integer distinctCount = pointMapper.distinctCount(params);
        resultList.forEach(item -> {
            if (null != item.getPingOnline() && item.getPingOnline()) {
            if(item.getPingOnline() ==null){
                item.setPingOnlineStr("未知");
            } else if (item.getPingOnline()) {
                item.setPingOnlineStr("在线");
            } else {
            } else if(!item.getPingOnline()){
                item.setPingOnlineStr("离线");
            }
            if (1 == item.getOnline()) {
@@ -242,11 +397,47 @@
                item.setOnlineStr("未知");
            }
        });
        Date now = new Date();
        // 统计设备数量
        //卡片统计
        int totalCount =0;
        int onlineCount =0;
        int offlineCount =0;
        int unknownCount =0;
        //构建条件
        List<Criteria> criteriaList = new ArrayList<>();
        // 添加固定条件
        criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*"));
        criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime()));
        // 根据dataType动态添加条件
        if (params.getDataType() == 1) {
            criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE));
        } else if (params.getDataType() == 2) {
            criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE));
        }
        // 构建match操作
        MatchOperation match = Aggregation.match(
                new Criteria().andOperator(criteriaList.toArray(new Criteria[0]))
        );
        GroupOperation group = Aggregation.group()
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount");
        // 将匹配阶段和分组阶段组合起来
        Aggregation aggregation = Aggregation.newAggregation(match, group);
        // 执行聚合查询
        AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称
        for (Map<String, Object> result : results.getMappedResults()) {
            offlineCount =(Integer) result.getOrDefault("offlineCount",0L);
            unknownCount =(Integer) result.getOrDefault("unknownCount",0L);
            onlineCount = (Integer) result.getOrDefault("onlineCount",0L);
            totalCount = offlineCount + unknownCount + onlineCount;
        }
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getKeyCommandImageOnline)
                .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .between(CheckIndexVideo::getCreateTime, params.getStartTime(),  params.getEndTime())
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
@@ -255,7 +446,7 @@
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate)));
        map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate)));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }
@@ -936,6 +1127,14 @@
    public Result vehiclePointOnlineRate(DataCenterQuery params) {
        List<String> likeFileds = Arrays.asList("name", "no", "ip");
        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null);
        //查车辆设备
        query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Car + ".*"));
        //下拉框在线情况查询条件
        if(params.getOption()!=null) {
            query.addCriteria(Criteria.where("online").is(params.getOption()));
        }
        // 通过pingOnline字段排序,为false的排在前面
        query.with(Sort.by(Sort.Order.asc("pingOnline")));
        //分页数量
        long total = mongoTemplate.count(query, TMonitorResult.class);
        MongoUtil.setPage(query, params, TIME_FIELD);
@@ -943,12 +1142,12 @@
        List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class);
        params.setDeptTag(-1);
        params.setDeviceType(2);
        // 统计设备数量
        Integer distinctCount = pointMapper.distinctCount(params);
        resultList.forEach(item -> {
            if (null != item.getPingOnline() && item.getPingOnline()) {
            if(item.getPingOnline() ==null){
                item.setPingOnlineStr("未知");
            } else if (item.getPingOnline()) {
                item.setPingOnlineStr("在线");
            } else {
            } else if(!item.getPingOnline()){
                item.setPingOnlineStr("离线");
            }
            if (1 == item.getOnline()) {
@@ -959,6 +1158,43 @@
                item.setOnlineStr("未知");
            }
        });
        // 统计设备数量
        //卡片统计
        int totalCount =0;
        int onlineCount =0;
        int offlineCount =0;
        int unknownCount =0;
        //构建条件
        List<Criteria> criteriaList = new ArrayList<>();
        // 添加固定条件
        criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Car + ".*"));
        criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime()));
        // 根据dataType动态添加条件
        if (params.getDataType() == 1) {
            criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE));
        } else if (params.getDataType() == 2) {
            criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE));
        }
        // 构建match操作
        MatchOperation match = Aggregation.match(
                new Criteria().andOperator(criteriaList.toArray(new Criteria[0]))
        );
        GroupOperation group = Aggregation.group()
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount");
        // 将匹配阶段和分组阶段组合起来
        Aggregation aggregation = Aggregation.newAggregation(match, group);
        // 执行聚合查询
        AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称
        for (Map<String, Object> result : results.getMappedResults()) {
            offlineCount =(Integer) result.getOrDefault("offlineCount",0L);
            unknownCount =(Integer) result.getOrDefault("unknownCount",0L);
            onlineCount = (Integer) result.getOrDefault("onlineCount",0L);
            totalCount = offlineCount + unknownCount + onlineCount;
        }
        List<CheckIndexCar> videoList = new LambdaQueryChainWrapper<>(checkIndexCarService.getBaseMapper())
                .select(CheckIndexCar::getSiteOnline)
                .eq(params.getDataType().equals(1), CheckIndexCar::getExamineTag, CheckConstants.Examine_Tag_Province)
@@ -971,7 +1207,7 @@
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate)));
        map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate)));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }
@@ -1450,15 +1686,25 @@
    public Result facePointOnlineRate(DataCenterQuery params) {
        List<String> likeFileds = Arrays.asList("name", "no", "ip");
        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null);
        //查人脸设备
        query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Face + ".*"));
        //下拉框在线情况查询条件
        if(params.getOption()!=null) {
            query.addCriteria(Criteria.where("online").is(params.getOption()));
        }
        // 通过pingOnline字段排序,为false的排在前面
        query.with(Sort.by(Sort.Order.asc("pingOnline")));
        //分页数量
        long total = mongoTemplate.count(query, TMonitorResult.class);
        MongoUtil.setPage(query, params, TIME_FIELD);
        List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class);
        resultList.forEach(item -> {
            if (null != item.getPingOnline() && item.getPingOnline()) {
                item.setOnlineStr("在线");
            } else {
                item.setOnlineStr("离线");
            if(item.getPingOnline() ==null){
                item.setPingOnlineStr("未知");
            } else if (item.getPingOnline()) {
                item.setPingOnlineStr("在线");
            } else if(!item.getPingOnline()){
                item.setPingOnlineStr("离线");
            }
            if (1 == item.getOnline()) {
                item.setOnlineStr("在线");
@@ -1470,14 +1716,46 @@
        });
        params.setDeptTag(-1);
        params.setDeviceType(3);
        // 统计设备数量
        Integer distinctCount = pointMapper.distinctCount(params);
        Date now = new Date();
// 统计设备数量
        //卡片统计
        int totalCount =0;
        int onlineCount =0;
        int offlineCount =0;
        int unknownCount =0;
        //构建条件
        List<Criteria> criteriaList = new ArrayList<>();
        // 添加固定条件
        criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Face + ".*"));
        criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime()));
        // 根据dataType动态添加条件
        if (params.getDataType() == 1) {
            criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE));
        } else if (params.getDataType() == 2) {
            criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE));
        }
        // 构建match操作
        MatchOperation match = Aggregation.match(
                new Criteria().andOperator(criteriaList.toArray(new Criteria[0]))
        );
        GroupOperation group = Aggregation.group()
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount")
                .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount");
        // 将匹配阶段和分组阶段组合起来
        Aggregation aggregation = Aggregation.newAggregation(match, group);
        // 执行聚合查询
        AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称
        for (Map<String, Object> result : results.getMappedResults()) {
            offlineCount =(Integer) result.getOrDefault("offlineCount",0L);
            unknownCount =(Integer) result.getOrDefault("unknownCount",0L);
            onlineCount = (Integer) result.getOrDefault("onlineCount",0L);
            totalCount = offlineCount + unknownCount + onlineCount;
        }
        List<CheckIndexFace> videoList = new LambdaQueryChainWrapper<>(checkIndexFaceService.getBaseMapper())
                .select(CheckIndexFace::getSiteOnline)
                .eq(params.getDataType().equals(1), CheckIndexFace::getExamineTag, CheckConstants.Examine_Tag_Province)
                .between(CheckIndexFace::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .between(CheckIndexFace::getCreateTime, params.getStartTime(),  params.getEndTime())
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
@@ -1485,11 +1763,9 @@
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        List<String> rList = new ArrayList<>(2);
        rList.add(distinctCount + "");
        rList.add(this.remove0(onlineRate));
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", rList);
        map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate)));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }