| | |
| | | import com.ycl.platform.service.ICheckIndexFaceService; |
| | | import com.ycl.platform.service.ITMonitorService; |
| | | import com.ycl.system.mapper.SysConfigMapper; |
| | | import constant.ApiConstants; |
| | | import constant.CheckConstants; |
| | | import constant.CheckSnapCountConstants; |
| | | import constant.*; |
| | | 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 java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | |
| | | private SysConfigMapper sysConfigMapper; |
| | | @Autowired |
| | | private TMonitorMapper monitorMapper; |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | //区域人脸点位在线指标的内部类 |
| | | private static class AreaStats { |
| | |
| | | List<String> provinceIds = getProvince(); |
| | | |
| | | Map<String, AreaStats> areaStatsMap = new HashMap<>(); |
| | | |
| | | // 获取当前日期 |
| | | LocalDate today = LocalDate.now(); |
| | | // 获取本月的第一天 |
| | | LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth()); |
| | | // 判断今天是否是本月的第一天 |
| | | if (today.equals(firstDayOfMonth)) { |
| | | // 如果是,则清除Redis中记录中断次数的数据 |
| | | redisTemplate.delete(RedisConstant.Check_Face_ViewConnect); |
| | | } |
| | | for (SnapshotDataMonitorResult result : list) { |
| | | TMonitorVO monitor = monitorMap.get(result.getExternalIndexCode()); |
| | | if (monitor == null) continue; |
| | |
| | | return null; |
| | | } |
| | | //调用点位在线计算方法 |
| | | Map<String, Object> siteOnlineParam = new HashMap<>(); |
| | | siteOnlineParam.put("totalSites", stats.totalSites); |
| | | siteOnlineParam.put("onlineSites", stats.onlineSites); |
| | | BigDecimal siteOnline = siteOnline(siteOnlineParam); |
| | | checkIndexFace.setSiteOnline(siteOnline); |
| | | if (stats.totalSites >= CheckThreadConstants.Check_Face_SiteOnline) { |
| | | Map<String, Object> siteOnlineParam = new HashMap<>(); |
| | | siteOnlineParam.put("totalSites", stats.totalSites); |
| | | siteOnlineParam.put("onlineSites", stats.onlineSites); |
| | | BigDecimal siteOnline = siteOnline(siteOnlineParam); |
| | | checkIndexFace.setSiteOnline(siteOnline); |
| | | } else { |
| | | checkIndexFace.setSiteOnline(BigDecimal.ZERO); |
| | | } |
| | | //视图库对接稳定性 |
| | | BigDecimal avgCount = key.startsWith(ApiConstants.Province) ? cityCountAvg : countyCountAvg; |
| | | Map<String, Object> viewConnectParam = new HashMap<>(); |
| | | viewConnectParam.put("totalDataSum", stats.totalDataSum); |
| | | viewConnectParam.put("avgCount", avgCount); |
| | | BigDecimal viewConnectStability = viewConnectStability(viewConnectParam); |
| | | checkIndexFace.setViewConnectStability(viewConnectStability); |
| | | //Redis记录该区县当月无数据上传次数 |
| | | Integer noDateCount = (Integer) redisTemplate.opsForHash().get(RedisConstant.Check_Face_ViewConnect, key); |
| | | // 如果值为null,则初始化为0 |
| | | if (noDateCount == null) { |
| | | noDateCount = 0; |
| | | } |
| | | Double deductScore = 0.1 * noDateCount; |
| | | if (stats.totalDataSum != 0) { |
| | | BigDecimal avgCount = key.startsWith(ApiConstants.Province) ? cityCountAvg : countyCountAvg; |
| | | Map<String, Object> viewConnectParam = new HashMap<>(); |
| | | viewConnectParam.put("totalDataSum", stats.totalDataSum); |
| | | viewConnectParam.put("avgCount", avgCount); |
| | | BigDecimal viewConnectStability = viewConnectStability(viewConnectParam); |
| | | viewConnectStability = viewConnectStability.subtract(new BigDecimal(deductScore)).max(BigDecimal.ZERO).min(BigDecimal.ONE); |
| | | checkIndexFace.setViewConnectStability(viewConnectStability); |
| | | } else { |
| | | noDateCount++; |
| | | } |
| | | // 将新的值放回Hash中 |
| | | redisTemplate.opsForHash().put(RedisConstant.Check_Face_ViewConnect, key, noDateCount); |
| | | return checkIndexFace; |
| | | } |
| | | } |