zxl
16 小时以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
ycl-server/src/main/java/com/ycl/task/HKTask.java
@@ -1,26 +1,41 @@
package com.ycl.task;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mongodb.client.result.DeleteResult;
import com.ycl.feign.HkApiUtil;
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.util.Date;
import java.util.List;
import java.util.Objects;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
//海康对接数据任务
@Slf4j
@@ -33,12 +48,34 @@
    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 ICheckIndexCarService carService;
    @Autowired
    private CheckIndexCarMapper carMapper;
    @Autowired
    private ICheckIndexFaceService faceService;
    @Autowired
    private CheckIndexFaceMapper faceMapper;
    //车辆设备全检指标监测结果
    public void vehicleDeviceInspectionTask() {
@@ -48,7 +85,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())));
@@ -77,7 +114,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())));
@@ -87,7 +124,7 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(list,CheckConstants.Rule_Category_Face);
            pointService.setDeviceTagByGB(list, CheckConstants.Rule_Category_Face);
            //存放在mongo中
            mongoTemplate.insertAll(list);
            //同步的数据进行工单阈值处理
@@ -108,7 +145,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
@@ -120,12 +157,10 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
            //存放在mongo中
            carList.forEach(item -> item.setDataType(ApiConstants.HK_DataType_CAR));
            mongoTemplate.insertAll(carList);
            //TODO:更新point表在线状态(有抓拍量视作在线)
            //工单
        }
        /** 人脸数据 */
@@ -134,9 +169,8 @@
        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());
            //如果今天存在之前的数据先删除
            Query query = new Query(Criteria
                    .where("mongoCreateTime").gte(DateUtils.getDayStart(new Date())).lt(DateUtils.getDayEnd(new Date()))
@@ -147,14 +181,62 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(faceList,CheckConstants.Rule_Category_Face);
            pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face);
            //存放在mongo中
            faceList.forEach(item -> item.setDataType(ApiConstants.HK_DataType_FACE));
            mongoTemplate.insertAll(faceList);
            //TODO:更新point表在线状态(有抓拍量视作在线)
            //工单
        }
        //修改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);
//            //离线生成工单,一个ip只生成一个工单
//            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("结束抓拍数据量检测结果数据同步");
    }
@@ -166,7 +248,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
@@ -177,7 +259,7 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(faceList,CheckConstants.Rule_Category_Face);
            pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face);
            //存放在mongo中
            mongoTemplate.insertAll(faceList);
        }
@@ -192,7 +274,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
@@ -203,7 +285,7 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
            //存放在mongo中
            mongoTemplate.insertAll(carList);
        }
@@ -219,7 +301,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)) {
            //如果今天存在之前的数据先删除
@@ -231,7 +313,7 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
            //存放在mongo中
            mongoTemplate.insertAll(carList);
        }
@@ -247,7 +329,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)) {
            //如果今天存在之前的数据先删除
@@ -259,7 +341,7 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
            //存放在mongo中
            mongoTemplate.insertAll(carList);
        }
@@ -277,7 +359,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)) {
            //如果今天存在之前的数据先删除
@@ -292,7 +374,7 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
            mongoTemplate.insertAll(carList);
        }
@@ -302,7 +384,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)) {
            //如果今天存在之前的数据先删除
@@ -317,7 +399,7 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(faceList,CheckConstants.Rule_Category_Face);
            pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face);
            mongoTemplate.insertAll(faceList);
        }
        log.info("结束抓拍数据时延监测结果数据同步");
@@ -332,7 +414,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)) {
            //如果今天存在之前的数据先删除
@@ -344,7 +426,7 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
            //存放在mongo中
            mongoTemplate.insertAll(carList);
        }
@@ -360,7 +442,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)) {
            //如果今天存在之前的数据先删除
@@ -372,7 +454,7 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(carList,CheckConstants.Rule_Category_Car);
            pointService.setDeviceTagByGB(carList, CheckConstants.Rule_Category_Car);
            //存放在mongo中
            mongoTemplate.insertAll(carList);
        }
