From b14531e3b850fe6d2fa916ba7b88b3e2bd2ff30a Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期三, 11 九月 2024 16:47:48 +0800
Subject: [PATCH] OSD加标签

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/DataCenterServiceImpl.java |  234 +++++++++++++---------------------------------------------
 1 files changed, 54 insertions(+), 180 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 f7b2e36..7d463d4 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
@@ -11,6 +11,7 @@
 import com.ycl.platform.domain.query.DataCenterQuery;
 import com.ycl.platform.domain.result.HK.*;
 import com.ycl.platform.domain.result.UY.*;
+import com.ycl.platform.domain.vo.PointDetailVO;
 import com.ycl.platform.mapper.ImageResourceSecurityDetailMapper;
 import com.ycl.platform.mapper.YwPointMapper;
 import com.ycl.platform.service.*;
@@ -65,19 +66,14 @@
      */
     @Override
     public Result videoPointOnlineRate(DataCenterQuery params) {
-        // 鐢熸垚鏌ヨ
-        List<String> likeFileds = Arrays.asList("arealayerName", "ipAddr", "deviceName", "deviceId");
-        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null);
+        params.setDeptTag(-1);
+        params.setDeviceType(1);
+        IPage<PointDetailVO> page = PageUtil.getPage(params, PointDetailVO.class);
+        pointMapper.dataCenterPage(page, params);
 
-        // 鍏堟煡鎬绘暟鍐嶅垎椤�
-        long total = mongoTemplate.count(query, VideoOnlineResult.class);
-        MongoUtil.setPage(query, params, TIME_FIELD);
-        List<VideoOnlineResult> resultList = mongoTemplate.find(query, VideoOnlineResult.class);
+        // 缁熻璁惧鏁伴噺
+        Integer distinctCount = pointMapper.distinctCount(params);
 
-        // 缁熻鏁伴噺
-        MongoDatabase database = mongoTemplate.getDb();
-        MongoCollection<Document> collection = database.getCollection("uy_online");
-        long distinctCount = collection.distinct("deviceId", String.class).into(new ArrayList<>()).size();
         Date now = new Date();
         List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                 .select(CheckIndexVideo::getSiteOnline)
@@ -91,8 +87,8 @@
         }
         HashMap<String, Object> map = new HashMap<>();
         map.put("count", Arrays.asList(distinctCount + "",this.remove0(onlineRate)));
-        map.put("list", resultList);
-        return Result.ok().data(map).total(total);
+        map.put("list", page.getRecords());
+        return Result.ok().data(map).total(page.getTotal());
     }
 
     /**
@@ -103,40 +99,14 @@
      */
     @Override
     public Result deptVideoPointOnlineRate(DataCenterQuery params) {
+        params.setDeptTag(1);
+        params.setDeviceType(1);
+        IPage<PointDetailVO> page = PageUtil.getPage(params, PointDetailVO.class);
+        pointMapper.dataCenterPage(page, params);
 
-        List<String> likeFileds = Arrays.asList("arealayerName", "ipAddr", "deviceName", "deviceId");
-        // 鐢熸垚鏌ヨ
-        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, 1);
+        // 缁熻璁惧鏁伴噺
+        Integer distinctCount = pointMapper.distinctCount(params);
 
-        // 鍏堟煡鎬绘暟鍐嶅垎椤�
-        long total = mongoTemplate.count(query, VideoOnlineResult.class);
-        MongoUtil.setPage(query, params, TIME_FIELD);
-        List<VideoOnlineResult> resultList = mongoTemplate.find(query, VideoOnlineResult.class);
-
-        // 缁熻鏁伴噺
-        MongoDatabase database = mongoTemplate.getDb();
-        MongoCollection<Document> collection = database.getCollection("uy_online");
-        List<Document> dList = new ArrayList<>(2);
-        dList.add(new Document("deptTag", new Document("$eq", Boolean.TRUE)));
-        if (params.getDataType().equals(1)) {
-            dList.add(new Document("provinceTag", new Document("$eq", Boolean.TRUE)));
-        }
-        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 鍙細浜х敓涓�涓粨鏋�
-        }
         Date now = new Date();
         List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
                 .select(CheckIndexVideo::getMinistrySiteOnline)
@@ -150,9 +120,9 @@
             onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
         }
         HashMap<String, Object> map = new HashMap<>();
