From 3b0516a2959e25576e4f3fda697a3b025d06c8c9 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期二, 24 六月 2025 14:09:07 +0800
Subject: [PATCH] 每日录像可用指标添加日志,修改大屏为查看当前月平均

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java |  959 ++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 751 insertions(+), 208 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 b044f0c..e450615 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
@@ -7,9 +7,7 @@
 import com.mongodb.client.MongoCollection;
 import com.mongodb.client.MongoDatabase;
 import com.ycl.platform.domain.entity.TMonitor;
-import com.ycl.platform.domain.excel.TMonitorExp;
-import com.ycl.platform.domain.excel.VideoDailyExp;
-import com.ycl.platform.domain.excel.VideoTotalExp;
+import com.ycl.platform.domain.excel.*;
 import com.ycl.platform.domain.form.VideoExportForm;
 import com.ycl.platform.domain.query.DashboardQuery;
 import com.ycl.platform.domain.query.DataCenterQuery;
@@ -32,10 +30,10 @@
 import com.ycl.platform.mapper.DynamicColumnMapper;
 import com.ycl.platform.mapper.TMonitorMapper;
 import com.ycl.platform.mapper.WorkOrderMapper;
+import com.ycl.platform.mapper.YwPointMapper;
 import com.ycl.platform.service.ITMonitorService;
 import com.ycl.system.Result;
 import com.ycl.system.entity.SysDictData;
-import com.ycl.system.mapper.SysConfigMapper;
 import com.ycl.system.mapper.SysDictDataMapper;
 import com.ycl.system.page.PageUtil;
 import com.ycl.system.service.ISysConfigService;
@@ -43,18 +41,19 @@
 import com.ycl.utils.StringUtils;
 import com.ycl.utils.poi.ExcelUtil;
 import constant.ApiConstants;
-import constant.CheckConstants;
 import enumeration.general.AreaDeptEnum;
 import jakarta.servlet.http.HttpServletResponse;
-import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.Validate;
 import org.bson.Document;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.MongoTemplate;
 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 org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import pojo.ExcelExp;
 import utils.poi.ExcelUtilManySheet;
@@ -63,15 +62,15 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
-import java.text.DecimalFormat;
+import java.math.RoundingMode;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.YearMonth;
-import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.time.temporal.TemporalAdjusters;
 import java.util.*;
+import java.util.concurrent.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -81,9 +80,12 @@
  * @date 2024-03-04
  */
 @Service
+@Slf4j
 public class TMonitorServiceImpl extends ServiceImpl<TMonitorMapper, TMonitor> implements ITMonitorService {
     @Autowired
     private TMonitorMapper tMonitorMapper;
+    @Autowired
+    private YwPointMapper pointMapper;
     @Autowired
     private ISysConfigService configService;
     @Autowired
@@ -94,6 +96,8 @@
     private SysDictDataMapper dictDataMapper;
     @Autowired
     private DynamicColumnMapper dynamicColumnMapper;
+    @Autowired
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
 
     /**
      * 鏌ヨ璁惧璧勪骇
@@ -353,23 +357,29 @@
     }
 
     /**
-     *  鏌ongo鏌ユ煇涓湀璁惧鎬绘暟
-     *  鏌ョ湅宸ュ崟鏁伴噺鏌ョ湅寮傚父鐨勬暟
+     * 鏌ongo鏌ユ煇涓湀璁惧鎬绘暟
+     * 鏌ョ湅宸ュ崟鏁伴噺鏌ョ湅寮傚父鐨勬暟
+     *
      * @param monitorQuery 鏌ヨ鏉′欢
      * @return
      */
     @Override
     public Map<String, Object> home(HomeQuery monitorQuery) {
-
+        System.out.println(monitorQuery + "~~~~~~~~~~~~~鎵撳嵃");
         Map<String, Object> dataMap = new HashMap<>();
         Map<String, Object> monthMap1 = new HashMap<>();
         Map<String, Object> monthMap2 = new HashMap<>();
         List<Map<String, Object>> home = baseMapper.home(monitorQuery);
         if (ObjectUtils.isNotEmpty(home)) {
+            //鎷垮埌鏁版嵁搴� 寰幆鏌ヨ
+            System.out.println(home + "~~~~~~~~~~~~~鎵撳嵃");
             for (Map<String, Object> map : home) {
+                //寰楀埌map鐨� months閿殑鍊�  num1閿殑鍊� 缁勮涓烘柊瀵硅薄
                 monthMap1.put(map.get("months").toString(), map.get("num1"));
+                //寰楀埌map鐨� months閿殑鍊�  num2閿殑鍊� 缁勮涓烘柊瀵硅薄
                 monthMap2.put(map.get("months").toString(), map.get("num2"));
             }
+            //home 鐨勪笅鏍�0鐨� map鐨� name閿殑鍊�
             dataMap.put("name", home.get(0).get("name"));
             dataMap.put("state", monthMap1);
             dataMap.put("state2", monthMap2);
@@ -432,75 +442,110 @@
             }
             exportForm.setDeptIds(deptIds);
         }
-        List<ExcelExp> mysheet = new ArrayList<>();
-        exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + ""));
+        List<ExcelExp> sheet = new ArrayList<>();
+        //閫氳繃Collections闈欐�佹柟娉曪紝鎶妉ist杞负绾跨▼瀹夊叏鐨刲ist
+        List mysheet = Collections.synchronizedList(sheet);
         VideoExportForm.convertTags(exportForm);
-        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
-        List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
-        Query query = getQuery(deviceIds, exportForm.getMonth());
+        Query query = getQuery(exportForm);
         //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
         List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+        // 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
+        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());
+        List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
+        // 灏嗗勾鏈堝瓧绗︿覆瑙f瀽涓篩earMonth瀵硅薄
+        YearMonth yearMonth = YearMonth.parse(exportForm.getMonth());
+        // 鑾峰彇褰撴湀鐨勭涓�澶�
+        LocalDate start = yearMonth.atDay(1);
+        // 鑾峰彇涓嬩釜鏈堢殑绗竴澶╋紙閫氳繃鍔犱笂1涓湀骞惰缃棩涓�1锛�
+        YearMonth nextMonth = yearMonth.plusMonths(1);
+        LocalDate end = nextMonth.atDay(1);
+        //鑾峰彇杩欎釜鏈堜唤鐨勯儴闂ㄦ暟鎹紝褰曞儚鐢变簬鏄墠涓�澶╃殑鎵�浠ヤ笉鐢╟reateTime瀛楁
+        Query videoQuery = new Query(Criteria.where("statTime").gte(start).lt(end));
+        videoQuery.addCriteria(Criteria.where("no").in(deviceIds));
         //鏈堜唤姣忔棩褰曞儚鏁版嵁
-        List<RecordMetaDSumResult> recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class);
+        List<RecordMetaDSumResult> recordResult = mongoTemplate.find(videoQuery, RecordMetaDSumResult.class);
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         String[] weeks = {"鏄熸湡涓�", "鏄熸湡浜�", "鏄熸湡涓�", "鏄熸湡鍥�", "鏄熸湡浜�", "鏄熸湡鍏�", "鏄熸湡鏃�"};
         // 鍒涘缓涓�涓狹ap鏉ュ瓨鍌ㄦ瘡澶╃殑绱姞鏁版嵁
