From 17244068535a9163ab1fd6b3be2a794d9a857879 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期四, 15 八月 2024 17:48:28 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ycl-server/src/main/java/com/ycl/calculate/MonitorRegistrationCalculation.java | 145 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 145 insertions(+), 0 deletions(-) diff --git a/ycl-server/src/main/java/com/ycl/calculate/MonitorRegistrationCalculation.java b/ycl-server/src/main/java/com/ycl/calculate/MonitorRegistrationCalculation.java new file mode 100644 index 0000000..d654649 --- /dev/null +++ b/ycl-server/src/main/java/com/ycl/calculate/MonitorRegistrationCalculation.java @@ -0,0 +1,145 @@ +package com.ycl.calculate; + +import com.alibaba.fastjson2.JSONArray; +import com.ycl.platform.domain.entity.CheckIndexVideo; +import com.ycl.platform.domain.entity.TMonitor; +import com.ycl.platform.domain.entity.YwPoint; +import com.ycl.platform.domain.result.UY.VideoOnlineResult; +import com.ycl.platform.domain.vo.TMonitorVO; +import com.ycl.platform.mapper.CheckIndexVideoMapper; +import com.ycl.platform.mapper.TMonitorMapper; +import com.ycl.platform.service.ICheckIndexVideoService; +import constant.ApiConstants; +import constant.RedisConstant; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import utils.DateUtils; +import utils.StringUtils; + +import java.math.BigDecimal; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 璁$畻涓�鏈轰竴妗f敞鍐岀巼銆佹。妗堣�冩牳姣� + * 鑾峰彇鍒嗙渷鍘呫�佸尯鍩熺殑map<k,v> k涓篸eptId鎴栬�匬rovince_deptId + * 鏇存柊鎴栨柊澧� + */ +@Component +public class MonitorRegistrationCalculation extends IndexCalculationServe implements CalculationStrategy<TMonitorVO> { + @Autowired + private CheckIndexVideoMapper checkIndexVideoMapper; + @Autowired + private ICheckIndexVideoService checkIndexVideoService; + @Autowired + private RedisTemplate redisTemplate; + + //鍖哄煙瑙嗛鍦ㄧ嚎鐜囩殑鍐呴儴绫� + private static class AreaStats { + //璧勪骇搴撶櫥璁板湪鐢ㄦ暟 + int totalSites = 0; + //鏈敞鍐岀殑鏁伴噺 + int newSites = 0; + //鍏ㄥ勾鐣欏瓨鏁� + int allFiles = 0; + //褰撴棩妗f鏁� + int todayFiles = 0; + } + + @Override + public void calculate(List<TMonitorVO> list) { + if (CollectionUtils.isEmpty(list)) { + return; + } + //鑾峰緱鍥芥爣鐮佷负key鐨勮澶噈ap + Map<String, TMonitorVO> monitorMap = new HashMap<>(); + if(!CollectionUtils.isEmpty(list)){ + monitorMap = list.stream().collect(Collectors.toMap(TMonitorVO::getSerialNumber, Function.identity())); + } + //鑾峰彇鐪佸巺鍥芥爣鐮侀泦鍚� + List<String> provinceIds = getProvince(); + //鏈敞鍐岃澶� + Map<String,TMonitor> newMonitorMap = new HashMap<>(); + //Mongo涓�鏈轰竴妗e悓姝ysql鏃舵斁鍏edis + String json = (String) redisTemplate.opsForValue().get(RedisConstant.New_Monitor_Set); + if (!StringUtils.isEmpty(json)) { + List<TMonitor> newMonitors = JSONArray.parseArray(json, TMonitor.class); + if(!CollectionUtils.isEmpty(newMonitors)){ + newMonitorMap = newMonitors.stream().collect(Collectors.toMap(TMonitor::getSerialNumber, Function.identity())); + } + } + + //鑾峰彇鏄ㄦ棩mongo涓�鏈轰竴妗f暟閲� + List<String> todayMonitor = getMonitorFromMongo(); + Map<String, AreaStats> areaStatsMap = new HashMap<>(); + for (TMonitorVO result : list) { + TMonitorVO monitor = monitorMap.get(result.getSerialNumber()); + if (monitor == null) continue; + + String deptId = monitor.getDeptId().toString(); + updateAreaStats(areaStatsMap, deptId, result,newMonitorMap,todayMonitor); + // 澶勭悊鐪佸巺鏁版嵁 + if (!CollectionUtils.isEmpty(provinceIds) && provinceIds.contains(monitor.getSerialNumber())) { + String provinceKey = ApiConstants.Province + deptId; + updateAreaStats(areaStatsMap, provinceKey, result,newMonitorMap,todayMonitor); + } + } + + // 鏌ヨ鏄惁index琛ㄥ凡缁忓瓨鍦ㄤ粖鏃ユ暟鎹� + List<CheckIndexVideo> checkIndexVideoList = checkIndexVideoMapper.selectToday(DateUtils.getDate()); + List<CheckIndexVideo> checkIndexVideos = new ArrayList<>(); + areaStatsMap.forEach((deptId, stats) -> { + if (stats.totalSites > 0) { + CheckIndexVideo CheckIndexVideo = createOrUpdateCheckIndexVideo(deptId, stats, checkIndexVideoList); + if (CheckIndexVideo != null) { + checkIndexVideos.add(CheckIndexVideo); + } + } + }); + + checkIndexVideoService.saveOrUpdateBatch(checkIndexVideos); + } + + /** + * 绱鎬荤偣浣嶆暟銆佸湪绾跨偣浣嶆暟銆侀噸鐐圭偣浣嶆暟銆侀噸鐐圭偣浣嶅湪绾挎暟銆佹寚鎸ュ浘鍍忔暟銆佹寚鎸ュ浘鍍忓湪绾挎暟 + */ + private void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, TMonitorVO result,Map<String,TMonitor> newMonitors,List<String> todayMonitor) { + //杩斿洖瀵硅薄鐨勫紩鐢紝濡傛灉涓嶅瓨鍦ㄤ細鏀惧叆鏂扮殑key,value + AreaStats stats = areaStatsMap.computeIfAbsent(key, k -> new AreaStats()); + stats.totalSites++; + stats.allFiles++; + if(newMonitors.containsKey(result.getSerialNumber())){ + stats.newSites++; + } + if(todayMonitor.contains(result.getSerialNumber())){ + stats.todayFiles++; + } + } + + /** + * 瑙嗛鐐逛綅鍦ㄧ嚎鐜� + */ + private CheckIndexVideo createOrUpdateCheckIndexVideo(String key, AreaStats stats, List<CheckIndexVideo> checkIndexVideoList) { + CheckIndexVideo checkIndexVideo = getCheckIndex(key, checkIndexVideoList, CheckIndexVideo.class); + if (checkIndexVideo == null) { + return null; + } + //璋冪敤涓�鏈轰竴妗f敞鍐岀巼 + Map<String, Object> param = new HashMap<>(); + param.put("totalSites", stats.totalSites); + param.put("newSites", stats.newSites); + BigDecimal monitorRegistration = monitorRegistration(param); + checkIndexVideo.setMonitorRegistration(monitorRegistration); + //璋冪敤妗f鑰冩牳姣旇绠� + Map<String, Object> importantParam = new HashMap<>(); + param.put("allFiles", stats.allFiles); + param.put("todayFiles", stats.todayFiles); + BigDecimal archivesRate = archivesRate(importantParam); + checkIndexVideo.setArchivesRate(archivesRate); + + return checkIndexVideo; + } +} -- Gitblit v1.8.0