| | |
| | | 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; |
| | |
| | | private SyncLogService syncLogService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void run(String params) { |
| | | logger.info("SyncEmsTask定时任务正在执行,参数为:{}", params); |
| | | String remark = "同步成功"; |
| | |
| | | |
| | | 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(); |
| | |
| | | } |
| | | byqlzAdsService.delete(yearMonth); |
| | | while (rs.next()) { |
| | | logger.error("进入循环"); |
| | | ByqlzAdsEntity entity = new ByqlzAdsEntity(); |
| | | |
| | | // 映射基础字段 |
| | |
| | | } 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运行完成"); |
| | | } |