xiangpei
2024-09-05 fb13447f6cc1c85378bf98ab81dbb3e893be949f
ycl-server/src/main/java/com/ycl/platform/service/impl/DataCenterServiceImpl.java
@@ -1,11 +1,13 @@
package com.ycl.platform.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mongodb.client.AggregateIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.ycl.platform.domain.entity.CheckIndexVideo;
import com.ycl.platform.domain.entity.ImageResourceSecurityDetail;
import com.ycl.platform.domain.entity.YwPoint;
import com.ycl.platform.domain.query.DataCenterQuery;
@@ -14,9 +16,12 @@
import com.ycl.platform.mapper.ImageResourceSecurityDetailMapper;
import com.ycl.platform.mapper.YwPointMapper;
import com.ycl.platform.service.DataCenterService;
import com.ycl.platform.service.ICheckIndexCarService;
import com.ycl.platform.service.ICheckIndexVideoService;
import com.ycl.platform.service.YwPointService;
import com.ycl.system.Result;
import com.ycl.system.page.PageUtil;
import com.ycl.utils.DateUtils;
import com.ycl.utils.MongoUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
@@ -28,6 +33,8 @@
import org.springframework.data.mongodb.core.query.TextCriteria;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@@ -44,6 +51,7 @@
    private final MongoTemplate mongoTemplate;
    private final ImageResourceSecurityDetailMapper securityDetailMapper;
    private final YwPointMapper pointMapper;
    private final ICheckIndexVideoService checkIndexVideoService;
    private final static String TIME_FIELD = "mongoCreateTime";
@@ -69,9 +77,19 @@
        MongoDatabase database = mongoTemplate.getDb();
        MongoCollection<Document> collection = database.getCollection("uy_online");
        long distinctCount = collection.distinct("deviceId", String.class).into(new ArrayList<>()).size();
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getSiteOnline)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getSiteOnline).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", Arrays.asList(distinctCount));
        map.put("count", Arrays.asList(distinctCount + "",onlineRate + "%"));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }
@@ -114,9 +132,19 @@
            uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds");
            break; // 不需要继续遍历,因为 $count 只会产生一个结果
        }
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getMinistrySiteOnline)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getMinistrySiteOnline).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", Arrays.asList(uniqueDeviceIdCount));
        map.put("count", Arrays.asList(uniqueDeviceIdCount + "", onlineRate + "%"));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }
@@ -157,13 +185,19 @@
            break; // 不需要继续遍历,因为 $count 只会产生一个结果
        }
//        long nonNetwork = mongoTemplate.count(new Query().addCriteria(Criteria.where("LWSX").is("0")), VideoOnlineResult.class);
//        long network = mongoTemplate.count(new Query().addCriteria(Criteria.where("LWSX").is("1")), VideoOnlineResult.class);
//        long video = mongoTemplate.count(new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*1.*")), VideoOnlineResult.class);
//        long car = mongoTemplate.count(new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*2.*")), VideoOnlineResult.class);
//        long face = mongoTemplate.count(new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*3.*")), VideoOnlineResult.class);
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getKeySiteOnline)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getKeySiteOnline).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", Arrays.asList(uniqueDeviceIdCount));
        map.put("count", Arrays.asList(uniqueDeviceIdCount + "", onlineRate + "%"));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }
@@ -204,14 +238,19 @@
            break; // 不需要继续遍历,因为 $count 只会产生一个结果
        }
//        // 统计数
//        long nonNetwork = mongoTemplate.count(new Query().addCriteria(Criteria.where("LWSX").is("0")), VideoOnlineResult.class);
//        long network = mongoTemplate.count(new Query().addCriteria(Criteria.where("LWSX").is("1")), VideoOnlineResult.class);
//        long video = mongoTemplate.count(new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*1.*")), VideoOnlineResult.class);
//        long car = mongoTemplate.count(new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*2.*")), VideoOnlineResult.class);
//        long face = mongoTemplate.count(new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*3.*")), VideoOnlineResult.class);
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getKeyCommandImageOnline)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getKeyCommandImageOnline).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", Arrays.asList(uniqueDeviceIdCount));
        map.put("count", Arrays.asList(uniqueDeviceIdCount + "", onlineRate + "%"));
        map.put("list", resultList);
        return Result.ok().data(map).total(total);
    }
