| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.github.pagehelper.Page; |
| | |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.MongoUtil; |
| | | import constant.ApiConstants; |
| | | import constant.CheckConstants; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.bson.Document; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.aggregation.*; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.TextCriteria; |
| | |
| | | public Result videoPointOnlineRate(DataCenterQuery params) { |
| | | List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | System.out.println("查询条件"+query.toString()); |
| | | //查视频设备 |
| | | query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | //下拉框在线情况查询条件 |
| | | if(params.getOption()!=null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(Sort.by(Sort.Order.asc("pingOnline"))); |
| | | //分页数量 |
| | | long total = mongoTemplate.count(query, TMonitorResult.class); |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | | List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class); |
| | | resultList.forEach(item -> { |
| | | if (null != item.getPingOnline() && item.getPingOnline()) { |
| | | if(item.getPingOnline() ==null){ |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else { |
| | | } else if(!item.getPingOnline()){ |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | if(1== item.getOnline() ){ |
| | |
| | | }); |
| | | params.setDeptTag(-1); |
| | | params.setDeviceType(1); |
| | | // 统计设备数量 |
| | | Integer distinctCount = pointMapper.distinctCount(params); |
| | | |
| | | List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | .select(CheckIndexVideo::getSiteOnline) |
| | | .between(CheckIndexVideo::getCreateTime, params.getStartTime(), params.getEndTime()) |
| | | .list(); |
| | | //卡片统计 |
| | | int totalCount =0; |
| | | int onlineCount =0; |
| | | int offlineCount =0; |
| | | int unknownCount =0; |
| | | //构建条件 |
| | | List<Criteria> criteriaList = new ArrayList<>(); |
| | | // 添加固定条件 |
| | | criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | // 根据dataType动态添加条件 |
| | | if (params.getDataType() == 1) { |
| | | criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE)); |
| | | } else if (params.getDataType() == 2) { |
| | | criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | } |
| | | // 构建match操作 |
| | | MatchOperation match = Aggregation.match( |
| | | new Criteria().andOperator(criteriaList.toArray(new Criteria[0])) |
| | | ); |
| | | GroupOperation group = Aggregation.group() |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount"); |
| | | // 将匹配阶段和分组阶段组合起来 |
| | | Aggregation aggregation = Aggregation.newAggregation(match, group); |
| | | // 执行聚合查询 |
| | | AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称 |
| | | for (Map<String, Object> result : results.getMappedResults()) { |
| | | offlineCount =(Integer) result.getOrDefault("offlineCount",0L); |
| | | unknownCount =(Integer) result.getOrDefault("unknownCount",0L); |
| | | onlineCount = (Integer) result.getOrDefault("onlineCount",0L); |
| | | totalCount = offlineCount + unknownCount + onlineCount; |
| | | } |
| | | /** 查询当天在线率 */ |
| | | // 创建一个QueryWrapper实例 |
| | | QueryWrapper<CheckIndexVideo> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.lambda().select(CheckIndexVideo::getSiteOnline) // 选择要查询的字段 |
| | | .between(CheckIndexVideo::getCreateTime, params.getStartTime(), params.getEndTime()); // 设置时间范围条件 |
| | | if (params.getDataType() == 0) { |
| | | //区县 |
| | | queryWrapper.lambda().eq(CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_County); |
| | | }else if(params.getDataType() == 1){ |
| | | //省厅 |
| | | queryWrapper.lambda().eq(CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province); |
| | | }else if(params.getDataType() == 2){ |
| | | //公安部 |
| | | queryWrapper.lambda().eq(CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Dept); |
| | | } |
| | | // 使用QueryWrapper执行查询 |
| | | List<CheckIndexVideo> videoList = checkIndexVideoService.getBaseMapper().selectList(queryWrapper); |
| | | |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (CollectionUtils.isNotEmpty(videoList)) { |
| | | BigDecimal sum = videoList.stream().map(CheckIndexVideo::getSiteOnline).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | |
| | | onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); |
| | | } |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate))); |
| | | map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate))); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |
| | |
| | | public Result deptVideoPointOnlineRate(DataCenterQuery params) { |
| | | List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | //查视频设备 |
| | | query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | query.addCriteria(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | //下拉框在线情况查询条件 |
| | | if(params.getOption()!=null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(Sort.by(Sort.Order.asc("pingOnline"))); |
| | | //分页数量 |
| | | long total = mongoTemplate.count(query, TMonitorResult.class); |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | | List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class); |
| | | resultList.forEach(item -> { |
| | | if (null != item.getPingOnline() && item.getPingOnline()) { |
| | | if(item.getPingOnline() ==null){ |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else { |
| | | } else if(!item.getPingOnline()){ |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | if (1 == item.getOnline()) { |
| | |
| | | } |
| | | }); |
| | | // 统计设备数量 |
| | | //卡片统计 |
| | | int totalCount =0; |
| | | int onlineCount =0; |
| | | int offlineCount =0; |
| | | int unknownCount =0; |
| | | //构建条件 |
| | | List<Criteria> criteriaList = new ArrayList<>(); |
| | | // 添加固定条件 |
| | | criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | // 根据dataType动态添加条件 |
| | | if (params.getDataType() == 1) { |
| | | criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE)); |
| | | } else if (params.getDataType() == 2) { |
| | | criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | } |
| | | // 构建match操作 |
| | | MatchOperation match = Aggregation.match( |
| | | new Criteria().andOperator(criteriaList.toArray(new Criteria[0])) |
| | | ); |
| | | GroupOperation group = Aggregation.group() |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount"); |
| | | // 将匹配阶段和分组阶段组合起来 |
| | | Aggregation aggregation = Aggregation.newAggregation(match, group); |
| | | // 执行聚合查询 |
| | | AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称 |
| | | for (Map<String, Object> result : results.getMappedResults()) { |
| | | offlineCount =(Integer) result.getOrDefault("offlineCount",0L); |
| | | unknownCount =(Integer) result.getOrDefault("unknownCount",0L); |
| | | onlineCount = (Integer) result.getOrDefault("onlineCount",0L); |
| | | totalCount = offlineCount + unknownCount + onlineCount; |
| | | } |
| | | |
| | | params.setDeptTag(1); |
| | | params.setDeviceType(1); |
| | | Integer distinctCount = pointMapper.distinctCount(params); |
| | | |
| | | List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | .select(CheckIndexVideo::getMinistrySiteOnline) |
| | | .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | |
| | | onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); |
| | | } |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate))); |
| | | map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate))); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |
| | |
| | | public Result videoImportantPointOnlineRate(DataCenterQuery params) { |
| | | List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | //查视频设备 |
| | | query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | query.addCriteria(Criteria.where("importantTag").is(Boolean.TRUE)); |
| | | //下拉框在线情况查询条件 |
| | | if(params.getOption()!=null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(Sort.by(Sort.Order.asc("pingOnline"))); |
| | | //分页数量 |
| | | long total = mongoTemplate.count(query, TMonitorResult.class); |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | | List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class); |
| | | params.setDeptTag(3); |
| | | params.setDeviceType(1); |
| | | // 统计设备数量 |
| | | Integer distinctCount = pointMapper.distinctCount(params); |
| | | resultList.forEach(item -> { |
| | | if (null != item.getPingOnline() && item.getPingOnline()) { |
| | | if(item.getPingOnline() ==null){ |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else { |
| | | } else if(!item.getPingOnline()){ |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | if (1 == item.getOnline()) { |
| | |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | }); |
| | | Date now = new Date(); |
| | | |
| | | // 统计设备数量 |
| | | //卡片统计 |
| | | int totalCount =0; |
| | | int onlineCount =0; |
| | | int offlineCount =0; |
| | | int unknownCount =0; |
| | | //构建条件 |
| | | List<Criteria> criteriaList = new ArrayList<>(); |
| | | // 添加固定条件 |
| | | criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | // 根据dataType动态添加条件 |
| | | if (params.getDataType() == 1) { |
| | | criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE)); |
| | | } else if (params.getDataType() == 2) { |
| | | criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | } |
| | | // 构建match操作 |
| | | MatchOperation match = Aggregation.match( |
| | | new Criteria().andOperator(criteriaList.toArray(new Criteria[0])) |
| | | ); |
| | | GroupOperation group = Aggregation.group() |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount"); |
| | | // 将匹配阶段和分组阶段组合起来 |
| | | Aggregation aggregation = Aggregation.newAggregation(match, group); |
| | | // 执行聚合查询 |
| | | AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称 |
| | | for (Map<String, Object> result : results.getMappedResults()) { |
| | | offlineCount =(Integer) result.getOrDefault("offlineCount",0L); |
| | | unknownCount =(Integer) result.getOrDefault("unknownCount",0L); |
| | | onlineCount = (Integer) result.getOrDefault("onlineCount",0L); |
| | | totalCount = offlineCount + unknownCount + onlineCount; |
| | | } |
| | | List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | .select(CheckIndexVideo::getKeySiteOnline) |
| | | .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now)) |
| | | .between(CheckIndexVideo::getCreateTime, params.getStartTime(), params.getEndTime()) |
| | | .list(); |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (CollectionUtils.isNotEmpty(videoList)) { |
| | |
| | | onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); |
| | | } |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate))); |
| | | map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate))); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |
| | |
| | | public Result videoImportantPointImageOnlineRate(DataCenterQuery params) { |
| | | List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | //查视频设备 |
| | | query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | query.addCriteria(Criteria.where("importantCommandImageTag").is(Boolean.TRUE)); |
| | | //下拉框在线情况查询条件 |
| | | if(params.getOption()!=null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(Sort.by(Sort.Order.asc("pingOnline"))); |
| | | //分页数量 |
| | | long total = mongoTemplate.count(query, TMonitorResult.class); |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | |
| | | |
| | | params.setDeptTag(4); |
| | | params.setDeviceType(1); |
| | | // 统计设备数量 |
| | | Integer distinctCount = pointMapper.distinctCount(params); |
| | | resultList.forEach(item -> { |
| | | if (null != item.getPingOnline() && item.getPingOnline()) { |
| | | if(item.getPingOnline() ==null){ |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else { |
| | | } else if(!item.getPingOnline()){ |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | if (1 == item.getOnline()) { |
| | |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | }); |
| | | Date now = new Date(); |
| | | |
| | | // 统计设备数量 |
| | | //卡片统计 |
| | | int totalCount =0; |
| | | int onlineCount =0; |
| | | int offlineCount =0; |
| | | int unknownCount =0; |
| | | //构建条件 |
| | | List<Criteria> criteriaList = new ArrayList<>(); |
| | | // 添加固定条件 |
| | | criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); |
| | | criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | // 根据dataType动态添加条件 |
| | | if (params.getDataType() == 1) { |
| | | criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE)); |
| | | } else if (params.getDataType() == 2) { |
| | | criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | } |
| | | // 构建match操作 |
| | | MatchOperation match = Aggregation.match( |
| | | new Criteria().andOperator(criteriaList.toArray(new Criteria[0])) |
| | | ); |
| | | GroupOperation group = Aggregation.group() |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount"); |
| | | // 将匹配阶段和分组阶段组合起来 |
| | | Aggregation aggregation = Aggregation.newAggregation(match, group); |
| | | // 执行聚合查询 |
| | | AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称 |
| | | for (Map<String, Object> result : results.getMappedResults()) { |
| | | offlineCount =(Integer) result.getOrDefault("offlineCount",0L); |
| | | unknownCount =(Integer) result.getOrDefault("unknownCount",0L); |
| | | onlineCount = (Integer) result.getOrDefault("onlineCount",0L); |
| | | totalCount = offlineCount + unknownCount + onlineCount; |
| | | } |
| | | |
| | | List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) |
| | | .select(CheckIndexVideo::getKeyCommandImageOnline) |
| | | .eq(params.getDataType().equals(1), CheckIndexVideo::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | .between(CheckIndexVideo::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now)) |
| | | .between(CheckIndexVideo::getCreateTime, params.getStartTime(), params.getEndTime()) |
| | | .list(); |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (CollectionUtils.isNotEmpty(videoList)) { |
| | |
| | | onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); |
| | | } |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate))); |
| | | map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate))); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |
| | |
| | | public Result vehiclePointOnlineRate(DataCenterQuery params) { |
| | | List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | //查车辆设备 |
| | | query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Car + ".*")); |
| | | //下拉框在线情况查询条件 |
| | | if(params.getOption()!=null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(Sort.by(Sort.Order.asc("pingOnline"))); |
| | | //分页数量 |
| | | long total = mongoTemplate.count(query, TMonitorResult.class); |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | |
| | | List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class); |
| | | params.setDeptTag(-1); |
| | | params.setDeviceType(2); |
| | | // 统计设备数量 |
| | | Integer distinctCount = pointMapper.distinctCount(params); |
| | | resultList.forEach(item -> { |
| | | if (null != item.getPingOnline() && item.getPingOnline()) { |
| | | if(item.getPingOnline() ==null){ |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else { |
| | | } else if(!item.getPingOnline()){ |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | if (1 == item.getOnline()) { |
| | |
| | | item.setOnlineStr("未知"); |
| | | } |
| | | }); |
| | | |
| | | // 统计设备数量 |
| | | //卡片统计 |
| | | int totalCount =0; |
| | | int onlineCount =0; |
| | | int offlineCount =0; |
| | | int unknownCount =0; |
| | | //构建条件 |
| | | List<Criteria> criteriaList = new ArrayList<>(); |
| | | // 添加固定条件 |
| | | criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Car + ".*")); |
| | | criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | // 根据dataType动态添加条件 |
| | | if (params.getDataType() == 1) { |
| | | criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE)); |
| | | } else if (params.getDataType() == 2) { |
| | | criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | } |
| | | // 构建match操作 |
| | | MatchOperation match = Aggregation.match( |
| | | new Criteria().andOperator(criteriaList.toArray(new Criteria[0])) |
| | | ); |
| | | GroupOperation group = Aggregation.group() |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount"); |
| | | // 将匹配阶段和分组阶段组合起来 |
| | | Aggregation aggregation = Aggregation.newAggregation(match, group); |
| | | // 执行聚合查询 |
| | | AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称 |
| | | for (Map<String, Object> result : results.getMappedResults()) { |
| | | offlineCount =(Integer) result.getOrDefault("offlineCount",0L); |
| | | unknownCount =(Integer) result.getOrDefault("unknownCount",0L); |
| | | onlineCount = (Integer) result.getOrDefault("onlineCount",0L); |
| | | totalCount = offlineCount + unknownCount + onlineCount; |
| | | } |
| | | |
| | | List<CheckIndexCar> videoList = new LambdaQueryChainWrapper<>(checkIndexCarService.getBaseMapper()) |
| | | .select(CheckIndexCar::getSiteOnline) |
| | | .eq(params.getDataType().equals(1), CheckIndexCar::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | |
| | | onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); |
| | | } |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate))); |
| | | map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate))); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |
| | |
| | | public Result facePointOnlineRate(DataCenterQuery params) { |
| | | List<String> likeFileds = Arrays.asList("name", "no", "ip"); |
| | | Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); |
| | | //查人脸设备 |
| | | query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Face + ".*")); |
| | | //下拉框在线情况查询条件 |
| | | if(params.getOption()!=null) { |
| | | query.addCriteria(Criteria.where("online").is(params.getOption())); |
| | | } |
| | | // 通过pingOnline字段排序,为false的排在前面 |
| | | query.with(Sort.by(Sort.Order.asc("pingOnline"))); |
| | | //分页数量 |
| | | long total = mongoTemplate.count(query, TMonitorResult.class); |
| | | MongoUtil.setPage(query, params, TIME_FIELD); |
| | | List<TMonitorResult> resultList = mongoTemplate.find(query, TMonitorResult.class); |
| | | resultList.forEach(item -> { |
| | | if (null != item.getPingOnline() && item.getPingOnline()) { |
| | | item.setOnlineStr("在线"); |
| | | } else { |
| | | item.setOnlineStr("离线"); |
| | | if(item.getPingOnline() ==null){ |
| | | item.setPingOnlineStr("未知"); |
| | | } else if (item.getPingOnline()) { |
| | | item.setPingOnlineStr("在线"); |
| | | } else if(!item.getPingOnline()){ |
| | | item.setPingOnlineStr("离线"); |
| | | } |
| | | if (1 == item.getOnline()) { |
| | | item.setOnlineStr("在线"); |
| | |
| | | }); |
| | | params.setDeptTag(-1); |
| | | params.setDeviceType(3); |
| | | // 统计设备数量 |
| | | Integer distinctCount = pointMapper.distinctCount(params); |
| | | |
| | | Date now = new Date(); |
| | | // 统计设备数量 |
| | | //卡片统计 |
| | | int totalCount =0; |
| | | int onlineCount =0; |
| | | int offlineCount =0; |
| | | int unknownCount =0; |
| | | //构建条件 |
| | | List<Criteria> criteriaList = new ArrayList<>(); |
| | | // 添加固定条件 |
| | | criteriaList.add(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Face + ".*")); |
| | | criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); |
| | | // 根据dataType动态添加条件 |
| | | if (params.getDataType() == 1) { |
| | | criteriaList.add(Criteria.where("provinceTag").is(Boolean.TRUE)); |
| | | } else if (params.getDataType() == 2) { |
| | | criteriaList.add(Criteria.where("deptTag").is(Boolean.TRUE)); |
| | | } |
| | | // 构建match操作 |
| | | MatchOperation match = Aggregation.match( |
| | | new Criteria().andOperator(criteriaList.toArray(new Criteria[0])) |
| | | ); |
| | | GroupOperation group = Aggregation.group() |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Online)).then(1).otherwise(0)).as("onlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Offline)).then(1).otherwise(0)).as("offlineCount") |
| | | .sum(ConditionalOperators.when(Criteria.where("online").is(ApiConstants.UY_OnlineSite_Unknown)).then(1).otherwise(0)).as("unknownCount"); |
| | | // 将匹配阶段和分组阶段组合起来 |
| | | Aggregation aggregation = Aggregation.newAggregation(match, group); |
| | | // 执行聚合查询 |
| | | AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "t_monitor_online", Map.class); // 替换为你的集合名称 |
| | | for (Map<String, Object> result : results.getMappedResults()) { |
| | | offlineCount =(Integer) result.getOrDefault("offlineCount",0L); |
| | | unknownCount =(Integer) result.getOrDefault("unknownCount",0L); |
| | | onlineCount = (Integer) result.getOrDefault("onlineCount",0L); |
| | | totalCount = offlineCount + unknownCount + onlineCount; |
| | | } |
| | | List<CheckIndexFace> videoList = new LambdaQueryChainWrapper<>(checkIndexFaceService.getBaseMapper()) |
| | | .select(CheckIndexFace::getSiteOnline) |
| | | .eq(params.getDataType().equals(1), CheckIndexFace::getExamineTag, CheckConstants.Examine_Tag_Province) |
| | | .between(CheckIndexFace::getCreateTime, DateUtils.getDayStart(now), DateUtils.getDayEnd(now)) |
| | | .between(CheckIndexFace::getCreateTime, params.getStartTime(), params.getEndTime()) |
| | | .list(); |
| | | BigDecimal onlineRate = BigDecimal.ZERO; |
| | | if (CollectionUtils.isNotEmpty(videoList)) { |
| | |
| | | BigDecimal count = BigDecimal.valueOf(videoList.size()); |
| | | onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); |
| | | } |
| | | List<String> rList = new ArrayList<>(2); |
| | | rList.add(distinctCount + ""); |
| | | rList.add(this.remove0(onlineRate)); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("count", rList); |
| | | map.put("count", Arrays.asList(totalCount + "",onlineCount +"",offlineCount+"" ,unknownCount+"", this.remove0(onlineRate))); |
| | | map.put("list", resultList); |
| | | return Result.ok().data(map).total(total); |
| | | } |