Commit 2484b165652ecc9600d941f1694314397012d664
1 parent
8d34972f
1.2023-07-31更新日志
Showing
19 changed files
with
1516 additions
and
1502 deletions
src/main/java/com/bsth/data/LineVersionsData.java
| 1 | -package com.bsth.data; | |
| 2 | - | |
| 3 | -import com.bsth.entity.LineVersions; | |
| 4 | -import com.bsth.service.LineVersionsService; | |
| 5 | -import com.bsth.service.StationRouteService; | |
| 6 | -import org.slf4j.Logger; | |
| 7 | -import org.slf4j.LoggerFactory; | |
| 8 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 9 | -import org.springframework.core.annotation.Order; | |
| 10 | -import org.springframework.stereotype.Component; | |
| 11 | - | |
| 12 | -import java.util.HashMap; | |
| 13 | -import java.util.List; | |
| 14 | -import java.util.Map; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * @ClassName: LineVersionsData | |
| 18 | - * @Description: TODO(线路版本数据管理) | |
| 19 | - */ | |
| 20 | -@Component | |
| 21 | -@Order(20) | |
| 22 | -public class LineVersionsData extends Thread { | |
| 23 | - | |
| 24 | - static Logger logger = LoggerFactory.getLogger(LineVersionsData.class); | |
| 25 | - | |
| 26 | - @Autowired | |
| 27 | - LineVersionsService lineVersionsService; | |
| 28 | - | |
| 29 | - @Autowired | |
| 30 | - StationRouteService stationRouteService; | |
| 31 | - | |
| 32 | - @Override | |
| 33 | - public void run() { | |
| 34 | - try { | |
| 35 | - List<LineVersions> list = lineVersionsService.lineUpdate(); | |
| 36 | - if(list.size() == 0){ | |
| 37 | - logger.info("没有需要更新的线路!"); | |
| 38 | - return; | |
| 39 | - } | |
| 40 | - for (LineVersions lineVersions : list) { | |
| 41 | - Integer lineId = lineVersions.getLine().getId(); | |
| 42 | - // 更新线路文件 | |
| 43 | - Map<String, Object> map = new HashMap<>(); | |
| 44 | - map.put("lineId", lineId); | |
| 45 | - stationRouteService.usingSingle(map); | |
| 46 | - logger.info("线路版本更新成功!"); | |
| 47 | - } | |
| 48 | - } catch (Exception e) { | |
| 49 | - e.printStackTrace(); | |
| 50 | - logger.error("线路版本更新出现异常!", e); | |
| 51 | - } | |
| 52 | - } | |
| 53 | -} | |
| 1 | +package com.bsth.data; | |
| 2 | + | |
| 3 | +import com.bsth.entity.LineVersions; | |
| 4 | +import com.bsth.service.LineVersionsService; | |
| 5 | +import com.bsth.service.StationRouteService; | |
| 6 | +import org.slf4j.Logger; | |
| 7 | +import org.slf4j.LoggerFactory; | |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 9 | +import org.springframework.core.annotation.Order; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.util.HashMap; | |
| 13 | +import java.util.List; | |
| 14 | +import java.util.Map; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * @ClassName: LineVersionsData | |
| 18 | + * @Description: TODO(线路版本数据管理) | |
| 19 | + */ | |
| 20 | +@Component | |
| 21 | +@Order(20) | |
| 22 | +public class LineVersionsData extends Thread { | |
| 23 | + | |
| 24 | + static Logger logger = LoggerFactory.getLogger(LineVersionsData.class); | |
| 25 | + | |
| 26 | + @Autowired | |
| 27 | + LineVersionsService lineVersionsService; | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + StationRouteService stationRouteService; | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public void run() { | |
| 34 | + logger.warn("线路版本更新开始"); | |
| 35 | + try { | |
| 36 | + List<LineVersions> list = lineVersionsService.lineUpdate(); | |
| 37 | + if(list.size() == 0){ | |
| 38 | + logger.info("没有需要更新的线路!"); | |
| 39 | + return; | |
| 40 | + } | |
| 41 | + for (LineVersions lineVersions : list) { | |
| 42 | + Integer lineId = lineVersions.getLine().getId(); | |
| 43 | + // 更新线路文件 | |
| 44 | + Map<String, Object> map = new HashMap<>(); | |
| 45 | + map.put("lineId", lineId); | |
| 46 | + stationRouteService.usingSingle(map); | |
| 47 | + logger.info("线路版本更新成功!"); | |
| 48 | + } | |
| 49 | + } catch (Exception e) { | |
| 50 | + e.printStackTrace(); | |
| 51 | + logger.error("线路版本更新出现异常!", e); | |
| 52 | + } | |
| 53 | + logger.warn("线路版本更新结束"); | |
| 54 | + } | |
| 55 | +} | ... | ... |
src/main/java/com/bsth/data/car_out_info/CarOutInfoHandler.java
| ... | ... | @@ -15,12 +15,8 @@ import org.slf4j.LoggerFactory; |
| 15 | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | 16 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
| 17 | 17 | import org.springframework.jdbc.core.JdbcTemplate; |
| 18 | -import org.springframework.jdbc.datasource.DataSourceTransactionManager; | |
| 19 | 18 | import org.springframework.stereotype.Component; |
| 20 | -import org.springframework.transaction.TransactionDefinition; | |
| 21 | 19 | import org.springframework.transaction.TransactionStatus; |
| 22 | -import org.springframework.transaction.support.DefaultTransactionDefinition; | |
| 23 | -import org.springframework.transaction.support.TransactionCallback; | |
| 24 | 20 | import org.springframework.transaction.support.TransactionCallbackWithoutResult; |
| 25 | 21 | import org.springframework.transaction.support.TransactionTemplate; |
| 26 | 22 | |
| ... | ... | @@ -70,6 +66,7 @@ public class CarOutInfoHandler { |
| 70 | 66 | * 全量更新发车信息表 |
| 71 | 67 | */ |
| 72 | 68 | public void updateAll() { |
| 69 | + logger.warn("发车信息更新开始"); | |
| 73 | 70 | try{ |
| 74 | 71 | //将班次按线路分组 |
| 75 | 72 | List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()); |
| ... | ... | @@ -88,6 +85,7 @@ public class CarOutInfoHandler { |
| 88 | 85 | }catch (Exception e){ |
| 89 | 86 | logger.error("", e); |
| 90 | 87 | } |
| 88 | + logger.warn("发车信息更新结束"); | |
| 91 | 89 | } |
| 92 | 90 | |
| 93 | 91 | public List<ScheduleRealInfo> update(List<ScheduleRealInfo> list) { | ... | ... |
src/main/java/com/bsth/data/directive/DirectivesPstThread.java
| ... | ... | @@ -14,11 +14,10 @@ import org.slf4j.LoggerFactory; |
| 14 | 14 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | 15 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
| 16 | 16 | import org.springframework.jdbc.core.JdbcTemplate; |
| 17 | -import org.springframework.jdbc.datasource.DataSourceTransactionManager; | |
| 18 | 17 | import org.springframework.stereotype.Component; |
| 19 | -import org.springframework.transaction.TransactionDefinition; | |
| 20 | 18 | import org.springframework.transaction.TransactionStatus; |
| 21 | -import org.springframework.transaction.support.DefaultTransactionDefinition; | |
| 19 | +import org.springframework.transaction.support.TransactionCallbackWithoutResult; | |
| 20 | +import org.springframework.transaction.support.TransactionTemplate; | |
| 22 | 21 | |
| 23 | 22 | import java.sql.PreparedStatement; |
| 24 | 23 | import java.sql.SQLException; |
| ... | ... | @@ -48,10 +47,14 @@ public class DirectivesPstThread extends Thread { |
| 48 | 47 | @Autowired |
| 49 | 48 | JdbcTemplate jdbcTemplate; |
| 50 | 49 | |
| 50 | + @Autowired | |
| 51 | + private TransactionTemplate transactionTemplate; | |
| 52 | + | |
| 51 | 53 | private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"); |
| 52 | 54 | |
| 53 | 55 | @Override |
| 54 | 56 | public void run() { |
| 57 | + logger.warn("指令持久化开始"); | |
| 55 | 58 | try{ |
| 56 | 59 | ConcurrentLinkedQueue<Directive> list = DayOfDirectives.pstDirectives; |
| 57 | 60 | |
| ... | ... | @@ -99,176 +102,172 @@ public class DirectivesPstThread extends Thread { |
| 99 | 102 | }catch (Exception e){ |
| 100 | 103 | logger.error("指令入库出现异常", e); |
| 101 | 104 | } |
| 105 | + logger.warn("指令持久化结束"); | |
| 102 | 106 | } |
| 103 | 107 | |
| 104 | 108 | private void save64(final List<D64> d64s) { |
| 105 | 109 | if(null == d64s || d64s.size() == 0) |
| 106 | 110 | return; |
| 107 | 111 | |
| 112 | + logger.warn("64指令保存开始"); | |
| 113 | + | |
| 108 | 114 | String sql = "insert into bsth_v_directive_64(device_id,error_text,http_code,oper_code,rq,sender,timestamp,city_code,line_id,txt_content,resp_ack) " + |
| 109 | 115 | " values(?,?,?,?,?,?,?,?,?,?,?)"; |
| 110 | 116 | |
| 111 | - //编程式事务 | |
| 112 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 113 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 114 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 115 | - TransactionStatus status = tran.getTransaction(def); | |
| 116 | - | |
| 117 | - try{ | |
| 118 | - jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { | |
| 119 | - @Override | |
| 120 | - public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 121 | - D64 d64 = d64s.get(i); | |
| 122 | - ps.setString(1 , d64.getDeviceId()); | |
| 123 | - ps.setString(2, isNvl(d64.getErrorText())); | |
| 124 | - ps.setInt(3, d64.getHttpCode()); | |
| 125 | - ps.setShort(4, isNvl(d64.getOperCode())); | |
| 126 | - ps.setString(5, d64.getRq()); | |
| 127 | - | |
| 128 | - ps.setString(6, isNvl(d64.getSender())); | |
| 129 | - ps.setLong(7, d64.getTimestamp()); | |
| 130 | - | |
| 131 | - ps.setShort(8, isNvl(d64.getData().getCityCode())); | |
| 132 | - ps.setString(9, isNvl(d64.getData().getLineId())); | |
| 133 | - ps.setString(10, isNvl(d64.getData().getTxtContent())); | |
| 134 | - ps.setShort(11, isNvl(d64.getRespAck())); | |
| 135 | - } | |
| 136 | - | |
| 137 | - @Override | |
| 138 | - public int getBatchSize() { | |
| 139 | - return d64s.size(); | |
| 117 | + transactionTemplate.execute(new TransactionCallbackWithoutResult() { | |
| 118 | + | |
| 119 | + @Override | |
| 120 | + protected void doInTransactionWithoutResult(TransactionStatus status) { | |
| 121 | + try { | |
| 122 | + jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { | |
| 123 | + @Override | |
| 124 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 125 | + D64 d64 = d64s.get(i); | |
| 126 | + ps.setString(1 , d64.getDeviceId()); | |
| 127 | + ps.setString(2, isNvl(d64.getErrorText())); | |
| 128 | + ps.setInt(3, d64.getHttpCode()); | |
| 129 | + ps.setShort(4, isNvl(d64.getOperCode())); | |
| 130 | + ps.setString(5, d64.getRq()); | |
| 131 | + | |
| 132 | + ps.setString(6, isNvl(d64.getSender())); | |
| 133 | + ps.setLong(7, d64.getTimestamp()); | |
| 134 | + | |
| 135 | + ps.setShort(8, isNvl(d64.getData().getCityCode())); | |
| 136 | + ps.setString(9, isNvl(d64.getData().getLineId())); | |
| 137 | + ps.setString(10, isNvl(d64.getData().getTxtContent())); | |
| 138 | + ps.setShort(11, isNvl(d64.getRespAck())); | |
| 139 | + } | |
| 140 | + | |
| 141 | + @Override | |
| 142 | + public int getBatchSize() { | |
| 143 | + return d64s.size(); | |
| 144 | + } | |
| 145 | + }); | |
| 146 | + } catch (Exception e) { | |
| 147 | + logger.error(String.format("错误数据:%s", JSON.toJSONString(d64s)), e); | |
| 148 | + status.setRollbackOnly(); | |
| 140 | 149 | } |
| 141 | - }); | |
| 142 | - | |
| 143 | - tran.commit(status); | |
| 144 | - | |
| 145 | - logger.info("64 入库成功: " + d64s.size()); | |
| 146 | - }catch (Exception e){ | |
| 147 | - logger.error(String.format("错误数据:%s", JSON.toJSONString(d64s)), e); | |
| 148 | - tran.rollback(status); | |
| 149 | - } | |
| 150 | + } | |
| 151 | + }); | |
| 152 | + logger.warn("64指令保存结束"); | |
| 150 | 153 | } |
| 151 | 154 | |
| 152 | 155 | private void update60(final List<D60> d60s) { |
| 153 | 156 | if(null == d60s || d60s.size() == 0) |
| 154 | 157 | return; |
| 155 | 158 | |
| 159 | + logger.warn("60指令更新开始"); | |
| 156 | 160 | String sql = "update bsth_v_directive_60 set reply46=?,reply46time=?,reply47=?,reply47time=? where device_id=? and timestamp=? and msg_id=?"; |
| 157 | 161 | |
| 158 | - //编程式事务 | |
| 159 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 160 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 161 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 162 | - TransactionStatus status = tran.getTransaction(def); | |
| 163 | - | |
| 164 | - try{ | |
| 165 | - jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { | |
| 166 | - @Override | |
| 167 | - public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 168 | - D60 d60 = d60s.get(i); | |
| 169 | - ps.setShort(1, isNvl(d60.getReply46())); | |
| 170 | - if(null == d60.getReply46Time()) | |
| 171 | - ps.setNull(2, Types.BIGINT); | |
| 172 | - else | |
| 173 | - ps.setLong(2, d60.getReply46Time()); | |
| 174 | - | |
| 175 | - ps.setShort(3, isNvl(d60.getReply47())); | |
| 176 | - | |
| 177 | - if(null == d60.getReply47Time()) | |
| 178 | - ps.setNull(4, Types.BIGINT); | |
| 179 | - else | |
| 180 | - ps.setLong(4, d60.getReply47Time()); | |
| 181 | - ps.setString(5, d60.getDeviceId()); | |
| 182 | - ps.setLong(6, d60.getTimestamp()); | |
| 183 | - ps.setInt(7, d60.getMsgId()); | |
| 184 | - } | |
| 185 | - | |
| 186 | - @Override | |
| 187 | - public int getBatchSize() { | |
| 188 | - return d60s.size(); | |
| 162 | + transactionTemplate.execute(new TransactionCallbackWithoutResult() { | |
| 163 | + | |
| 164 | + @Override | |
| 165 | + protected void doInTransactionWithoutResult(TransactionStatus status) { | |
| 166 | + try{ | |
| 167 | + jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { | |
| 168 | + @Override | |
| 169 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 170 | + D60 d60 = d60s.get(i); | |
| 171 | + ps.setShort(1, isNvl(d60.getReply46())); | |
| 172 | + if(null == d60.getReply46Time()) | |
| 173 | + ps.setNull(2, Types.BIGINT); | |
| 174 | + else | |
| 175 | + ps.setLong(2, d60.getReply46Time()); | |
| 176 | + | |
| 177 | + ps.setShort(3, isNvl(d60.getReply47())); | |
| 178 | + | |
| 179 | + if(null == d60.getReply47Time()) | |
| 180 | + ps.setNull(4, Types.BIGINT); | |
| 181 | + else | |
| 182 | + ps.setLong(4, d60.getReply47Time()); | |
| 183 | + ps.setString(5, d60.getDeviceId()); | |
| 184 | + ps.setLong(6, d60.getTimestamp()); | |
| 185 | + ps.setInt(7, d60.getMsgId()); | |
| 186 | + } | |
| 187 | + | |
| 188 | + @Override | |
| 189 | + public int getBatchSize() { | |
| 190 | + return d60s.size(); | |
| 191 | + } | |
| 192 | + }); | |
| 193 | + }catch (Exception e){ | |
| 194 | + logger.error(String.format("错误数据:%s", JSON.toJSONString(d60s)), e); | |
| 195 | + status.setRollbackOnly(); | |
| 189 | 196 | } |
| 190 | - }); | |
| 191 | - | |
| 192 | - tran.commit(status); | |
| 193 | - | |
| 194 | - logger.info("60 更新成功: " + d60s.size()); | |
| 195 | - }catch (Exception e){ | |
| 196 | - logger.error(String.format("错误数据:%s", JSON.toJSONString(d60s)), e); | |
| 197 | - tran.rollback(status); | |
| 198 | - } | |
| 197 | + } | |
| 198 | + }); | |
| 199 | + logger.warn("60指令更新结束"); | |
| 199 | 200 | } |
| 200 | 201 | |
| 201 | 202 | private void save60(final List<D60> d60s) { |
| 202 | 203 | if(null == d60s || d60s.size() == 0) |
| 203 | 204 | return; |
| 204 | 205 | |
| 206 | + logger.warn("60指令保存开始"); | |
| 205 | 207 | String sql = "insert into bsth_v_directive_60(device_id,error_text,http_code,oper_code,rq,sender,timestamp" + |
| 206 | 208 | ",alarm_time,company_code,dispatch_instruct,instruct_type,msg_id,service_state,txt_content,is_dispatch" + |
| 207 | 209 | ",line_code,reply46,reply46time,reply47,reply47time,sch) " + |
| 208 | 210 | " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
| 209 | 211 | |
| 210 | - //编程式事务 | |
| 211 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 212 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 213 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 214 | - TransactionStatus status = tran.getTransaction(def); | |
| 215 | - | |
| 216 | - try{ | |
| 217 | - jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { | |
| 218 | - @Override | |
| 219 | - public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 220 | - D60 d60 = d60s.get(i); | |
| 221 | - ps.setString(1, d60.getDeviceId()); | |
| 222 | - ps.setString(2, isNvl(d60.getErrorText())); | |
| 223 | - ps.setInt(3, d60.getHttpCode()); | |
| 224 | - ps.setShort(4, d60.getOperCode()); | |
| 225 | - ps.setString(5, d60.getRq()); | |
| 226 | - ps.setString(6, d60.getSender()); | |
| 227 | - ps.setLong(7, d60.getTimestamp()); | |
| 228 | - | |
| 229 | - ps.setLong(8, isNvl(d60.getData().getAlarmTime())); | |
| 230 | - ps.setShort(9, isNvl(d60.getData().getCompanyCode())); | |
| 231 | - ps.setShort(10, isNvl(d60.getData().getDispatchInstruct())); | |
| 232 | - ps.setInt(11, d60.getData().getInstructType()); | |
| 233 | - ps.setInt(12, d60.getData().getMsgId()); | |
| 234 | - ps.setLong(13, d60.getData().getServiceState()); | |
| 235 | - ps.setString(14, d60.getData().getTxtContent()); | |
| 236 | - ps.setBoolean(15, d60.isDispatch()); | |
| 237 | - | |
| 238 | - ps.setString(16, isNvl(d60.getLineCode())); | |
| 239 | - ps.setShort(17, isNvl(d60.getReply46())); | |
| 240 | - | |
| 241 | - if(null == d60.getReply46Time()) | |
| 242 | - ps.setNull(18, Types.BIGINT); | |
| 243 | - else | |
| 244 | - ps.setLong(18, d60.getReply46Time()); | |
| 245 | - | |
| 246 | - ps.setShort(19, isNvl(d60.getReply47())); | |
| 247 | - | |
| 248 | - if(null == d60.getReply47Time()) | |
| 249 | - ps.setNull(20, Types.BIGINT); | |
| 250 | - else | |
| 251 | - ps.setLong(20, d60.getReply47Time()); | |
| 252 | - | |
| 253 | - if(d60.getSch()==null) | |
| 254 | - ps.setNull(21, Types.BIGINT); | |
| 255 | - else | |
| 256 | - ps.setLong(21, d60.getSch().getId()); | |
| 212 | + transactionTemplate.execute(new TransactionCallbackWithoutResult() { | |
| 213 | + | |
| 214 | + @Override | |
| 215 | + protected void doInTransactionWithoutResult(TransactionStatus status) { | |
| 216 | + try{ | |
| 217 | + jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { | |
| 218 | + @Override | |
| 219 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 220 | + D60 d60 = d60s.get(i); | |
| 221 | + ps.setString(1, d60.getDeviceId()); | |
| 222 | + ps.setString(2, isNvl(d60.getErrorText())); | |
| 223 | + ps.setInt(3, d60.getHttpCode()); | |
| 224 | + ps.setShort(4, d60.getOperCode()); | |
| 225 | + ps.setString(5, d60.getRq()); | |
| 226 | + ps.setString(6, d60.getSender()); | |
| 227 | + ps.setLong(7, d60.getTimestamp()); | |
| 228 | + | |
| 229 | + ps.setLong(8, isNvl(d60.getData().getAlarmTime())); | |
| 230 | + ps.setShort(9, isNvl(d60.getData().getCompanyCode())); | |
| 231 | + ps.setShort(10, isNvl(d60.getData().getDispatchInstruct())); | |
| 232 | + ps.setInt(11, d60.getData().getInstructType()); | |
| 233 | + ps.setInt(12, d60.getData().getMsgId()); | |
| 234 | + ps.setLong(13, d60.getData().getServiceState()); | |
| 235 | + ps.setString(14, d60.getData().getTxtContent()); | |
| 236 | + ps.setBoolean(15, d60.isDispatch()); | |
| 237 | + | |
| 238 | + ps.setString(16, isNvl(d60.getLineCode())); | |
| 239 | + ps.setShort(17, isNvl(d60.getReply46())); | |
| 240 | + | |
| 241 | + if(null == d60.getReply46Time()) | |
| 242 | + ps.setNull(18, Types.BIGINT); | |
| 243 | + else | |
| 244 | + ps.setLong(18, d60.getReply46Time()); | |
| 245 | + | |
| 246 | + ps.setShort(19, isNvl(d60.getReply47())); | |
| 247 | + | |
| 248 | + if(null == d60.getReply47Time()) | |
| 249 | + ps.setNull(20, Types.BIGINT); | |
| 250 | + else | |
| 251 | + ps.setLong(20, d60.getReply47Time()); | |
| 252 | + | |
| 253 | + if(d60.getSch()==null) | |
| 254 | + ps.setNull(21, Types.BIGINT); | |
| 255 | + else | |
| 256 | + ps.setLong(21, d60.getSch().getId()); | |
| 257 | + } | |
| 258 | + | |
| 259 | + @Override | |
| 260 | + public int getBatchSize() { | |
| 261 | + return d60s.size(); | |
| 262 | + } | |
| 263 | + }); | |
| 264 | + }catch (Exception e){ | |
| 265 | + logger.error(String.format("错误数据:%s", JSON.toJSONString(d60s)), e); | |
| 266 | + status.setRollbackOnly(); | |
| 257 | 267 | } |
| 258 | - | |
| 259 | - @Override | |
| 260 | - public int getBatchSize() { | |
| 261 | - return d60s.size(); | |
| 262 | - } | |
| 263 | - }); | |
| 264 | - | |
| 265 | - tran.commit(status); | |
| 266 | - | |
| 267 | - logger.info("60 入库成功: " + d60s.size()); | |
| 268 | - }catch (Exception e){ | |
| 269 | - logger.error(String.format("错误数据:%s", JSON.toJSONString(d60s)), e); | |
| 270 | - tran.rollback(status); | |
| 271 | - } | |
| 268 | + } | |
| 269 | + }); | |
| 270 | + logger.warn("60指令保存结束"); | |
| 272 | 271 | } |
| 273 | 272 | |
| 274 | 273 | private String isNvl(String v) { | ... | ... |
src/main/java/com/bsth/data/forecast/SampleTimeDataLoader.java
| 1 | -package com.bsth.data.forecast; | |
| 2 | - | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.Collections; | |
| 5 | -import java.util.Comparator; | |
| 6 | -import java.util.Date; | |
| 7 | -import java.util.Iterator; | |
| 8 | -import java.util.List; | |
| 9 | -import java.util.Set; | |
| 10 | - | |
| 11 | -import org.joda.time.format.DateTimeFormat; | |
| 12 | -import org.joda.time.format.DateTimeFormatter; | |
| 13 | -import org.slf4j.Logger; | |
| 14 | -import org.slf4j.LoggerFactory; | |
| 15 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | -import org.springframework.stereotype.Component; | |
| 17 | - | |
| 18 | -import com.bsth.data.forecast.entity.SimpleRoute; | |
| 19 | -import com.bsth.data.forecast.entity.SimpleRoute.TimeRange; | |
| 20 | -import com.bsth.entity.StationRoute; | |
| 21 | -import com.bsth.entity.forecast.Sample; | |
| 22 | -import com.bsth.repository.StationRouteRepository; | |
| 23 | -import com.bsth.repository.forecast.SampleRepository; | |
| 24 | -import com.google.common.collect.ArrayListMultimap; | |
| 25 | - | |
| 26 | -/** | |
| 27 | - * | |
| 28 | - * @Title: loadData | |
| 29 | - * @Description: TODO(从数据库加载数据) | |
| 30 | - */ | |
| 31 | -@Component | |
| 32 | -public class SampleTimeDataLoader extends Thread { | |
| 33 | - | |
| 34 | - @Autowired | |
| 35 | - SampleRepository sampleRepository; | |
| 36 | - | |
| 37 | - @Autowired | |
| 38 | - StationRouteRepository stationRouteRepository; | |
| 39 | - | |
| 40 | - // 当天日期 | |
| 41 | - String rq; | |
| 42 | - | |
| 43 | - private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm") | |
| 44 | - ,fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"); | |
| 45 | - | |
| 46 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 47 | - | |
| 48 | - @Override | |
| 49 | - public void run() { | |
| 50 | - rq = fmtyyyyMMdd.print(new Date().getTime()); | |
| 51 | - | |
| 52 | - Iterator<Sample> iterator = sampleRepository.findAll().iterator(); | |
| 53 | - ArrayListMultimap<String, Sample> sampleMap = ArrayListMultimap.create(); | |
| 54 | - | |
| 55 | - Sample sample; | |
| 56 | - String key; | |
| 57 | - while (iterator.hasNext()) { | |
| 58 | - sample = iterator.next(); | |
| 59 | - key = sample.getLineCode() + "_" + sample.getUpdown() + "_" + sample.getsStation() + "_" | |
| 60 | - + sample.geteStation(); | |
| 61 | - sampleMap.put(key, sample); | |
| 62 | - } | |
| 63 | - | |
| 64 | - // 加载全部路由信息 | |
| 65 | - List<StationRoute> allRoutes = stationRouteRepository.findAllEffective(); | |
| 66 | - // 线路和走向分组 | |
| 67 | - ArrayListMultimap<String, StationRoute> groupMap = ArrayListMultimap.create(); | |
| 68 | - for (StationRoute sr : allRoutes) | |
| 69 | - groupMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr); | |
| 70 | - | |
| 71 | - ArrayListMultimap<String, SimpleRoute> lineSampleMapCopy = ArrayListMultimap.create(); | |
| 72 | - // 排序路由链并附加各个时区耗时信息 | |
| 73 | - StationRouteComp comp = new StationRouteComp(); | |
| 74 | - Set<String> kys = groupMap.keySet(); | |
| 75 | - List<StationRoute> routeList; | |
| 76 | - StationRoute sRoute; | |
| 77 | - | |
| 78 | - List<Sample> sapList; | |
| 79 | - for (String k : kys) { | |
| 80 | - routeList = groupMap.get(k); | |
| 81 | - // 排序 | |
| 82 | - Collections.sort(routeList, comp); | |
| 83 | - | |
| 84 | - for (int i = 1; i < routeList.size(); i++) { | |
| 85 | - sRoute = routeList.get(i); | |
| 86 | - | |
| 87 | - sapList = sampleMap.get(k + "_" +routeList.get(i - 1).getStationCode() + "_" + sRoute.getStationCode()); | |
| 88 | - | |
| 89 | - lineSampleMapCopy.put(k, createSimpleRoute(sRoute, sapList)); | |
| 90 | - } | |
| 91 | - } | |
| 92 | - | |
| 93 | - ForecastRealServer.lineSampleMap = lineSampleMapCopy; | |
| 94 | - logger.info("SampleTimeDataLoader.... over..."); | |
| 95 | - } | |
| 96 | - | |
| 97 | - private SimpleRoute createSimpleRoute(StationRoute sRoute, List<Sample> list) { | |
| 98 | - SimpleRoute simple = new SimpleRoute(); | |
| 99 | - | |
| 100 | - simple.stationCode = sRoute.getStationCode(); | |
| 101 | - simple.ranges = new ArrayList<>(); | |
| 102 | - | |
| 103 | - try{ | |
| 104 | - TimeRange tg; | |
| 105 | - for (Sample s : list) { | |
| 106 | - tg = new TimeRange(); | |
| 107 | - | |
| 108 | - tg.startTime = fmtyyyyMMddHHmm.parseMillis(rq + s.getsDate()); | |
| 109 | - tg.endTime = fmtyyyyMMddHHmm.parseMillis(rq + s.geteDate()); | |
| 110 | - tg.runTime = s.getRunTime(); | |
| 111 | - simple.ranges.add(tg); | |
| 112 | - } | |
| 113 | - | |
| 114 | - //排序 | |
| 115 | - Collections.sort(simple.ranges); | |
| 116 | - }catch(Exception e){ | |
| 117 | - logger.error("", e); | |
| 118 | - } | |
| 119 | - return simple; | |
| 120 | - } | |
| 121 | - | |
| 122 | - public static class StationRouteComp implements Comparator<StationRoute> { | |
| 123 | - | |
| 124 | - @Override | |
| 125 | - public int compare(StationRoute o1, StationRoute o2) { | |
| 126 | - return o1.getStationRouteCode() - o2.getStationRouteCode(); | |
| 127 | - } | |
| 128 | - } | |
| 129 | -} | |
| 1 | +package com.bsth.data.forecast; | |
| 2 | + | |
| 3 | +import java.util.ArrayList; | |
| 4 | +import java.util.Collections; | |
| 5 | +import java.util.Comparator; | |
| 6 | +import java.util.Date; | |
| 7 | +import java.util.Iterator; | |
| 8 | +import java.util.List; | |
| 9 | +import java.util.Set; | |
| 10 | + | |
| 11 | +import org.joda.time.format.DateTimeFormat; | |
| 12 | +import org.joda.time.format.DateTimeFormatter; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | +import org.springframework.stereotype.Component; | |
| 17 | + | |
| 18 | +import com.bsth.data.forecast.entity.SimpleRoute; | |
| 19 | +import com.bsth.data.forecast.entity.SimpleRoute.TimeRange; | |
| 20 | +import com.bsth.entity.StationRoute; | |
| 21 | +import com.bsth.entity.forecast.Sample; | |
| 22 | +import com.bsth.repository.StationRouteRepository; | |
| 23 | +import com.bsth.repository.forecast.SampleRepository; | |
| 24 | +import com.google.common.collect.ArrayListMultimap; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * | |
| 28 | + * @Title: loadData | |
| 29 | + * @Description: TODO(从数据库加载数据) | |
| 30 | + */ | |
| 31 | +@Component | |
| 32 | +public class SampleTimeDataLoader extends Thread { | |
| 33 | + | |
| 34 | + @Autowired | |
| 35 | + SampleRepository sampleRepository; | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + StationRouteRepository stationRouteRepository; | |
| 39 | + | |
| 40 | + // 当天日期 | |
| 41 | + String rq; | |
| 42 | + | |
| 43 | + private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm") | |
| 44 | + ,fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"); | |
| 45 | + | |
| 46 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 47 | + | |
| 48 | + @Override | |
| 49 | + public void run() { | |
| 50 | + logger.warn("到离站预测样本加载开始"); | |
| 51 | + rq = fmtyyyyMMdd.print(System.currentTimeMillis()); | |
| 52 | + | |
| 53 | + Iterator<Sample> iterator = sampleRepository.findAll().iterator(); | |
| 54 | + ArrayListMultimap<String, Sample> sampleMap = ArrayListMultimap.create(); | |
| 55 | + | |
| 56 | + Sample sample; | |
| 57 | + String key; | |
| 58 | + while (iterator.hasNext()) { | |
| 59 | + sample = iterator.next(); | |
| 60 | + key = sample.getLineCode() + "_" + sample.getUpdown() + "_" + sample.getsStation() + "_" | |
| 61 | + + sample.geteStation(); | |
| 62 | + sampleMap.put(key, sample); | |
| 63 | + } | |
| 64 | + | |
| 65 | + // 加载全部路由信息 | |
| 66 | + List<StationRoute> allRoutes = stationRouteRepository.findAllEffective(); | |
| 67 | + // 线路和走向分组 | |
| 68 | + ArrayListMultimap<String, StationRoute> groupMap = ArrayListMultimap.create(); | |
| 69 | + for (StationRoute sr : allRoutes) | |
| 70 | + groupMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr); | |
| 71 | + | |
| 72 | + ArrayListMultimap<String, SimpleRoute> lineSampleMapCopy = ArrayListMultimap.create(); | |
| 73 | + // 排序路由链并附加各个时区耗时信息 | |
| 74 | + StationRouteComp comp = new StationRouteComp(); | |
| 75 | + Set<String> kys = groupMap.keySet(); | |
| 76 | + List<StationRoute> routeList; | |
| 77 | + StationRoute sRoute; | |
| 78 | + | |
| 79 | + List<Sample> sapList; | |
| 80 | + for (String k : kys) { | |
| 81 | + routeList = groupMap.get(k); | |
| 82 | + // 排序 | |
| 83 | + Collections.sort(routeList, comp); | |
| 84 | + | |
| 85 | + for (int i = 1; i < routeList.size(); i++) { | |
| 86 | + sRoute = routeList.get(i); | |
| 87 | + | |
| 88 | + sapList = sampleMap.get(k + "_" +routeList.get(i - 1).getStationCode() + "_" + sRoute.getStationCode()); | |
| 89 | + | |
| 90 | + lineSampleMapCopy.put(k, createSimpleRoute(sRoute, sapList)); | |
| 91 | + } | |
| 92 | + } | |
| 93 | + | |
| 94 | + ForecastRealServer.lineSampleMap = lineSampleMapCopy; | |
| 95 | + logger.warn("到离站预测样本加载结束"); | |
| 96 | + } | |
| 97 | + | |
| 98 | + private SimpleRoute createSimpleRoute(StationRoute sRoute, List<Sample> list) { | |
| 99 | + SimpleRoute simple = new SimpleRoute(); | |
| 100 | + | |
| 101 | + simple.stationCode = sRoute.getStationCode(); | |
| 102 | + simple.ranges = new ArrayList<>(); | |
| 103 | + | |
| 104 | + try{ | |
| 105 | + TimeRange tg; | |
| 106 | + for (Sample s : list) { | |
| 107 | + tg = new TimeRange(); | |
| 108 | + | |
| 109 | + tg.startTime = fmtyyyyMMddHHmm.parseMillis(rq + s.getsDate()); | |
| 110 | + tg.endTime = fmtyyyyMMddHHmm.parseMillis(rq + s.geteDate()); | |
| 111 | + tg.runTime = s.getRunTime(); | |
| 112 | + simple.ranges.add(tg); | |
| 113 | + } | |
| 114 | + | |
| 115 | + //排序 | |
| 116 | + Collections.sort(simple.ranges); | |
| 117 | + }catch(Exception e){ | |
| 118 | + logger.error("", e); | |
| 119 | + } | |
| 120 | + return simple; | |
| 121 | + } | |
| 122 | + | |
| 123 | + public static class StationRouteComp implements Comparator<StationRoute> { | |
| 124 | + | |
| 125 | + @Override | |
| 126 | + public int compare(StationRoute o1, StationRoute o2) { | |
| 127 | + return o1.getStationRouteCode() - o2.getStationRouteCode(); | |
| 128 | + } | |
| 129 | + } | |
| 130 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/thread/GpsDataLoaderThread.java
| 1 | -package com.bsth.data.gpsdata_v2.thread; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.DataHandleProcess; | |
| 4 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | -import com.bsth.data.gpsdata_v2.load.GatewayHttpLoader; | |
| 6 | -import com.bsth.data.gpsdata_v2.load.SocketClientLoader; | |
| 7 | -import org.slf4j.Logger; | |
| 8 | -import org.slf4j.LoggerFactory; | |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | -import org.springframework.stereotype.Component; | |
| 11 | - | |
| 12 | -import java.util.List; | |
| 13 | - | |
| 14 | -/** | |
| 15 | - * Created by panzhao on 2017/1/11. | |
| 16 | - */ | |
| 17 | -@Component | |
| 18 | -public class GpsDataLoaderThread extends Thread { | |
| 19 | - | |
| 20 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 21 | - | |
| 22 | - //0:从GPS客户端内存获取 -1:从网关获取 | |
| 23 | - private static int flag = 0; | |
| 24 | - | |
| 25 | - public static void setFlag(int v) { | |
| 26 | - flag = v; | |
| 27 | - } | |
| 28 | - | |
| 29 | - @Autowired | |
| 30 | - DataHandleProcess handleProcess; | |
| 31 | - | |
| 32 | - @Override | |
| 33 | - public void run() { | |
| 34 | - try { | |
| 35 | - List<GpsEntity> list; | |
| 36 | - if (flag == 0) | |
| 37 | - list = SocketClientLoader.load(); | |
| 38 | - else | |
| 39 | - list = GatewayHttpLoader.load(); | |
| 40 | - | |
| 41 | - if(null != list && list.size() > 0) | |
| 42 | - handleProcess.handle(list); | |
| 43 | - } catch (Exception e) { | |
| 44 | - logger.error("", e); | |
| 45 | - } | |
| 46 | - } | |
| 1 | +package com.bsth.data.gpsdata_v2.thread; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.DataHandleProcess; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.data.gpsdata_v2.load.GatewayHttpLoader; | |
| 6 | +import com.bsth.data.gpsdata_v2.load.SocketClientLoader; | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Created by panzhao on 2017/1/11. | |
| 16 | + */ | |
| 17 | +@Component | |
| 18 | +public class GpsDataLoaderThread extends Thread { | |
| 19 | + | |
| 20 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 21 | + | |
| 22 | + //0:从GPS客户端内存获取 -1:从网关获取 | |
| 23 | + private static int flag = 0; | |
| 24 | + | |
| 25 | + public static void setFlag(int v) { | |
| 26 | + flag = v; | |
| 27 | + } | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + DataHandleProcess handleProcess; | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public void run() { | |
| 34 | + logger.warn("GPS获取数据开始"); | |
| 35 | + try { | |
| 36 | + List<GpsEntity> list; | |
| 37 | + if (flag == 0) | |
| 38 | + list = SocketClientLoader.load(); | |
| 39 | + else | |
| 40 | + list = GatewayHttpLoader.load(); | |
| 41 | + | |
| 42 | + if(null != list && list.size() > 0) | |
| 43 | + handleProcess.handle(list); | |
| 44 | + } catch (Exception e) { | |
| 45 | + logger.error("", e); | |
| 46 | + } | |
| 47 | + logger.warn("GPS获取数据结束"); | |
| 48 | + } | |
| 47 | 49 | } |
| 48 | 50 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/thread/OfflineMonitorThread.java
| 1 | -package com.bsth.data.gpsdata_v2.thread; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 4 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | -import com.bsth.data.gpsdata_v2.handlers.overspeed.OverspeedProcess; | |
| 6 | -import com.bsth.websocket.handler.SendUtils; | |
| 7 | -import org.slf4j.Logger; | |
| 8 | -import org.slf4j.LoggerFactory; | |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | -import org.springframework.stereotype.Component; | |
| 11 | - | |
| 12 | -import java.util.Collection; | |
| 13 | - | |
| 14 | -/** | |
| 15 | - * GPS掉离线监控 | |
| 16 | - * Created by panzhao on 2017/1/11. | |
| 17 | - */ | |
| 18 | -@Component | |
| 19 | -public class OfflineMonitorThread extends Thread{ | |
| 20 | - | |
| 21 | - @Autowired | |
| 22 | - GpsRealData gpsRealData; | |
| 23 | - | |
| 24 | - //掉线阈值 | |
| 25 | - private final static int LOSE_TIME = 1000 * 60 * 10; | |
| 26 | - | |
| 27 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 28 | - | |
| 29 | - @Autowired | |
| 30 | - SendUtils sendUtils; | |
| 31 | - | |
| 32 | - @Autowired | |
| 33 | - OverspeedProcess overspeedProcess; | |
| 34 | - | |
| 35 | - //无任务时 离线阈值 | |
| 36 | - //private final static int OFFLINE_TIME = 1000 * 60 * 10; | |
| 37 | - | |
| 38 | - @Override | |
| 39 | - public void run() { | |
| 40 | - try{ | |
| 41 | - long t = System.currentTimeMillis(); | |
| 42 | - Collection<GpsEntity> list = gpsRealData.all(); | |
| 43 | - | |
| 44 | - String state; | |
| 45 | - for(GpsEntity gps : list){ | |
| 46 | - state = gps.getAbnormalStatus(); | |
| 47 | - | |
| 48 | - if(state != null && state.equals("offline")) | |
| 49 | - continue; | |
| 50 | - | |
| 51 | - if (t - gps.getTimestamp() > LOSE_TIME){ | |
| 52 | - gps.offline(); | |
| 53 | - | |
| 54 | - //结束超速 | |
| 55 | - overspeedProcess.offline(gps.getDeviceId()); | |
| 56 | - //通知页面有设备掉线 | |
| 57 | - sendUtils.deviceOffline(gps); | |
| 58 | - } | |
| 59 | - } | |
| 60 | - }catch (Exception e){ | |
| 61 | - logger.error("", e); | |
| 62 | - } | |
| 63 | - } | |
| 64 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.thread; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.data.gpsdata_v2.handlers.overspeed.OverspeedProcess; | |
| 6 | +import com.bsth.websocket.handler.SendUtils; | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.util.Collection; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * GPS掉离线监控 | |
| 16 | + * Created by panzhao on 2017/1/11. | |
| 17 | + */ | |
| 18 | +@Component | |
| 19 | +public class OfflineMonitorThread extends Thread{ | |
| 20 | + | |
| 21 | + @Autowired | |
| 22 | + GpsRealData gpsRealData; | |
| 23 | + | |
| 24 | + //掉线阈值 | |
| 25 | + private final static int LOSE_TIME = 1000 * 60 * 10; | |
| 26 | + | |
| 27 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + SendUtils sendUtils; | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + OverspeedProcess overspeedProcess; | |
| 34 | + | |
| 35 | + //无任务时 离线阈值 | |
| 36 | + //private final static int OFFLINE_TIME = 1000 * 60 * 10; | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public void run() { | |
| 40 | + logger.warn("GPS离线检查开始"); | |
| 41 | + try{ | |
| 42 | + long t = System.currentTimeMillis(); | |
| 43 | + Collection<GpsEntity> list = gpsRealData.all(); | |
| 44 | + | |
| 45 | + String state; | |
| 46 | + for(GpsEntity gps : list){ | |
| 47 | + state = gps.getAbnormalStatus(); | |
| 48 | + | |
| 49 | + if(state != null && state.equals("offline")) | |
| 50 | + continue; | |
| 51 | + | |
| 52 | + if (t - gps.getTimestamp() > LOSE_TIME){ | |
| 53 | + gps.offline(); | |
| 54 | + | |
| 55 | + //结束超速 | |
| 56 | + overspeedProcess.offline(gps.getDeviceId()); | |
| 57 | + //通知页面有设备掉线 | |
| 58 | + sendUtils.deviceOffline(gps); | |
| 59 | + } | |
| 60 | + } | |
| 61 | + }catch (Exception e){ | |
| 62 | + logger.error("", e); | |
| 63 | + } | |
| 64 | + logger.warn("GPS离线检查结束"); | |
| 65 | + } | |
| 66 | +} | ... | ... |
src/main/java/com/bsth/data/maintenance_plan/MtPlanDataLoadThread.java
| 1 | 1 | package com.bsth.data.maintenance_plan; |
| 2 | 2 | |
| 3 | -import com.alibaba.fastjson.JSON; | |
| 4 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 5 | 4 | import org.apache.http.HttpEntity; |
| 6 | 5 | import org.apache.http.client.config.RequestConfig; |
| ... | ... | @@ -27,6 +26,7 @@ import java.util.Map; |
| 27 | 26 | |
| 28 | 27 | /** |
| 29 | 28 | * 维修保养计划 |
| 29 | + * @author Hill | |
| 30 | 30 | */ |
| 31 | 31 | @Component |
| 32 | 32 | public class MtPlanDataLoadThread extends Thread implements InitializingBean { |
| ... | ... | @@ -57,6 +57,7 @@ public class MtPlanDataLoadThread extends Thread implements InitializingBean { |
| 57 | 57 | |
| 58 | 58 | @Override |
| 59 | 59 | public void run() { |
| 60 | + logger.warn("维修保养计划获取数据开始"); | |
| 60 | 61 | List<MaintenancePlan> list; |
| 61 | 62 | StringBuilder sb = new StringBuilder(url); |
| 62 | 63 | try { |
| ... | ... | @@ -92,6 +93,7 @@ public class MtPlanDataLoadThread extends Thread implements InitializingBean { |
| 92 | 93 | } catch (Exception e) { |
| 93 | 94 | logger.error("维修保养计划接口报错了", e); |
| 94 | 95 | } |
| 96 | + logger.warn("维修保养计划获取数据结束"); | |
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | @Override | ... | ... |
src/main/java/com/bsth/data/safe_driv/SafeDrivDataLoadThread.java
| 1 | -package com.bsth.data.safe_driv; | |
| 2 | - | |
| 3 | -import com.alibaba.fastjson.JSON; | |
| 4 | -import org.apache.http.HttpEntity; | |
| 5 | -import org.apache.http.client.config.RequestConfig; | |
| 6 | -import org.apache.http.client.methods.CloseableHttpResponse; | |
| 7 | -import org.apache.http.client.methods.HttpGet; | |
| 8 | -import org.apache.http.impl.client.CloseableHttpClient; | |
| 9 | -import org.apache.http.impl.client.HttpClients; | |
| 10 | -import org.slf4j.Logger; | |
| 11 | -import org.slf4j.LoggerFactory; | |
| 12 | -import org.springframework.stereotype.Component; | |
| 13 | - | |
| 14 | -import java.io.BufferedReader; | |
| 15 | -import java.io.InputStreamReader; | |
| 16 | -import java.util.List; | |
| 17 | - | |
| 18 | -/** | |
| 19 | - * 安全驾驶数据加载线程 | |
| 20 | - * Created by panzhao on 2017/4/6. | |
| 21 | - */ | |
| 22 | -@Component | |
| 23 | -public class SafeDrivDataLoadThread extends Thread { | |
| 24 | - | |
| 25 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 26 | - | |
| 27 | - static String url; | |
| 28 | - static CloseableHttpClient httpClient; | |
| 29 | - static HttpGet get; | |
| 30 | - static RequestConfig requestConfig; | |
| 31 | - static CloseableHttpResponse response; | |
| 32 | - static HttpEntity entity; | |
| 33 | - static BufferedReader br; | |
| 34 | - | |
| 35 | - static { | |
| 36 | - url = "http://211.95.61.66:9008/safedriving/realtimeInterface"; | |
| 37 | - httpClient = HttpClients.createDefault(); | |
| 38 | - get = new HttpGet(url); | |
| 39 | - requestConfig = RequestConfig.custom() | |
| 40 | - .setConnectTimeout(5500).setConnectionRequestTimeout(5000) | |
| 41 | - .setSocketTimeout(5500).build(); | |
| 42 | - get.setConfig(requestConfig); | |
| 43 | - } | |
| 44 | - | |
| 45 | - @Override | |
| 46 | - public void run() { | |
| 47 | - List<SafeDriv> list; | |
| 48 | - try { | |
| 49 | - | |
| 50 | - response = httpClient.execute(get); | |
| 51 | - | |
| 52 | - int statusCode = response.getStatusLine().getStatusCode(); | |
| 53 | - if(statusCode != 200){ | |
| 54 | - logger.error("http client status code: " + statusCode); | |
| 55 | - } | |
| 56 | - | |
| 57 | - entity = response.getEntity(); | |
| 58 | - if (null != entity) { | |
| 59 | - br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 60 | - StringBuffer stringBuffer = new StringBuffer(); | |
| 61 | - String str = ""; | |
| 62 | - while ((str = br.readLine()) != null) | |
| 63 | - stringBuffer.append(str); | |
| 64 | - | |
| 65 | - | |
| 66 | - list = JSON.parseArray(stringBuffer.toString(), SafeDriv.class); | |
| 67 | - | |
| 68 | - for (SafeDriv sd : list) { | |
| 69 | - SafeDrivCenter.put(sd); | |
| 70 | - } | |
| 71 | - } | |
| 72 | - | |
| 73 | - if (null != response) | |
| 74 | - response.close(); | |
| 75 | - } catch (Exception e) { | |
| 76 | - logger.error("安全驾驶接口报错了", e); | |
| 77 | - } | |
| 78 | - } | |
| 79 | -} | |
| 1 | +package com.bsth.data.safe_driv; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import org.apache.http.HttpEntity; | |
| 5 | +import org.apache.http.client.config.RequestConfig; | |
| 6 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
| 7 | +import org.apache.http.client.methods.HttpGet; | |
| 8 | +import org.apache.http.impl.client.CloseableHttpClient; | |
| 9 | +import org.apache.http.impl.client.HttpClients; | |
| 10 | +import org.slf4j.Logger; | |
| 11 | +import org.slf4j.LoggerFactory; | |
| 12 | +import org.springframework.stereotype.Component; | |
| 13 | + | |
| 14 | +import java.io.BufferedReader; | |
| 15 | +import java.io.InputStreamReader; | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * 安全驾驶数据加载线程 | |
| 20 | + * Created by panzhao on 2017/4/6. | |
| 21 | + */ | |
| 22 | +@Component | |
| 23 | +public class SafeDrivDataLoadThread extends Thread { | |
| 24 | + | |
| 25 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 26 | + | |
| 27 | + static String url; | |
| 28 | + static CloseableHttpClient httpClient; | |
| 29 | + static HttpGet get; | |
| 30 | + static RequestConfig requestConfig; | |
| 31 | + static CloseableHttpResponse response; | |
| 32 | + static HttpEntity entity; | |
| 33 | + static BufferedReader br; | |
| 34 | + | |
| 35 | + static { | |
| 36 | + url = "http://211.95.61.66:9008/safedriving/realtimeInterface"; | |
| 37 | + httpClient = HttpClients.createDefault(); | |
| 38 | + get = new HttpGet(url); | |
| 39 | + requestConfig = RequestConfig.custom() | |
| 40 | + .setConnectTimeout(5500).setConnectionRequestTimeout(5000) | |
| 41 | + .setSocketTimeout(5500).build(); | |
| 42 | + get.setConfig(requestConfig); | |
| 43 | + } | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public void run() { | |
| 47 | + logger.warn("安全驾驶获取数据开始"); | |
| 48 | + List<SafeDriv> list; | |
| 49 | + try { | |
| 50 | + | |
| 51 | + response = httpClient.execute(get); | |
| 52 | + | |
| 53 | + int statusCode = response.getStatusLine().getStatusCode(); | |
| 54 | + if(statusCode != 200){ | |
| 55 | + logger.error("http client status code: " + statusCode); | |
| 56 | + } | |
| 57 | + | |
| 58 | + entity = response.getEntity(); | |
| 59 | + if (null != entity) { | |
| 60 | + br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 61 | + StringBuffer stringBuffer = new StringBuffer(); | |
| 62 | + String str = ""; | |
| 63 | + while ((str = br.readLine()) != null) | |
| 64 | + stringBuffer.append(str); | |
| 65 | + | |
| 66 | + | |
| 67 | + list = JSON.parseArray(stringBuffer.toString(), SafeDriv.class); | |
| 68 | + | |
| 69 | + for (SafeDriv sd : list) { | |
| 70 | + SafeDrivCenter.put(sd); | |
| 71 | + } | |
| 72 | + } | |
| 73 | + | |
| 74 | + if (null != response) | |
| 75 | + response.close(); | |
| 76 | + } catch (Exception e) { | |
| 77 | + logger.error("安全驾驶接口报错了", e); | |
| 78 | + } | |
| 79 | + logger.warn("安全驾驶获取数据结束"); | |
| 80 | + } | |
| 81 | +} | ... | ... |
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
| ... | ... | @@ -15,6 +15,8 @@ import com.bsth.entity.schedule.SchedulePlanInfo; |
| 15 | 15 | import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; |
| 16 | 16 | import com.bsth.service.schedule.SchedulePlanInfoService; |
| 17 | 17 | import com.bsth.websocket.handler.SendUtils; |
| 18 | +import com.fasterxml.jackson.core.JsonProcessingException; | |
| 19 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
| 18 | 20 | import com.google.common.collect.ArrayListMultimap; |
| 19 | 21 | import com.google.common.collect.HashMultimap; |
| 20 | 22 | import com.google.common.collect.ListMultimap; |
| ... | ... | @@ -29,11 +31,10 @@ import org.springframework.beans.factory.annotation.Value; |
| 29 | 31 | import org.springframework.dao.DataIntegrityViolationException; |
| 30 | 32 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
| 31 | 33 | import org.springframework.jdbc.core.JdbcTemplate; |
| 32 | -import org.springframework.jdbc.datasource.DataSourceTransactionManager; | |
| 33 | 34 | import org.springframework.stereotype.Component; |
| 34 | -import org.springframework.transaction.TransactionDefinition; | |
| 35 | 35 | import org.springframework.transaction.TransactionStatus; |
| 36 | -import org.springframework.transaction.support.DefaultTransactionDefinition; | |
| 36 | +import org.springframework.transaction.support.TransactionCallbackWithoutResult; | |
| 37 | +import org.springframework.transaction.support.TransactionTemplate; | |
| 37 | 38 | |
| 38 | 39 | import java.sql.PreparedStatement; |
| 39 | 40 | import java.sql.SQLException; |
| ... | ... | @@ -440,85 +441,84 @@ public class DayOfSchedule { |
| 440 | 441 | item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate())); |
| 441 | 442 | } |
| 442 | 443 | |
| 443 | - //编程式事务 | |
| 444 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 445 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 446 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 447 | - TransactionStatus status = tran.getTransaction(def); | |
| 448 | - | |
| 449 | - try{ | |
| 450 | - final List<ScheduleRealInfo> pstList = list; | |
| 451 | - //写入 | |
| 452 | - jdbcTemplate.batchUpdate("insert into bsth_c_s_sp_info_real(id,bc_type,bcs,bcsj,cl_zbh,create_date,dfsj,directive_state,fcno,fcsj,fcsj_actual,j_gh,j_name,jhlc,lp_name,qdz_code,qdz_name,real_exec_date,remarks,s_gh,s_name,schedule_date,schedule_date_str,sflj,sp_id,status,update_date,xl_bm,xl_dir,xl_name,zdsj,zdsj_actual,zdz_code,zdz_name,ccno,df_auto,fgs_bm,fgs_name,gs_bm,gs_name,online,adjust_exps,reissue,jhlc_orig,sigin_compate,drift_status,cc_service,major_station_name,rfid_state,first_rfid_state)" + | |
| 453 | - " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() { | |
| 454 | - @Override | |
| 455 | - public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 456 | - ScheduleRealInfo sch = pstList.get(i); | |
| 457 | - ps.setLong(1, sch.getId()); | |
| 458 | - ps.setString(2, sch.getBcType()); | |
| 459 | - ps.setInt(3, sch.getBcs()==null?0:sch.getBcs()); | |
| 460 | - ps.setInt(4, sch.getBcsj()==null?0:sch.getBcsj()); | |
| 461 | - ps.setString(5, sch.getClZbh()); | |
| 462 | - ps.setTimestamp(6, new java.sql.Timestamp(sch.getCreateDate().getTime())); | |
| 463 | - ps.setString(7, sch.getDfsj()); | |
| 464 | - ps.setInt(8, sch.getDirectiveState()); | |
| 465 | - ps.setInt(9, sch.getFcno()==null?0:sch.getFcno()); | |
| 466 | - ps.setString(10, sch.getFcsj()); | |
| 467 | - ps.setString(11, sch.getFcsjActual()); | |
| 468 | - ps.setString(12, sch.getjGh()); | |
| 469 | - ps.setString(13, sch.getjName()); | |
| 470 | - ps.setDouble(14, sch.getJhlc()); | |
| 471 | - ps.setString(15, sch.getLpName()); | |
| 472 | - ps.setString(16, sch.getQdzCode()); | |
| 473 | - ps.setString(17, sch.getQdzName()); | |
| 474 | - ps.setString(18, sch.getRealExecDate()); | |
| 475 | - ps.setString(19, sch.getRemarks()); | |
| 476 | - ps.setString(20, sch.getsGh()); | |
| 477 | - ps.setString(21, sch.getsName()); | |
| 478 | - ps.setTimestamp(22, new java.sql.Timestamp(sch.getScheduleDate().getTime())); | |
| 479 | - ps.setString(23, sch.getScheduleDateStr()); | |
| 480 | - ps.setBoolean(24, sch.isSflj()); | |
| 481 | - ps.setLong(25, sch.getSpId()); | |
| 482 | - ps.setInt(26, sch.getStatus()); | |
| 483 | - ps.setTimestamp(27, new java.sql.Timestamp(sch.getUpdateDate().getTime())); | |
| 484 | - ps.setString(28, sch.getXlBm()); | |
| 485 | - ps.setString(29, sch.getXlDir()); | |
| 486 | - ps.setString(30, sch.getXlName()); | |
| 487 | - ps.setString(31, sch.getZdsj()); | |
| 488 | - ps.setString(32, sch.getZdsjActual()); | |
| 489 | - ps.setString(33, sch.getZdzCode()); | |
| 490 | - ps.setString(34, sch.getZdzName()); | |
| 491 | - ps.setInt(35, sch.getCcno()==null?0:sch.getCcno()); | |
| 492 | - ps.setBoolean(36, sch.isDfAuto()); | |
| 493 | - ps.setString(37, sch.getFgsBm()); | |
| 494 | - ps.setString(38, sch.getFgsName()); | |
| 495 | - ps.setString(39, sch.getGsBm()); | |
| 496 | - ps.setString(40, sch.getGsName()); | |
| 497 | - ps.setBoolean(41, sch.isOnline()); | |
| 498 | - ps.setString(42, sch.getAdjustExps()); | |
| 499 | - ps.setBoolean(43, sch.isReissue()); | |
| 500 | - ps.setDouble(44, sch.getJhlcOrig()); | |
| 501 | - ps.setInt(45, sch.getSiginCompate()); | |
| 502 | - ps.setInt(46, sch.getDriftStatus()); | |
| 503 | - ps.setBoolean(47, sch.isCcService()); | |
| 504 | - ps.setString(48, sch.getMajorStationName()); | |
| 505 | - ps.setInt(49, sch.getRfidState()); | |
| 506 | - ps.setInt(50, sch.getFirstRfidState()); | |
| 507 | - } | |
| 508 | - | |
| 509 | - @Override | |
| 510 | - public int getBatchSize() { | |
| 511 | - return pstList.size(); | |
| 444 | + transactionTemplate.execute(new TransactionCallbackWithoutResult() { | |
| 445 | + @Override | |
| 446 | + protected void doInTransactionWithoutResult(TransactionStatus status) { | |
| 447 | + try{ | |
| 448 | + final List<ScheduleRealInfo> pstList = list; | |
| 449 | + //写入 | |
| 450 | + jdbcTemplate.batchUpdate("insert into bsth_c_s_sp_info_real(id,bc_type,bcs,bcsj,cl_zbh,create_date,dfsj,directive_state,fcno,fcsj,fcsj_actual,j_gh,j_name,jhlc,lp_name,qdz_code,qdz_name,real_exec_date,remarks,s_gh,s_name,schedule_date,schedule_date_str,sflj,sp_id,status,update_date,xl_bm,xl_dir,xl_name,zdsj,zdsj_actual,zdz_code,zdz_name,ccno,df_auto,fgs_bm,fgs_name,gs_bm,gs_name,online,adjust_exps,reissue,jhlc_orig,sigin_compate,drift_status,cc_service,major_station_name,rfid_state,first_rfid_state)" + | |
| 451 | + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() { | |
| 452 | + @Override | |
| 453 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 454 | + ScheduleRealInfo sch = pstList.get(i); | |
| 455 | + ps.setLong(1, sch.getId()); | |
| 456 | + ps.setString(2, sch.getBcType()); | |
| 457 | + ps.setInt(3, sch.getBcs()==null?0:sch.getBcs()); | |
| 458 | + ps.setInt(4, sch.getBcsj()==null?0:sch.getBcsj()); | |
| 459 | + ps.setString(5, sch.getClZbh()); | |
| 460 | + ps.setTimestamp(6, new java.sql.Timestamp(sch.getCreateDate().getTime())); | |
| 461 | + ps.setString(7, sch.getDfsj()); | |
| 462 | + ps.setInt(8, sch.getDirectiveState()); | |
| 463 | + ps.setInt(9, sch.getFcno()==null?0:sch.getFcno()); | |
| 464 | + ps.setString(10, sch.getFcsj()); | |
| 465 | + ps.setString(11, sch.getFcsjActual()); | |
| 466 | + ps.setString(12, sch.getjGh()); | |
| 467 | + ps.setString(13, sch.getjName()); | |
| 468 | + ps.setDouble(14, sch.getJhlc()); | |
| 469 | + ps.setString(15, sch.getLpName()); | |
| 470 | + ps.setString(16, sch.getQdzCode()); | |
| 471 | + ps.setString(17, sch.getQdzName()); | |
| 472 | + ps.setString(18, sch.getRealExecDate()); | |
| 473 | + ps.setString(19, sch.getRemarks()); | |
| 474 | + ps.setString(20, sch.getsGh()); | |
| 475 | + ps.setString(21, sch.getsName()); | |
| 476 | + ps.setTimestamp(22, new java.sql.Timestamp(sch.getScheduleDate().getTime())); | |
| 477 | + ps.setString(23, sch.getScheduleDateStr()); | |
| 478 | + ps.setBoolean(24, sch.isSflj()); | |
| 479 | + ps.setLong(25, sch.getSpId()); | |
| 480 | + ps.setInt(26, sch.getStatus()); | |
| 481 | + ps.setTimestamp(27, new java.sql.Timestamp(sch.getUpdateDate().getTime())); | |
| 482 | + ps.setString(28, sch.getXlBm()); | |
| 483 | + ps.setString(29, sch.getXlDir()); | |
| 484 | + ps.setString(30, sch.getXlName()); | |
| 485 | + ps.setString(31, sch.getZdsj()); | |
| 486 | + ps.setString(32, sch.getZdsjActual()); | |
| 487 | + ps.setString(33, sch.getZdzCode()); | |
| 488 | + ps.setString(34, sch.getZdzName()); | |
| 489 | + ps.setInt(35, sch.getCcno()==null?0:sch.getCcno()); | |
| 490 | + ps.setBoolean(36, sch.isDfAuto()); | |
| 491 | + ps.setString(37, sch.getFgsBm()); | |
| 492 | + ps.setString(38, sch.getFgsName()); | |
| 493 | + ps.setString(39, sch.getGsBm()); | |
| 494 | + ps.setString(40, sch.getGsName()); | |
| 495 | + ps.setBoolean(41, sch.isOnline()); | |
| 496 | + ps.setString(42, sch.getAdjustExps()); | |
| 497 | + ps.setBoolean(43, sch.isReissue()); | |
| 498 | + ps.setDouble(44, sch.getJhlcOrig()); | |
| 499 | + ps.setInt(45, sch.getSiginCompate()); | |
| 500 | + ps.setInt(46, sch.getDriftStatus()); | |
| 501 | + ps.setBoolean(47, sch.isCcService()); | |
| 502 | + ps.setString(48, sch.getMajorStationName()); | |
| 503 | + ps.setInt(49, sch.getRfidState()); | |
| 504 | + ps.setInt(50, sch.getFirstRfidState()); | |
| 505 | + } | |
| 506 | + | |
| 507 | + @Override | |
| 508 | + public int getBatchSize() { | |
| 509 | + return pstList.size(); | |
| 510 | + } | |
| 511 | + }); | |
| 512 | + }catch (Exception e){ | |
| 513 | + status.setRollbackOnly(); | |
| 514 | + try { | |
| 515 | + logger.error(String.format("翻班实际排班数据批量保存异常: %s", mapper.writeValueAsString(list)), e); | |
| 516 | + } catch (JsonProcessingException jsonProcessingException) { | |
| 517 | + jsonProcessingException.printStackTrace(); | |
| 518 | + } | |
| 512 | 519 | } |
| 513 | - }); | |
| 514 | - | |
| 515 | - tran.commit(status); | |
| 516 | - }catch (Exception e){ | |
| 517 | - tran.rollback(status); | |
| 518 | - logger.error("real schedule batchSave error...", e); | |
| 519 | - } | |
| 520 | - // 入库 | |
| 521 | - //new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class); | |
| 520 | + } | |
| 521 | + }); | |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | public List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) { |
| ... | ... | @@ -993,6 +993,12 @@ public class DayOfSchedule { |
| 993 | 993 | @Autowired |
| 994 | 994 | JdbcTemplate jdbcTemplate; |
| 995 | 995 | |
| 996 | + @Autowired | |
| 997 | + private TransactionTemplate transactionTemplate; | |
| 998 | + | |
| 999 | + @Autowired | |
| 1000 | + private ObjectMapper mapper; | |
| 1001 | + | |
| 996 | 1002 | /** |
| 997 | 1003 | * 删除实际排班 |
| 998 | 1004 | * | ... | ... |
src/main/java/com/bsth/data/schedule/auto_exec/AutoExecScanThread.java
| 1 | -package com.bsth.data.schedule.auto_exec; | |
| 2 | - | |
| 3 | -import com.bsth.data.LineConfigData; | |
| 4 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 5 | -import com.bsth.entity.realcontrol.LineConfig; | |
| 6 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 7 | -import org.slf4j.Logger; | |
| 8 | -import org.slf4j.LoggerFactory; | |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | -import org.springframework.stereotype.Component; | |
| 11 | - | |
| 12 | -import java.util.ArrayList; | |
| 13 | -import java.util.Collection; | |
| 14 | -import java.util.List; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * 班次自动执行扫描线程 | |
| 18 | - * Created by panzhao on 2017/10/31. | |
| 19 | - */ | |
| 20 | -@Component | |
| 21 | -public class AutoExecScanThread extends Thread{ | |
| 22 | - | |
| 23 | - | |
| 24 | - @Autowired | |
| 25 | - LineConfigData lineConfigData; | |
| 26 | - | |
| 27 | - @Autowired | |
| 28 | - DayOfSchedule dayOfSchedule; | |
| 29 | - | |
| 30 | - @Autowired | |
| 31 | - RealScheduleAutoExecHandler realScheduleAutoExecHandler; | |
| 32 | - | |
| 33 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 34 | - | |
| 35 | - @Override | |
| 36 | - public void run() { | |
| 37 | - try{ | |
| 38 | - //要自动执行的线路 | |
| 39 | - List<String> autos = new ArrayList<>(); | |
| 40 | - Collection<LineConfig> lcs = lineConfigData.getAll(); | |
| 41 | - | |
| 42 | - for(LineConfig config : lcs){ | |
| 43 | - if(config.isAutoExec()){ | |
| 44 | - autos.add(config.getLine().getLineCode()); | |
| 45 | - } | |
| 46 | - } | |
| 47 | - | |
| 48 | - if(autos.size()==0) | |
| 49 | - return; | |
| 50 | - List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()); | |
| 51 | - for(ScheduleRealInfo sch : all){ | |
| 52 | - if(autos.contains(sch.getXlBm())){ | |
| 53 | - realScheduleAutoExecHandler.exec(sch); | |
| 54 | - } | |
| 55 | - } | |
| 56 | - }catch (Exception e){ | |
| 57 | - logger.error("", e); | |
| 58 | - } | |
| 59 | - } | |
| 60 | -} | |
| 1 | +package com.bsth.data.schedule.auto_exec; | |
| 2 | + | |
| 3 | +import com.bsth.data.LineConfigData; | |
| 4 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 5 | +import com.bsth.entity.realcontrol.LineConfig; | |
| 6 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.util.ArrayList; | |
| 13 | +import java.util.Collection; | |
| 14 | +import java.util.List; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * 班次自动执行扫描线程 | |
| 18 | + * Created by panzhao on 2017/10/31. | |
| 19 | + */ | |
| 20 | +@Component | |
| 21 | +public class AutoExecScanThread extends Thread{ | |
| 22 | + | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + LineConfigData lineConfigData; | |
| 26 | + | |
| 27 | + @Autowired | |
| 28 | + DayOfSchedule dayOfSchedule; | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + RealScheduleAutoExecHandler realScheduleAutoExecHandler; | |
| 32 | + | |
| 33 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public void run() { | |
| 37 | + logger.warn("班次自动执行扫描开始"); | |
| 38 | + try{ | |
| 39 | + //要自动执行的线路 | |
| 40 | + List<String> autos = new ArrayList<>(); | |
| 41 | + Collection<LineConfig> lcs = lineConfigData.getAll(); | |
| 42 | + | |
| 43 | + for(LineConfig config : lcs){ | |
| 44 | + if(config.isAutoExec()){ | |
| 45 | + autos.add(config.getLine().getLineCode()); | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 49 | + if(autos.size()==0) | |
| 50 | + return; | |
| 51 | + List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()); | |
| 52 | + for(ScheduleRealInfo sch : all){ | |
| 53 | + if(autos.contains(sch.getXlBm())){ | |
| 54 | + realScheduleAutoExecHandler.exec(sch); | |
| 55 | + } | |
| 56 | + } | |
| 57 | + }catch (Exception e){ | |
| 58 | + logger.error("", e); | |
| 59 | + } | |
| 60 | + logger.warn("班次自动执行扫描结束"); | |
| 61 | + } | |
| 62 | +} | ... | ... |
src/main/java/com/bsth/data/schedule/e_state_check/thread/FixedCheckStationCodeThread.java
| 1 | -package com.bsth.data.schedule.e_state_check.thread; | |
| 2 | - | |
| 3 | -import com.bsth.data.schedule.e_state_check.ScheduleStationCodeChecker; | |
| 4 | -import org.slf4j.Logger; | |
| 5 | -import org.slf4j.LoggerFactory; | |
| 6 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | -import org.springframework.stereotype.Component; | |
| 8 | - | |
| 9 | -/** | |
| 10 | - * 定时检查班次站点编码线程 | |
| 11 | - * Created by panzhao on 2018/4/2. | |
| 12 | - */ | |
| 13 | -@Component | |
| 14 | -public class FixedCheckStationCodeThread extends Thread { | |
| 15 | - | |
| 16 | - @Autowired | |
| 17 | - ScheduleStationCodeChecker scheduleStationCodeChecker; | |
| 18 | - | |
| 19 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 20 | - | |
| 21 | - @Override | |
| 22 | - public void run() { | |
| 23 | - try { | |
| 24 | - scheduleStationCodeChecker.checkAll(); | |
| 25 | - } catch (Exception e) { | |
| 26 | - logger.error("", e); | |
| 27 | - } | |
| 28 | - } | |
| 29 | -} | |
| 1 | +package com.bsth.data.schedule.e_state_check.thread; | |
| 2 | + | |
| 3 | +import com.bsth.data.schedule.e_state_check.ScheduleStationCodeChecker; | |
| 4 | +import org.slf4j.Logger; | |
| 5 | +import org.slf4j.LoggerFactory; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 定时检查班次站点编码线程 | |
| 11 | + * Created by panzhao on 2018/4/2. | |
| 12 | + */ | |
| 13 | +@Component | |
| 14 | +public class FixedCheckStationCodeThread extends Thread { | |
| 15 | + | |
| 16 | + @Autowired | |
| 17 | + ScheduleStationCodeChecker scheduleStationCodeChecker; | |
| 18 | + | |
| 19 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 20 | + | |
| 21 | + @Override | |
| 22 | + public void run() { | |
| 23 | + logger.warn("班次站点编码检查开始"); | |
| 24 | + try { | |
| 25 | + scheduleStationCodeChecker.checkAll(); | |
| 26 | + } catch (Exception e) { | |
| 27 | + logger.error("", e); | |
| 28 | + } | |
| 29 | + logger.warn("班次站点编码检查结束"); | |
| 30 | + } | |
| 31 | +} | ... | ... |
src/main/java/com/bsth/data/schedule/edit_logs/SeiPstThread.java
| ... | ... | @@ -28,6 +28,7 @@ public class SeiPstThread extends Thread{ |
| 28 | 28 | |
| 29 | 29 | @Override |
| 30 | 30 | public void run() { |
| 31 | + log.warn("班次修正日志保存开始"); | |
| 31 | 32 | try{ |
| 32 | 33 | List<SchEditInfo> pstList = new ArrayList<>(); |
| 33 | 34 | LinkedList<SchEditInfo> list = ScheduleModifyLogger.list; |
| ... | ... | @@ -48,5 +49,6 @@ public class SeiPstThread extends Thread{ |
| 48 | 49 | }catch (Exception e){ |
| 49 | 50 | log.error("", e); |
| 50 | 51 | } |
| 52 | + log.warn("班次修正日志保存结束"); | |
| 51 | 53 | } |
| 52 | 54 | } |
| 53 | 55 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/schedule/late_adjust/LateAdjustHandle.java
| 1 | - | |
| 2 | -package com.bsth.data.schedule.late_adjust; | |
| 3 | - | |
| 4 | -import com.bsth.data.LineConfigData; | |
| 5 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | -import com.bsth.entity.realcontrol.LineConfig; | |
| 7 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 8 | -import com.bsth.util.Arith; | |
| 9 | -import com.bsth.websocket.handler.SendUtils; | |
| 10 | -import org.slf4j.Logger; | |
| 11 | -import org.slf4j.LoggerFactory; | |
| 12 | -import org.springframework.beans.BeansException; | |
| 13 | -import org.springframework.context.ApplicationContext; | |
| 14 | -import org.springframework.context.ApplicationContextAware; | |
| 15 | -import org.springframework.stereotype.Component; | |
| 16 | - | |
| 17 | -import java.util.Collection; | |
| 18 | -import java.util.concurrent.ConcurrentHashMap; | |
| 19 | -import java.util.concurrent.ConcurrentMap; | |
| 20 | - | |
| 21 | -/** | |
| 22 | - * 误点自动调整待发 处理程序 | |
| 23 | - * <p> | |
| 24 | - * 注意 :这里的误点是指应发未到 | |
| 25 | - * Created by panzhao on 2017/4/16. | |
| 26 | - */ | |
| 27 | -@Component | |
| 28 | -public class LateAdjustHandle implements ApplicationContextAware { | |
| 29 | - | |
| 30 | - static LineConfigData lineConfigData; | |
| 31 | - static SendUtils sendUtils; | |
| 32 | - | |
| 33 | - static Logger logger = LoggerFactory.getLogger(LateAdjustHandle.class); | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * 应发未到的班次 key : id | |
| 37 | - */ | |
| 38 | - private static ConcurrentMap<Long, ScheduleRealInfo> lateSchMap = new ConcurrentHashMap<>(); | |
| 39 | - | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 新增一个误点班次 | |
| 43 | - * | |
| 44 | - * @param sch | |
| 45 | - */ | |
| 46 | - public static void putLate(ScheduleRealInfo sch) { | |
| 47 | - try { | |
| 48 | - //线路配置 | |
| 49 | - LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 50 | - if (sch.getLateMinute() == 0) { | |
| 51 | - if (!config.isEnableYjtk()) | |
| 52 | - return; | |
| 53 | - | |
| 54 | - sch.setLateMinute(sch.getXlDir().equals("0") ? config.getUpStopMinute() : config.getDownStopMinute()); | |
| 55 | - } | |
| 56 | - | |
| 57 | - if (sch.getDfsj().compareTo(config.getYjtkStart()) > 0 | |
| 58 | - && sch.getDfsj().compareTo(config.getYjtkEnd()) <= 0) { | |
| 59 | - | |
| 60 | - //班次压入 | |
| 61 | - if (!lateSchMap.containsKey(sch.getId())) { | |
| 62 | - logger.info("29【应发未到 班次 " + sch.getClZbh() + " -" + sch.getDfsj() + " -id: " + sch.getId() + " -加入误点调整!"); | |
| 63 | - | |
| 64 | - sch.setLate2(true); | |
| 65 | - lateSchMap.put(sch.getId(), sch); | |
| 66 | - //通知客户端 | |
| 67 | - sendUtils.sendAutoWdtz(sch, null); | |
| 68 | - } | |
| 69 | - } | |
| 70 | - | |
| 71 | - } catch (Exception e) { | |
| 72 | - logger.error("", e); | |
| 73 | - } | |
| 74 | - } | |
| 75 | - | |
| 76 | - | |
| 77 | - /** | |
| 78 | - * 获取所有应发未到的班次 | |
| 79 | - * | |
| 80 | - * @return | |
| 81 | - */ | |
| 82 | - public static Collection<ScheduleRealInfo> allLateSch() { | |
| 83 | - return lateSchMap.values(); | |
| 84 | - } | |
| 85 | - | |
| 86 | - public static void remove(ScheduleRealInfo sch) { | |
| 87 | - try { | |
| 88 | - if (lateSchMap.containsKey(sch.getId())) { | |
| 89 | - lateSchMap.remove(sch.getId()); | |
| 90 | - | |
| 91 | - sch.setLate2(false); | |
| 92 | - sch.setLateMinute(0); | |
| 93 | - sch.setDfAuto(false); | |
| 94 | - | |
| 95 | - logger.info("移除误点调整 -" + sch.getClZbh() + " -time: " + sch.getDfsj() + " -id: " + sch.getId()); | |
| 96 | - } | |
| 97 | - } catch (Exception e) { | |
| 98 | - logger.error("", e); | |
| 99 | - } | |
| 100 | - } | |
| 101 | - | |
| 102 | - /** | |
| 103 | - * 车辆到站 进站 进 的哪个班次,就调该车辆的下一个班次 | |
| 104 | - * | |
| 105 | - * @param gps | |
| 106 | - */ | |
| 107 | - public static void carArrive(GpsEntity gps, ScheduleRealInfo sch) { | |
| 108 | - try { | |
| 109 | - if (gps.getInstation() <= 0 || null == sch) | |
| 110 | - return; | |
| 111 | - | |
| 112 | - if (!lateSchMap.containsKey(sch.getId())) { | |
| 113 | - //班次是否误点(可能处于误点线程扫描的空隙,所以再判定一次) | |
| 114 | - if (sch.getDfsjT() <= gps.getTimestamp()) { | |
| 115 | - putLate(sch); | |
| 116 | - | |
| 117 | - if (!lateSchMap.containsKey(sch.getId())) | |
| 118 | - return; | |
| 119 | - | |
| 120 | - logger.info("线程空隙漏掉的误点,id: " + sch.getId()); | |
| 121 | - } else | |
| 122 | - return; | |
| 123 | - } | |
| 124 | - | |
| 125 | - | |
| 126 | - //可能是延迟信号,gps时间没有误点 | |
| 127 | - if (gps.getTimestamp() <= sch.getDfsjT()) { | |
| 128 | - sch.setLate2(false); | |
| 129 | - lateSchMap.remove(sch.getId()); | |
| 130 | - return; | |
| 131 | - } | |
| 132 | - | |
| 133 | - | |
| 134 | - //自动调整待发 到达时间 + 停靠时间 | |
| 135 | - long dt = Arith.addLong(gps.getTimestamp(), (sch.getLateMinute() * 60 * 1000)); | |
| 136 | - | |
| 137 | - sch.setDfsjAll(dt); | |
| 138 | - sch.setDfAuto(true); | |
| 139 | - //取消应发未到标记 | |
| 140 | - sch.setLate2(false); | |
| 141 | - | |
| 142 | - lateSchMap.remove(sch.getId()); | |
| 143 | - logger.info("【应发未到】车辆到站 " + sch.getClZbh() + " -" + sch.getDfsj() + " -到站时间:" + gps.getTimestamp() + " -停靠时间:" + sch.getLateMinute() + " -自动设置的待发时间:" + dt + " -id:" + sch.getId()); | |
| 144 | - } catch (Exception e) { | |
| 145 | - e.printStackTrace(); | |
| 146 | - logger.error("late2 car arrive", e); | |
| 147 | - } | |
| 148 | - } | |
| 149 | - | |
| 150 | - | |
| 151 | - @Override | |
| 152 | - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 153 | - lineConfigData = applicationContext.getBean(LineConfigData.class); | |
| 154 | - sendUtils = applicationContext.getBean(SendUtils.class); | |
| 155 | - } | |
| 1 | + | |
| 2 | +package com.bsth.data.schedule.late_adjust; | |
| 3 | + | |
| 4 | +import com.bsth.data.LineConfigData; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.entity.realcontrol.LineConfig; | |
| 7 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 8 | +import com.bsth.util.Arith; | |
| 9 | +import com.bsth.websocket.handler.SendUtils; | |
| 10 | +import org.slf4j.Logger; | |
| 11 | +import org.slf4j.LoggerFactory; | |
| 12 | +import org.springframework.beans.BeansException; | |
| 13 | +import org.springframework.context.ApplicationContext; | |
| 14 | +import org.springframework.context.ApplicationContextAware; | |
| 15 | +import org.springframework.stereotype.Component; | |
| 16 | + | |
| 17 | +import java.util.Collection; | |
| 18 | +import java.util.concurrent.ConcurrentHashMap; | |
| 19 | +import java.util.concurrent.ConcurrentMap; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * 误点自动调整待发 处理程序 | |
| 23 | + * <p> | |
| 24 | + * 注意 :这里的误点是指应发未到 | |
| 25 | + * Created by panzhao on 2017/4/16. | |
| 26 | + */ | |
| 27 | +@Component | |
| 28 | +public class LateAdjustHandle implements ApplicationContextAware { | |
| 29 | + | |
| 30 | + static LineConfigData lineConfigData; | |
| 31 | + static SendUtils sendUtils; | |
| 32 | + | |
| 33 | + static Logger logger = LoggerFactory.getLogger(LateAdjustHandle.class); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 应发未到的班次 key : id | |
| 37 | + */ | |
| 38 | + private static ConcurrentMap<Long, ScheduleRealInfo> lateSchMap = new ConcurrentHashMap<>(); | |
| 39 | + | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 新增一个误点班次 | |
| 43 | + * | |
| 44 | + * @param sch | |
| 45 | + */ | |
| 46 | + public static void putLate(ScheduleRealInfo sch) { | |
| 47 | + try { | |
| 48 | + //线路配置 | |
| 49 | + LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 50 | + if (sch.getLateMinute() == 0) { | |
| 51 | + if (!config.isEnableYjtk()) | |
| 52 | + return; | |
| 53 | + | |
| 54 | + sch.setLateMinute(sch.getXlDir().equals("0") ? config.getUpStopMinute() : config.getDownStopMinute()); | |
| 55 | + } | |
| 56 | + | |
| 57 | + if (sch.getDfsj().compareTo(config.getYjtkStart()) > 0 | |
| 58 | + && sch.getDfsj().compareTo(config.getYjtkEnd()) <= 0) { | |
| 59 | + | |
| 60 | + //班次压入 | |
| 61 | + if (!lateSchMap.containsKey(sch.getId())) { | |
| 62 | + logger.info("【应发未到】 班次 " + sch.getClZbh() + " -" + sch.getDfsj() + " -id: " + sch.getId() + " -加入误点调整!"); | |
| 63 | + | |
| 64 | + sch.setLate2(true); | |
| 65 | + lateSchMap.put(sch.getId(), sch); | |
| 66 | + //通知客户端 | |
| 67 | + sendUtils.sendAutoWdtz(sch, null); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | + } catch (Exception e) { | |
| 72 | + logger.error("", e); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * 获取所有应发未到的班次 | |
| 79 | + * | |
| 80 | + * @return | |
| 81 | + */ | |
| 82 | + public static Collection<ScheduleRealInfo> allLateSch() { | |
| 83 | + return lateSchMap.values(); | |
| 84 | + } | |
| 85 | + | |
| 86 | + public static void remove(ScheduleRealInfo sch) { | |
| 87 | + try { | |
| 88 | + if (lateSchMap.containsKey(sch.getId())) { | |
| 89 | + lateSchMap.remove(sch.getId()); | |
| 90 | + | |
| 91 | + sch.setLate2(false); | |
| 92 | + sch.setLateMinute(0); | |
| 93 | + sch.setDfAuto(false); | |
| 94 | + | |
| 95 | + logger.info("移除误点调整 -" + sch.getClZbh() + " -time: " + sch.getDfsj() + " -id: " + sch.getId()); | |
| 96 | + } | |
| 97 | + } catch (Exception e) { | |
| 98 | + logger.error("", e); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * 车辆到站 进站 进 的哪个班次,就调该车辆的下一个班次 | |
| 104 | + * | |
| 105 | + * @param gps | |
| 106 | + */ | |
| 107 | + public static void carArrive(GpsEntity gps, ScheduleRealInfo sch) { | |
| 108 | + try { | |
| 109 | + if (gps.getInstation() <= 0 || null == sch) | |
| 110 | + return; | |
| 111 | + | |
| 112 | + if (!lateSchMap.containsKey(sch.getId())) { | |
| 113 | + //班次是否误点(可能处于误点线程扫描的空隙,所以再判定一次) | |
| 114 | + if (sch.getDfsjT() <= gps.getTimestamp()) { | |
| 115 | + putLate(sch); | |
| 116 | + | |
| 117 | + if (!lateSchMap.containsKey(sch.getId())) | |
| 118 | + return; | |
| 119 | + | |
| 120 | + logger.info("线程空隙漏掉的误点,id: " + sch.getId()); | |
| 121 | + } else | |
| 122 | + return; | |
| 123 | + } | |
| 124 | + | |
| 125 | + | |
| 126 | + //可能是延迟信号,gps时间没有误点 | |
| 127 | + if (gps.getTimestamp() <= sch.getDfsjT()) { | |
| 128 | + sch.setLate2(false); | |
| 129 | + lateSchMap.remove(sch.getId()); | |
| 130 | + return; | |
| 131 | + } | |
| 132 | + | |
| 133 | + | |
| 134 | + //自动调整待发 到达时间 + 停靠时间 | |
| 135 | + long dt = Arith.addLong(gps.getTimestamp(), (sch.getLateMinute() * 60 * 1000)); | |
| 136 | + | |
| 137 | + sch.setDfsjAll(dt); | |
| 138 | + sch.setDfAuto(true); | |
| 139 | + //取消应发未到标记 | |
| 140 | + sch.setLate2(false); | |
| 141 | + | |
| 142 | + lateSchMap.remove(sch.getId()); | |
| 143 | + logger.info("【应发未到】车辆到站 " + sch.getClZbh() + " -" + sch.getDfsj() + " -到站时间:" + gps.getTimestamp() + " -停靠时间:" + sch.getLateMinute() + " -自动设置的待发时间:" + dt + " -id:" + sch.getId()); | |
| 144 | + } catch (Exception e) { | |
| 145 | + e.printStackTrace(); | |
| 146 | + logger.error("late2 car arrive", e); | |
| 147 | + } | |
| 148 | + } | |
| 149 | + | |
| 150 | + | |
| 151 | + @Override | |
| 152 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 153 | + lineConfigData = applicationContext.getBean(LineConfigData.class); | |
| 154 | + sendUtils = applicationContext.getBean(SendUtils.class); | |
| 155 | + } | |
| 156 | 156 | } |
| 157 | 157 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/schedule/late_adjust/ScheduleLateThread.java
| 1 | -package com.bsth.data.schedule.late_adjust; | |
| 2 | - | |
| 3 | - | |
| 4 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 5 | -import com.bsth.data.schedule.ScheduleComparator; | |
| 6 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 7 | -import com.bsth.websocket.handler.SendUtils; | |
| 8 | -import org.apache.commons.lang3.StringUtils; | |
| 9 | -import org.slf4j.Logger; | |
| 10 | -import org.slf4j.LoggerFactory; | |
| 11 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | -import org.springframework.stereotype.Component; | |
| 13 | - | |
| 14 | -import java.util.ArrayList; | |
| 15 | -import java.util.Collections; | |
| 16 | -import java.util.Comparator; | |
| 17 | -import java.util.List; | |
| 18 | - | |
| 19 | -/** | |
| 20 | - * | |
| 21 | - * @ClassName: ScheduleLateThread | |
| 22 | - * @Description: TODO(班次误点扫描线程) | |
| 23 | - * @author PanZhao | |
| 24 | - * @date 2016年8月31日 下午3:09:02 | |
| 25 | - * | |
| 26 | - */ | |
| 27 | -@Component | |
| 28 | -public class ScheduleLateThread extends Thread{ | |
| 29 | - | |
| 30 | - @Autowired | |
| 31 | - DayOfSchedule dayOfSchedule; | |
| 32 | - | |
| 33 | - @Autowired | |
| 34 | - SendUtils sendUtils; | |
| 35 | - | |
| 36 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 37 | - | |
| 38 | - private static Comparator<ScheduleRealInfo> cpm = new ScheduleComparator.DFSJ2(); | |
| 39 | - | |
| 40 | - @Override | |
| 41 | - public void run() { | |
| 42 | - try{ | |
| 43 | - List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()); | |
| 44 | - Collections.sort(all, cpm); | |
| 45 | - | |
| 46 | - long t = System.currentTimeMillis(); | |
| 47 | - int size = all.size(); | |
| 48 | - | |
| 49 | - ScheduleRealInfo sch; | |
| 50 | - for(int i = 0; i < size; i ++){ | |
| 51 | - sch = all.get(i); | |
| 52 | - if(sch.getDfsjT() > t) | |
| 53 | - break; | |
| 54 | - | |
| 55 | - if(sch.isLate()) | |
| 56 | - continue; | |
| 57 | - | |
| 58 | - if(sch.getStatus() == 0 | |
| 59 | - && StringUtils.isEmpty(sch.getFcsjActual())){ | |
| 60 | - | |
| 61 | - //检查应发未到 当前班次无起点到达时间 | |
| 62 | - if(StringUtils.isEmpty(sch.getQdzArrDatesj())){ | |
| 63 | - ScheduleRealInfo prev = dayOfSchedule.prev(sch); | |
| 64 | - //上一个班次也没有实际终点到达时间 | |
| 65 | - if(prev != null && StringUtils.isEmpty(prev.getZdsjActual())){ | |
| 66 | - //进入误点调整程序 | |
| 67 | - LateAdjustHandle.putLate(sch); | |
| 68 | - } | |
| 69 | - } | |
| 70 | - | |
| 71 | - //应发未发 | |
| 72 | - sch.setLate(true); | |
| 73 | - //通知客户端 | |
| 74 | - sendUtils.refreshSch(sch); | |
| 75 | - } | |
| 76 | - } | |
| 77 | - }catch (Exception e){ | |
| 78 | - logger.error("", e); | |
| 79 | - } | |
| 80 | - } | |
| 1 | +package com.bsth.data.schedule.late_adjust; | |
| 2 | + | |
| 3 | + | |
| 4 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 5 | +import com.bsth.data.schedule.ScheduleComparator; | |
| 6 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 7 | +import com.bsth.websocket.handler.SendUtils; | |
| 8 | +import org.apache.commons.lang3.StringUtils; | |
| 9 | +import org.slf4j.Logger; | |
| 10 | +import org.slf4j.LoggerFactory; | |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | +import org.springframework.stereotype.Component; | |
| 13 | + | |
| 14 | +import java.util.ArrayList; | |
| 15 | +import java.util.Collections; | |
| 16 | +import java.util.Comparator; | |
| 17 | +import java.util.List; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * | |
| 21 | + * @ClassName: ScheduleLateThread | |
| 22 | + * @Description: TODO(班次误点扫描线程) | |
| 23 | + * @author PanZhao | |
| 24 | + * @date 2016年8月31日 下午3:09:02 | |
| 25 | + * | |
| 26 | + */ | |
| 27 | +@Component | |
| 28 | +public class ScheduleLateThread extends Thread{ | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + DayOfSchedule dayOfSchedule; | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + SendUtils sendUtils; | |
| 35 | + | |
| 36 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 37 | + | |
| 38 | + private static Comparator<ScheduleRealInfo> cpm = new ScheduleComparator.DFSJ2(); | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + public void run() { | |
| 42 | + logger.warn("班次误点扫描开始"); | |
| 43 | + try{ | |
| 44 | + List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()); | |
| 45 | + Collections.sort(all, cpm); | |
| 46 | + | |
| 47 | + long t = System.currentTimeMillis(); | |
| 48 | + int size = all.size(); | |
| 49 | + | |
| 50 | + ScheduleRealInfo sch; | |
| 51 | + for(int i = 0; i < size; i ++){ | |
| 52 | + sch = all.get(i); | |
| 53 | + if(sch.getDfsjT() > t) | |
| 54 | + break; | |
| 55 | + | |
| 56 | + if(sch.isLate()) | |
| 57 | + continue; | |
| 58 | + | |
| 59 | + if(sch.getStatus() == 0 | |
| 60 | + && StringUtils.isEmpty(sch.getFcsjActual())){ | |
| 61 | + | |
| 62 | + //检查应发未到 当前班次无起点到达时间 | |
| 63 | + if(StringUtils.isEmpty(sch.getQdzArrDatesj())){ | |
| 64 | + ScheduleRealInfo prev = dayOfSchedule.prev(sch); | |
| 65 | + //上一个班次也没有实际终点到达时间 | |
| 66 | + if(prev != null && StringUtils.isEmpty(prev.getZdsjActual())){ | |
| 67 | + //进入误点调整程序 | |
| 68 | + LateAdjustHandle.putLate(sch); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + //应发未发 | |
| 73 | + sch.setLate(true); | |
| 74 | + //通知客户端 | |
| 75 | + sendUtils.refreshSch(sch); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + }catch (Exception e){ | |
| 79 | + logger.error("", e); | |
| 80 | + } | |
| 81 | + logger.warn("班次误点扫描结束"); | |
| 82 | + } | |
| 81 | 83 | } |
| 82 | 84 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/schedule/thread/SchedulePstThread.java
| ... | ... | @@ -54,7 +54,7 @@ public class SchedulePstThread extends Thread { |
| 54 | 54 | |
| 55 | 55 | @Override |
| 56 | 56 | public void run() { |
| 57 | - | |
| 57 | + logger.warn("班次批量保存开始"); | |
| 58 | 58 | try{ |
| 59 | 59 | ScheduleRealInfo schedule; |
| 60 | 60 | for (int i = 0; i < 500; i++) { |
| ... | ... | @@ -75,6 +75,7 @@ public class SchedulePstThread extends Thread { |
| 75 | 75 | }catch (Exception e){ |
| 76 | 76 | logger.error("", e); |
| 77 | 77 | } |
| 78 | + logger.warn("班次批量保存结束"); | |
| 78 | 79 | } |
| 79 | 80 | |
| 80 | 81 | private void save(){ | ... | ... |
src/main/java/com/bsth/data/schedule/thread/ScheduleRefreshThread.java
| 1 | -package com.bsth.data.schedule.thread; | |
| 2 | - | |
| 3 | -import com.bsth.data.LineConfigData; | |
| 4 | -import com.bsth.data.directive.DayOfDirectives; | |
| 5 | -import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 6 | -import com.bsth.data.pilot80.PilotReport; | |
| 7 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 8 | -import com.bsth.data.schedule.f_a_l.FirstAndLastHandler; | |
| 9 | -import com.bsth.entity.realcontrol.LineConfig; | |
| 10 | -import org.slf4j.Logger; | |
| 11 | -import org.slf4j.LoggerFactory; | |
| 12 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | -import org.springframework.stereotype.Component; | |
| 14 | - | |
| 15 | -import java.util.Collection; | |
| 16 | -import java.util.Set; | |
| 17 | - | |
| 18 | -/** | |
| 19 | - * | |
| 20 | - * @ClassName: ScheduleRefreshThread | |
| 21 | - * @Description: TODO(班次刷新线程,用于在营运开始时间切换到当日排班) | |
| 22 | - * @author PanZhao | |
| 23 | - * @date 2016年8月17日 下午1:23:34 | |
| 24 | - * | |
| 25 | - */ | |
| 26 | -@Component | |
| 27 | -public class ScheduleRefreshThread extends Thread{ | |
| 28 | - | |
| 29 | - @Autowired | |
| 30 | - DayOfSchedule dayOfSchedule; | |
| 31 | - | |
| 32 | - @Autowired | |
| 33 | - LineConfigData lineConfs; | |
| 34 | - | |
| 35 | - @Autowired | |
| 36 | - DayOfDirectives dayOfDirectives; | |
| 37 | - | |
| 38 | - @Autowired | |
| 39 | - PilotReport pilotReport; | |
| 40 | - | |
| 41 | - Logger logger = LoggerFactory.getLogger(ScheduleRefreshThread.class); | |
| 42 | - | |
| 43 | - @Override | |
| 44 | - public void run() { | |
| 45 | - try { | |
| 46 | - Collection<LineConfig> confs = lineConfs.getAll(); | |
| 47 | - | |
| 48 | - String currSchDate, oldSchDate; | |
| 49 | - String lineCode = null; | |
| 50 | - for(LineConfig conf : confs){ | |
| 51 | - try{ | |
| 52 | - lineCode = conf.getLine().getLineCode(); | |
| 53 | - oldSchDate = dayOfSchedule.getCurrSchDate().get(lineCode); | |
| 54 | - currSchDate = dayOfSchedule.calcSchDate(lineCode); | |
| 55 | - | |
| 56 | - if(oldSchDate == null || !oldSchDate.equals(currSchDate)){ | |
| 57 | - | |
| 58 | - try{ | |
| 59 | - Set<String> cars = dayOfSchedule.findCarByLineCode(lineCode); | |
| 60 | - for(String car : cars){ | |
| 61 | - GpsCacheData.remove(car); | |
| 62 | - dayOfSchedule.resetRepairReport(car); | |
| 63 | - } | |
| 64 | - //清除驾驶员上报数据 | |
| 65 | - pilotReport.clear(lineCode); | |
| 66 | - //清除指令数据 指令数据,直接定时全部清空 | |
| 67 | - //dayOfDirectives.clear(lineCode); | |
| 68 | - }catch (Exception e){ | |
| 69 | - logger.error("清理 60 和 80出现问题", e); | |
| 70 | - } | |
| 71 | - | |
| 72 | - //重载排班数据 | |
| 73 | - dayOfSchedule.reloadSch(lineCode, currSchDate, false); | |
| 74 | - logger.info(lineCode + "翻班完成, " + currSchDate + " -班次数量:" + dayOfSchedule.findByLineCode(lineCode).size()); | |
| 75 | - } | |
| 76 | - }catch (Exception e){ | |
| 77 | - logger.error("班次更新失败!! -" + lineCode, e); | |
| 78 | - } | |
| 79 | - } | |
| 80 | - | |
| 81 | - //按公司编码索引数据 | |
| 82 | - dayOfSchedule.groupByGsbm(); | |
| 83 | - | |
| 84 | - //首末班入库(给网关用的数据) | |
| 85 | - FirstAndLastHandler.saveAll(); | |
| 86 | - } catch (Exception e) { | |
| 87 | - logger.error("", e); | |
| 88 | - } | |
| 89 | - } | |
| 90 | -} | |
| 1 | +package com.bsth.data.schedule.thread; | |
| 2 | + | |
| 3 | +import com.bsth.data.LineConfigData; | |
| 4 | +import com.bsth.data.directive.DayOfDirectives; | |
| 5 | +import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 6 | +import com.bsth.data.pilot80.PilotReport; | |
| 7 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 8 | +import com.bsth.data.schedule.f_a_l.FirstAndLastHandler; | |
| 9 | +import com.bsth.entity.realcontrol.LineConfig; | |
| 10 | +import org.slf4j.Logger; | |
| 11 | +import org.slf4j.LoggerFactory; | |
| 12 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | +import org.springframework.stereotype.Component; | |
| 14 | + | |
| 15 | +import java.util.Collection; | |
| 16 | +import java.util.Set; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * | |
| 20 | + * @ClassName: ScheduleRefreshThread | |
| 21 | + * @Description: TODO(班次刷新线程,用于在营运开始时间切换到当日排班) | |
| 22 | + * @author PanZhao | |
| 23 | + * @date 2016年8月17日 下午1:23:34 | |
| 24 | + * | |
| 25 | + */ | |
| 26 | +@Component | |
| 27 | +public class ScheduleRefreshThread extends Thread{ | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + DayOfSchedule dayOfSchedule; | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + LineConfigData lineConfs; | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + DayOfDirectives dayOfDirectives; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + PilotReport pilotReport; | |
| 40 | + | |
| 41 | + Logger logger = LoggerFactory.getLogger(ScheduleRefreshThread.class); | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + public void run() { | |
| 45 | + logger.warn("班次刷新开始"); | |
| 46 | + try { | |
| 47 | + Collection<LineConfig> confs = lineConfs.getAll(); | |
| 48 | + | |
| 49 | + String currSchDate, oldSchDate; | |
| 50 | + String lineCode = null; | |
| 51 | + for(LineConfig conf : confs){ | |
| 52 | + try{ | |
| 53 | + lineCode = conf.getLine().getLineCode(); | |
| 54 | + oldSchDate = dayOfSchedule.getCurrSchDate().get(lineCode); | |
| 55 | + currSchDate = dayOfSchedule.calcSchDate(lineCode); | |
| 56 | + | |
| 57 | + if(oldSchDate == null || !oldSchDate.equals(currSchDate)){ | |
| 58 | + | |
| 59 | + try{ | |
| 60 | + Set<String> cars = dayOfSchedule.findCarByLineCode(lineCode); | |
| 61 | + for(String car : cars){ | |
| 62 | + GpsCacheData.remove(car); | |
| 63 | + dayOfSchedule.resetRepairReport(car); | |
| 64 | + } | |
| 65 | + //清除驾驶员上报数据 | |
| 66 | + pilotReport.clear(lineCode); | |
| 67 | + //清除指令数据 指令数据,直接定时全部清空 | |
| 68 | + //dayOfDirectives.clear(lineCode); | |
| 69 | + }catch (Exception e){ | |
| 70 | + logger.error("清理 60 和 80出现问题", e); | |
| 71 | + } | |
| 72 | + | |
| 73 | + //重载排班数据 | |
| 74 | + dayOfSchedule.reloadSch(lineCode, currSchDate, false); | |
| 75 | + logger.info(lineCode + "翻班完成, " + currSchDate + " -班次数量:" + dayOfSchedule.findByLineCode(lineCode).size()); | |
| 76 | + } | |
| 77 | + }catch (Exception e){ | |
| 78 | + logger.error("班次更新失败!! -" + lineCode, e); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + //按公司编码索引数据 | |
| 83 | + dayOfSchedule.groupByGsbm(); | |
| 84 | + | |
| 85 | + //首末班入库(给网关用的数据) | |
| 86 | + FirstAndLastHandler.saveAll(); | |
| 87 | + } catch (Exception e) { | |
| 88 | + logger.error("", e); | |
| 89 | + } | |
| 90 | + logger.warn("班次刷新结束"); | |
| 91 | + } | |
| 92 | +} | ... | ... |
src/main/java/com/bsth/service/geo_data/impl/GeoDataServiceImpl.java
| ... | ... | @@ -12,8 +12,8 @@ import com.bsth.service.geo_data.impl.dto.CascadeSaveRoad; |
| 12 | 12 | import com.bsth.service.geo_data.impl.dto.CascadeSaveStation; |
| 13 | 13 | import com.bsth.service.geo_data.impl.dto.SaveRoadRouteDTO; |
| 14 | 14 | import com.bsth.service.geo_data.impl.dto.SaveStationRouteDTO; |
| 15 | -import com.bsth.util.GetUIDAndCode; | |
| 16 | 15 | import com.bsth.util.TransGPS; |
| 16 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
| 17 | 17 | import com.google.common.base.Splitter; |
| 18 | 18 | import org.slf4j.Logger; |
| 19 | 19 | import org.slf4j.LoggerFactory; |
| ... | ... | @@ -21,11 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired; |
| 21 | 21 | import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
| 22 | 22 | import org.springframework.jdbc.core.BeanPropertyRowMapper; |
| 23 | 23 | import org.springframework.jdbc.core.JdbcTemplate; |
| 24 | -import org.springframework.jdbc.datasource.DataSourceTransactionManager; | |
| 25 | 24 | import org.springframework.stereotype.Service; |
| 26 | -import org.springframework.transaction.TransactionDefinition; | |
| 27 | 25 | import org.springframework.transaction.TransactionStatus; |
| 28 | -import org.springframework.transaction.support.DefaultTransactionDefinition; | |
| 26 | +import org.springframework.transaction.support.TransactionCallback; | |
| 27 | +import org.springframework.transaction.support.TransactionTemplate; | |
| 29 | 28 | |
| 30 | 29 | import java.sql.PreparedStatement; |
| 31 | 30 | import java.sql.SQLException; |
| ... | ... | @@ -47,6 +46,12 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 47 | 46 | @Autowired |
| 48 | 47 | StationRepository stationRepository; |
| 49 | 48 | |
| 49 | + @Autowired | |
| 50 | + private TransactionTemplate transactionTemplate; | |
| 51 | + | |
| 52 | + @Autowired | |
| 53 | + private ObjectMapper mapper; | |
| 54 | + | |
| 50 | 55 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 51 | 56 | |
| 52 | 57 | @Override |
| ... | ... | @@ -172,141 +177,138 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 172 | 177 | public Map<String, Object> updateStationName(Map<String, Object> map) { |
| 173 | 178 | Map<String, Object> rs = new HashMap<>(); |
| 174 | 179 | |
| 175 | - //编程式事务 | |
| 176 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 177 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 178 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 179 | - TransactionStatus status = tran.getTransaction(def); | |
| 180 | - try { | |
| 181 | - | |
| 182 | - int id = Integer.parseInt(map.get("id").toString()); | |
| 183 | - String name = map.get("stationName").toString(); | |
| 184 | - String code = map.get("stationCode").toString(); | |
| 185 | - String lineCode = map.get("lineCode").toString(); | |
| 186 | - String versions = map.get("versions").toString(); | |
| 187 | - | |
| 188 | - //更新历史站点路由 | |
| 189 | - jdbcTemplate.update("update bsth_c_ls_stationroute set station_name=? where id=?", name, id); | |
| 190 | - //更新站点 | |
| 191 | - jdbcTemplate.update("update bsth_c_station set station_name=? where station_cod=?", name, code); | |
| 192 | - | |
| 193 | - //写一条走向变更记录 | |
| 194 | - jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions); | |
| 195 | - | |
| 196 | - tran.commit(status); | |
| 197 | - | |
| 198 | - rs.put("station", findOne(id)); | |
| 199 | - rs.put("status", ResponseCode.SUCCESS); | |
| 200 | - } catch (Exception e) { | |
| 201 | - tran.rollback(status); | |
| 202 | - logger.error("", e); | |
| 203 | - rs.put("status", ResponseCode.ERROR); | |
| 204 | - rs.put("msg", "服务器出现异常"); | |
| 205 | - } | |
| 206 | - return rs; | |
| 180 | + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() { | |
| 181 | + @Override | |
| 182 | + public Map<String, Object> doInTransaction(TransactionStatus status) { | |
| 183 | + try { | |
| 184 | + | |
| 185 | + int id = Integer.parseInt(map.get("id").toString()); | |
| 186 | + String name = map.get("stationName").toString(); | |
| 187 | + String code = map.get("stationCode").toString(); | |
| 188 | + String lineCode = map.get("lineCode").toString(); | |
| 189 | + String versions = map.get("versions").toString(); | |
| 190 | + | |
| 191 | + //更新历史站点路由 | |
| 192 | + jdbcTemplate.update("update bsth_c_ls_stationroute set station_name=? where id=?", name, id); | |
| 193 | + //更新站点 | |
| 194 | + jdbcTemplate.update("update bsth_c_station set station_name=? where station_cod=?", name, code); | |
| 195 | + | |
| 196 | + //写一条走向变更记录 | |
| 197 | + jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions); | |
| 198 | + | |
| 199 | + rs.put("station", findOne(id)); | |
| 200 | + rs.put("status", ResponseCode.SUCCESS); | |
| 201 | + } catch (Exception e) { | |
| 202 | + status.setRollbackOnly(); | |
| 203 | + logger.error("", e); | |
| 204 | + rs.put("status", ResponseCode.ERROR); | |
| 205 | + rs.put("msg", "服务器出现异常"); | |
| 206 | + } | |
| 207 | + return rs; | |
| 208 | + } | |
| 209 | + }); | |
| 207 | 210 | } |
| 208 | 211 | |
| 209 | 212 | @Override |
| 210 | 213 | public Map<String, Object> addNewRoadRoute(String lineCode, int upDown, int versions, String sectionName, String crosesRoad, String coords, int prevRouteId) { |
| 211 | 214 | Map<String, Object> rs = new HashMap<>(); |
| 212 | 215 | |
| 213 | - //编程式事务 | |
| 214 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 215 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 216 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 217 | - TransactionStatus status = tran.getTransaction(def); | |
| 218 | - try { | |
| 219 | - //根据线路编码,查询线路ID | |
| 220 | - int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class); | |
| 221 | - | |
| 222 | - String sql = "select * from bsth_c_ls_sectionroute where line_code='" + lineCode + "' and line=" + lineId + " and directions=" + upDown + " and destroy=0 and versions=" + versions; | |
| 223 | - List<SaveRoadRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveRoadRouteDTO.class)); | |
| 224 | - | |
| 225 | - Collections.sort(routes, new RoadRouteComp()); | |
| 226 | - | |
| 227 | - long sCode = sectionRepository.sectionMaxId() + 1; | |
| 228 | - //转wgs | |
| 229 | - String wgsCoord = "LINESTRING(" + bdPolygon2Wgs(coords) + ")"; | |
| 230 | - String bdCooed = "LINESTRING(" + coords + ")"; | |
| 231 | - //insert 路段 | |
| 232 | - sql = "insert into bsth_c_section(id, section_code, section_name, croses_road, bsection_vector, gsection_vector, create_date, update_date, versions) " + | |
| 233 | - " values(?,?,?,?,ST_GeomFromText('" + bdCooed + "'),ST_GeomFromText('" + wgsCoord + "'),sysdate(),sysdate(),?)"; | |
| 234 | - | |
| 235 | - jdbcTemplate.update(sql, sCode, sCode, sectionName, crosesRoad, 1); | |
| 236 | - | |
| 216 | + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() { | |
| 237 | 217 | |
| 238 | - SaveRoadRouteDTO srr; | |
| 239 | - int currentNo = -1, | |
| 240 | - no = 100, step = 100; | |
| 241 | - | |
| 242 | - if (prevRouteId == -1) { | |
| 243 | - //起点站 | |
| 244 | - currentNo = no; | |
| 245 | - no += step; | |
| 246 | - } | |
| 247 | - //重新排序路由 | |
| 248 | - for (int i = 0, size = routes.size(); i < size; i++) { | |
| 249 | - srr = routes.get(i); | |
| 250 | - srr.setSectionrouteCode(no += step); | |
| 251 | - if (srr.getId().intValue() == prevRouteId) { | |
| 252 | - no += step; | |
| 253 | - currentNo = no; | |
| 218 | + @Override | |
| 219 | + public Map<String, Object> doInTransaction(TransactionStatus status) { | |
| 220 | + try { | |
| 221 | + //根据线路编码,查询线路ID | |
| 222 | + int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class); | |
| 223 | + | |
| 224 | + String sql = "select * from bsth_c_ls_sectionroute where line_code='" + lineCode + "' and line=" + lineId + " and directions=" + upDown + " and destroy=0 and versions=" + versions; | |
| 225 | + List<SaveRoadRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveRoadRouteDTO.class)); | |
| 226 | + | |
| 227 | + Collections.sort(routes, new RoadRouteComp()); | |
| 228 | + | |
| 229 | + long sCode = sectionRepository.sectionMaxId() + 1; | |
| 230 | + //转wgs | |
| 231 | + String wgsCoord = "LINESTRING(" + bdPolygon2Wgs(coords) + ")"; | |
| 232 | + String bdCooed = "LINESTRING(" + coords + ")"; | |
| 233 | + //insert 路段 | |
| 234 | + sql = "insert into bsth_c_section(id, section_code, section_name, croses_road, bsection_vector, gsection_vector, create_date, update_date, versions) " + | |
| 235 | + " values(?,?,?,?,ST_GeomFromText('" + bdCooed + "'),ST_GeomFromText('" + wgsCoord + "'),sysdate(),sysdate(),?)"; | |
| 236 | + | |
| 237 | + jdbcTemplate.update(sql, sCode, sCode, sectionName, crosesRoad, 1); | |
| 238 | + | |
| 239 | + | |
| 240 | + SaveRoadRouteDTO srr; | |
| 241 | + int currentNo = -1, | |
| 242 | + no = 100, step = 100; | |
| 243 | + | |
| 244 | + if (prevRouteId == -1) { | |
| 245 | + //起点站 | |
| 246 | + currentNo = no; | |
| 247 | + no += step; | |
| 248 | + } | |
| 249 | + //重新排序路由 | |
| 250 | + for (int i = 0, size = routes.size(); i < size; i++) { | |
| 251 | + srr = routes.get(i); | |
| 252 | + srr.setSectionrouteCode(no += step); | |
| 253 | + if (srr.getId().intValue() == prevRouteId) { | |
| 254 | + no += step; | |
| 255 | + currentNo = no; | |
| 256 | + } | |
| 257 | + } | |
| 258 | + | |
| 259 | + srr = new SaveRoadRouteDTO(); | |
| 260 | + srr.setLine(lineId); | |
| 261 | + srr.setLineCode(lineCode); | |
| 262 | + srr.setDirections(upDown); | |
| 263 | + srr.setVersions(versions); | |
| 264 | + | |
| 265 | + srr.setSectionrouteCode(currentNo); | |
| 266 | + srr.setSection(sCode); | |
| 267 | + srr.setSectionCode(sCode + ""); | |
| 268 | + srr.setIsRoadeSpeed(0); | |
| 269 | + srr.setDestroy(0); | |
| 270 | + Date d = new Date(); | |
| 271 | + srr.setCreateDate(d); | |
| 272 | + srr.setUpdateDate(d); | |
| 273 | + | |
| 274 | + final List<SaveRoadRouteDTO> saveList = routes; | |
| 275 | + //insert 新路由 (ID自增) | |
| 276 | + jdbcTemplate.update("insert into bsth_c_ls_sectionroute(line_code, section_code, sectionroute_code, directions, line, section, create_date,update_date,versions,destroy,is_roade_speed)" + | |
| 277 | + " values(?,?,?,?,?,?,?,?,?,?,?)", srr.getLineCode(), srr.getSectionCode(), srr.getSectionrouteCode(), srr.getDirections(), srr.getLine(), srr.getSection(), srr.getCreateDate(), srr.getUpdateDate(), versions, srr.getDestroy(), srr.getIsRoadeSpeed()); | |
| 278 | + | |
| 279 | + // update 原路由 | |
| 280 | + jdbcTemplate.batchUpdate("update bsth_c_ls_sectionroute set sectionroute_code=? where id=?" | |
| 281 | + , new BatchPreparedStatementSetter() { | |
| 282 | + @Override | |
| 283 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 284 | + SaveRoadRouteDTO srr = saveList.get(i); | |
| 285 | + ps.setInt(1, srr.getSectionrouteCode()); | |
| 286 | + ps.setInt(2, srr.getId()); | |
| 287 | + } | |
| 288 | + | |
| 289 | + @Override | |
| 290 | + public int getBatchSize() { | |
| 291 | + return saveList.size(); | |
| 292 | + } | |
| 293 | + }); | |
| 294 | + | |
| 295 | + | |
| 296 | + //写一条走向变更记录 | |
| 297 | + jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions); | |
| 298 | + | |
| 299 | + //返回更新之后的数据 | |
| 300 | + List<GeoRoad> list = findRoadByUpdown(lineCode, upDown, versions); | |
| 301 | + rs.put("list", list); | |
| 302 | + rs.put("status", ResponseCode.SUCCESS); | |
| 303 | + } catch (Exception e) { | |
| 304 | + status.setRollbackOnly(); | |
| 305 | + logger.error("", e); | |
| 306 | + rs.put("status", ResponseCode.ERROR); | |
| 307 | + rs.put("msg", "服务器出现异常"); | |
| 254 | 308 | } |
| 309 | + return rs; | |
| 255 | 310 | } |
| 256 | - | |
| 257 | - srr = new SaveRoadRouteDTO(); | |
| 258 | - srr.setLine(lineId); | |
| 259 | - srr.setLineCode(lineCode); | |
| 260 | - srr.setDirections(upDown); | |
| 261 | - srr.setVersions(versions); | |
| 262 | - | |
| 263 | - srr.setSectionrouteCode(currentNo); | |
| 264 | - srr.setSection(sCode); | |
| 265 | - srr.setSectionCode(sCode + ""); | |
| 266 | - srr.setIsRoadeSpeed(0); | |
| 267 | - srr.setDestroy(0); | |
| 268 | - Date d = new Date(); | |
| 269 | - srr.setCreateDate(d); | |
| 270 | - srr.setUpdateDate(d); | |
| 271 | - | |
| 272 | - final List<SaveRoadRouteDTO> saveList = routes; | |
| 273 | - //insert 新路由 (ID自增) | |
| 274 | - jdbcTemplate.update("insert into bsth_c_ls_sectionroute(line_code, section_code, sectionroute_code, directions, line, section, create_date,update_date,versions,destroy,is_roade_speed)" + | |
| 275 | - " values(?,?,?,?,?,?,?,?,?,?,?)", srr.getLineCode(), srr.getSectionCode(), srr.getSectionrouteCode(), srr.getDirections(), srr.getLine(), srr.getSection(), srr.getCreateDate(), srr.getUpdateDate(), versions, srr.getDestroy(), srr.getIsRoadeSpeed()); | |
| 276 | - | |
| 277 | - // update 原路由 | |
| 278 | - jdbcTemplate.batchUpdate("update bsth_c_ls_sectionroute set sectionroute_code=? where id=?" | |
| 279 | - , new BatchPreparedStatementSetter() { | |
| 280 | - @Override | |
| 281 | - public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 282 | - SaveRoadRouteDTO srr = saveList.get(i); | |
| 283 | - ps.setInt(1, srr.getSectionrouteCode()); | |
| 284 | - ps.setInt(2, srr.getId()); | |
| 285 | - } | |
| 286 | - | |
| 287 | - @Override | |
| 288 | - public int getBatchSize() { | |
| 289 | - return saveList.size(); | |
| 290 | - } | |
| 291 | - }); | |
| 292 | - | |
| 293 | - | |
| 294 | - //写一条走向变更记录 | |
| 295 | - jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions); | |
| 296 | - | |
| 297 | - tran.commit(status); | |
| 298 | - | |
| 299 | - //返回更新之后的数据 | |
| 300 | - List<GeoRoad> list = findRoadByUpdown(lineCode, upDown, versions); | |
| 301 | - rs.put("list", list); | |
| 302 | - rs.put("status", ResponseCode.SUCCESS); | |
| 303 | - } catch (Exception e) { | |
| 304 | - tran.rollback(status); | |
| 305 | - logger.error("", e); | |
| 306 | - rs.put("status", ResponseCode.ERROR); | |
| 307 | - rs.put("msg", "服务器出现异常"); | |
| 308 | - } | |
| 309 | - return rs; | |
| 311 | + }); | |
| 310 | 312 | } |
| 311 | 313 | |
| 312 | 314 | /** |
| ... | ... | @@ -339,99 +341,100 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 339 | 341 | public Map<String, Object> addNewLineVersion(Map<String, Object> map) { |
| 340 | 342 | Map<String, Object> rs = new HashMap<>(); |
| 341 | 343 | |
| 342 | - //编程式事务 | |
| 343 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 344 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 345 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 346 | - TransactionStatus status = tran.getTransaction(def); | |
| 347 | - try { | |
| 348 | - | |
| 349 | - String lineCode = map.get("lineCode").toString(); | |
| 350 | - String remark = map.get("remark").toString(); | |
| 351 | - String name = map.get("name").toString(); | |
| 352 | - Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(map.get("startDate").toString()); | |
| 353 | - int extendsVersion = Integer.parseInt(map.get("extendsVersion").toString()); | |
| 344 | + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() { | |
| 354 | 345 | |
| 355 | - if(startDate.getTime() - System.currentTimeMillis() < 1000 * 60 * 3){ | |
| 356 | - rs.put("status", ResponseCode.ERROR); | |
| 357 | - rs.put("msg", "启用时间最少需要晚于当前服务器时间3分钟!"); | |
| 358 | - return rs; | |
| 359 | - } | |
| 360 | - | |
| 361 | - int nameCount = jdbcTemplate.queryForObject("select count(*) from bsth_c_line_versions where line_code=" + lineCode + " and name='"+name+"'", Integer.class); | |
| 362 | - if(nameCount > 0){ | |
| 363 | - rs.put("status", ResponseCode.ERROR); | |
| 364 | - rs.put("msg", "你不能使用一个已经存在的版本名称!!"); | |
| 365 | - return rs; | |
| 366 | - } | |
| 367 | - | |
| 368 | - //当前最大的版本号 | |
| 369 | - int maxVersion = jdbcTemplate.queryForObject("select max(versions) as versions from bsth_c_line_versions where line_code=" + lineCode, Integer.class); | |
| 370 | - Date d = new Date(); | |
| 371 | - | |
| 372 | - //根据线路编码,查询线路ID | |
| 373 | - int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class); | |
| 374 | - | |
| 375 | - maxVersion += 1; | |
| 376 | - LineVersions lVersion = new LineVersions(); | |
| 377 | - lVersion.setName(name); | |
| 378 | - lVersion.setVersions(maxVersion); | |
| 379 | - lVersion.setRemark(remark); | |
| 380 | - lVersion.setStartDate(startDate); | |
| 381 | - lVersion.setStatus(2); | |
| 382 | - lVersion.setCreateDate(d); | |
| 383 | - lVersion.setUpdateDate(d); | |
| 384 | - lVersion.setLineCode(lineCode); | |
| 385 | - | |
| 386 | - //如果有待启用的版本,设置为历史版本 | |
| 387 | - jdbcTemplate.update("update bsth_c_line_versions set `status`=2, start_date=null,end_date=null where line_code='"+lineCode+"' and `status`=0"); | |
| 388 | - | |
| 389 | - //入库线路版本 | |
| 390 | - jdbcTemplate.update("insert into bsth_c_line_versions(name, line, line_code, versions, start_date, create_date, update_date, remark,status, isupdate) " + | |
| 391 | - " values(?,?,?,?,?,?,?,?,?,?)", lVersion.getName(), lineId, lVersion.getLineCode() | |
| 392 | - , lVersion.getVersions(), lVersion.getStartDate(), lVersion.getCreateDate(), lVersion.getUpdateDate(), lVersion.getRemark(), lVersion.getStatus(), lVersion.getIsupdate()); | |
| 393 | - | |
| 394 | - if (extendsVersion != -1) { | |
| 395 | - //复制站点信息 | |
| 396 | - String sql = "SELECT t1.id AS route_id,t1.line,t1.directions,t1.station,t1.station_name,t1.station_route_code,t1.line_code,t1.station_code,t1.station_mark,t1.distances,t1.to_time,t2.id AS station_id,t2.db_type,t2.b_jwpoints,t2.g_lonx,t2.g_laty,t2.radius,ST_AsText(t2.g_polygon_grid) as g_polygon_grid,t2.shapes_type FROM bsth_c_ls_stationroute t1 LEFT JOIN bsth_c_station t2 ON t1.station_code = t2.station_cod where t1.destroy=0 and t1.line_code='" + lineCode + "' and t1.versions="+extendsVersion+" order by t1.directions, t1.station_route_code"; | |
| 397 | - List<CascadeSaveStation> cssList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(CascadeSaveStation.class)); | |
| 398 | - | |
| 399 | - //新的站点编码 | |
| 400 | - long sCode; | |
| 401 | - for (CascadeSaveStation ss : cssList) { | |
| 402 | - sCode = stationRepository.stationMaxId() + 1; | |
| 403 | - ss.setRouteId(null); | |
| 404 | - ss.setStationCode(sCode + ""); | |
| 405 | - ss.setStation((int) sCode); | |
| 406 | - } | |
| 407 | - //入库新版本的站点 和 路由 | |
| 408 | - batchInsertStation(cssList, maxVersion); | |
| 409 | - | |
| 410 | - //复制路段信息 | |
| 411 | - sql = "SELECT t1.id AS route_id,t1.line,t1.line_code,t1.directions,t1.section,t1.section_code,t1.sectionroute_code,t1.versions,t2.section_name,t2.croses_road,ST_AsText(t2.gsection_vector) as gsection_vector,t2.db_type,t2.speed_limit FROM bsth_c_ls_sectionroute t1 LEFT JOIN bsth_c_section t2 ON t1.section_code = t2.section_code WHERE t1.destroy = 0 AND t1.line_code = '"+lineCode+"' and t1.versions="+ extendsVersion +" ORDER BY t1.directions,t1.sectionroute_code"; | |
| 412 | - List<CascadeSaveRoad> csrList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(CascadeSaveRoad.class)); | |
| 413 | - //新的路段编码 | |
| 414 | - long cCode; | |
| 415 | - for(CascadeSaveRoad csr : csrList){ | |
| 416 | - cCode = sectionRepository.sectionMaxId() + 1; | |
| 417 | - csr.setRouteId(null); | |
| 418 | - csr.setSection((int) cCode); | |
| 419 | - csr.setSectionCode(cCode + ""); | |
| 346 | + @Override | |
| 347 | + public Map<String, Object> doInTransaction(TransactionStatus status) { | |
| 348 | + try { | |
| 349 | + | |
| 350 | + String lineCode = map.get("lineCode").toString(); | |
| 351 | + String remark = map.get("remark").toString(); | |
| 352 | + String name = map.get("name").toString(); | |
| 353 | + Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(map.get("startDate").toString()); | |
| 354 | + int extendsVersion = Integer.parseInt(map.get("extendsVersion").toString()); | |
| 355 | + | |
| 356 | + if(startDate.getTime() - System.currentTimeMillis() < 1000 * 60 * 3){ | |
| 357 | + rs.put("status", ResponseCode.ERROR); | |
| 358 | + rs.put("msg", "启用时间最少需要晚于当前服务器时间3分钟!"); | |
| 359 | + return rs; | |
| 360 | + } | |
| 361 | + | |
| 362 | + int nameCount = jdbcTemplate.queryForObject("select count(*) from bsth_c_line_versions where line_code=" + lineCode + " and name='"+name+"'", Integer.class); | |
| 363 | + if(nameCount > 0){ | |
| 364 | + rs.put("status", ResponseCode.ERROR); | |
| 365 | + rs.put("msg", "你不能使用一个已经存在的版本名称!!"); | |
| 366 | + return rs; | |
| 367 | + } | |
| 368 | + | |
| 369 | + //当前最大的版本号 | |
| 370 | + int maxVersion = jdbcTemplate.queryForObject("select max(versions) as versions from bsth_c_line_versions where line_code=" + lineCode, Integer.class); | |
| 371 | + Date d = new Date(); | |
| 372 | + | |
| 373 | + //根据线路编码,查询线路ID | |
| 374 | + int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class); | |
| 375 | + | |
| 376 | + maxVersion += 1; | |
| 377 | + LineVersions lVersion = new LineVersions(); | |
| 378 | + lVersion.setName(name); | |
| 379 | + lVersion.setVersions(maxVersion); | |
| 380 | + lVersion.setRemark(remark); | |
| 381 | + lVersion.setStartDate(startDate); | |
| 382 | + lVersion.setStatus(2); | |
| 383 | + lVersion.setCreateDate(d); | |
| 384 | + lVersion.setUpdateDate(d); | |
| 385 | + lVersion.setLineCode(lineCode); | |
| 386 | + | |
| 387 | + //如果有待启用的版本,设置为历史版本 | |
| 388 | + jdbcTemplate.update("update bsth_c_line_versions set `status`=2, start_date=null,end_date=null where line_code='"+lineCode+"' and `status`=0"); | |
| 389 | + | |
| 390 | + //入库线路版本 | |
| 391 | + jdbcTemplate.update("insert into bsth_c_line_versions(name, line, line_code, versions, start_date, create_date, update_date, remark,status, isupdate) " + | |
| 392 | + " values(?,?,?,?,?,?,?,?,?,?)", lVersion.getName(), lineId, lVersion.getLineCode() | |
| 393 | + , lVersion.getVersions(), lVersion.getStartDate(), lVersion.getCreateDate(), lVersion.getUpdateDate(), lVersion.getRemark(), lVersion.getStatus(), lVersion.getIsupdate()); | |
| 394 | + | |
| 395 | + if (extendsVersion != -1) { | |
| 396 | + //复制站点信息 | |
| 397 | + String sql = "SELECT t1.id AS route_id,t1.line,t1.directions,t1.station,t1.station_name,t1.station_route_code,t1.line_code,t1.station_code,t1.station_mark,t1.distances,t1.to_time,t2.id AS station_id,t2.db_type,t2.b_jwpoints,t2.g_lonx,t2.g_laty,t2.radius,ST_AsText(t2.g_polygon_grid) as g_polygon_grid,t2.shapes_type FROM bsth_c_ls_stationroute t1 LEFT JOIN bsth_c_station t2 ON t1.station_code = t2.station_cod where t1.destroy=0 and t1.line_code='" + lineCode + "' and t1.versions="+extendsVersion+" order by t1.directions, t1.station_route_code"; | |
| 398 | + List<CascadeSaveStation> cssList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(CascadeSaveStation.class)); | |
| 399 | + | |
| 400 | + //新的站点编码 | |
| 401 | + long sCode; | |
| 402 | + for (CascadeSaveStation ss : cssList) { | |
| 403 | + sCode = stationRepository.stationMaxId() + 1; | |
| 404 | + ss.setRouteId(null); | |
| 405 | + ss.setStationCode(sCode + ""); | |
| 406 | + ss.setStation((int) sCode); | |
| 407 | + } | |
| 408 | + //入库新版本的站点 和 路由 | |
| 409 | + batchInsertStation(cssList, maxVersion); | |
| 410 | + | |
| 411 | + //复制路段信息 | |
| 412 | + sql = "SELECT t1.id AS route_id,t1.line,t1.line_code,t1.directions,t1.section,t1.section_code,t1.sectionroute_code,t1.versions,t2.section_name,t2.croses_road,ST_AsText(t2.gsection_vector) as gsection_vector,t2.db_type,t2.speed_limit FROM bsth_c_ls_sectionroute t1 LEFT JOIN bsth_c_section t2 ON t1.section_code = t2.section_code WHERE t1.destroy = 0 AND t1.line_code = '"+lineCode+"' and t1.versions="+ extendsVersion +" ORDER BY t1.directions,t1.sectionroute_code"; | |
| 413 | + List<CascadeSaveRoad> csrList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(CascadeSaveRoad.class)); | |
| 414 | + //新的路段编码 | |
| 415 | + long cCode; | |
| 416 | + for(CascadeSaveRoad csr : csrList){ | |
| 417 | + cCode = sectionRepository.sectionMaxId() + 1; | |
| 418 | + csr.setRouteId(null); | |
| 419 | + csr.setSection((int) cCode); | |
| 420 | + csr.setSectionCode(cCode + ""); | |
| 421 | + } | |
| 422 | + //入库新版本的路段 和 路段路由 | |
| 423 | + batchInsertRoad(csrList, maxVersion); | |
| 424 | + } | |
| 425 | + | |
| 426 | + rs.put("newVersion", maxVersion); | |
| 427 | + rs.put("status", ResponseCode.SUCCESS); | |
| 428 | + } catch (Exception e) { | |
| 429 | + status.setRollbackOnly(); | |
| 430 | + logger.error("", e); | |
| 431 | + rs.put("status", ResponseCode.ERROR); | |
| 432 | + rs.put("msg", "服务器出现异常"); | |
| 420 | 433 | } |
| 421 | - //入库新版本的路段 和 路段路由 | |
| 422 | - batchInsertRoad(csrList, maxVersion); | |
| 434 | + return rs; | |
| 423 | 435 | } |
| 436 | + }); | |
| 424 | 437 | |
| 425 | - tran.commit(status); | |
| 426 | - rs.put("newVersion", maxVersion); | |
| 427 | - rs.put("status", ResponseCode.SUCCESS); | |
| 428 | - } catch (Exception e) { | |
| 429 | - tran.rollback(status); | |
| 430 | - logger.error("", e); | |
| 431 | - rs.put("status", ResponseCode.ERROR); | |
| 432 | - rs.put("msg", "服务器出现异常"); | |
| 433 | - } | |
| 434 | - return rs; | |
| 435 | 438 | } |
| 436 | 439 | |
| 437 | 440 | /** |
| ... | ... | @@ -444,19 +447,17 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 444 | 447 | public Map<String, Object> deleteLineVersion(String lineCode, int version) { |
| 445 | 448 | Map<String, Object> rs = new HashMap<>(); |
| 446 | 449 | |
| 447 | - //编程式事务 | |
| 448 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 449 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 450 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 451 | - TransactionStatus status = tran.getTransaction(def); | |
| 452 | - try{ | |
| 453 | - int enableVersion = jdbcTemplate.queryForObject("select versions from bsth_c_line_versions where line_code='"+lineCode+"' and `status`=1", Integer.class); | |
| 454 | - | |
| 455 | - if(enableVersion==version){ | |
| 456 | - rs.put("status", ResponseCode.ERROR); | |
| 457 | - rs.put("msg", "你不能删除当前正在启用的走向版本!"); | |
| 458 | - return rs; | |
| 459 | - } | |
| 450 | + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() { | |
| 451 | + @Override | |
| 452 | + public Map<String, Object> doInTransaction(TransactionStatus status) { | |
| 453 | + try{ | |
| 454 | + int enableVersion = jdbcTemplate.queryForObject("select versions from bsth_c_line_versions where line_code='"+lineCode+"' and `status`=1", Integer.class); | |
| 455 | + | |
| 456 | + if(enableVersion==version){ | |
| 457 | + rs.put("status", ResponseCode.ERROR); | |
| 458 | + rs.put("msg", "你不能删除当前正在启用的走向版本!"); | |
| 459 | + return rs; | |
| 460 | + } | |
| 460 | 461 | /*int versionCount = jdbcTemplate.queryForObject("select count(*) from bsth_c_line_versions where line_code='"+lineCode+"'", Integer.class); |
| 461 | 462 | if(versionCount == 1){ |
| 462 | 463 | rs.put("status", ResponseCode.ERROR); |
| ... | ... | @@ -472,27 +473,29 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 472 | 473 | |
| 473 | 474 | List<Integer> stationRemoves = jdbcTemplate.queryForList(sql, Integer.class);*/ |
| 474 | 475 | |
| 475 | - //删除站点路由 | |
| 476 | - String sql = "delete from bsth_c_ls_stationroute where line_code='"+lineCode+"' and versions=" + version; | |
| 477 | - jdbcTemplate.update(sql); | |
| 476 | + //删除站点路由 | |
| 477 | + String sql = "delete from bsth_c_ls_stationroute where line_code='"+lineCode+"' and versions=" + version; | |
| 478 | + jdbcTemplate.update(sql); | |
| 478 | 479 | |
| 479 | - //删除路段路由 | |
| 480 | - sql = "delete from bsth_c_ls_sectionroute where line_code='"+lineCode+"' and versions=" + version; | |
| 481 | - jdbcTemplate.update(sql); | |
| 480 | + //删除路段路由 | |
| 481 | + sql = "delete from bsth_c_ls_sectionroute where line_code='"+lineCode+"' and versions=" + version; | |
| 482 | + jdbcTemplate.update(sql); | |
| 482 | 483 | |
| 483 | - //删除版本信息 | |
| 484 | - sql = "delete from bsth_c_line_versions where line_code='"+lineCode+"' and versions=" + version; | |
| 485 | - jdbcTemplate.update(sql); | |
| 484 | + //删除版本信息 | |
| 485 | + sql = "delete from bsth_c_line_versions where line_code='"+lineCode+"' and versions=" + version; | |
| 486 | + jdbcTemplate.update(sql); | |
| 487 | + | |
| 488 | + rs.put("status", ResponseCode.SUCCESS); | |
| 489 | + }catch (Exception e){ | |
| 490 | + status.setRollbackOnly(); | |
| 491 | + logger.error("", e); | |
| 492 | + rs.put("status", ResponseCode.ERROR); | |
| 493 | + rs.put("msg", "服务器出现异常"); | |
| 494 | + } | |
| 495 | + return rs; | |
| 496 | + } | |
| 497 | + }); | |
| 486 | 498 | |
| 487 | - tran.commit(status); | |
| 488 | - rs.put("status", ResponseCode.SUCCESS); | |
| 489 | - }catch (Exception e){ | |
| 490 | - tran.rollback(status); | |
| 491 | - logger.error("", e); | |
| 492 | - rs.put("status", ResponseCode.ERROR); | |
| 493 | - rs.put("msg", "服务器出现异常"); | |
| 494 | - } | |
| 495 | - return rs; | |
| 496 | 499 | } |
| 497 | 500 | |
| 498 | 501 | /** |
| ... | ... | @@ -541,7 +544,7 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 541 | 544 | |
| 542 | 545 | /** |
| 543 | 546 | * 批量入库路段 |
| 544 | - * @param cssList | |
| 547 | + * @param csrList | |
| 545 | 548 | * @param version |
| 546 | 549 | */ |
| 547 | 550 | private void batchInsertRoad(final List<CascadeSaveRoad> csrList, final int version){ |
| ... | ... | @@ -659,145 +662,144 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 659 | 662 | public Map<String, Object> addNewStationRoute(String lineCode, int upDown, int versions, String stationName, Float lat, Float lng, int prevRouteId) { |
| 660 | 663 | Map<String, Object> rs = new HashMap<>(); |
| 661 | 664 | |
| 662 | - //编程式事务 | |
| 663 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 664 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 665 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 666 | - TransactionStatus status = tran.getTransaction(def); | |
| 667 | - try { | |
| 668 | - //根据线路编码,查询线路ID | |
| 669 | - int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class); | |
| 665 | + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() { | |
| 666 | + @Override | |
| 667 | + public Map<String, Object> doInTransaction(TransactionStatus status) { | |
| 668 | + try { | |
| 669 | + //根据线路编码,查询线路ID | |
| 670 | + int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class); | |
| 670 | 671 | |
| 671 | - String sql = "select * from bsth_c_ls_stationroute where line_code='" + lineCode + "' and line=" + lineId + " and directions=" + upDown + " and destroy=0 and versions=" + versions; | |
| 672 | - List<SaveStationRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveStationRouteDTO.class)); | |
| 672 | + String sql = "select * from bsth_c_ls_stationroute where line_code='" + lineCode + "' and line=" + lineId + " and directions=" + upDown + " and destroy=0 and versions=" + versions; | |
| 673 | + List<SaveStationRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveStationRouteDTO.class)); | |
| 673 | 674 | |
| 674 | - for (SaveStationRouteDTO s : routes) { | |
| 675 | - if (s.getStationName().equals(stationName)) { | |
| 675 | + for (SaveStationRouteDTO s : routes) { | |
| 676 | + if (s.getStationName().equals(stationName)) { | |
| 676 | 677 | |
| 678 | + rs.put("status", ResponseCode.ERROR); | |
| 679 | + rs.put("msg", "重复的站点路由名称!"); | |
| 680 | + return rs; | |
| 681 | + } | |
| 682 | + } | |
| 683 | + //按路由顺序排列 | |
| 684 | + Collections.sort(routes, new StationRouteComp()); | |
| 685 | + | |
| 686 | + //转WGS | |
| 687 | + TransGPS.Location wgsLoc = TransGPS.transformFromGCJToWGS(TransGPS.bd_decrypt(TransGPS.LocationMake(Double.parseDouble(String.valueOf(lng)), Double.parseDouble(String.valueOf(lat))))); | |
| 688 | + | |
| 689 | + //insert 站点 | |
| 690 | + long sCode = stationRepository.stationMaxId() + 1; | |
| 691 | + jdbcTemplate.update("insert into bsth_c_station(id, station_cod, station_name, db_type, b_jwpoints, g_lonx, g_laty, destroy, radius, shapes_type, versions) " + | |
| 692 | + " values(?,?,?,?,?,?,?,?,?,?,?)", sCode, sCode, stationName, "b", lng + " " + lat, wgsLoc.getLng(), wgsLoc.getLat(), 0, 88, "r", 1); | |
| 693 | + | |
| 694 | + | |
| 695 | + SaveStationRouteDTO sr; | |
| 696 | + int currentNo = -1, | |
| 697 | + no = 100, step = 100; | |
| 698 | + | |
| 699 | + if (prevRouteId == -1) { | |
| 700 | + //起点站 | |
| 701 | + currentNo = no; | |
| 702 | + no += step; | |
| 703 | + } | |
| 704 | + //重新排序路由 | |
| 705 | + for (int i = 0, size = routes.size(); i < size; i++) { | |
| 706 | + sr = routes.get(i); | |
| 707 | + sr.setStationRouteCode(no); | |
| 708 | + no += step; | |
| 709 | + if (sr.getId().intValue() == prevRouteId) { | |
| 710 | + currentNo = no; | |
| 711 | + no += step; | |
| 712 | + } | |
| 713 | + } | |
| 714 | + | |
| 715 | + SaveStationRouteDTO nsr = new SaveStationRouteDTO(); | |
| 716 | + nsr.setLine(lineId); | |
| 717 | + nsr.setLineCode(lineCode); | |
| 718 | + nsr.setDirections(upDown); | |
| 719 | + nsr.setVersions(versions); | |
| 720 | + nsr.setStationRouteCode(currentNo); | |
| 721 | + nsr.setStation(sCode); | |
| 722 | + nsr.setStationCode(sCode + ""); | |
| 723 | + nsr.setStationName(stationName); | |
| 724 | + nsr.setDistances(0d); | |
| 725 | + nsr.setToTime(0d); | |
| 726 | + Date d = new Date(); | |
| 727 | + nsr.setCreateDate(d); | |
| 728 | + nsr.setUpdateDate(d); | |
| 729 | + nsr.setDestroy(0); | |
| 730 | + if (prevRouteId == -1) | |
| 731 | + nsr.setStationMark("B"); | |
| 732 | + else if(routes.size()==1) | |
| 733 | + nsr.setStationMark("E"); | |
| 734 | + | |
| 735 | + //routes.add(sr); | |
| 736 | + | |
| 737 | + //重新标记mark | |
| 738 | + Collections.sort(routes, new StationRouteComp()); | |
| 739 | + for (int i = 0, size = routes.size(); i < size; i++) { | |
| 740 | + routes.get(i).setStationMark("Z"); | |
| 741 | + } | |
| 742 | + if(routes.size() > 0 && prevRouteId!=-1) | |
| 743 | + routes.get(0).setStationMark("B"); | |
| 744 | + if(routes.size() > 1) | |
| 745 | + routes.get(routes.size() - 1).setStationMark("E"); | |
| 746 | + | |
| 747 | + final List<SaveStationRouteDTO> saveList = routes; | |
| 748 | + //insert 新路由 (ID自增) | |
| 749 | + jdbcTemplate.update("insert into bsth_c_ls_stationroute(line, station, station_name, station_route_code, line_code, station_code, station_mark, distances, to_time, destroy, versions, create_date, update_date,directions) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)" | |
| 750 | + , nsr.getLine(), nsr.getStation(), nsr.getStationName(), nsr.getStationRouteCode(), nsr.getLineCode(), nsr.getStationCode(), nsr.getStationMark() | |
| 751 | + , nsr.getDistances(), nsr.getToTime(), nsr.getDestroy(), nsr.getVersions(), nsr.getCreateDate(), nsr.getUpdateDate(), nsr.getDirections()); | |
| 752 | + | |
| 753 | + // update 原路由 | |
| 754 | + jdbcTemplate.batchUpdate("update bsth_c_ls_stationroute set line=?,station=?,station_name=?,station_route_code=?," + | |
| 755 | + "line_code=?,station_code=?,station_mark=?,distances=?,to_time=?,destroy=?,versions=?,create_date=?,update_date=?,directions=?" + | |
| 756 | + " where id=?" | |
| 757 | + , new BatchPreparedStatementSetter() { | |
| 758 | + @Override | |
| 759 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 760 | + SaveStationRouteDTO sr = saveList.get(i); | |
| 761 | + ps.setInt(1, sr.getLine()); | |
| 762 | + ps.setLong(2, sr.getStation()); | |
| 763 | + ps.setString(3, sr.getStationName()); | |
| 764 | + ps.setInt(4, sr.getStationRouteCode()); | |
| 765 | + ps.setString(5, sr.getLineCode()); | |
| 766 | + ps.setString(6, sr.getStationCode()); | |
| 767 | + ps.setString(7, sr.getStationMark()); | |
| 768 | + ps.setDouble(8, sr.getDistances()); | |
| 769 | + ps.setDouble(9, sr.getToTime()); | |
| 770 | + ps.setInt(10, sr.getDestroy()); | |
| 771 | + ps.setInt(11, sr.getVersions()); | |
| 772 | + ps.setTimestamp(12, new java.sql.Timestamp(sr.getCreateDate().getTime())); | |
| 773 | + ps.setTimestamp(13, new java.sql.Timestamp(sr.getUpdateDate().getTime())); | |
| 774 | + ps.setInt(14, sr.getDirections()); | |
| 775 | + ps.setInt(15, sr.getId()); | |
| 776 | + } | |
| 777 | + | |
| 778 | + @Override | |
| 779 | + public int getBatchSize() { | |
| 780 | + return saveList.size(); | |
| 781 | + } | |
| 782 | + }); | |
| 783 | + | |
| 784 | + //写一条走向变更记录 | |
| 785 | + jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions); | |
| 786 | + | |
| 787 | + //返回更新之后的数据 | |
| 788 | + List<GeoStation> list = findByUpdown(lineCode, upDown, versions); | |
| 789 | + | |
| 790 | + rs.put("list", list); | |
| 791 | + rs.put("newStationRouteCode", currentNo); | |
| 792 | + rs.put("status", ResponseCode.SUCCESS); | |
| 793 | + } catch (Exception e) { | |
| 794 | + status.setRollbackOnly(); | |
| 795 | + logger.error("", e); | |
| 677 | 796 | rs.put("status", ResponseCode.ERROR); |
| 678 | - rs.put("msg", "重复的站点路由名称!"); | |
| 679 | - return rs; | |
| 797 | + rs.put("msg", "服务器出现异常"); | |
| 680 | 798 | } |
| 799 | + return rs; | |
| 681 | 800 | } |
| 682 | - //按路由顺序排列 | |
| 683 | - Collections.sort(routes, new StationRouteComp()); | |
| 684 | - | |
| 685 | - //转WGS | |
| 686 | - TransGPS.Location wgsLoc = TransGPS.transformFromGCJToWGS(TransGPS.bd_decrypt(TransGPS.LocationMake(Double.parseDouble(String.valueOf(lng)), Double.parseDouble(String.valueOf(lat))))); | |
| 687 | - | |
| 688 | - //insert 站点 | |
| 689 | - long sCode = stationRepository.stationMaxId() + 1; | |
| 690 | - jdbcTemplate.update("insert into bsth_c_station(id, station_cod, station_name, db_type, b_jwpoints, g_lonx, g_laty, destroy, radius, shapes_type, versions) " + | |
| 691 | - " values(?,?,?,?,?,?,?,?,?,?,?)", sCode, sCode, stationName, "b", lng + " " + lat, wgsLoc.getLng(), wgsLoc.getLat(), 0, 88, "r", 1); | |
| 692 | - | |
| 693 | - | |
| 694 | - SaveStationRouteDTO sr; | |
| 695 | - int currentNo = -1, | |
| 696 | - no = 100, step = 100; | |
| 697 | - | |
| 698 | - if (prevRouteId == -1) { | |
| 699 | - //起点站 | |
| 700 | - currentNo = no; | |
| 701 | - no += step; | |
| 702 | - } | |
| 703 | - //重新排序路由 | |
| 704 | - for (int i = 0, size = routes.size(); i < size; i++) { | |
| 705 | - sr = routes.get(i); | |
| 706 | - sr.setStationRouteCode(no); | |
| 707 | - no += step; | |
| 708 | - if (sr.getId().intValue() == prevRouteId) { | |
| 709 | - currentNo = no; | |
| 710 | - no += step; | |
| 711 | - } | |
| 712 | - } | |
| 713 | - | |
| 714 | - SaveStationRouteDTO nsr = new SaveStationRouteDTO(); | |
| 715 | - nsr.setLine(lineId); | |
| 716 | - nsr.setLineCode(lineCode); | |
| 717 | - nsr.setDirections(upDown); | |
| 718 | - nsr.setVersions(versions); | |
| 719 | - nsr.setStationRouteCode(currentNo); | |
| 720 | - nsr.setStation(sCode); | |
| 721 | - nsr.setStationCode(sCode + ""); | |
| 722 | - nsr.setStationName(stationName); | |
| 723 | - nsr.setDistances(0d); | |
| 724 | - nsr.setToTime(0d); | |
| 725 | - Date d = new Date(); | |
| 726 | - nsr.setCreateDate(d); | |
| 727 | - nsr.setUpdateDate(d); | |
| 728 | - nsr.setDestroy(0); | |
| 729 | - if (prevRouteId == -1) | |
| 730 | - nsr.setStationMark("B"); | |
| 731 | - else if(routes.size()==1) | |
| 732 | - nsr.setStationMark("E"); | |
| 733 | - | |
| 734 | - //routes.add(sr); | |
| 735 | - | |
| 736 | - //重新标记mark | |
| 737 | - Collections.sort(routes, new StationRouteComp()); | |
| 738 | - for (int i = 0, size = routes.size(); i < size; i++) { | |
| 739 | - routes.get(i).setStationMark("Z"); | |
| 740 | - } | |
| 741 | - if(routes.size() > 0 && prevRouteId!=-1) | |
| 742 | - routes.get(0).setStationMark("B"); | |
| 743 | - if(routes.size() > 1) | |
| 744 | - routes.get(routes.size() - 1).setStationMark("E"); | |
| 745 | - | |
| 746 | - final List<SaveStationRouteDTO> saveList = routes; | |
| 747 | - //insert 新路由 (ID自增) | |
| 748 | - jdbcTemplate.update("insert into bsth_c_ls_stationroute(line, station, station_name, station_route_code, line_code, station_code, station_mark, distances, to_time, destroy, versions, create_date, update_date,directions) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)" | |
| 749 | - , nsr.getLine(), nsr.getStation(), nsr.getStationName(), nsr.getStationRouteCode(), nsr.getLineCode(), nsr.getStationCode(), nsr.getStationMark() | |
| 750 | - , nsr.getDistances(), nsr.getToTime(), nsr.getDestroy(), nsr.getVersions(), nsr.getCreateDate(), nsr.getUpdateDate(), nsr.getDirections()); | |
| 751 | - | |
| 752 | - // update 原路由 | |
| 753 | - jdbcTemplate.batchUpdate("update bsth_c_ls_stationroute set line=?,station=?,station_name=?,station_route_code=?," + | |
| 754 | - "line_code=?,station_code=?,station_mark=?,distances=?,to_time=?,destroy=?,versions=?,create_date=?,update_date=?,directions=?" + | |
| 755 | - " where id=?" | |
| 756 | - , new BatchPreparedStatementSetter() { | |
| 757 | - @Override | |
| 758 | - public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 759 | - SaveStationRouteDTO sr = saveList.get(i); | |
| 760 | - ps.setInt(1, sr.getLine()); | |
| 761 | - ps.setLong(2, sr.getStation()); | |
| 762 | - ps.setString(3, sr.getStationName()); | |
| 763 | - ps.setInt(4, sr.getStationRouteCode()); | |
| 764 | - ps.setString(5, sr.getLineCode()); | |
| 765 | - ps.setString(6, sr.getStationCode()); | |
| 766 | - ps.setString(7, sr.getStationMark()); | |
| 767 | - ps.setDouble(8, sr.getDistances()); | |
| 768 | - ps.setDouble(9, sr.getToTime()); | |
| 769 | - ps.setInt(10, sr.getDestroy()); | |
| 770 | - ps.setInt(11, sr.getVersions()); | |
| 771 | - ps.setTimestamp(12, new java.sql.Timestamp(sr.getCreateDate().getTime())); | |
| 772 | - ps.setTimestamp(13, new java.sql.Timestamp(sr.getUpdateDate().getTime())); | |
| 773 | - ps.setInt(14, sr.getDirections()); | |
| 774 | - ps.setInt(15, sr.getId()); | |
| 775 | - } | |
| 776 | - | |
| 777 | - @Override | |
| 778 | - public int getBatchSize() { | |
| 779 | - return saveList.size(); | |
| 780 | - } | |
| 781 | - }); | |
| 782 | - | |
| 783 | - //写一条走向变更记录 | |
| 784 | - jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions); | |
| 785 | - | |
| 786 | - tran.commit(status); | |
| 787 | - | |
| 788 | - //返回更新之后的数据 | |
| 789 | - List<GeoStation> list = findByUpdown(lineCode, upDown, versions); | |
| 801 | + }); | |
| 790 | 802 | |
| 791 | - rs.put("list", list); | |
| 792 | - rs.put("newStationRouteCode", currentNo); | |
| 793 | - rs.put("status", ResponseCode.SUCCESS); | |
| 794 | - } catch (Exception e) { | |
| 795 | - tran.rollback(status); | |
| 796 | - logger.error("", e); | |
| 797 | - rs.put("status", ResponseCode.ERROR); | |
| 798 | - rs.put("msg", "服务器出现异常"); | |
| 799 | - } | |
| 800 | - return rs; | |
| 801 | 803 | } |
| 802 | 804 | |
| 803 | 805 | private List<GeoStation> findByUpdown(String lineCode, int upDown, int versions) { |
| ... | ... | @@ -827,87 +829,86 @@ public class GeoDataServiceImpl implements GeoDataService { |
| 827 | 829 | public Map<String, Object> destroyStation(GeoStation station) { |
| 828 | 830 | Map<String, Object> rs = new HashMap<>(); |
| 829 | 831 | |
| 830 | - //编程式事务 | |
| 831 | - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 832 | - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 833 | - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 834 | - TransactionStatus status = tran.getTransaction(def); | |
| 835 | - try { | |
| 836 | - String sql = "update bsth_c_ls_stationroute set destroy=1 where id=?"; | |
| 837 | - jdbcTemplate.update(sql, station.getId()); | |
| 838 | - | |
| 839 | - /** | |
| 840 | - * ########## 重新排序路由,标记mark ######### | |
| 841 | - */ | |
| 842 | - sql = "select * from bsth_c_ls_stationroute where line_code='" + station.getLineCode() + "' and directions=" + station.getDirections() + " and destroy=0 and versions=" + station.getVersions(); | |
| 843 | - List<SaveStationRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveStationRouteDTO.class)); | |
| 844 | - Collections.sort(routes, new StationRouteComp()); | |
| 845 | - | |
| 846 | - int no = 0, | |
| 847 | - step = 100; | |
| 848 | - SaveStationRouteDTO sr; | |
| 849 | - //重新排序路由 | |
| 850 | - for (int i = 0, size = routes.size(); i < size; i++) { | |
| 851 | - sr = routes.get(i); | |
| 852 | - sr.setStationRouteCode(no += step); | |
| 853 | - } | |
| 854 | - | |
| 855 | - for (int i = 0, size = routes.size(); i < size; i++) { | |
| 856 | - routes.get(i).setStationMark("Z"); | |
| 832 | + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() { | |
| 833 | + @Override | |
| 834 | + public Map<String, Object> doInTransaction(TransactionStatus status) { | |
| 835 | + try { | |
| 836 | + String sql = "update bsth_c_ls_stationroute set destroy=1 where id=?"; | |
| 837 | + jdbcTemplate.update(sql, station.getId()); | |
| 838 | + | |
| 839 | + /** | |
| 840 | + * ########## 重新排序路由,标记mark ######### | |
| 841 | + */ | |
| 842 | + sql = "select * from bsth_c_ls_stationroute where line_code='" + station.getLineCode() + "' and directions=" + station.getDirections() + " and destroy=0 and versions=" + station.getVersions(); | |
| 843 | + List<SaveStationRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveStationRouteDTO.class)); | |
| 844 | + Collections.sort(routes, new StationRouteComp()); | |
| 845 | + | |
| 846 | + int no = 0, | |
| 847 | + step = 100; | |
| 848 | + SaveStationRouteDTO sr; | |
| 849 | + //重新排序路由 | |
| 850 | + for (int i = 0, size = routes.size(); i < size; i++) { | |
| 851 | + sr = routes.get(i); | |
| 852 | + sr.setStationRouteCode(no += step); | |
| 853 | + } | |
| 854 | + | |
| 855 | + for (int i = 0, size = routes.size(); i < size; i++) { | |
| 856 | + routes.get(i).setStationMark("Z"); | |
| 857 | + } | |
| 858 | + if(routes.size() > 0) | |
| 859 | + routes.get(0).setStationMark("B"); | |
| 860 | + if(routes.size() > 1) | |
| 861 | + routes.get(routes.size() - 1).setStationMark("E"); | |
| 862 | + | |
| 863 | + final List<SaveStationRouteDTO> saveList = routes; | |
| 864 | + // update 原路由 | |
| 865 | + jdbcTemplate.batchUpdate("update bsth_c_ls_stationroute set line=?,station=?,station_name=?,station_route_code=?," + | |
| 866 | + "line_code=?,station_code=?,station_mark=?,distances=?,to_time=?,destroy=?,versions=?,create_date=?,update_date=?,directions=?" + | |
| 867 | + " where id=?" | |
| 868 | + , new BatchPreparedStatementSetter() { | |
| 869 | + @Override | |
| 870 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 871 | + SaveStationRouteDTO sr = saveList.get(i); | |
| 872 | + ps.setInt(1, sr.getLine()); | |
| 873 | + ps.setLong(2, sr.getStation()); | |
| 874 | + ps.setString(3, sr.getStationName()); | |
| 875 | + ps.setInt(4, sr.getStationRouteCode()); | |
| 876 | + ps.setString(5, sr.getLineCode()); | |
| 877 | + ps.setString(6, sr.getStationCode()); | |
| 878 | + ps.setString(7, sr.getStationMark()); | |
| 879 | + ps.setDouble(8, sr.getDistances()); | |
| 880 | + ps.setDouble(9, sr.getToTime()); | |
| 881 | + ps.setInt(10, sr.getDestroy()); | |
| 882 | + ps.setInt(11, sr.getVersions()); | |
| 883 | + ps.setTimestamp(12, new java.sql.Timestamp(sr.getCreateDate().getTime())); | |
| 884 | + ps.setTimestamp(13, new java.sql.Timestamp(sr.getUpdateDate().getTime())); | |
| 885 | + ps.setInt(14, sr.getDirections()); | |
| 886 | + ps.setInt(15, sr.getId()); | |
| 887 | + } | |
| 888 | + | |
| 889 | + @Override | |
| 890 | + public int getBatchSize() { | |
| 891 | + return saveList.size(); | |
| 892 | + } | |
| 893 | + }); | |
| 894 | + | |
| 895 | + //写一条走向变更记录 | |
| 896 | + jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), station.getLineCode(), station.getVersions()); | |
| 897 | + | |
| 898 | + //返回更新之后的数据 | |
| 899 | + List<GeoStation> list = findByUpdown(station.getLineCode(), station.getDirections(), station.getVersions()); | |
| 900 | + rs.put("list", list); | |
| 901 | + rs.put("status", ResponseCode.SUCCESS); | |
| 902 | + } catch (Exception e) { | |
| 903 | + status.setRollbackOnly(); | |
| 904 | + logger.error("", e); | |
| 905 | + rs.put("status", ResponseCode.ERROR); | |
| 906 | + rs.put("msg", "服务器出现异常"); | |
| 907 | + } | |
| 908 | + return rs; | |
| 857 | 909 | } |
| 858 | - if(routes.size() > 0) | |
| 859 | - routes.get(0).setStationMark("B"); | |
| 860 | - if(routes.size() > 1) | |
| 861 | - routes.get(routes.size() - 1).setStationMark("E"); | |
| 862 | - | |
| 863 | - final List<SaveStationRouteDTO> saveList = routes; | |
| 864 | - // update 原路由 | |
| 865 | - jdbcTemplate.batchUpdate("update bsth_c_ls_stationroute set line=?,station=?,station_name=?,station_route_code=?," + | |
| 866 | - "line_code=?,station_code=?,station_mark=?,distances=?,to_time=?,destroy=?,versions=?,create_date=?,update_date=?,directions=?" + | |
| 867 | - " where id=?" | |
| 868 | - , new BatchPreparedStatementSetter() { | |
| 869 | - @Override | |
| 870 | - public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 871 | - SaveStationRouteDTO sr = saveList.get(i); | |
| 872 | - ps.setInt(1, sr.getLine()); | |
| 873 | - ps.setLong(2, sr.getStation()); | |
| 874 | - ps.setString(3, sr.getStationName()); | |
| 875 | - ps.setInt(4, sr.getStationRouteCode()); | |
| 876 | - ps.setString(5, sr.getLineCode()); | |
| 877 | - ps.setString(6, sr.getStationCode()); | |
| 878 | - ps.setString(7, sr.getStationMark()); | |
| 879 | - ps.setDouble(8, sr.getDistances()); | |
| 880 | - ps.setDouble(9, sr.getToTime()); | |
| 881 | - ps.setInt(10, sr.getDestroy()); | |
| 882 | - ps.setInt(11, sr.getVersions()); | |
| 883 | - ps.setTimestamp(12, new java.sql.Timestamp(sr.getCreateDate().getTime())); | |
| 884 | - ps.setTimestamp(13, new java.sql.Timestamp(sr.getUpdateDate().getTime())); | |
| 885 | - ps.setInt(14, sr.getDirections()); | |
| 886 | - ps.setInt(15, sr.getId()); | |
| 887 | - } | |
| 888 | - | |
| 889 | - @Override | |
| 890 | - public int getBatchSize() { | |
| 891 | - return saveList.size(); | |
| 892 | - } | |
| 893 | - }); | |
| 894 | - | |
| 895 | - //写一条走向变更记录 | |
| 896 | - jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), station.getLineCode(), station.getVersions()); | |
| 897 | - | |
| 898 | - tran.commit(status); | |
| 910 | + }); | |
| 899 | 911 | |
| 900 | - //返回更新之后的数据 | |
| 901 | - List<GeoStation> list = findByUpdown(station.getLineCode(), station.getDirections(), station.getVersions()); | |
| 902 | - rs.put("list", list); | |
| 903 | - rs.put("status", ResponseCode.SUCCESS); | |
| 904 | - } catch (Exception e) { | |
| 905 | - tran.rollback(status); | |
| 906 | - logger.error("", e); | |
| 907 | - rs.put("status", ResponseCode.ERROR); | |
| 908 | - rs.put("msg", "服务器出现异常"); | |
| 909 | - } | |
| 910 | - return rs; | |
| 911 | 912 | } |
| 912 | 913 | |
| 913 | 914 | @Override | ... | ... |
src/main/resources/logback.xml
| ... | ... | @@ -9,8 +9,7 @@ |
| 9 | 9 | |
| 10 | 10 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 11 | 11 | <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> |
| 12 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level-%msg%n | |
| 13 | - </pattern> | |
| 12 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 14 | 13 | </layout> |
| 15 | 14 | </appender> |
| 16 | 15 | |
| ... | ... | @@ -31,8 +30,7 @@ |
| 31 | 30 | |
| 32 | 31 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 33 | 32 | <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> |
| 34 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level-%msg%n | |
| 35 | - </pattern> | |
| 33 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 36 | 34 | </layout> |
| 37 | 35 | </appender> |
| 38 | 36 | |
| ... | ... | @@ -50,8 +48,7 @@ |
| 50 | 48 | |
| 51 | 49 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 52 | 50 | <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> |
| 53 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level -%msg%n | |
| 54 | - </pattern> | |
| 51 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 55 | 52 | </layout> |
| 56 | 53 | </appender> |
| 57 | 54 | <logger name="com.bsth.filter.AccessLogFilter" level="INFO" |
| ... | ... | @@ -72,8 +69,7 @@ |
| 72 | 69 | </rollingPolicy> |
| 73 | 70 | |
| 74 | 71 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 75 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n | |
| 76 | - </pattern> | |
| 72 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 77 | 73 | </layout> |
| 78 | 74 | </appender> |
| 79 | 75 | <logger name="com.bsth.service.directive.DirectiveServiceImpl" |
| ... | ... | @@ -102,8 +98,7 @@ |
| 102 | 98 | </rollingPolicy> |
| 103 | 99 | |
| 104 | 100 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 105 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n | |
| 106 | - </pattern> | |
| 101 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 107 | 102 | </layout> |
| 108 | 103 | </appender> |
| 109 | 104 | <logger name="com.bsth.service.impl.TrafficManageServiceImpl" |
| ... | ... | @@ -124,8 +119,7 @@ |
| 124 | 119 | </rollingPolicy> |
| 125 | 120 | |
| 126 | 121 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 127 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n | |
| 128 | - </pattern> | |
| 122 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 129 | 123 | </layout> |
| 130 | 124 | </appender> |
| 131 | 125 | <!-- schedule 时刻表操作日志 --> |
| ... | ... | @@ -141,8 +135,7 @@ |
| 141 | 135 | </rollingPolicy> |
| 142 | 136 | |
| 143 | 137 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 144 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n | |
| 145 | - </pattern> | |
| 138 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 146 | 139 | </layout> |
| 147 | 140 | </appender> |
| 148 | 141 | <logger name="com.bsth.service.schedule.impl.TTInfoServiceImpl" |
| ... | ... | @@ -171,7 +164,7 @@ |
| 171 | 164 | <file>${LOG_BASE}/datasync/vehicle/vehicle-data-sync.${taskLogKey}.log</file> |
| 172 | 165 | <append>true</append> |
| 173 | 166 | <encoder charset="UTF-8"> |
| 174 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level-%msg%n</pattern> | |
| 167 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 175 | 168 | </encoder> |
| 176 | 169 | </appender> |
| 177 | 170 | </sift> |
| ... | ... | @@ -234,8 +227,7 @@ |
| 234 | 227 | </rollingPolicy> |
| 235 | 228 | |
| 236 | 229 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 237 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n | |
| 238 | - </pattern> | |
| 230 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 239 | 231 | </layout> |
| 240 | 232 | </appender> |
| 241 | 233 | <logger name="com.bsth.data.gpsdata_v2" |
| ... | ... | @@ -256,8 +248,7 @@ |
| 256 | 248 | </rollingPolicy> |
| 257 | 249 | |
| 258 | 250 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 259 | - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n | |
| 260 | - </pattern> | |
| 251 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 261 | 252 | </layout> |
| 262 | 253 | </appender> |
| 263 | 254 | <logger name="com.bsth.data.gpsdata.status_manager" |
| ... | ... | @@ -278,8 +269,7 @@ |
| 278 | 269 | </rollingPolicy> |
| 279 | 270 | |
| 280 | 271 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 281 | - <pattern>%d{MM-dd HH:mm:ss.SSS} %-5level -%msg%n | |
| 282 | - </pattern> | |
| 272 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 283 | 273 | </layout> |
| 284 | 274 | </appender> |
| 285 | 275 | <logger name="com.bsth.data.msg_queue.WebSocketPushQueue" |
| ... | ... | @@ -298,8 +288,7 @@ |
| 298 | 288 | </rollingPolicy> |
| 299 | 289 | |
| 300 | 290 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 301 | - <pattern>%d{MM-dd HH:mm:ss.SSS} %-5level -%msg%n | |
| 302 | - </pattern> | |
| 291 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 303 | 292 | </layout> |
| 304 | 293 | </appender> |
| 305 | 294 | <logger name="com.bsth.data.msg_queue.DirectivePushQueue" |
| ... | ... | @@ -325,8 +314,7 @@ |
| 325 | 314 | </rollingPolicy> |
| 326 | 315 | |
| 327 | 316 | <layout class="ch.qos.logback.classic.PatternLayout"> |
| 328 | - <pattern>%d{MM-dd HH:mm:ss.SSS} %-5level -%msg%n | |
| 329 | - </pattern> | |
| 317 | + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n</pattern> | |
| 330 | 318 | </layout> |
| 331 | 319 | </appender> |
| 332 | 320 | <logger name="com.bsth.data.schedule.thread.SchedulePstThread" | ... | ... |
src/main/resources/static/pages/home.html
| ... | ... | @@ -59,7 +59,7 @@ |
| 59 | 59 | } |
| 60 | 60 | </style> |
| 61 | 61 | <div class="system_change_log"> |
| 62 | - <h2 style="text-indent: 35px;margin: 10px 0 5px;">2023-07-31 更新说明 Changelog</h2> | |
| 62 | + <h2 style="text-indent: 35px;margin: 10px 0 5px;">2023-08-06 更新说明 Changelog</h2> | |
| 63 | 63 | <br><br> |
| 64 | 64 | <ul> |
| 65 | 65 | <li class="sub_title"><h6>线调</h6></li> | ... | ... |