Commit ee209390913afab6bb5ed6948d84de880be49dcd

Authored by 王通
1 parent f3af1893

1.解决路单批量保存时可能失败的情况

src/main/java/com/bsth/data/schedule/thread/SchedulePstThread.java
... ... @@ -12,6 +12,7 @@ import org.springframework.jdbc.core.BatchPreparedStatementSetter;
12 12 import org.springframework.jdbc.core.JdbcTemplate;
13 13 import org.springframework.stereotype.Component;
14 14 import org.springframework.transaction.TransactionStatus;
  15 +import org.springframework.transaction.support.TransactionCallback;
15 16 import org.springframework.transaction.support.TransactionCallbackWithoutResult;
16 17 import org.springframework.transaction.support.TransactionTemplate;
17 18  
... ... @@ -81,19 +82,20 @@ public class SchedulePstThread extends Thread {
81 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 90 logger.info("update end! ");
89 91 }
90 92  
91   - private void update2Db(){
  93 + private boolean update2Db(){
92 94 final List<ScheduleRealInfo> pstList = saveList;
93   - transactionTemplate.execute(new TransactionCallbackWithoutResult() {
  95 + Boolean success = transactionTemplate.execute(new TransactionCallback<Boolean>() {
94 96  
95 97 @Override
96   - public void doInTransactionWithoutResult(TransactionStatus status) {
  98 + public Boolean doInTransaction(TransactionStatus status) {
97 99 try {
98 100 //更新
99 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 165 return pstList.size();
164 166 }
165 167 });
  168 +
  169 + return true;
166 170 } catch (Exception e) {
167 171 status.setRollbackOnly();
168 172 try {
... ... @@ -171,7 +175,11 @@ public class SchedulePstThread extends Thread {
171 175 jsonProcessingException.printStackTrace();
172 176 }
173 177 }
  178 +
  179 + return false;
174 180 }
175 181 });
  182 +
  183 + return success.booleanValue();
176 184 }
177 185 }
... ...