双重预防项目-国泰新华二开定制版
heheng
2025-10-20 317ec348c68c176eada17c509adb45526772fe1b
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
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.ZDTaskDangerLogDTO;
import com.ruoyi.doublePrevention.entity.ZDReport.ZDTaskLogDTO;
import com.ruoyi.doublePrevention.enums.SyncEnum;
import com.ruoyi.project.tr.specialCheck.domin.TbSpecialCheckScoreAndDangerLog;
import com.ruoyi.project.tr.specialCheck.domin.TbSpecialCheckTaskLog;
import com.ruoyi.project.tr.specialCheck.mapper.TbSpecialCheckScoreAndDangerLogMapper;
import com.ruoyi.project.tr.specialCheck.mapper.TbSpecialCheckTaskLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
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;
 
import static com.ruoyi.common.utils.Threads.sleep;
 
@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;
 
    @Autowired
    private TbSpecialCheckScoreAndDangerLogMapper tbSpecialCheckScoreAndDangerLogMapper;
 
 
     @Scheduled(cron = "15 11 0/2 * * ? ")
    //@Scheduled(cron = "0 0/2 * * * ? ")
    public void updateZhunDongTASkLogReportStatus() {
        // 准东基础数据推送
 
        log.info("【AA】开始推送准东专项数据..." + DateUtils.dateTimeNow());
        //专项检查情况记录
        ZDCheckRecordLogWork();
        sleep(5000);
        //专项隐患
        ZDCheckDangerLogWork();
 
    }
 
 
    @Transactional
    public void ZDCheckRecordLogWork() {
        HttpURLConnection con = null;
        BufferedReader buffer = null;
        int responseCode = 200;
        /**
         * 1、专项检查情况记录数据
         * */
        log.info("【QQ】专项检查情况记录数据-处理数据...");
        List<TbSpecialCheckTaskLog> taskLogLists = taskSpecialLogMapper.listZDCheckRecordLog();
 
        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.YYYYMMDD, 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("【【【QQ】专项检查情况记录数据】】" + 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("【QQ】专项检查情况记录数据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();
                                //封装数据
                                handlerZDReportParam.setId(tbSpecialCheckTaskLog.getId());
                                handlerZDReportParam.setZhunReportStatus(SyncEnum.SYNC_EXEC_SUCCESS.getCode());
                                handlerZDReportParam.setZhunReportTime(new Date());
                                taskSpecialLogMapper.updateEventReportStatusZhunDong(handlerZDReportParam);
                            }
                        }
 
                    } else {
                        log.info("【QQ】专项检查情况记录数据推送数据失败..." + eventResultBuffer);
                    }
 
                }
 
            } catch (Exception e) {
                e.printStackTrace();
            }
            log.info("【QQ】专项检查情况记录数据推送数据结束...");
        } else {
            log.info("【QQ】专项检查情况记录数据无可推数据");
        }
    }
 
 
    @Transactional
    public void ZDCheckDangerLogWork() {
        HttpURLConnection con = null;
        BufferedReader buffer = null;
        int responseCode = 200;
        /**
         * 1、专项检查隐患信息
         * */
        log.info("【PP】专项检查隐患信息数据-处理数据...");
        List<TbSpecialCheckScoreAndDangerLog> dangerLogs = tbSpecialCheckScoreAndDangerLogMapper.listCheckDangerList();
 
        if (ObjectUtils.isNotEmpty(dangerLogs)) {
            List<ZDTaskDangerLogDTO> zdTaskDangerLogDTOS = new ArrayList<>();
            for (TbSpecialCheckScoreAndDangerLog dangerLog : dangerLogs) {
                ZDTaskDangerLogDTO taskDangerLogDTO = new ZDTaskDangerLogDTO();
                taskDangerLogDTO.setId(dangerLog.getId());
                taskDangerLogDTO.setDanger_id(dangerLog.getDangerId());
                taskDangerLogDTO.setTask_id(dangerLog.getTaskId());
                taskDangerLogDTO.setCheck_type(dangerLog.getCheckType());
                taskDangerLogDTO.setCheck_date(DateUtils.parseDateToStrLocal(DateUtils.YYYYMMDD, dangerLog.getCheckDate()));
                taskDangerLogDTO.setCheck_pay(dangerLog.getCheckPay());
                taskDangerLogDTO.setCheck_item_id(dangerLog.getCheckItemId());
                taskDangerLogDTO.setCheck_score_id(dangerLog.getCheckScoreId());
                taskDangerLogDTO.setHarm_type(dangerLog.getHarmType());
                taskDangerLogDTO.setCreate_date(DateUtils.parseDateToStrLocal(DateUtils.YYYYMMDDHHMMSS, dangerLog.getCreateDate()));
                taskDangerLogDTO.setUpdate_date(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
                taskDangerLogDTO.setCreate_by(dangerLog.getCreateBy());
                taskDangerLogDTO.setUpdate_by(dangerLog.getUpdateBy());
                taskDangerLogDTO.setDeleted(dangerLog.getDeleted().toString());
 
                zdTaskDangerLogDTOS.add(taskDangerLogDTO);
            }
 
            log.info("【【【PP】专项检查隐患信息数据】】" + JSONObject.toJSONString(zdTaskDangerLogDTOS));
            //加密数据
 
            StringBuffer eventResultBuffer = null;
            //上报数据
            try {
                URL url = new URL(URL + "/api/wwyt/tb_base_check_danger_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(zdTaskDangerLogDTOS).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("【PP】专项检查隐患信息数据result:" + eventResultBuffer.toString());
 
                    JSONObject jsonObject = JSONObject.parseObject(eventResultBuffer.toString());
                    if (jsonObject.getInteger("status") == 200) {
                        String message = jsonObject.getString("message");
                        if (message.contains("失效0条")) {
                            for (TbSpecialCheckScoreAndDangerLog scoreAndDangerLog : dangerLogs) {
                                HandlerZDReportParam handlerZDReportParam = new HandlerZDReportParam();
                                //封装数据
                                handlerZDReportParam.setId(scoreAndDangerLog.getId());
                                handlerZDReportParam.setZhunReportStatus(SyncEnum.SYNC_EXEC_SUCCESS.getCode());
                                handlerZDReportParam.setZhunReportTime(new Date());
                                tbSpecialCheckScoreAndDangerLogMapper.updateEventReportStatusZhunDong(handlerZDReportParam);
                            }
                        }
 
                    } else if (jsonObject.getInteger("status") == 500) {
                        String message = jsonObject.getString("message");
                        if (message.contains("不存在danger_id为")) {
                            String s = extractDangerId(message);
                            if (ObjectUtils.isNotEmpty(s)) {
                                HandlerZDReportParam handlerZDReportParam = new HandlerZDReportParam();
                                //封装数据
                                handlerZDReportParam.setId(s);
                                handlerZDReportParam.setZhunReportStatus(SyncEnum.SYNC_EXEC_FAIL.getCode());
                                handlerZDReportParam.setZhunReportTime(new Date());
                                tbSpecialCheckScoreAndDangerLogMapper.updateEventReportStatusZhunDongSp(handlerZDReportParam);
                            }
                        }
 
 
                        log.info("【PP】专项检查隐患信息数据推送数据失败..." + eventResultBuffer);
                    } else {
                        log.info("【PP】专项检查隐患信息数据推送数据失败..." + eventResultBuffer);
                    }
 
                }
 
            } catch (Exception e) {
                e.printStackTrace();
            }
            log.info("【PP】专项检查隐患信息数据推送数据结束...");
        } else {
            log.info("【PP】专项检查隐患信息数据无可推数据");
        }
    }
 
 
    public static String extractDangerId(String message) {
        // 方法1: 使用substring方式提取
        String prefix = "不存在danger_id为";
        String suffix = "的隐患";
 
        if (message.contains(prefix) && message.contains(suffix)) {
            int startIndex = message.indexOf(prefix) + prefix.length();
            int endIndex = message.indexOf(suffix);
            return message.substring(startIndex, endIndex);
        }
        return null;
//        int start = message.indexOf("不存在danger_id为") + "不存在danger_id为".length();
//        int end = message.indexOf("的隐患");
//        if (end > start) {
//            return message.substring(start, end);
//        }
//        return null;
    }
}