-        Map<String, VideoTotalExp> totalMap = new HashMap<>();
+        Map<String, VideoTotalExp> totalMap = new ConcurrentHashMap<>();
+        List<CompletableFuture<Void>> futures = new ArrayList<>();
         //涓�涓儴闂ㄤ竴涓猻heet
         for (Integer deptId : exportForm.getDeptIds()) {
-            //浠庢暟鎹簱闆嗗悎绛涢�夐儴闂ㄦ暟鎹�
-            List<String> ids = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).map(BaseResult::getNo).collect(Collectors.toList());
-            if (CollectionUtils.isEmpty(ids)) continue;
-            //绛涢�夐儴闂ㄦ暟鎹�
-            List<TMonitorResult> onlineList = onlineResult.stream().filter(tMonitorResult -> ids.contains(tMonitorResult.getNo())).collect(Collectors.toList());
-            List<RecordMetaDSumResult> recordList = recordResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList());
-            List<VideoTotalExp> videoTotalExps = new ArrayList<>();
-            for (int i = 0; i < 31; i++) {
-                String date = exportForm.getMonth();
-                date += "-" + (i < 9 ? "0" + (i + 1) : (i + 1));
-                //鎬婚噺
-                VideoTotalExp totalExp = totalMap.computeIfAbsent(date, k -> new VideoTotalExp());
-                LocalDate parseTime = LocalDate.parse(date, formatter);
-                //鑾峰彇鏄熸湡鍑�
-                String week = weeks[parseTime.getDayOfWeek().getValue() - 1];
-                VideoTotalExp videoExp = new VideoTotalExp();
-                videoExp.setDate(date);
-                videoExp.setWeek(week);
-                //璁剧疆鐐逛綅鍦ㄧ嚎鎬婚噺
-                List<TMonitorResult> onlines = onlineList.stream().filter(tMonitorResult -> tMonitorResult.getMongoCreateTime().minusDays(1).equals(parseTime)).collect(Collectors.toList());
-                if (!CollectionUtils.isEmpty(onlines)) {
-                    videoExp.setTotal(onlines.size());
-                    long count = onlines.stream()
-                            .filter(item -> ApiConstants.UY_OnlineSite_Online.equals(item.getOnline()))
-                            .count();
-                    videoExp.setOnline(Integer.valueOf(count + ""));
-                    videoExp.setOffline(videoExp.getTotal() - videoExp.getOnline());
+            CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
+                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+                //绛涢�夐儴闂ㄦ暟鎹�
+                Set<String> ids = onlineResult.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).map(BaseResult::getNo).collect(Collectors.toSet());
+                if (CollectionUtils.isEmpty(ids)) return;
+                //绛涢�夐儴闂ㄦ暟鎹�
+                List<TMonitorResult> onlineList = onlineResult.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList());
+                Map<LocalDate, List<TMonitorResult>> onlineMap = onlineList.stream()
+                        .collect(Collectors.groupingBy(TMonitorResult::getMongoCreateTime));
+                List<RecordMetaDSumResult> recordList = recordResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList());
+                Map<Date, List<RecordMetaDSumResult>> recordMap = recordList.stream().collect(Collectors.groupingBy(RecordMetaDSumResult::getStatTime));
+                List<VideoTotalExp> videoTotalExps = new ArrayList<>();
+                for (int i = 0; i < 31; i++) {
+                    String date = exportForm.getMonth();
+                    date += "-" + (i < 9 ? "0" + (i + 1) : (i + 1));
+                    //鎬婚噺
+                    VideoTotalExp totalExp = totalMap.computeIfAbsent(date, k -> new VideoTotalExp());
+                    LocalDate parseTime = LocalDate.parse(date, formatter);
+                    try {
+                        Date parseDate = simpleDateFormat.parse(date);
+                        //鑾峰彇鏄熸湡鍑�
+                        String week = weeks[parseTime.getDayOfWeek().getValue() - 1];
+                        VideoTotalExp videoExp = new VideoTotalExp();
+                        videoExp.setDate(date);
+                        videoExp.setWeek(week);
+                        //璁剧疆鐐逛綅鍦ㄧ嚎鎬婚噺
+                        List<TMonitorResult> onlines = onlineMap.get(parseTime);
+                        if (!CollectionUtils.isEmpty(onlines)) {
+                            videoExp.setTotal(onlines.size());
+                            long count = onlines.stream()
+                                    .filter(item -> ApiConstants.UY_OnlineSite_Online.equals(item.getOnline()))
+                                    .count();
+                            videoExp.setOnline(Integer.valueOf(count + ""));
+                            videoExp.setOffline(videoExp.getTotal() - videoExp.getOnline());
+                        }
+                        //璁剧疆瀛樺偍鎯呭喌
+                        List<RecordMetaDSumResult> records = recordMap.get(parseDate);
+                        if (!CollectionUtils.isEmpty(records)) {
+                            videoExp.setNoStore(Integer.valueOf(records.stream()
+                                    .filter(record -> ApiConstants.UY_RecordStatus_Abnormal.equals(record.getRecordStatus()))
+                                    .count() + ""));
+                            videoExp.setPartStore(Integer.valueOf(records.stream()
+                                    .filter(record -> ApiConstants.UY_RecordStatus_Interval.equals(record.getRecordStatus()))
+                                    .count() + ""));
+                        }
+                        videoTotalExps.add(videoExp);
+                        //绱姞浣滀负鍏ㄩ噺琛�
+                        totalExp.setDate(date);
+                        totalExp.setWeek(week);
+                        totalExp.setTotal((totalExp.getTotal() == null ? 0 : totalExp.getTotal()) + (videoExp.getTotal() == null ? 0 : videoExp.getTotal()));
+                        totalExp.setOnline((totalExp.getOnline() == null ? 0 : totalExp.getOnline()) + (videoExp.getOnline() == null ? 0 : videoExp.getOnline()));
+                        totalExp.setOffline((totalExp.getOffline() == null ? 0 : totalExp.getOffline()) + (videoExp.getOffline() == null ? 0 : videoExp.getOffline()));
+                        totalExp.setNoStore((totalExp.getNoStore() == null ? 0 : totalExp.getNoStore()) + (videoExp.getNoStore() == null ? 0 : videoExp.getNoStore()));
+                        totalExp.setPartStore((totalExp.getPartStore() == null ? 0 : totalExp.getPartStore()) + (videoExp.getPartStore() == null ? 0 : videoExp.getPartStore()));
+                        totalMap.put(date, totalExp);
+                    } catch (ParseException e) {
+                        e.printStackTrace();
+                    }
                 }
