| | |
| | | import com.ycl.utils.bean.BeanUtils; |
| | | import com.ycl.utils.poi.ExcelUtil; |
| | | import constant.*; |
| | | import enumeration.DataCenterMethodNameEnum; |
| | | import enumeration.general.AreaDeptEnum; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.bson.Document; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | 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.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.IOException; |
| | |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.CompletionException; |
| | | import java.util.concurrent.ExecutionException; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private final ICheckIndexFaceService checkIndexFaceService; |
| | | private final DynamicColumnMapper dynamicColumnMapper; |
| | | |
| | | |
| | | @Qualifier("threadPoolTaskExecutor") |
| | | @Autowired |
| | | private ThreadPoolTaskExecutor taskExecutor; |
| | | |
| | | private final static String TIME_FIELD = "mongoCreateTime"; |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 视频:点位在线率 |
| | | * |
| | | * @param params |
| | | * @return |
| | | * 内部类:存储统计结果(避免零散变量传递) |
| | | */ |
| | | @Override |
| | | public Result videoPointOnlineRate(DataCenterQuery params) { |
| | | List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | //此处新增了根据用户权限查询的情况 |
| | | Query query = null; |
| | | SysDept sysDept = getSysDeptByLoginUser(); |
| | | AreaDeptEnum areaDeptEnum = null; |
| | | if (sysDept !=null){ |
| | | areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); |
| | | if (areaDeptEnum != null){ |
| | | query = MongoUtil.getQueryDataCenter(areaDeptEnum.getCode(),params,TIME_FIELD,likeFileds,null,"no"); |
| | | private static class StatisticsResult { |
| | | int totalCount; |
| | | int onlineCount; |
| | | int offlineCount; |
| | | int unknownCount; |
| | | BigDecimal onlineRate; |
| | | |
| | | }else{ |
| | | query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | } |
| | | }else { |
| | | query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | public StatisticsResult(int totalCount, int onlineCount, int offlineCount, int unknownCount, BigDecimal onlineRate) { |
| | | this.totalCount = totalCount; |
| | | this.onlineCount = onlineCount; |
| | | this.offlineCount = offlineCount; |
| | | this.unknownCount = unknownCount; |
| | | this.onlineRate = onlineRate; |
| | | } |
| | | //查视频设备 |
| | | query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | //下拉框在线情况查询条件 |
| | | if (params.getOption() != null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | Sort sort = Sort.by( |
| | | Sort.Order.asc("pingOnline"), // 首先按照 pingOnline 升序排序 |
| | | Sort.Order.desc("offLineCount") // 首先按照 pingOnline 升序排序 |
| | | ); |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(sort); |
| | | //分页数量 |
| | | 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 (item.getPingOnline() == null) { |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else if (!item.getPingOnline()) { |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | if (1 == item.getOnline()) { |
| | | item.setOnlineStr("在线"); |
| | | } else if (-1 == item.getOnline()) { |
| | | item.setOnlineStr("离线"); |
| | | } else { |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | List<String> offLineTime = item.getOffLineTimeStr(); |
| | | if (!CollectionUtils.isEmpty(offLineTime)) { |
| | | if (offLineTime.size() > 1) { |
| | | offLineTime = offLineTime.subList(offLineTime.size() - 2, offLineTime.size()); |
| | | } |
| | | /** |
| | | * 列表数据格式化 |
| | | */ |
| | | private void formatResultList(List<TMonitorResult> resultList,String tag) { |
| | | if(DataCenterMethodNameEnum.VIDEO_POINT_ONLINE_RATE.name().equals(tag)){ |
| | | resultList.forEach(item -> { |
| | | // pingOnline 状态转换 |
| | | if (item.getPingOnline() == null) { |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else { |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | item.setOffLineTimeStr(offLineTime); |
| | | } |
| | | //添加动态数据 |
| | | List<DynamicColumnVO> list = dynamicColumnMapper.getDynamicColumnByTable(TableNameConstants.COLUMN_NAME_VIDEO_POINT,item.getNo()); |
| | | item.setDynamicColumnList(list); |
| | | }); |
| | | |
| | | // online 状态转换 |
| | | if (1 == item.getOnline()) { |
| | | item.setOnlineStr("在线"); |
| | | } else if (-1 == item.getOnline()) { |
| | | item.setOnlineStr("离线"); |
| | | } else { |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | |
| | | params.setDeptTag(-1); |
| | | params.setDeviceType(1); |
| | | // 离线时间截断(保留最后2条) |
| | | List<String> offLineTime = item.getOffLineTimeStr(); |
| | | if (!CollectionUtils.isEmpty(offLineTime) && offLineTime.size() > 1) { |
| | | item.setOffLineTimeStr(offLineTime.subList(offLineTime.size() - 2, offLineTime.size())); |
| | | } |
| | | |
| | | //卡片统计 |
| | | 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())); |
| | | //此处新增了根据用户权限查询的情况 |
| | | if (areaDeptEnum != null){ |
| | | criteriaList.add(Criteria.where("no").regex("^" +areaDeptEnum.getCode())); |
| | | // 添加动态列数据 |
| | | List<DynamicColumnVO> dynamicColumns = dynamicColumnMapper.getDynamicColumnByTable( |
| | | TableNameConstants.COLUMN_NAME_VIDEO_POINT, |
| | | item.getNo() |
| | | ); |
| | | item.setDynamicColumnList(dynamicColumns); |
| | | }); |
| | | } |
| | | // 根据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)); |
| | | else if (DataCenterMethodNameEnum.DEPT_VIDEO_POINT_ONLINE_RATE.name().equals(tag) |
| | | || DataCenterMethodNameEnum.VIDEO_IMPORTANT_POINT_ONLINE_RATE.name().equals(tag)){ |
| | | resultList.forEach(item -> { |
| | | if (item.getPingOnline() == null) { |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else if (!item.getPingOnline()) { |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | if (1 == item.getOnline()) { |
| | | item.setOnlineStr("在线"); |
| | | } else if (-1 == item.getOnline()) { |
| | | item.setOnlineStr("离线"); |
| | | } else { |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | }); |
| | | } |
| | | // 构建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; |
| | | } |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (totalCount!=0) { |
| | | onlineRate = new BigDecimal(onlineCount).divide(new BigDecimal(totalCount), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | } |
| | | // /** 查询当天在线率 */ |
| | | // List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | // .select(CheckIndexVideo::getSiteOnline) |
| | | // .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | // .eq(params.getDataType().equals(2), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Dept) |
| | | // .between(CheckIndexVideo::getCreateTime, params.getStartTime(), params.getEndTime()) |
| | | // .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(totalCount + "", onlineCount + "", offlineCount + "", unknownCount + "", this.remove0(onlineRate))); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 视频:部级点位在线率 |
| | | * 卡片统计计算 |
| | | */ |
| | | private StatisticsResult calculateStatistics(DataCenterQuery params, AreaDeptEnum areaDeptEnum,String tag) { |
| | | int totalCount = 0, onlineCount = 0, offlineCount = 0, unknownCount = 0; |
| | | |
| | | // 计算在线率 |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (DataCenterMethodNameEnum.VIDEO_POINT_ONLINE_RATE.name().equals(tag)){ |
| | | // 构建统计条件 |
| | | 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())); |
| | | |
| | | // 权限过滤 |
| | | if (areaDeptEnum != null) { |
| | | criteriaList.add(Criteria.where("no").regex("^" + areaDeptEnum.getCode())); |
| | | } |
| | | // 数据类型过滤(省/部门标签) |
| | | 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)); |
| | | } |
| | | |
| | | // MongoDB 聚合查询 |
| | | 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()) { |
| | | onlineCount = (Integer) result.getOrDefault("onlineCount", 0); |
| | | offlineCount = (Integer) result.getOrDefault("offlineCount", 0); |
| | | unknownCount = (Integer) result.getOrDefault("unknownCount", 0); |
| | | totalCount = onlineCount + offlineCount + unknownCount; |
| | | } |
| | | |
| | | if (totalCount != 0) { |
| | | onlineRate = new BigDecimal(onlineCount) |
| | | .divide(new BigDecimal(totalCount), 3, RoundingMode.DOWN) |
| | | .multiply(new BigDecimal("100")); |
| | | } |
| | | } |
| | | else if (DataCenterMethodNameEnum.DEPT_VIDEO_POINT_ONLINE_RATE.name().equals(tag)) { |
| | | // 构建统计条件 |
| | | 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())); |
| | | //部级视频标签 差异点 |
| | | criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | // 权限过滤 |
| | | if (areaDeptEnum != null) { |
| | | criteriaList.add(Criteria.where("no").regex("^" + areaDeptEnum.getCode())); |
| | | } |
| | | // 数据类型过滤(省/部门标签) |
| | | 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)); |
| | | } |
| | | |
| | | // MongoDB 聚合查询 |
| | | 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()) { |
| | | onlineCount = (Integer) result.getOrDefault("onlineCount", 0); |
| | | offlineCount = (Integer) result.getOrDefault("offlineCount", 0); |
| | | unknownCount = (Integer) result.getOrDefault("unknownCount", 0); |
| | | totalCount = onlineCount + offlineCount + unknownCount; |
| | | } |
| | | |
| | | |
| | | if (totalCount != 0) { |
| | | onlineRate = new BigDecimal(onlineCount) |
| | | .divide(new BigDecimal(totalCount), 3, RoundingMode.DOWN) |
| | | .multiply(new BigDecimal("100")); |
| | | } |
| | | |
| | | } |
| | | else if (DataCenterMethodNameEnum.VIDEO_IMPORTANT_POINT_ONLINE_RATE.name().equals(tag)){ |
| | | // 构建统计条件 |
| | | 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())); |
| | | criteriaList.add(Criteria.where("importantTag").is(Boolean.TRUE)); |
| | | |
| | | // 权限过滤 |
| | | if (areaDeptEnum != null) { |
| | | criteriaList.add(Criteria.where("no").regex("^" + areaDeptEnum.getCode())); |
| | | } |
| | | // 数据类型过滤(省/部门标签) |
| | | 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)); |
| | | } |
| | | |
| | | // MongoDB 聚合查询 |
| | | 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()) { |
| | | onlineCount = (Integer) result.getOrDefault("onlineCount", 0); |
| | | offlineCount = (Integer) result.getOrDefault("offlineCount", 0); |
| | | unknownCount = (Integer) result.getOrDefault("unknownCount", 0); |
| | | totalCount = onlineCount + offlineCount + unknownCount; |
| | | } |
| | | |
| | | if (totalCount != 0) { |
| | | onlineRate = new BigDecimal(onlineCount) |
| | | .divide(new BigDecimal(totalCount), 3, RoundingMode.DOWN) |
| | | .multiply(new BigDecimal("100")); |
| | | } |
| | | } |
| | | |
| | | return new StatisticsResult(totalCount, onlineCount, offlineCount, unknownCount, onlineRate); |
| | | } |
| | | |
| | | /** |
| | | * 视频:点位在线率优化线程 |
| | | * |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result deptVideoPointOnlineRate(DataCenterQuery params) { |
| | | public Result videoPointOnlineRate(DataCenterQuery params) { |
| | | List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | //此处新增了根据用户权限查询的情况 |
| | | Query query = null; |
| | | final Query query; |
| | | SysDept sysDept = getSysDeptByLoginUser(); |
| | | AreaDeptEnum areaDeptEnum = null; |
| | | final AreaDeptEnum areaDeptEnum; // 声明为final |
| | | |
| | | if (sysDept != null) { |
| | | |
| | | areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); |
| | | if (areaDeptEnum != null) { |
| | | query = MongoUtil.getQueryDataCenter(areaDeptEnum.getCode(), params, TIME_FIELD, likeFileds, null, "no"); |
| | | } else { |
| | | query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | } |
| | | } else { |
| | | //需要初始化 不然下方引入 多线程会报未初始化 |
| | | areaDeptEnum = null; |
| | | query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | } |
| | | |
| | | |
| | | query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | if (params.getOption() != null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | |
| | | Sort sort = Sort.by( |
| | | Sort.Order.asc("pingOnline"), |
| | | Sort.Order.desc("offLineCount") |
| | | ); |
| | | query.with(sort); |
| | | |
| | | long total = mongoTemplate.count(query, TMonitorResult.class); |
| | | //运行分页查询线程 |
| | | CompletableFuture<List<TMonitorResult>> listFuture = CompletableFuture.supplyAsync(() -> { |
| | | try { |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | | List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class); |
| | | //构建列表数据 |
| | | formatResultList(resultList,DataCenterMethodNameEnum.VIDEO_POINT_ONLINE_RATE.name()); |
| | | return resultList; |
| | | } catch (Exception e) { |
| | | throw new CompletionException("视频设备列表查询失败:" + e.getMessage(), e); |
| | | } |
| | | }, taskExecutor); |
| | | //运行统计线程 |
| | | CompletableFuture<StatisticsResult> statsFuture = CompletableFuture.supplyAsync(() -> { |
| | | try { |
| | | return calculateStatistics(params, areaDeptEnum,DataCenterMethodNameEnum.VIDEO_POINT_ONLINE_RATE.name()); // 现在可安全引用 |
| | | } catch (Exception e) { |
| | | throw new CompletionException("视频设备状态统计失败:" + e.getMessage(), e); |
| | | } |
| | | }, taskExecutor); |
| | | |
| | | try { |
| | | CompletableFuture.allOf(listFuture, statsFuture).join(); |
| | | List<TMonitorResult> resultList = listFuture.get(); |
| | | StatisticsResult statsResult = statsFuture.get(); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", Arrays.asList( |
| | | String.valueOf(statsResult.totalCount), |
| | | String.valueOf(statsResult.onlineCount), |
| | | String.valueOf(statsResult.offlineCount), |
| | | String.valueOf(statsResult.unknownCount), |
| | | this.remove0(statsResult.onlineRate) |
| | | )); |
| | | map.put("list", resultList); |
| | | |
| | | return Result.ok().data(map).total(total); |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); |
| | | return Result.error("查询被中断,请稍后重试"); |
| | | } catch (ExecutionException e) { |
| | | Throwable rootCause = e.getCause(); |
| | | String errorMsg = rootCause != null ? rootCause.getMessage() : "视频设备数据查询失败"; |
| | | return Result.error(errorMsg); |
| | | } |
| | | } |
| | | |
| | | // @Override |
| | | // public Result videoPointOnlineRate(DataCenterQuery params) { |
| | | // List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | // //此处新增了根据用户权限查询的情况 |
| | | // Query query = null; |
| | | // SysDept sysDept = getSysDeptByLoginUser(); |
| | | // AreaDeptEnum areaDeptEnum = null; |
| | | // if (sysDept !=null){ |
| | | // areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); |
| | | // if (areaDeptEnum != null){ |
| | | // query = MongoUtil.getQueryDataCenter(areaDeptEnum.getCode(),params,TIME_FIELD,likeFileds,null,"no"); |
| | | // |
| | | // }else{ |
| | | // query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | // } |
| | | // }else { |
| | | // query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | // } |
| | | // |
| | | // //查视频设备 |
| | | // query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | // //下拉框在线情况查询条件 |
| | | // if (params.getOption() != null) { |
| | | // query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | // } |
| | | // Sort sort = Sort.by( |
| | | // Sort.Order.asc("pingOnline"), // 首先按照 pingOnline 升序排序 |
| | | // Sort.Order.desc("offLineCount") // 首先按照 pingOnline 升序排序 |
| | | // ); |
| | | // // 通过pingOnline字段排序,为false的排在前面 |
| | | // query.with(sort); |
| | | // //分页数量 |
| | | // 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 (item.getPingOnline() == null) { |
| | | // item.setPingOnlineStr("未知"); |
| | | // } else if (item.getPingOnline()) { |
| | | // item.setPingOnlineStr("在线"); |
| | | // } else if (!item.getPingOnline()) { |
| | | // item.setPingOnlineStr("离线"); |
| | | // } |
| | | // if (1 == item.getOnline()) { |
| | | // item.setOnlineStr("在线"); |
| | | // } else if (-1 == item.getOnline()) { |
| | | // item.setOnlineStr("离线"); |
| | | // } else { |
| | | // item.setOnlineStr("未知"); |
| | | // } |
| | | // List<String> offLineTime = item.getOffLineTimeStr(); |
| | | // if (!CollectionUtils.isEmpty(offLineTime)) { |
| | | // if (offLineTime.size() > 1) { |
| | | // offLineTime = offLineTime.subList(offLineTime.size() - 2, offLineTime.size()); |
| | | // } |
| | | // item.setOffLineTimeStr(offLineTime); |
| | | // } |
| | | // //添加动态数据 |
| | | // List<DynamicColumnVO> list = dynamicColumnMapper.getDynamicColumnByTable(TableNameConstants.COLUMN_NAME_VIDEO_POINT,item.getNo()); |
| | | // item.setDynamicColumnList(list); |
| | | // }); |
| | | // |
| | | // |
| | | // params.setDeptTag(-1); |
| | | // params.setDeviceType(1); |
| | | // |
| | | // //卡片统计 |
| | | // 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())); |
| | | // //此处新增了根据用户权限查询的情况 |
| | | // if (areaDeptEnum != null){ |
| | | // criteriaList.add(Criteria.where("no").regex("^" +areaDeptEnum.getCode())); |
| | | // } |
| | | // // 根据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; |
| | | // } |
| | | // BigDecimal onlineRate = BigDecimal.ZERO; |
| | | // if (totalCount!=0) { |
| | | // onlineRate = new BigDecimal(onlineCount).divide(new BigDecimal(totalCount), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | // } |
| | | // HashMap<String, Object> map = new HashMap<>(); |
| | | // map.put("count", Arrays.asList(totalCount + "", onlineCount + "", offlineCount + "", unknownCount + "", this.remove0(onlineRate))); |
| | | // map.put("list", resultList); |
| | | // return Result.ok().data(map).total(total); |
| | | // } |
| | | /** |
| | | * 视频:部级点位在线率优化线程 |
| | | * |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result deptVideoPointOnlineRate(DataCenterQuery params){ |
| | | List<String> likeFileds =Arrays.asList("name","no","ip"); |
| | | final Query query; |
| | | SysDept sysDept = getSysDeptByLoginUser(); |
| | | final AreaDeptEnum areaDeptEnum; |
| | | if (sysDept !=null){ |
| | | areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); |
| | | if (areaDeptEnum != null){ |
| | |
| | | query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | } |
| | | }else { |
| | | areaDeptEnum = null; |
| | | 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)); |
| | | //下拉框在线情况查询条件 |
| | |
| | | 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 (item.getPingOnline() == null) { |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else if (!item.getPingOnline()) { |
| | | item.setPingOnlineStr("离线"); |
| | | |
| | | CompletableFuture<List<TMonitorResult>> listFuture = CompletableFuture.supplyAsync(() ->{ |
| | | MongoUtil.setPage(query,params,TIME_FIELD); |
| | | List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class); |
| | | formatResultList(resultList,DataCenterMethodNameEnum.DEPT_VIDEO_POINT_ONLINE_RATE.name()); |
| | | return resultList; |
| | | },taskExecutor); |
| | | |
| | | CompletableFuture<StatisticsResult> statsFuture = CompletableFuture.supplyAsync(()->{ |
| | | try { |
| | | return calculateStatistics(params, areaDeptEnum,DataCenterMethodNameEnum.DEPT_VIDEO_POINT_ONLINE_RATE.name()); // 现在可安全引用 |
| | | } catch (Exception e) { |
| | | throw new CompletionException("视频设备状态统计失败:" + e.getMessage(), e); |
| | | } |
| | | if (1 == item.getOnline()) { |
| | | item.setOnlineStr("在线"); |
| | | } else if (-1 == item.getOnline()) { |
| | | item.setOnlineStr("离线"); |
| | | } else { |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | }); |
| | | // 统计设备数量 |
| | | //卡片统计 |
| | | int totalCount = 0; |
| | | int onlineCount = 0; |
| | | int offlineCount = 0; |
| | | int unknownCount = 0; |
| | | //构建条件 |
| | | List<Criteria> criteriaList = new ArrayList<>(); |
| | | //此处新增了根据用户权限查询的情况 |
| | | if (areaDeptEnum != null){ |
| | | criteriaList.add(Criteria.where("no").regex("^" +areaDeptEnum.getCode())); |
| | | },taskExecutor); |
| | | |
| | | try { |
| | | CompletableFuture.allOf(listFuture, statsFuture).join(); |
| | | List<TMonitorResult> resultList = listFuture.get(); |
| | | StatisticsResult statsResult = statsFuture.get(); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", Arrays.asList( |
| | | String.valueOf(statsResult.totalCount), |
| | | String.valueOf(statsResult.onlineCount), |
| | | String.valueOf(statsResult.offlineCount), |
| | | String.valueOf(statsResult.unknownCount), |
| | | this.remove0(statsResult.onlineRate) |
| | | )); |
| | | map.put("list", resultList); |
| | | |
| | | return Result.ok().data(map).total(total); |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); |
| | | return Result.error("查询被中断,请稍后重试"); |
| | | } catch (ExecutionException e) { |
| | | Throwable rootCause = e.getCause(); |
| | | String errorMsg = rootCause != null ? rootCause.getMessage() : "视频设备数据查询失败"; |
| | | return Result.error(errorMsg); |
| | | } |
| | | // 添加固定条件 |
| | | criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | // 根据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; |
| | | } |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (totalCount!=0) { |
| | | onlineRate = new BigDecimal(onlineCount).divide(new BigDecimal(totalCount), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | } |
| | | // params.setDeptTag(1); |
| | | // params.setDeviceType(1); |
| | | // List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | // .select(CheckIndexVideo::getMinistrySiteOnline) |
| | | // .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | // .eq(params.getDataType().equals(2), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Dept) |
| | | // .between(CheckIndexVideo::getCreateTime, params.getStartTime(), params.getEndTime()) |
| | | // .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(totalCount + "", onlineCount + "", offlineCount + "", unknownCount + "", this.remove0(onlineRate))); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |
| | | |
| | | // @Override |
| | | // public Result deptVideoPointOnlineRate(DataCenterQuery params) { |
| | | // List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | // //此处新增了根据用户权限查询的情况 |
| | | // Query query = null; |
| | | // SysDept sysDept = getSysDeptByLoginUser(); |
| | | // AreaDeptEnum areaDeptEnum = null; |
| | | // if (sysDept !=null){ |
| | | // areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); |
| | | // if (areaDeptEnum != null){ |
| | | // query = MongoUtil.getQueryDataCenter(areaDeptEnum.getCode(),params,TIME_FIELD,likeFileds,null,"no"); |
| | | // |
| | | // }else{ |
| | | // query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | // } |
| | | // }else { |
| | | // 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 (item.getPingOnline() == null) { |
| | | // item.setPingOnlineStr("未知"); |
| | | // } else if (item.getPingOnline()) { |
| | | // item.setPingOnlineStr("在线"); |
| | | // } else if (!item.getPingOnline()) { |
| | | // item.setPingOnlineStr("离线"); |
| | | // } |
| | | // if (1 == item.getOnline()) { |
| | | // item.setOnlineStr("在线"); |
| | | // } else if (-1 == item.getOnline()) { |
| | | // item.setOnlineStr("离线"); |
| | | // } else { |
| | | // item.setOnlineStr("未知"); |
| | | // } |
| | | // }); |
| | | // // 统计设备数量 |
| | | // //卡片统计 |
| | | // int totalCount = 0; |
| | | // int onlineCount = 0; |
| | | // int offlineCount = 0; |
| | | // int unknownCount = 0; |
| | | // //构建条件 |
| | | // List<Criteria> criteriaList = new ArrayList<>(); |
| | | // //此处新增了根据用户权限查询的情况 |
| | | // if (areaDeptEnum != null){ |
| | | // criteriaList.add(Criteria.where("no").regex("^" +areaDeptEnum.getCode())); |
| | | // } |
| | | // // 添加固定条件 |
| | | // criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | // criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | // criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | // // 根据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; |
| | | // } |
| | | // BigDecimal onlineRate = BigDecimal.ZERO; |
| | | // if (totalCount!=0) { |
| | | // onlineRate = new BigDecimal(onlineCount).divide(new BigDecimal(totalCount), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | // } |
| | | //// params.setDeptTag(1); |
| | | //// params.setDeviceType(1); |
| | | //// List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | //// .select(CheckIndexVideo::getMinistrySiteOnline) |
| | | //// .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | //// .eq(params.getDataType().equals(2), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Dept) |
| | | //// .between(CheckIndexVideo::getCreateTime, params.getStartTime(), params.getEndTime()) |
| | | //// .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(totalCount + "", onlineCount + "", offlineCount + "", unknownCount + "", this.remove0(onlineRate))); |
| | | // map.put("list", resultList); |
| | | // return Result.ok().data(map).total(total); |
| | | // } |
| | | |
| | | // @Override |
| | | // public Result videoImportantPointOnlineRate(DataCenterQuery params) { |
| | | // List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | // //此处新增了根据用户权限查询的情况 |
| | | // Query query = null; |
| | | // SysDept sysDept = getSysDeptByLoginUser(); |
| | | // AreaDeptEnum areaDeptEnum = null; |
| | | // if (sysDept !=null){ |
| | | // areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); |
| | | // if (areaDeptEnum != null){ |
| | | // query = MongoUtil.getQueryDataCenter(areaDeptEnum.getCode(),params,TIME_FIELD,likeFileds,null,"no"); |
| | | // |
| | | // }else{ |
| | | // query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | // } |
| | | // }else { |
| | | // 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); |
| | | // resultList.forEach(item -> { |
| | | // if (item.getPingOnline() == null) { |
| | | // item.setPingOnlineStr("未知"); |
| | | // } else if (item.getPingOnline()) { |
| | | // item.setPingOnlineStr("在线"); |
| | | // } else if (!item.getPingOnline()) { |
| | | // item.setPingOnlineStr("离线"); |
| | | // } |
| | | // if (1 == item.getOnline()) { |
| | | // item.setOnlineStr("在线"); |
| | | // } else if (-1 == item.getOnline()) { |
| | | // item.setOnlineStr("离线"); |
| | | // } else { |
| | | // item.setOnlineStr("未知"); |
| | | // } |
| | | // }); |
| | | // |
| | | // // 统计设备数量 |
| | | // //卡片统计 |
| | | // int totalCount = 0; |
| | | // int onlineCount = 0; |
| | | // int offlineCount = 0; |
| | | // int unknownCount = 0; |
| | | // //构建条件 |
| | | // List<Criteria> criteriaList = new ArrayList<>(); |
| | | // //此处新增了根据用户权限查询的情况 |
| | | // if (areaDeptEnum != null){ |
| | | // criteriaList.add(Criteria.where("no").regex("^" +areaDeptEnum.getCode())); |
| | | // } |
| | | // // 添加固定条件 |
| | | // criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | // criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | // criteriaList.add(Criteria.where("importantTag").is(Boolean.TRUE)); |
| | | // // 根据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; |
| | | // } |
| | | // BigDecimal onlineRate = BigDecimal.ZERO; |
| | | // if (totalCount!=0) { |
| | | // onlineRate = new BigDecimal(onlineCount).divide(new BigDecimal(totalCount), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | // } |
| | | // HashMap<String, Object> map = new HashMap<>(); |
| | | // map.put("count", Arrays.asList(totalCount + "", onlineCount + "", offlineCount + "", unknownCount + "", this.remove0(onlineRate))); |
| | | // map.put("list", resultList); |
| | | // return Result.ok().data(map).total(total); |
| | | // } |
| | | /** |
| | | * 视频:重点点位在线率 |
| | | * |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result videoImportantPointOnlineRate(DataCenterQuery params) { |
| | | public Result videoImportantPointOnlineRate(DataCenterQuery params){ |
| | | List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | //此处新增了根据用户权限查询的情况 |
| | | Query query = null; |
| | | final Query query; |
| | | SysDept sysDept = getSysDeptByLoginUser(); |
| | | AreaDeptEnum areaDeptEnum = null; |
| | | final AreaDeptEnum areaDeptEnum; |
| | | if (sysDept !=null){ |
| | | areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); |
| | | if (areaDeptEnum != null){ |
| | |
| | | query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | } |
| | | }else { |
| | | areaDeptEnum = null; |
| | | query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | } |
| | | //查视频设备 |
| | |
| | | } |
| | | // 通过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); |
| | | resultList.forEach(item -> { |
| | | if (item.getPingOnline() == null) { |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else if (!item.getPingOnline()) { |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | if (1 == item.getOnline()) { |
| | | item.setOnlineStr("在线"); |
| | | } else if (-1 == item.getOnline()) { |
| | | item.setOnlineStr("离线"); |
| | | } else { |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | }); |
| | | |
| | | // 统计设备数量 |
| | | //卡片统计 |
| | | int totalCount = 0; |
| | | int onlineCount = 0; |
| | | int offlineCount = 0; |
| | | int unknownCount = 0; |
| | | //构建条件 |
| | | List<Criteria> criteriaList = new ArrayList<>(); |
| | | //此处新增了根据用户权限查询的情况 |
| | | if (areaDeptEnum != null){ |
| | | criteriaList.add(Criteria.where("no").regex("^" +areaDeptEnum.getCode())); |
| | | CompletableFuture<List<TMonitorResult>> listFuture = CompletableFuture.supplyAsync(()->{ |
| | | try { |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | | List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class); |
| | | //构建列表数据 |
| | | formatResultList(resultList,DataCenterMethodNameEnum.VIDEO_IMPORTANT_POINT_ONLINE_RATE.name()); |
| | | |
| | | return resultList; |
| | | } catch (Exception e) { |
| | | throw new CompletionException("视频设备列表查询失败:" + e.getMessage(), e); |
| | | } |
| | | },taskExecutor); |
| | | |
| | | CompletableFuture<StatisticsResult> statsFuture = CompletableFuture.supplyAsync(()->{ |
| | | try { |
| | | return calculateStatistics(params, areaDeptEnum, DataCenterMethodNameEnum.VIDEO_IMPORTANT_POINT_ONLINE_RATE.name()); |
| | | }catch (Exception e){ |
| | | throw new CompletionException("视频设备状态统计失败:" + e.getMessage(), e); |
| | | } |
| | | },taskExecutor); |
| | | try { |
| | | CompletableFuture.allOf(listFuture, statsFuture).join(); |
| | | List<TMonitorResult> resultList = listFuture.get(); |
| | | StatisticsResult statsResult = statsFuture.get(); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", Arrays.asList( |
| | | String.valueOf(statsResult.totalCount), |
| | | String.valueOf(statsResult.onlineCount), |
| | | String.valueOf(statsResult.offlineCount), |
| | | String.valueOf(statsResult.unknownCount), |
| | | this.remove0(statsResult.onlineRate) |
| | | )); |
| | | map.put("list", resultList); |
| | | |
| | | return Result.ok().data(map).total(total); |
| | | } catch (InterruptedException e) { |
| | | Thread.currentThread().interrupt(); |
| | | return Result.error("查询被中断,请稍后重试"); |
| | | } catch (ExecutionException e) { |
| | | Throwable rootCause = e.getCause(); |
| | | String errorMsg = rootCause != null ? rootCause.getMessage() : "视频设备数据查询失败"; |
| | | return Result.error(errorMsg); |
| | | } |
| | | // 添加固定条件 |
| | | criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | criteriaList.add(Criteria.where("importantTag").is(Boolean.TRUE)); |
| | | // 根据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; |
| | | } |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (totalCount!=0) { |
| | | onlineRate = new BigDecimal(onlineCount).divide(new BigDecimal(totalCount), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | } |
| | | // List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | // .select(CheckIndexVideo::getKeySiteOnline) |
| | | // .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | // .eq(params.getDataType().equals(2), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Dept) |
| | | // .between(CheckIndexVideo::getCreateTime, params.getStartTime(), params.getEndTime()) |
| | | // .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(totalCount + "", onlineCount + "", offlineCount + "", unknownCount + "", this.remove0(onlineRate))); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | if (!StringUtils.isEmpty(rList.get(0)) && !"0".equals(rList.get(0))) { |
| | | onlineRate = new BigDecimal(rList.get(1)).divide(new BigDecimal(rList.get(0)), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | } |
| | | // List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | // .select(CheckIndexVideo::getMonitorQualification) |
| | | // .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | // .eq(params.getDataType().equals(2), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Dept) |
| | | // .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(params.getStartTime()), DateUtils.getDayEnd(params.getEndTime())) |
| | | // .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(this.remove0(onlineRate)); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", rList); |
| | |
| | | |
| | | List<DynamicColumnVO> list = dynamicColumnMapper.getDynamicColumnByTable(TableNameConstants.COLUMN_NAME_VIDEO,item.getId()); |
| | | item.setDynamicColumnList(list); |
| | | |
| | | }); |
| | | // 统计数量 |
| | | |
| | | MongoDatabase database = mongoTemplate.getDb(); |
| | | MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum"); |
| | | List<Integer> status = Arrays.asList(1, 0, -1); |
| | | // // 统计数量 |
| | | // MongoDatabase database = mongoTemplate.getDb(); |
| | | // MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum"); |
| | | // |
| | | // List<Integer> status = Arrays.asList(1, 0, -1); |
| | | // AreaDeptEnum finalAreaDeptEnum = areaDeptEnum; |
| | | // List<String> resultCount = status.stream().map(item -> { |
| | | // List<Document> dList = new ArrayList<>(2); |
| | | // |
| | | // dList.add(new Document("recordStatus", new Document("$eq", item))); |
| | | // if(finalAreaDeptEnum != null){ |
| | | // dList.add(new Document("$and", Arrays.asList( |
| | | // new Document("no", new Document("$in", noString)), |
| | | // new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | // ))); |
| | | // }else { |
| | | // dList.add(new Document("no", new Document("$in", noString))); |
| | | // } |
| | | // |
| | | // setTag(params, dList); |
| | | // Document filter = new Document("$and", dList); |
| | | // // 构建聚合管道 |
| | | // List<Document> pipeline = Arrays.asList( |
| | | // new Document("$match", filter), |
| | | // // $group 去重 |
| | | // new Document("$group", new Document("_id", "$deviceId")), |
| | | // new Document("$count", "uniqueDeviceIds") |
| | | // ); |
| | | // // 执行聚合查询并获取结果 |
| | | // AggregateIterable<Document> result = collection.aggregate(pipeline); |
| | | // Integer uniqueDeviceIdCount = 0; |
| | | // for (Document doc : result) { |
| | | // uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | // break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | // } |
| | | // return uniqueDeviceIdCount + ""; |
| | | // }).collect(Collectors.toList()); |
| | | // |
| | | // //计算录像可用率 |
| | | // MongoDatabase databaes2 = mongoTemplate.getDb(); |
| | | // MongoCollection<Document> collection2 = databaes2.getCollection("uy_record_meta_d_sum"); |
| | | // |
| | | // double finalRecordingMinTime = getSySMinTime(); |
| | | // |
| | | // List<Document> documentList = new ArrayList<>(2); |
| | | // if(finalAreaDeptEnum != null){ |
| | | // documentList.add(new Document("$and", Arrays.asList( |
| | | // new Document("no", new Document("$in", noString)), |
| | | // new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | // ))); |
| | | // }else { |
| | | // documentList.add(new Document("no", new Document("$in", noString))); |
| | | // } |
| | | // // documentList.add(new Document("$and", Arrays.asList( |
| | | // // new Document("no", new Document("$in", noString)), |
| | | // // new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | // // ))); |
| | | // setTag(params, documentList); |
| | | // Document recording = new Document("missDuration",new Document("$lte", finalRecordingMinTime)); |
| | | // documentList.add(recording); |
| | | // |
| | | // Document filter = new Document("$and", documentList); |
| | | // // 构建聚合管道 |
| | | // List<Document> pipeline = Arrays.asList( |
| | | // new Document("$match", filter), |
| | | // // $group 去重 |
| | | // new Document("$group", new Document("_id", "$deviceId")), |
| | | // new Document("$count", "uniqueDeviceIds") |
| | | // ); |
| | | // AggregateIterable<Document> result = collection2.aggregate(pipeline); |
| | | // |
| | | // |
| | | // Integer uniqueDeviceIdCount = 0; |
| | | // for (Document doc : result) { |
| | | // uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | // break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | // } |
| | | // log.error("录像可用率打印:{}",uniqueDeviceIdCount); |
| | | // int totalCount = 0; |
| | | // for (String s : resultCount) { |
| | | // totalCount += Integer.parseInt(s); |
| | | // } |
| | | // resultCount.add(0, totalCount + ""); |
| | | // |
| | | // BigDecimal onlineRate = BigDecimal.ZERO; |
| | | // // 1:完整 0:间歇 -1:异常 | |
| | | // if (!StringUtils.isEmpty(resultCount.get(0)) && !"0".equals(resultCount.get(0))) { |
| | | // //resultCount.get(0)是总数 uniqueDeviceIdCount是根据系统参数查询到mongodb中大于等于 recordDuration字段的总数 |
| | | // onlineRate = new BigDecimal(uniqueDeviceIdCount).divide(new BigDecimal(resultCount.get(0)), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | // } |
| | | // resultCount.add(this.remove0(onlineRate)); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", this.buildCount(areaDeptEnum,noString,params,DataCenterMethodNameEnum.VIDEO_AVAILABILITY_RATE.name())); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |
| | | public List<String> buildCount(AreaDeptEnum areaDeptEnum,List<String> noString,DataCenterQuery params,String tag){ |
| | | MongoDatabase databaes= mongoTemplate.getDb(); |
| | | MongoCollection<Document> collection = databaes.getCollection("uy_record_meta_d_sum"); |
| | | AreaDeptEnum finalAreaDeptEnum = areaDeptEnum; |
| | | List<String> resultCount = status.stream().map(item -> { |
| | | List<Document> dList = new ArrayList<>(2); |
| | | |
| | | dList.add(new Document("recordStatus", new Document("$eq", item))); |
| | | if(finalAreaDeptEnum != null){ |
| | | dList.add(new Document("$and", Arrays.asList( |
| | | new Document("no", new Document("$in", noString)), |
| | | new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | ))); |
| | | }else { |
| | | dList.add(new Document("no", new Document("$in", noString))); |
| | | } |
| | | |
| | | setTag(params, dList); |
| | | Document filter = new Document("$and", dList); |
| | | // 构建聚合管道 |
| | | List<Document> pipeline = Arrays.asList( |
| | | new Document("$match", filter), |
| | | // $group 去重 |
| | | new Document("$group", new Document("_id", "$deviceId")), |
| | | new Document("$count", "uniqueDeviceIds") |
| | | ); |
| | | // 执行聚合查询并获取结果 |
| | | AggregateIterable<Document> result = collection.aggregate(pipeline); |
| | | Integer uniqueDeviceIdCount = 0; |
| | | for (Document doc : result) { |
| | | uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | } |
| | | return uniqueDeviceIdCount + ""; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | //计算录像可用率 |
| | | MongoDatabase databaes2 = mongoTemplate.getDb(); |
| | | MongoCollection<Document> collection2 = databaes2.getCollection("uy_record_meta_d_sum"); |
| | | |
| | | double finalRecordingMinTime = getSySMinTime(); |
| | | // 2. 构建聚合管道(核心:一次管道统计所有指标) |
| | | List<Document> pipeline = new ArrayList<>(); |
| | | |
| | | List<Document> documentList = new ArrayList<>(2); |
| | | if(finalAreaDeptEnum != null){ |
| | | documentList.add(new Document("$and", Arrays.asList( |
| | | // 阶段1:$match - 基础过滤(复用两次查询的共同条件) |
| | | List<Document> baseFilterList = new ArrayList<>(); |
| | | if (DataCenterMethodNameEnum.DEPT_VIDEO_POINT_ONLINE_RATE.name().equals(tag)){ |
| | | baseFilterList.add(new Document("deptTag", new Document("$eq", Boolean.TRUE))); |
| | | } |
| | | if (DataCenterMethodNameEnum.VIDEO_IMPORTANT_POINT_AVAILABILITY_RATE.name().equals(tag)){ |
| | | baseFilterList.add(new Document("importantTag", new Document("$eq", Boolean.TRUE))); |
| | | } |
| | | |
| | | // 条件1:no的过滤(in + 可选前缀匹配,和你原代码逻辑一致) |
| | | if (finalAreaDeptEnum != null) { |
| | | baseFilterList.add(new Document("$and", Arrays.asList( |
| | | new Document("no", new Document("$in", noString)), |
| | | new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | ))); |
| | | }else { |
| | | documentList.add(new Document("no", new Document("$in", noString))); |
| | | } else { |
| | | baseFilterList.add(new Document("no", new Document("$in", noString))); |
| | | } |
| | | // documentList.add(new Document("$and", Arrays.asList( |
| | | // new Document("no", new Document("$in", noString)), |
| | | // new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | // ))); |
| | | setTag(params, documentList); |
| | | Document recording = new Document("missDuration",new Document("$lte", finalRecordingMinTime)); |
| | | documentList.add(recording); |
| | | |
| | | Document filter = new Document("$and", documentList); |
| | | // 构建聚合管道 |
| | | List<Document> pipeline = Arrays.asList( |
| | | new Document("$match", filter), |
| | | // $group 去重 |
| | | new Document("$group", new Document("_id", "$deviceId")), |
| | | new Document("$count", "uniqueDeviceIds") |
| | | setTag(params, baseFilterList); |
| | | Document matchStage = new Document("$match", new Document("$and", baseFilterList)); |
| | | pipeline.add(matchStage); |
| | | // 阶段2:$group - 按deviceId去重,标记各条件是否满足 |
| | | // -------------------------- |
| | | // 逻辑:每个设备只统计一次,用$cond标记“是否符合某条件”(符合=1,不符合=0) |
| | | Document groupByDeviceStage = new Document("$group", |
| | | new Document("_id", "$deviceId") // 按设备ID分组(去重核心) |
| | | // 标记:该设备是否满足 recordStatus=1 |
| | | .append("status1Flag", new Document("$sum", |
| | | new Document("$cond", Arrays.asList( |
| | | new Document("$eq", Arrays.asList("$recordStatus", 1)), // 判断条件 |
| | | 1, // 符合:记1 |
| | | 0 // 不符合:记0 |
| | | )) |
| | | )) |
| | | // 标记:该设备是否满足 recordStatus=0 |
| | | .append("status0Flag", new Document("$sum", |
| | | new Document("$cond", Arrays.asList( |
| | | new Document("$eq", Arrays.asList("$recordStatus", 0)), |
| | | 1, |
| | | 0 |
| | | )) |
| | | )) |
| | | // 标记:该设备是否满足 recordStatus=-1 |
| | | .append("statusMinus1Flag", new Document("$sum", |
| | | new Document("$cond", Arrays.asList( |
| | | new Document("$eq", Arrays.asList("$recordStatus", -1)), |
| | | 1, |
| | | 0 |
| | | )) |
| | | )) |
| | | // 标记:该设备是否满足 missDuration ≤ finalRecordingMinTime(原第二段查询条件) |
| | | .append("missOkFlag", new Document("$sum", |
| | | new Document("$cond", Arrays.asList( |
| | | new Document("$lte", Arrays.asList("$missDuration", finalRecordingMinTime)), |
| | | 1, |
| | | 0 |
| | | )) |
| | | )) |
| | | ); |
| | | AggregateIterable<Document> result = collection2.aggregate(pipeline); |
| | | pipeline.add(groupByDeviceStage); |
| | | // -------------------------- |
| | | // 阶段3:$group - 全局统计(累加所有设备的标记,得到最终数量) |
| | | // -------------------------- |
| | | // 逻辑:无分组键(_id: null),将所有设备的标记累加,得到总计数 |
| | | Document groupGlobalStage = new Document("$group", |
| | | new Document("_id", null) // 全局分组(统计所有设备) |
| | | // 原第一段查询结果1:status=1的设备数 |
| | | .append("status1Count", new Document("$sum", "$status1Flag")) |
| | | // 原第一段查询结果2:status=0的设备数 |
| | | .append("status0Count", new Document("$sum", "$status0Flag")) |
| | | // 原第一段查询结果3:status=-1的设备数 |
| | | .append("statusMinus1Count", new Document("$sum", "$statusMinus1Flag")) |
| | | // 原第二段查询结果:missDuration符合条件的设备数 |
| | | .append("missOkCount", new Document("$sum", "$missOkFlag")) |
| | | ); |
| | | pipeline.add(groupGlobalStage); |
| | | |
| | | |
| | | Integer uniqueDeviceIdCount = 0; |
| | | for (Document doc : result) { |
| | | uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | // -------------------------- |
| | | // 执行聚合查询,提取所有统计结果 |
| | | // -------------------------- |
| | | AggregateIterable<Document> aggregateResult = collection.aggregate(pipeline); |
| | | Document statDoc = null; |
| | | for (Document doc : aggregateResult) { // 全局分组只会返回1条结果 |
| | | statDoc = doc; |
| | | break; |
| | | } |
| | | log.error("录像可用率打印:{}",uniqueDeviceIdCount); |
| | | int totalCount = 0; |
| | | for (String s : resultCount) { |
| | | totalCount += Integer.parseInt(s); |
| | | } |
| | | resultCount.add(0, totalCount + ""); |
| | | |
| | | // 初始化默认值(避免空指针) |
| | | int status1Count = 0, status0Count = 0, statusMinus1Count = 0, missOkCount = 0; |
| | | if (statDoc != null) { |
| | | status1Count = statDoc.getInteger("status1Count", 0); |
| | | status0Count = statDoc.getInteger("status0Count", 0); |
| | | statusMinus1Count = statDoc.getInteger("statusMinus1Count", 0); |
| | | missOkCount = statDoc.getInteger("missOkCount", 0); |
| | | } |
| | | int total = status1Count + status0Count + statusMinus1Count; |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | // 1:完整 0:间歇 -1:异常 | |
| | | if (!StringUtils.isEmpty(resultCount.get(0)) && !"0".equals(resultCount.get(0))) { |
| | | //resultCount.get(0)是总数 uniqueDeviceIdCount是更具系统参数查询到mongodb中大于等于 recordDuration字段的总数 |
| | | onlineRate = new BigDecimal(uniqueDeviceIdCount).divide(new BigDecimal(resultCount.get(0)), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | if (total != 0) { // 只有当total不为0时,才计算比率 |
| | | onlineRate = new BigDecimal(missOkCount) |
| | | .divide(new BigDecimal(total), 3, RoundingMode.DOWN) |
| | | .multiply(new BigDecimal("100")); |
| | | } |
| | | resultCount.add(this.remove0(onlineRate)); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", resultCount); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(total +""); |
| | | list.add(status1Count +""); |
| | | list.add(status0Count +""); |
| | | list.add(statusMinus1Count +""); |
| | | list.add(this.remove0(onlineRate)); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public Result deptVideoAvailabilityRate(DataCenterQuery params) { |
| | | List<String> noString = tMonitorMapper.getIdListVideo(); |
| | | List<String> likeFileds = Arrays.asList("deviceId", "deviceName"); |
| | | SysDept sysDept = getSysDeptByLoginUser(); |
| | | AreaDeptEnum areaDeptEnum = null; |
| | |
| | | }else { |
| | | query = MongoUtil.getQuery(params, "createTime", likeFileds, null); |
| | | } |
| | | if (CollectionUtils.isNotEmpty(noString)) { // 防止空集合异常 |
| | | query.addCriteria(Criteria.where("no").in(noString)); |
| | | } |
| | | //下拉框录像情况查询条件 |
| | | if (params.getOption() != null) { |
| | | query.addCriteria(Criteria.where("recordStatus").is(params.getOption())); |
| | | } |
| | | //新增部级判断 |
| | | query.addCriteria(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | long total = mongoTemplate.count(query, RecordMetaDSumResult.class); |
| | | MongoUtil.setPage(query, params, "createTime"); |
| | | List<RecordMetaDSumResult> resultList = mongoTemplate.find(query, RecordMetaDSumResult.class); |
| | |
| | | AreaDeptEnum areaDeptEnumInfo = AreaDeptEnum.fromCode(areaCode); |
| | | if (areaDeptEnumInfo != null) item.setArealayername(areaDeptEnumInfo.getName()); |
| | | }); |
| | | // 统计数量 |
| | | MongoDatabase database = mongoTemplate.getDb(); |
| | | MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum"); |
| | | List<Integer> status = Arrays.asList(1, 0, -1); |
| | | AreaDeptEnum finalAreaDeptEnum = areaDeptEnum; |
| | | List<String> resultCount = status.stream().map(item -> { |
| | | List<Document> dList = new ArrayList<>(4); |
| | | dList.add(new Document("deptTag", new Document("$eq", Boolean.TRUE))); |
| | | dList.add(new Document("recordStatus", new Document("$eq", item))); |
| | | setTag(params, dList); |
| | | if (finalAreaDeptEnum != null){ |
| | | dList.add(new Document("$and", Arrays.asList( |
| | | // new Document("no", new Document("$in", noString)), |
| | | new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | ))); |
| | | } |
| | | Document filter = new Document("$and", dList); |
| | | // 构建聚合管道 |
| | | List<Document> pipeline = Arrays.asList( |
| | | new Document("$match", filter), |
| | | // $group 去重 |
| | | new Document("$group", new Document("_id", "$deviceId")), |
| | | new Document("$count", "uniqueDeviceIds") |
| | | ); |
| | | // 执行聚合查询并获取结果 |
| | | AggregateIterable<Document> result = collection.aggregate(pipeline); |
| | | Integer uniqueDeviceIdCount = 0; |
| | | for (Document doc : result) { |
| | | uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | } |
| | | return uniqueDeviceIdCount + ""; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | |
| | | //计算部级录像可用率 |
| | | MongoDatabase database2 = mongoTemplate.getDb(); |
| | | MongoCollection<Document> collection2 = database2.getCollection("uy_record_meta_d_sum"); |
| | | double finalRecordingMinTime = getSySMinTime(); |
| | | |
| | | List<Document> documentList = new ArrayList<>(4); |
| | | documentList.add(new Document("deptTag", new Document("$eq", Boolean.TRUE))); |
| | | setTag(params, documentList); |
| | | Document recording = new Document("missDuration",new Document("$lte", finalRecordingMinTime)); |
| | | documentList.add(recording); |
| | | if (finalAreaDeptEnum != null){ |
| | | documentList.add(new Document("$and", Arrays.asList( |
| | | // new Document("no", new Document("$in", noString)), |
| | | new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | ))); |
| | | } |
| | | Document filter = new Document("$and", documentList); |
| | | // 构建聚合管道 |
| | | List<Document> pipeline = Arrays.asList( |
| | | new Document("$match", filter), |
| | | // $group 去重 |
| | | new Document("$group", new Document("_id", "$deviceId")), |
| | | new Document("$count", "uniqueDeviceIds") |
| | | ); |
| | | AggregateIterable<Document> result = collection2.aggregate(pipeline); |
| | | Integer uniqueDeviceIdCount = 0; |
| | | for (Document doc : result) { |
| | | uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | } |
| | | log.error("部级录像可用率{}:",uniqueDeviceIdCount); |
| | | |
| | | |
| | | |
| | | // List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | // .select(CheckIndexVideo::getMinistryVideoAvailable) |
| | | // .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | // .eq(params.getDataType().equals(2), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Dept) |
| | | // .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(params.getStartTime()), DateUtils.getDayEnd(params.getEndTime())) |
| | | // .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)); |
| | | // } |
| | | //加一个总数 |
| | | int totalCount = 0; |
| | | for (String s : resultCount) { |
| | | totalCount += Integer.parseInt(s); |
| | | } |
| | | resultCount.add(0, totalCount + ""); |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (!StringUtils.isEmpty(resultCount.get(0)) && !"0".equals(resultCount.get(0))) { |
| | | onlineRate = new BigDecimal(uniqueDeviceIdCount).divide(new BigDecimal(resultCount.get(0)), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | } |
| | | resultCount.add(this.remove0(onlineRate)); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", resultCount); |
| | | map.put("count", this.buildCount(areaDeptEnum,noString,params,DataCenterMethodNameEnum.DEPT_VIDEO_POINT_ONLINE_RATE.name())); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |
| | | |
| | | /** |
| | | * 视频:重点点位录像可用率 |
| | | * |
| | |
| | | */ |
| | | @Override |
| | | public Result videoImportantPointAvailabilityRate(DataCenterQuery params) { |
| | | List<String> noString = tMonitorMapper.getIdListVideo(); |
| | | List<String> likeFileds = Arrays.asList("deviceId", "deviceName"); |
| | | SysDept sysDept = getSysDeptByLoginUser(); |
| | | AreaDeptEnum areaDeptEnum = null; |
| | |
| | | query = MongoUtil.getQuery(params, "createTime", likeFileds, null); |
| | | } |
| | | query.addCriteria(Criteria.where("importantTag").is(Boolean.TRUE)); |
| | | if (CollectionUtils.isNotEmpty(noString)) { // 防止空集合异常 |
| | | query.addCriteria(Criteria.where("no").in(noString)); |
| | | } |
| | | //下拉框录像情况查询条件 |
| | | if (params.getOption() != null) { |
| | | query.addCriteria(Criteria.where("recordStatus").is(params.getOption())); |
| | | } |
| | | |
| | | long total = mongoTemplate.count(query, RecordMetaDSumResult.class); |
| | | MongoUtil.setPage(query, params, "createTime"); |
| | | List<RecordMetaDSumResult> resultList = mongoTemplate.find(query, RecordMetaDSumResult.class); |
| | |
| | | if (areaDeptEnumInfo != null) item.setArealayername(areaDeptEnumInfo.getName()); |
| | | }); |
| | | // 统计数量 |
| | | MongoDatabase database = mongoTemplate.getDb(); |
| | | MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum"); |
| | | List<Integer> status = Arrays.asList(1, 0, -1); |
| | | AreaDeptEnum finalAreaDeptEnum = areaDeptEnum; |
| | | List<String> resultCount = status.stream().map(item -> { |
| | | List<Document> dList = new ArrayList<>(4); |
| | | dList.add(new Document("importantTag", new Document("$eq", Boolean.TRUE))); |
| | | dList.add(new Document("recordStatus", new Document("$eq", item))); |
| | | setTag(params, dList); |
| | | if (finalAreaDeptEnum != null){ |
| | | dList.add(new Document("$and", Arrays.asList( |
| | | // new Document("no", new Document("$in", noString)), |
| | | new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | ))); |
| | | } |
| | | Document filter = new Document("$and", dList); |
| | | // 构建聚合管道 |
| | | List<Document> pipeline = Arrays.asList( |
| | | new Document("$match", filter), |
| | | // $group 去重 |
| | | new Document("$group", new Document("_id", "$deviceId")), |
| | | new Document("$count", "uniqueDeviceIds") |
| | | ); |
| | | // 执行聚合查询并获取结果 |
| | | AggregateIterable<Document> result = collection.aggregate(pipeline); |
| | | Integer uniqueDeviceIdCount = 0; |
| | | for (Document doc : result) { |
| | | uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | } |
| | | return uniqueDeviceIdCount + ""; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | //计算重点点位录像可用率 |
| | | MongoDatabase database2 = mongoTemplate.getDb(); |
| | | MongoCollection<Document> collection2 = database2.getCollection("uy_record_meta_d_sum"); |
| | | double finalRecordingMinTime = getSySMinTime(); |
| | | |
| | | List<Document> documentList = new ArrayList<>(4); |
| | | documentList.add(new Document("importantTag", new Document("$eq", Boolean.TRUE))); |
| | | setTag(params, documentList); |
| | | Document recording = new Document("missDuration",new Document("$lte", finalRecordingMinTime)); |
| | | documentList.add(recording); |
| | | if (finalAreaDeptEnum != null){ |
| | | documentList.add(new Document("$and", Arrays.asList( |
| | | // new Document("no", new Document("$in", noString)), |
| | | new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | ))); |
| | | } |
| | | Document filter = new Document("$and", documentList); |
| | | // 构建聚合管道 |
| | | List<Document> pipeline = Arrays.asList( |
| | | new Document("$match", filter), |
| | | // $group 去重 |
| | | new Document("$group", new Document("_id", "$deviceId")), |
| | | new Document("$count", "uniqueDeviceIds") |
| | | ); |
| | | AggregateIterable<Document> result = collection2.aggregate(pipeline); |
| | | Integer uniqueDeviceIdCount = 0; |
| | | for (Document doc : result) { |
| | | uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | } |
| | | log.error("重点点位录像可用率{}:",uniqueDeviceIdCount); |
| | | |
| | | // List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | // .select(CheckIndexVideo::getKeyVideoAvailable) |
| | | // .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | // .eq(params.getDataType().equals(2), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Dept) |
| | | // .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(params.getStartTime()), DateUtils.getDayEnd(params.getEndTime())) |
| | | // .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)); |
| | | // MongoDatabase database = mongoTemplate.getDb(); |
| | | // MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum"); |
| | | // List<Integer> status = Arrays.asList(1, 0, -1); |
| | | // AreaDeptEnum finalAreaDeptEnum = areaDeptEnum; |
| | | // List<String> resultCount = status.stream().map(item -> { |
| | | // List<Document> dList = new ArrayList<>(4); |
| | | // dList.add(new Document("importantTag", new Document("$eq", Boolean.TRUE))); |
| | | // dList.add(new Document("recordStatus", new Document("$eq", item))); |
| | | // setTag(params, dList); |
| | | // if (finalAreaDeptEnum != null){ |
| | | // dList.add(new Document("$and", Arrays.asList( |
| | | //// new Document("no", new Document("$in", noString)), |
| | | // new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | // ))); |
| | | // } |
| | | // Document filter = new Document("$and", dList); |
| | | // // 构建聚合管道 |
| | | // List<Document> pipeline = Arrays.asList( |
| | | // new Document("$match", filter), |
| | | // // $group 去重 |
| | | // new Document("$group", new Document("_id", "$deviceId")), |
| | | // new Document("$count", "uniqueDeviceIds") |
| | | // ); |
| | | // // 执行聚合查询并获取结果 |
| | | // AggregateIterable<Document> result = collection.aggregate(pipeline); |
| | | // Integer uniqueDeviceIdCount = 0; |
| | | // for (Document doc : result) { |
| | | // uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | // break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | // } |
| | | // return uniqueDeviceIdCount + ""; |
| | | // }).collect(Collectors.toList()); |
| | | // |
| | | // //计算重点点位录像可用率 |
| | | // MongoDatabase database2 = mongoTemplate.getDb(); |
| | | // MongoCollection<Document> collection2 = database2.getCollection("uy_record_meta_d_sum"); |
| | | // double finalRecordingMinTime = getSySMinTime(); |
| | | // |
| | | // List<Document> documentList = new ArrayList<>(4); |
| | | // documentList.add(new Document("importantTag", new Document("$eq", Boolean.TRUE))); |
| | | // setTag(params, documentList); |
| | | // Document recording = new Document("missDuration",new Document("$lte", finalRecordingMinTime)); |
| | | // documentList.add(recording); |
| | | // if (finalAreaDeptEnum != null){ |
| | | // documentList.add(new Document("$and", Arrays.asList( |
| | | //// new Document("no", new Document("$in", noString)), |
| | | // new Document("no", new Document("$regex", "^" + finalAreaDeptEnum.getCode())) |
| | | // ))); |
| | | // } |
| | | //加一个总数 |
| | | int totalCount = 0; |
| | | for (String s : resultCount) { |
| | | totalCount += Integer.parseInt(s); |
| | | } |
| | | resultCount.add(0, totalCount + ""); |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (!StringUtils.isEmpty(resultCount.get(0)) && !"0".equals(resultCount.get(0))) { |
| | | onlineRate = new BigDecimal(uniqueDeviceIdCount).divide(new BigDecimal(resultCount.get(0)), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | } |
| | | resultCount.add(this.remove0(onlineRate)); |
| | | // Document filter = new Document("$and", documentList); |
| | | // // 构建聚合管道 |
| | | // List<Document> pipeline = Arrays.asList( |
| | | // new Document("$match", filter), |
| | | // // $group 去重 |
| | | // new Document("$group", new Document("_id", "$deviceId")), |
| | | // new Document("$count", "uniqueDeviceIds") |
| | | // ); |
| | | // AggregateIterable<Document> result = collection2.aggregate(pipeline); |
| | | // Integer uniqueDeviceIdCount = 0; |
| | | // for (Document doc : result) { |
| | | // uniqueDeviceIdCount = doc.getInteger("uniqueDeviceIds"); |
| | | // break; // 不需要继续遍历,因为 $count 只会产生一个结果 |
| | | // } |
| | | // log.error("重点点位录像可用率{}:",uniqueDeviceIdCount); |
| | | // |
| | | // //加一个总数 |
| | | // int totalCount = 0; |
| | | // for (String s : resultCount) { |
| | | // totalCount += Integer.parseInt(s); |
| | | // } |
| | | // resultCount.add(0, totalCount + ""); |
| | | // BigDecimal onlineRate = BigDecimal.ZERO; |
| | | // if (!StringUtils.isEmpty(resultCount.get(0)) && !"0".equals(resultCount.get(0))) { |
| | | // onlineRate = new BigDecimal(uniqueDeviceIdCount).divide(new BigDecimal(resultCount.get(0)), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); |
| | | // } |
| | | // resultCount.add(this.remove0(onlineRate)); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", resultCount); |
| | | map.put("count", this.buildCount(areaDeptEnum,noString,params,DataCenterMethodNameEnum.VIDEO_IMPORTANT_POINT_AVAILABILITY_RATE.name())); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |