鞍钢鲅鱼圈能源管控系统后端代码
潘志宝
9 天以前 9efa602abc97ef54ebaa2fee97ba8a0002aad0ae
Merge remote-tracking branch 'origin/master'
已修改1个文件
20 ■■■■ 文件已修改
ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/SyncEmsTask.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/SyncEmsTask.java
@@ -10,6 +10,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.sql.*;
import java.text.SimpleDateFormat;
@@ -35,6 +36,7 @@
    private SyncLogService syncLogService;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void run(String params) {
        logger.info("SyncEmsTask定时任务正在执行,参数为:{}", params);
        String remark = "同步成功";
@@ -49,14 +51,17 @@
        String sql = "SELECT * FROM ems.BYQLZ_ADS_WH_CL_JH01_BYQ WHERE date_code = ?";
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
            PreparedStatement pstmt = conn.prepareStatement(sql);
            conn = DriverManager.getConnection(URL, USER, PASSWORD);
            pstmt = conn.prepareStatement(sql);
            // 设置参数
            pstmt.setString(1, yearMonth);
            // 执行查询并处理结果
            ResultSet rs = pstmt.executeQuery();
            rs = pstmt.executeQuery();
            if(!rs.isBeforeFirst()){
                pstmt.setString(1, lastMonth);
                rs = pstmt.executeQuery();
@@ -70,7 +75,6 @@
            }
            byqlzAdsService.delete(yearMonth);
            while (rs.next()) {
                logger.error("进入循环");
                ByqlzAdsEntity entity = new ByqlzAdsEntity();
                // 映射基础字段
@@ -132,6 +136,14 @@
        } catch (SQLException e) {
            logger.error("SyncEmsTask运行异常");
            e.printStackTrace();
        } finally {
            try {
                if (rs != null) rs.close();     // 先关闭结果集
                if (pstmt != null) pstmt.close(); // 再关闭语句
                if (conn != null) conn.close(); // 最后关闭连接
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        logger.info("SyncEmsTask运行完成");
    }