From 7b73755e320f1bec9254b86a0f078c5f7969880d Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期四, 19 十二月 2024 10:06:47 +0800
Subject: [PATCH] 接入海康成绩

---
 ycl-server/src/main/java/com/ycl/task/HKTask.java |  260 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 187 insertions(+), 73 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 784d9cf..759cf0e 100644
--- a/ycl-server/src/main/java/com/ycl/task/HKTask.java
+++ b/ycl-server/src/main/java/com/ycl/task/HKTask.java
@@ -3,18 +3,27 @@
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.mongodb.client.result.DeleteResult;
+import com.ycl.feign.HKClient;
 import com.ycl.feign.HkApiUtil;
+import com.ycl.feign.UYClient;
+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.MonitorQualifyResult;
 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.mapper.WorkOrderMapper;
 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;
@@ -24,6 +33,8 @@
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -39,6 +50,14 @@
     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
@@ -49,6 +68,17 @@
     private TMonitorMapper monitorMapper;
     @Autowired
     private UYErrorTypeCheckService uyErrorTypeCheckService;
+    @Autowired
+    private HKClient hkClient;
+    @Autowired
+    private ICheckIndexCarService carService;
+    @Autowired
+    private CheckIndexCarMapper carMapper;
+    @Autowired
+    private ICheckIndexFaceService faceService;
+    @Autowired
+    private CheckIndexFaceMapper faceMapper;
+
     //杞﹁締璁惧鍏ㄦ鎸囨爣鐩戞祴缁撴灉
     public void vehicleDeviceInspectionTask() {
         log.info("寮�濮嬫墽琛岃溅杈嗚澶囧叏妫�鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾");
@@ -57,7 +87,7 @@
         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);
+        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())));
@@ -86,7 +116,7 @@
         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);
+        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())));
@@ -96,7 +126,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(list,CheckConstants.Rule_Category_Face);
+            pointService.setDeviceTagByGB(list, CheckConstants.Rule_Category_Face);
             //瀛樻斁鍦╩ongo涓�
             mongoTemplate.insertAll(list);
             //鍚屾鐨勬暟鎹繘琛屽伐鍗曢槇鍊煎鐞�
@@ -117,7 +147,7 @@
         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);
+        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
@@ -129,7 +159,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
+            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
             //瀛樻斁鍦╩ongo涓�
             carList.forEach(item -> item.setDataType(ApiConstants.HK_DataType_CAR));
             mongoTemplate.insertAll(carList);
@@ -141,9 +171,9 @@
         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);
+        List<SnapshotDataMonitorResult> faceList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/snapCountDetail/query", faceParam, SnapshotDataMonitorResult.class);
         if (!CollectionUtils.isEmpty(faceList)) {
-            log.info("缁撴灉鏁版嵁澶у皬锛歿}",faceList.size());
+            log.info("缁撴灉鏁版嵁澶у皬锛歿}", faceList.size());
             //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎
             Query query = new Query(Criteria
                     .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))
@@ -154,29 +184,29 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(faceList,CheckConstants.Rule_Category_Face);
+            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<>();
+        List<SnapshotDataMonitorResult> totalResult = new ArrayList<>();
         totalResult.addAll(carList);
         totalResult.addAll(faceList);
-        if(!CollectionUtils.isEmpty(totalResult)) {
+        if (!CollectionUtils.isEmpty(totalResult)) {
             List<String> numbers = totalResult.stream().map(SnapshotDataMonitorResult::getExternalIndexCode).collect(Collectors.toList());
             Map<String, TMonitor> map = monitorMapper.selectList(new QueryWrapper<TMonitor>().in("serial_number", numbers))
                     .stream().collect(Collectors.toMap(TMonitor::getSerialNumber, Function.identity()));
             Date now = new Date();
             //杩囨护
             totalResult = totalResult.stream().filter(item -> map.get(item.getExternalIndexCode()) != null).collect(Collectors.toList());
-            totalResult.forEach(item->{
+            totalResult.forEach(item -> {
                 TMonitor monitor = map.get(item.getExternalIndexCode());
                 item.setIp(monitor.getIp());
             });
             List<UpdateOnlineVO> willUpdateList = totalResult.stream().map(item -> {
                 UpdateOnlineVO vo = new UpdateOnlineVO();
-                vo.setOnline(item.getDataCount()>0?1:-1);
+                vo.setOnline(item.getDataCount() > 0 ? 1 : -1);
                 vo.setIp(map.get(item.getExternalIndexCode()).getIp());
                 vo.setUpdateTime(now);
                 return vo;
@@ -184,7 +214,7 @@
             monitorMapper.updateOnlineFromUyOrHk(willUpdateList);
             //绂荤嚎鐢熸垚宸ュ崟,涓�涓猧p鍙敓鎴愪竴涓伐鍗�
             List<SnapshotDataMonitorResult> workOrders = new ArrayList<>(totalResult.stream()
-                    .filter(item -> ApiConstants.UY_OnlineSite_Offline.equals(item.getDataCount()>0?1:-1))
+                    .filter(item -> ApiConstants.UY_OnlineSite_Offline.equals(item.getDataCount() > 0 ? 1 : -1))
                     .collect(Collectors.toMap(
                             SnapshotDataMonitorResult::getIp,
                             Function.identity(),
@@ -203,7 +233,7 @@
         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);
+        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
@@ -214,7 +244,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(faceList,CheckConstants.Rule_Category_Face);
+            pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face);
             //瀛樻斁鍦╩ongo涓�
             mongoTemplate.insertAll(faceList);
         }
@@ -229,7 +259,7 @@
         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);
+        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
@@ -240,7 +270,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
+            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
             //瀛樻斁鍦╩ongo涓�
             mongoTemplate.insertAll(carList);
         }
@@ -256,7 +286,7 @@
         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);
+        List<DataIntegrityMonitoringResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/attributeIntegrity/query", param, DataIntegrityMonitoringResult.class);
 
         if (!CollectionUtils.isEmpty(carList)) {
             //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎
@@ -268,7 +298,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
+            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
             //瀛樻斁鍦╩ongo涓�
             mongoTemplate.insertAll(carList);
         }
@@ -284,7 +314,7 @@
         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);
+        List<AttrRecognitionMonitorResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/attributeRecognition/query", param, AttrRecognitionMonitorResult.class);
 
         if (!CollectionUtils.isEmpty(carList)) {
             //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎
@@ -296,7 +326,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
+            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
             //瀛樻斁鍦╩ongo涓�
             mongoTemplate.insertAll(carList);
         }
@@ -314,7 +344,7 @@
         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);
+        List<SnapshotDelayMonitorResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/snapAgingDetail/query", carParam, SnapshotDelayMonitorResult.class);
 
         if (!CollectionUtils.isEmpty(carList)) {
             //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎
@@ -329,7 +359,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
+            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
             mongoTemplate.insertAll(carList);
         }
 
@@ -339,7 +369,7 @@
         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);
