fuliqi
2024-07-22 2be2f6c3e5b2be2bae1562423a9a4d29aa174aae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.ycl.task;
 
import com.alibaba.fastjson2.JSONObject;
import com.ycl.platform.domain.entity.YwThreshold;
import com.ycl.platform.domain.param.HK.FaceDeviceInspectionParam;
import com.ycl.platform.domain.param.HK.VehicleDeviceInspectionParam;
import com.ycl.platform.domain.result.HK.FaceDeviceInspectionResult;
import com.ycl.platform.domain.result.HK.VehicleDeviceInspectionResult;
import com.ycl.platform.mapper.YwThresholdMapper;
import com.ycl.web.HKClient;
import enumeration.BusinessType;
import enumeration.general.BusinessTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
 
@Slf4j
@Component("HKTask")
public class HKTask {
 
    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private HKClient hkClient;
    @Autowired
    private YwThresholdMapper thresholdMapper;
 
    private final static Integer pageNo = 1;
    private final static Integer pageSize = 5000;
    //成功状态码
    private final static String successCode = "0";
 
    //车辆设备全检指标监测结果
    public void VehicleDeviceInspectionTask() {
        log.info("开始执行车辆设备全检指标监测结果数据同步");
        VehicleDeviceInspectionParam param = new VehicleDeviceInspectionParam();
        param.setPageNO(pageNo).setPageSize(pageSize).setDate(getToday());
        JSONObject jsonObject = hkClient.VehicleDeviceInspection(param);
        if (jsonObject != null && successCode.equals(jsonObject.getString("code"))) {
            JSONObject data = jsonObject.getJSONObject("data");
            if (data == null) {
                throw new RuntimeException("车辆设备全检指标监测结果数据为空");
            }
            List<VehicleDeviceInspectionResult> list = data.getList("list", VehicleDeviceInspectionResult.class);
            list.forEach(item ->item.setCreateTime(new Date()));
            if (CollectionUtils.isEmpty(list)) {
                throw new RuntimeException("车辆设备全检指标监测结果数据为空");
            }
            //TODO:同步的数据可能需要工单阈值等处理
            List<YwThreshold> ywThresholds = thresholdMapper.selectByType(BusinessTypeEnum.CAR.name());
            //存放在mongo中
            mongoTemplate.insert(list);
        } else {
            log.error("同步车辆设备全检指标监测结果失败", jsonObject);
        }
        log.info("结束车辆设备全检指标监测结果数据同步");
    }
 
 
    public void FaceDeviceInspectionTask() {
        log.info("开始执行人脸设备全检指标监测结果数据同步");
        FaceDeviceInspectionParam param = new FaceDeviceInspectionParam();
        param.setPageNO(pageNo).setPageSize(pageSize).setDate(getToday());
        JSONObject jsonObject = hkClient.FaceDeviceInspection(param);
        if (jsonObject != null && successCode.equals(jsonObject.getString("code"))) {
            JSONObject data = jsonObject.getJSONObject("data");
            if (data == null) {
                throw new RuntimeException("人脸设备全检指标监测结果数据为空");
            }
            List<FaceDeviceInspectionResult> list = data.getList("list", FaceDeviceInspectionResult.class);
            list.forEach(item ->item.setCreateTime(new Date()));
            if (CollectionUtils.isEmpty(list)) {
                throw new RuntimeException("人脸设备全检指标监测结果数据为空");
            }
            //TODO:同步的数据可能需要工单阈值等处理
 
            //存放在mongo中
            mongoTemplate.insert(list);
        } else {
            log.error("同步人脸设备全检指标监测结果失败", jsonObject);
        }
        log.info("结束人脸设备全检指标监测结果数据同步");
    }
 
 
    private String getToday() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String today = sdf.format(date);
        return today;
    }
}