| | |
| | | @Transactional |
| | | public ReturnT<String> start() { |
| | | try { |
| | | batchDelete("asr_stk_hplc", 180); |
| | | batchDelete("asr_wrk_detl_log", 360); |
| | | batchDelete("asr_wrk_mast_log", 360); |
| | | batchDelete("cust_wait_pakin_log", 360); |
| | | batchDelete("asr_stk_hplc", "appe_time", 180); |
| | | batchDelete("asr_wrk_detl_log", "io_time", 360); |
| | | batchDelete("asr_wrk_mast_log", "io_time", 360); |
| | | batchDelete("cust_wait_pakin_log", "appe_time", 360); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | |
| | | return SUCCESS; |
| | | } |
| | | |
| | | private void batchDelete(String tableName, int days) { |
| | | @SuppressWarnings("SameParameterValue") |
| | | private void batchDelete(String tableName, String time, int days) { |
| | | int batchSize = 1000; |
| | | int affected; |
| | | do { |
| | | String sql = String.format( |
| | | "WITH cte AS (SELECT TOP (%d) * FROM %s WHERE dateadd(day, %d, appe_time) <= getdate()) DELETE FROM cte", |
| | | batchSize, tableName, days |
| | | "WITH cte AS (SELECT TOP (%d) * FROM %s WHERE dateadd(day, %d, %s) <= getdate()) DELETE FROM cte", |
| | | batchSize, tableName, days, time |
| | | ); |
| | | affected = jdbcTemplate.update(sql); |
| | | } while (affected > 0); |