+        List<SnapshotDelayMonitorResult> faceList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/snapAgingDetail/query", faceParam, SnapshotDelayMonitorResult.class);
 
         if (!CollectionUtils.isEmpty(faceList)) {
             //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎
@@ -354,7 +384,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(faceList,CheckConstants.Rule_Category_Face);
+            pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face);
             mongoTemplate.insertAll(faceList);
         }
         log.info("缁撴潫鎶撴媿鏁版嵁鏃跺欢鐩戞祴缁撴灉鏁版嵁鍚屾");
@@ -369,7 +399,7 @@
         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);
+        List<PicAccessResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v1/data/picAccessDetail/query", param, PicAccessResult.class);
 
         if (!CollectionUtils.isEmpty(carList)) {
             //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎
@@ -381,7 +411,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
+            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
             //瀛樻斁鍦╩ongo涓�
             mongoTemplate.insertAll(carList);
         }
@@ -397,7 +427,7 @@
         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);
+        List<VehicleDeviceSamplingResult> carList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v2/data/vehSampleAmount/query", param, VehicleDeviceSamplingResult.class);
 
         if (!CollectionUtils.isEmpty(carList)) {
             //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎
@@ -409,7 +439,7 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
+            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
             //瀛樻斁鍦╩ongo涓�
             mongoTemplate.insertAll(carList);
         }
@@ -424,7 +454,7 @@
         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);
+        List<FaceDeviceSamplingResult> faceList = HkApiUtil.sendAPI(host, appKey, appSecret, "/api/dqd/service/rs/v2/data/faceSampleAmount/query", param, FaceDeviceSamplingResult.class);
 
         if (!CollectionUtils.isEmpty(faceList)) {
             //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎
@@ -436,65 +466,149 @@
                     item.setNo(item.getExternalIndexCode());
                 }
             });
-            pointService.setDeviceTagByGB(faceList,CheckConstants.Rule_Category_Face);
+            pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face);
             //瀛樻斁鍦╩ongo涓�
             mongoTemplate.insertAll(faceList);
         }
         log.info("缁撴潫浜鸿劯璁惧鎶芥鎸囨爣鐩戞祴缁撴灉鏁版嵁鍚屾");
     }
 
-    //涓氬姟鏍�
-    public void TreeTask() {
-        log.info("寮�濮嬫墽琛屼笟鍔℃爲鏁版嵁");
-        TreeParam param = new TreeParam();
-        param.setStartDate("2024-12-06");
-        param.setEndDate("2024-12-06");
-        List<HKTreeResult> faceList = HkApiUtil.sendGetAPI(host,appKey,appSecret,"/api/third/timeTree", param, HKTreeResult.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("2024-12-06");
-        param.setEndDate("2024-12-06");
-        List<HKScoreResult> dataList = HkApiUtil.sendGetAPI(host,appKey,appSecret,"/api/third/score/get", param, HKScoreResult.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);
-//        }
+        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("缁撴潫娴峰悍鑰冩牳鎴愮哗鏁版嵁");
+    }
+
+    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"));
+        //TODO:寰呭畬鍠� 閲嶇偣鎬庝箞鍔犺繘鍘�
+        car.setVehicleCaptureIntegrity(new BigDecimal(score.getDownCrossAllCarDataIntegrityScoreString() == null ? "1" : score.getDownCrossAllCarDataIntegrityScoreString()));
+        //TODO:寰呭畬鍠� 涓や釜椤瑰悎鎴愪竴涓�
+        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.getDownCrossNumPushCarScoreString() == null ? "1" : score.getDownCrossNumPushCarScoreString()));
+        //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()));
     }
 
     //瑙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);
+            log.info("鏁版嵁鏍煎紡" + jsonObject);
             JSONObject data = jsonObject.getJSONObject("data");
             if (data == null) {
                 log.error(message, jsonObject);

--
Gitblit v1.8.0