@@ -241,7 +280,7 @@
        Document longitudeErrFilter = new Document("longitude.error", true);
        List<Document> lists = Arrays.asList(ipErrFilter, macdzErrFilter, latitudeErrFilter, longitudeErrFilter);
        List<Integer> rList = lists.stream().map(filter -> {
        List<String> rList = lists.stream().map(filter -> {
            // 构建聚合管道
            List<Document> pipeline = Arrays.asList(
                    new Document("$match", filter),
@@ -256,9 +295,21 @@
                uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds");
                break; // 不需要继续遍历,因为 $count 只会产生一个结果
            }
            return uniqueDeviceIdCount;
            return uniqueDeviceIdCount + "";
        }).collect(Collectors.toList());
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getMonitorRegistration)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getMonitorRegistration).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        rList.add(onlineRate + "%");
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", rList);
        map.put("list", resultList);
@@ -290,7 +341,7 @@
        Document longitudeErrFilter = new Document("longitude.error", true);
        List<Document> lists = Arrays.asList(ipErrFilter, macdzErrFilter, latitudeErrFilter, longitudeErrFilter);
        List<Integer> rList = lists.stream().map(filter -> {
        List<String> rList = lists.stream().map(filter -> {
            // 构建聚合管道
            List<Document> pipeline = Arrays.asList(
                    new Document("$match", filter),
@@ -305,9 +356,21 @@
                uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds");
                break; // 不需要继续遍历,因为 $count 只会产生一个结果
            }
            return uniqueDeviceIdCount;
            return uniqueDeviceIdCount + "";
        }).collect(Collectors.toList());
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getMonitorQualification)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getMonitorQualification).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        rList.add(onlineRate + "%");
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", rList);
        map.put("list", resultList);
