fuliqi
2024-07-29 ad31fa93abe524baec2216f9b2f203acb8cc2d6a
ycl-server/src/main/java/com/ycl/task/HKTask.java
@@ -1,16 +1,19 @@
package com.ycl.task;
import com.alibaba.fastjson2.JSONObject;
import com.ycl.platform.domain.entity.YwThreshold;
import com.ycl.platform.domain.param.HK.FaceDeviceInspectionParam;
import com.ycl.platform.domain.param.HK.SnapshotDataMonitorParam;
import com.ycl.platform.domain.param.HK.VehicleDeviceInspectionParam;
import com.ycl.platform.domain.result.HK.BaseResult;
import com.ycl.platform.domain.result.HK.FaceDeviceInspectionResult;
import com.ycl.platform.domain.result.HK.SnapshotDataMonitorResult;
import com.ycl.platform.domain.result.HK.VehicleDeviceInspectionResult;
import com.ycl.platform.mapper.YwThresholdMapper;
import com.ycl.platform.service.ICheckIndexCarService;
import com.ycl.platform.service.ICheckIndexFaceService;
import com.ycl.platform.service.ICheckIndexVideoService;
import com.ycl.platform.service.IYwThresholdService;
import com.ycl.web.HKClient;
import enumeration.BusinessType;
import enumeration.general.BusinessTypeEnum;
import constant.ApiConstants;
import com.ycl.feign.HKClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
@@ -32,69 +35,144 @@
    private HKClient hkClient;
    @Autowired
    private IYwThresholdService ywThresholdService;
    private final static Integer pageNo = 1;
    private final static Integer pageSize = 5000;
    //成功状态码
    private final static String successCode = "0";
    @Autowired
    private ICheckIndexFaceService checkIndexFaceService;
    @Autowired
    private ICheckIndexCarService checkIndexCarService;
    @Autowired
    private ICheckIndexVideoService checkIndexVideoService;
    //车辆设备全检指标监测结果
    public void VehicleDeviceInspectionTask() {
        log.info("开始执行车辆设备全检指标监测结果数据同步");
        VehicleDeviceInspectionParam param = new VehicleDeviceInspectionParam();
        param.setPageNO(pageNo).setPageSize(pageSize).setDate(getToday());
        param.setPageNO(ApiConstants.pageNo).setPageSize(ApiConstants.pageSize).setDate(getToday());
        JSONObject jsonObject = hkClient.VehicleDeviceInspection(param);
        if (jsonObject != null && successCode.equals(jsonObject.getString("code"))) {
            JSONObject data = jsonObject.getJSONObject("data");
            if (data == null) {
                throw new RuntimeException("车辆设备全检指标监测结果数据为空");
            }
            List<VehicleDeviceInspectionResult> list = data.getList("list", VehicleDeviceInspectionResult.class);
            list.forEach(item ->item.setCreateTime(new Date()));
            if (CollectionUtils.isEmpty(list)) {
                throw new RuntimeException("车辆设备全检指标监测结果数据为空");
            }
        List<VehicleDeviceInspectionResult> list = getDataList(jsonObject, VehicleDeviceInspectionResult.class, "车辆设备全检指标监测结果数据为空");
        if (!CollectionUtils.isEmpty(list)) {
            //存放在mongo中
            mongoTemplate.insert(list);
            //同步的数据进行工单阈值处理
            ywThresholdService.carCheck(list);
        } else {
            log.error("同步车辆设备全检指标监测结果失败", jsonObject);
        }
        log.info("结束车辆设备全检指标监测结果数据同步");
    }
    //人脸设备全检指标监测结果
    public void FaceDeviceInspectionTask() {
        log.info("开始执行人脸设备全检指标监测结果数据同步");
        FaceDeviceInspectionParam param = new FaceDeviceInspectionParam();
        param.setPageNO(pageNo).setPageSize(pageSize).setDate(getToday());
        param.setPageNO(ApiConstants.pageNo).setPageSize(ApiConstants.pageSize).setDate(getToday());
        JSONObject jsonObject = hkClient.FaceDeviceInspection(param);
        if (jsonObject != null && successCode.equals(jsonObject.getString("code"))) {
            JSONObject data = jsonObject.getJSONObject("data");
            if (data == null) {
                throw new RuntimeException("人脸设备全检指标监测结果数据为空");
            }
            List<FaceDeviceInspectionResult> list = data.getList("list", FaceDeviceInspectionResult.class);
            list.forEach(item ->item.setCreateTime(new Date()));
            if (CollectionUtils.isEmpty(list)) {
                throw new RuntimeException("人脸设备全检指标监测结果数据为空");
            }
            //TODO:同步的数据可能需要工单阈值等处理
        List<FaceDeviceInspectionResult> list = getDataList(jsonObject, FaceDeviceInspectionResult.class, "人脸设备全检指标监测结果数据为空");
        if (!CollectionUtils.isEmpty(list)) {
            //存放在mongo中
            mongoTemplate.insert(list);
        } else {
            log.error("同步人脸设备全检指标监测结果失败", jsonObject);
            //同步的数据进行工单阈值处理
            ywThresholdService.faceCheck(list);
        }
        log.info("结束人脸设备全检指标监测结果数据同步");
    }
    //抓拍数据量监测结果
    public void SnapshotDataMonitorTask() {
        log.info("开始执行抓拍数据量检测结果数据同步");
        /** 车辆数据 */
        SnapshotDataMonitorParam carParam = new SnapshotDataMonitorParam();
        carParam.setPageNO(ApiConstants.pageNo).setPageSize(ApiConstants.pageSize).setDate(getToday()).setDataType(ApiConstants.HK_DATATYPE_CAR);
        JSONObject carJsonObject = hkClient.SnapshotDataMonitor(carParam);
        List<SnapshotDataMonitorResult> carList = getDataList(carJsonObject, SnapshotDataMonitorResult.class, "车辆抓拍数据量检测结果数据");
        if (!CollectionUtils.isEmpty(carList)) {
            //存放在mongo中
            mongoTemplate.insert(carList);
            //TODO:车辆点位在线率
            checkIndexCarService.siteOnline(carList);
        }
        /** 人脸数据 */
        SnapshotDataMonitorParam faceParam = new SnapshotDataMonitorParam();
        faceParam.setPageNO(ApiConstants.pageNo).setPageSize(ApiConstants.pageSize).setDate(getToday()).setDataType(ApiConstants.HK_DATATYPE_FACE);
        JSONObject faceJsonObject = hkClient.SnapshotDataMonitor(carParam);
        List list = getDataList(faceJsonObject, SnapshotDataMonitorResult.class, "人脸抓拍数据量检测结果数据为空");
        if (!CollectionUtils.isEmpty(list)) {
            //存放在mongo中
            mongoTemplate.insert(list);
            //TODO:人脸点位在线率
            checkIndexFaceService.siteOnline(list);
        }
        log.info("结束抓拍数据量检测结果数据同步");
    }
    //一机一档
    public void task2() {
        //联网卡口设备目录一致率
    }
    //卡口属性监测结果
    public void task3() {
        //车辆卡口信息采集准确率
    }
    //数据完整性监测结果
    public void task4() {
        //车辆卡口设备抓拍数据完整性
    }
    //属性识别准确监测结果
    public void task5() {
        //车辆卡口设备抓拍数据完整性
    }
    //车辆设备全检指标监测结果
    public void task6() {
        //车辆卡口设备时钟准确性
    }
    //抓拍数据时延监测结果
    public void task7() {
        //车辆卡口设备抓拍数据上传及时性
    }
    //图片访问监测结果
    public void task8() {
        //车辆卡口信息采集准确率
        //车辆卡口设备url可用性
    }
    //获取当前日期
    private String getToday() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String today = sdf.format(date);
        return today;
    }
    //解析数据
    private <T> List<T> getDataList(JSONObject faceJsonObject, Class<T> resultClass, String message) {
        if (faceJsonObject != null && ApiConstants.successCode.equals(faceJsonObject.getString("code"))) {
            JSONObject data = faceJsonObject.getJSONObject("data");
            if (data == null) {
                log.error(message, faceJsonObject);
                return null;
            }
            List<T> list = data.getList("list", resultClass);
            if (CollectionUtils.isEmpty(list)) {
                log.error(message, data);
                return null;
            }
            for (T t : list) {
                if (t instanceof BaseResult) {
                    ((BaseResult) t).setCreateTime(new Date());
                }
            }
            return list;
        } else {
            log.error(message);
        }
        return null;
    }
}