双重预防项目-国泰新华二开定制版
heheng
2025-10-20 2b67ed2da39eba5824cfee7950e03be2c1a256ec
src/main/java/com/ruoyi/doublePrevention/scheduls/ZhunDongTaskLogSchedule.java
@@ -5,11 +5,16 @@
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;
@@ -24,32 +29,47 @@
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";
    //    private static final String TOKEN_PRE = "token";
    @Autowired
    private TbSpecialCheckTaskLogMapper taskSpecialLogMapper;
    // @Scheduled(cron = "0 0/6 * * * ? ")
    @Autowired
    private TbSpecialCheckScoreAndDangerLogMapper tbSpecialCheckScoreAndDangerLogMapper;
    // @Scheduled(cron = "35 1 0/2 * * ? ")
    @Scheduled(cron = "0 0/2 * * * ? ")
    public void updateZhunDongTASkLogReportStatus() {
        //todo 准东基础数据推送
        // 准东基础数据推送
        log.info("【AA】开始推送准东专项数据..." + DateUtils.dateTimeNow());
        //专项检查情况记录
        ZDCheckRecordLogWork();
        sleep(5000);
        //专项隐患
        ZDCheckDangerLogWork();
    }
    @Transactional
    public void ZDTaskLogWork() {
    public void ZDCheckRecordLogWork() {
        HttpURLConnection con = null;
        BufferedReader buffer = null;
        int responseCode = 200;
        /**
         * 1、隐患排查任务基础数据
         * 1、专项检查情况记录数据
         * */
        log.info("【Q】隐患排查任务基础数据-处理数据...");
        //todo 更换查询sql
        List<TbSpecialCheckTaskLog> taskLogLists = taskSpecialLogMapper.listTestReportTask();
        log.info("【QQ】专项检查情况记录数据-处理数据...");
        List<TbSpecialCheckTaskLog> taskLogLists = taskSpecialLogMapper.listZDCheckRecordLog();
        if (ObjectUtils.isNotEmpty(taskLogLists)) {
            List<ZDTaskLogDTO> zdTaskLogDTOS = new ArrayList<>();
@@ -59,7 +79,7 @@
                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.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());
@@ -68,7 +88,7 @@
                zdTaskLogDTOS.add(zdTaskLogDTO);
            }
            log.info("【【【Q】隐患排查任务基础数据】】" + JSONObject.toJSONString(zdTaskLogDTOS));
            log.info("【【【QQ】专项检查情况记录数据】】" + JSONObject.toJSONString(zdTaskLogDTOS));
            //加密数据
            StringBuffer eventResultBuffer = null;
@@ -101,7 +121,7 @@
                    while ((line = buffer.readLine()) != null) {
                        eventResultBuffer.append(line);
                    }
                    log.info("【Q】隐患排查任务基础数据result:" + eventResultBuffer.toString());
                    log.info("【QQ】专项检查情况记录数据result:" + eventResultBuffer.toString());
                    JSONObject jsonObject = JSONObject.parseObject(eventResultBuffer.toString());
                    if (jsonObject.getInteger("status") == 200) {
@@ -109,17 +129,16 @@
                        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);
                                handlerZDReportParam.setId(tbSpecialCheckTaskLog.getId());
                                handlerZDReportParam.setZhunReportStatus(SyncEnum.SYNC_EXEC_SUCCESS.getCode());
                                handlerZDReportParam.setZhunReportTime(new Date());
                                taskSpecialLogMapper.updateEventReportStatusZhunDong(handlerZDReportParam);
                            }
                        }
                    } else {
                        log.info("【Q】隐患排查任务基础数据推送数据失败..." + eventResultBuffer);
                        log.info("【QQ】专项检查情况记录数据推送数据失败..." + eventResultBuffer);
                    }
                }
@@ -127,9 +146,143 @@
            } catch (Exception e) {
                e.printStackTrace();
            }
            log.info("【Q】隐患排查任务基础数据推送数据结束...");
        }else {
            log.info("【Q】隐患排查任务基础数据无可推数据");
            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;
    }
}