@@ -340,7 +403,7 @@
        Document longitudeErrFilter = new Document("longitude.error", true);
        List<Document> lists = Arrays.asList(ipErrFilter, macdzErrFilter, latitudeErrFilter, longitudeErrFilter);
        List<Integer> rList = lists.stream().map(filter -> {
        List<String> rList = lists.stream().map(filter -> {
            // 构建聚合管道
            List<Document> pipeline = Arrays.asList(
                    new Document("$match", filter),
@@ -355,9 +418,10 @@
                uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds");
                break; // 不需要继续遍历,因为 $count 只会产生一个结果
            }
            return uniqueDeviceIdCount;
            return uniqueDeviceIdCount + "";
        }).collect(Collectors.toList());
        rList.add("0%");
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", rList);
        map.put("list", resultList);
@@ -383,7 +447,7 @@
        MongoDatabase database = mongoTemplate.getDb();
        MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum");
        List<Integer> status = Arrays.asList(1, 0, -1);
        List<Integer> resultCount = status.stream().map(item -> {
        List<String> resultCount = status.stream().map(item -> {
            Document filter = new Document("recordStatus", item);
            // 构建聚合管道
            List<Document> pipeline = Arrays.asList(
@@ -399,10 +463,21 @@
                uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds");
                break; // 不需要继续遍历,因为 $count 只会产生一个结果
            }
            return uniqueDeviceIdCount;
            return uniqueDeviceIdCount + "";
        }).collect(Collectors.toList());
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getVideoAvailable)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getVideoAvailable).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        resultCount.add(onlineRate + "%");
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", resultCount);
        map.put("list", resultList);
@@ -430,7 +505,7 @@
        MongoDatabase database = mongoTemplate.getDb();
        MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum");
        List<Integer> status = Arrays.asList(1, 0, -1);
        List<Integer> resultCount = status.stream().map(item -> {
        List<String> resultCount = status.stream().map(item -> {
            Document filter = new Document("$and", Arrays.asList(
                    new Document("deviceId", new Document("$in", deptGBList)), // $in 条件
                    new Document("recordStatus", item)
@@ -449,10 +524,21 @@
                uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds");
                break; // 不需要继续遍历,因为 $count 只会产生一个结果
            }
            return uniqueDeviceIdCount;
            return uniqueDeviceIdCount + "";
        }).collect(Collectors.toList());
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getMinistryVideoAvailable)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getMinistryVideoAvailable).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        resultCount.add(onlineRate + "%");
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", resultCount);
        map.put("list", resultList);
@@ -480,7 +566,7 @@
        MongoDatabase database = mongoTemplate.getDb();
        MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum");
        List<Integer> status = Arrays.asList(1, 0, -1);
        List<Integer> resultCount = status.stream().map(item -> {
        List<String> resultCount = status.stream().map(item -> {
            Document filter = new Document("$and", Arrays.asList(
                    new Document("deviceId", new Document("$in", deptGBList)), // $in 条件
                    new Document("recordStatus", item)
@@ -499,9 +585,21 @@
                uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds");
                break; // 不需要继续遍历,因为 $count 只会产生一个结果
            }
            return uniqueDeviceIdCount;
            return uniqueDeviceIdCount + "%";
        }).collect(Collectors.toList());
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getKeyVideoAvailable)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getKeyVideoAvailable).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        resultCount.add(onlineRate + "%");
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", resultCount);
        map.put("list", resultList);
@@ -559,7 +657,7 @@
        Document osdTimeFilter = new Document("osdTimeCorrect", 1);
        Document osdTimeErrFilter = new Document("osdTimeCorrect", -1);
        List<Document> lists = Arrays.asList(osdNameFilter, osdNameErrFilter, osdTimeFilter, osdTimeErrFilter);
        List<Integer> rList = lists.stream().map(filter -> {
        List<String> rList = lists.stream().map(filter -> {
            // 构建聚合管道
            List<Document> pipeline = Arrays.asList(
                    new Document("$match", filter),
@@ -574,10 +672,21 @@
                uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds");
                break; // 不需要继续遍历,因为 $count 只会产生一个结果
            }
            return uniqueDeviceIdCount;
            return uniqueDeviceIdCount + "";
        }).collect(Collectors.toList());
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getKeyAnnotationAccuracy)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getKeyAnnotationAccuracy).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        rList.add(onlineRate + "%");
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", rList);
        map.put("list", resultList);
@@ -634,7 +743,7 @@
        Document osdTimeFilter = new Document("osdTimeCorrect", 1);
        Document osdTimeErrFilter = new Document("osdTimeCorrect", -1);
        List<Document> lists = Arrays.asList(osdTimeFilter, osdTimeErrFilter);
        List<Integer> rList = lists.stream().map(filter -> {
        List<String> rList = lists.stream().map(filter -> {
            // 构建聚合管道
            List<Document> pipeline = Arrays.asList(
                    new Document("$match", filter),
@@ -649,9 +758,21 @@
                uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds");
                break; // 不需要继续遍历,因为 $count 只会产生一个结果
            }
            return uniqueDeviceIdCount;
            return uniqueDeviceIdCount + "";
        }).collect(Collectors.toList());
        Date now = new Date();
        List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                .select(CheckIndexVideo::getKeyTimingAccuracy)
                .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now))
                .list();
        BigDecimal onlineRate = BigDecimal.ZERO;
        if (CollectionUtils.isNotEmpty(videoList)) {
            BigDecimal sum = videoList.stream().map(CheckIndexVideo::getKeyTimingAccuracy).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal count = BigDecimal.valueOf(videoList.size());
            onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        rList.add(onlineRate + "%");
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", rList);
        map.put("list", resultList);