双重预防项目-国泰新华二开定制版
heheng
2025-06-06 2b9d73629912d3982af1d96da8f9d50b7863cd58
优化每年专项数据获取,定时重推数据
已修改3个文件
已添加1个文件
207 ■■■■ 文件已修改
src/main/java/com/ruoyi/doublePrevention/repository/PreventCJReportCheckRecordFromTaskRepository.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/doublePrevention/scheduls/RePushDataSchedule.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/project/tr/specialCheck/Test/SpecialCheckTaskDownload.java 132 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mybatis/doublePrevention/PreventCJReportCheckRecordFromTaskMapper.xml 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/doublePrevention/repository/PreventCJReportCheckRecordFromTaskRepository.java
@@ -41,4 +41,8 @@
    int insertRecordList(@Param(value="list") List<PreventCJReportCheckRecordFromTask> recordFromTaskList);
    int updateCJReportStatusBatchById(List<PreventCJReportCheckRecordFromTask> cjRecordFromTasks);
    int updateTaskReportStatusForRePushV1(@Param("startTime") String startTime, @Param("endTime") String endTime);
    int updateTaskReportStatusForRePushV2(@Param("startTime") String startTime, @Param("endTime") String endTime);
}
src/main/java/com/ruoyi/doublePrevention/scheduls/RePushDataSchedule.java
对比新文件
@@ -0,0 +1,60 @@
package com.ruoyi.doublePrevention.scheduls;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.doublePrevention.repository.PreventCJReportCheckRecordFromTaskRepository;
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.time.DayOfWeek;
import java.time.LocalDate;
@Component
@Slf4j
public class RePushDataSchedule {
    @Autowired
    private PreventCJReportCheckRecordFromTaskRepository preventCJReportCheckRecordFromTaskRepository;
    @Transactional
    @Scheduled(cron = "0 0 12 * * 4 ")
    public void repushDataV1(){
        log.info("周四【双重预防】重新推送数据..."+ DateUtils.dateTimeNow());
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 计算当前周的周一日期
        LocalDate mondayDate = currentDate.with(DayOfWeek.MONDAY);
        log.info("当前周的周一日期:" + mondayDate);
        String startTime = mondayDate + " 00:00:00";
        String endTime = DateUtils.getDate() + " 12:00:00";
        int i = preventCJReportCheckRecordFromTaskRepository.updateTaskReportStatusForRePushV1(startTime, endTime);
        log.info("执行更新了:"+i+"条数据,结束周四【双重预防】重新推送数据..."+ DateUtils.dateTimeNow());
    }
//update prevent_cj_report_check_record_from_task set  id=concat(substring(id,1,length(id)-4),'ccab'),report_status=1 where check_time>="2024-11-04 00:00:00" ;
    @Transactional
    @Scheduled(cron = "0 0 16 * * 0 ")
    public void repushDataV2(){
        log.info("周日【双重预防】重新推送数据..."+ DateUtils.dateTimeNow());
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 计算当前周的周一日期
        LocalDate mondayDate = currentDate.with(DayOfWeek.THURSDAY);
        log.info("当前周的周四日期:" + mondayDate);
        String startTime = mondayDate + " 12:00:00";
        String endTime = DateUtils.getDate() + " 16:00:00";
        int i = preventCJReportCheckRecordFromTaskRepository.updateTaskReportStatusForRePushV2(startTime, endTime);
        log.info("执行更新了:"+i+"条数据,结束周四【双重预防】重新推送数据..."+ DateUtils.dateTimeNow());
    }
}
src/main/java/com/ruoyi/project/tr/specialCheck/Test/SpecialCheckTaskDownload.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.project.tr.riskList.service.IRiskListService;
import com.ruoyi.project.tr.specialCheck.domin.DownloadDTO.*;
import com.ruoyi.project.tr.specialCheck.domin.TbBaseCheckItem;
@@ -17,6 +18,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -25,6 +27,10 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.chrono.ChronoLocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@@ -75,6 +81,22 @@
        }
        return sr;
    }
    public static String decrypt(String encryptedText, byte[] key, byte[] iv) {
        String sr;
        try {
            byte[] encryptedBytes = Base64.getDecoder().decode(encryptedText);
            GCMBlockCipher cipher = new GCMBlockCipher(new AESFastEngine());
            AEADParameters parameters = new AEADParameters(new KeyParameter(key), MAC_BIT_SIZE, iv, null);
            cipher.init(false, parameters);
            byte[] decryptedBytes = new byte[cipher.getOutputSize(encryptedBytes.length)];
            int retLen = cipher.processBytes(encryptedBytes, 0, encryptedBytes.length, decryptedBytes, 0);
            cipher.doFinal(decryptedBytes, retLen);
            sr = new String(decryptedBytes, StandardCharsets.UTF_8);
        } catch (Exception ex) {
            throw new RuntimeException(ex.getMessage());
        }
        return sr;
    }
    @Transactional