-                //璁剧疆瀛樺偍鎯呭喌
-                List<RecordMetaDSumResult> records = recordList.stream().filter(record -> record.getMongoCreateTime().minusDays(1).equals(parseTime)).collect(Collectors.toList());
-                if (!CollectionUtils.isEmpty(records)) {
-                    videoExp.setNoStore(Integer.valueOf(records.stream()
-                            .filter(record -> ApiConstants.UY_RecordStatus_Abnormal.equals(record.getRecordStatus()))
-                            .count() + ""));
-                    videoExp.setPartStore(Integer.valueOf(records.stream()
-                            .filter(record -> ApiConstants.UY_RecordStatus_Interval.equals(record.getRecordStatus()))
-                            .count() + ""));
-                }
-                videoTotalExps.add(videoExp);
-                //绱姞浣滀负鍏ㄩ噺琛�
-                totalExp.setDate(date);
-                totalExp.setWeek(week);
-                totalExp.setTotal((totalExp.getTotal() == null ? 0 : totalExp.getTotal()) + (videoExp.getTotal() == null ? 0 : videoExp.getTotal()));
-                totalExp.setOnline((totalExp.getOnline() == null ? 0 : totalExp.getOnline()) + (videoExp.getOnline() == null ? 0 : videoExp.getOnline()));
-                totalExp.setOffline((totalExp.getOffline() == null ? 0 : totalExp.getOffline()) + (videoExp.getOffline() == null ? 0 : videoExp.getOffline()));
-                totalExp.setNoStore((totalExp.getNoStore() == null ? 0 : totalExp.getNoStore()) + (videoExp.getNoStore() == null ? 0 : videoExp.getNoStore()));
-                totalExp.setPartStore((totalExp.getPartStore() == null ? 0 : totalExp.getPartStore()) + (videoExp.getPartStore() == null ? 0 : videoExp.getPartStore()));
-                totalMap.put(date, totalExp);
-            }
-            AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
-            ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoTotalExps, VideoTotalExp.class);
-            mysheet.add(excelExp);
+                AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
+                ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoTotalExps, VideoTotalExp.class);
+                mysheet.add(excelExp);
+            }, threadPoolTaskExecutor);
+            futures.add(future);
         }
+        // 绛夊緟鎵�鏈変换鍔″畬鎴�
+        CompletableFuture<Void> allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
+        allFutures.join(); // 杩欏皢闃诲鐩村埌鎵�鏈変换鍔″畬鎴�
         //娣诲姞鍏ㄩ噺琛�
         List<VideoTotalExp> totalExps = new ArrayList<>(totalMap.values());
         totalExps = totalExps.stream().sorted(Comparator.comparing(VideoTotalExp::getDate)).collect(Collectors.toList());
@@ -517,6 +562,8 @@
      */
     @Override
     public void exportVideoOnline(HttpServletResponse response, VideoExportForm exportForm) throws IOException, NoSuchFieldException, IllegalAccessException {
+        log.error("寮�濮嬪鍑烘暟鎹�");
+        log.error("浼犲叆鐨勬湀浠�:{}",exportForm.getMonth());
         //榛樿鏌ユ墍鏈夐儴闂�
         if (CollectionUtils.isEmpty(exportForm.getDeptIds())) {
             List<Integer> deptIds = new ArrayList<>();
@@ -525,10 +572,24 @@
             }
             exportForm.setDeptIds(deptIds);
         }
-        List<ExcelExp> mysheet = new ArrayList<>();
-        exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + ""));
+        List<ExcelExp> sheet = new ArrayList<>();
+        //閫氳繃Collections闈欐�佹柟娉曪紝鎶妉ist杞负绾跨▼瀹夊叏鐨刲ist
+        List mysheet = Collections.synchronizedList(sheet);
         VideoExportForm.convertTags(exportForm);
-        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
+        Query query = getQuery(exportForm);
+        //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+        List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+        log.error("鏈堜唤鍦ㄧ嚎鏁版嵁:{}鏉℃暟",onlineResult.size());
+        // 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
+        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);
@@ -540,51 +601,424 @@
                 tMonitorResult.setDynamicColumnList(map.get(pointId));
             }
         }
-        List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
-        Query query = getQuery(deviceIds, exportForm.getMonth());
-        //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
-        List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
-        //鍏ㄩ噺琛�
-        List<VideoDailyExp> totalExps = new ArrayList<>();
+        //瀛樻斁鍖哄煙 涓� 璁惧鍒楄〃 map key涓� 鍖哄煙
+        Map<Integer, List<VideoDailyExp>> map = new HashMap<>();
+        List<CompletableFuture<List<VideoDailyExp>>> futures = new ArrayList<>();
         for (Integer deptId : exportForm.getDeptIds()) {
-            List<VideoDailyExp> videoDailyExps = new ArrayList<>();
-            //浠庢暟鎹簱闆嗗悎绛涢�夐儴闂ㄦ暟鎹�
-            List<TMonitorResult> monitors = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList());
-            if (CollectionUtils.isEmpty(monitors)) continue;
-            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);
-            for (TMonitorResult result : monitors) {
-                VideoDailyExp videoDailyExp = new VideoDailyExp();
-                videoDailyExp.setSerialNumber(result.getNo());
-                videoDailyExp.setDeviceName(result.getName());
-                videoDailyExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
-                StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : ""));
-                //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
-                if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) {
-                    List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
-                    for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
-                        tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+            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;
+
+                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);
+                for (TMonitorResult result : monitors) {
+                    VideoDailyExp videoDailyExp = new VideoDailyExp();
+                    videoDailyExp.setSerialNumber(result.getNo());
+                    videoDailyExp.setDeviceName(result.getName());
+                    videoDailyExp.setType(result.getMonitorType());
+
+                    videoDailyExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
+
+                    StringBuilder tag = new StringBuilder("" +
+                            (result.getProvinceTag() ? "鐪佸巺銆�" : "") +
+                            (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") +
+                            (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") +
+                            (result.getDeptTag() ? "閮ㄧ骇銆�" : ""));
+
+                    //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
+                    if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) {
+                        for (DynamicColumnVO dynamicColumnVO : result.getDynamicColumnList()) {
+                            tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+                        }
                     }
+                    // 鍒犻櫎瀛楃涓叉湯灏剧殑"銆�"
+                    if (tag.toString().endsWith("銆�")) {
+                        tag = new StringBuilder(tag.substring(0, tag.length() - 1));
+                    }
+                    videoDailyExp.setTag(tag.toString());
+
+                    try {
+                        setOnlineDaily(videoDailyExp, result, onlines);
+                    } catch (Exception e) {
+                        log.error(e.getMessage());
+                    }
+                    videoDailyExps.add(videoDailyExp);
                 }
-                // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
-                if (tag.toString().endsWith("銆�")) {
-                    tag = new StringBuilder(tag.substring(0, tag.length() - 1));
-                }
-                videoDailyExp.setTag(tag.toString());
-                setOnlineDaily(videoDailyExp, result, onlines);
-                videoDailyExps.add(videoDailyExp);
-                //鍏ㄩ噺琛�
-                totalExps.add(videoDailyExp);
-            }
-            ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoDailyExps, VideoDailyExp.class);
-            mysheet.add(excelExp);
+
+                ExcelExp excelExp = new ExcelExp(
+                        areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(),
+                        videoDailyExps,
+                        VideoDailyExp.class
+                );
+                mysheet.add(excelExp);
+
+
+                return videoDailyExps;
+            }, threadPoolTaskExecutor);
+            futures.add(future);
+            map.put(deptId,future.join());
         }
+        // 鑾峰彇鍏ㄩ噺鏁版嵁
+        List<VideoDailyExp> totalExps = futures.stream()
+                .map(CompletableFuture::join)
+                .flatMap(List::stream)
+                .collect(Collectors.toList());
         ExcelExp excelExp = new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class);
         mysheet.add(excelExp);
