From a4a904acc5f4de80d30eafe19dd97f3cc8f56a0b Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期一, 29 九月 2025 17:17:34 +0800
Subject: [PATCH] 新问题 25-9-28
---
ycl-server/src/main/java/com/ycl/platform/service/impl/TMonitorServiceImpl.java | 447 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 430 insertions(+), 17 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 3cc7abe..beebaa8 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
@@ -3,14 +3,11 @@
import annotation.DataScope;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.mongodb.ExplainVerbosity;
import com.mongodb.client.AggregateIterable;
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;
@@ -37,7 +34,6 @@
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;
@@ -45,13 +41,12 @@
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;
@@ -67,18 +62,16 @@
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.BinaryOperator;
import java.util.function.Function;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@@ -88,6 +81,7 @@
* @date 2024-03-04
*/
@Service
+@Slf4j
public class TMonitorServiceImpl extends ServiceImpl<TMonitorMapper, TMonitor> implements ITMonitorService {
@Autowired
private TMonitorMapper tMonitorMapper;
@@ -372,16 +366,21 @@
*/
@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);
@@ -564,6 +563,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<>();
@@ -579,6 +580,7 @@
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(
@@ -588,6 +590,7 @@
));
// 灏� 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);
@@ -599,6 +602,8 @@
tMonitorResult.setDynamicColumnList(map.get(pointId));
}
}
+ //瀛樻斁鍖哄煙 涓� 璁惧鍒楄〃 map key涓� 鍖哄煙
+ Map<Integer, List<VideoDailyExp>> map = new HashMap<>();
List<CompletableFuture<List<VideoDailyExp>>> futures = new ArrayList<>();
for (Integer deptId : exportForm.getDeptIds()) {
CompletableFuture<List<VideoDailyExp>> future = CompletableFuture.supplyAsync(() -> {
@@ -622,6 +627,8 @@
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("" +
@@ -657,9 +664,11 @@
);
mysheet.add(excelExp);
+
return videoDailyExps;
}, threadPoolTaskExecutor);
futures.add(future);
+ map.put(deptId,future.join());
}
// 鑾峰彇鍏ㄩ噺鏁版嵁
List<VideoDailyExp> totalExps = futures.stream()
@@ -668,8 +677,349 @@
.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);
+ }
+
+ }
}
@@ -811,6 +1161,8 @@
exportForm.setDeptIds(deptIds);
}
Query query = getQuery(exportForm);
+
+
//鏈堜唤姣忔棩鍦ㄧ嚎鏁版嵁
List<TMonitorResult> onlineResult = mongoTemplate.find(query, TMonitorResult.class);
// 浣跨敤 Collectors.toMap 鍘婚噸锛屼繚鐣欐瘡涓� No 鐨勭涓�涓亣鍒扮殑鍏冪礌
@@ -820,6 +1172,7 @@
Function.identity(), // valueMapper锛岀洿鎺ヤ娇鐢ㄥ璞℃湰韬�
(existing, replacement) -> existing // mergeFunction锛屽鏋滄湁閲嶅锛屼繚鐣欑涓�涓�
));
+
// 灏� Map 杞崲涓� List
List<TMonitorResult> tMonitorResults = new ArrayList<>(uniqueResultsMap.values());
//鑾峰彇鍔ㄦ�佸垪鏁版嵁
@@ -919,6 +1272,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)) {
//濡傛灉涓虹┖鏌ユ湰鏈堢殑鏁版嵁
@@ -945,13 +1299,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),
@@ -964,6 +1335,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,
@@ -979,6 +1357,8 @@
homeVideoVO.setCreateDate(doc.getDate("_id"));
homeVideoVO.setIntegrityNum(doc.getInteger("normalCount"));
homeVideoVO.setLoseNum(doc.getInteger("loseCount"));
+ homeVideoVO.setErrNum(doc.getInteger("errCount"));
+
results.add(homeVideoVO);
}
@@ -992,8 +1372,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)),
@@ -1007,6 +1403,10 @@
))
)
);
+ //鎺掗櫎鍗″彛闆嗗悎
+
+
+
// 鎵ц鑱氬悎鏌ヨ骞惰幏鍙栫粨鏋�
AggregateIterable<Document> onlineResult = onlineCollection.aggregate(onlinePipeline);
for (Document doc : onlineResult) {
@@ -1138,10 +1538,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(
@@ -1166,6 +1569,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(
@@ -1244,6 +1649,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");
@@ -1254,6 +1660,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(
@@ -1280,6 +1688,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(
@@ -1373,6 +1783,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 = "";
@@ -1388,6 +1799,8 @@
field.setAccessible(true);
field.set(videoDailyExp, online);
}
+
+
}
//璁剧疆姣忔棩褰曞儚鏁版嵁
@@ -1414,13 +1827,13 @@
private void setLoseDaily(VideoDailyExp videoDailyExp, List<RecordMetaDSumResult> recordResults) throws NoSuchFieldException, IllegalAccessException {
//涓�涓澶囧綋鏈堝湪绾挎儏鍐�
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