zxl
6 天以前 8f2e8522daf081ad4da027c39a776fdd9483b97e
ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java
@@ -71,6 +71,7 @@
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@@ -1269,6 +1270,7 @@
    @Override
    public Map<String, Object> videoHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        List<HomeVideoVO> results = new ArrayList<>();
        String month = monitorQuery.getDate();
        if (StringUtils.isEmpty(month)) {
            //如果为空查本月的数据
@@ -1295,13 +1297,30 @@
        MongoDatabase database = mongoTemplate.getDb();
        MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum");
        Integer examineTag = monitorQuery.getExamineTag();
        String arealayerno = monitorQuery.getArea();
        Document matchConditions = new Document("statTime", new Document("$gte", startDate).append("$lte", endDate));
        // 根据examineTag的值动态添加额外的条件
        if (examineTag != null && examineTag.equals(1)) {
            matchConditions.append("provinceTag", true);
        } else if (examineTag != null && examineTag.equals(2)) {
            matchConditions.append("deptTag", true);
        } else if(StringUtils.isNotBlank(arealayerno)){
            matchConditions.append("arealayerno",
                    new Document("$regex", "^" + arealayerno));
        }
        Document noExpr = new Document("$and", Arrays.asList(
                new Document("$gte", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
                new Document("$ne", Arrays.asList(
                        new Document("$substrCP", Arrays.asList(
                                "$no",
                                new Document("$subtract", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
                                1
                        )),
                        "3"
                ))
        ));
// 正确添加$expr条件(键为"$expr",值为上面定义的条件)
        matchConditions.append("$expr", noExpr);
        // 构建聚合管道
        List<Document> pipeline = Arrays.asList(
                new Document("$match", matchConditions),
@@ -1337,6 +1356,7 @@
            homeVideoVO.setIntegrityNum(doc.getInteger("normalCount"));
            homeVideoVO.setLoseNum(doc.getInteger("loseCount"));
            homeVideoVO.setErrNum(doc.getInteger("errCount"));
            results.add(homeVideoVO);
        }
@@ -1350,8 +1370,24 @@
            onlineMatch.add(new Document("provinceTag", true));
        } else if (examineTag != null && examineTag.equals(2)) {
            onlineMatch.add(new Document("deptTag", true));
        }
        } else if(StringUtils.isNotBlank(arealayerno)){
            Document noStartsWith = new Document("no", new Document("$regex", "^" + arealayerno));
            // 构建倒数第三位不是3的条件
            Document noThirdLastNot3 = new Document("$expr", new Document("$and", Arrays.asList(
                    new Document("$gte", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
                    new Document("$ne", Arrays.asList(
                            new Document("$substrCP", Arrays.asList(
                                    "$no",
                                    new Document("$subtract", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
                                    1
                            )),
                            "3"
                    ))
            )));
            // 将两个条件用$and组合后添加到条件列表
            onlineMatch.add(new Document("$and", Arrays.asList(noStartsWith, noThirdLastNot3)));
        }
        // 构建聚合管道
        List<Document> onlinePipeline = Arrays.asList(
                new Document("$match", new Document("$and", onlineMatch)),
@@ -1365,6 +1401,10 @@
                        ))
                )
        );
        //排除卡口集合
        // 执行聚合查询并获取结果
        AggregateIterable<Document> onlineResult = onlineCollection.aggregate(onlinePipeline);
        for (Document doc : onlineResult) {
@@ -1496,10 +1536,13 @@
        Integer examineTag = monitorQuery.getExamineTag();
        // 构建基本的$match条件
        List<Document> matchConditions = new ArrayList<>();
        String arealayerno = monitorQuery.getArea();
        matchConditions.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
        matchConditions.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_CAR)));
        if (examineTag != null && examineTag.equals(1)) {
            matchConditions.add(new Document("provinceTag", true));
        }else if(StringUtils.isNotBlank(arealayerno)){
            matchConditions.add(new Document("orgCode",new Document("$eq", arealayerno)));
        }
        // 构建聚合管道
        List<Document> pipeline = Arrays.asList(
@@ -1524,6 +1567,8 @@
        onlineMatch.add(new Document("monitorType", new Document("$regex", "2")));
        if (examineTag != null && examineTag.equals(1)) {
            onlineMatch.add(new Document("provinceTag", true));
        }else if(StringUtils.isNotBlank(arealayerno)){
            onlineMatch.add(new Document("no", new Document("$regex", "^" + arealayerno)));
        }
        // 构建聚合管道
        List<Document> onlinePipeline = Arrays.asList(
@@ -1602,6 +1647,7 @@
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        // 获取月份最后一天的Date
        Date endDate = calendar.getTime();
        String arealayerno = monitorQuery.getArea();
        //mongo查抓拍量
        MongoDatabase database = mongoTemplate.getDb();
        MongoCollection<Document> collection = database.getCollection("hk_snapshot_data_monitor");
@@ -1612,6 +1658,8 @@
        matchConditions.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_FACE)));
        if (examineTag != null && examineTag.equals(1)) {
            matchConditions.add(new Document("provinceTag", true));
        }else if(StringUtils.isNotBlank(arealayerno)){
            matchConditions.add(new Document("orgCode",new Document("$eq", arealayerno)));
        }
        // 构建聚合管道
        List<Document> pipeline = Arrays.asList(
@@ -1638,6 +1686,8 @@
        onlineMatch.add(new Document("monitorType", new Document("$regex", "3")));
        if (examineTag != null && examineTag.equals(1)) {
            onlineMatch.add(new Document("provinceTag", true));
        }else if(StringUtils.isNotBlank(arealayerno)){
            onlineMatch.add(new Document("no", new Document("$regex", "^" + arealayerno)));
        }
        // 构建聚合管道
        List<Document> onlinePipeline = Arrays.asList(