+
+        long face = totalExps.stream().filter(item -> item.getType().contains("1")).count();
+        long car = totalExps.stream().filter(item -> item.getType().contains("2")).count();
+        long video = totalExps.stream().filter(item -> item.getType().contains("3")).count();
+        log.error("浜鸿劯鏁�:{}",face);
+        log.error("car鏁�:{}",car);
+        log.error("video鏁�:{}",video);
+        //娣诲姞鏂扮殑sheet 绂荤嚎鏁扮粺璁¤〃
+        List<VideoTypeOffOnlineExp> videoTypeOffOnlineExps = new ArrayList<>();
+
+        //鍦ㄧ嚎鐜囩粺璁¤〃
+        List<VideoOnlineRateExp> videoOnlineRateExps = new ArrayList<>();
+
+        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);
+            //鍗″彛
+            VideoTypeOffOnlineExp carVideoTypeOffOnlineExp =this.getListOfflineCountInfo(list,"2",areaDeptEnum);
+            //瑙嗛
+            VideoTypeOffOnlineExp videoTypeOffOnlineExp = this.getListOfflineCountInfo(list,"3",areaDeptEnum);
+
+            VideoOnlineRateExp faceVideoOnlineRateExp = this.getListOnLineCountInfo(list,"1",areaDeptEnum);
+            //鍗″彛
+            VideoOnlineRateExp carVideoOnlineRateExp =this.getListOnLineCountInfo(list,"2",areaDeptEnum);
+            //瑙嗛
+            VideoOnlineRateExp VideoOnlineRateExp = this.getListOnLineCountInfo(list,"3",areaDeptEnum);
+
+
+            //灏嗚鍖哄煙绫讳笁绉嶈澶囩被鍨嬬殑 淇℃伅 鏀惧叆 excel瀵硅薄鍐�
+            //鏀惧叆褰撳墠鍖哄煙鐨勪汉鑴歌澶囩浉鍏宠缁�
+            videoTypeOffOnlineExps.add(faceVideoTypeOffOnlineExp);
+            //鏀惧叆褰撳墠鍖哄煙鐨勮溅杈嗚澶囩浉鍏宠缁�
+            videoTypeOffOnlineExps.add(carVideoTypeOffOnlineExp);
+            //鏀惧叆褰撳墠鍖哄煙鐨勮棰戣澶囩浉鍏宠缁�
+            videoTypeOffOnlineExps.add(videoTypeOffOnlineExp);
+
+            videoOnlineRateExps.add(faceVideoOnlineRateExp);
+            videoOnlineRateExps.add(carVideoOnlineRateExp);
+            videoOnlineRateExps.add(VideoOnlineRateExp);
+        }
+
+        //璁$畻鑷础甯傚悎璁�
+        //鎻掑叆excel鏃剁‘淇濇暟鎹嚭鐜板湪鏈�鍚�
+        List<VideoTypeOffOnlineExp> allVideoTypeOffOnlineExps = new ArrayList<>();
+        //鎻掑叆excel鏃剁‘淇濇暟鎹嚭鐜板湪鏈�鍚�
+        List<VideoOnlineRateExp> allVideoOnlineRateExps =  new ArrayList<>();
+
+        //鎵�鏈夌绾挎暟鎹腑锛屽悇鍖鸿澶囦负浜鸿劯鐨勫璞�  鍚堣瑁呴厤瀵硅薄
+        VideoTypeOffOnlineExp allFaceVideosOffline = new VideoTypeOffOnlineExp();
+        setAllVideoTypeOffOnlineExpCount(videoTypeOffOnlineExps,allFaceVideosOffline,"浜鸿劯");
+
+        VideoTypeOffOnlineExp allCarVideosOffline = new VideoTypeOffOnlineExp();
+        setAllVideoTypeOffOnlineExpCount(videoTypeOffOnlineExps,allCarVideosOffline,"鍗″彛");
+
+        VideoTypeOffOnlineExp allVideosOffline = new VideoTypeOffOnlineExp();
+        setAllVideoTypeOffOnlineExpCount(videoTypeOffOnlineExps,allVideosOffline,"瑙嗛");
+
+        allVideoTypeOffOnlineExps.add(allFaceVideosOffline);
+        allVideoTypeOffOnlineExps.add(allCarVideosOffline);
+        allVideoTypeOffOnlineExps.add(allVideosOffline);
+
+        //鎵�鏈夊湪绾挎暟鎹� 鍚堣瑁呴厤瀵硅薄
+        VideoOnlineRateExp allFaceVideosOnline = new VideoOnlineRateExp();
+        setAllVideoTypeOnlineExpCount(face,videoOnlineRateExps,allFaceVideosOnline,"浜鸿劯");
+
+
+        VideoOnlineRateExp allCarVideosOnline = new VideoOnlineRateExp();
+        setAllVideoTypeOnlineExpCount(car,videoOnlineRateExps,allCarVideosOnline,"鍗″彛");
+
+        VideoOnlineRateExp allVideosOnline = new VideoOnlineRateExp();
+        setAllVideoTypeOnlineExpCount(video,videoOnlineRateExps,allVideosOnline,"瑙嗛");
+
+
+        allVideoOnlineRateExps.add(allFaceVideosOnline);
+        allVideoOnlineRateExps.add(allCarVideosOnline);
+        allVideoOnlineRateExps.add(allVideosOnline);
+
+        videoTypeOffOnlineExps.addAll(allVideoTypeOffOnlineExps);
+        videoOnlineRateExps.addAll(allVideoOnlineRateExps);
+        log.error("鎵撳嵃璁$畻绂荤嚎鐨勪俊鎭�:{}" ,videoTypeOffOnlineExps );
+        log.error("鎵撳嵃鍦ㄧ嚎鐨勪俊鎭�:{}" ,videoOnlineRateExps );
+        //娣诲姞鍚堣鏁版嵁
+
+        ExcelExp excelTypeOffLineExp = new ExcelExp("绂荤嚎鏁扮粺璁�", videoTypeOffOnlineExps, VideoTypeOffOnlineExp.class);
+        mysheet.add(excelTypeOffLineExp);
+
+        //娣诲姞鍦ㄧ嚎鐜囪〃
+        ExcelExp excelOnlineRateExp = new ExcelExp("鍦ㄧ嚎鐜囩粺璁�",videoOnlineRateExps, VideoOnlineRateExp.class);
+        mysheet.add(excelOnlineRateExp);
+
         ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
         util.exportExcelManySheet(response, mysheet);
