双重预防项目-国泰新华二开定制版
heheng
2025-06-24 e98eeaaa5766511fdb8e6d5e412eb1c59d1f07ce
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.ruoyi.doublePrevention.scheduls;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.doublePrevention.entity.ZDReport.HandlerZDReportParam;
import com.ruoyi.doublePrevention.entity.ZDReport.ZDTaskLogDTO;
import com.ruoyi.project.tr.specialCheck.domin.TbSpecialCheckTaskLog;
import com.ruoyi.project.tr.specialCheck.mapper.TbSpecialCheckTaskLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@Component
@Slf4j
public class ZhunDongTaskLogSchedule {
 
    private static final String TOKEN = "030B6744-EECB-4732-B679-280373E7E575";
    private static final String URL = "http://218.31.50.112:8087";
    private static final String TOKEN_PRE = "token";
    @Autowired
    private TbSpecialCheckTaskLogMapper taskSpecialLogMapper;
    // @Scheduled(cron = "0 0/6 * * * ? ")
    public void updateZhunDongTASkLogReportStatus() {
        //todo 准东基础数据推送
    }
 
 
    @Transactional
    public void ZDTaskLogWork() {
        HttpURLConnection con = null;
        BufferedReader buffer = null;
        int responseCode = 200;
        /**
         * 1、隐患排查任务基础数据
         * */
        log.info("【Q】隐患排查任务基础数据-处理数据...");
        //todo 更换查询sql
        List<TbSpecialCheckTaskLog> taskLogLists = taskSpecialLogMapper.listTestReportTask();
 
        if (ObjectUtils.isNotEmpty(taskLogLists)) {
            List<ZDTaskLogDTO> zdTaskLogDTOS = new ArrayList<>();
            for (TbSpecialCheckTaskLog specialCheckTaskLog : taskLogLists) {
                ZDTaskLogDTO zdTaskLogDTO = new ZDTaskLogDTO();
                zdTaskLogDTO.setId(specialCheckTaskLog.getId());
                zdTaskLogDTO.setHazard_code(specialCheckTaskLog.getHazardCode());
                zdTaskLogDTO.setTask_id(specialCheckTaskLog.getTaskId());
                zdTaskLogDTO.setCheck_type(specialCheckTaskLog.getCheckType());
                zdTaskLogDTO.setCheck_date(DateUtils.parseDateToStrLocal(DateUtils.YYYYMMDDHHMMSS, specialCheckTaskLog.getCheckDate()));
                zdTaskLogDTO.setCreate_date(DateUtils.parseDateToStrLocal(DateUtils.YYYYMMDDHHMMSS, specialCheckTaskLog.getCreateDate()));
                zdTaskLogDTO.setUpdate_date(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
                zdTaskLogDTO.setCreate_by(specialCheckTaskLog.getCreateBy());
                zdTaskLogDTO.setUpdate_by(specialCheckTaskLog.getUpdateBy());
                zdTaskLogDTO.setDeleted(specialCheckTaskLog.getDeleted().toString());
                zdTaskLogDTOS.add(zdTaskLogDTO);
            }
 
            log.info("【【【Q】隐患排查任务基础数据】】" + JSONObject.toJSONString(zdTaskLogDTOS));
            //加密数据
 
            StringBuffer eventResultBuffer = null;
            //上报数据
            try {
                URL url = new URL(URL + "/api/wwyt/tb_base_check_record_List");
                //得到连接对象
                con = (HttpURLConnection) url.openConnection();
                // 设置请求方式和参数
                con.setRequestMethod("POST");
                con.setDoOutput(true);
                con.setDoInput(true);
                con.setUseCaches(false);
                con.setRequestProperty("token", TOKEN);
                con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
                // 发送请求体
                try (OutputStream os = con.getOutputStream()) {
                    os.write(JSON.toJSONString(zdTaskLogDTOS).getBytes(StandardCharsets.UTF_8));
                }
                //得到响应码
                responseCode = con.getResponseCode();
                //确认响应流不为空
                if (responseCode == HttpURLConnection.HTTP_OK) {
                    //得到响应流
                    InputStream inputStream = con.getInputStream();
                    //将响应流转换成字符串
                    eventResultBuffer = new StringBuffer();
                    String line;
                    buffer = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
                    while ((line = buffer.readLine()) != null) {
                        eventResultBuffer.append(line);
                    }
                    log.info("【Q】隐患排查任务基础数据result:" + eventResultBuffer.toString());
 
                    JSONObject jsonObject = JSONObject.parseObject(eventResultBuffer.toString());
                    if (jsonObject.getInteger("status") == 200) {
                        String message = jsonObject.getString("message");
                        if (message.contains("失效0条")) {
                            for (TbSpecialCheckTaskLog tbSpecialCheckTaskLog : taskLogLists) {
                                HandlerZDReportParam handlerZDReportParam = new HandlerZDReportParam();
                                //todo 更换查询数据
                                //封装数据
//                                handlerZDReportParam.setId(CJEvent.getId());
//                                handlerZDReportParam.setZhunReportStatus(SyncEnum.SYNC_EXEC_SUCCESS.getCode());
//                                handlerZDReportParam.setZhunReportTime(new Date());
//                                CJEventService.updateEventReportStatusHuaiDong(handlerZDReportParam);
                            }
                        }
 
                    } else {
                        log.info("【Q】隐患排查任务基础数据推送数据失败..." + eventResultBuffer);
                    }
 
                }
 
            } catch (Exception e) {
                e.printStackTrace();
            }
            log.info("【Q】隐患排查任务基础数据推送数据结束...");
        }else {
            log.info("【Q】隐患排查任务基础数据无可推数据");
        }
    }
}