Commit ee209390913afab6bb5ed6948d84de880be49dcd
1 parent
f3af1893
1.解决路单批量保存时可能失败的情况
Showing
1 changed file
with
14 additions
and
6 deletions
src/main/java/com/bsth/data/schedule/thread/SchedulePstThread.java
| @@ -12,6 +12,7 @@ import org.springframework.jdbc.core.BatchPreparedStatementSetter; | @@ -12,6 +12,7 @@ import org.springframework.jdbc.core.BatchPreparedStatementSetter; | ||
| 12 | import org.springframework.jdbc.core.JdbcTemplate; | 12 | import org.springframework.jdbc.core.JdbcTemplate; |
| 13 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
| 14 | import org.springframework.transaction.TransactionStatus; | 14 | import org.springframework.transaction.TransactionStatus; |
| 15 | +import org.springframework.transaction.support.TransactionCallback; | ||
| 15 | import org.springframework.transaction.support.TransactionCallbackWithoutResult; | 16 | import org.springframework.transaction.support.TransactionCallbackWithoutResult; |
| 16 | import org.springframework.transaction.support.TransactionTemplate; | 17 | import org.springframework.transaction.support.TransactionTemplate; |
| 17 | 18 | ||
| @@ -81,19 +82,20 @@ public class SchedulePstThread extends Thread { | @@ -81,19 +82,20 @@ public class SchedulePstThread extends Thread { | ||
| 81 | logger.info("real schedule update size: " + saveList.size()); | 82 | logger.info("real schedule update size: " + saveList.size()); |
| 82 | 83 | ||
| 83 | //批量入库 | 84 | //批量入库 |
| 84 | - update2Db(); | 85 | + boolean success = update2Db(); |
| 85 | 86 | ||
| 86 | - //清空容器 | ||
| 87 | - saveList.clear(); | 87 | + if (success) { |
| 88 | + saveList.clear(); | ||
| 89 | + } | ||
| 88 | logger.info("update end! "); | 90 | logger.info("update end! "); |
| 89 | } | 91 | } |
| 90 | 92 | ||
| 91 | - private void update2Db(){ | 93 | + private boolean update2Db(){ |
| 92 | final List<ScheduleRealInfo> pstList = saveList; | 94 | final List<ScheduleRealInfo> pstList = saveList; |
| 93 | - transactionTemplate.execute(new TransactionCallbackWithoutResult() { | 95 | + Boolean success = transactionTemplate.execute(new TransactionCallback<Boolean>() { |
| 94 | 96 | ||
| 95 | @Override | 97 | @Override |
| 96 | - public void doInTransactionWithoutResult(TransactionStatus status) { | 98 | + public Boolean doInTransaction(TransactionStatus status) { |
| 97 | try { | 99 | try { |
| 98 | //更新 | 100 | //更新 |
| 99 | jdbcTemplate.batchUpdate("update bsth_c_s_sp_info_real set bc_type=?,bcs=?,bcsj=?,cl_zbh=?,create_date=?" + | 101 | jdbcTemplate.batchUpdate("update bsth_c_s_sp_info_real set bc_type=?,bcs=?,bcsj=?,cl_zbh=?,create_date=?" + |
| @@ -163,6 +165,8 @@ public class SchedulePstThread extends Thread { | @@ -163,6 +165,8 @@ public class SchedulePstThread extends Thread { | ||
| 163 | return pstList.size(); | 165 | return pstList.size(); |
| 164 | } | 166 | } |
| 165 | }); | 167 | }); |
| 168 | + | ||
| 169 | + return true; | ||
| 166 | } catch (Exception e) { | 170 | } catch (Exception e) { |
| 167 | status.setRollbackOnly(); | 171 | status.setRollbackOnly(); |
| 168 | try { | 172 | try { |
| @@ -171,7 +175,11 @@ public class SchedulePstThread extends Thread { | @@ -171,7 +175,11 @@ public class SchedulePstThread extends Thread { | ||
| 171 | jsonProcessingException.printStackTrace(); | 175 | jsonProcessingException.printStackTrace(); |
| 172 | } | 176 | } |
| 173 | } | 177 | } |
| 178 | + | ||
| 179 | + return false; | ||
| 174 | } | 180 | } |
| 175 | }); | 181 | }); |
| 182 | + | ||
| 183 | + return success.booleanValue(); | ||
| 176 | } | 184 | } |
| 177 | } | 185 | } |