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/task/HKTask.java | 955 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 896 insertions(+), 59 deletions(-) diff --git a/ycl-server/src/main/java/com/ycl/task/HKTask.java b/ycl-server/src/main/java/com/ycl/task/HKTask.java index d4bf4be..b9388dd 100644 --- a/ycl-server/src/main/java/com/ycl/task/HKTask.java +++ b/ycl-server/src/main/java/com/ycl/task/HKTask.java @@ -1,100 +1,937 @@ package com.ycl.task; import com.alibaba.fastjson2.JSONObject; -import com.ycl.platform.domain.entity.YwThreshold; -import com.ycl.platform.domain.param.HK.FaceDeviceInspectionParam; -import com.ycl.platform.domain.param.HK.VehicleDeviceInspectionParam; -import com.ycl.platform.domain.result.HK.FaceDeviceInspectionResult; -import com.ycl.platform.domain.result.HK.VehicleDeviceInspectionResult; -import com.ycl.platform.mapper.YwThresholdMapper; -import com.ycl.platform.service.IYwThresholdService; -import com.ycl.web.HKClient; -import enumeration.BusinessType; -import enumeration.general.BusinessTypeEnum; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.mongodb.client.result.DeleteResult; +import com.ycl.feign.*; +import com.ycl.platform.domain.entity.CheckIndexCar; +import com.ycl.platform.domain.entity.CheckIndexFace; +import com.ycl.platform.domain.entity.TMonitor; +import com.ycl.platform.domain.param.HK.*; +import com.ycl.platform.domain.result.HK.*; +import com.ycl.platform.domain.result.UY.VideoOnlineResult; +import com.ycl.platform.domain.vo.UpdateOnlineVO; +import com.ycl.platform.mapper.CheckIndexCarMapper; +import com.ycl.platform.mapper.CheckIndexFaceMapper; +import com.ycl.platform.mapper.TMonitorMapper; +import com.ycl.platform.service.*; +import com.ycl.utils.DateUtils; +import constant.ApiConstants; +import constant.CheckConstants; +import enumeration.general.AreaDeptEnum; +import enumeration.general.PublishType; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.client.loadbalancer.LoadBalancerRequestFactory; 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.http.converter.StringHttpMessageConverter; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; - +//娴峰悍瀵规帴鏁版嵁浠诲姟 @Slf4j @Component("HKTask") public class HKTask { + @Value("${HK.host}") + public String host; + @Value("${HK.appKey}") + public String appKey; + @Value("${HK.appSecret}") + public String appSecret; + @Value("${HK.carCode}") + public String carCode; + @Value("${HK.faceCode}") + public String faceCode; + @Value("${HK.carProvinceCode}") + public String carProvinceCode; + @Value("${HK.faceProvinceCode}") + public String faceProvinceCode; @Autowired private MongoTemplate mongoTemplate; @Autowired + private IYwThresholdService ywThresholdService; + @Autowired + private YwPointService pointService; + @Autowired + private TMonitorMapper monitorMapper; + @Autowired + private UYErrorTypeCheckService uyErrorTypeCheckService; + @Autowired private HKClient hkClient; @Autowired - private IYwThresholdService ywThresholdService; - - private final static Integer pageNo = 1; - private final static Integer pageSize = 5000; - //鎴愬姛鐘舵�佺爜 - private final static String successCode = "0"; + private ICheckIndexCarService carService; + @Autowired + private CheckIndexCarMapper carMapper; + @Autowired + private ICheckIndexFaceService faceService; + @Autowired + private CheckIndexFaceMapper faceMapper; //杞﹁締璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉 - public void VehicleDeviceInspectionTask() { + public void vehicleDeviceInspectionTask() { log.info("寮�濮嬫墽琛岃溅杈嗚澶囧叏妫�鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾"); VehicleDeviceInspectionParam param = new VehicleDeviceInspectionParam(); - param.setPageNO(pageNo).setPageSize(pageSize).setDate(getToday()); - JSONObject jsonObject = hkClient.VehicleDeviceInspection(param); - if (jsonObject != null && successCode.equals(jsonObject.getString("code"))) { - JSONObject data = jsonObject.getJSONObject("data"); - if (data == null) { - throw new RuntimeException("杞﹁締璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉鏁版嵁涓虹┖"); - } - List<VehicleDeviceInspectionResult> list = data.getList("list", VehicleDeviceInspectionResult.class); - list.forEach(item ->item.setCreateTime(new Date())); - if (CollectionUtils.isEmpty(list)) { - throw new RuntimeException("杞﹁締璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉鏁版嵁涓虹┖"); - } + param.setPageNo(ApiConstants.PageNo); + param.setPageSize(ApiConstants.HKPageSize); + param.setDate(DateUtils.getDate()); + param.setDataType(ApiConstants.HK_DataType_CAR); + List<VehicleDeviceInspectionResult> list = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v2/data/vehFullAmount/query", param, VehicleDeviceInspectionResult.class); + if (!CollectionUtils.isEmpty(list)) { + //濡傛灉瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + DeleteResult result = mongoTemplate.remove(query, VehicleDeviceInspectionResult.class); + list.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(list, CheckConstants.Rule_Category_Car); //瀛樻斁鍦╩ongo涓� - mongoTemplate.insert(list); + mongoTemplate.insertAll(list); //鍚屾鐨勬暟鎹繘琛屽伐鍗曢槇鍊煎鐞� ywThresholdService.carCheck(list); - } else { - log.error("鍚屾杞﹁締璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉澶辫触", jsonObject); } + // 鏈湴娴嬭瘯 +// Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); +// ywThresholdService.carCheck(mongoTemplate.find(query, VehicleDeviceInspectionResult.class)); log.info("缁撴潫杞﹁締璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾"); } - - public void FaceDeviceInspectionTask() { + //浜鸿劯璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉 + public void faceDeviceInspectionTask() { log.info("寮�濮嬫墽琛屼汉鑴歌澶囧叏妫�鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾"); FaceDeviceInspectionParam param = new FaceDeviceInspectionParam(); - param.setPageNO(pageNo).setPageSize(pageSize).setDate(getToday()); - JSONObject jsonObject = hkClient.FaceDeviceInspection(param); - if (jsonObject != null && successCode.equals(jsonObject.getString("code"))) { - JSONObject data = jsonObject.getJSONObject("data"); - if (data == null) { - throw new RuntimeException("浜鸿劯璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉鏁版嵁涓虹┖"); - } - List<FaceDeviceInspectionResult> list = data.getList("list", FaceDeviceInspectionResult.class); - list.forEach(item ->item.setCreateTime(new Date())); - if (CollectionUtils.isEmpty(list)) { - throw new RuntimeException("浜鸿劯璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉鏁版嵁涓虹┖"); - } - //TODO:鍚屾鐨勬暟鎹彲鑳介渶瑕佸伐鍗曢槇鍊肩瓑澶勭悊 - + param.setPageNo(ApiConstants.PageNo); + param.setPageSize(ApiConstants.HKPageSize); + param.setDate(DateUtils.getDate()); + List<FaceDeviceInspectionResult> list = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v2/data/faceFullAmount/query", param, FaceDeviceInspectionResult.class); + if (!CollectionUtils.isEmpty(list)) { + //濡傛灉瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria.where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + DeleteResult result = mongoTemplate.remove(query, FaceDeviceInspectionResult.class); + list.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(list, CheckConstants.Rule_Category_Face); //瀛樻斁鍦╩ongo涓� - mongoTemplate.insert(list); - } else { - log.error("鍚屾浜鸿劯璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉澶辫触", jsonObject); + mongoTemplate.insertAll(list); + //鍚屾鐨勬暟鎹繘琛屽伐鍗曢槇鍊煎鐞� + ywThresholdService.faceCheck(list); } +// Query query = new Query(Criteria.where("mongoCreateTime").lt(DateUtils.getDayEnd(new Date()))); +// ywThresholdService.faceCheck(mongoTemplate.find(query, FaceDeviceInspectionResult.class)); log.info("缁撴潫浜鸿劯璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾"); } - private String getToday() { - Date date = new Date(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - String today = sdf.format(date); - return today; + // 鎶撴媿鏁版嵁閲忕洃娴嬬粨鏋� + public void snapshotDataMonitorTask() { + log.info("寮�濮嬫墽琛屾姄鎷嶆暟鎹噺妫�娴嬬粨鏋滄暟鎹悓姝�"); + /** 杞﹁締鏁版嵁 */ + SnapshotDataMonitorParam carParam = new SnapshotDataMonitorParam(); + carParam.setPageNo(ApiConstants.PageNo); + carParam.setPageSize(ApiConstants.HKPageSize); + carParam.setDate(DateUtils.getDate()); + carParam.setDataType(ApiConstants.HK_DataType_CAR); + List<SnapshotDataMonitorResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/snapCountDetail/query", carParam, SnapshotDataMonitorResult.class); + if (!CollectionUtils.isEmpty(carList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date())) + .and("dataType").is(ApiConstants.HK_DataType_CAR)); + DeleteResult result = mongoTemplate.remove(query, SnapshotDataMonitorResult.class); + carList.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car); + //瀛樻斁鍦╩ongo涓� + carList.forEach(item -> item.setDataType(ApiConstants.HK_DataType_CAR)); + mongoTemplate.insertAll(carList); + } + + /** 浜鸿劯鏁版嵁 */ + SnapshotDataMonitorParam faceParam = new SnapshotDataMonitorParam(); + faceParam.setPageNo(ApiConstants.PageNo); + faceParam.setPageSize(ApiConstants.HKPageSize); + faceParam.setDate(DateUtils.getDate()); + faceParam.setDataType(ApiConstants.HK_DataType_FACE); + List<SnapshotDataMonitorResult> faceList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/snapCountDetail/query", faceParam, SnapshotDataMonitorResult.class); + if (!CollectionUtils.isEmpty(faceList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date())) + .and("dataType").is(ApiConstants.HK_DataType_FACE)); + DeleteResult result = mongoTemplate.remove(query, SnapshotDataMonitorResult.class); + faceList.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face); + //瀛樻斁鍦╩ongo涓� + faceList.forEach(item -> item.setDataType(ApiConstants.HK_DataType_FACE)); + mongoTemplate.insertAll(faceList); + } + //淇敼online鐘舵�� + List<SnapshotDataMonitorResult> totalResult = new ArrayList<>(); + totalResult.addAll(carList); + totalResult.addAll(faceList); + if (!CollectionUtils.isEmpty(totalResult)) { + //鍏堟嬁浼樹簯鐨勫湪绾匡紝杩囨护鎺変紭浜戝凡鏈夌殑鍥芥爣鐮� + Query query = new Query(); + query.addCriteria(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + List<VideoOnlineResult> results = mongoTemplate.find(query, VideoOnlineResult.class); + if (!CollectionUtils.isEmpty(results)) { + Date now = new Date(); + List<String> uyNoList = results.stream().map(VideoOnlineResult::getNo).collect(Collectors.toList()); + List<String> numbers = totalResult.stream().filter(result->!uyNoList.contains(result.getExternalIndexCode())) + .map(SnapshotDataMonitorResult::getExternalIndexCode).collect(Collectors.toList()); + //鎺掗櫎鎺変紭浜戜笖涓嶅寘鍚棰戣澶囩殑鍥芥爣 + Map<String, TMonitor> map = monitorMapper.selectList(new QueryWrapper<TMonitor>() + .in("serial_number", numbers)) + .stream().filter(monitor -> monitor.getCameraFunType()!=null && !monitor.getCameraFunType().contains("1")) + .collect(Collectors.toMap(TMonitor::getSerialNumber, Function.identity())); + List<UpdateOnlineVO> willUpdateList = new ArrayList<>(); + totalResult.forEach(item -> { + TMonitor monitor = map.get(item.getExternalIndexCode()); + if(monitor!=null) { + UpdateOnlineVO vo = new UpdateOnlineVO(); + vo.setOnline(item.getDataCount() > 0 ? 1 : -1); + vo.setSerialNumber(monitor.getSerialNumber()); + vo.setUpdateTime(now); + willUpdateList.add(vo); + } + }); + if(!CollectionUtils.isEmpty(willUpdateList)) monitorMapper.updateOnlineFromHk(willUpdateList); +// List<UpdateOnlineVO> willUpdateList = totalResult.stream().map(item -> { +// UpdateOnlineVO vo = new UpdateOnlineVO(); +// vo.setOnline(item.getDataCount() > 0 ? 1 : -1); +// vo.setIp(map.get(item.getExternalIndexCode()).getIp()); +// vo.setUpdateTime(now); +// return vo; +// }).collect(Collectors.toList()); +// monitorMapper.updateOnlineFromUyOrHk(willUpdateList); +// //绂荤嚎鐢熸垚宸ュ崟,涓�涓猧p鍙敓鎴愪竴涓伐鍗� +// List<SnapshotDataMonitorResult> workOrders = new ArrayList<>(totalResult.stream() +// .filter(item -> ApiConstants.UY_OnlineSite_Offline.equals(item.getDataCount() > 0 ? 1 : -1)) +// .collect(Collectors.toMap( +// SnapshotDataMonitorResult::getIp, +// Function.identity(), +// (existing, replacement) -> existing // 濡傛灉閬囧埌鐩稿悓鐨� IP锛屼繚鐣欑涓�涓紙existing锛� +// )).values()); +// uyErrorTypeCheckService.hkOnlineCheck(workOrders); + } + } + log.info("缁撴潫鎶撴媿鏁版嵁閲忔娴嬬粨鏋滄暟鎹悓姝�"); + } + + //閲囬泦璁惧灞炴�х洃娴嬬粨鏋�(浜鸿劯) + public void monitorDetailTask() { + log.info("寮�濮嬫墽琛岄噰闆嗚澶囧睘鎬х洃娴嬬粨鏋滄暟鎹悓姝�"); + //浜鸿劯鍗″彛淇℃伅閲囬泦鍑嗙‘鐜� + MonitoringDetailParam param = new MonitoringDetailParam(); + param.setPageNo(ApiConstants.PageNo); + param.setPageSize(ApiConstants.HKPageSize); + param.setDate(DateUtils.getDate()); + List<MonitoringDetailResult> faceList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/device/cameraExpDetailInfo/query", param, MonitoringDetailResult.class); + if (!CollectionUtils.isEmpty(faceList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + DeleteResult result = mongoTemplate.remove(query, MonitoringDetailResult.class); + faceList.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face); + //瀛樻斁鍦╩ongo涓� + mongoTemplate.insertAll(faceList); + } + log.info("缁撴潫閲囬泦璁惧灞炴�х洃娴嬬粨鏋滄暟鎹悓姝�"); + } + + //鍗″彛灞炴�х洃娴嬬粨鏋� + public void crossDetailTask() { + log.info("寮�濮嬫墽琛屽崱鍙e睘鎬х洃娴嬬粨鏋滄暟鎹悓姝�"); + //杞﹁締鍗″彛淇℃伅閲囬泦鍑嗙‘鐜� + CrossDetailParam param = new CrossDetailParam(); + param.setPageNo(ApiConstants.PageNo); + param.setPageSize(ApiConstants.HKPageSize); + param.setDate(DateUtils.getDate()); + List<CrossDetailResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/device/crossExpDetailInfo/query", param, CrossDetailResult.class); + if (!CollectionUtils.isEmpty(carList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + DeleteResult result = mongoTemplate.remove(query, CrossDetailResult.class); + carList.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car); + //瀛樻斁鍦╩ongo涓� + mongoTemplate.insertAll(carList); + } + log.info("缁撴潫鍗″彛灞炴�х洃娴嬬粨鏋滄暟鎹悓姝�"); + } + + //鏁版嵁瀹屾暣鎬х洃娴嬬粨鏋� + public void dataIntegrityMonitoringTask() { + log.info("寮�濮嬫墽琛屾暟鎹畬鏁存�х洃娴嬬粨鏋滄暟鎹悓姝�"); + //杞﹁締鍗″彛璁惧鎶撴媿鏁版嵁瀹屾暣鎬� + DataIntegrityMonitoringParam param = new DataIntegrityMonitoringParam(); + param.setPageNo(ApiConstants.PageNo); + param.setPageSize(ApiConstants.HKPageSize); + param.setDate(DateUtils.getDate()); + param.setDataType(ApiConstants.HK_DataType_CAR); + List<DataIntegrityMonitoringResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/attributeIntegrity/query", param, DataIntegrityMonitoringResult.class); + + if (!CollectionUtils.isEmpty(carList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + DeleteResult result = mongoTemplate.remove(query, DataIntegrityMonitoringResult.class); + carList.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car); + //瀛樻斁鍦╩ongo涓� + mongoTemplate.insertAll(carList); + } + log.info("缁撴潫鏁版嵁瀹屾暣鎬х洃娴嬬粨鏋滄暟鎹悓姝�"); + } + + //灞炴�ц瘑鍒噯纭洃娴嬬粨鏋� + public void attrRecognitionMonitorTask() { + log.info("寮�濮嬫墽琛屽睘鎬ц瘑鍒噯纭洃娴嬬粨鏋滄暟鎹悓姝�"); + //杞﹁締鍗″彛璁惧鎶撴媿鏁版嵁鍑嗙‘鎬� + AttrRecognitionParam param = new AttrRecognitionParam(); + param.setPageNo(ApiConstants.PageNo); + param.setPageSize(ApiConstants.HKPageSize); + param.setDate(DateUtils.getDate()); + param.setDataType(ApiConstants.HK_DataType_CAR); + List<AttrRecognitionMonitorResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/attributeRecognition/query", param, AttrRecognitionMonitorResult.class); + + if (!CollectionUtils.isEmpty(carList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + DeleteResult result = mongoTemplate.remove(query, AttrRecognitionMonitorResult.class); + carList.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car); + //瀛樻斁鍦╩ongo涓� + mongoTemplate.insertAll(carList); + } + log.info("缁撴潫灞炴�ц瘑鍒噯纭洃娴嬬粨鏋滄暟鎹悓姝�"); + + } + + //鎶撴媿鏁版嵁鏃跺欢鐩戞祴缁撴灉 + public void snapshopDelayMonitorTask() { + log.info("寮�濮嬫墽琛屾姄鎷嶆暟鎹椂寤剁洃娴嬬粨鏋滄暟鎹悓姝�"); + //杞﹁締鍗″彛璁惧鎶撴媿鏁版嵁涓婁紶鍙婃椂鎬� + /** 杞﹁締鏁版嵁 */ + SnapshotDelayMonitorParam carParam = new SnapshotDelayMonitorParam(); + carParam.setPageNo(ApiConstants.PageNo); + carParam.setPageSize(ApiConstants.HKPageSize); + carParam.setDate(DateUtils.getDate()); + carParam.setDataType(ApiConstants.HK_DataType_CAR); + List<SnapshotDelayMonitorResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/snapAgingDetail/query", carParam, SnapshotDelayMonitorResult.class); + + if (!CollectionUtils.isEmpty(carList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date())) + .and("dataType").is(ApiConstants.HK_DataType_CAR)); + DeleteResult result = mongoTemplate.remove(query, SnapshotDelayMonitorResult.class); + //瀛樻斁鍦╩ongo涓� + carList.stream().forEach(item -> { + item.setDataType(ApiConstants.HK_DataType_CAR); + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car); + mongoTemplate.insertAll(carList); + } + + /** 浜鸿劯鏁版嵁 */ + SnapshotDelayMonitorParam faceParam = new SnapshotDelayMonitorParam(); + faceParam.setPageNo(ApiConstants.PageNo); + faceParam.setPageSize(ApiConstants.HKPageSize); + faceParam.setDate(DateUtils.getDate()); + faceParam.setDataType(ApiConstants.HK_DataType_FACE); + List<SnapshotDelayMonitorResult> faceList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/snapAgingDetail/query", faceParam, SnapshotDelayMonitorResult.class); + + if (!CollectionUtils.isEmpty(faceList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date())) + .and("dataType").is(ApiConstants.HK_DataType_FACE)); + DeleteResult result = mongoTemplate.remove(query, SnapshotDelayMonitorResult.class); + //瀛樻斁鍦╩ongo涓� + faceList.forEach(item -> { + item.setDataType(ApiConstants.HK_DataType_FACE); + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face); + mongoTemplate.insertAll(faceList); + } + log.info("缁撴潫鎶撴媿鏁版嵁鏃跺欢鐩戞祴缁撴灉鏁版嵁鍚屾"); + } + + //鍥剧墖璁块棶鐩戞祴缁撴灉 + public void picAccessTask() { + log.info("寮�濮嬫墽琛屽浘鐗囪闂洃娴嬬粨鏋滄暟鎹悓姝�"); + //杞﹁締鍗″彛淇℃伅閲囬泦鍑嗙‘鐜囥�佽溅杈嗗崱鍙h澶噓rl鍙敤鎬� + PicAccessParam param = new PicAccessParam(); + param.setPageNo(ApiConstants.PageNo); + param.setPageSize(ApiConstants.HKPageSize); + param.setDate(DateUtils.getDate()); + param.setDataType(ApiConstants.HK_DataType_CAR); + List<PicAccessResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/picAccessDetail/query", param, PicAccessResult.class); + + if (!CollectionUtils.isEmpty(carList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + DeleteResult result = mongoTemplate.remove(query, PicAccessResult.class); + carList.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car); + //瀛樻斁鍦╩ongo涓� + mongoTemplate.insertAll(carList); + } + log.info("缁撴潫鍥剧墖璁块棶鐩戞祴缁撴灉鏁版嵁鍚屾"); + } + + //杞﹁締璁惧鎶芥鎸囨爣鐩戞祴缁撴灉 + public void vehicleDeviceSamplingTask() { + log.info("寮�濮嬫墽琛岃溅杈嗚澶囨娊妫�鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾"); + //杞﹁締鍗″彛淇℃伅閲囬泦鍑嗙‘鐜囥�佽溅杈嗗崱鍙h澶噓rl鍙敤鎬� + VehicleDeviceSamplingParam param = new VehicleDeviceSamplingParam(); + param.setPageNo(ApiConstants.PageNo); + param.setPageSize(ApiConstants.HKPageSize); + param.setDate(DateUtils.getDate()); + param.setDataType(ApiConstants.HK_DataType_CAR); + List<VehicleDeviceSamplingResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v2/data/vehSampleAmount/query", param, VehicleDeviceSamplingResult.class); + + if (!CollectionUtils.isEmpty(carList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + DeleteResult result = mongoTemplate.remove(query, VehicleDeviceSamplingResult.class); + carList.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car); + //瀛樻斁鍦╩ongo涓� + mongoTemplate.insertAll(carList); + } + log.info("缁撴潫杞﹁締璁惧鎶芥鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾"); + } + + + //浜鸿劯璁惧鎶芥鎸囨爣鐩戞祴缁撴灉 + public void faceDeviceSamplingTask() { + log.info("寮�濮嬫墽琛屼汉鑴歌澶囨娊妫�鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾"); + FaceDeviceSamplingParam param = new FaceDeviceSamplingParam(); + param.setPageNo(ApiConstants.PageNo); + param.setPageSize(ApiConstants.HKPageSize); + param.setDate(DateUtils.getDate()); + List<FaceDeviceSamplingResult> faceList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v2/data/faceSampleAmount/query", param, FaceDeviceSamplingResult.class); + + if (!CollectionUtils.isEmpty(faceList)) { + //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎 + Query query = new Query(Criteria + .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))); + DeleteResult result = mongoTemplate.remove(query, FaceDeviceSamplingResult.class); + faceList.stream().forEach(item -> { + if (Objects.nonNull(item.getExternalIndexCode())) { + item.setNo(item.getExternalIndexCode()); + } + }); + pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face); + //瀛樻斁鍦╩ongo涓� + mongoTemplate.insertAll(faceList); + } + log.info("缁撴潫浜鸿劯璁惧鎶芥鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾"); + } + + //鑰冩牳鎴愮哗 +// public void HkScoreTask() { +// log.info("寮�濮嬫墽琛屾捣搴疯�冩牳鎴愮哗鏁版嵁"); +// //鍑嗗鏂板鎴栦慨鏀圭殑鏁版嵁 +// List<CheckIndexCar> cars = new ArrayList<>(); +// List<CheckIndexFace> faces = new ArrayList<>(); +// // 鏌ヨ鏄惁index琛ㄥ凡缁忓瓨鍦ㄤ粖鏃ユ暟鎹� +// List<CheckIndexFace> checkIndexFaceList = faceMapper.selectToday(utils.DateUtils.getDate()); +// List<CheckIndexCar> checkIndexCarList = carMapper.selectToday(utils.DateUtils.getDate()); +// +// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); +// // 鑾峰彇褰撳墠鏃堕棿鐨凜alendar瀹炰緥 +// Calendar calendar = Calendar.getInstance(); +// // 璁剧疆鏃堕棿涓哄墠涓�澶� +// calendar.add(Calendar.DATE, -1); +// // 鑾峰彇鍓嶄竴澶╃殑Date瀵硅薄 +// Date yesterday = calendar.getTime(); +// //鍏堣姹傚叏閲忔暟鎹� +// ScoreParam param = new ScoreParam(); +// param.setStartDate(format.format(yesterday)); +// param.setEndDate(format.format(yesterday)); +//// param.setFocusFlag(ApiConstants.HK_FOCUS_FLAG_ALL); +//// param.setCarTree(carCode); +//// param.setFaceTree(faceCode); +// JSONObject scoreJson = hkClient.getScore(param); +// if (scoreJson != null) { +// String code = scoreJson.getString("code"); +// if (ApiConstants.HKSuccessCode.equals(code)) { +// List<HKScoreResult> data = scoreJson.getList("data", HKScoreResult.class); +// +// //鏍规嵁鏁版嵁杞崲涓篿ndex瀵硅薄 +// data.forEach(score -> { +// CheckIndexCar car = new CheckIndexCar(); +// CheckIndexFace face = new CheckIndexFace(); +// score2Index(score, car, face); +// car.setExamineTag(CheckConstants.Examine_Tag_County); +// face.setExamineTag(CheckConstants.Examine_Tag_County); +// Optional<CheckIndexCar> carFirst = checkIndexCarList.stream() +// .filter(index -> CheckConstants.Examine_Tag_County.equals(index.getExamineTag()) && car.getDeptId().equals(index.getDeptId())) +// .findFirst(); +// Optional<CheckIndexFace> faceFirst = checkIndexFaceList.stream() +// .filter(index -> CheckConstants.Examine_Tag_County.equals(index.getExamineTag()) && face.getDeptId().equals(index.getDeptId())) +// .findFirst(); +// if (carFirst.isPresent()) { +// car.setId(carFirst.get().getId()); +// } +// if (faceFirst.isPresent()) { +// face.setId(faceFirst.get().getId()); +// } +// cars.add(car); +// faces.add(face); +// }); +// } +// } +// +// //鍏堣姹傜渷鍘呮暟鎹� +// ScoreParam provinceParam = new ScoreParam(); +// provinceParam.setStartDate(format.format(yesterday)); +// provinceParam.setEndDate(format.format(yesterday)); +//// provinceParam.setFocusFlag(ApiConstants.HK_FOCUS_FLAG_ALL); +//// provinceParam.setCarTree(carProvinceCode); +//// provinceParam.setFaceTree(faceProvinceCode); +// JSONObject scoreProvinceJson = hkClient.getScore(provinceParam); +// if (scoreProvinceJson != null) { +// String code = scoreProvinceJson.getString("code"); +// if (ApiConstants.HKSuccessCode.equals(code)) { +// List<HKScoreResult> data = scoreProvinceJson.getList("data", HKScoreResult.class); +// +// //鏍规嵁鏁版嵁杞崲涓篿ndex瀵硅薄 +// data.forEach(score -> { +// CheckIndexCar car = new CheckIndexCar(); +// CheckIndexFace face = new CheckIndexFace(); +// score2Index(score, car, face); +// car.setExamineTag(CheckConstants.Examine_Tag_Province); +// face.setExamineTag(CheckConstants.Examine_Tag_Province); +// Optional<CheckIndexCar> carFirst = checkIndexCarList.stream() +// .filter(index -> CheckConstants.Examine_Tag_Province.equals(index.getExamineTag()) && car.getDeptId().equals(index.getDeptId())) +// .findFirst(); +// Optional<CheckIndexFace> faceFirst = checkIndexFaceList.stream() +// .filter(index -> CheckConstants.Examine_Tag_Province.equals(index.getExamineTag()) && face.getDeptId().equals(index.getDeptId())) +// .findFirst(); +// if (carFirst.isPresent()) { +// car.setId(carFirst.get().getId()); +// } +// if (faceFirst.isPresent()) { +// face.setId(faceFirst.get().getId()); +// } +// cars.add(car); +// faces.add(face); +// }); +// } +// } +// //瀛樻斁鎴愮哗鍒癿ysql锛屽鏋滃瓨鍦ㄥ垯鏇挎崲涓嶅瓨鍦ㄥ氨鏂板銆� +// if (!CollectionUtils.isEmpty(cars)) carService.saveOrUpdateBatch(cars); +// if (!CollectionUtils.isEmpty(faces)) faceService.saveOrUpdateBatch(faces); +// log.info("缁撴潫娴峰悍鑰冩牳鎴愮哗鏁版嵁"); +// } + + public void HkScoreTask(){ + log.info("寮�濮嬫墽琛屾捣搴疯�冩牳鎴愮哗鏁版嵁"); + //鍏堟墽琛岃幏寰楁爣绛� 鍥犱负鍏ㄩ噺榛樿浼犲弬涓簄ull锛屼絾鏄渷鍘呮暟鎹渶瑕佽幏寰楁爣绛� + JSONObject labelJson = hkClient.getGetLabel(); + Integer faceLabelId = null; + Integer carLabelId = null; + Integer allLabelId = null; + if (labelJson != null) { + String code = labelJson.getString("code"); + if (ApiConstants.HKSuccessCode.equals(code)){ + //鑾峰緱label鑰冩牳鏍囩瀵硅薄 + log.error("labelJson鐨刣ata:{}",labelJson.get("data")); + List<HKResultLabel> hkResultLabels = labelJson.getList("data",HKResultLabel.class); + for (HKResultLabel label : hkResultLabels) { + if ("鐪佸巺浜鸿劯".equals(label.getLabelName())){ + faceLabelId = label.getId(); + }else if ("鐪佸巺杞﹁締".equals(label.getLabelName())){ + carLabelId = label.getId(); + }else if ("鍏ㄩ噺".equals(label.getLabelName())){ + allLabelId = label.getId(); + } + } + log.error("鎵撳嵃hkResultLabels锛歿}",hkResultLabels); + } + } + if (faceLabelId == null || carLabelId == null){ + log.error("娴峰悍鑾峰彇鐪佸巺鑰冩牳鏍囩涓簄ull"); + } + + //鍑嗗鏂板鎴栦慨鏀圭殑鏁版嵁 + List<CheckIndexCar> cars = new ArrayList<>(); + List<CheckIndexFace> faces = new ArrayList<>(); + // 鏌ヨ鏄惁index琛ㄥ凡缁忓瓨鍦ㄤ粖鏃ユ暟鎹� + List<CheckIndexFace> checkIndexFaceList = faceMapper.selectToday(utils.DateUtils.getDate()); + List<CheckIndexCar> checkIndexCarList = carMapper.selectToday(utils.DateUtils.getDate()); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + // 鑾峰彇褰撳墠鏃堕棿鐨凜alendar瀹炰緥 + Calendar calendar = Calendar.getInstance(); + // 璁剧疆鏃堕棿涓哄墠涓�澶� + calendar.add(Calendar.DATE, -1); + // 鑾峰彇鍓嶄竴澶╃殑Date瀵硅薄 + Date yesterday = calendar.getTime(); + + ScoreParam param = new ScoreParam(); +// param.setStartDate(format.format(yesterday)); +// param.setEndDate(format.format(yesterday)); +// param.setLabelId(); + + //------------榛樿鍙傛暟涓簄ull璇锋眰鍏ㄩ噺鏁版嵁 + if (allLabelId == null){ + allLabelId = -1; + } + param.setLabelId(allLabelId); + JSONObject scoreJson = hkClient.getScoreNew(param); + log.error("鍏ㄩ噺鏁版嵁"); + if (scoreJson != null) { + List<HkResultInfo> allInfo = new ArrayList<>(); + String code = scoreJson.getString("code"); + if (ApiConstants.HKSuccessCode.equals(code)){ + JSONObject data = scoreJson.getJSONObject("data"); + + Map<Integer,JSONObject> map = new HashMap<>(); + //鑾峰緱data 涓� batchId 鐨勬壒娆d瀵硅薄 鏀惧叆map涓� + for (String batchIdKey :data.keySet() ) { + JSONObject batch = data.getJSONObject(batchIdKey); + //浠ユ壒娆d涓簁ey 鏀惧叆 JSONObject瀵硅薄 + map.put(Integer.valueOf(batchIdKey),batch); + //鎵规id 涓� 鍚勫尯淇℃伅闆嗗悎 + } + //鑾峰緱鏈�澶х殑閿�� + Optional<Integer> maxKey = map.keySet().stream() + .max(Integer::compareTo); + if (maxKey.isPresent()) { + //鑾峰彇鏈�澶х殑key 鎺ュ彛杩斿洖鍐呭涓渶鏂扮殑鎵规 + Integer id = maxKey.get(); + //杩欎竴灞備负鑾峰緱 data -> 涓� 鎵规鏁扮粍涓� -> 鍖哄煙code鏁扮粍鐨刱ey + for (String areaCodeKey : map.get(id).keySet()) { + //瀛樻斁鏈�鏂版壒娆$殑鍐呭鍒癮llInfo闆嗗悎涓� + log.error("鎵撳嵃鍖轰俊鎭�:{}",map.get(id).get(areaCodeKey)); + allInfo.addAll(map.get(id).getList(areaCodeKey,HkResultInfo.class)); + } + } + //瀵筧llInfo杩涜鍒嗙粍 鍒嗙粍鎸夊尯鍩焛d + Map<String, List<HkResultInfo>> groupedByAreaName = allInfo.stream() + .collect(Collectors.groupingBy(HkResultInfo::getAreaCode)); + for (Map.Entry<String, List<HkResultInfo>> entry : groupedByAreaName.entrySet()) { + log.error("鏈�鏂版壒娆″唴size:{}",groupedByAreaName.get(entry.getKey()).size()); + log.error("鏈�鏂版壒娆″唴鏁版嵁:{}",groupedByAreaName.get(entry.getKey())); + CheckIndexCar car = new CheckIndexCar(); + CheckIndexFace face = new CheckIndexFace(); + score3Index(groupedByAreaName.get(entry.getKey()), car, face,entry.getKey()); + car.setExamineTag(CheckConstants.Examine_Tag_County); + face.setExamineTag(CheckConstants.Examine_Tag_County); + Optional<CheckIndexCar> carFirst = checkIndexCarList.stream() + .filter(index -> CheckConstants.Examine_Tag_County.equals(index.getExamineTag()) && car.getDeptId().equals(index.getDeptId())) + .findFirst(); + Optional<CheckIndexFace> faceFirst = checkIndexFaceList.stream() + .filter(index -> CheckConstants.Examine_Tag_County.equals(index.getExamineTag()) && face.getDeptId().equals(index.getDeptId())) + .findFirst(); + if (carFirst.isPresent()) { + car.setId(carFirst.get().getId()); + } + if (faceFirst.isPresent()) { + face.setId(faceFirst.get().getId()); + } + cars.add(car); + faces.add(face); + } + }else { + log.error("璋冪敤娴峰悍鍏ㄩ噺鏁版嵁api澶辫触"); + } + + } + //------------鑾峰彇鐪佸巺鏁版嵁 + List<HkResultInfo> provincialList = new ArrayList<>(); + //鑾峰彇鐪佸巺浜鸿劯鏁版嵁 + if (faceLabelId != null){ + ScoreParam faceParam = new ScoreParam(); + log.error("faceLabelId:{}",faceLabelId); + faceParam.setLabelId(faceLabelId); + JSONObject faceJson = hkClient.getScoreNew(faceParam); + log.error("鐪佸巺浜鸿劯鏁版嵁"); + if (faceJson != null) { + String code = faceJson.getString("code"); + if (ApiConstants.HKSuccessCode.equals(code)){ + JSONObject data = faceJson.getJSONObject("data"); + + Map<Integer,JSONObject> map = new HashMap<>(); + //鑾峰緱data 涓� batchId 鐨勬壒娆d瀵硅薄 鏀惧叆map涓� + for (String batchIdKey :data.keySet() ) { + JSONObject batch = data.getJSONObject(batchIdKey); + //浠ユ壒娆d涓簁ey 鏀惧叆 JSONObject瀵硅薄 + map.put(Integer.valueOf(batchIdKey),batch); + //鎵规id 涓� 鍚勫尯淇℃伅闆嗗悎 + log.error("鎵撳嵃鍑虹渷鍘呬汉鑴竏ata鍐呭涓壒娆d锛歿}锛屼互鍙婂搴旂殑缁撴灉info:{}",batchIdKey,batch); + } + //鑾峰緱鏈�澶х殑閿�� + Optional<Integer> maxKey = map.keySet().stream() + .max(Integer::compareTo); + if (maxKey.isPresent()) { + //鑾峰彇鏈�澶х殑key 鎺ュ彛杩斿洖鍐呭涓渶鏂扮殑鎵规 + Integer id = maxKey.get(); + //杩欎竴灞備负鑾峰緱 data -> 涓� 鎵规鏁扮粍涓� -> 鍖哄煙code鏁扮粍鐨刱ey + for (String areaCodeKey : map.get(id).keySet()) { + //瀛樻斁鏈�鏂版壒娆$殑鍐呭鍒癮llInfo闆嗗悎涓� + provincialList.addAll(map.get(id).getList(areaCodeKey,HkResultInfo.class)); + } + } + + }else { + log.error("璋冪敤娴峰悍鐪佸巺浜鸿劯鏁版嵁api澶辫触"); + } + + } + }else { + log.error("faceLabelId:涓虹┖涓嶆墽琛岃幏寰楃渷鍘呮暟鎹�"); + } + //鑾峰彇鐪佸巺杞﹁締鏁版嵁v. + if (carLabelId != null){ + ScoreParam carParam = new ScoreParam(); + log.error("carLabelId:{}",carLabelId); + carParam.setLabelId(carLabelId); + JSONObject carJson = hkClient.getScoreNew(carParam); + log.error("鐪佸巺杞﹁締鏁版嵁"); + if (carJson != null) { + String code = carJson.getString("code"); + if (ApiConstants.HKSuccessCode.equals(code)){ + JSONObject data = carJson.getJSONObject("data"); + + Map<Integer,JSONObject> map = new HashMap<>(); + //鑾峰緱data 涓� batchId 鐨勬壒娆d瀵硅薄 鏀惧叆map涓� + for (String batchIdKey :data.keySet() ) { + JSONObject batch = data.getJSONObject(batchIdKey); + //浠ユ壒娆d涓簁ey 鏀惧叆 JSONObject瀵硅薄 + map.put(Integer.valueOf(batchIdKey),batch); + //鎵规id 涓� 鍚勫尯淇℃伅闆嗗悎 + log.error("鎵撳嵃鍑虹渷鍘呮垚杈哾ata鍐呭涓壒娆d锛歿}锛屼互鍙婂搴旂殑缁撴灉info:{}",batchIdKey,batch); + } + //鑾峰緱鏈�澶х殑閿�� + Optional<Integer> maxKey = map.keySet().stream() + .max(Integer::compareTo); + if (maxKey.isPresent()) { + //鑾峰彇鏈�澶х殑key 鎺ュ彛杩斿洖鍐呭涓渶鏂扮殑鎵规 + Integer id = maxKey.get(); + //杩欎竴灞備负鑾峰緱 data -> 涓� 鎵规鏁扮粍涓� -> 鍖哄煙code鏁扮粍鐨刱ey + for (String areaCodeKey : map.get(id).keySet()) { + //瀛樻斁鏈�鏂版壒娆$殑鍐呭鍒癮llInfo闆嗗悎涓� + provincialList.addAll(map.get(id).getList(areaCodeKey,HkResultInfo.class)); + } + } + }else { + log.error("璋冪敤娴峰悍鐪佸巺杞﹁締鏁版嵁api澶辫触"); + } + } + }else { + log.error("carLabelId:涓虹┖涓嶆墽琛岃幏寰楃渷鍘呮暟鎹�"); + } + //鑾峰彇瀹屾暟鎹紑濮嬪垎缁� + Map<String,List<HkResultInfo>> provincialGroupedByAreaName = provincialList.stream() + .collect(Collectors.groupingBy(HkResultInfo::getAreaCode)); + for (Map.Entry<String, List<HkResultInfo>> entry : provincialGroupedByAreaName.entrySet()) { + CheckIndexCar car = new CheckIndexCar(); + CheckIndexFace face = new CheckIndexFace(); + score3Index(provincialGroupedByAreaName.get(entry.getKey()), car, face,entry.getKey()); + car.setExamineTag(CheckConstants.Examine_Tag_Province); + face.setExamineTag(CheckConstants.Examine_Tag_Province); + Optional<CheckIndexCar> carFirst = checkIndexCarList.stream() + .filter(index -> CheckConstants.Examine_Tag_Province.equals(index.getExamineTag()) && car.getDeptId().equals(index.getDeptId())) + .findFirst(); + Optional<CheckIndexFace> faceFirst = checkIndexFaceList.stream() + .filter(index -> CheckConstants.Examine_Tag_Province.equals(index.getExamineTag()) && face.getDeptId().equals(index.getDeptId())) + .findFirst(); + if (carFirst.isPresent()) { + car.setId(carFirst.get().getId()); + } + if (faceFirst.isPresent()) { + face.setId(faceFirst.get().getId()); + } + cars.add(car); + faces.add(face); + } + log.error("鎵撳嵃鎻掑叆鏁版嵁cars:{}",cars); + log.error("鎵撳嵃鎻掑叆鏁版嵁faces:{}",faces); + //瀛樻斁鎴愮哗鍒癿ysql锛屽鏋滃瓨鍦ㄥ垯鏇挎崲涓嶅瓨鍦ㄥ氨鏂板銆� + if (!CollectionUtils.isEmpty(cars)) carService.saveOrUpdateBatch(cars); + if (!CollectionUtils.isEmpty(faces)) faceService.saveOrUpdateBatch(faces); + log.info("缁撴潫娴峰悍鑰冩牳鎴愮哗鏁版嵁"); + } + + private void score2Index(HKScoreResult score, CheckIndexCar car, CheckIndexFace face) { + car.setDeptId(Long.parseLong(AreaDeptEnum.fromCode(score.getAreaCode()).getDeptId() + "")); + car.setCreateTime(new Date()); + car.setPublish(PublishType.PUBLISHED.getCode()); + face.setDeptId(Long.parseLong(AreaDeptEnum.fromCode(score.getAreaCode()).getDeptId() + "")); + face.setCreateTime(new Date()); + face.setPublish(PublishType.PUBLISHED.getCode()); + + car.setViewConnectStability(new BigDecimal(score.getDownCarDataUploadScoreString() == null ? "1" : score.getDownCarDataUploadScoreString())); + car.setSiteOnline(new BigDecimal(score.getDownCrossQualityCarScoreString() == null ? "1" : score.getDownCrossQualityCarScoreString())); + car.setDeviceDirectoryConsistent(new BigDecimal(score.getDownCrossNumPushCarScoreString() == null ? "1" : score.getDownCrossNumPushCarScoreString())); + //TODO:娌℃壘鍒拌�冩牳椤� + car.setVehicleInformationCollectionAccuracy(new BigDecimal("1")); + car.setVehicleCaptureIntegrity(new BigDecimal(score.getDownCrossAllCarDataIntegrityScoreString() == null ? "1" : score.getDownCrossAllCarDataIntegrityScoreString())); + //娴峰悍鏄涓�1鐨勶紝浣嗘槸鎺ュ彛鎺ㄧ殑鍘熷鏁版嵁 + car.setVehicleCaptureAccuracy(new BigDecimal("1")); + car.setVehicleTimingAccuracy(new BigDecimal(score.getDownCrossCarInvertScoreString() == null ? "1" : score.getDownCrossCarInvertScoreString())); + car.setVehicleUploadTimeliness(new BigDecimal(score.getDownCrossAllCarDelayScoreString() == null ? "1" : score.getDownCrossAllCarDelayScoreString())); + //TODO:娌℃壘鍒拌�冩牳椤� + car.setVehicleUrlAvailability(new BigDecimal("1")); + car.setVehiclePictureAvailability(new BigDecimal(score.getDownCrossPictureQualityCarScoreString() == null ? "1" : score.getDownCrossPictureQualityCarScoreString())); + + face.setViewConnectStability(new BigDecimal(score.getDownFaceDataUploadScoreString() == null ? "1" : score.getDownFaceDataUploadScoreString())); + face.setSiteOnline(new BigDecimal(score.getDownFaceDataUploadScoreString() == null ? "1" : score.getDownFaceDataUploadScoreString())); + face.setDeviceDirectoryConsistent(new BigDecimal(score.getDownCrossNumPushFaceScoreString() == null ? "1" : score.getDownCrossNumPushFaceScoreString())); + //TODO:娌℃壘鍒拌�冩牳椤� + face.setFaceInformationCollectionAccuracy(new BigDecimal("1")); + //TODO:娌℃壘鍒拌�冩牳椤� + face.setFacePictureQualification(new BigDecimal("1")); + face.setFaceTimingAccuracy(new BigDecimal(score.getDownCrossFaceInvertScoreString() == null ? "1" : score.getDownCrossFaceInvertScoreString())); + face.setFaceUploadTimeliness(new BigDecimal(score.getDownCrossAllFaceDelayScoreString() == null ? "1" : score.getDownCrossAllFaceDelayScoreString())); + face.setFacePictureAvailability(new BigDecimal(score.getDownCrossPictureQualityFaceScoreString() == null ? "1" : score.getDownCrossPictureQualityFaceScoreString())); + } + + private void score3Index(List<HkResultInfo> score, CheckIndexCar car, CheckIndexFace face,String areaCode){ + car.setCreateTime(new Date()); + car.setPublish(PublishType.PUBLISHED.getCode()); + face.setCreateTime(new Date()); + face.setPublish(PublishType.PUBLISHED.getCode()); + car.setDeptId(Long.parseLong(AreaDeptEnum.fromCode(areaCode).getDeptId() + "")); + face.setDeptId(Long.parseLong(AreaDeptEnum.fromCode(areaCode).getDeptId() + "")); + + for(HkResultInfo hkResultInfo : score){ + if (HKLabelName.carDelay.getCode().equals(hkResultInfo.getIndexCode())){ + //杞﹁締鍗″彛璁惧鎶撴媿鏁版嵁涓婁紶鍙婃椂鎬� + car.setVehicleUploadTimeliness(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.carOnlineRate2023.getCode().equals(hkResultInfo.getIndexCode())){ + //杞﹁締鐐逛綅鍦ㄧ嚎鐜� + car.setSiteOnline(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.carButtStability2023.getCode().equals(hkResultInfo.getIndexCode())){ + //杞﹁締瑙嗗浘搴撳鎺ョǔ瀹氭�� + car.setViewConnectStability(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.carQualifiedRate.getCode().equals(hkResultInfo.getIndexCode())){ + //杞﹁締鍗″彛璁惧鎶撴媿鏁版嵁瀹屾暣鎬� + car.setVehicleCaptureIntegrity(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.carCorrectRate.getCode().equals(hkResultInfo.getIndexCode())){ + //杞﹁締鍗″彛璁惧鎶撴媿鏁版嵁鍑嗙‘鎬� + car.setVehicleCaptureAccuracy(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.carClockAccuracy.getCode().equals(hkResultInfo.getIndexCode())){ + //杞﹁締鍗″彛璁惧鏃堕挓鍑嗙‘鎬� + car.setVehicleTimingAccuracy(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.carBigPictureAccess.getCode().equals(hkResultInfo.getIndexCode())){ + //杞﹁締鍗″彛璁惧鎶撴媿鏁版嵁澶у浘鍙敤鎬� + car.setVehiclePictureAvailability(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.carUrlOkRate.getCode().equals(hkResultInfo.getIndexCode())){ + //杞﹁締鍗″彛璁惧url鍙敤鎬� + car.setVehicleUrlAvailability(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if(HKLabelName.faceButtStability2023.getCode().equals(hkResultInfo.getIndexCode())){ + //浜鸿劯瑙嗗浘搴撳鎺ョǔ瀹氭�� + face.setViewConnectStability(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.faceOnlineRate.getCode().equals(hkResultInfo.getIndexCode())){ + //浜鸿劯鐐逛綅鍦ㄧ嚎鐜� + face.setSiteOnline(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.faceCapturedPicturesEligibility.getCode().equals(hkResultInfo.getIndexCode())){ + //浜鸿劯璁惧鎶撴媿鍥剧墖鍚堟牸鎬� + face.setFacePictureQualification(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.faceClockAccuracy.getCode().equals(hkResultInfo.getIndexCode())){ + //浜鸿劯璁惧鎶撴媿鍥剧墖鏃堕挓鍑嗙‘鎬� + face.setFaceTimingAccuracy(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.faceDelay.getCode().equals(hkResultInfo.getIndexCode())){ + //璁惧鎶撴媿浜鸿劯鏁版嵁涓婁紶鍙婃椂鎬� + face.setFaceUploadTimeliness(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + }else if (HKLabelName.faceBigPictureAccess.getCode().equals(hkResultInfo.getIndexCode())){ + //浜鸿劯鍗″彛璁惧鎶撴媿鏁版嵁澶у浘鍙敤鎬� + face.setFacePictureAvailability(new BigDecimal(hkResultInfo.getScore() == null ? "1" : String.valueOf(hkResultInfo.getScore()))); + } + } + //TODO:娌℃壘鍒拌�冩牳椤� 浜鸿劯鍗″彛淇℃伅閲囬泦鍑嗙‘鐜� + face.setFaceInformationCollectionAccuracy(new BigDecimal("1")); + //TODO:娌℃壘鍒拌�冩牳椤� 璁惧鐩綍涓�鑷寸巼 + face.setDeviceDirectoryConsistent(new BigDecimal("1")); + + + //TODO:娌℃壘鍒拌�冩牳椤� 杞﹁締鍗″彛淇℃伅閲囬泦鍑嗙‘鐜� + car.setVehicleInformationCollectionAccuracy(new BigDecimal("1")); + //TODO:娌℃壘鍒拌�冩牳椤� 鑱旂綉鍗″彛璁惧鐩綍涓�鑷寸巼 + car.setDeviceDirectoryConsistent(new BigDecimal("1")); + } + + //瑙f瀽鏁版嵁 + private <T> List<T> getDataList(JSONObject jsonObject, Class<T> resultClass, String message) { + if (jsonObject != null && ApiConstants.HKSuccessCode.equals(jsonObject.getString("code"))) { + log.info("鏁版嵁鏍煎紡" + jsonObject); + JSONObject data = jsonObject.getJSONObject("data"); + if (data == null) { + log.error(message, jsonObject); + return null; + } + List<T> list = data.getList("list", resultClass); + if (CollectionUtils.isEmpty(list)) { + log.error(message, data); + return null; + } + return list; + } else { + log.error(message); + } + return null; } } -- Gitblit v1.8.0