| | |
| | | import java.util.*; |
| | | import java.util.concurrent.*; |
| | | import java.util.function.Function; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | exportForm.setDeptIds(deptIds); |
| | | } |
| | | Query query = getQuery(exportForm); |
| | | |
| | | |
| | | //月份每日在线数据 |
| | | List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class); |
| | | // 使用 Collectors.toMap 去重,保留每个 No 的第一个遇到的元素 |
| | |
| | | @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)) { |
| | | //如果为空查本月的数据 |
| | |
| | | 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), |
| | |
| | | homeVideoVO.setIntegrityNum(doc.getInteger("normalCount")); |
| | | homeVideoVO.setLoseNum(doc.getInteger("loseCount")); |
| | | homeVideoVO.setErrNum(doc.getInteger("errCount")); |
| | | |
| | | results.add(homeVideoVO); |
| | | } |
| | | |
| | |
| | | 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)), |
| | |
| | | )) |
| | | ) |
| | | ); |
| | | //排除卡口集合 |
| | | |
| | | |
| | | |
| | | // 执行聚合查询并获取结果 |
| | | AggregateIterable<Document> onlineResult = onlineCollection.aggregate(onlinePipeline); |
| | | for (Document doc : onlineResult) { |
| | |
| | | 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( |
| | |
| | | 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( |
| | |
| | | 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"); |
| | |
| | | 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( |
| | |
| | | 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( |