ycl-server/src/main/java/com/ycl/calculate/CarDataIntegrityCalculation.java
New file @@ -0,0 +1,126 @@ package com.ycl.calculate; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ycl.platform.base.CheckIndex; import com.ycl.platform.domain.entity.CheckIndexCar; import com.ycl.platform.domain.entity.TMonitor; import com.ycl.platform.domain.result.HK.CrossDetailResult; import com.ycl.platform.domain.result.HK.DataIntegrityMonitoringResult; import com.ycl.platform.mapper.CheckIndexCarMapper; import com.ycl.platform.mapper.TMonitorMapper; import com.ycl.platform.service.ICheckIndexCarService; import com.ycl.platform.service.ITMonitorService; import com.ycl.system.mapper.SysConfigMapper; import constant.ApiConstants; import constant.CheckConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import utils.DateUtils; import java.math.BigDecimal; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; /** * 计算车辆数据完整性 * 获取分省厅、区域的map<k,v> k为deptId或者Province_deptId * 更新或新增 */ @Component public class CarDataIntegrityCalculation extends IndexCalculationServe implements CalculationStrategy<DataIntegrityMonitoringResult> { @Autowired private CheckIndexCarMapper checkIndexCarMapper; @Autowired private ITMonitorService monitorService; @Autowired private ICheckIndexCarService checkIndexCarService; //区域车辆信息采集准确率的内部类 private static class AreaStats { int totalSites = 0; int importantTotalSites = 0; int integritySites = 0; int importantIntegritySites = 0; } @Override public void calculate(List<DataIntegrityMonitoringResult> list) { if (CollectionUtils.isEmpty(list)) { return; } //返回以国标码为key的设备map //TODO:monitor去掉了deptId Map<String, TMonitor> monitorMap = monitorService.list(new QueryWrapper<TMonitor>() .in("serial_number", list.stream().map(DataIntegrityMonitoringResult::getExternalIndexCode).collect(Collectors.toList()))) .stream().collect(Collectors.toMap(TMonitor::getSerialNumber, Function.identity())); //获取省厅国标码集合 List<String> provinceIds = getProvince(); //获取重点点位集合 List<String> importantIds = getImportant(); Map<String, AreaStats> areaStatsMap = new HashMap<>(); for (DataIntegrityMonitoringResult result : list) { TMonitor monitor = monitorMap.get(result.getExternalIndexCode()); if (monitor == null) continue; String deptId = monitor.getDeptId().toString(); updateAreaStats(areaStatsMap, deptId, result, importantIds); // 处理省厅数据 if (!CollectionUtils.isEmpty(provinceIds) && provinceIds.contains(monitor.getSerialNumber())) { String provinceKey = "Province_" + deptId; updateAreaStats(areaStatsMap, provinceKey, result, importantIds); } } // 查询是否index表已经存在今日数据 List<CheckIndexCar> checkIndexCarList = checkIndexCarMapper.selectToday(DateUtils.getDate()); List<CheckIndexCar> checkIndexCars = new ArrayList<>(); areaStatsMap.forEach((deptId, stats) -> { if (stats.totalSites > 0) { CheckIndexCar checkIndexCar = createOrUpdateCheckIndexCar(deptId, stats, checkIndexCarList); checkIndexCars.add(checkIndexCar); } }); checkIndexCarService.saveOrUpdateBatch(checkIndexCars); } /** * 累计抓拍数据完整设备数和设备总数,区分重点点位 */ private void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, DataIntegrityMonitoringResult result, List<String> importantIds) { //返回对象的引用,如果不存在会放入新的key,value AreaStats stats = areaStatsMap.computeIfAbsent(key, k -> new AreaStats()); stats.totalSites++; //90%及以上数据合格则此车辆卡口设备被视为抓拍数据完整 if(result.getMainNoIntegrityPercent() <= 0.1){ stats.integritySites++; } //重点点位为六项属性 if(importantIds.contains(key)){ stats.importantTotalSites++; if(result.getNoIntegrityPercent() <= 0.1){ stats.importantIntegritySites++; } } } /** * 车辆信息采集正确率 */ private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, List<CheckIndexCar> checkIndexCarList) { CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList); //调用计算方法 Map<String, Object> param = new HashMap<>(); param.put("totalSites", stats.totalSites); param.put("importantTotalSites", stats.importantTotalSites); param.put("integritySites", stats.integritySites); param.put("importantIntegritySites", stats.importantIntegritySites); BigDecimal dataIntegrity = dataIntegrity(param); checkIndexCar.setVehicleCaptureIntegrity(dataIntegrity); return checkIndexCar; } } ycl-server/src/main/java/com/ycl/calculate/CarInFoAccuracyCalculation.java
@@ -35,11 +35,7 @@ @Autowired private CheckIndexCarMapper checkIndexCarMapper; @Autowired private SysConfigMapper sysConfigMapper; @Autowired private ITMonitorService monitorService; @Autowired private TMonitorMapper monitorMapper; @Autowired private ICheckIndexCarService checkIndexCarService; @@ -108,28 +104,12 @@ * 车辆信息采集正确率 */ private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, List<CheckIndexCar> checkIndexCarList) { CheckIndexCar checkIndexCar; // 检查是否已存在今日数据 Optional<CheckIndexCar> existingCar = checkIndexCarList.stream() .filter(car -> key.equals(car.getDeptId().toString()) && (key.startsWith("Province_") ? CheckConstants.Examine_Tag_City.equals(car.getExamineTag()) : CheckConstants.Examine_Tag_County.equals(car.getExamineTag()))) .findFirst(); if (existingCar.isPresent()) { checkIndexCar = existingCar.get(); } else { checkIndexCar = new CheckIndexCar(); checkIndexCar.setDeptId(key.startsWith("Province_") ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); checkIndexCar.setExamineTag(key.startsWith("Province_") ? CheckConstants.Examine_Tag_City : CheckConstants.Examine_Tag_County); checkIndexCar.setCreateTime(new Date()); } CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList); //调用计算方法 Map<String, Object> siteOnlineParam = new HashMap<>(); siteOnlineParam.put("totalSites", stats.totalSites); siteOnlineParam.put("qualifySite", stats.qualifySite); BigDecimal infoAccuracy = infoAccuracy(siteOnlineParam); Map<String, Object> param = new HashMap<>(); param.put("totalSites", stats.totalSites); param.put("qualifySite", stats.qualifySite); BigDecimal infoAccuracy = infoAccuracy(param); checkIndexCar.setVehicleInformationCollectionAccuracy(infoAccuracy); return checkIndexCar; } ycl-server/src/main/java/com/ycl/calculate/CarSiteOnlineCalculation.java
@@ -115,23 +115,7 @@ /** 车辆点位在线率和视图库对接稳定性 */ private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, BigDecimal cityCountAvg, BigDecimal countyCountAvg, List<CheckIndexCar> checkIndexCarList) { CheckIndexCar checkIndexCar; // 检查是否已存在今日数据 Optional<CheckIndexCar> existingCar = checkIndexCarList.stream() .filter(car -> key.equals(car.getDeptId().toString()) && (key.startsWith("Province_") ? CheckConstants.Examine_Tag_City.equals(car.getExamineTag()) : CheckConstants.Examine_Tag_County.equals(car.getExamineTag()))) .findFirst(); if (existingCar.isPresent()) { checkIndexCar = existingCar.get(); } else { checkIndexCar = new CheckIndexCar(); checkIndexCar.setDeptId(key.startsWith("Province_") ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); checkIndexCar.setExamineTag(key.startsWith("Province_") ? CheckConstants.Examine_Tag_City : CheckConstants.Examine_Tag_County); checkIndexCar.setCreateTime(new Date()); } CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList); //调用点位在线计算方法 Map<String, Object> siteOnlineParam = new HashMap<>(); siteOnlineParam.put("totalSites", stats.totalSites); ycl-server/src/main/java/com/ycl/calculate/CarSnapshotDelayCalculation.java
@@ -35,8 +35,6 @@ @Autowired private CheckIndexCarMapper checkIndexCarMapper; @Autowired private SysConfigMapper sysConfigMapper; @Autowired private ITMonitorService monitorService; @Autowired private ICheckIndexCarService checkIndexCarService; @@ -110,24 +108,7 @@ * 车辆点位在线率和视图库对接稳定性 */ private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, List<CheckIndexCar> checkIndexCarList) { CheckIndexCar checkIndexCar; // 检查是否已存在今日数据 Optional<CheckIndexCar> existingCar = checkIndexCarList.stream() .filter(car -> key.equals(car.getDeptId().toString()) && (key.startsWith("Province_") ? CheckConstants.Examine_Tag_City.equals(car.getExamineTag()) : CheckConstants.Examine_Tag_County.equals(car.getExamineTag()))) .findFirst(); if (existingCar.isPresent()) { checkIndexCar = existingCar.get(); } else { checkIndexCar = new CheckIndexCar(); checkIndexCar.setDeptId(key.startsWith("Province_") ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); checkIndexCar.setExamineTag(key.startsWith("Province_") ? CheckConstants.Examine_Tag_City : CheckConstants.Examine_Tag_County); checkIndexCar.setCreateTime(new Date()); } CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList); //调用抓拍上传及时性计算方法 Map<String, Object> param = new HashMap<>(); param.put("totalCount", stats.totalCount); ycl-server/src/main/java/com/ycl/calculate/FaceInFoAccuracyCalculation.java
@@ -33,11 +33,7 @@ @Autowired private ICheckIndexFaceService checkIndexFaceService; @Autowired private SysConfigMapper sysConfigMapper; @Autowired private ITMonitorService monitorService; @Autowired private TMonitorMapper monitorMapper; //区域车辆信息采集准确率的内部类 private static class AreaStats { @@ -104,28 +100,12 @@ * 车辆信息采集正确率 */ private CheckIndexFace createOrUpdateCheckIndexFace(String key, AreaStats stats, List<CheckIndexFace> checkIndexFaceList) { CheckIndexFace checkIndexFace; // 检查是否已存在今日数据 Optional<CheckIndexFace> existingFace = checkIndexFaceList.stream() .filter(car -> key.equals(car.getDeptId().toString()) && (key.startsWith("Province_") ? CheckConstants.Examine_Tag_City.equals(car.getExamineTag()) : CheckConstants.Examine_Tag_County.equals(car.getExamineTag()))) .findFirst(); if (existingFace.isPresent()) { checkIndexFace = existingFace.get(); } else { checkIndexFace = new CheckIndexFace(); checkIndexFace.setDeptId(key.startsWith("Province_") ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); checkIndexFace.setExamineTag(key.startsWith("Province_") ? CheckConstants.Examine_Tag_City : CheckConstants.Examine_Tag_County); checkIndexFace.setCreateTime(new Date()); } CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList); //调用计算方法 Map<String, Object> siteOnlineParam = new HashMap<>(); siteOnlineParam.put("totalSites", stats.totalSites); siteOnlineParam.put("qualifySite", stats.qualifySite); BigDecimal infoAccuracy = infoAccuracy(siteOnlineParam); Map<String, Object> param = new HashMap<>(); param.put("totalSites", stats.totalSites); param.put("qualifySite", stats.qualifySite); BigDecimal infoAccuracy = infoAccuracy(param); checkIndexFace.setFaceInformationCollectionAccuracy(infoAccuracy); return checkIndexFace; } ycl-server/src/main/java/com/ycl/calculate/FaceSiteOnlineCalculation.java
@@ -115,24 +115,7 @@ //车辆点位在线率和视图库对接稳定性 private CheckIndexFace createOrUpdateCheckIndexFace(String key, AreaStats stats, BigDecimal cityCountAvg, BigDecimal countyCountAvg, List<CheckIndexFace> checkIndexFaceList) { CheckIndexFace checkIndexFace; // 检查是否已存在今日数据 Optional<CheckIndexFace> existingFace = checkIndexFaceList.stream() .filter(face -> key.equals(face.getDeptId().toString()) && (key.startsWith("Province_") ? CheckConstants.Examine_Tag_City.equals(face.getExamineTag()) : CheckConstants.Examine_Tag_County.equals(face.getExamineTag()))) .findFirst(); if (existingFace.isPresent()) { checkIndexFace = existingFace.get(); } else { checkIndexFace = new CheckIndexFace(); checkIndexFace.setDeptId(key.startsWith("Province_") ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); checkIndexFace.setExamineTag(key.startsWith("Province_") ? CheckConstants.Examine_Tag_City : CheckConstants.Examine_Tag_County); checkIndexFace.setCreateTime(new Date()); } CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList); //调用点位在线计算方法 Map<String, Object> siteOnlineParam = new HashMap<>(); siteOnlineParam.put("totalSites", stats.totalSites); ycl-server/src/main/java/com/ycl/calculate/FaceSnapshotDelayCalculation.java
@@ -30,8 +30,6 @@ @Autowired private CheckIndexFaceMapper checkIndexFaceMapper; @Autowired private SysConfigMapper sysConfigMapper; @Autowired private ITMonitorService monitorService; @Autowired private ICheckIndexFaceService checkIndexFaceService; @@ -105,24 +103,7 @@ * 车辆点位在线率和视图库对接稳定性 */ private CheckIndexFace createOrUpdateCheckIndexFace(String key, AreaStats stats, List<CheckIndexFace> checkIndexFaceList) { CheckIndexFace checkIndexFace; // 检查是否已存在今日数据 Optional<CheckIndexFace> existingFace = checkIndexFaceList.stream() .filter(face -> key.equals(face.getDeptId().toString()) && (key.startsWith("Province_") ? CheckConstants.Examine_Tag_City.equals(face.getExamineTag()) : CheckConstants.Examine_Tag_County.equals(face.getExamineTag()))) .findFirst(); if (existingFace.isPresent()) { checkIndexFace = existingFace.get(); } else { checkIndexFace = new CheckIndexFace(); checkIndexFace.setDeptId(key.startsWith("Province_") ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); checkIndexFace.setExamineTag(key.startsWith("Province_") ? CheckConstants.Examine_Tag_City : CheckConstants.Examine_Tag_County); checkIndexFace.setCreateTime(new Date()); } CheckIndexFace checkIndexFace = getCheckIndex(key, checkIndexFaceList); //调用抓拍上传及时性计算方法 Map<String, Object> param = new HashMap<>(); param.put("totalCount", stats.totalCount); ycl-server/src/main/java/com/ycl/calculate/IndexCalculationServe.java
@@ -2,18 +2,19 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ycl.platform.base.CheckIndex; import com.ycl.platform.domain.entity.CheckIndexCar; import com.ycl.platform.domain.entity.TMonitor; import com.ycl.platform.domain.result.HK.SnapshotDataMonitorResult; import com.ycl.platform.service.ITMonitorService; import constant.CheckConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -22,9 +23,6 @@ */ @Component public class IndexCalculationServe { @Autowired private ITMonitorService monitorService; //点位在线率 public BigDecimal siteOnline(Map<String, Object> param) { @@ -60,10 +58,55 @@ .add(delayCount3.divide(totalCount, 10, RoundingMode.HALF_UP).multiply(new BigDecimal("0.6"))); return result.setScale(4, RoundingMode.HALF_UP); } //数据完整性 public BigDecimal dataIntegrity(Map<String, Object> param){ BigDecimal totalSites = new BigDecimal((Integer) param.get("totalSites")); BigDecimal importantTotalSites = new BigDecimal((Integer) param.get("importantTotalSites")); BigDecimal integritySites = new BigDecimal((Integer) param.get("integritySites")); BigDecimal importantIntegritySites = new BigDecimal((Integer) param.get("importantIntegritySites")); BigDecimal result = integritySites.divide(totalSites, 10, RoundingMode.HALF_UP) .add(importantIntegritySites.divide(importantTotalSites, 10, RoundingMode.HALF_UP)); return result.setScale(4, RoundingMode.HALF_UP); } //返回省厅国标码集合 public List<String> getProvince() { // TODO: 分省厅市局 需要补充集合数据 List<String> list = new ArrayList<>(); return list; } //返回重点点位集合 public List<String> getImportant() { // TODO: 重点点位 需要补充集合数据 List<String> list = new ArrayList<>(); return list; } //检查是否存在当日数据 public <T extends CheckIndex> T getCheckIndex(String key, List<T> checkIndexList) { T checkIndex; // 检查是否已存在今日数据 Optional<T> existingIndex = checkIndexList.stream() .filter(index -> key.equals(index.getDeptId().toString()) && (key.startsWith("Province_") ? CheckConstants.Examine_Tag_City.equals(index.getExamineTag()) : CheckConstants.Examine_Tag_County.equals(index.getExamineTag()))) .findFirst(); if (existingIndex.isPresent()) { checkIndex = existingIndex.get(); } else { try { checkIndex = (T) CheckIndexCar.class.getDeclaredConstructor().newInstance(); checkIndex.setDeptId(key.startsWith("Province_") ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); checkIndex.setExamineTag(key.startsWith("Province_") ? CheckConstants.Examine_Tag_City : CheckConstants.Examine_Tag_County); checkIndex.setCreateTime(new Date()); } catch (Exception e) { throw new RuntimeException("无法创建 CheckIndexCar 实例", e); } } return checkIndex; } } ycl-server/src/main/java/com/ycl/factory/IndexCalculationFactory.java
@@ -10,10 +10,13 @@ private static final Map<String, CalculationStrategy> calculators = new HashMap<>(); static { //点位在线、视图库对接稳定性 calculators.put(CalculationStrategyConstants.Car_SiteOnline_ViewStability, new CarSiteOnlineCalculation()); calculators.put(CalculationStrategyConstants.Face_SiteOnline_ViewStability, new FaceSiteOnlineCalculation()); //信息准确率 calculators.put(CalculationStrategyConstants.Car_InfoAccuracy, new CarInFoAccuracyCalculation()); calculators.put(CalculationStrategyConstants.Face_InfoAccuracy, new FaceInFoAccuracyCalculation()); //抓拍数据上传延迟 calculators.put(CalculationStrategyConstants.Car_SnapshotDelay, new CarSnapshotDelayCalculation()); calculators.put(CalculationStrategyConstants.Face_SnapshotDelay, new FaceSnapshotDelayCalculation()); } ycl-server/src/main/java/com/ycl/task/MonitorTask.java
@@ -47,6 +47,16 @@ List<TMonitor> monitorList = new ArrayList<>(); //新的数据,原数据库中不存在的数据 Set<TMonitor> newMonitorList = new HashSet<>(); //TODO:解析区域、补充deptId List<SysDictData> areaCodeList = new ArrayList<>(); //TODO:解析重点点位 //重点点位集合字典(解析SXJCJQY字段) SysDictData sysDictData = new SysDictData(); sysDictData.setDictType("platform_important_site"); List<SysDictData> DictDataList = dictDataService.selectDictDataList(sysDictData); List<String> importantSite = DictDataList.stream().map(SysDictData::getDictValue).collect(Collectors.toList()); for (OneMachineFileResult result : oneMachineFileResults) { TMonitor monitor = setMonitor(result); monitorList.add(monitor); @@ -57,15 +67,6 @@ } //新的数据放入Redis中等待考核指标任务使用 redisTemplate.opsForValue().set(RedisConstant.New_Monitor_Set, JSONArray.toJSONString(newMonitorList)); //TODO:解析区域 //TODO:解析重点点位 //重点点位集合字典 SysDictData sysDictData = new SysDictData(); sysDictData.setDictType("platform_important_site"); List<SysDictData> DictDataList = dictDataService.selectDictDataList(sysDictData); List<String> importantSite = DictDataList.stream().map(SysDictData::getDictValue).collect(Collectors.toList()); }