| | |
| | | import com.iailab.module.ansteel.ems.entity.ByqlzAdsEntity; |
| | | import com.iailab.module.ansteel.ems.service.ByqlzAdsService; |
| | | import com.iailab.module.ansteel.sync.service.SyncLogService; |
| | | import com.iailab.module.model.api.mdk.MdkApi; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO; |
| | | import org.slf4j.Logger; |
| | | 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; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.Date; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 同步ems.byqlz_ads_wh_cl_jh01_byq表定时任务 |
| | |
| | | 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(); |
| | |
| | | entity.setLoadTime(rs.getString("LOAD_TIME")); |
| | | resultList.add(entity); |
| | | } |
| | | resultList.forEach(System.out::println); |
| | | |
| | | byqlzAdsService.save(resultList); |
| | | |
| | | syncLogService.save(remark); |
| | | // 输出结果 |
| | | resultList.forEach(System.out::println); |
| | | resultList.clear(); |
| | | } 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运行完成"); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | SyncEmsTask syncEmsTask = new SyncEmsTask(); |
| | | String params = ""; |
| | | syncEmsTask.run(params); |
| | | } |
| | | } |