-        map.put("count", Arrays.asList(uniqueDeviceIdCount + "", this.remove0(onlineRate)));
-        map.put("list", resultList);
-        return Result.ok().data(map).total(total);
+        map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate)));
+        map.put("list", page.getRecords());
+        return Result.ok().data(map).total(page.getTotal());
     }
 
     /**
@@ -163,37 +133,13 @@
      */
     @Override
     public Result videoImportantPointOnlineRate(DataCenterQuery params) {
-        List<String> likeFileds = Arrays.asList("arealayerName", "ipAddr", "deviceName", "deviceId");
-        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, 3);
+        params.setDeptTag(3);
+        params.setDeviceType(1);
+        IPage<PointDetailVO> page = PageUtil.getPage(params, PointDetailVO.class);
+        pointMapper.dataCenterPage(page, params);
 
-        long total = mongoTemplate.count(query, VideoOnlineResult.class);
-        MongoUtil.setPage(query, params, TIME_FIELD);
-        List<VideoOnlineResult> resultList = mongoTemplate.find(query, VideoOnlineResult.class);
-
-        // 缁熻鏁伴噺
-        MongoDatabase database = mongoTemplate.getDb();
-        MongoCollection<Document> collection = database.getCollection("uy_online");
-
-        List<Document> dList = new ArrayList<>(2);
-        dList.add(new Document("importantTag", new Document("$eq", Boolean.TRUE)));
-        if (params.getDataType().equals(1)) {
-            dList.add(new Document("provinceTag", new Document("$eq", Boolean.TRUE)));
-        }
-        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 鍙細浜х敓涓�涓粨鏋�
-        }
+        // 缁熻璁惧鏁伴噺
+        Integer distinctCount = pointMapper.distinctCount(params);
 
         Date now = new Date();
         List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
@@ -208,9 +154,9 @@
             onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
         }
         HashMap<String, Object> map = new HashMap<>();
-        map.put("count", Arrays.asList(uniqueDeviceIdCount + "", this.remove0(onlineRate)));
-        map.put("list", resultList);
-        return Result.ok().data(map).total(total);
+        map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate)));
+        map.put("list", page.getRecords());
+        return Result.ok().data(map).total(page.getTotal());
     }
 
     /**
@@ -221,37 +167,13 @@
      */
     @Override
     public Result videoImportantPointImageOnlineRate(DataCenterQuery params) {
-        List<String> likeFileds = Arrays.asList("arealayerName", "ipAddr", "deviceName", "deviceId");
-        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, 4);
+        params.setDeptTag(4);
+        params.setDeviceType(1);
+        IPage<PointDetailVO> page = PageUtil.getPage(params, PointDetailVO.class);
+        pointMapper.dataCenterPage(page, params);
 
-        long total = mongoTemplate.count(query, VideoOnlineResult.class);
-        MongoUtil.setPage(query, params, TIME_FIELD);
-        List<VideoOnlineResult> resultList = mongoTemplate.find(query, VideoOnlineResult.class);
-
-        // 缁熻鏁伴噺
-        MongoDatabase database = mongoTemplate.getDb();
-        MongoCollection<Document> collection = database.getCollection("uy_online");
-
-        List<Document> dList = new ArrayList<>(2);
-        dList.add(new Document("importantCommandImageTag", new Document("$eq", Boolean.TRUE)));
-        if (params.getDataType().equals(1)) {
-            dList.add(new Document("provinceTag", new Document("$eq", Boolean.TRUE)));
-        }
-        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 鍙細浜х敓涓�涓粨鏋�
-        }
+        // 缁熻璁惧鏁伴噺
+        Integer distinctCount = pointMapper.distinctCount(params);
 
         Date now = new Date();
         List<CheckIndexVideo> videoList = new LambdaQueryChainWrapper<>(checkIndexVideoService.getBaseMapper())
@@ -266,9 +188,9 @@
             onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
         }
         HashMap<String, Object> map = new HashMap<>();
-        map.put("count", Arrays.asList(uniqueDeviceIdCount + "", this.remove0(onlineRate)));
-        map.put("list", resultList);
-        return Result.ok().data(map).total(total);
+        map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate)));
+        map.put("list", page.getRecords());
+        return Result.ok().data(map).total(page.getTotal());
     }
 
     /**
@@ -996,17 +918,13 @@
      */
     @Override
     public Result vehiclePointOnlineRate(DataCenterQuery params) {
-        List<String> likeFileds = Arrays.asList("externalIndexCode", "deviceName");
-        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null);
+        params.setDeptTag(-1);
+        params.setDeviceType(2);
+        IPage<PointDetailVO> page = PageUtil.getPage(params, PointDetailVO.class);
+        pointMapper.dataCenterPage(page, params);
 
