| | |
| | | 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.result.UY.MonitorQualifyResult; |
| | | 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.CheckThreadConstants; |
| | | import constant.RedisConstant; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 计算一机一档注册率、档案考核比 |
| | |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class MonitorRegistrationCalculation extends IndexCalculationServe implements CalculationStrategy<TMonitorVO> { |
| | | public class MonitorRegistrationCalculation extends IndexCalculationServe<MonitorQualifyResult, MonitorRegistrationCalculation.AreaStats> implements CalculationStrategy<MonitorQualifyResult> { |
| | | @Autowired |
| | | private CheckIndexVideoMapper checkIndexVideoMapper; |
| | | @Autowired |
| | | private ICheckIndexVideoService checkIndexVideoService; |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | private TMonitorMapper monitorMapper; |
| | | |
| | | //区域视频在线率的内部类 |
| | | private static class AreaStats { |
| | | //资产库登记在用数 |
| | | int totalSites = 0; |
| | | protected static class AreaStats { |
| | | //当日档案数 |
| | | int todayFiles = 0; |
| | | //未注册的数量 |
| | | int newSites = 0; |
| | | //全年留存数 |
| | | int allFiles = 0; |
| | | //当日档案数 |
| | | int todayFiles = 0; |
| | | } |
| | | |
| | | @Override |
| | | public void calculate(List<TMonitorVO> list) { |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | log.info("数据为空"); |
| | | return; |
| | | } |
| | | //获得国标码为key的设备map |
| | | 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一机一档同步Mysql时放入Redis |
| | | 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())); |
| | | } |
| | | } |
| | | public void calculate(List<MonitorQualifyResult> list) { |
| | | //获取分区域的指标数量 |
| | | Map<String, MonitorRegistrationCalculation.AreaStats> areaStatsMap = getAreaStatsMap(list); |
| | | if (areaStatsMap == null) return; |
| | | |
| | | //获取昨日mongo一机一档数量 |
| | | 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); |
| | | //查数据库补充全年留存数 |
| | | List<TMonitorVO> monitorVOS = monitorMapper.selectMonitorVOList(); |
| | | areaStatsMap.forEach((key,areaStats)->{ |
| | | if(key.startsWith(ApiConstants.Province)){ |
| | | long count = monitorVOS.stream().filter(vo -> ApiConstants.TRUE.equals(vo.getProvinceTag())) |
| | | .filter(vo -> key.split("_")[1].equals(vo.getDeptId() + "")).count(); |
| | | areaStats.allFiles = Integer.parseInt(count+""); |
| | | }else { |
| | | long count = monitorVOS.stream().filter(vo -> key.equals(vo.getDeptId() + "")).count(); |
| | | areaStats.allFiles = Integer.parseInt(count+""); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // 查询是否index表已经存在今日数据 |
| | | List<CheckIndexVideo> checkIndexVideoList = checkIndexVideoMapper.selectToday(DateUtils.getDate()); |
| | | List<CheckIndexVideo> checkIndexVideos = new ArrayList<>(); |
| | | areaStatsMap.forEach((key, stats) -> { |
| | | if (stats.totalSites > 0) { |
| | | if (stats.todayFiles > 0) { |
| | | CheckIndexVideo checkIndexVideo = createOrUpdateCheckIndexVideo(key, stats, checkIndexVideoList); |
| | | if (checkIndexVideo != null) { |
| | | checkIndexVideos.add(checkIndexVideo); |
| | |
| | | /** |
| | | * 累计总点位数、在线点位数、重点点位数、重点点位在线数、指挥图像数、指挥图像在线数 |
| | | */ |
| | | private void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, TMonitorVO result, Map<String, TMonitor> newMonitors, List<String> todayMonitor) { |
| | | @Override |
| | | public void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, MonitorQualifyResult result) { |
| | | //返回对象的引用,如果不存在会放入新的key,value |
| | | AreaStats stats = areaStatsMap.computeIfAbsent(key, k -> new AreaStats()); |
| | | stats.totalSites++; |
| | | stats.allFiles++; |
| | | if (newMonitors.containsKey(result.getSerialNumber())) { |
| | | stats.todayFiles++; |
| | | if (result.getNewDevice()!=null && result.getNewDevice()) { |
| | | stats.newSites++; |
| | | } |
| | | if (todayMonitor.contains(result.getSerialNumber())) { |
| | | stats.todayFiles++; |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | //调用一机一档注册率 |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("totalSites", stats.totalSites); |
| | | param.put("totalSites", stats.todayFiles); |
| | | param.put("newSites", stats.newSites); |
| | | BigDecimal monitorRegistration = monitorRegistration(param); |
| | | checkIndexVideo.setMonitorRegistration(monitorRegistration); |