Commit 0fd7f5783605ed56b02dfc12b9196cad69cfd3ca
1 parent
46ef5393
update...
Showing
1 changed file
with
15 additions
and
8 deletions
src/main/java/com/bsth/data/car_out_info/CarOutInfoHandler.java
| ... | ... | @@ -52,6 +52,7 @@ public class CarOutInfoHandler { |
| 52 | 52 | |
| 53 | 53 | |
| 54 | 54 | ArrayListMultimap<String, ScheduleRealInfo> xlMaps = ArrayListMultimap.create(); |
| 55 | + List<ScheduleRealInfo> pstList = new ArrayList<>(); | |
| 55 | 56 | /** |
| 56 | 57 | * 全量更新发车信息表 |
| 57 | 58 | */ |
| ... | ... | @@ -65,9 +66,11 @@ public class CarOutInfoHandler { |
| 65 | 66 | |
| 66 | 67 | Set<String> ks = xlMaps.keySet(); |
| 67 | 68 | for (String k : ks) { |
| 68 | - update(xlMaps.get(k)); | |
| 69 | + pstList.addAll(update(xlMaps.get(k))); | |
| 69 | 70 | } |
| 70 | 71 | |
| 72 | + save(pstList); | |
| 73 | + pstList.clear(); | |
| 71 | 74 | xlMaps.clear(); |
| 72 | 75 | logger.info("更新发车信息表!!"); |
| 73 | 76 | }catch (Exception e){ |
| ... | ... | @@ -75,10 +78,9 @@ public class CarOutInfoHandler { |
| 75 | 78 | } |
| 76 | 79 | } |
| 77 | 80 | |
| 78 | - public void update(List<ScheduleRealInfo> list) { | |
| 81 | + public List<ScheduleRealInfo> update(List<ScheduleRealInfo> list) { | |
| 79 | 82 | if (list.size() == 0) |
| 80 | - return; | |
| 81 | - String lineCode = list.get(0).getXlBm(); | |
| 83 | + return new ArrayList<>(); | |
| 82 | 84 | //按上下行分组 |
| 83 | 85 | List<ScheduleRealInfo> ups = new ArrayList<>(), downs = new ArrayList<>(); |
| 84 | 86 | for (ScheduleRealInfo sch : list) { |
| ... | ... | @@ -91,7 +93,12 @@ public class CarOutInfoHandler { |
| 91 | 93 | ScheduleRealInfo[] upArray = nexts(ups), |
| 92 | 94 | downArray = nexts(downs); |
| 93 | 95 | |
| 94 | - final List<ScheduleRealInfo> pstArray = mergeArray(upArray, downArray); | |
| 96 | + List<ScheduleRealInfo> pstArray = mergeArray(upArray, downArray); | |
| 97 | + | |
| 98 | + return pstArray; | |
| 99 | + } | |
| 100 | + | |
| 101 | + private void save(final List<ScheduleRealInfo> pstList){ | |
| 95 | 102 | //编程式事务 |
| 96 | 103 | DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); |
| 97 | 104 | DefaultTransactionDefinition def = new DefaultTransactionDefinition(); |
| ... | ... | @@ -100,13 +107,13 @@ public class CarOutInfoHandler { |
| 100 | 107 | |
| 101 | 108 | try{ |
| 102 | 109 | //删除 |
| 103 | - jdbcTemplate.update("delete from bsth_t_clfcxxb where line_code=?", lineCode); | |
| 110 | + jdbcTemplate.update("delete from bsth_t_clfcxxb"); | |
| 104 | 111 | //重新写入 |
| 105 | 112 | jdbcTemplate.batchUpdate("insert into bsth_t_clfcxxb(rq, line_code, line_name, lp_name, lp_sn, dfsj, nbbm, cph, bc_type, end_station_name, updown, jGh, jName, remarks, sn)" + |
| 106 | 113 | " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new BatchPreparedStatementSetter() { |
| 107 | 114 | @Override |
| 108 | 115 | public void setValues(PreparedStatement ps, int i) throws SQLException { |
| 109 | - ScheduleRealInfo sch = pstArray.get(i); | |
| 116 | + ScheduleRealInfo sch = pstList.get(i); | |
| 110 | 117 | ps.setString(1, sch.getScheduleDateStr()); |
| 111 | 118 | ps.setString(2, sch.getXlBm()); |
| 112 | 119 | ps.setString(3, sch.getXlName()); |
| ... | ... | @@ -126,7 +133,7 @@ public class CarOutInfoHandler { |
| 126 | 133 | |
| 127 | 134 | @Override |
| 128 | 135 | public int getBatchSize() { |
| 129 | - return pstArray.size(); | |
| 136 | + return pstList.size(); | |
| 130 | 137 | } |
| 131 | 138 | }); |
| 132 | 139 | ... | ... |