-        long total = mongoTemplate.count(query, SnapshotDataMonitorResult.class);
-        MongoUtil.setPage(query, params, TIME_FIELD);
-        List<SnapshotDataMonitorResult> resultList = mongoTemplate.find(query, SnapshotDataMonitorResult.class);
-
-        // 缁熻鏁伴噺
-        MongoDatabase database = mongoTemplate.getDb();
-        MongoCollection<Document> collection = database.getCollection("hk_snapshot_data_monitor");
-        long distinctCount = collection.distinct("externalIndexCode", String.class).into(new ArrayList<>()).size();
+        // 缁熻璁惧鏁伴噺
+        Integer distinctCount = pointMapper.distinctCount(params);
 
         Date now = new Date();
         List<CheckIndexCar> videoList = new LambdaQueryChainWrapper<>(checkIndexCarService.getBaseMapper())
@@ -1022,8 +940,8 @@
         }
         HashMap<String, Object> map = new HashMap<>();
         map.put("count", Arrays.asList(distinctCount + "", this.remove0(onlineRate)));
-        map.put("list", resultList);
-        return Result.ok().data(map).total(total);
+        map.put("list", page.getRecords());
+        return Result.ok().data(map).total(page.getTotal());
     }
 
     /**
@@ -1528,59 +1446,13 @@
      */
     @Override
     public Result facePointOnlineRate(DataCenterQuery params) {
-        List<String> likeFileds = Arrays.asList("externalIndexCode", "deviceName");
-        Query query = MongoUtil.getQuery(params, TIME_FIELD, likeFileds, null);
+        params.setDeptTag(-1);
+        params.setDeviceType(3);
+        IPage<PointDetailVO> page = PageUtil.getPage(params, PointDetailVO.class);
+        pointMapper.dataCenterPage(page, params);
 
-        long total = mongoTemplate.count(query, SnapshotDataMonitorResult.class);
-        MongoUtil.setPage(query, params, TIME_FIELD);
-        List<SnapshotDataMonitorResult> resultList = mongoTemplate.find(query, SnapshotDataMonitorResult.class);
-
-        // 缁熻鏁伴噺
-        MongoDatabase database = mongoTemplate.getDb();
-        MongoCollection<Document> collection = database.getCollection("hk_snapshot_data_monitor");
-
-        List<Document> dList1 = new ArrayList<>(2);
-        dList1.add(new Document("resultType", new Document("$eq", 1)));
-        if (params.getDataType().equals(1)) {
-            dList1.add(new Document("provinceTag", new Document("$eq", Boolean.TRUE)));
-        }
-        List<Document> dList2 = new ArrayList<>(2);
-        dList2.add(new Document("resultType", new Document("$eq", 2)));
-        if (params.getDataType().equals(1)) {
-            dList2.add(new Document("provinceTag", new Document("$eq", Boolean.TRUE)));
-        }
-        List<Document> dList3 = new ArrayList<>(2);
-        dList3.add(new Document("resultType", new Document("$eq", 3)));
-        if (params.getDataType().equals(1)) {
-            dList3.add(new Document("provinceTag", new Document("$eq", Boolean.TRUE)));
-        }
-        List<Document> dList4 = new ArrayList<>(2);
-        dList4.add(new Document("resultType", new Document("$eq", 4)));
-        if (params.getDataType().equals(1)) {
-            dList4.add(new Document("provinceTag", new Document("$eq", Boolean.TRUE)));
-        }
-        Document normalFilter = new Document("$and", dList1);
-        Document noDataFilter = new Document("$and", dList2);
-        Document trFilter = new Document("$and", dList3);
-        Document littleFilter = new Document("$and", dList4);
-        List<Document> lists = Arrays.asList(normalFilter, noDataFilter, trFilter, littleFilter);
-        List<String> rList = lists.stream().map(filter -> {
-            // 鏋勫缓鑱氬悎绠¢亾
-            List<Document> pipeline = Arrays.asList(
-                    new Document("$match", filter),
-                    // $group 鍘婚噸
-                    new Document("$group", new Document("_id", "$externalIndexCode")),
-                    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());
+        // 缁熻璁惧鏁伴噺
+        Integer distinctCount = pointMapper.distinctCount(params);
 
         Date now = new Date();
         List<CheckIndexFace> videoList = new LambdaQueryChainWrapper<>(checkIndexFaceService.getBaseMapper())
@@ -1594,11 +1466,13 @@
             BigDecimal count = BigDecimal.valueOf(videoList.size());
             onlineRate = sum.divide(count, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
         }
+        List<String> rList = new ArrayList<>(2);
+        rList.add(distinctCount + "");
         rList.add(this.remove0(onlineRate));
         HashMap<String, Object> map = new HashMap<>();
         map.put("count", rList);
-        map.put("list", resultList);
-        return Result.ok().data(map).total(total);
+        map.put("list", page.getRecords());
+        return Result.ok().data(map).total(page.getTotal());
     }
 
     /**

--
Gitblit v1.8.0