+        log.error("瀵煎嚭缁撴潫");
+    }
+    //绂荤嚎璁惧鏁版嵁锛屽悎璁″璞★紝淇℃伅瑁呴厤
+    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瀵硅薄淇℃伅
+     * @param videoDailyExps 浼犲叆鐨勮澶囬泦鍚堜俊鎭�
+     * @param type 璁惧绫诲瀷 1浜鸿劯 2杞﹁締 3瑙嗛
+     * @param areaDeptEnum 鍖哄煙
+     * @return
+     */
+    public VideoTypeOffOnlineExp getListOfflineCountInfo(List<VideoDailyExp> videoDailyExps,
+                                                         String type,
+                                                         AreaDeptEnum areaDeptEnum
+                                                        ){
+        VideoTypeOffOnlineExp videoTypeOffOnlineExp = new VideoTypeOffOnlineExp();
+
+        List<VideoDailyExp> list = videoDailyExps.stream()
+                .filter(device ->device.getType() != null && device.getType().contains(type)).collect(Collectors.toList());
+        log.error("绛涢�夊畬璁惧绫诲瀷 锛歿} 鍚庨泦鍚堢殑澶у皬锛歿}",type,list.size());
+        //绂荤嚎鏁伴噺
+        try {
+            //璁剧疆绂荤嚎鏁伴噺 浠ュ強姣忔棩绂荤嚎鏁伴噺
+            setVideoTypeOffOnlineExpCountAndDays(list,videoTypeOffOnlineExp);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        //璁惧绫诲瀷
+        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)throws NoSuchFieldException, IllegalAccessException {
+        //寰幆涓�涓湀
+        //绂荤嚎鎬绘暟
+        long AllOffLineCount = 0;
+        for (VideoDailyExp videoDailyExp : videoDailyExps) {
+            if (videoDailyExp.isAllOfflineByMonth()) {
+                AllOffLineCount++;
+            }
+        }
+        //鏄悎璁℃暟鎹笉闇�瑕佷笅鏂规暟鎹�
+
+            for (int i = 1; i <= 31; i++) {
+                //姣忔棩绂荤嚎鏁�
+                long count = 0;
+                String fieldName = "day" + i;
+                for (VideoDailyExp videoDailyExp : videoDailyExps) {
+                    // 鏋勯�犲瓧娈靛悕
+                    Field field = videoDailyExp.getClass().getDeclaredField(fieldName);
+                    // 纭繚瀛楁鏄鏈夌殑鍙互璁块棶
+                    field.setAccessible(true);
+                    // 鑾峰彇瀛楁鍊�
+                    String value = (String) field.get(videoDailyExp);
+                    if ("绂荤嚎".equals(value)) {
+                        count++;
+                    }
+                }
+                //鍙嶅皠娣诲姞鍒板璞″睘鎬т腑
+                Field field = videoTypeOffOnlineExp.getClass().getDeclaredField(fieldName);
+                field.setAccessible(true);
+                String rateStr = count + "";
+                if (!"0".equals(rateStr)) {
+                    field.set(videoTypeOffOnlineExp, rateStr);
+                }
+
+            }
+//        }
+        videoTypeOffOnlineExp.setOfflineCount(String.valueOf(AllOffLineCount));
+    }
+
+    /**
+     * 璁$畻鍦ㄧ嚎璁惧excel瀵硅薄淇℃伅
+     * @param videoDailyExps 浼犲叆鐨勮澶囬泦鍚堜俊鎭�
+     * @param type 璁惧绫诲瀷 1浜鸿劯 2杞﹁締 3瑙嗛
+     * @param areaDeptEnum 鍖哄煙
+     * @return
+     */
+    public VideoOnlineRateExp getListOnLineCountInfo(List<VideoDailyExp> videoDailyExps,
+                                                         String type,
+                                                         AreaDeptEnum areaDeptEnum
+                                                         ){
+        VideoOnlineRateExp videoOnlineRateExp = new VideoOnlineRateExp();
+
+        List<VideoDailyExp> list = videoDailyExps.stream()
+                .filter(device ->device.getType() != null && device.getType().contains(type)).collect(Collectors.toList());
+        log.error("绛涢�夊畬璁惧绫诲瀷 锛歿} 鍚庨泦鍚堢殑澶у皬锛歿}",type,list.size());
+        //绂荤嚎鏁伴噺
+        try {
+            setVideoOnlineRateExpCountAndDays(list,videoOnlineRateExp);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+        //璁惧绫诲瀷
+        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());
+        return videoOnlineRateExp;
+    }
+
+
+    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);
+                // 纭繚瀛楁鏄鏈夌殑鍙互璁块棶
+                field.setAccessible(true);
+                // 鑾峰彇瀛楁鍊�
+                String value = (String) field.get(videoDailyExp);
+                if ("鍦ㄧ嚎".equals(value)) {
+                    count ++;
+                }
+            }
+            //姣忔棩鍦ㄧ嚎鐜�
+            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)){
+                field.set(videoOnlineRateExp, rateStr);
+            }
+
+        }
     }
 
 
@@ -601,10 +1035,22 @@
             }
             exportForm.setDeptIds(deptIds);
         }
-        List<ExcelExp> mysheet = new ArrayList<>();
-        exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + ""));
+
         VideoExportForm.convertTags(exportForm);
-        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
+        Query query = getQuery(exportForm);
+        //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+        List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+
+        // 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
+        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());
+        List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
         //鑾峰彇鍔ㄦ�佸垪鏁版嵁
         List<Integer> pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList());
         List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
@@ -616,7 +1062,7 @@
                 tMonitorResult.setDynamicColumnList(map.get(pointId));
             }
         }
-        List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
+
         // 灏嗗勾鏈堝瓧绗︿覆瑙f瀽涓篩earMonth瀵硅薄
         YearMonth yearMonth = YearMonth.parse(exportForm.getMonth());
         // 鑾峰彇褰撴湀鐨勭涓�澶�
@@ -625,48 +1071,75 @@
         YearMonth nextMonth = yearMonth.plusMonths(1);
         LocalDate end = nextMonth.atDay(1);
         //鑾峰彇杩欎釜鏈堜唤鐨勯儴闂ㄦ暟鎹紝褰曞儚鐢变簬鏄墠涓�澶╃殑鎵�浠ヤ笉鐢╟reateTime瀛楁
-        Query query = new Query(Criteria.where("statTime").gte(start).lt(end));
-        query.addCriteria(Criteria.where("no").in(deviceIds));
+        Query videoQuery = new Query(Criteria.where("statTime").gte(start).lt(end));
+        videoQuery.addCriteria(Criteria.where("no").in(deviceIds));
         //鏈堜唤姣忔棩褰曞儚绾挎暟鎹�
