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 |  489 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 399 insertions(+), 90 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 759cf0e..b9388dd 100644
--- a/ycl-server/src/main/java/com/ycl/task/HKTask.java
+++ b/ycl-server/src/main/java/com/ycl/task/HKTask.java
@@ -3,21 +3,17 @@
 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.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.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;
@@ -27,9 +23,11 @@
 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;
 
@@ -173,7 +171,6 @@
         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)) {
-            log.info("缁撴灉鏁版嵁澶у皬锛歿}", faceList.size());
             //濡傛灉浠婂ぉ瀛樺湪涔嬪墠鐨勬暟鎹厛鍒犻櫎
             Query query = new Query(Criteria
                     .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))
@@ -189,38 +186,56 @@
             faceList.forEach(item -> item.setDataType(ApiConstants.HK_DataType_FACE));
             mongoTemplate.insertAll(faceList);
         }
-        //淇敼online鐘舵�佷互鍙婄敓鎴愬伐鍗�
+        //淇敼online鐘舵��
         List<SnapshotDataMonitorResult> totalResult = new ArrayList<>();
         totalResult.addAll(carList);
         totalResult.addAll(faceList);
         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 -> {
-                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.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);
+            //鍏堟嬁浼樹簯鐨勫湪绾匡紝杩囨护鎺変紭浜戝凡鏈夌殑鍥芥爣鐮�
+            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("缁撴潫鎶撴媿鏁版嵁閲忔娴嬬粨鏋滄暟鎹悓姝�");
     }
@@ -474,15 +489,138 @@
     }
 
     //鑰冩牳鎴愮哗
-    public void HkScoreTask() {
+//    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();
@@ -490,23 +628,55 @@
         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);
+//        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)) {
-                List<HKScoreResult> data = scoreJson.getList("data", HKScoreResult.class);
-                //鏍规嵁鏁版嵁杞崲涓篿ndex瀵硅薄
-                data.forEach(score -> {
+            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();
-                    score2Index(score, car, face);
+                    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()
@@ -523,47 +693,122 @@
                     }
                     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");
 
-        //鍏堣姹傜渷鍘呮暟鎹�
-        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);
+                    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));
+                        }
+                    }
 
-                //鏍规嵁鏁版嵁杞崲涓篿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);
-                });
+                }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);
@@ -581,30 +826,94 @@
         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:寰呭畬鍠�
+        //TODO:娌℃壘鍒拌�冩牳椤�
         car.setVehicleInformationCollectionAccuracy(new BigDecimal("1"));
-        //TODO:寰呭畬鍠� 閲嶇偣鎬庝箞鍔犺繘鍘�
         car.setVehicleCaptureIntegrity(new BigDecimal(score.getDownCrossAllCarDataIntegrityScoreString() == null ? "1" : score.getDownCrossAllCarDataIntegrityScoreString()));
-        //TODO:寰呭畬鍠� 涓や釜椤瑰悎鎴愪竴涓�
+        //娴峰悍鏄涓�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:寰呭畬鍠�
+        //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.setDeviceDirectoryConsistent(new BigDecimal(score.getDownCrossNumPushFaceScoreString() == null ? "1" : score.getDownCrossNumPushFaceScoreString()));
+        //TODO:娌℃壘鍒拌�冩牳椤�
         face.setFaceInformationCollectionAccuracy(new BigDecimal("1"));
-        //TODO:寰呭畬鍠�
+        //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"))) {

--
Gitblit v1.8.0