From 2a12d6d43b6f7abc0ef594ee9b992f34ee00b7a1 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期五, 16 八月 2024 10:28:59 +0800
Subject: [PATCH] python接口

---
 ycl-server/src/main/java/com/ycl/calculate/VideoOnlineCalculation.java |   65 +++++++++++++++++++++-----------
 1 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/ycl-server/src/main/java/com/ycl/calculate/VideoOnlineCalculation.java b/ycl-server/src/main/java/com/ycl/calculate/VideoOnlineCalculation.java
index fef8088..5c4f9ea 100644
--- a/ycl-server/src/main/java/com/ycl/calculate/VideoOnlineCalculation.java
+++ b/ycl-server/src/main/java/com/ycl/calculate/VideoOnlineCalculation.java
@@ -5,7 +5,10 @@
 import com.ycl.platform.domain.entity.TMonitor;
 import com.ycl.platform.domain.result.HK.SnapshotDelayMonitorResult;
 import com.ycl.platform.domain.result.UY.QueryVqdResult;
+import com.ycl.platform.domain.result.UY.VideoOnlineResult;
+import com.ycl.platform.domain.vo.TMonitorVO;
 import com.ycl.platform.mapper.CheckIndexVideoMapper;
+import com.ycl.platform.mapper.TMonitorMapper;
 import com.ycl.platform.service.ICheckIndexFaceService;
 import com.ycl.platform.service.ICheckIndexVideoService;
 import com.ycl.platform.service.ITMonitorService;
@@ -24,19 +27,18 @@
 import java.util.stream.Collectors;
 
 /**
- * 璁$畻瑙嗛璁惧鐐逛綅鍦ㄧ嚎鐜囥�侀噸鐐圭偣浣嶅湪绾跨巼
+ * 璁$畻瑙嗛璁惧鐐逛綅鍦ㄧ嚎鐜囥�侀噸鐐圭偣浣嶅湪绾跨巼銆侀噸鐐规寚鎸ュ浘鍍忓湪绾跨巼
  * 鍥惧儚鐩戞祴璇婃柇缁撴灉
  * 鑾峰彇鍒嗙渷鍘呫�佸尯鍩熺殑map<k,v> k涓篸eptId鎴栬�匬rovince_deptId
  * 寰幆map璁$畻鏁版嵁涓婁紶鍙婃椂鎬�
  * 鏇存柊鎴栨柊澧�
  */
 @Component