@@ -387,7 +469,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)) {
            //如果今天存在之前的数据先删除
@@ -399,41 +481,443 @@
                    item.setNo(item.getExternalIndexCode());
                }
            });
            pointService.setDeviceTagByGB(faceList,CheckConstants.Rule_Category_Face);
            pointService.setDeviceTagByGB(faceList, CheckConstants.Rule_Category_Face);
            //存放在mongo中
            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);
//            //存放在mongo中
//            mongoTemplate.insertAll(faceList);
    //考核成绩
//    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");
//        // 获取当前时间的Calendar实例
//        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);
//
//                //根据数据转换为index对象
//                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);
//                });
//            }
//        }
        log.info("结束业务树数据");
//
//        //先请求省厅数据
//        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);
//
//                //根据数据转换为index对象
//                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);
//                });
//            }
//        }
//        //存放成绩到mysql,如果存在则替换不存在就新增。
//        if (!CollectionUtils.isEmpty(cars)) carService.saveOrUpdateBatch(cars);
//        if (!CollectionUtils.isEmpty(faces)) faceService.saveOrUpdateBatch(faces);
//        log.info("结束海康考核成绩数据");
//    }
    public void HkScoreTask(){
        log.info("开始执行海康考核成绩数据");
        //先执行获得标签 因为全量默认传参为null,但是省厅数据需要获得标签
        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的data:{}",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("海康获取省厅考核标签为null");
        }
        //准备新增或修改的数据
        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");
        // 获取当前时间的Calendar实例
        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();
        //------------默认参数为null请求全量数据
        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 的批次id对象 放入map中
                for (String batchIdKey :data.keySet() ) {
                    JSONObject batch = data.getJSONObject(batchIdKey);
                    //以批次id为key 放入 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数组的key
                    for (String areaCodeKey : map.get(id).keySet()) {
                        //存放最新批次的内容到allInfo集合中
                        log.error("打印区信息:{}",map.get(id).get(areaCodeKey));
                        allInfo.addAll(map.get(id).getList(areaCodeKey,HkResultInfo.class));
                    }
                }
                //对allInfo进行分组 分组按区域id
                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 的批次id对象 放入map中
                    for (String batchIdKey :data.keySet() ) {
                        JSONObject batch = data.getJSONObject(batchIdKey);
                        //以批次id为key 放入 JSONObject对象
                        map.put(Integer.valueOf(batchIdKey),batch);
                        //批次id 下 各区信息集合
                        log.error("打印出省厅人脸data内容中批次id:{},以及对应的结果info:{}",batchIdKey,batch);
                    }
                //获得最大的键值
                    Optional<Integer> maxKey = map.keySet().stream()
                            .max(Integer::compareTo);
                    if (maxKey.isPresent()) {
                        //获取最大的key 接口返回内容中最新的批次
                        Integer id = maxKey.get();
                        //这一层为获得 data -> 中 批次数组中 -> 区域code数组的key
                        for (String areaCodeKey : map.get(id).keySet()) {
                            //存放最新批次的内容到allInfo集合中
                            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 的批次id对象 放入map中
                    for (String batchIdKey :data.keySet() ) {
                        JSONObject batch = data.getJSONObject(batchIdKey);
                        //以批次id为key 放入 JSONObject对象
                        map.put(Integer.valueOf(batchIdKey),batch);
                        //批次id 下 各区信息集合
                        log.error("打印出省厅成辆data内容中批次id:{},以及对应的结果info:{}",batchIdKey,batch);
                    }
                    //获得最大的键值
                    Optional<Integer> maxKey = map.keySet().stream()
                            .max(Integer::compareTo);
                    if (maxKey.isPresent()) {
                        //获取最大的key 接口返回内容中最新的批次
                        Integer id = maxKey.get();
                        //这一层为获得 data -> 中 批次数组中 -> 区域code数组的key
                        for (String areaCodeKey : map.get(id).keySet()) {
                            //存放最新批次的内容到allInfo集合中
                            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);
        //存放成绩到mysql,如果存在则替换不存在就新增。
        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"));
    }
    //解析数据
    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);