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】隐患排查任务基础数据无可推数据");
|
}
|
}
|
}
|