@@ -82,7 +104,7 @@
//    @Scheduled(cron = "0 0 22,23 * * ?")    //每天晚上22、23点执行一次
//    @Scheduled(cron = "0 0/1 * * * ? ")    // 分钟
//    @Scheduled(cron = "0 0/20 * * * ? ")    // 分钟
//    @Scheduled(cron = "0/5 * * * * ?")
    //@Scheduled(cron = "0/15 * * * * ?")
    public void execReportDateSchedule() throws UnsupportedEncodingException {
        logger.info("【####】拉取专项检查数据开始...");
@@ -100,10 +122,20 @@
        logger.info("【token时间】" + formatDate);
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取今年的1月1号
        LocalDate startOfYear = LocalDate.of(currentDate.getYear(), 1, 1);
        //String taskId = "84766708-9b18-4133-8acf-08aba67792c7";
        String taskId = "a8de03f0-4c3e-43fe-a139-0e4ed34edd35";
        /**
         * 1
         * */
        logger.info("【####】拉取专项任务数据开始...");
//        logger.info("【####】拉取专项任务数据开始...");
        TbCheckConfig specialCheckConfig = configMapper.getSpecialCheckConfig();
        if (specialCheckConfig.getStatus() == 2){
@@ -130,6 +162,8 @@
             OutputStream os = con.getOutputStream();
                 System.out.println("token:"+token+formatDate.toString());
            //本段日志,测试成功后,可注释掉
            if (responseCode == HttpURLConnection.HTTP_OK) {
                //得到响应流
@@ -152,11 +186,20 @@
            //接收返回值,保存返回值
            TbBaseCheckTaskDownloadBO checkTaskDownloadDTO = JSONObject.parseObject(specialCheckBuffer.toString(), TbBaseCheckTaskDownloadBO.class);
            //接收返回值,保存返回值
            CheckTaskData tasks = JSONObject.parseObject(checkTaskDownloadDTO.getData(), CheckTaskData.class);
            if (tasks.getCheckTaskLists().size() > 0){
                for (TbBaseCheckTask checkTask : tasks.getCheckTaskLists()) {
                    checkTask.setStatus(1);
                    int insert = taskTbRepository.insert(checkTask);
            List<TbBaseCheckTask> tbBaseCheckTasks = JSONArray.parseArray(checkTaskDownloadDTO.getData(), TbBaseCheckTask.class);
            if (tbBaseCheckTasks.size() > 0){
                for (TbBaseCheckTask tbBaseCheckTask : tbBaseCheckTasks) {
                    LocalDateTime taskStartTime = tbBaseCheckTask.getTaskStartTime();
                    LocalDate localDate = taskStartTime.toLocalDate();
                    if (localDate.isAfter(startOfYear)) {
                        logger.info("当前日期大于今年的1月1号");
                        tbBaseCheckTask.setStatus(1);
                        tbBaseCheckTask.setId(tbBaseCheckTask.getTaskId());
                        taskId = tbBaseCheckTask.getTaskId();
                        int insert = taskTbRepository.insert(tbBaseCheckTask);
                    }
                }
            }
@@ -180,10 +223,19 @@
            page.setCurrent(String.valueOf(1));
            page.setSize(String.valueOf(1000));
            itemDownloadRespDTO.setTaskId(baseCheckTask.getId());
            itemDownloadRespDTO.setTaskId(taskId);
            itemDownloadRespDTO.setPage(page);
            System.out.println("请求参数:" + JSONObject.toJSONString(itemDownloadRespDTO));
            JSONObject itemDownloadRespDTOJson = new JSONObject();
            itemDownloadRespDTOJson.put("taskId",taskId);
            itemDownloadRespDTOJson.put("page",page);
            System.out.println("【【原始数据2】】" + JSONObject.toJSONString(itemDownloadRespDTOJson));
            String encrypted = encrypt(JSONObject.toJSONString(itemDownloadRespDTOJson), key.getBytes(), iv.getBytes());
            System.out.println("【【加密数据2】】" + encrypted);
            //加密请求数据
            String AESReportUnitDate = encrypt(JSONObject.toJSONString(itemDownloadRespDTO), key.getBytes(), iv.getBytes());
            System.out.println("【【加密数据2】】" + AESReportUnitDate);
            //上报数据
            try {
                URL url = new URL("http://120.71.182.198:9999/v1/data/receive/getCheckItem");
@@ -204,11 +256,11 @@
                con.setRequestProperty("Content-Type", "application/json;charset=utf8");
                OutputStream os = con.getOutputStream();
                Map paraMap = new HashMap();
                paraMap.put("data", AESReportUnitDate); /**封装数据*/
                System.out.println("【【加密请求体】】" +  JSONArray.toJSON(paraMap).toString());
//                Map paraMap = new HashMap();
//                paraMap.put("data", encrypted); /**封装数据*/
               // System.out.println("【【加密请求体】】" +  JSONArray.toJSON(paraMap).toString());
                //组装入参,设置请求体
                os.write(JSON.toJSONString(paraMap).getBytes());
                os.write(JSON.toJSONString(itemDownloadRespDTOJson).getBytes());
                //本段日志,测试成功后,可注释掉
                if (responseCode == HttpURLConnection.HTTP_OK) {
@@ -232,15 +284,22 @@
            //接收返回值,保存返回值
            ItemDownloadRespBO itemDownloadRespBO = JSONObject.parseObject(specialCheckBuffer.toString(), ItemDownloadRespBO.class);
            //接收返回值,保存返回值
            CheckItemData itemData = JSONObject.parseObject(itemDownloadRespBO.getData(), CheckItemData.class);
            if (itemData.getItemLists().size() > 0){
                for (TbBaseCheckItem item : itemData.getItemLists()) {
                    item.setStatus(1);
                    int insert = itemTbRepository.insert(item);
                }
            String data = itemDownloadRespBO.getData();
            if (ObjectUtils.isNotEmpty(data)){
                JSONObject jsonObject = JSON.parseObject(data);
                String data1 = jsonObject.get("data").toString();
                List<TbBaseCheckItem> tbBaseCheckItems = JSONObject.parseArray(data1, TbBaseCheckItem.class);
                    if (ObjectUtils.isNotEmpty(tbBaseCheckItems)){
                        for (TbBaseCheckItem item : tbBaseCheckItems) {
                            item.setStatus(1);
                            item.setId(item.getCheckItemId());
                            int insert = itemTbRepository.insertBatch(item);
                        }
                    }
            }
            taskTbRepository.updateStatusById(baseCheckTask.getId());
            taskTbRepository.updateStatusById(baseCheckTask.getTaskId());
            logger.info("【专项任务检查项】-读取检查项结果:" + itemDownloadRespBO.getCode());
            System.out.println("【专项任务检查项】-读取检查项完成");
@@ -265,11 +324,15 @@
            scoreDownloadRespDTO.setTaskId(baseItemByStatus.getTaskId());
            scoreDownloadRespDTO.setCheckItemId(baseItemByStatus.getId());
            scoreDownloadRespDTO.setPage(page);
            System.out.println("【【加密前请求体】】" +JSON.toJSONString(scoreDownloadRespDTO));
            //加密请求数据
            String AESReportUnitDate = encrypt(JSONObject.toJSONString(scoreDownloadRespDTO), key.getBytes(), iv.getBytes());
            String AESReportUnitDate = encrypt(JSON.toJSONString(scoreDownloadRespDTO), key.getBytes(), iv.getBytes());
            System.out.println("【【加密请求体】】" +AESReportUnitDate);
            String decrypt = decrypt(AESReportUnitDate, key.getBytes(), iv.getBytes());
            System.out.println("【【解密请求体】】" +decrypt);
            //上报数据
            try {
                URL url = new URL("http://120.71.182.198:9999/v1/data/receive/getCheckItem");
                URL url = new URL("http://120.71.182.198:9999/v1/data/receive/getCheckScore");
                //得到连接对象
                con = (HttpURLConnection) url.openConnection();
                //设置请求类型
@@ -287,11 +350,11 @@
                con.setRequestProperty("Content-Type", "application/json;charset=utf8");
                OutputStream os = con.getOutputStream();
                Map paraMap = new HashMap();
                paraMap.put("data", AESReportUnitDate); /**封装数据*/
                System.out.println("【【加密请求体】】" +  JSONArray.toJSON(paraMap).toString());
//                Map paraMap = new HashMap();
//                paraMap.put("data", AESReportUnitDate); /**封装数据*/
//                System.out.println("【【加密请求体】】" +  JSONArray.toJSON(paraMap).toString());
                //组装入参,设置请求体
                os.write(JSON.toJSONString(paraMap).getBytes());
                os.write(JSON.toJSONString(scoreDownloadRespDTO).getBytes());
                //本段日志,测试成功后,可注释掉
                if (responseCode == HttpURLConnection.HTTP_OK) {
@@ -314,14 +377,21 @@
            //接收返回值,保存返回值
            ScoreDownloadRespBO scoreDownloadRespBO = JSONObject.parseObject(specialCheckBuffer.toString(), ScoreDownloadRespBO.class);
            //接收返回值,保存返回值
            CheckScoreData scoreData = JSONObject.parseObject(scoreDownloadRespBO.getData(), CheckScoreData.class);
            if (scoreData.getScoreLists().size() > 0){
                for (TbBaseCheckScore score : scoreData.getScoreLists()) {
                    int insert = scoreTbRepository.insert(score);
                }
            String data = scoreDownloadRespBO.getData();
            if (ObjectUtils.isNotEmpty(data)){
                JSONObject jsonObject = JSON.parseObject(data);
                String data1 = jsonObject.get("data").toString();
                List<TbBaseCheckScore> tbBaseCheckScores = JSONObject.parseArray(data1, TbBaseCheckScore.class);
                    if (ObjectUtils.isNotEmpty(tbBaseCheckScores)){
                        for (TbBaseCheckScore item : tbBaseCheckScores) {
                            item.setId(item.getScoreId());
                            int insert = scoreTbRepository.save(item);
                        }
                    }
            }
            itemTbRepository.updateStatusById(baseItemByStatus.getId());
            logger.info("【评分细则】-读取结果:" + scoreDownloadRespBO.getCode());
src/main/resources/mybatis/doublePrevention/PreventCJReportCheckRecordFromTaskMapper.xml
@@ -91,4 +91,15 @@
        where id = #{id}
    </update>
    <update id="updateTaskReportStatusForRePushV1">
        update prevent_cj_report_check_record_from_task set id=concat(substring(id,1,length(id)-4),'ccab'),report_status=1
        where check_time &gt;= #{startTime} and check_time &lt;= #{endTime}
    </update>
    <update id="updateTaskReportStatusForRePushV2">
        update prevent_cj_report_check_record_from_task set id=concat(substring(id,1,length(id)-4),'ccab'),report_status=1
        where check_time &gt; #{startTime} and check_time &lt;= #{endTime}
    </update>
</mapper>