Commit c1bc1070638b8328c6736f8107af5d9ad2631f05
1 parent
0fd7f578
update...
Showing
1 changed file
with
83 additions
and
3 deletions
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
| ... | ... | @@ -13,7 +13,6 @@ import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 13 | 13 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| 14 | 14 | import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; |
| 15 | 15 | import com.bsth.service.schedule.SchedulePlanInfoService; |
| 16 | -import com.bsth.util.BatchSaveUtils; | |
| 17 | 16 | import com.bsth.websocket.handler.SendUtils; |
| 18 | 17 | import com.google.common.base.Predicate; |
| 19 | 18 | import com.google.common.collect.ArrayListMultimap; |
| ... | ... | @@ -25,9 +24,16 @@ import org.slf4j.Logger; |
| 25 | 24 | import org.slf4j.LoggerFactory; |
| 26 | 25 | import org.springframework.beans.factory.annotation.Autowired; |
| 27 | 26 | import org.springframework.dao.DataIntegrityViolationException; |
| 27 | +import org.springframework.jdbc.core.BatchPreparedStatementSetter; | |
| 28 | 28 | import org.springframework.jdbc.core.JdbcTemplate; |
| 29 | +import org.springframework.jdbc.datasource.DataSourceTransactionManager; | |
| 29 | 30 | import org.springframework.stereotype.Component; |
| 31 | +import org.springframework.transaction.TransactionDefinition; | |
| 32 | +import org.springframework.transaction.TransactionStatus; | |
| 33 | +import org.springframework.transaction.support.DefaultTransactionDefinition; | |
| 30 | 34 | |
| 35 | +import java.sql.PreparedStatement; | |
| 36 | +import java.sql.SQLException; | |
| 31 | 37 | import java.text.ParseException; |
| 32 | 38 | import java.text.SimpleDateFormat; |
| 33 | 39 | import java.util.*; |
| ... | ... | @@ -381,7 +387,7 @@ public class DayOfSchedule { |
| 381 | 387 | * @Title: batchSave |
| 382 | 388 | * @Description: TODO(批量入库) |
| 383 | 389 | */ |
| 384 | - private void batchSave(List<ScheduleRealInfo> list) { | |
| 390 | + private void batchSave(final List<ScheduleRealInfo> list) { | |
| 385 | 391 | // 查询数据库最大ID |
| 386 | 392 | Long id = schRepository.getMaxId(); |
| 387 | 393 | if (null == id) |
| ... | ... | @@ -395,8 +401,82 @@ public class DayOfSchedule { |
| 395 | 401 | item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate())); |
| 396 | 402 | } |
| 397 | 403 | |
| 404 | + //编程式事务 | |
| 405 | + DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource()); | |
| 406 | + DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | |
| 407 | + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | |
| 408 | + TransactionStatus status = tran.getTransaction(def); | |
| 409 | + | |
| 410 | + try{ | |
| 411 | + //写入 | |
| 412 | + 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)" + | |
| 413 | + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() { | |
| 414 | + @Override | |
| 415 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | |
| 416 | + ScheduleRealInfo sch = list.get(i); | |
| 417 | + ps.setLong(1, sch.getId()); | |
| 418 | + ps.setString(2, sch.getBcType()); | |
| 419 | + ps.setInt(3, sch.getBcs()==null?0:sch.getBcs()); | |
| 420 | + ps.setInt(4, sch.getBcsj()==null?0:sch.getBcsj()); | |
| 421 | + ps.setString(5, sch.getClZbh()); | |
| 422 | + ps.setDate(6, new java.sql.Date(sch.getCreateDate().getTime())); | |
| 423 | + ps.setString(7, sch.getDfsj()); | |
| 424 | + ps.setInt(8, sch.getDirectiveState()); | |
| 425 | + ps.setInt(9, sch.getFcno()==null?0:sch.getFcno()); | |
| 426 | + ps.setString(10, sch.getFcsj()); | |
| 427 | + ps.setString(11, sch.getFcsjActual()); | |
| 428 | + ps.setString(12, sch.getjGh()); | |
| 429 | + ps.setString(13, sch.getjName()); | |
| 430 | + ps.setDouble(14, sch.getJhlc()); | |
| 431 | + ps.setString(15, sch.getLpName()); | |
| 432 | + ps.setString(16, sch.getQdzCode()); | |
| 433 | + ps.setString(17, sch.getQdzName()); | |
| 434 | + ps.setString(18, sch.getRealExecDate()); | |
| 435 | + ps.setString(19, sch.getRemarks()); | |
| 436 | + ps.setString(20, sch.getsGh()); | |
| 437 | + ps.setString(21, sch.getsName()); | |
| 438 | + ps.setDate(22, new java.sql.Date(sch.getScheduleDate().getTime())); | |
| 439 | + ps.setString(23, sch.getScheduleDateStr()); | |
| 440 | + ps.setBoolean(24, sch.isSflj()); | |
| 441 | + ps.setLong(25, sch.getSpId()); | |
| 442 | + ps.setInt(26, sch.getStatus()); | |
| 443 | + ps.setDate(27, new java.sql.Date(sch.getUpdateDate().getTime())); | |
| 444 | + ps.setString(28, sch.getXlBm()); | |
| 445 | + ps.setString(29, sch.getXlDir()); | |
| 446 | + ps.setString(30, sch.getXlName()); | |
| 447 | + ps.setString(31, sch.getZdsj()); | |
| 448 | + ps.setString(32, sch.getZdsjActual()); | |
| 449 | + ps.setString(33, sch.getZdzCode()); | |
| 450 | + ps.setString(34, sch.getZdzName()); | |
| 451 | + ps.setInt(35, sch.getCcno()==null?0:sch.getCcno()); | |
| 452 | + ps.setBoolean(36, sch.isDfAuto()); | |
| 453 | + ps.setString(37, sch.getFgsBm()); | |
| 454 | + ps.setString(38, sch.getFgsName()); | |
| 455 | + ps.setString(39, sch.getGsBm()); | |
| 456 | + ps.setString(40, sch.getGsName()); | |
| 457 | + ps.setBoolean(41, sch.isOnline()); | |
| 458 | + ps.setString(42, sch.getAdjustExps()); | |
| 459 | + ps.setBoolean(43, sch.isReissue()); | |
| 460 | + ps.setDouble(44, sch.getJhlcOrig()); | |
| 461 | + ps.setInt(45, sch.getSiginCompate()); | |
| 462 | + ps.setInt(46, sch.getDriftStatus()); | |
| 463 | + ps.setBoolean(47, sch.isCcService()); | |
| 464 | + ps.setString(48, sch.getMajorStationName()); | |
| 465 | + } | |
| 466 | + | |
| 467 | + @Override | |
| 468 | + public int getBatchSize() { | |
| 469 | + return list.size(); | |
| 470 | + } | |
| 471 | + }); | |
| 472 | + | |
| 473 | + tran.commit(status); | |
| 474 | + }catch (Exception e){ | |
| 475 | + tran.rollback(status); | |
| 476 | + logger.error("real schedule batchSave error...", e); | |
| 477 | + } | |
| 398 | 478 | // 入库 |
| 399 | - new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class); | |
| 479 | + //new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class); | |
| 400 | 480 | } |
| 401 | 481 | |
| 402 | 482 | public List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) { | ... | ... |