From 7fa07718de92093c6315c5cb37bbc8dd7cdafa3c Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期三, 25 十二月 2024 10:28:43 +0800
Subject: [PATCH] 考核积分修改、点位导出修改

---
 ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java |  140 +++++++++++++++++++++++++++++-----------------
 1 files changed, 89 insertions(+), 51 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 6fc3f24..b044f0c 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
@@ -352,8 +352,15 @@
         return tMonitorMapper.recoveryException(monitor);
     }
 
+    /**
+     *  鏌ongo鏌ユ煇涓湀璁惧鎬绘暟
+     *  鏌ョ湅宸ュ崟鏁伴噺鏌ョ湅寮傚父鐨勬暟
+     * @param monitorQuery 鏌ヨ鏉′欢
+     * @return
+     */
     @Override
     public Map<String, Object> home(HomeQuery monitorQuery) {
+
         Map<String, Object> dataMap = new HashMap<>();
         Map<String, Object> monthMap1 = new HashMap<>();
         Map<String, Object> monthMap2 = new HashMap<>();
@@ -610,7 +617,16 @@
             }
         }
         List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
-        Query query = getQuery(deviceIds, exportForm.getMonth());
+        // 灏嗗勾鏈堝瓧绗︿覆瑙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 query = new Query(Criteria.where("statTime").gte(start).lt(end));
+        query.addCriteria(Criteria.where("no").in(deviceIds));
         //鏈堜唤姣忔棩褰曞儚绾挎暟鎹�
         List<RecordMetaDSumResult> recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class);
         //鍏ㄩ噺琛�
@@ -686,7 +702,16 @@
             }
         }
         List<String> deviceIds = tMonitorResults.stream().map(BaseResult::getNo).collect(Collectors.toList());
-        Query query = getQuery(deviceIds, exportForm.getMonth());
+        // 灏嗗勾鏈堝瓧绗︿覆瑙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 query = new Query(Criteria.where("statTime").gte(start).lt(end));
+        query.addCriteria(Criteria.where("no").in(deviceIds));
         //鏈堜唤姣忔棩褰曞儚绾挎暟鎹�
         List<RecordMetaDSumResult> recordResult = mongoTemplate.find(query, RecordMetaDSumResult.class);
         //鍏ㄩ噺琛�
@@ -762,7 +787,7 @@
         MongoDatabase database = mongoTemplate.getDb();
         MongoCollection<Document> collection = database.getCollection("uy_record_meta_d_sum");
         Integer examineTag = monitorQuery.getExamineTag();
