From 2e644445577d0773482753b7d08b3425afae7837 Mon Sep 17 00:00:00 2001 From: zxl <763096477@qq.com> Date: 星期一, 29 九月 2025 13:58:20 +0800 Subject: [PATCH] 新问题 25-9-28 --- ycl-server/src/main/java/com/ycl/platform/service/impl/DataCenterServiceImpl.java | 2064 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 1,546 insertions(+), 518 deletions(-) diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/DataCenterServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/DataCenterServiceImpl.java index 65543d8..ff6e689 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/impl/DataCenterServiceImpl.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/DataCenterServiceImpl.java @@ -20,27 +20,36 @@ import com.ycl.platform.domain.vo.DynamicColumnVO; import com.ycl.platform.mapper.DynamicColumnMapper; import com.ycl.platform.mapper.ImageResourceSecurityDetailMapper; +import com.ycl.platform.mapper.TMonitorMapper; import com.ycl.platform.mapper.YwPointMapper; import com.ycl.platform.service.*; import com.ycl.system.Result; +import com.ycl.system.entity.SysDept; +import com.ycl.system.model.LoginUser; import com.ycl.system.service.ISysConfigService; +import com.ycl.system.service.ISysDeptService; import com.ycl.utils.DateUtils; import com.ycl.utils.MongoUtil; +import com.ycl.utils.SecurityUtils; import com.ycl.utils.StringUtils; 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; @@ -49,6 +58,9 @@ 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; @@ -66,34 +78,79 @@ private final MongoTemplate mongoTemplate; private final ImageResourceSecurityDetailMapper securityDetailMapper; private final YwPointMapper pointMapper; - private final ICheckIndexVideoService checkIndexVideoService; private final ICheckIndexCarService checkIndexCarService; private final ICheckIndexFaceService checkIndexFaceService; private final DynamicColumnMapper dynamicColumnMapper; - + @Qualifier("threadPoolTaskExecutor") + @Autowired + private ThreadPoolTaskExecutor taskExecutor; private final static String TIME_FIELD = "mongoCreateTime"; private static DecimalFormat DF = new DecimalFormat("#.####"); + + + public Map<String,List<DynamicColumnVO>> getDynamicByConditions(DataCenterQuery params,List<DynamicColumnVO> list){ + //TODO 璇ヤ綅缃病鏈夎繃婊よ处鍙风殑閮ㄩ棬瀵瑰簲鐨勮澶囦俊鎭紝鑰屾槸鏇村叿鏉′欢鏌ヨ鐨勫叏閮� + //鑾峰緱鍒板搴攊d锛屼笖鍖呭惈浼犲叆瀛楃涓� 鍔ㄦ�佸垪闆嗗悎 + List<DynamicColumnVO> likeFieldDynamicColumnVOList = list.stream() + .filter(dynamicColumnVO -> + dynamicColumnVO.getLabelId().equals(params.getDyId()) && + dynamicColumnVO.getColumnValue().contains(params.getDyValue()) + ).collect(Collectors.toList()); + //鑾峰緱婊¤冻鏉′欢鐨刬d闆嗗悎 + List<String> ids = likeFieldDynamicColumnVOList.stream().map(DynamicColumnVO::getRefStringId).toList(); + Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = list.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); + Set<String> removeSet = new HashSet<>(ids); + //绉婚櫎鎺変笉绗﹀悎鏉′欢鐨刱ey + groupByRefStringIdMap.keySet().retainAll(removeSet); + + return groupByRefStringIdMap; + } + //褰曞儚鍙敤 @Override public void recordingAvailabilityExport(HttpServletResponse response,DataCenterQuery params) throws IOException { + List<String> likeFileds = Arrays.asList("deviceId", "deviceName"); Query query = MongoUtil.getQuery(params, "createTime", likeFileds, null); //涓嬫媺妗嗗綍鍍忔儏鍐垫煡璇㈡潯浠� if (params.getOption() != null) { query.addCriteria(Criteria.where("recordStatus").is(params.getOption())); } + SysDept sysDept = getSysDeptByLoginUser(); + if (sysDept !=null){ + AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); + if (areaDeptEnum != null){ + query.addCriteria(Criteria.where("no").regex("^" +areaDeptEnum.getCode())); + } + } + MongoUtil.setNoPage(query, params, TIME_FIELD); List<RecordMetaDSumResult> resultList = mongoTemplate.find(query, RecordMetaDSumResult.class); + + + //缈昏瘧琛屾斂鍖哄煙 resultList.forEach(item -> { String areaCode = item.getArealayername().substring(0, 6); AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromCode(areaCode); if (areaDeptEnum != null) item.setArealayername(areaDeptEnum.getName()); }); + //鑾峰緱鍔ㄦ�佸垪鏁版嵁 List<DynamicColumnVO> dynamicColumnVOList = dynamicColumnMapper.getDynamicColumnByTableName(TableNameConstants.COLUMN_NAME_VIDEO); - Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = dynamicColumnVOList.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); + + //鍒ゆ柇鏄惁鏈夋煡璇㈡潯浠� + boolean conditions = false; + Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = new HashMap<>(); + if (params.getDyId() != null && StringUtils.isNotEmpty(params.getDyValue())){ + conditions = true; + //鑾峰緱鍔ㄦ�佸垪闆嗗悎涓寘鍚簡鐨勫瓧绗︿覆鍊肩殑闆嗗悎 鍖哄垎澶у皬鍐� + + groupByRefStringIdMap = getDynamicByConditions(params,dynamicColumnVOList); + }else{ + groupByRefStringIdMap = dynamicColumnVOList.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); + } //鍥哄畾琛ㄥご LinkedHashSet<String> headers = new LinkedHashSet<>(); headers.add(RecordingAvailabilityHeaders.arealayername); @@ -115,21 +172,28 @@ headersList.addAll(dynamicsHeaders); headers.addAll(headersList); } - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - +// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + //鏌ヨ鍒版湁鍔ㄦ�佸垪鏌ヨ鏉′欢 + //鑾峰緱瀵瑰簲鍔ㄦ�佸垪涓璻ef鐨勫璞d 涓� 鏌ヨ缁撴灉id杩囨护 + if (conditions){ + Map<String, List<DynamicColumnVO>> finalGroupByRefStringIdMap = groupByRefStringIdMap; + resultList = resultList.stream() + .filter(obj -> finalGroupByRefStringIdMap.containsKey(obj.getId())) + .collect(Collectors.toList()); + } + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); List<List<Object>> data = new ArrayList<>(); for (RecordMetaDSumResult result : resultList){ List<Object> row = new ArrayList<>(); row.add(result.getArealayername()); row.add(result.getArealayerno()); - row.add(dateFormat2.format(result.getCreateTime())); + row.add(dateFormat.format(result.getCreateTime())); row.add(result.getDeviceId()); row.add(result.getMissDuration()); row.add(result.getPlatId()); row.add(result.getRecordDuration()); row.add(result.getRecordStatusText()); - row.add(dateFormat2.format(result.getCreateTime())); + row.add(dateFormat.format(result.getCreateTime())); //娣诲姞鍔ㄦ�佸垪鏁版嵁 for (String header : headersList){ boolean flag = false; @@ -158,10 +222,21 @@ .doWrite(data); // 鍐欏叆鏁版嵁 } + //鐐逛綅鍦ㄧ嚎 @Override public void pointOnlineFaceExport(HttpServletResponse response, DataCenterQuery params) throws IOException { + List<String> likeFileds = Arrays.asList("name", "no", "ip"); - Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); + Query query = null; + SysDept sysDept = getSysDeptByLoginUser(); + if (sysDept !=null){ + AreaDeptEnum 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); + } //鏌ヤ汉鑴歌澶� query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Face + ".*")); //涓嬫媺妗嗗湪绾挎儏鍐垫煡璇㈡潯浠� @@ -201,8 +276,23 @@ item.setOffLineTimeStr(offLineTime); } }); + + + List<DynamicColumnVO> dynamicColumnVOList = dynamicColumnMapper.getDynamicColumnByTableName(TableNameConstants.COLUMN_NAME_FACE_POINT); - Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = dynamicColumnVOList.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); + + + //鍒ゆ柇鏄惁鏈夋煡璇㈡潯浠� + boolean conditions = false; + Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = new HashMap<>(); + if (params.getDyId() != null && StringUtils.isNotEmpty(params.getDyValue())){ + conditions = true; + //鑾峰緱鍔ㄦ�佸垪闆嗗悎涓寘鍚簡鐨勫瓧绗︿覆鍊肩殑闆嗗悎 鍖哄垎澶у皬鍐� + groupByRefStringIdMap = getDynamicByConditions(params,dynamicColumnVOList); + }else{ + groupByRefStringIdMap = dynamicColumnVOList.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); + } + //鍥哄畾琛ㄥご LinkedHashSet<String> headers = new LinkedHashSet<>(); headers.add(PointOnlineHeaders.no); @@ -223,6 +313,13 @@ //浣跨敤閾捐〃淇濊瘉鍚庣画琛ュ厖鏁版嵁鏃惰幏鍙栨暟鎹『搴忎竴鑷� headersList.addAll(dynamicsHeaders); headers.addAll(headersList); + } + + if (conditions){ + Map<String, List<DynamicColumnVO>> finalGroupByRefStringIdMap = groupByRefStringIdMap; + resultList = resultList.stream() + .filter(obj -> finalGroupByRefStringIdMap.containsKey(obj.getNo())) + .collect(Collectors.toList()); } List<List<Object>> data = new ArrayList<>(); @@ -269,12 +366,34 @@ .sheet("浜鸿劯鐐逛綅鍦ㄧ嚎鐜�") // 璁剧疆sheet鍚嶇О .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) .doWrite(data); // 鍐欏叆鏁版嵁 - } + } private final ISysDeptService deptService; + + public SysDept getSysDeptByLoginUser(){ + LoginUser loginUser = SecurityUtils.getLoginUser(); + SysDept sysDept = null; + Long deptId =null; + if (loginUser.getDeptId() != null){ + deptId = loginUser.getDeptId(); + sysDept = deptService.selectDeptById(deptId); + } + return sysDept; + } + //瑙嗛鍗曚綅鍦ㄧ嚎 @Override public void pointOnlineVideoExport(HttpServletResponse response, DataCenterQuery params) throws IOException { List<String> likeFileds = Arrays.asList("name", "no", "ip"); - Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); + Query query = null; + SysDept sysDept = getSysDeptByLoginUser(); + if (sysDept !=null){ + AreaDeptEnum 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); + } + //鏌ヨ棰戣澶� query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Video + ".*")); //涓嬫媺妗嗗湪绾挎儏鍐垫煡璇㈡潯浠� @@ -313,7 +432,16 @@ } }); List<DynamicColumnVO> dynamicColumnVOList = dynamicColumnMapper.getDynamicColumnByTableName(TableNameConstants.COLUMN_NAME_VIDEO_POINT); - Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = dynamicColumnVOList.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); + //鍒ゆ柇鏄惁鏈夋煡璇㈡潯浠� + boolean conditions = false; + Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = new HashMap<>(); + if (params.getDyId() != null && StringUtils.isNotEmpty(params.getDyValue())){ + conditions = true; + //鑾峰緱鍔ㄦ�佸垪闆嗗悎涓寘鍚簡鐨勫瓧绗︿覆鍊肩殑闆嗗悎 鍖哄垎澶у皬鍐� + groupByRefStringIdMap = getDynamicByConditions(params,dynamicColumnVOList); + }else{ + groupByRefStringIdMap = dynamicColumnVOList.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); + } //鍥哄畾琛ㄥご LinkedHashSet<String> headers = new LinkedHashSet<>(); headers.add(PointOnlineHeaders.no); @@ -334,6 +462,14 @@ //浣跨敤閾捐〃淇濊瘉鍚庣画琛ュ厖鏁版嵁鏃惰幏鍙栨暟鎹『搴忎竴鑷� headersList.addAll(dynamicsHeaders); headers.addAll(headersList); + } + + + if (conditions){ + Map<String, List<DynamicColumnVO>> finalGroupByRefStringIdMap = groupByRefStringIdMap; + resultList = resultList.stream() + .filter(obj -> finalGroupByRefStringIdMap.containsKey(obj.getNo())) + .collect(Collectors.toList()); } List<List<Object>> data = new ArrayList<>(); @@ -383,11 +519,20 @@ } - + //杞﹁締鐐逛綅鍦ㄧ嚎 @Override public void pointOnlineCarExport(HttpServletResponse response, DataCenterQuery params) throws IOException { List<String> likeFileds = Arrays.asList("name", "no", "ip"); - Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); + Query query = null; + SysDept sysDept = getSysDeptByLoginUser(); + if (sysDept !=null){ + AreaDeptEnum 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); + } //鏌ヨ溅杈嗚澶� query.addCriteria(Criteria.where("monitorType").regex(".*" + CheckConstants.Rule_Category_Car + ".*")); //涓嬫媺妗嗗湪绾挎儏鍐垫煡璇㈡潯浠� @@ -428,7 +573,16 @@ } }); List<DynamicColumnVO> dynamicColumnVOList = dynamicColumnMapper.getDynamicColumnByTableName(TableNameConstants.COLUMN_NAME_CAR_POINT); - Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = dynamicColumnVOList.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); + //鍒ゆ柇鏄惁鏈夋煡璇㈡潯浠� + boolean conditions = false; + Map<String,List<DynamicColumnVO>> groupByRefStringIdMap = new HashMap<>(); + if (params.getDyId() != null && StringUtils.isNotEmpty(params.getDyValue())){ + conditions = true; + //鑾峰緱鍔ㄦ�佸垪闆嗗悎涓寘鍚簡鐨勫瓧绗︿覆鍊肩殑闆嗗悎 鍖哄垎澶у皬鍐� + groupByRefStringIdMap = getDynamicByConditions(params,dynamicColumnVOList); + }else{ + groupByRefStringIdMap = dynamicColumnVOList.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefStringId)); + } //鍥哄畾琛ㄥご LinkedHashSet<String> headers = new LinkedHashSet<>(); headers.add(PointOnlineHeaders.no); @@ -449,6 +603,14 @@ //浣跨敤閾捐〃淇濊瘉鍚庣画琛ュ厖鏁版嵁鏃惰幏鍙栨暟鎹『搴忎竴鑷� headersList.addAll(dynamicsHeaders); headers.addAll(headersList); + } + + + if (conditions){ + Map<String, List<DynamicColumnVO>> finalGroupByRefStringIdMap = groupByRefStringIdMap; + resultList = resultList.stream() + .filter(obj -> finalGroupByRefStringIdMap.containsKey(obj.getNo())) + .collect(Collectors.toList()); } List<List<Object>> data = new ArrayList<>(); @@ -538,132 +700,450 @@ } /** - * 瑙嗛锛氱偣浣嶅湪绾跨巼 - * - * @param params - * @return + * 鍐呴儴绫伙細瀛樺偍缁熻缁撴灉锛堥伩鍏嶉浂鏁e彉閲忎紶閫掞級 */ - @Override - public Result videoPointOnlineRate(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 + ".*")); - //涓嬫媺妗嗗湪绾挎儏鍐垫煡璇㈡潯浠� - 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); + private static class StatisticsResult { + int totalCount; + int onlineCount; + int offlineCount; + int unknownCount; + BigDecimal onlineRate; - 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()); + 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; + } + } + /** + * 鍒楄〃鏁版嵁鏍煎紡鍖� + */ + 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())); - // 鏍规嵁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)); + // 娣诲姞鍔ㄦ�佸垪鏁版嵁 + List<DynamicColumnVO> dynamicColumns = dynamicColumnMapper.getDynamicColumnByTable( + TableNameConstants.COLUMN_NAME_VIDEO_POINT, + item.getNo() + ); + item.setDynamicColumnList(dynamicColumns); + }); } - // 鏋勫缓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; + 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("鏈煡"); + } + }); } - 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 = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); - //鏌ヨ棰戣澶� + final Query query; + SysDept sysDept = getSysDeptByLoginUser(); + final AreaDeptEnum areaDeptEnum; // 澹版槑涓篺inal + + 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.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 + ".*")); query.addCriteria(Criteria.where("deptTag").is(Boolean.TRUE)); //涓嬫媺妗嗗湪绾挎儏鍐垫煡璇㈡潯浠� @@ -674,84 +1154,258 @@ 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<>(); - // 娣诲姞鍥哄畾鏉′欢 - 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)); + },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); } - // 鏋勫缓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); +// } /** * 瑙嗛锛氶噸鐐圭偣浣嶅湪绾跨巼 * @@ -759,9 +1413,24 @@ * @return */ @Override - public Result videoImportantPointOnlineRate(DataCenterQuery params) { + public Result videoImportantPointOnlineRate(DataCenterQuery params){ List<String> likeFileds = Arrays.asList("name", "no", "ip"); - Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); + //姝ゅ鏂板浜嗘牴鎹敤鎴锋潈闄愭煡璇㈢殑鎯呭喌 + final Query query; + SysDept sysDept = getSysDeptByLoginUser(); + final AreaDeptEnum areaDeptEnum; + 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 + ".*")); query.addCriteria(Criteria.where("importantTag").is(Boolean.TRUE)); @@ -771,85 +1440,53 @@ } // 閫氳繃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<>(); - // 娣诲姞鍥哄畾鏉′欢 - 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)); + 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); } - // 鏋勫缓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); + } /** @@ -861,7 +1498,21 @@ @Override public Result videoImportantPointImageOnlineRate(DataCenterQuery params) { List<String> likeFileds = Arrays.asList("name", "no", "ip"); - Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); + //姝ゅ鏂板浜嗘牴鎹敤鎴锋潈闄愭煡璇㈢殑鎯呭喌 + 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("importantCommandImageTag").is(Boolean.TRUE)); @@ -903,6 +1554,10 @@ 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())); @@ -962,7 +1617,19 @@ @Override public Result videoOneMachineDocumentRegister(DataCenterQuery params) { List<String> likeFileds = Arrays.asList("ip.showValue", "name.showValue", "serialNumber.showValue"); - List<Criteria> andCriteria = MongoUtil.getAndCriteria(params, TIME_FIELD, likeFileds, null); + SysDept sysDept = getSysDeptByLoginUser(); + List<Criteria> andCriteria; + AreaDeptEnum areaDeptEnum = null; + if (sysDept != null) { + areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); + if (areaDeptEnum != null) { + andCriteria = MongoUtil.getAndCriteriaDateCenter(areaDeptEnum.getCode(),params, TIME_FIELD, likeFileds, null); + }else { + andCriteria = MongoUtil.getAndCriteria(params, TIME_FIELD, likeFileds, null); + } + }else { + andCriteria = MongoUtil.getAndCriteria(params, TIME_FIELD, likeFileds, null); + } Query query = new Query(); Criteria and = new Criteria(); if (params.getOption() != null) { @@ -985,12 +1652,23 @@ // 缁熻鏁伴噺 MongoDatabase database = mongoTemplate.getDb(); MongoCollection<Document> collection = database.getCollection("uy_monitor_qualify"); + Document areDocument = null; + if (areaDeptEnum != null) { + String areaCodePrefix = areaDeptEnum.getCode(); + areDocument = new Document("deviceNo", new Document("$regex", "^" + areaCodePrefix)); + } //鎬绘暟 List<Document> dList1 = new ArrayList<>(2); + if(areDocument != null){ + dList1.add(areDocument); + } setTag(params, dList1); Document totalFilter = new Document("$and", dList1); //鏂拌澶囨暟 List<Document> dList2 = new ArrayList<>(2); + if(areDocument != null){ + dList1.add(areDocument); + } setTag(params, dList2); dList2.add(new Document("newDevice", Boolean.TRUE)); Document newFilter = new Document("$and", dList2); @@ -1046,7 +1724,20 @@ @Override public Result videoOneMachineDocumentQualified(DataCenterQuery params) { List<String> likeFileds = Arrays.asList("ip.showValue", "name.showValue", "serialNumber.showValue"); - List<Criteria> andCriteria = MongoUtil.getAndCriteria(params, TIME_FIELD, likeFileds, null); + SysDept sysDept = getSysDeptByLoginUser(); + List<Criteria> andCriteria; + AreaDeptEnum areaDeptEnum = null; + if (sysDept != null) { + areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); + if (areaDeptEnum != null) { + andCriteria = MongoUtil.getAndCriteriaDateCenter(areaDeptEnum.getCode(),params, TIME_FIELD, likeFileds, null); + }else { + andCriteria = MongoUtil.getAndCriteria(params, TIME_FIELD, likeFileds, null); + } + }else { + andCriteria = MongoUtil.getAndCriteria(params, TIME_FIELD, likeFileds, null); + } + Query query = new Query(); Criteria and = new Criteria(); and.andOperator(andCriteria); @@ -1098,12 +1789,25 @@ // 缁熻鏁伴噺 MongoDatabase database = mongoTemplate.getDb(); MongoCollection<Document> collection = database.getCollection("uy_monitor_qualify"); + Document areDocument = null; + if (areaDeptEnum != null) { + String areaCodePrefix = areaDeptEnum.getCode(); + areDocument = new Document("deviceNo", new Document("$regex", "^" + areaCodePrefix)); + } //鎬绘暟 List<Document> dList1 = new ArrayList<>(2); + if (areDocument != null){ + dList1.add(areDocument); + } setTag(params, dList1); Document totalFilter = new Document("$and", dList1); + //list1 + //鍚堟牸鏁� List<Document> dList2 = new ArrayList<>(2); + if (areDocument != null){ + dList2.add(areDocument); + } dList2.add(new Document("serialNumber.error", Boolean.FALSE)); dList2.add(new Document("name.error", Boolean.FALSE)); dList2.add(new Document("civilCode.error", Boolean.FALSE)); @@ -1120,6 +1824,9 @@ Document qualifyFilter = new Document("$and", dList2); //涓嶅悎鏍兼暟 List<Document> dList3 = new ArrayList<>(2); + if (areDocument != null){ + dList3.add(areDocument); + } setTag(params, dList3); List<Document> errorConditions = new ArrayList<>(); errorConditions.add(new Document("serialNumber.error", new Document("$eq", Boolean.TRUE))); @@ -1160,18 +1867,6 @@ 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); @@ -1261,6 +1956,22 @@ } private final ISysConfigService configService; + + public double getSySMinTime(){ + //鑾峰彇绯荤粺鍙傛暟 + String dictLabel = configService.selectConfigByKey("recording_min_time"); + double recordingMinTime; + try { + recordingMinTime = Double.parseDouble(dictLabel) / 60; // 濡傛灉 dictLabel 鏄互灏忔椂涓哄崟浣嶏紝鍒欐棤闇�闄や互 60 + } catch (Exception e) { + log.error("閰嶇疆鐨勫垹闄ゆ椂闂磋寖鍥存牸寮忎笉姝g‘: {}", dictLabel, e); + return 12.0; // 榛樿 12 灏忔椂锛堜互灏忔椂涓哄崟浣嶏級 + } + + return recordingMinTime; + } + private final TMonitorMapper tMonitorMapper; + /** * 瑙嗛锛氬綍鍍忓彲鐢ㄧ巼 * @@ -1268,21 +1979,26 @@ * @return */ @Override - public Result videoAvailabilityRate(DataCenterQuery params) { - //鑾峰彇绯荤粺鍙傛暟 - String dictLabel = configService.selectConfigByKey("recording_min_time"); - - double recordingMinTime; - try { - recordingMinTime = Double.parseDouble(dictLabel) / 60; // 濡傛灉 dictLabel 鏄互灏忔椂涓哄崟浣嶏紝鍒欐棤闇�闄や互 60 - } catch (Exception e) { - log.error("閰嶇疆鐨勫垹闄ゆ椂闂磋寖鍥存牸寮忎笉姝g‘: {}", dictLabel, e); - recordingMinTime = 12.0; // 榛樿 12 灏忔椂锛堜互灏忔椂涓哄崟浣嶏級 + List<String> noString = tMonitorMapper.getIdListVideo(); + List<String> likeFileds = Arrays.asList("deviceId", "deviceName"); + SysDept sysDept = getSysDeptByLoginUser(); + AreaDeptEnum areaDeptEnum = null; + Query query = null; + if (sysDept !=null){ + areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); + if (areaDeptEnum != null){ + query = MongoUtil.getQueryDataCenter(areaDeptEnum.getCode(),params,"createTime",likeFileds,null,"no"); + }else{ + query = MongoUtil.getQuery(params, "createTime", likeFileds, null); + } + }else { + query = MongoUtil.getQuery(params, "createTime", likeFileds, null); } - List<String> likeFileds = Arrays.asList("deviceId", "deviceName"); - Query 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())); @@ -1296,96 +2012,227 @@ //缈昏瘧琛屾斂鍖哄煙 resultList.forEach(item -> { String areaCode = item.getArealayername().substring(0, 6); - AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromCode(areaCode); - if (areaDeptEnum != null) item.setArealayername(areaDeptEnum.getName()); + AreaDeptEnum areaDeptEnumInfo = AreaDeptEnum.fromCode(areaCode); + if (areaDeptEnumInfo != null) item.setArealayername(areaDeptEnumInfo.getName()); 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); - List<String> resultCount = status.stream().map(item -> { - List<Document> dList = new ArrayList<>(2); - dList.add(new Document("recordStatus", new Document("$eq", item))); - 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 = recordingMinTime; - - List<Document> documentList = new ArrayList<>(3); - setTag(params, documentList); - Document recording = new Document("recordDuration",new Document("$gte", 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); -// List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) -// .select(CheckIndexVideo::getVideoAvailable) -// .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::getVideoAvailable).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<>(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))); // } - //鍔犱竴涓�绘暟 - 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))) { - onlineRate = new BigDecimal(uniqueDeviceIdCount).divide(new BigDecimal(resultCount.get(0)), 3,RoundingMode.DOWN).multiply(new BigDecimal("100")); - } - resultCount.add(this.remove0(onlineRate)); +// // 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", resultCount); + 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; + double finalRecordingMinTime = getSySMinTime(); + // 2. 鏋勫缓鑱氬悎绠¢亾锛堟牳蹇冿細涓�娆$閬撶粺璁℃墍鏈夋寚鏍囷級 + List<Document> pipeline = new ArrayList<>(); + + // 闃舵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锛歯o鐨勮繃婊わ紙in + 鍙�夊墠缂�鍖归厤锛屽拰浣犲師浠g爜閫昏緫涓�鑷达級 + 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 { + baseFilterList.add(new Document("no", new Document("$in", noString))); + } + setTag(params, baseFilterList); + Document matchStage = new Document("$match", new Document("$and", baseFilterList)); + pipeline.add(matchStage); + // 闃舵2锛�$group - 鎸塪eviceId鍘婚噸锛屾爣璁板悇鏉′欢鏄惁婊¤冻 + // -------------------------- + // 閫昏緫锛氭瘡涓澶囧彧缁熻涓�娆★紝鐢�$cond鏍囪鈥滄槸鍚︾鍚堟煇鏉′欢鈥濓紙绗﹀悎=1锛屼笉绗﹀悎=0锛� + Document groupByDeviceStage = new Document("$group", + new Document("_id", "$deviceId") // 鎸夎澶嘔D鍒嗙粍锛堝幓閲嶆牳蹇冿級 + // 鏍囪锛氳璁惧鏄惁婊¤冻 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 + )) + )) + ); + pipeline.add(groupByDeviceStage); + // -------------------------- + // 闃舵3锛�$group - 鍏ㄥ眬缁熻锛堢疮鍔犳墍鏈夎澶囩殑鏍囪锛屽緱鍒版渶缁堟暟閲忥級 + // -------------------------- + // 閫昏緫锛氭棤鍒嗙粍閿紙_id: null锛夛紝灏嗘墍鏈夎澶囩殑鏍囪绱姞锛屽緱鍒版�昏鏁� + Document groupGlobalStage = new Document("$group", + new Document("_id", null) // 鍏ㄥ眬鍒嗙粍锛堢粺璁℃墍鏈夎澶囷級 + // 鍘熺涓�娈垫煡璇㈢粨鏋�1锛歴tatus=1鐨勮澶囨暟 + .append("status1Count", new Document("$sum", "$status1Flag")) + // 鍘熺涓�娈垫煡璇㈢粨鏋�2锛歴tatus=0鐨勮澶囨暟 + .append("status0Count", new Document("$sum", "$status0Flag")) + // 鍘熺涓�娈垫煡璇㈢粨鏋�3锛歴tatus=-1鐨勮澶囨暟 + .append("statusMinus1Count", new Document("$sum", "$statusMinus1Flag")) + // 鍘熺浜屾鏌ヨ缁撴灉锛歮issDuration绗﹀悎鏉′欢鐨勮澶囨暟 + .append("missOkCount", new Document("$sum", "$missOkFlag")) + ); + pipeline.add(groupGlobalStage); + + // -------------------------- + // 鎵ц鑱氬悎鏌ヨ锛屾彁鍙栨墍鏈夌粺璁$粨鏋� + // -------------------------- + AggregateIterable<Document> aggregateResult = collection.aggregate(pipeline); + Document statDoc = null; + for (Document doc : aggregateResult) { // 鍏ㄥ眬鍒嗙粍鍙細杩斿洖1鏉$粨鏋� + statDoc = doc; + break; + } + + // 鍒濆鍖栭粯璁ゅ�硷紙閬垮厤绌烘寚閽堬級 + 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; + if (total != 0) { // 鍙湁褰搕otal涓嶄负0鏃讹紝鎵嶈绠楁瘮鐜� + onlineRate = new BigDecimal(missOkCount) + .divide(new BigDecimal(total), 3, RoundingMode.DOWN) + .multiply(new BigDecimal("100")); + } + List<String> list = new ArrayList<>(); + list.add(total +""); + list.add(status1Count +""); + list.add(status0Count +""); + list.add(statusMinus1Count +""); + list.add(this.remove0(onlineRate)); + return list; } /** @@ -1396,77 +2243,45 @@ */ @Override public Result deptVideoAvailabilityRate(DataCenterQuery params) { + List<String> noString = tMonitorMapper.getIdListVideo(); List<String> likeFileds = Arrays.asList("deviceId", "deviceName"); - Query query = MongoUtil.getQuery(params, "createTime", likeFileds, 1); + SysDept sysDept = getSysDeptByLoginUser(); + AreaDeptEnum areaDeptEnum = null; + Query query = null; + if (sysDept !=null){ + areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); + if (areaDeptEnum != null){ + query = MongoUtil.getQueryDataCenter(areaDeptEnum.getCode(),params,"createTime",likeFileds,null,"no"); + }else{ + query = MongoUtil.getQuery(params, "createTime", likeFileds, 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); //缈昏瘧琛屾斂鍖哄煙 resultList.forEach(item -> { String areaCode = item.getArealayername().substring(0, 6); - AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromCode(areaCode); - if (areaDeptEnum != null) item.setArealayername(areaDeptEnum.getName()); + 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); - 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); - 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()); -// 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(resultCount.get(1)).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); } - /** * 瑙嗛锛氶噸鐐圭偣浣嶅綍鍍忓彲鐢ㄧ巼 * @@ -1475,73 +2290,118 @@ */ @Override public Result videoImportantPointAvailabilityRate(DataCenterQuery params) { + List<String> noString = tMonitorMapper.getIdListVideo(); List<String> likeFileds = Arrays.asList("deviceId", "deviceName"); - Query query = MongoUtil.getQuery(params, "createTime", likeFileds, 3); + SysDept sysDept = getSysDeptByLoginUser(); + AreaDeptEnum areaDeptEnum = null; + Query query = null; + if (sysDept !=null){ + areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); + if (areaDeptEnum != null){ + query = MongoUtil.getQueryDataCenter(areaDeptEnum.getCode(),params,"createTime",likeFileds,null,"no"); + }else{ + query = MongoUtil.getQuery(params, "createTime", likeFileds, null); + } + }else { + 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); //缈昏瘧琛屾斂鍖哄煙 resultList.forEach(item -> { String areaCode = item.getArealayername().substring(0, 6); - AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromCode(areaCode); - if (areaDeptEnum != null) item.setArealayername(areaDeptEnum.getName()); + 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); - 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); - 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()); - -// 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(resultCount.get(1)).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); } @@ -1559,12 +2419,32 @@ long total = mongoTemplate.count(query, RecordMetaDSumResult.class); List<RecordMetaDSumResult> resultList = mongoTemplate.find(query, RecordMetaDSumResult.class); + Query nonNetworkQuery; + Query networkQuery; + Query videoQuery; + Query carQuery; + Query faceQuery; +// if (areaDeptEnum == null){ + nonNetworkQuery = new Query().addCriteria(Criteria.where("LWSX").is("0")); + networkQuery = new Query().addCriteria(Criteria.where("LWSX").is("1")); + videoQuery = new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*1.*")); + carQuery = new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*2.*")); + faceQuery = new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*3.*")); +// } +// else { +// nonNetworkQuery = new Query().addCriteria(Criteria.where("LWSX").is("0")).addCriteria(Criteria.where("no").regex("^" + Pattern.quote(areaDeptEnum.getCode()))); +// networkQuery = new Query().addCriteria(Criteria.where("LWSX").is("1")).addCriteria(Criteria.where("no").regex("^" + Pattern.quote(areaDeptEnum.getCode()))); +// videoQuery = new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*1.*")).addCriteria(Criteria.where("no").regex("^" + Pattern.quote(areaDeptEnum.getCode()))); +// carQuery = new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*2.*")).addCriteria(Criteria.where("no").regex("^" + Pattern.quote(areaDeptEnum.getCode()))); +// faceQuery = new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*3.*")).addCriteria(Criteria.where("no").regex("^" + Pattern.quote(areaDeptEnum.getCode()))); +// } + // 缁熻鏁� - long nonNetwork = mongoTemplate.count(new Query().addCriteria(Criteria.where("LWSX").is("0")), RecordMetaDSumResult.class); - long network = mongoTemplate.count(new Query().addCriteria(Criteria.where("LWSX").is("1")), RecordMetaDSumResult.class); - long video = mongoTemplate.count(new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*1.*")), RecordMetaDSumResult.class); - long car = mongoTemplate.count(new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*2.*")), RecordMetaDSumResult.class); - long face = mongoTemplate.count(new Query().addCriteria(Criteria.where("SXJGNLX").regex(".*3.*")), RecordMetaDSumResult.class); + long nonNetwork = mongoTemplate.count(nonNetworkQuery, RecordMetaDSumResult.class); + long network = mongoTemplate.count(networkQuery, RecordMetaDSumResult.class); + long video = mongoTemplate.count(videoQuery, RecordMetaDSumResult.class); + long car = mongoTemplate.count(carQuery, RecordMetaDSumResult.class); + long face = mongoTemplate.count(faceQuery, RecordMetaDSumResult.class); HashMap<String, Object> map = new HashMap<>(); map.put("count", Arrays.asList(nonNetwork, network, video, car, face)); map.put("list", resultList); @@ -1580,12 +2460,26 @@ @Override public Result videoImportantPointLabelingAccuracy(DataCenterQuery params) { List<String> likeFileds = Arrays.asList("deviceNo", "osdName"); - List<Criteria> andCriteria = MongoUtil.getAndCriteria(params, "checkTime", likeFileds, null); + SysDept sysDept = getSysDeptByLoginUser(); + List<Criteria> andCriteria; + AreaDeptEnum areaDeptEnum = null; + if (sysDept != null) { + areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); + if (areaDeptEnum != null) { + andCriteria = MongoUtil.getAndCriteriaDateCenter(areaDeptEnum.getCode(),params, "checkTime", likeFileds, null); + }else { + andCriteria = MongoUtil.getAndCriteria(params, "checkTime", likeFileds, null); + } + }else { + andCriteria = MongoUtil.getAndCriteria(params, "checkTime", likeFileds, null); + } + Query query = new Query(); Criteria and = new Criteria(); and.andOperator(andCriteria); query = Query.query(and); - //涓嬫媺妗嗘爣娉ㄦ纭煡璇㈡潯浠� + query.addCriteria(Criteria.where("importantTag").is(Boolean.TRUE)); + // 涓嬫媺妗嗘爣娉ㄦ纭煡璇㈡潯浠� if (params.getOption() != null) { if (params.getOption() == 1) { andCriteria.add(Criteria.where("osdNameCorrect").is(1)); @@ -1626,13 +2520,26 @@ // 缁熻鏁伴噺 MongoDatabase database = mongoTemplate.getDb(); MongoCollection<Document> collection = database.getCollection("osd_check_result"); - //鎬绘暟 + // 纭繚鍦ㄧ粺璁℃煡璇腑涔熷簲鐢ㄧ浉鍚岀殑杩囨护鏉′欢 + Document areDocument = null; + if (areaDeptEnum != null) { + String areaCodePrefix = areaDeptEnum.getCode(); + areDocument = new Document("deviceNo", new Document("$regex", "^" + areaCodePrefix)); + } + // 鎬绘暟 List<Document> dList = new ArrayList<>(2); + if (areDocument != null){ + dList.add(areDocument); + } dList.add(new Document("importantTag", Boolean.TRUE)); setTag(params, dList); + Document osdFilter = new Document("$and", dList); - //姝e父鏁� + // 姝e父鏁� List<Document> dList1 = new ArrayList<>(2); + if (areDocument != null){ + dList1.add(areDocument); + } dList1.add(new Document("importantTag", Boolean.TRUE)); dList1.add(new Document("osdNameCorrect", new Document("$eq", 1))); dList1.add(new Document("osdTimeCorrect", new Document("$eq", 1))); @@ -1640,9 +2547,13 @@ dList1.add(new Document("osdCityCorrect", new Document("$eq", 1))); dList1.add(new Document("osdPartCorrect", new Document("$eq", 1))); setTag(params, dList1); + Document osdCorrectFilter = new Document("$and", dList1); //寮傚父鏁� List<Document> dList2 = new ArrayList<>(2); + if (areDocument != null){ + dList2.add(areDocument); + } setTag(params, dList2); Document importantTagCondition = new Document("importantTag", Boolean.TRUE); dList2.add(importantTagCondition); @@ -1654,9 +2565,14 @@ errorConditions.add(new Document("osdPartCorrect", new Document("$eq", -1))); Document errorFilter = new Document("$or", errorConditions); dList2.add(errorFilter); + Document osdErrorFilter = new Document("$and", dList2); - //鏈煡鏁� + + // 鏈煡鏁� List<Document> dList3 = new ArrayList<>(2); + if (areDocument != null){ + dList3.add(areDocument); + } setTag(params, dList3); dList3.add(importantTagCondition); List<Document> unknownConditions = new ArrayList<>(); @@ -1665,9 +2581,9 @@ unknownConditions.add(new Document("osdProvinceCorrect", new Document("$eq", 0))); unknownConditions.add(new Document("osdCityCorrect", new Document("$eq", 0))); unknownConditions.add(new Document("osdPartCorrect", new Document("$eq", 0))); - // 浣跨敤$or閫昏緫缁勫悎鍓╀綑鐨勬潯浠� Document unknownFilter = new Document("$or", unknownConditions); dList3.add(unknownFilter); + Document osdUnknownFilter = new Document("$and", dList3); List<Document> lists = Arrays.asList(osdFilter, osdCorrectFilter, osdErrorFilter, osdUnknownFilter); @@ -1689,18 +2605,6 @@ return uniqueDeviceIdCount + ""; }).collect(Collectors.toList()); -// List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper()) -// .select(CheckIndexVideo::getKeyAnnotationAccuracy) -// .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::getKeyAnnotationAccuracy).reduce(BigDecimal.ZERO, BigDecimal::add); -// BigDecimal count = BigDecimal.valueOf(videoList.size()); -// onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); -// } BigDecimal onlineRate = BigDecimal.ZERO; 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")); @@ -1807,7 +2711,25 @@ @Override public Result videoImportantPointCheckTimeAccuracy(DataCenterQuery params) { List<String> likeFileds = Arrays.asList("deviceNo", "osdName"); - Query query = MongoUtil.getQuery(params, "checkTime", likeFileds, null); + + SysDept sysDept = getSysDeptByLoginUser(); + List<Criteria> andCriteria; + AreaDeptEnum areaDeptEnum = null; + if (sysDept != null) { + areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); + if (areaDeptEnum != null) { + andCriteria = MongoUtil.getAndCriteriaDateCenter(areaDeptEnum.getCode(),params, "checkTime", likeFileds, null); + }else { + andCriteria = MongoUtil.getAndCriteria(params, "checkTime", likeFileds, null); + } + }else { + andCriteria = MongoUtil.getAndCriteria(params, "checkTime", likeFileds, null); + } + Query query = new Query(); + Criteria and = new Criteria(); + and.andOperator(andCriteria); + query = Query.query(and); + query.addCriteria(Criteria.where("importantTag").is(Boolean.TRUE)); //涓嬫媺妗嗘爣娉ㄦ纭煡璇㈡潯浠� if (params.getOption() != null) { if (params.getOption() == 1) { @@ -1822,6 +2744,11 @@ long total = mongoTemplate.count(query, OsdCheckResult.class); MongoUtil.setPage(query, params, "checkTime"); List<OsdCheckResult> resultList = mongoTemplate.find(query, OsdCheckResult.class); + Document areDocument = null; + if (areaDeptEnum != null) { + String areaCodePrefix = areaDeptEnum.getCode(); + areDocument = new Document("deviceNo", new Document("$regex", "^" + areaCodePrefix)); + } for (OsdCheckResult osdCheckResult : resultList) { OsdCheckResult.getError(osdCheckResult); @@ -1830,7 +2757,10 @@ MongoDatabase database = mongoTemplate.getDb(); MongoCollection<Document> collection = database.getCollection("osd_check_result"); //鎬绘暟 - List<Document> dList = new ArrayList<>(2); + List<Document> dList = new ArrayList<>(3); + if (areDocument != null){ + dList.add(areDocument); + } dList.add(new Document("importantTag", Boolean.TRUE)); setTag(params, dList); Document osdFilter = new Document("$and", dList); @@ -1842,10 +2772,16 @@ dList1.add(new Document("osdProvinceCorrect", new Document("$eq", 1))); dList1.add(new Document("osdCityCorrect", new Document("$eq", 1))); dList1.add(new Document("osdPartCorrect", new Document("$eq", 1))); + if (areDocument != null){ + dList1.add(areDocument); + } setTag(params, dList1); Document osdCorrectFilter = new Document("$and", dList1); //寮傚父鏁� List<Document> dList2 = new ArrayList<>(2); + if (areDocument != null){ + dList2.add(areDocument); + } setTag(params, dList2); Document importantTagCondition = new Document("importantTag", Boolean.TRUE); dList2.add(importantTagCondition); @@ -1860,6 +2796,9 @@ Document osdErrorFilter = new Document("$and", dList2); //鏈煡鏁� List<Document> dList3 = new ArrayList<>(2); + if (areDocument != null){ + dList3.add(areDocument); + } setTag(params, dList3); dList3.add(importantTagCondition); List<Document> unknownConditions = new ArrayList<>(); @@ -1925,7 +2864,20 @@ @Override public Result vehicleViewDockStable(DataCenterQuery params) { List<String> likeFileds = Arrays.asList("externalIndexCode", "deviceName"); - Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); + 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); + } //鍔燚ataType涓鸿溅杈� query.addCriteria(Criteria.where("dataType").is(ApiConstants.HK_DataType_CAR)); if (params.getOption() != null) { @@ -1943,23 +2895,41 @@ MongoUtil.setPage(query, params, TIME_FIELD); List<SnapshotDataMonitorResult> resultList = mongoTemplate.find(query, SnapshotDataMonitorResult.class); resultList.forEach(item -> item.setResultTypeText(item.getResultTypeText())); + Document areDocument = null; + if (areaDeptEnum != null) { + String areaCodePrefix = areaDeptEnum.getCode(); + areDocument = new Document("deviceNo", new Document("$regex", "^" + areaCodePrefix)); + } // 缁熻鏁伴噺 MongoDatabase database = mongoTemplate.getDb(); MongoCollection<Document> collection = database.getCollection("hk_snapshot_data_monitor"); List<Document> dList2 = new ArrayList<>(2); + if (areDocument != null){ + dList2.add(areDocument); + } dList2.add(new Document("resultType", new Document("$eq", 1))); dList2.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_CAR))); setTag(params, dList2); + List<Document> dList3 = new ArrayList<>(2); + if (areDocument != null){ + dList3.add(areDocument); + } dList3.add(new Document("resultType", new Document("$eq", 2))); dList3.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_CAR))); setTag(params, dList3); List<Document> dList4 = new ArrayList<>(2); + if (areDocument != null){ + dList4.add(areDocument); + } dList4.add(new Document("resultType", new Document("$eq", 3))); dList4.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_CAR))); setTag(params, dList4); List<Document> dList5 = new ArrayList<>(2); + if (areDocument != null){ + dList5.add(areDocument); + } dList5.add(new Document("resultType", new Document("$eq", 4))); dList5.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_CAR))); setTag(params, dList5); @@ -2029,6 +2999,24 @@ return Result.ok().data(map).total(total); } + public Query buildQuery(DataCenterQuery params,List<String> likeFileds,String fileName){ + 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); + } + return query; + } + /** * 杞﹁締锛氱偣浣嶅湪绾跨巼 * @@ -2038,7 +3026,20 @@ @Override public Result vehiclePointOnlineRate(DataCenterQuery params) { List<String> likeFileds = Arrays.asList("name", "no", "ip"); - Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null); + 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_Car + ".*")); //涓嬫媺妗嗗湪绾挎儏鍐垫煡璇㈡潯浠� @@ -2094,6 +3095,9 @@ 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_Car + ".*")); criteriaList.add(Criteria.where("mongoCreateTime").gte(params.getStartTime()).lte(params.getEndTime())); @@ -2153,7 +3157,19 @@ @Override public Result vehicleNetDeviceDirectoryConsistency(DataCenterQuery params) { List<String> likeFileds = Arrays.asList("ip.showValue", "name.showValue", "serialNumber.showValue"); - List<Criteria> andCriteria = MongoUtil.getAndCriteria(params, TIME_FIELD, likeFileds, null); + SysDept sysDept = getSysDeptByLoginUser(); + List<Criteria> andCriteria; + AreaDeptEnum areaDeptEnum = null; + if (sysDept != null) { + areaDeptEnum = AreaDeptEnum.fromDept(Math.toIntExact(sysDept.getDeptId())); + if (areaDeptEnum != null) { + andCriteria = MongoUtil.getAndCriteriaDateCenter(areaDeptEnum.getCode(),params, "checkTime", likeFileds, null); + }else { + andCriteria = MongoUtil.getAndCriteria(params, "checkTime", likeFileds, null); + } + }else { + andCriteria = MongoUtil.getAndCriteria(params, "checkTime", likeFileds, null); + } // 1/2/3 瑙嗛/杞﹁締/浜鸿劯 Pattern pattern = Pattern.compile(".*2.*"); andCriteria.add(Criteria.where("sxjgnlx.value").regex(pattern)); @@ -2179,13 +3195,25 @@ //缁熻鏁伴噺 MongoDatabase database = mongoTemplate.getDb(); MongoCollection<Document> collection = database.getCollection("uy_monitor_qualify"); + Document areDocument = null; + if (areaDeptEnum != null) { + String areaCodePrefix = areaDeptEnum.getCode(); + areDocument = new Document("no", new Document("$regex", "^" + areaCodePrefix)); + } + //鎬绘暟 List<Document> dList1 = new ArrayList<>(2); + if (areDocument != null){ + dList1.add(areDocument); + } setTag(params, dList1); dList1.add(new Document("sxjgnlx.value", new Document("$regex", ".*2.*"))); Document totalFilter = new Document("$and", dList1); //鏂拌澶囨暟 List<Document> dList2 = new ArrayList<>(2); + if (areDocument != null){ + dList2.add(areDocument); + } setTag(params, dList2); dList2.add(new Document("sxjgnlx.value", new Document("$regex", ".*2.*"))); dList2.add(new Document("newDevice", Boolean.TRUE)); -- Gitblit v1.8.0