-//TODO锛氶噸鐐规寚鎸ュ浘鍍忓湪绾跨巼
-public class VideoOnlineCalculation extends IndexCalculationServe implements CalculationStrategy<QueryVqdResult> {
+public class VideoOnlineCalculation extends IndexCalculationServe implements CalculationStrategy<VideoOnlineResult> {
     @Autowired
     private CheckIndexVideoMapper checkIndexVideoMapper;
     @Autowired
-    private ITMonitorService monitorService;
+    private TMonitorMapper monitorMapper;
     @Autowired
     private ICheckIndexVideoService checkIndexVideoService;
 
@@ -46,35 +48,38 @@
         int onlineSites = 0;
         int importantSites = 0;
         int importantOnlineSites = 0;
+        int commandSites = 0;
+        int commandOnlineSites =0;
     }
 
     @Override
-    public void calculate(List<QueryVqdResult> list) {
+    public void calculate(List<VideoOnlineResult> list) {
         if (CollectionUtils.isEmpty(list)) {
             return;
         }
 
         //鑾峰緱鍥芥爣鐮佷负key鐨勮澶噈ap
-        Map<String, TMonitor> monitorMap = monitorService.list(new QueryWrapper<TMonitor>()
-                        .in("serial_number", list.stream().map(QueryVqdResult::getDeviceId).collect(Collectors.toList())))
-                .stream().collect(Collectors.toMap(TMonitor::getSerialNumber, Function.identity()));
+        Map<String, TMonitorVO> monitorMap = monitorMapper.selectListByIds(list.stream().map(VideoOnlineResult::getDeviceId).collect(Collectors.toList()))
+                .stream().collect(Collectors.toMap(TMonitorVO::getSerialNumber, Function.identity()));
         //鑾峰彇鐪佸巺鍥芥爣鐮侀泦鍚�
         List<String> provinceIds = getProvince();
         //閲嶇偣鐐逛綅闆嗗悎
         List<String> important = getImportant();
+        //閲嶇偣鎸囨尌鍥惧儚闆嗗悎
+        List<String> commandImage = getCommandImage();
 
         Map<String, AreaStats> areaStatsMap = new HashMap<>();
-        for (QueryVqdResult result : list) {
-            TMonitor monitor = monitorMap.get(result.getDeviceId());
+        for (VideoOnlineResult result : list) {
+            TMonitorVO monitor = monitorMap.get(result.getDeviceId());
             if (monitor == null) continue;
 
             String deptId = monitor.getDeptId().toString();
-            updateAreaStats(areaStatsMap, deptId, result, important);
+            updateAreaStats(areaStatsMap, deptId, result, important,commandImage);
 
             // 澶勭悊鐪佸巺鏁版嵁
             if (!CollectionUtils.isEmpty(provinceIds) && provinceIds.contains(monitor.getSerialNumber())) {
-                String provinceKey = "Province_" + deptId;
-                updateAreaStats(areaStatsMap, provinceKey, result, important);
+                String provinceKey = ApiConstants.Province  + deptId;
+                updateAreaStats(areaStatsMap, provinceKey, result, important,commandImage);
             }
         }
 
@@ -83,7 +88,7 @@
         List<CheckIndexVideo> checkIndexVideos = new ArrayList<>();
         areaStatsMap.forEach((deptId, stats) -> {
             if (stats.totalSites > 0) {
-                CheckIndexVideo CheckIndexVideo = createOrUpdateCheckIndexFace(deptId, stats, checkIndexVideoList);
+                CheckIndexVideo CheckIndexVideo = createOrUpdateCheckIndexVideo(deptId, stats, checkIndexVideoList);
                 if (CheckIndexVideo != null) {
                     checkIndexVideos.add(CheckIndexVideo);
                 }
@@ -94,19 +99,27 @@
     }
 
     /**
-     * 绱鎬荤偣浣嶆暟銆佸湪绾跨偣浣嶆暟銆侀噸鐐圭偣浣嶆暟銆侀噸鐐圭偣浣嶅湪绾挎暟
+     * 绱鎬荤偣浣嶆暟銆佸湪绾跨偣浣嶆暟銆侀噸鐐圭偣浣嶆暟銆侀噸鐐圭偣浣嶅湪绾挎暟銆佹寚鎸ュ浘鍍忔暟銆佹寚鎸ュ浘鍍忓湪绾挎暟
      */
-    private void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, QueryVqdResult result, List<String> important) {
+    private void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, VideoOnlineResult result, List<String> important, List<String>  commandImage) {
         //杩斿洖瀵硅薄鐨勫紩鐢紝濡傛灉涓嶅瓨鍦ㄤ細鏀惧叆鏂扮殑key,value
         AreaStats stats = areaStatsMap.computeIfAbsent(key, k -> new AreaStats());
         stats.totalSites++;
+        //閲嶇偣鐐逛綅
         if(important.contains(result.getDeviceId())){
             stats.importantSites++;
         }
-        if (ApiConstants.UY_OnlineSite_Online.equals(result.getOnlineStatus())){
+        //鎸囨尌鍥惧儚鐐逛綅
+        if(commandImage.contains(result.getDeviceId())){
+            stats.commandSites++;
+        }
+        if (ApiConstants.UY_OnlineSite_Online.equals(result.getStatus())){
             stats.onlineSites++;
             if(important.contains(result.getDeviceId())){
                 stats.importantOnlineSites++;
+            }
+            if(commandImage.contains(result.getDeviceId())){
+                stats.commandOnlineSites++;
             }
         }
     }
@@ -114,9 +127,9 @@
     /**
      * 瑙嗛鐐逛綅鍦ㄧ嚎鐜�
      */
-    private CheckIndexVideo createOrUpdateCheckIndexFace(String key, AreaStats stats, List<CheckIndexVideo> checkIndexVideoList) {
-        CheckIndexVideo CheckIndexVideo = getCheckIndex(key, checkIndexVideoList, CheckIndexVideo.class);
-        if (CheckIndexVideo == null) {
+    private CheckIndexVideo createOrUpdateCheckIndexVideo(String key, AreaStats stats, List<CheckIndexVideo> checkIndexVideoList) {
+        CheckIndexVideo checkIndexVideo = getCheckIndex(key, checkIndexVideoList, CheckIndexVideo.class);
+        if (checkIndexVideo == null) {
             return null;
         }
         //璋冪敤鐐逛綅鍦ㄧ嚎鐜囪绠楁柟娉�
@@ -124,13 +137,19 @@
         param.put("totalSites", stats.totalSites);
         param.put("onlineSites", stats.onlineSites);
         BigDecimal siteOnline = siteOnline(param);
-        CheckIndexVideo.setSiteOnline(siteOnline);
+        checkIndexVideo.setSiteOnline(siteOnline);
         //璋冪敤鐐逛綅鍦ㄧ嚎鐜囪绠楁柟娉� 璁$畻閲嶇偣鐐逛綅鍦ㄧ嚎鐜�
         Map<String, Object> importantParam = new HashMap<>();
         param.put("totalSites", stats.importantSites);
         param.put("onlineSites", stats.importantOnlineSites);
         BigDecimal importantSiteOnline = siteOnline(importantParam);
-        CheckIndexVideo.setKeySiteOnline(importantSiteOnline);
-        return CheckIndexVideo;
+        checkIndexVideo.setKeySiteOnline(importantSiteOnline);
+        //璋冪敤鐐逛綅鍦ㄧ嚎鐜囪绠楁柟娉� 璁$畻鎸囨尌鍥惧儚鍦ㄧ嚎鐜�
+        Map<String, Object> commandParam = new HashMap<>();
+        param.put("totalSites", stats.commandSites);
+        param.put("onlineSites", stats.commandOnlineSites);
+        BigDecimal commandSiteOnline = siteOnline(importantParam);
+        checkIndexVideo.setKeyCommandImageOnline(commandSiteOnline);
+        return checkIndexVideo;
     }
 }

--
Gitblit v1.8.0