-        Document matchConditions = new Document("mongoCreateTime", new Document("$gte", startDate).append("$lte", endDate));
+        Document matchConditions = new Document("statTime", new Document("$gte", startDate).append("$lte", endDate));
         // 鏍规嵁examineTag鐨勫�煎姩鎬佹坊鍔犻澶栫殑鏉′欢
         if (examineTag != null && examineTag.equals(1)) {
             matchConditions.append("provinceTag", true);
@@ -772,7 +797,7 @@
         // 鏋勫缓鑱氬悎绠¢亾
         List<Document> pipeline = Arrays.asList(
                 new Document("$match", matchConditions),
-                new Document("$group", new Document("_id", "$mongoCreateTime")
+                new Document("$group", new Document("_id", "$statTime")
                         .append("normalCount", new Document("$sum",
                                 new Document("$cond", Arrays.asList(
                                         new Document("$eq", Arrays.asList("$recordStatus", 1)),
@@ -879,7 +904,7 @@
                 String type = car.replaceAll("3", "浜鸿劯");
                 monitor.setCameraFunType(type);
             }
-            StringBuilder tag = new StringBuilder("" + (monitor.getProvinceTag() ? "鐪佸巺銆�" : "") + (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();
@@ -894,7 +919,15 @@
             monitor.setTag(tag.toString());
         });
         ExcelUtil<TMonitorExp> util = new ExcelUtil<>(TMonitorExp.class);
-        util.exportExcel(response, monitors, "2".equals(tMonitor.getCameraFunType()) ? "杞﹁締" : "浜鸿劯");
+        String sheetName = "";
+        if("1".equals(tMonitor.getCameraFunType())){
+            sheetName = "瑙嗛";
+        }else if("2".equals(tMonitor.getCameraFunType())){
+            sheetName = "杞﹁締";
+        }else if("3".equals(tMonitor.getCameraFunType())){
+            sheetName = "浜鸿劯";
+        }
+        util.exportExcel(response, monitors,sheetName);
     }
 
 
@@ -950,7 +983,6 @@
             results.add(homecarVO);
         }
 
-        //TODO锛氬湪绾夸慨鏀癸紝闇�瑕佹妸妫�娴嬫捣搴蜂紭浜戞娴嬬殑缁撴灉瀛樺叆mongo锛宮ongo鏌ョ偣浣嶅湪绾�
         MongoCollection<Document> onlineCollection = database.getCollection("t_monitor_online");
         // 鏋勫缓鍩烘湰鐨�$match鏉′欢
         List<Document> onlineMatch = new ArrayList<>();
@@ -981,30 +1013,33 @@
         Map<String, Object> resultMap = new HashMap<>();
         //鎸夋椂闂存帓搴�
         results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList());
-        int snapCount = 0;
-        for (HomeCarVO vo : results) {
-            if (vo.getSnapCount() != null) {
-                snapCount += vo.getSnapCount();
+        //濡傛灉鏄粯璁ゆ垨绱拰鍒欒繘琛岀疮鍜屼互鍙婅幏鍙栧熀鍑嗙嚎
+        if(monitorQuery.getCategory() == null || monitorQuery.getCategory().equals(1)) {
+            int snapCount = 0;
+            for (HomeCarVO vo : results) {
+                if (vo.getSnapCount() != null) {
+                    snapCount += vo.getSnapCount();
+                }
+                vo.setSnapCount(snapCount);
             }
-            vo.setSnapCount(snapCount);
+            //浠庡瓧鍏歌幏鍙栧熀鍑嗙嚎
+            List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
+            String condition;
+            if (examineTag != null && examineTag == 1) {
+                condition = "car_province_baseLine";
+            } else if (examineTag != null && examineTag == 2) {
+                condition = "car_dept_baseLine";
+            } else {
+                condition = "car_all_baseLine";
+            }
+
+            Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
+            if (first.isPresent()) {
+                SysDictData sysDictData = first.get();
+                resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
+            }
         }
         resultMap.put("list", results);
-        //浠庡瓧鍏歌幏鍙栧熀鍑嗙嚎
-        List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
-        String condition;
-        if (examineTag != null && examineTag == 1) {
-            condition = "car_province_baseLine";
-        } else if (examineTag != null && examineTag == 2) {
-            condition = "car_dept_baseLine";
-        } else {
-            condition = "car_all_baseLine";
-        }
-
-        Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
-        if (first.isPresent()) {
-            SysDictData sysDictData = first.get();
-            resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
-        }
         return resultMap;
     }
 
@@ -1089,32 +1124,35 @@
             HomeFaceVO vo = findOrCreateVO(doc, results, HomeFaceVO.class);
             vo.setOnline(doc.getInteger("onlineCount"));
         }
+        Map<String, Object> resultMap = new HashMap<>();
         //鎸夋椂闂存帓搴�
         results = results.stream().sorted(Comparator.comparing(BaseHomeVO::getCreateDate)).collect(Collectors.toList());
-        int snapCount = 0;
-        for (HomeFaceVO vo : results) {
-            if (vo.getSnapCount() != null) {
-                snapCount += vo.getSnapCount();
+        //濡傛灉鏄粯璁ゆ垨绱拰鍒欒繘琛岀疮鍜屼互鍙婅幏鍙栧熀鍑嗙嚎
+        if(monitorQuery.getCategory() == null || monitorQuery.getCategory().equals(1)) {
+            int snapCount = 0;
+            for (HomeFaceVO vo : results) {
+                if (vo.getSnapCount() != null) {
+                    snapCount += vo.getSnapCount();
+                }
+                vo.setSnapCount(snapCount);
             }
-            vo.setSnapCount(snapCount);
+            //浠庡瓧鍏歌幏鍙栧熀鍑嗙嚎
+            List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
+            String condition;
+            if (examineTag != null && examineTag == 1) {
+                condition = "face_province_baseLine";
+            } else if (examineTag != null && examineTag == 2) {
+                condition = "face_dept_baseLine";
+            } else {
+                condition = "face_all_baseLine";
+            }
+            Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
+            if (first.isPresent()) {
+                SysDictData sysDictData = first.get();
+                resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
+            }
         }
-        Map<String, Object> resultMap = new HashMap<>();
         resultMap.put("list", results);
-        //浠庡瓧鍏歌幏鍙栧熀鍑嗙嚎
-        List<SysDictData> baseLines = dictDataMapper.selectDictDataByType("home_baseLine");
-        String condition;
-        if (examineTag != null && examineTag == 1) {
-            condition = "face_province_baseLine";
-        } else if (examineTag != null && examineTag == 2) {
-            condition = "face_dept_baseLine";
-        } else {
-            condition = "face_all_baseLine";
-        }
-        Optional<SysDictData> first = baseLines.stream().filter(sysDictData -> condition.equals(sysDictData.getDictLabel())).findFirst();
-        if (first.isPresent()) {
-            SysDictData sysDictData = first.get();
-            resultMap.put("baseLine", Integer.valueOf(sysDictData.getDictValue()));
-        }
         return resultMap;
     }
 
@@ -1172,7 +1210,7 @@
         //涓�涓澶囧綋鏈堝湪绾挎儏鍐�
         List<RecordMetaDSumResult> recordResults = records.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList());
         for (RecordMetaDSumResult recordResult : recordResults) {
-            int dayOfMonth = recordResult.getMongoCreateTime().getDayOfMonth();
+            int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime());
             Integer status = recordResult.getRecordStatus();
             String text = "";
             if (ApiConstants.UY_RecordStatus_Interval.equals(status)) {
@@ -1194,7 +1232,7 @@
         //涓�涓澶囧綋鏈堝湪绾挎儏鍐�
         List<RecordMetaDSumResult> recordResults = records.stream().filter(online -> online.getNo().equals(result.getNo())).collect(Collectors.toList());
         for (RecordMetaDSumResult recordResult : recordResults) {
-            int dayOfMonth = recordResult.getMongoCreateTime().getDayOfMonth();
+            int dayOfMonth = DateUtils.getDayOfMonth(recordResult.getStatTime());
             //鍙嶅皠璧嬪�硷紝瀛楁缁熶竴瀹氫箟涓篸ay+1锛�2锛�3...
             Field field = videoDailyExp.getClass().getDeclaredField("day" + dayOfMonth);
             field.setAccessible(true);

--
Gitblit v1.8.0