-        List<RecordMetaDSumResult> recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class);
-        //鍏ㄩ噺琛�
-        List<VideoDailyExp> totalExps = new ArrayList<>();
+        List<RecordMetaDSumResult> recordResult = mongoTemplate.find(videoQuery, RecordMetaDSumResult.class);
+
+        // 棰勫厛鎸夐儴闂↖D鍒嗙粍
+        Map<Integer, List<TMonitorResult>> monitorsByDept = tMonitorResults.stream()
+                .collect(Collectors.groupingBy(TMonitorResult::getDeptId));
+        // 棰勫厛鏋勫缓鏄犲皠
+        Map<String, List<RecordMetaDSumResult>> recordMap = recordResult.stream()
+                .collect(Collectors.groupingBy(RecordMetaDSumResult::getNo));
+        List<CompletableFuture<List<VideoDailyExp>>> futures = new ArrayList<>();
         for (Integer deptId : exportForm.getDeptIds()) {
-            List<VideoDailyExp> videoDailyExps = new ArrayList<>();
-            //浠庢暟鎹簱闆嗗悎绛涢�夐儴闂ㄦ暟鎹�
-            List<TMonitorResult> monitors = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList());
-            if (CollectionUtils.isEmpty(monitors)) continue;
-            List<String> ids = monitors.stream().map(BaseResult::getNo).collect(Collectors.toList());
-            //绛涢�塵ongo鍖哄幙鏁版嵁
-            List<RecordMetaDSumResult> records = recordResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList());
-            AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
-            for (TMonitorResult result : monitors) {
-                VideoDailyExp videoDailyExp = new VideoDailyExp();
-                videoDailyExp.setSerialNumber(result.getNo());
-                videoDailyExp.setDeviceName(result.getName());
-                videoDailyExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
-                StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : ""));
-                //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
-                if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) {
-                    List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
-                    for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
-                        tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+            CompletableFuture<List<VideoDailyExp>> future = CompletableFuture.supplyAsync(() -> {
+                List<VideoDailyExp> videoDailyExps = new ArrayList<>();
+                // 鑾峰彇褰撳墠閮ㄩ棬鐨勬暟鎹�
+                List<TMonitorResult> monitors = monitorsByDept.getOrDefault(deptId, Collections.emptyList());
+                if (CollectionUtils.isEmpty(monitors)) return videoDailyExps;
+                AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
+                for (TMonitorResult result : monitors) {
+                    VideoDailyExp videoDailyExp = new VideoDailyExp();
+                    videoDailyExp.setSerialNumber(result.getNo());
+                    videoDailyExp.setDeviceName(result.getName());
+                    videoDailyExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
+                    StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : ""));
+                    //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
+                    if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) {
+                        List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
+                        for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
+                            tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+                        }
                     }
+                    // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
+                    if (tag.toString().endsWith("銆�")) {
+                        tag = new StringBuilder(tag.substring(0, tag.length() - 1));
+                    }
+                    videoDailyExp.setTag(tag.toString());
+                    // 浣跨敤Map鐩存帴鑾峰彇璁板綍锛岄伩鍏峟ilter鎿嶄綔
+                    List<RecordMetaDSumResult> recordsResult = recordMap.get(result.getNo());
+                    try {
+                        if (!CollectionUtils.isEmpty(recordsResult))
+                            setRecordDaily(videoDailyExp, result, recordsResult);
+                    } catch (Exception e) {
+                        log.error(e.getMessage());
+                    }
+                    //鍖哄幙琛�
+                    videoDailyExps.add(videoDailyExp);
                 }
-                // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
-                if (tag.toString().endsWith("銆�")) {
-                    tag = new StringBuilder(tag.substring(0, tag.length() - 1));
-                }
-                videoDailyExp.setTag(tag.toString());
-                setRecordDaily(videoDailyExp, result, records);
-                //鍖哄幙琛�
-                videoDailyExps.add(videoDailyExp);
-                //鍏ㄩ噺琛�
-                totalExps.add(videoDailyExp);
-            }
-            ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoDailyExps, VideoDailyExp.class);
-            mysheet.add(excelExp);
+                return videoDailyExps;
+            }, threadPoolTaskExecutor);
+            futures.add(future);
         }
+        // 绛夊緟鎵�鏈変换鍔″畬鎴�
+        CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
+        // 姣忎釜閮ㄩ棬鐨勬暟鎹崟鐙繚瀛�
+        List<List<VideoDailyExp>> results = futures.stream()
+                .map(CompletableFuture::join)  // 鑾峰彇姣忎釜Future鐨勭粨鏋�
+                .collect(Collectors.toList());
+        List<VideoDailyExp> totalExps = new ArrayList<>();
+        List<ExcelExp> mysheet = new ArrayList<>();
+        for (List<VideoDailyExp> result : results) {
+            ExcelExp excelExp = new ExcelExp(
+                    result.get(0).getArea() == null ? "鏈煡" : result.get(0).getArea(),
+                    result,
+                    VideoDailyExp.class);
+            mysheet.add(excelExp);
+            totalExps.addAll(result);
+        }
+
         ExcelExp excelExp = new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class);
         mysheet.add(excelExp);
         ExcelUtilManySheet<List<ExcelExp>> util = new ExcelUtilManySheet<>(mysheet);
@@ -686,10 +1159,19 @@
             }
             exportForm.setDeptIds(deptIds);
         }
-        List<ExcelExp> mysheet = new ArrayList<>();
-        exportForm.setCameraFunType(Integer.valueOf(CheckConstants.Rule_Category_Video + ""));
-        VideoExportForm.convertTags(exportForm);
-        List<TMonitorResult> tMonitorResults = tMonitorMapper.selectMonitorResult(exportForm);
+        Query query = getQuery(exportForm);
+        //鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
+        List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
+        // 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
+        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());
         //鑾峰彇鍔ㄦ�佸垪鏁版嵁
         List<Integer> pointIds = tMonitorResults.stream().map(TMonitorResult::getPointId).collect(Collectors.toList());
         List<DynamicColumnVO> dynamics = dynamicColumnMapper.getDynamicsByIds("t_yw_point", pointIds);
@@ -710,46 +1192,72 @@
         YearMonth nextMonth = yearMonth.plusMonths(1);
         LocalDate end = nextMonth.atDay(1);
         //鑾峰彇杩欎釜鏈堜唤鐨勯儴闂ㄦ暟鎹紝褰曞儚鐢变簬鏄墠涓�澶╃殑鎵�浠ヤ笉鐢╟reateTime瀛楁
-        Query query = new Query(Criteria.where("statTime").gte(start).lt(end));
-        query.addCriteria(Criteria.where("no").in(deviceIds));
+        Query videoQuery = new Query(Criteria.where("statTime").gte(start).lt(end));
+        videoQuery.addCriteria(Criteria.where("no").in(deviceIds));
         //鏈堜唤姣忔棩褰曞儚绾挎暟鎹�
