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 | 415 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 399 insertions(+), 16 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 8aaa8bf..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 @@ -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; @@ -33,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; @@ -44,19 +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; @@ -65,17 +62,14 @@ 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.stream.Collectors; @@ -86,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 @@ -368,16 +365,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); @@ -560,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<>(); @@ -575,6 +579,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( @@ -584,6 +589,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); @@ -595,6 +601,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(() -> { @@ -618,6 +626,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("" + @@ -653,9 +663,11 @@ ); mysheet.add(excelExp); + return videoDailyExps; }, threadPoolTaskExecutor); futures.add(future); + map.put(deptId,future.join()); } // 鑾峰彇鍏ㄩ噺鏁版嵁 List<VideoDailyExp> totalExps = futures.stream() @@ -664,8 +676,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); + } + + } } @@ -816,6 +1169,7 @@ Function.identity(), // valueMapper锛岀洿鎺ヤ娇鐢ㄥ璞℃湰韬� (existing, replacement) -> existing // mergeFunction锛屽鏋滄湁閲嶅锛屼繚鐣欑涓�涓� )); + // 灏� Map 杞崲涓� List List<TMonitorResult> tMonitorResults = new ArrayList<>(uniqueResultsMap.values()); //鑾峰彇鍔ㄦ�佸垪鏁版嵁 @@ -961,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 @@ -975,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); } @@ -1082,6 +1444,24 @@ 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); } @@ -1351,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 = ""; @@ -1366,6 +1747,8 @@ field.setAccessible(true); field.set(videoDailyExp, online); } + + } //璁剧疆姣忔棩褰曞儚鏁版嵁 @@ -1392,13 +1775,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