From fea22e82e7e49691f6e0c20a29b228d0ab3173e9 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期三, 29 十月 2025 17:08:38 +0800
Subject: [PATCH] 修改问题

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java |  892 +++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 566 insertions(+), 326 deletions(-)

diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java
index 3127208..d837e1a 100644
--- a/ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java
+++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java
@@ -6,6 +6,7 @@
 import com.mongodb.client.AggregateIterable;
 import com.mongodb.client.MongoCollection;
 import com.mongodb.client.MongoDatabase;
+import com.ycl.platform.domain.entity.MonitorConstruction;
 import com.ycl.platform.domain.entity.TMonitor;
 import com.ycl.platform.domain.excel.*;
 import com.ycl.platform.domain.form.VideoExportForm;
@@ -31,6 +32,7 @@
 import com.ycl.platform.mapper.TMonitorMapper;
 import com.ycl.platform.mapper.WorkOrderMapper;
 import com.ycl.platform.mapper.YwPointMapper;
+import com.ycl.platform.service.IMonitorConstructionService;
 import com.ycl.platform.service.ITMonitorService;
 import com.ycl.system.Result;
 import com.ycl.system.entity.SysDictData;
@@ -71,7 +73,10 @@
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.function.Function;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
+
+import static com.ycl.utils.PageUtils.startPage;
 
 /**
  * 璁惧璧勪骇Service涓氬姟灞傚鐞�
@@ -98,7 +103,8 @@
     private DynamicColumnMapper dynamicColumnMapper;
     @Autowired
     private ThreadPoolTaskExecutor threadPoolTaskExecutor;
-
+    @Autowired
+    private IMonitorConstructionService monitorConstructionService;
     /**
      * 鏌ヨ璁惧璧勪骇
      *
@@ -128,156 +134,173 @@
             }
             tMonitor.setTime(time);
         }
-        List<TMonitorVO> monitors = tMonitorMapper.selectTMonitorList(tMonitor);
-        // 寮傚父鎭㈠鐩戞帶
-        if (Objects.equals(tMonitor.getRecovery(), 1L)) {
-            //宸ュ崟鍙�
-            List<String> orders = monitors.stream().map(TMonitorVO::getWorkOrderNo).collect(Collectors.toList());
-            if (CollectionUtils.isEmpty(orders)) {
+        List<TMonitorVO> monitors = new ArrayList<>();
+        if (StringUtils.isNotBlank(tMonitor.getConstructionType())){
+            List<MonitorConstruction> list =
+                    monitorConstructionService.getSerialNumberListByConstructionType(tMonitor.getConstructionType());
+            log.info("鎵撳嵃鏌ヨ璁惧鏍囩鏁�:{},寤鸿绫诲瀷鏍囩:{}",list.size(), tMonitor.getConstructionType() );
+            //鑾峰緱璁惧缂栧彿闆嗗悎 閫氳繃寤鸿绫诲瀷鏍囩
+            if(!CollectionUtils.isEmpty(list)){
+                tMonitor.setIds(
+                        list.stream().map(MonitorConstruction::getSerialNumber).collect(Collectors.toList()));
+
+                startPage();
+                monitors = tMonitorMapper.selectTMonitorListAndIds(tMonitor);
+            }
+
+        }else{
+            startPage();
+            monitors = tMonitorMapper.selectTMonitorList(tMonitor);
+        }
+            // 寮傚父鎭㈠鐩戞帶
+            if (Objects.equals(tMonitor.getRecovery(), 1L)) {
+                //宸ュ崟鍙�
+                List<String> orders = monitors.stream().map(TMonitorVO::getWorkOrderNo).collect(Collectors.toList());
+                if (CollectionUtils.isEmpty(orders)) {
+                    return monitors;
+                }
+                List<WorkOrderVO> voList = workOrderMapper.getRecoveryInfo(orders);
+                for (TMonitorVO monitor : monitors) {
+                    if (!CollectionUtils.isEmpty(voList)) {
+                        for (WorkOrderVO workOrderVO : voList) {
+                            if (monitor.getWorkOrderNo() != null && monitor.getWorkOrderNo().equals(workOrderVO.getWorkOrderNo())) {
+                                monitor.setUnitContact(workOrderVO.getUnitContact());
+                                monitor.setUnitContactPhone(workOrderVO.getUnitContactPhone());
+                                monitor.setYwPeopleName(workOrderVO.getYwPeopleName());
+                                monitor.setErrorType(workOrderVO.getErrorType());
+                            }
+                        }
+                    }
+                }
                 return monitors;
             }
-            List<WorkOrderVO> voList = workOrderMapper.getRecoveryInfo(orders);
-            for (TMonitorVO monitor : monitors) {
-                if (!CollectionUtils.isEmpty(voList)) {
-                    for (WorkOrderVO workOrderVO : voList) {
-                        if (monitor.getWorkOrderNo() != null && monitor.getWorkOrderNo().equals(workOrderVO.getWorkOrderNo())) {
-                            monitor.setUnitContact(workOrderVO.getUnitContact());
-                            monitor.setUnitContactPhone(workOrderVO.getUnitContactPhone());
-                            monitor.setYwPeopleName(workOrderVO.getYwPeopleName());
-                            monitor.setErrorType(workOrderVO.getErrorType());
+            //璁惧缂栧彿
+            List<String> numbers = monitors.stream().map(TMonitorVO::getSerialNumber).collect(Collectors.toList());
+            Query query = new Query();
+            Date now = new Date();
+            query.addCriteria(Criteria.where("no").in(numbers)
+                    .and("mongoCreateTime").gte(DateUtils.getDayStart(now)).lt(DateUtils.getDayEnd(now))
+            );
+            //涓�鏈轰竴妗d俊鎭�
+            List<MonitorQualifyResult> monitorQualifyResults = mongoTemplate.find(query, MonitorQualifyResult.class);
+            // 瑙嗛鐩戞帶璁惧
+            if (Objects.equals(tMonitor.getCameraFunType(), "1")) {
+                //OSD淇℃伅
+                List<OsdCheckResult> osdCheckResults = mongoTemplate.find(query, OsdCheckResult.class);
+                //褰曞儚鍙敤淇℃伅
+                List<RecordMetaDSumResult> videoResults = mongoTemplate.find(query, RecordMetaDSumResult.class);
+                for (TMonitorVO monitor : monitors) {
+                    monitor.setMongoCreateTime(now);
+                    //涓�鏈轰竴妗�
+                    setOneFile(monitorQualifyResults, monitor);
+                    //褰曞儚
+                    if (!CollectionUtils.isEmpty(videoResults)) {
+                        for (RecordMetaDSumResult videoResult : videoResults) {
+                            if (monitor.getSerialNumber().equals(videoResult.getNo())) {
+                                monitor.setVideoComplete(videoResult.getRecordStatus());
+                                monitor.setVideoLoseTime(videoResult.getMissDuration());
+                            }
+                        }
+                    }
+                    //OSD
+                    if (!CollectionUtils.isEmpty(osdCheckResults)) {
+                        for (OsdCheckResult osdCheckResult : osdCheckResults) {
+                            if (monitor.getSerialNumber().equals(osdCheckResult.getNo())) {
+                                monitor.setOSD(OsdCheckResult.checkOsd(osdCheckResult));
+                                monitor.setOSDTime(OsdCheckResult.checkTime(osdCheckResult));
+                            }
                         }
                     }
                 }
             }
-            return monitors;
-        }
-        //璁惧缂栧彿
-        List<String> numbers = monitors.stream().map(TMonitorVO::getSerialNumber).collect(Collectors.toList());
-        Query query = new Query();
-        Date now = new Date();
-        query.addCriteria(Criteria.where("no").in(numbers)
-                .and("mongoCreateTime").gte(DateUtils.getDayStart(now)).lt(DateUtils.getDayEnd(now))
-        );
-        //涓�鏈轰竴妗d俊鎭�
-        List<MonitorQualifyResult> monitorQualifyResults = mongoTemplate.find(query, MonitorQualifyResult.class);
-        // 瑙嗛鐩戞帶璁惧
-        if (Objects.equals(tMonitor.getCameraFunType(), "1")) {
-            //OSD淇℃伅
-            List<OsdCheckResult> osdCheckResults = mongoTemplate.find(query, OsdCheckResult.class);
-            //褰曞儚鍙敤淇℃伅
-            List<RecordMetaDSumResult> videoResults = mongoTemplate.find(query, RecordMetaDSumResult.class);
-            for (TMonitorVO monitor : monitors) {
-                monitor.setMongoCreateTime(now);
-                //涓�鏈轰竴妗�
-                setOneFile(monitorQualifyResults, monitor);
-                //褰曞儚
-                if (!CollectionUtils.isEmpty(videoResults)) {
-                    for (RecordMetaDSumResult videoResult : videoResults) {
-                        if (monitor.getSerialNumber().equals(videoResult.getNo())) {
-                            monitor.setVideoComplete(videoResult.getRecordStatus());
-                            monitor.setVideoLoseTime(videoResult.getMissDuration());
-                        }
-                    }
-                }
-                //OSD
-                if (!CollectionUtils.isEmpty(osdCheckResults)) {
-                    for (OsdCheckResult osdCheckResult : osdCheckResults) {
-                        if (monitor.getSerialNumber().equals(osdCheckResult.getNo())) {
-                            monitor.setOSD(OsdCheckResult.checkOsd(osdCheckResult));
-                            monitor.setOSDTime(OsdCheckResult.checkTime(osdCheckResult));
-                        }
-                    }
-                }
-            }
-        }
-        // 杞﹁締鐩戞帶璁惧
-        if (Objects.equals(tMonitor.getCameraFunType(), "2")) {
-            //灞炴�т竴鑷寸巼銆佸ぇ鍥�
-            List<VehicleDeviceSamplingResult> sampleResults = mongoTemplate.find(query, VehicleDeviceSamplingResult.class);
-            List<PicAccessResult> picAccessResults = mongoTemplate.find(query, PicAccessResult.class);
-            //鎶撴媿閲忋�佹椂閽熴�佷笂浼�
-            List<VehicleDeviceInspectionResult> inspectResults = mongoTemplate.find(query, VehicleDeviceInspectionResult.class);
-            for (TMonitorVO monitor : monitors) {
-                monitor.setMongoCreateTime(now);
-                //涓�鏈轰竴妗�
-                setOneFile(monitorQualifyResults, monitor);
-                //url
-                if (!CollectionUtils.isEmpty(sampleResults)) {
-                    for (PicAccessResult picAccessResult : picAccessResults) {
-                        if (monitor.getSerialNumber().equals(picAccessResult.getNo())) {
-                            BigDecimal bigDecimal = PicAccessResult.calUrl(picAccessResult);
-                            monitor.setUrlPercent(bigDecimal);
-                        }
-                    }
-                }
+            // 杞﹁締鐩戞帶璁惧
+            if (Objects.equals(tMonitor.getCameraFunType(), "2")) {
                 //灞炴�т竴鑷寸巼銆佸ぇ鍥�
-                if (!CollectionUtils.isEmpty(sampleResults)) {
-                    for (VehicleDeviceSamplingResult sampleResult : sampleResults) {
-                        if (monitor.getSerialNumber().equals(sampleResult.getNo())) {
-                            if (sampleResult.getBigUseful() != null) {
-                                monitor.setBigUsefulPercent(sampleResult.getBigUseful().getBigUsefulPercent());
-                            }
-                            if (sampleResult.getVehDiff() != null) {
-                                monitor.setImportantConPercent(sampleResult.getVehDiff().getImportantConPercent());
-                                monitor.setMajorConPercent(sampleResult.getVehDiff().getMajorConPercent());
-                            }
-                        }
-                    }
-                }
+                List<VehicleDeviceSamplingResult> sampleResults = mongoTemplate.find(query, VehicleDeviceSamplingResult.class);
+                List<PicAccessResult> picAccessResults = mongoTemplate.find(query, PicAccessResult.class);
                 //鎶撴媿閲忋�佹椂閽熴�佷笂浼�
-                if (!CollectionUtils.isEmpty(inspectResults)) {
-                    for (VehicleDeviceInspectionResult inspectResult : inspectResults) {
-                        if (monitor.getSerialNumber().equals(inspectResult.getNo())) {
-                            monitor.setSnapResult(inspectResult.getSnapResult());
-                            monitor.setSnapCount(inspectResult.getDataCount());
-                            if (inspectResult.getSnapClock() != null)
-                                monitor.setClockPercent(inspectResult.getSnapClock().getClockPercent());
-                            if (inspectResult.getSnapTimely() != null)
-                                monitor.setUploadPercent(inspectResult.getSnapTimely().getTimelyPercent());
-                        }
-                    }
-                }
-            }
-        }
-        // 浜鸿劯鐩戞帶璁惧
-        if (Objects.equals(tMonitor.getCameraFunType(), "3")) {
-            //浜鸿劯鍚堟牸銆佸ぇ鍥俱�乽rl璁块棶寮傚父
-            List<FaceDeviceSamplingResult> sampleResults = mongoTemplate.find(query, FaceDeviceSamplingResult.class);
-            //鎶撴媿閲忋�佹椂閽熴�佷笂浼�
-            List<FaceDeviceInspectionResult> inspectResults = mongoTemplate.find(query, FaceDeviceInspectionResult.class);
-            for (TMonitorVO monitor : monitors) {
-                monitor.setMongoCreateTime(now);
-                //涓�鏈轰竴妗�
-                setOneFile(monitorQualifyResults, monitor);
-                //浜鸿劯鍚堟牸銆佸ぇ鍥�
-                if (!CollectionUtils.isEmpty(sampleResults)) {
-                    for (FaceDeviceSamplingResult sampleResult : sampleResults) {
-                        if (monitor.getSerialNumber().equals(sampleResult.getNo())) {
-                            if (sampleResult.getBigUseful() != null) {
-                                monitor.setBigUsefulPercent(sampleResult.getBigUseful().getBigUsefulPercent());
+                List<VehicleDeviceInspectionResult> inspectResults = mongoTemplate.find(query, VehicleDeviceInspectionResult.class);
+                for (TMonitorVO monitor : monitors) {
+                    monitor.setMongoCreateTime(now);
+                    //涓�鏈轰竴妗�
+                    setOneFile(monitorQualifyResults, monitor);
+                    //url
+                    if (!CollectionUtils.isEmpty(sampleResults)) {
+                        for (PicAccessResult picAccessResult : picAccessResults) {
+                            if (monitor.getSerialNumber().equals(picAccessResult.getNo())) {
+                                BigDecimal bigDecimal = PicAccessResult.calUrl(picAccessResult);
+                                monitor.setUrlPercent(bigDecimal);
                             }
-                            if (sampleResult.getFaceEligibility() != null)
-                                monitor.setFacePercent(sampleResult.getFaceEligibility().getFaceEligPercent());
                         }
                     }
-                }
-                //鎶撴媿閲忋�佹椂閽熴�佷笂浼犮�佸缓妯″け璐ョ巼
-                if (!CollectionUtils.isEmpty(inspectResults)) {
-                    for (FaceDeviceInspectionResult inspectResult : inspectResults) {
-                        if (monitor.getSerialNumber().equals(inspectResult.getNo())) {
-                            monitor.setSnapResult(inspectResult.getSnapResult());
-                            monitor.setSnapCount(inspectResult.getDataCount());
-                            if (inspectResult.getSnapClock() != null)
-                                monitor.setClockPercent(inspectResult.getSnapClock().getClockPercent());
-                            if (inspectResult.getSnapTimely() != null)
-                                monitor.setUploadPercent(inspectResult.getSnapTimely().getTimelyPercent());
-                            if (inspectResult.getSnapValidity() != null)
-                                monitor.setFailPercent(inspectResult.getSnapValidity().getFailPercent());
+                    //灞炴�т竴鑷寸巼銆佸ぇ鍥�
+                    if (!CollectionUtils.isEmpty(sampleResults)) {
+                        for (VehicleDeviceSamplingResult sampleResult : sampleResults) {
+                            if (monitor.getSerialNumber().equals(sampleResult.getNo())) {
+                                if (sampleResult.getBigUseful() != null) {
+                                    monitor.setBigUsefulPercent(sampleResult.getBigUseful().getBigUsefulPercent());
+                                }
+                                if (sampleResult.getVehDiff() != null) {
+                                    monitor.setImportantConPercent(sampleResult.getVehDiff().getImportantConPercent());
+                                    monitor.setMajorConPercent(sampleResult.getVehDiff().getMajorConPercent());
+                                }
+                            }
+                        }
+                    }
+                    //鎶撴媿閲忋�佹椂閽熴�佷笂浼�
+                    if (!CollectionUtils.isEmpty(inspectResults)) {
+                        for (VehicleDeviceInspectionResult inspectResult : inspectResults) {
+                            if (monitor.getSerialNumber().equals(inspectResult.getNo())) {
+                                monitor.setSnapResult(inspectResult.getSnapResult());
+                                monitor.setSnapCount(inspectResult.getDataCount());
+                                if (inspectResult.getSnapClock() != null)
+                                    monitor.setClockPercent(inspectResult.getSnapClock().getClockPercent());
+                                if (inspectResult.getSnapTimely() != null)
+                                    monitor.setUploadPercent(inspectResult.getSnapTimely().getTimelyPercent());
+                            }
                         }
                     }
                 }
             }
-        }
+            // 浜鸿劯鐩戞帶璁惧
+            if (Objects.equals(tMonitor.getCameraFunType(), "3")) {
+                //浜鸿劯鍚堟牸銆佸ぇ鍥俱�乽rl璁块棶寮傚父
+                List<FaceDeviceSamplingResult> sampleResults = mongoTemplate.find(query, FaceDeviceSamplingResult.class);
+                //鎶撴媿閲忋�佹椂閽熴�佷笂浼�
+                List<FaceDeviceInspectionResult> inspectResults = mongoTemplate.find(query, FaceDeviceInspectionResult.class);
+                for (TMonitorVO monitor : monitors) {
+                    monitor.setMongoCreateTime(now);
+                    //涓�鏈轰竴妗�
+                    setOneFile(monitorQualifyResults, monitor);
+                    //浜鸿劯鍚堟牸銆佸ぇ鍥�
+                    if (!CollectionUtils.isEmpty(sampleResults)) {
+                        for (FaceDeviceSamplingResult sampleResult : sampleResults) {
+                            if (monitor.getSerialNumber().equals(sampleResult.getNo())) {
+                                if (sampleResult.getBigUseful() != null) {
+                                    monitor.setBigUsefulPercent(sampleResult.getBigUseful().getBigUsefulPercent());
+                                }
+                                if (sampleResult.getFaceEligibility() != null)
+                                    monitor.setFacePercent(sampleResult.getFaceEligibility().getFaceEligPercent());
+                            }
+                        }
+                    }
+                    //鎶撴媿閲忋�佹椂閽熴�佷笂浼犮�佸缓妯″け璐ョ巼
+                    if (!CollectionUtils.isEmpty(inspectResults)) {
+                        for (FaceDeviceInspectionResult inspectResult : inspectResults) {
+                            if (monitor.getSerialNumber().equals(inspectResult.getNo())) {
+                                monitor.setSnapResult(inspectResult.getSnapResult());
+                                monitor.setSnapCount(inspectResult.getDataCount());
+                                if (inspectResult.getSnapClock() != null)
+                                    monitor.setClockPercent(inspectResult.getSnapClock().getClockPercent());
+                                if (inspectResult.getSnapTimely() != null)
+                                    monitor.setUploadPercent(inspectResult.getSnapTimely().getTimelyPercent());
+                                if (inspectResult.getSnapValidity() != null)
+                                    monitor.setFailPercent(inspectResult.getSnapValidity().getFailPercent());
+                            }
+                        }
+                    }
+                }
+            }
         return monitors;
     }
 
@@ -345,6 +368,13 @@
     @Override
     @DataScope(deptAlias = "d", userAlias = "u")
     public Map<String, String> getVideoCount(TMonitorVO tMonitor) {
+
+        List<MonitorConstruction> list =
+                monitorConstructionService.getSerialNumberListByConstructionType(tMonitor.getConstructionType());
+        //鑾峰緱璁惧缂栧彿闆嗗悎 閫氳繃寤鸿绫诲瀷鏍囩
+        tMonitor.setIds(
+                list.stream().map(MonitorConstruction::getSerialNumber).collect(Collectors.toList()));
+
         return tMonitorMapper.getVideoCount(tMonitor);
     }
 
@@ -555,212 +585,371 @@
         ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
         util.exportExcelManySheet(response, mysheet);
     }
-
-
     /**
      * 瀵煎嚭姣忔棩鍦ㄧ嚎鏁版嵁
      */
     @Override
     public void exportVideoOnline(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException {
-        log.error("寮�濮嬪鍑烘暟鎹�");
-        log.error("浼犲叆鐨勬湀浠�:{}",exportForm.getMonth());
-        //榛樿鏌ユ墍鏈夐儴闂�
+        log.info("寮�濮嬪鍑烘暟鎹�");
+        log.info("浼犲叆鐨勬湀浠�:{}", exportForm.getMonth());
+
+        // 榛樿鏌ユ墍鏈夐儴闂�
         if (CollectionUtils.isEmpty(exportForm.getDeptIds())) {
-            List<Integer> deptIds = new ArrayList<>();
+            List<Integer> deptIds = new ArrayList<>(AreaDeptEnum.values().length);
             for (AreaDeptEnum value : AreaDeptEnum.values()) {
                 deptIds.add(value.getDeptId());
             }
             exportForm.setDeptIds(deptIds);
         }
-        List<ExcelExp> sheet = new ArrayList<>();
-        //閫氳繃Collections闈欐�佹柟娉曪紝鎶妉ist杞负绾跨▼瀹夊叏鐨刲ist
-        List mysheet = Collections.synchronizedList(sheet);
+
+        // 浣跨敤绾跨▼瀹夊叏鐨凩ist锛岄鍏堟寚瀹氬閲�
+        List<ExcelExp> mysheet = Collections.synchronizedList(new ArrayList<>());
         VideoExportForm.convertTags(exportForm);
-        Query query = getQuery(exportForm);
-        //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+        Query query = getQuery(exportForm);//瑁呴厤鏉′欢
+        // 鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+
         List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
-        log.error("鏈堜唤鍦ㄧ嚎鏁版嵁:{}鏉℃暟",onlineResult.size());
-        // 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
+        log.info("澶у皬:{}",onlineResult.size());
+        //姝ゅ闇�瑕佽繃婊ゆ帀璁惧鍏ㄦ櫙鍦ㄧ嚎 缁嗚妭涓嶅湪绾跨殑鎯呭喌  鍙互鎸� point鍒嗙粍 鍒嗘垜璁稿缁勪箣鍚庡啀鍋氬鐞�
+        Map<String, List<TMonitorResult>> ipToDevices = onlineResult.stream()
+                .collect(Collectors.groupingBy(TMonitorResult::getIp));
+
+//        onlineResult = ipToDevices.values().stream()
+//                .map(devices -> {
+//                    // 妫�鏌ュ垎缁勪腑鏄惁鏈� online = true 鐨勮澶�
+//                    List<TMonitorResult> onlineDevices = devices.stream()
+//                            .filter(monitor -> monitor.getOnline() == 1) // 鍋囪online瀛楁鐨刧etter鏄痠sOnline()
+//                            .collect(Collectors.toList());
+//
+//                    if (!onlineDevices.isEmpty()) {
+//                        // 鑻ュ瓨鍦╫nline=true鐨勮澶囷紝鍙繚鐣欑涓�涓紙鎴栧彇浠绘剰涓�涓紝鎸夐渶璋冩暣锛�
+//                        return onlineDevices.get(0);
+//                    } else {
+//                        // 鑻ュ叏涓簅nline=false锛屽彧淇濈暀绗竴涓�
+//                        return devices.get(0);
+//                    }
+//                })
+//                .collect(Collectors.toList());
+
+
+
+        log.info("鏈堜唤鍦ㄧ嚎鏁版嵁:{}鏉℃暟", onlineResult.size());
+        // 浣跨敤Collectors.toMap鍘婚噸锛屼繚鐣欐瘡涓狽o鐨勭涓�涓亣鍒扮殑鍏冪礌
         Map<String, TMonitorResult> uniqueResultsMap = onlineResult.stream()
                 .collect(Collectors.toMap(
                         TMonitorResult::getNo, // keyMapper锛岃繖閲屽亣璁� getNo() 杩斿洖 No 瀛楁
                         Function.identity(),  // valueMapper锛岀洿鎺ヤ娇鐢ㄥ璞℃湰韬�
                         (existing, replacement) -> existing // mergeFunction锛屽鏋滄湁閲嶅锛屼繚鐣欑涓�涓�
                 ));
+
+
         // 灏� Map 杞崲涓� List
         List<TMonitorResult> tMonitorResults = new ArrayList<>(uniqueResultsMap.values());
-        log.error("鍘婚噸鍚庡ぇ灏�:{}",tMonitorResults.size());
-        //鑾峰彇鍔ㄦ�佸垪鏁版嵁
-        List<Integer> pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList());
-        List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
-        //琛ュ厖鍔ㄦ�佸垪鏁版嵁
-        if (!CollectionUtils.isEmpty(dynamics)) {
-            Map<Integer, List<DynamicColumnVO>> map = dynamics.stream().collect(Collectors.groupingBy(DynamicColumnVO::getRefId));
-            for (TMonitorResult tMonitorResult : tMonitorResults) {
-                Integer pointId = tMonitorResult.getPointId();
-                tMonitorResult.setDynamicColumnList(map.get(pointId));
+        log.info("鍘婚噸鍚庡ぇ灏�:{}", tMonitorResults.size());
+
+
+
+        // 鑾峰彇鍔ㄦ�佸垪鏁版嵁骞舵瀯寤虹紦瀛楳ap
+        Map<Integer, List<DynamicColumnVO>> dynamicColumnMap = new HashMap<>();
+        if (!tMonitorResults.isEmpty()) {
+            //鑾峰彇鐐逛綅闆嗗悎
+            List<Integer> pointIds = tMonitorResults.stream()
+                    .map(TMonitorResult::getPointId)
+                    .distinct() // 鍘婚噸锛屽噺灏戞暟鎹簱鏌ヨ
+                    .collect(Collectors.toList());
+
+
+            //鑾峰彇闆嗗悎鐐逛綅鐨勮ˉ鍏呭垪淇℃伅
+            List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
+            if (!CollectionUtils.isEmpty(dynamics)) {
+                dynamicColumnMap = dynamics.stream()
+                        .collect(Collectors.groupingBy(DynamicColumnVO::getRefId));
+            }
+
+            // 琛ュ厖鍔ㄦ�佸垪鏁版嵁
+            for (TMonitorResult result : tMonitorResults) {
+                result.setDynamicColumnList(dynamicColumnMap.getOrDefault(result.getPointId(), Collections.emptyList()));
             }
         }
-        //瀛樻斁鍖哄煙 涓� 璁惧鍒楄〃 map key涓� 鍖哄煙
-        Map<Integer, List<VideoDailyExp>> map = new HashMap<>();
-        List<CompletableFuture<List<VideoDailyExp>>> futures = new ArrayList<>();
+
+        // 鎸夐儴闂ㄥ垎缁勶紝鍑忓皯鍚庣画寰幆涓殑杩囨护鎿嶄綔
+        Map<Integer, List<TMonitorResult>> deptMonitorMap = tMonitorResults.stream()
+                .collect(Collectors.groupingBy(TMonitorResult::getDeptId));
+
+        // 鎸夎澶囩紪鍙峰垎缁刼nlineResult锛屽姞閫熷悗缁煡鎵�
+        Map<String, List<TMonitorResult>> noToOnlineMap = onlineResult.stream()
+                .collect(Collectors.groupingBy(TMonitorResult::getNo));
+
+        // 骞惰澶勭悊鍚勯儴闂ㄦ暟鎹�
+        List<CompletableFuture<ExcelExp>> futures = new ArrayList<>(exportForm.getDeptIds().size());
+        Map<Integer, List<VideoDailyExp>> deptExpMap = new ConcurrentHashMap<>();
+
         for (Integer deptId : exportForm.getDeptIds()) {
-            CompletableFuture<List<VideoDailyExp>> future = CompletableFuture.supplyAsync(() -> {
-                List<VideoDailyExp> videoDailyExps = new ArrayList<>();
-                //绛涢�夐儴闂ㄦ暟鎹�
-                List<TMonitorResult> monitors = tMonitorResults.stream()
-                        .filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId()))
-                        .collect(Collectors.toList());
-                if (CollectionUtils.isEmpty(monitors)) return videoDailyExps;
+            // 浣跨敤閮ㄩ棬ID鐨勬渶缁堝彉閲�
+            final Integer currentDeptId = deptId;
+            CompletableFuture<ExcelExp> future = CompletableFuture.supplyAsync(() -> {
+                // 鐩存帴浠庨鍒嗙粍鐨凪ap涓幏鍙栵紝閬垮厤姣忔杩囨护
+                List<TMonitorResult> monitors = deptMonitorMap.getOrDefault(currentDeptId, Collections.emptyList());
 
-                List<String> ids = monitors.stream()
-                        .map(BaseResult::getNo)
-                        .collect(Collectors.toList());
-                //绛涢�塵ongo鍖哄幙鏁版嵁
-                List<TMonitorResult> onlines = onlineResult.stream()
-                        .filter(result -> ids.contains(result.getNo()))
-                        .collect(Collectors.toList());
 
-                AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
+
+                if (monitors.isEmpty()) {
+                    return null;
+                }
+
+                List<VideoDailyExp> videoDailyExps = new ArrayList<>(monitors.size());
+                AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(currentDeptId);
+                String areaName = areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName();
+
                 for (TMonitorResult result : monitors) {
                     VideoDailyExp videoDailyExp = new VideoDailyExp();
                     videoDailyExp.setSerialNumber(result.getNo());
                     videoDailyExp.setDeviceName(result.getName());
                     videoDailyExp.setType(result.getMonitorType());
+                    videoDailyExp.setArea(areaName);
 
-                    videoDailyExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
+                    // 鏋勫缓鏍囩瀛楃涓�
+                    StringBuilder tag = new StringBuilder();
+                    if (result.getProvinceTag()) tag.append("鐪佸巺銆�");
+                    if (result.getImportantTag()) tag.append("閲嶇偣鐐逛綅銆�");
+                    if (result.getImportantCommandImageTag()) tag.append("閲嶇偣鎸囨尌鍥惧儚銆�");
+                    if (result.getDeptTag()) tag.append("閮ㄧ骇銆�");
 
-                    StringBuilder tag = new StringBuilder("" +
-                            (result.getProvinceTag() ? "鐪佸巺銆�" : "") +
-                            (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") +
-                            (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") +
-                            (result.getDeptTag() ? "閮ㄧ骇銆�" : ""));
-
-                    //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
-                    if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) {
-                        for (DynamicColumnVO dynamicColumnVO : result.getDynamicColumnList()) {
+                    // 澶勭悊鍔ㄦ�佸垪
+                    List<DynamicColumnVO> dynamicColumns = result.getDynamicColumnList();
+                    if (!dynamicColumns.isEmpty()) {
+                        for (DynamicColumnVO dynamicColumnVO : dynamicColumns) {
                             tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
                         }
                     }
-                    // 鍒犻櫎瀛楃涓叉湯灏剧殑"銆�"
-                    if (tag.toString().endsWith("銆�")) {
-                        tag = new StringBuilder(tag.substring(0, tag.length() - 1));
+
+                    // 绉婚櫎鏈熬鐨�"銆�"
+                    if (tag.length() > 0) {
+                        tag.setLength(tag.length() - 1);
                     }
                     videoDailyExp.setTag(tag.toString());
 
+                    // 璁剧疆鍦ㄧ嚎鏁版嵁
                     try {
+                        // 浠庨鏋勫缓鐨凪ap涓幏鍙栵紝閬垮厤姣忔杩囨护
+                        List<TMonitorResult> onlines = noToOnlineMap.getOrDefault(result.getNo(), Collections.emptyList());
                         setOnlineDaily(videoDailyExp, result, onlines);
                     } catch (Exception e) {
-                        log.error(e.getMessage());
+                        log.error("璁剧疆鍦ㄧ嚎鏁版嵁寮傚父", e);
                     }
+
                     videoDailyExps.add(videoDailyExp);
                 }
 
-                ExcelExp excelExp = new ExcelExp(
-                        areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(),
-                        videoDailyExps,
-                        VideoDailyExp.class
-                );
-                mysheet.add(excelExp);
+                // 瀛樺偍缁撴灉鍒扮嚎绋嬪畨鍏ㄧ殑Map
+                deptExpMap.put(currentDeptId, videoDailyExps);
 
-
-                return videoDailyExps;
+                return new ExcelExp(areaName, videoDailyExps, VideoDailyExp.class);
             }, threadPoolTaskExecutor);
+
             futures.add(future);
-            map.put(deptId,future.join());
         }
-        // 鑾峰彇鍏ㄩ噺鏁版嵁
-        List<VideoDailyExp> totalExps = futures.stream()
-                .map(CompletableFuture::join)
+
+        // 绛夊緟鎵�鏈夊苟琛屼换鍔″畬鎴�
+        CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
+
+        // 鏀堕泦鎵�鏈夐儴闂ㄧ殑ExcelExp缁撴灉
+        for (CompletableFuture<ExcelExp> future : futures) {
+            ExcelExp excelExp = future.join();
+            if (excelExp != null) {
+                mysheet.add(excelExp);
+            }
+        }
+
+        // 鑾峰彇鍏ㄩ噺鏁版嵁骞舵坊鍔�"鍏ㄩ噺"sheet
+        List<VideoDailyExp> totalExps = deptExpMap.values().stream()
                 .flatMap(List::stream)
                 .collect(Collectors.toList());
-        log.error("鎵撳嵃鍏ㄩ噺鏁版嵁:{}",totalExps);
-        ExcelExp excelExp = new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class);
-        mysheet.add(excelExp);
-        //娣诲姞鏂扮殑sheet 绂荤嚎鏁扮粺璁¤〃
-        List<VideoTypeOffOnlineExp> videoTypeOffOnlineExps = new ArrayList<>();
-        //鎻掑叆excel鏃剁‘淇濇暟鎹嚭鐜板湪鏈�鍚�
-        List<VideoTypeOffOnlineExp> allVideoTypeOffOnlineExps = new ArrayList<>();
 
-        //鍦ㄧ嚎鐜囩粺璁¤〃
-        List<VideoOnlineRateExp> videoOnlineRateExps = new ArrayList<>();
-        //鎻掑叆excel鏃剁‘淇濇暟鎹嚭鐜板湪鏈�鍚�
-        List<VideoOnlineRateExp> allVideoOnlineRateExps = new ArrayList<>();
+        mysheet.add(new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class));
 
-        for (Integer deptId : map.keySet()){
-            List<VideoDailyExp>  list = map.get(deptId);
-            AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
-            // 娣诲姞绂荤嚎琛ㄨ褰�
-            //璁惧绫诲瀷 1浜鸿劯 2杞﹁締 3瑙嗛
-            //浜鸿劯
-            log.error("浼犲叆閮ㄩ棬闆嗗悎澶у皬:{} + 閮ㄩ棬id:{}" ,list.size(),deptId);
-            VideoTypeOffOnlineExp faceVideoTypeOffOnlineExp = this.getListOfflineCountInfo(list,"1",areaDeptEnum,false);
-            //鍗″彛
-            VideoTypeOffOnlineExp carVideoTypeOffOnlineExp =this.getListOfflineCountInfo(list,"2",areaDeptEnum,false);
-            //瑙嗛
-            VideoTypeOffOnlineExp videoTypeOffOnlineExp = this.getListOfflineCountInfo(list,"3",areaDeptEnum,false);
-
-            VideoOnlineRateExp faceVideoOnlineRateExp = this.getListOnLineCountInfo(list,"1",areaDeptEnum,false);
-            //鍗″彛
-            VideoOnlineRateExp carVideoOnlineRateExp =this.getListOnLineCountInfo(list,"2",areaDeptEnum,false);
-            //瑙嗛
-            VideoOnlineRateExp VideoOnlineRateExp = this.getListOnLineCountInfo(list,"3",areaDeptEnum,false);
-
-
-            //灏嗚鍖哄煙绫讳笁绉嶈澶囩被鍨嬬殑 淇℃伅 鏀惧叆 excel瀵硅薄鍐�
-            //鏀惧叆褰撳墠鍖哄煙鐨勪汉鑴歌澶囩浉鍏宠缁�
-            videoTypeOffOnlineExps.add(faceVideoTypeOffOnlineExp);
-            //鏀惧叆褰撳墠鍖哄煙鐨勮溅杈嗚澶囩浉鍏宠缁�
-            videoTypeOffOnlineExps.add(carVideoTypeOffOnlineExp);
-            //鏀惧叆褰撳墠鍖哄煙鐨勮棰戣澶囩浉鍏宠缁�
-            videoTypeOffOnlineExps.add(videoTypeOffOnlineExp);
-
-            videoOnlineRateExps.add(faceVideoOnlineRateExp);
-            videoOnlineRateExps.add(carVideoOnlineRateExp);
-            videoOnlineRateExps.add(VideoOnlineRateExp);
-
-
-            VideoTypeOffOnlineExp ALLfaceVideoTypeOffOnlineExp = this.getListOfflineCountInfo(list,"1",areaDeptEnum,true);
-            //鍗″彛
-            VideoTypeOffOnlineExp ALLcarVideoTypeOffOnlineExp =this.getListOfflineCountInfo(list,"2",areaDeptEnum,true);
-            //瑙嗛
-            VideoTypeOffOnlineExp ALLvideoTypeOffOnlineExp = this.getListOfflineCountInfo(list,"3",areaDeptEnum,true);
-
-            VideoOnlineRateExp ALLfaceVideoOnlineRateExp = this.getListOnLineCountInfo(list,"1",areaDeptEnum,true);
-            //鍗″彛
-            VideoOnlineRateExp ALLcarVideoOnlineRateExp =this.getListOnLineCountInfo(list,"2",areaDeptEnum,true);
-            //瑙嗛
-            VideoOnlineRateExp ALLVideoOnlineRateExp = this.getListOnLineCountInfo(list,"3",areaDeptEnum,true);
-
-            //娣诲姞鍚堣鏁版嵁
-            allVideoTypeOffOnlineExps.add(ALLfaceVideoTypeOffOnlineExp);
-            //鏀惧叆褰撳墠鍖哄煙鐨勮溅杈嗚澶囩浉鍏宠缁�
-            allVideoTypeOffOnlineExps.add(ALLcarVideoTypeOffOnlineExp);
-            //鏀惧叆褰撳墠鍖哄煙鐨勮棰戣澶囩浉鍏宠缁�
-            allVideoTypeOffOnlineExps.add(ALLvideoTypeOffOnlineExp);
-
-            allVideoOnlineRateExps.add(ALLfaceVideoOnlineRateExp);
-            allVideoOnlineRateExps.add(ALLcarVideoOnlineRateExp);
-            allVideoOnlineRateExps.add(ALLVideoOnlineRateExp);
-
+        // 缁熻鍚勭被鍨嬭澶囨暟閲�
+        long face = 0, car = 0, video = 0;
+        for (VideoDailyExp exp : totalExps) {
+            String type = exp.getType();
+            if (type.contains("1")) face++;
+            if (type.contains("2")) car++;
+            if (type.contains("3")) video++;
         }
-        videoTypeOffOnlineExps.addAll(allVideoTypeOffOnlineExps);
-        videoOnlineRateExps.addAll(allVideoOnlineRateExps);
-        log.error("鎵撳嵃璁$畻绂荤嚎鐨勪俊鎭�:{}" ,videoTypeOffOnlineExps );
-        log.error("鎵撳嵃璁″湪绾跨殑淇℃伅:{}" ,videoOnlineRateExps );
-        //娣诲姞鍚堣鏁版嵁
 
-        ExcelExp excelTypeOffLineExp = new ExcelExp("绂荤嚎鏁扮粺璁�", videoTypeOffOnlineExps, VideoTypeOffOnlineExp.class);
-        mysheet.add(excelTypeOffLineExp);
+        log.info("浜鸿劯鏁�:{}", face);
+        log.info("car鏁�:{}", car);
+        log.info("video鏁�:{}", video);
 
-        //娣诲姞鍦ㄧ嚎鐜囪〃
-        ExcelExp excelOnlineRateExp = new ExcelExp("鍦ㄧ嚎鐜囩粺璁�",videoOnlineRateExps, VideoOnlineRateExp.class);
-        mysheet.add(excelOnlineRateExp);
+        // 澶勭悊绂荤嚎鏁扮粺璁″拰鍦ㄧ嚎鐜囩粺璁�
+        List<VideoTypeOffOnlineExp> videoTypeOffOnlineExps = new ArrayList<>();
+        List<VideoOnlineRateExp> videoOnlineRateExps = new ArrayList<>();
 
+        for (Map.Entry<Integer, List<VideoDailyExp>> entry : deptExpMap.entrySet()) {
+            Integer deptId = entry.getKey();
+            List<VideoDailyExp> list = entry.getValue();
+            AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
+
+            // 鎵归噺澶勭悊涓夌璁惧绫诲瀷
+            addDeviceStats(list, areaDeptEnum, "1", "浜鸿劯", videoTypeOffOnlineExps, videoOnlineRateExps);
+            addDeviceStats(list, areaDeptEnum, "2", "鍗″彛", videoTypeOffOnlineExps, videoOnlineRateExps);
+            addDeviceStats(list, areaDeptEnum, "3", "瑙嗛", videoTypeOffOnlineExps, videoOnlineRateExps);
+        }
+
+        // 璁$畻鍚堣鏁版嵁
+        addTotalStats(videoTypeOffOnlineExps, videoOnlineRateExps, face, car, video);
+
+        // 娣诲姞缁熻sheet
+        mysheet.add(new ExcelExp("绂荤嚎鏁扮粺璁�", videoTypeOffOnlineExps, VideoTypeOffOnlineExp.class));
+        mysheet.add(new ExcelExp("鍦ㄧ嚎鐜囩粺璁�", videoOnlineRateExps, VideoOnlineRateExp.class));
+
+        // 瀵煎嚭Excel
         ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
         util.exportExcelManySheet(response, mysheet);
-        log.error("瀵煎嚭缁撴潫");
+        log.info("瀵煎嚭缁撴潫");
     }
+
+    // 鏂板杈呭姪鏂规硶锛氭壒閲忔坊鍔犺澶囩粺璁′俊鎭�
+    private void addDeviceStats(List<VideoDailyExp> list, AreaDeptEnum areaDeptEnum,
+                                String typeCode, String typeName,
+                                List<VideoTypeOffOnlineExp> offLineList,
+                                List<VideoOnlineRateExp> onlineList) {
+        offLineList.add(getListOfflineCountInfo(list, typeCode, areaDeptEnum));
+        onlineList.add(getListOnLineCountInfo(list, typeCode, areaDeptEnum));
+    }
+
+    // 鏂板杈呭姪鏂规硶锛氭坊鍔犲悎璁$粺璁�
+    private void addTotalStats(List<VideoTypeOffOnlineExp> offLineList,
+                               List<VideoOnlineRateExp> onlineList,
+                               long face, long car, long video) throws NoSuchFieldException, IllegalAccessException {
+        // 绂荤嚎缁熻鍚堣
+        VideoTypeOffOnlineExp allFaceVideosOffline = new VideoTypeOffOnlineExp();
+        setAllVideoTypeOffOnlineExpCount(offLineList, allFaceVideosOffline, "浜鸿劯");
+
+        VideoTypeOffOnlineExp allCarVideosOffline = new VideoTypeOffOnlineExp();
+        setAllVideoTypeOffOnlineExpCount(offLineList, allCarVideosOffline, "鍗″彛");
+
+        VideoTypeOffOnlineExp allVideosOffline = new VideoTypeOffOnlineExp();
+        setAllVideoTypeOffOnlineExpCount(offLineList, allVideosOffline, "瑙嗛");
+
+        offLineList.add(allFaceVideosOffline);
+        offLineList.add(allCarVideosOffline);
+        offLineList.add(allVideosOffline);
+
+        // 鍦ㄧ嚎缁熻鍚堣
+        VideoOnlineRateExp allFaceVideosOnline = new VideoOnlineRateExp();
+        setAllVideoTypeOnlineExpCount(face, onlineList, allFaceVideosOnline, "浜鸿劯");
+
+        VideoOnlineRateExp allCarVideosOnline = new VideoOnlineRateExp();
+        setAllVideoTypeOnlineExpCount(car, onlineList, allCarVideosOnline, "鍗″彛");
+
+        VideoOnlineRateExp allVideosOnline = new VideoOnlineRateExp();
+        setAllVideoTypeOnlineExpCount(video, onlineList, allVideosOnline, "瑙嗛");
+
+        onlineList.add(allFaceVideosOnline);
+        onlineList.add(allCarVideosOnline);
+        onlineList.add(allVideosOnline);
+    }
+
+
+
+    //绂荤嚎璁惧鏁版嵁锛屽悎璁″璞★紝淇℃伅瑁呴厤
+    public void setAllVideoTypeOffOnlineExpCount(List<VideoTypeOffOnlineExp> videoTypeOffOnlineExps,
+                                                                  VideoTypeOffOnlineExp videoTypeOffOnlineExp,
+                                                                  String type) throws NoSuchFieldException, IllegalAccessException {
+        List<VideoTypeOffOnlineExp> filterExps = videoTypeOffOnlineExps.stream().filter(exp -> type.equals(exp.getType())).collect(Collectors.toList());
+        long allCount = 0;
+        for (VideoTypeOffOnlineExp obj :filterExps){
+            //obj 瀵硅薄浠h〃浜嗚鍖� 绛涢�変簡鐨勬寚瀹歵ype鐨勮澶囩殑瀵硅薄
+            //璁$畻鎬荤殑璁惧绂荤嚎鎬绘暟
+            long count  = Long.parseLong(obj.getOfflineCount());
+            allCount += count;
+            //璁$畻姣忔棩
+            for (int i =1 ;i <= 31; i++){
+                String fieldName = "day" + i;
+                Field dayField = obj.getClass().getDeclaredField(fieldName);
+                dayField.setAccessible(true);
+                Object value = dayField.get(obj); //鑾峰彇瀛楁鍊�
+                if (value != null) {
+                    long newFieldValue = Long.parseLong(value.toString());
+                    //鑾峰彇闇�瑕佸~鍏呯殑瀛楁
+                    Field videoTypeOffOnlineExpField = videoTypeOffOnlineExp.getClass().getDeclaredField(fieldName);
+                    videoTypeOffOnlineExpField.setAccessible(true);
+                    //鍏堣幏鍙栦竴娆�
+                    Object oldValue = videoTypeOffOnlineExpField.get(videoTypeOffOnlineExp);
+
+                    //涓簄ull 绗竴娆$洿鎺ヨ璧嬪��
+                    if (oldValue == null){
+                        videoTypeOffOnlineExpField.set(videoTypeOffOnlineExp,newFieldValue + "");
+                    }else {
+                        //瀛樺湪鏃у�� 鐩稿姞瑕嗙洊
+                        videoTypeOffOnlineExpField.set(videoTypeOffOnlineExp, (Long.parseLong(oldValue.toString()) + newFieldValue) + "");
+                    }
+                }
+
+
+
+            }
+
+        }
+        videoTypeOffOnlineExp.setOfflineCount(String.valueOf(allCount));
+        videoTypeOffOnlineExp.setArea("鑷础甯�");
+        videoTypeOffOnlineExp.setType(type + "鍚堣");
+    }
+    //鍦ㄧ嚎璁惧鏁版嵁锛屽悎璁″璞★紝淇℃伅瑁呴厤
+    public void setAllVideoTypeOnlineExpCount(
+            long allVideoCount,List<VideoOnlineRateExp> videoOnlineRateExps,
+                                              VideoOnlineRateExp videoOnlineRateExp,
+                                              String type) throws NoSuchFieldException, IllegalAccessException{
+        List<VideoOnlineRateExp> filterExps = videoOnlineRateExps.stream().filter(item -> type.equals(item.getType())).collect(Collectors.toList());
+
+        for (VideoOnlineRateExp obj :filterExps){
+            for (int i = 1;i <= 31; i++){
+                String countFileName = "count" +i;
+                Field countField = obj.getClass().getDeclaredField(countFileName);
+                countField.setAccessible(true);
+                long newFieldValue = countField.getLong(obj);
+                Field videoOnlineRateExpField = obj.getClass().getDeclaredField(countFileName);
+                videoOnlineRateExpField.setAccessible(true);
+                Object oldValue = videoOnlineRateExpField.get(videoOnlineRateExp);
+                if (oldValue == null){
+                    videoOnlineRateExpField.setLong(videoOnlineRateExp,newFieldValue);
+                }else {
+                    //瀛樺湪鏃у�� 鐩稿姞瑕嗙洊
+                    videoOnlineRateExpField.setLong(videoOnlineRateExp, Long.parseLong(oldValue.toString()) + newFieldValue);
+                }
+            }
+        }
+        //璁$畻瀹屾瘡鏃ュ湪绾胯澶囨暟
+        //寰幆涓�涓湀
+        for (int i = 1;i <= 31 ;i++){
+            //鍦ㄧ嚎鐜囪绠�
+            String countFileName = "count" +i;
+            Field countField = videoOnlineRateExp.getClass().getDeclaredField(countFileName);
+            countField.setAccessible(true);
+            long newFieldValue = countField.getLong(videoOnlineRateExp);
+            String fieldName = "day" + i;
+            //姣忔棩鍦ㄧ嚎鐜�
+            double rate = (double) newFieldValue / allVideoCount;
+            //鍙嶅皠娣诲姞鍒板璞″睘鎬т腑
+            Field field = videoOnlineRateExp.getClass().getDeclaredField(fieldName);
+            //璁剧疆姣忔棩鍦ㄧ嚎璁惧璁惧鏁�
+            field.setAccessible(true);
+            String rateStr = String.format("%.2f", rate * 100) +"%";
+            if (!"0.00%".equals(rateStr)){
+                field.set(videoOnlineRateExp, rateStr);
+            }
+
+        }
+
+
+        videoOnlineRateExp.setArea("鑷础甯�");
+        videoOnlineRateExp.setType(type + "鍚堣");
+    }
+
+
+
+
 
     /**
      * 璁$畻绂荤嚎璁惧excel瀵硅薄淇℃伅
@@ -771,8 +960,8 @@
      */
     public VideoTypeOffOnlineExp getListOfflineCountInfo(List<VideoDailyExp> videoDailyExps,
                                                          String type,
-                                                         AreaDeptEnum areaDeptEnum,
-                                                         boolean isTotal){
+                                                         AreaDeptEnum areaDeptEnum
+                                                        ){
         VideoTypeOffOnlineExp videoTypeOffOnlineExp = new VideoTypeOffOnlineExp();
 
         List<VideoDailyExp> list = videoDailyExps.stream()
@@ -781,45 +970,36 @@
         //绂荤嚎鏁伴噺
         try {
             //璁剧疆绂荤嚎鏁伴噺 浠ュ強姣忔棩绂荤嚎鏁伴噺
-            setVideoTypeOffOnlineExpCountAndDays(list,videoTypeOffOnlineExp,isTotal);
+            setVideoTypeOffOnlineExpCountAndDays(list,videoTypeOffOnlineExp);
         } catch (Exception e) {
             log.error(e.getMessage());
         }
         //璁惧绫诲瀷
-        if(isTotal){
-            if ("1".equals(type)){
-                videoTypeOffOnlineExp.setType("浜鸿劯鍚堣");
-            }else if ("2".equals(type)){
-                videoTypeOffOnlineExp.setType("鍗″彛鍚堣");
-            }else if ("3".equals(type)){
-                videoTypeOffOnlineExp.setType("瑙嗛鍚堣");
-            }
-        }else {
-            if ("1".equals(type)){
-                videoTypeOffOnlineExp.setType("浜鸿劯");
-            }else if ("2".equals(type)){
-                videoTypeOffOnlineExp.setType("鍗″彛");
-            }else if ("3".equals(type)){
-                videoTypeOffOnlineExp.setType("瑙嗛");
-            }
+        if ("1".equals(type)){
+            videoTypeOffOnlineExp.setType("浜鸿劯");
+        }else if ("2".equals(type)){
+            videoTypeOffOnlineExp.setType("鍗″彛");
         }
+        else if ("3".equals(type)){
+            videoTypeOffOnlineExp.setType("瑙嗛");
+        }
+
         //淇敼鍖哄煙
         videoTypeOffOnlineExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
         return videoTypeOffOnlineExp;
     }
 
-    private void setVideoTypeOffOnlineExpCountAndDays(List<VideoDailyExp> videoDailyExps,VideoTypeOffOnlineExp videoTypeOffOnlineExp,boolean isTotal)throws NoSuchFieldException, IllegalAccessException {
+    private void setVideoTypeOffOnlineExpCountAndDays(List<VideoDailyExp> videoDailyExps,VideoTypeOffOnlineExp videoTypeOffOnlineExp)throws NoSuchFieldException, IllegalAccessException {
         //寰幆涓�涓湀
         //绂荤嚎鎬绘暟
         long AllOffLineCount = 0;
-        log.error("浼犲叆闆嗗悎澶у皬:{}", videoDailyExps.size());
         for (VideoDailyExp videoDailyExp : videoDailyExps) {
             if (videoDailyExp.isAllOfflineByMonth()) {
                 AllOffLineCount++;
             }
         }
         //鏄悎璁℃暟鎹笉闇�瑕佷笅鏂规暟鎹�
-//        if (!isTotal) {
+
             for (int i = 1; i <= 31; i++) {
                 //姣忔棩绂荤嚎鏁�
                 long count = 0;
@@ -857,8 +1037,8 @@
      */
     public VideoOnlineRateExp getListOnLineCountInfo(List<VideoDailyExp> videoDailyExps,
                                                          String type,
-                                                         AreaDeptEnum areaDeptEnum,
-                                                         boolean isTotal){
+                                                         AreaDeptEnum areaDeptEnum
+                                                         ){
         VideoOnlineRateExp videoOnlineRateExp = new VideoOnlineRateExp();
 
         List<VideoDailyExp> list = videoDailyExps.stream()
@@ -866,28 +1046,17 @@
         log.error("绛涢�夊畬璁惧绫诲瀷 锛歿} 鍚庨泦鍚堢殑澶у皬锛歿}",type,list.size());
         //绂荤嚎鏁伴噺
         try {
-            //璁剧疆绂荤嚎鏁伴噺 浠ュ強姣忔棩绂荤嚎鏁伴噺
-            setVideoOnlineRateExpCountAndDays(list,videoOnlineRateExp,isTotal);
+            setVideoOnlineRateExpCountAndDays(list,videoOnlineRateExp);
         } catch (Exception e) {
             log.error(e.getMessage());
         }
         //璁惧绫诲瀷
-        if(isTotal) {
-            if ("1".equals(type)) {
-                videoOnlineRateExp.setType("浜鸿劯鍚堣");
-            } else if ("2".equals(type)) {
-                videoOnlineRateExp.setType("鍗″彛鍚堣");
-            } else if ("3".equals(type)) {
-                videoOnlineRateExp.setType("瑙嗛鍚堣");
-            }
-        }else {
-            if ("1".equals(type)) {
-                videoOnlineRateExp.setType("浜鸿劯");
-            } else if ("2".equals(type)) {
-                videoOnlineRateExp.setType("鍗″彛");
-            } else if ("3".equals(type)) {
-                videoOnlineRateExp.setType("瑙嗛");
-            }
+        if ("1".equals(type)) {
+             videoOnlineRateExp.setType("浜鸿劯");
+        } else if ("2".equals(type)) {
+            videoOnlineRateExp.setType("鍗″彛");
+        } else if ("3".equals(type)) {
+            videoOnlineRateExp.setType("瑙嗛");
         }
         //淇敼鍖哄煙
         videoOnlineRateExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
@@ -895,13 +1064,13 @@
     }
 
 
-    private void setVideoOnlineRateExpCountAndDays(List<VideoDailyExp> videoDailyExps,VideoOnlineRateExp videoOnlineRateExp,boolean isTotal)throws NoSuchFieldException, IllegalAccessException {
-
+    private void setVideoOnlineRateExpCountAndDays(List<VideoDailyExp> videoDailyExps,VideoOnlineRateExp videoOnlineRateExp)throws NoSuchFieldException, IllegalAccessException {
         //寰幆涓�涓湀
         for (int i = 1;i <= 31 ;i++){
             //鍦ㄧ嚎鐜囪绠�
             long count = 0;
             String fieldName = "day" + i;
+            String countName = "count" + i;
             for(VideoDailyExp videoDailyExp: videoDailyExps){
                 // 鏋勯�犲瓧娈靛悕
                 Field field = videoDailyExp.getClass().getDeclaredField(fieldName);
@@ -917,6 +1086,10 @@
             double rate = (double) count / videoDailyExps.size();
             //鍙嶅皠娣诲姞鍒板璞″睘鎬т腑
             Field field = videoOnlineRateExp.getClass().getDeclaredField(fieldName);
+            Field countField = videoOnlineRateExp.getClass().getDeclaredField(countName);
+            countField.setAccessible(true);
+            //璁剧疆姣忔棩鍦ㄧ嚎璁惧璁惧鏁�
+            countField.setLong(videoOnlineRateExp, count);
             field.setAccessible(true);
             String rateStr = String.format("%.2f", rate * 100) +"%";
             if (!"0.00%".equals(rateStr)){
@@ -1065,6 +1238,8 @@
             exportForm.setDeptIds(deptIds);
         }
         Query query = getQuery(exportForm);
+
+
         //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
         List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
         // 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
@@ -1174,6 +1349,7 @@
     @Override
     public Map<String, Object> videoHome(HomeQuery monitorQuery) throws ParseException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
         List<HomeVideoVO> results = new ArrayList<>();
+
         String month = monitorQuery.getDate();
         if (StringUtils.isEmpty(month)) {
             //濡傛灉涓虹┖鏌ユ湰鏈堢殑鏁版嵁
@@ -1200,13 +1376,30 @@
         MongoDatabase database = mongoTemplate.getDb();
         MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum");
         Integer examineTag = monitorQuery.getExamineTag();
+        String arealayerno = monitorQuery.getArea();
         Document matchConditions = new Document("statTime", new Document("$gte", startDate).append("$lte", endDate));
         // 鏍规嵁examineTag鐨勫�煎姩鎬佹坊鍔犻澶栫殑鏉′欢
         if (examineTag != null && examineTag.equals(1)) {
             matchConditions.append("provinceTag", true);
         } else if (examineTag != null && examineTag.equals(2)) {
             matchConditions.append("deptTag", true);
+        } else if(StringUtils.isNotBlank(arealayerno)){
+            matchConditions.append("arealayerno",
+                    new Document("$regex", "^" + arealayerno));
         }
+        Document noExpr = new Document("$and", Arrays.asList(
+                new Document("$gte", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
+                new Document("$ne", Arrays.asList(
+                        new Document("$substrCP", Arrays.asList(
+                                "$no",
+                                new Document("$subtract", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
+                                1
+                        )),
+                        "3"
+                ))
+        ));
+// 姝g‘娣诲姞$expr鏉′欢锛堥敭涓�"$expr"锛屽�间负涓婇潰瀹氫箟鐨勬潯浠讹級
+        matchConditions.append("$expr", noExpr);
         // 鏋勫缓鑱氬悎绠¢亾
         List<Document> pipeline = Arrays.asList(
                 new Document("$match", matchConditions),
@@ -1242,6 +1435,7 @@
             homeVideoVO.setIntegrityNum(doc.getInteger("normalCount"));
             homeVideoVO.setLoseNum(doc.getInteger("loseCount"));
             homeVideoVO.setErrNum(doc.getInteger("errCount"));
+
             results.add(homeVideoVO);
         }
 
@@ -1255,8 +1449,24 @@
             onlineMatch.add(new Document("provinceTag", true));
         } else if (examineTag != null && examineTag.equals(2)) {
             onlineMatch.add(new Document("deptTag", true));
-        }
+        } else if(StringUtils.isNotBlank(arealayerno)){
+            Document noStartsWith = new Document("no", new Document("$regex", "^" + arealayerno));
 
+            // 鏋勫缓鍊掓暟绗笁浣嶄笉鏄�3鐨勬潯浠�
+            Document noThirdLastNot3 = new Document("$expr", new Document("$and", Arrays.asList(
+                    new Document("$gte", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
+                    new Document("$ne", Arrays.asList(
+                            new Document("$substrCP", Arrays.asList(
+                                    "$no",
+                                    new Document("$subtract", Arrays.asList(new Document("$strLenCP", "$no"), 3)),
+                                    1
+                            )),
+                            "3"
+                    ))
+            )));
+            // 灏嗕袱涓潯浠剁敤$and缁勫悎鍚庢坊鍔犲埌鏉′欢鍒楄〃
+            onlineMatch.add(new Document("$and", Arrays.asList(noStartsWith, noThirdLastNot3)));
+        }
         // 鏋勫缓鑱氬悎绠¢亾
         List<Document> onlinePipeline = Arrays.asList(
                 new Document("$match", new Document("$and", onlineMatch)),
@@ -1270,6 +1480,10 @@
                         ))
                 )
         );
+        //鎺掗櫎鍗″彛闆嗗悎
+
+
+
         // 鎵ц鑱氬悎鏌ヨ骞惰幏鍙栫粨鏋�
         AggregateIterable<Document> onlineResult = onlineCollection.aggregate(onlinePipeline);
         for (Document doc : onlineResult) {
@@ -1306,6 +1520,22 @@
     @Override
     public void export(HttpServletResponse response, TMonitorVO tMonitor) {
         List<TMonitorExp> monitors = tMonitorMapper.exportTMonitorList(tMonitor);
+        //杩囨护鍑鸿澶囧缓璁剧被鍨�
+        if (StringUtils.isNotBlank(tMonitor.getConstructionType())){
+            List<MonitorConstruction> list =
+                    monitorConstructionService.getSerialNumberListByConstructionType(tMonitor.getConstructionType());
+            //鑾峰緱璁惧缂栧彿闆嗗悎 閫氳繃寤鸿绫诲瀷鏍囩
+            List<String> serialNumberList = list.stream().map(MonitorConstruction::getSerialNumber).collect(Collectors.toList());
+            monitors = monitors.stream()
+                    .filter(result -> {
+                        String sn = result.getSerialNumber();
+                        // 浠讳竴瀛楁闈炵┖涓斿湪闆嗗悎涓嵆鍙�
+                        return (sn != null && serialNumberList.contains(sn));
+                    })
+                    .collect(Collectors.toList());
+        }
+
+
         //鑾峰彇鍔ㄦ�佸垪鏁版嵁
         List<Integer> pointIds = monitors.stream().map(TMonitorExp::getPointId).collect(Collectors.toList());
         List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
@@ -1401,10 +1631,13 @@
         Integer examineTag = monitorQuery.getExamineTag();
         // 鏋勫缓鍩烘湰鐨�$match鏉′欢
         List<Document> matchConditions = new ArrayList<>();
+        String arealayerno = monitorQuery.getArea();
         matchConditions.add(new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate)));
         matchConditions.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_CAR)));
         if (examineTag != null && examineTag.equals(1)) {
             matchConditions.add(new Document("provinceTag", true));
+        }else if(StringUtils.isNotBlank(arealayerno)){
+            matchConditions.add(new Document("orgCode",new Document("$eq", arealayerno)));
         }
         // 鏋勫缓鑱氬悎绠¢亾
         List<Document> pipeline = Arrays.asList(
@@ -1429,6 +1662,8 @@
         onlineMatch.add(new Document("monitorType", new Document("$regex", "2")));
         if (examineTag != null && examineTag.equals(1)) {
             onlineMatch.add(new Document("provinceTag", true));
+        }else if(StringUtils.isNotBlank(arealayerno)){
+            onlineMatch.add(new Document("no", new Document("$regex", "^" + arealayerno)));
         }
         // 鏋勫缓鑱氬悎绠¢亾
         List<Document> onlinePipeline = Arrays.asList(
@@ -1507,6 +1742,7 @@
         calendar.add(Calendar.DAY_OF_MONTH, -1);
         // 鑾峰彇鏈堜唤鏈�鍚庝竴澶╃殑Date
         Date endDate = calendar.getTime();
+        String arealayerno = monitorQuery.getArea();
         //mongo鏌ユ姄鎷嶉噺
         MongoDatabase database = mongoTemplate.getDb();
         MongoCollection<Document> collection = database.getCollection("hk_snapshot_data_monitor");
@@ -1517,6 +1753,8 @@
         matchConditions.add(new Document("dataType", new Document("$eq", ApiConstants.HK_DataType_FACE)));
         if (examineTag != null && examineTag.equals(1)) {
             matchConditions.add(new Document("provinceTag", true));
+        }else if(StringUtils.isNotBlank(arealayerno)){
+            matchConditions.add(new Document("orgCode",new Document("$eq", arealayerno)));
         }
         // 鏋勫缓鑱氬悎绠¢亾
         List<Document> pipeline = Arrays.asList(
@@ -1543,6 +1781,8 @@
         onlineMatch.add(new Document("monitorType", new Document("$regex", "3")));
         if (examineTag != null && examineTag.equals(1)) {
             onlineMatch.add(new Document("provinceTag", true));
+        }else if(StringUtils.isNotBlank(arealayerno)){
+            onlineMatch.add(new Document("no", new Document("$regex", "^" + arealayerno)));
         }
         // 鏋勫缓鑱氬悎绠¢亾
         List<Document> onlinePipeline = Arrays.asList(

--
Gitblit v1.8.0