-        List<RecordMetaDSumResult> recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class);
-        //鍏ㄩ噺琛�
-        List<VideoDailyExp> totalExps = new ArrayList<>();
+        List<RecordMetaDSumResult> recordResult = mongoTemplate.find(videoQuery, RecordMetaDSumResult.class);
+        // 棰勫厛鎸夐儴闂↖D鍒嗙粍
+        Map<Integer, List<TMonitorResult>> monitorsByDept = tMonitorResults.stream()
+                .collect(Collectors.groupingBy(TMonitorResult::getDeptId));
+        // 棰勫厛鏋勫缓鏄犲皠
+        Map<String, List<RecordMetaDSumResult>> recordMap = recordResult.stream()
+                .collect(Collectors.groupingBy(RecordMetaDSumResult::getNo));
+
+        List<CompletableFuture<List<VideoDailyExp>>> futures = new ArrayList<>();
         for (Integer deptId : exportForm.getDeptIds()) {
-            List<VideoDailyExp> videoDailyExps = new ArrayList<>();
-            //浠庢暟鎹簱闆嗗悎绛涢�夐儴闂ㄦ暟鎹�
-            List<TMonitorResult> monitors = tMonitorResults.stream().filter(tMonitorResult -> deptId.equals(tMonitorResult.getDeptId())).collect(Collectors.toList());
-            if (CollectionUtils.isEmpty(monitors)) continue;
-            List<String> ids = monitors.stream().map(BaseResult::getNo).collect(Collectors.toList());
-            //绛涢�塵ongo鍖哄幙鏁版嵁
-            List<RecordMetaDSumResult> records = recordResult.stream().filter(result -> ids.contains(result.getNo())).collect(Collectors.toList());
-            AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
-            for (TMonitorResult result : monitors) {
-                VideoDailyExp videoDailyExp = new VideoDailyExp();
-                videoDailyExp.setSerialNumber(result.getNo());
-                videoDailyExp.setDeviceName(result.getName());
-                videoDailyExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
-                StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : ""));
-                //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
-                if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) {
-                    List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
-                    for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
-                        tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+            CompletableFuture<List<VideoDailyExp>> future = CompletableFuture.supplyAsync(() -> {
+                List<VideoDailyExp> videoDailyExps = new ArrayList<>();
+                // 鑾峰彇褰撳墠閮ㄩ棬鐨勬暟鎹�
+                List<TMonitorResult> monitors = monitorsByDept.getOrDefault(deptId, Collections.emptyList());
+                if (CollectionUtils.isEmpty(monitors)) return videoDailyExps;
+                AreaDeptEnum areaDeptEnum = AreaDeptEnum.fromDept(deptId);
+                for (TMonitorResult result : monitors) {
+                    VideoDailyExp videoDailyExp = new VideoDailyExp();
+                    videoDailyExp.setSerialNumber(result.getNo());
+                    videoDailyExp.setDeviceName(result.getName());
+                    videoDailyExp.setArea(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName());
+                    StringBuilder tag = new StringBuilder("" + (result.getProvinceTag() ? "鐪佸巺銆�" : "") + (result.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (result.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (result.getDeptTag() ? "閮ㄧ骇銆�" : ""));
+                    //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
+                    if (!CollectionUtils.isEmpty(result.getDynamicColumnList())) {
+                        List<DynamicColumnVO> dynamicColumnList = result.getDynamicColumnList();
+                        for (DynamicColumnVO dynamicColumnVO : dynamicColumnList) {
+                            tag.append(dynamicColumnVO.getColumnValue()).append("銆�");
+                        }
                     }
+                    // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
+                    if (tag.toString().endsWith("銆�")) {
+                        tag = new StringBuilder(tag.substring(0, tag.length() - 1));
+                    }
+                    videoDailyExp.setTag(tag.toString());
+                    // 浣跨敤Map鐩存帴鑾峰彇璁板綍锛岄伩鍏峟ilter鎿嶄綔
+                    List<RecordMetaDSumResult> recordsResult = recordMap.get(result.getNo());
+                    try {
+                        if (!CollectionUtils.isEmpty(recordsResult)) setLoseDaily(videoDailyExp, recordsResult);
+                    } catch (Exception e) {
+                        log.error(e.getMessage());
+                    }
+                    videoDailyExps.add(videoDailyExp);
                 }
-                // 鍒犻櫎瀛楃涓叉湯灏剧殑鈥溿�佲��
-                if (tag.toString().endsWith("銆�")) {
-                    tag = new StringBuilder(tag.substring(0, tag.length() - 1));
-                }
-                videoDailyExp.setTag(tag.toString());
-                setLoseDaily(videoDailyExp, result, records);
-                videoDailyExps.add(videoDailyExp);
-                //鍏ㄩ噺琛�
-                totalExps.add(videoDailyExp);
-            }
-            ExcelExp excelExp = new ExcelExp(areaDeptEnum == null ? "鏈煡" : areaDeptEnum.getName(), videoDailyExps, VideoDailyExp.class);
+                return videoDailyExps;
+            }, threadPoolTaskExecutor);
+            futures.add(future);
+        }
+        // 绛夊緟鎵�鏈変换鍔″畬鎴�
+        CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
+
+        // 姣忎釜閮ㄩ棬鐨勬暟鎹崟鐙繚瀛�
+        List<List<VideoDailyExp>> results = futures.stream()
+                .map(CompletableFuture::join)  // 鑾峰彇姣忎釜Future鐨勭粨鏋�
+                .collect(Collectors.toList());
+        List<VideoDailyExp> totalExps = new ArrayList<>();
+        List<ExcelExp> mysheet = new ArrayList<>();
+        for (List<VideoDailyExp> result : results) {
+            ExcelExp excelExp = new ExcelExp(
+                    result.get(0).getArea() == null ? "鏈煡" : result.get(0).getArea(),
+                    result,
+                    VideoDailyExp.class);
             mysheet.add(excelExp);
+            totalExps.addAll(result);
         }
         ExcelExp excelExp = new ExcelExp("鍏ㄩ噺", totalExps, VideoDailyExp.class);
         mysheet.add(excelExp);
@@ -807,6 +1315,13 @@
                         ))
                         .append("loseCount", new Document("$sum",
                                 new Document("$cond", Arrays.asList(
+                                        new Document("$eq", Arrays.asList("$recordStatus", 0)),
+                                        1,
+                                        0
+                                ))
+                        ))
+                        .append("errCount", new Document("$sum",
+                                new Document("$cond", Arrays.asList(
                                         new Document("$eq", Arrays.asList("$recordStatus", -1)),
                                         1,
                                         0
@@ -821,6 +1336,7 @@
             homeVideoVO.setCreateDate(doc.getDate("_id"));
             homeVideoVO.setIntegrityNum(doc.getInteger("normalCount"));
             homeVideoVO.setLoseNum(doc.getInteger("loseCount"));
+            homeVideoVO.setErrNum(doc.getInteger("errCount"));
             results.add(homeVideoVO);
         }
 
@@ -904,7 +1420,7 @@
                 String type = car.replaceAll("3", "浜鸿劯");
                 monitor.setCameraFunType(type);
             }
-            StringBuilder tag = new StringBuilder("" + (monitor.getProvinceTagVideo() ? "鐪佸巺瑙嗛銆�" : "") + (monitor.getProvinceTagCar() ? "鐪佸巺杞﹁締銆�" : "")+ (monitor.getProvinceTagFace() ? "鐪佸巺浜鸿劯銆�" : "")+ (monitor.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (monitor.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (monitor.getDeptTag() ? "閮ㄧ骇銆�" : ""));
+            StringBuilder tag = new StringBuilder("" + (monitor.getProvinceTagVideo() ? "鐪佸巺瑙嗛銆�" : "") + (monitor.getProvinceTagCar() ? "鐪佸巺杞﹁締銆�" : "") + (monitor.getProvinceTagFace() ? "鐪佸巺浜鸿劯銆�" : "") + (monitor.getImportantTag() ? "閲嶇偣鐐逛綅銆�" : "") + (monitor.getImportantCommandImageTag() ? "閲嶇偣鎸囨尌鍥惧儚銆�" : "") + (monitor.getDeptTag() ? "閮ㄧ骇銆�" : ""));
             //鍔ㄦ�佸垪澶勭悊鍔犲湪鏍囩閲�
             if (!CollectionUtils.isEmpty(monitor.getDynamicColumnList())) {
                 List<DynamicColumnVO> dynamicColumnList = monitor.getDynamicColumnList();
@@ -920,14 +1436,32 @@
         });
         ExcelUtil<TMonitorExp> util = new ExcelUtil<>(TMonitorExp.class);
         String sheetName = "";
-        if("1".equals(tMonitor.getCameraFunType())){
+        if ("1".equals(tMonitor.getCameraFunType())) {
             sheetName = "瑙嗛";
-        }else if("2".equals(tMonitor.getCameraFunType())){
+        } else if ("2".equals(tMonitor.getCameraFunType())) {
             sheetName = "杞﹁締";
-        }else if("3".equals(tMonitor.getCameraFunType())){
+        } else if ("3".equals(tMonitor.getCameraFunType())) {
             sheetName = "浜鸿劯";
         }
-        util.exportExcel(response, monitors,sheetName);
+        util.exportExcel(response, monitors, sheetName);
+    }
+
+    /**
+     * 娓呯悊涓�鏈轰竴妗�
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result clearMonitor() {
+      tMonitorMapper.clearMonitor();
+      pointMapper.clearMonitor();
+      return Result.ok();
+    }
+
+    @Override
+    public Result assetManagementCount(DataCenterQuery query) {
+        Map<String, String> map =tMonitorMapper.assetManagementCount();
+        return Result.ok().data(map);
     }
 
 
@@ -1014,7 +1548,7 @@
         //鎸夋椂闂存帓搴�
         results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList());
         //濡傛灉鏄粯璁ゆ垨绱拰鍒欒繘琛岀疮鍜屼互鍙婅幏鍙栧熀鍑嗙嚎
-        if(monitorQuery.getCategory() == null || monitorQuery.getCategory().equals(1)) {
+        if (monitorQuery.getCategory() == null || monitorQuery.getCategory().equals(1)) {
             int snapCount = 0;
             for (HomeCarVO vo : results) {
                 if (vo.getSnapCount() != null) {
@@ -1128,7 +1662,7 @@
         //鎸夋椂闂存帓搴�
         results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList());
         //濡傛灉鏄粯璁ゆ垨绱拰鍒欒繘琛岀疮鍜屼互鍙婅幏鍙栧熀鍑嗙嚎
-        if(monitorQuery.getCategory() == null || monitorQuery.getCategory().equals(1)) {
+        if (monitorQuery.getCategory() == null || monitorQuery.getCategory().equals(1)) {
             int snapCount = 0;
             for (HomeFaceVO vo : results) {
                 if (vo.getSnapCount() != null) {
@@ -1170,7 +1704,8 @@
         return vo;
     }
 
-    private Query getQuery(List<String> deviceIds, String month) {
+    private Query getQuery(VideoExportForm exportForm) {
+        String month = exportForm.getMonth();
         // 灏嗗勾鏈堝瓧绗︿覆瑙f瀽涓篩earMonth瀵硅薄
         YearMonth yearMonth = YearMonth.parse(month);
         // 鑾峰彇褰撴湀鐨勭涓�澶�
@@ -1180,7 +1715,15 @@
         LocalDate end = nextMonth.atDay(1);
         //鑾峰彇杩欎釜鏈堜唤鐨勯儴闂ㄦ暟鎹�
         Query query = new Query(Criteria.where("mongoCreateTime").gte(start).lt(end));
-        query.addCriteria(Criteria.where("no").in(deviceIds));
+        if (!CollectionUtils.isEmpty(exportForm.getDeptIds()))
+            query.addCriteria(Criteria.where("deptId").in(exportForm.getDeptIds()));
+        if (exportForm.getDeptTag() != null) query.addCriteria(Criteria.where("deptTag").is(exportForm.getDeptTag()));
+        if (exportForm.getProvinceTag() != null)
+            query.addCriteria(Criteria.where("provinceTag").is(exportForm.getProvinceTag()));
+        if (exportForm.getImportantTag() != null)
+            query.addCriteria(Criteria.where("importantTag").is(exportForm.getImportantTag()));
+        if (exportForm.getImportantCommandImageTag() != null)
+            query.addCriteria(Criteria.where("importantCommandImageTag").is(exportForm.getImportantCommandImageTag()));
         return query;
     }
 
@@ -1188,6 +1731,7 @@
     private void setOnlineDaily(VideoDailyExp videoDailyExp, TMonitorResult result, List<TMonitorResult> onlines) throws NoSuchFieldException, IllegalAccessException {
         //涓�涓澶囧綋鏈堝湪绾挎儏鍐�
         List<TMonitorResult> onlineResult = onlines.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList());
+        videoDailyExp.setOnlineStateList(onlineResult);
         for (TMonitorResult monitorResult : onlineResult) {
             int dayOfMonth = monitorResult.getMongoCreateTime().getDayOfMonth();
             String online = "";
@@ -1203,12 +1747,12 @@
             field.setAccessible(true);
             field.set(videoDailyExp, online);
         }
+
+
     }
 
     //璁剧疆姣忔棩褰曞儚鏁版嵁
-    private void setRecordDaily(VideoDailyExp videoDailyExp, TMonitorResult result, List<RecordMetaDSumResult> records) throws NoSuchFieldException, IllegalAccessException {
-        //涓�涓澶囧綋鏈堝湪绾挎儏鍐�
-        List<RecordMetaDSumResult> recordResults = records.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList());
+    private void setRecordDaily(VideoDailyExp videoDailyExp, TMonitorResult result, List<RecordMetaDSumResult> recordResults) throws NoSuchFieldException, IllegalAccessException {
         for (RecordMetaDSumResult recordResult : recordResults) {
             int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime());
             Integer status = recordResult.getRecordStatus();
@@ -1228,17 +1772,16 @@
     }
 
     //璁剧疆姣忔棩褰曞儚缂哄け鏃堕暱鏁版嵁
-    private void setLoseDaily(VideoDailyExp videoDailyExp, TMonitorResult result, List<RecordMetaDSumResult> records) throws NoSuchFieldException, IllegalAccessException {
+    private void setLoseDaily(VideoDailyExp videoDailyExp, List<RecordMetaDSumResult> recordResults) throws NoSuchFieldException, IllegalAccessException {
         //涓�涓澶囧綋鏈堝湪绾挎儏鍐�
-        List<RecordMetaDSumResult> recordResults = records.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList());
         for (RecordMetaDSumResult recordResult : recordResults) {
-            int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime());
+            int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime());  //鑾峰彇鍚姩鏃ユ湡鏄綋鏈堢鍑犲ぉ
             //鍙嶅皠璧嬪�硷紝瀛楁缁熶竴瀹氫箟涓篸ay+1锛�2锛�3...
             Field field = videoDailyExp.getClass().getDeclaredField("day" + dayOfMonth);
             field.setAccessible(true);
             //闃叉杞崲涓虹瀛﹁鏁版硶
-            BigDecimal bigDecimal = BigDecimal.valueOf(recordResult.getMissDuration() == null ? 0 : recordResult.getMissDuration());
-            field.set(videoDailyExp, bigDecimal.toString());
+            BigDecimal bigDecimal = BigDecimal.valueOf(recordResult.getMissDuration() == null ? 0 : (recordResult.getMissDuration()) * 60);
+            field.set(videoDailyExp, bigDecimal.setScale(2, RoundingMode.HALF_UP).toString());
         }
     }
 }

--
Gitblit v1.8.0