Commit ef59ccde1fb22ed39dad81c1dbdfaff48c5de898

Authored by 潘钊
1 parent 637544cf

update...

src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
@@ -23,9 +23,6 @@ import java.util.*; @@ -23,9 +23,6 @@ import java.util.*;
23 @RequestMapping("/realSchedule") 23 @RequestMapping("/realSchedule")
24 public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, Long> { 24 public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, Long> {
25 25
26 - /*@Autowired  
27 - GetSchedulePlanThread getSchedulePlanThread;*/  
28 -  
29 @Autowired 26 @Autowired
30 ScheduleRealInfoService scheduleRealInfoService; 27 ScheduleRealInfoService scheduleRealInfoService;
31 28
src/main/java/com/bsth/controller/realcontrol/anomalyCheckController.java
@@ -110,4 +110,14 @@ public class anomalyCheckController { @@ -110,4 +110,14 @@ public class anomalyCheckController {
110 dayOfSchedule.removeExecPlan(nbbm); 110 dayOfSchedule.removeExecPlan(nbbm);
111 return 1; 111 return 1;
112 } 112 }
  113 +
  114 + @RequestMapping(value = "/sch_re_calc_id_maps")
  115 + public int reCalcIdMaps(){
  116 + return dayOfSchedule.reCalcIdMaps();
  117 + }
  118 +
  119 + @RequestMapping(value = "/sch_size_string")
  120 + public String schSizeString(){
  121 + return dayOfSchedule.sizeString();
  122 + }
113 } 123 }
src/main/java/com/bsth/data/directive/DayOfDirectives.java
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Component; 15 import org.springframework.stereotype.Component;
16 16
17 import java.util.*; 17 import java.util.*;
  18 +import java.util.concurrent.ConcurrentHashMap;
18 19
19 /** 20 /**
20 * 21 *
@@ -52,8 +53,8 @@ public class DayOfDirectives { @@ -52,8 +53,8 @@ public class DayOfDirectives {
52 53
53 54
54 static{ 55 static{
55 - d60Map = new HashMap<>();  
56 - d64Map = new HashMap<>(); 56 + d60Map = new ConcurrentHashMap<>();
  57 + d64Map = new ConcurrentHashMap<>();
57 pstDirectives = new LinkedList<>(); 58 pstDirectives = new LinkedList<>();
58 } 59 }
59 60
src/main/java/com/bsth/data/directive/DirectivesPstThread.java
@@ -51,10 +51,6 @@ public class DirectivesPstThread extends Thread { @@ -51,10 +51,6 @@ public class DirectivesPstThread extends Thread {
51 logger.warn("save 指令,发现 deleted=true 的班次,id=" + sch.getId()); 51 logger.warn("save 指令,发现 deleted=true 的班次,id=" + sch.getId());
52 continue; 52 continue;
53 } 53 }
54 - if(dayOfSchedule.get(sch.getId()) == null){  
55 - logger.warn("班次:" + sch.getId() + "不存在了,调度指令放弃入库。");  
56 - continue;  
57 - }  
58 } 54 }
59 d60Repository.save(d60); 55 d60Repository.save(d60);
60 } 56 }
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
@@ -14,9 +14,7 @@ import com.bsth.entity.schedule.SchedulePlanInfo; @@ -14,9 +14,7 @@ import com.bsth.entity.schedule.SchedulePlanInfo;
14 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; 14 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
15 import com.bsth.service.schedule.SchedulePlanInfoService; 15 import com.bsth.service.schedule.SchedulePlanInfoService;
16 import com.bsth.websocket.handler.SendUtils; 16 import com.bsth.websocket.handler.SendUtils;
17 -import com.google.common.base.Predicate;  
18 import com.google.common.collect.ArrayListMultimap; 17 import com.google.common.collect.ArrayListMultimap;
19 -import com.google.common.collect.Collections2;  
20 import org.apache.commons.lang3.StringUtils; 18 import org.apache.commons.lang3.StringUtils;
21 import org.joda.time.format.DateTimeFormat; 19 import org.joda.time.format.DateTimeFormat;
22 import org.joda.time.format.DateTimeFormatter; 20 import org.joda.time.format.DateTimeFormatter;
@@ -37,6 +35,7 @@ import java.sql.SQLException; @@ -37,6 +35,7 @@ import java.sql.SQLException;
37 import java.text.ParseException; 35 import java.text.ParseException;
38 import java.text.SimpleDateFormat; 36 import java.text.SimpleDateFormat;
39 import java.util.*; 37 import java.util.*;
  38 +import java.util.concurrent.ConcurrentHashMap;
40 import java.util.concurrent.ConcurrentLinkedQueue; 39 import java.util.concurrent.ConcurrentLinkedQueue;
41 40
42 /** 41 /**
@@ -100,11 +99,11 @@ public class DayOfSchedule { @@ -100,11 +99,11 @@ public class DayOfSchedule {
100 nbbmScheduleMap = ArrayListMultimap.create(); 99 nbbmScheduleMap = ArrayListMultimap.create();
101 lpScheduleMap = ArrayListMultimap.create(); 100 lpScheduleMap = ArrayListMultimap.create();
102 101
103 - id2SchedulMap = new HashMap<>(); 102 + id2SchedulMap = new ConcurrentHashMap<>();
104 pstBuffer = new ConcurrentLinkedQueue<>(); 103 pstBuffer = new ConcurrentLinkedQueue<>();
105 schFCSJComparator = new ScheduleComparator.FCSJ(); 104 schFCSJComparator = new ScheduleComparator.FCSJ();
106 currSchDateMap = new HashMap<>(); 105 currSchDateMap = new HashMap<>();
107 - carExecutePlanMap = new HashMap<>(); 106 + carExecutePlanMap = new ConcurrentHashMap<>();
108 107
109 schedulePlanMap = new HashMap<>(); 108 schedulePlanMap = new HashMap<>();
110 } 109 }
@@ -266,7 +265,7 @@ public class DayOfSchedule { @@ -266,7 +265,7 @@ public class DayOfSchedule {
266 public void clearRAMData(String lineCode) { 265 public void clearRAMData(String lineCode) {
267 int count = 0; 266 int count = 0;
268 List<ScheduleRealInfo> remList = new ArrayList<>(); 267 List<ScheduleRealInfo> remList = new ArrayList<>();
269 - Collection<ScheduleRealInfo> all = id2SchedulMap.values(); 268 + Collection<ScheduleRealInfo> all = nbbmScheduleMap.values();
270 for (ScheduleRealInfo sch : all) { 269 for (ScheduleRealInfo sch : all) {
271 if (sch.getXlBm().equals(lineCode)) 270 if (sch.getXlBm().equals(lineCode))
272 remList.add(sch); 271 remList.add(sch);
@@ -512,7 +511,7 @@ public class DayOfSchedule { @@ -512,7 +511,7 @@ public class DayOfSchedule {
512 public List<ScheduleRealInfo> findByLineCode(String lineCode) { 511 public List<ScheduleRealInfo> findByLineCode(String lineCode) {
513 List<ScheduleRealInfo> rs = new ArrayList<>(); 512 List<ScheduleRealInfo> rs = new ArrayList<>();
514 513
515 - Collection<ScheduleRealInfo> schs = id2SchedulMap.values(); 514 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
516 for (ScheduleRealInfo sch : schs) { 515 for (ScheduleRealInfo sch : schs) {
517 if (sch.getXlBm().equals(lineCode)) 516 if (sch.getXlBm().equals(lineCode))
518 rs.add(sch); 517 rs.add(sch);
@@ -527,7 +526,7 @@ public class DayOfSchedule { @@ -527,7 +526,7 @@ public class DayOfSchedule {
527 public Map<String, Collection<ScheduleRealInfo>> findByLineCodes(List<String> lineList) { 526 public Map<String, Collection<ScheduleRealInfo>> findByLineCodes(List<String> lineList) {
528 ArrayListMultimap<String, ScheduleRealInfo> mMap = ArrayListMultimap.create(); 527 ArrayListMultimap<String, ScheduleRealInfo> mMap = ArrayListMultimap.create();
529 528
530 - Collection<ScheduleRealInfo> schs = id2SchedulMap.values(); 529 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
531 for (ScheduleRealInfo sch : schs) { 530 for (ScheduleRealInfo sch : schs) {
532 if (lineList.contains(sch.getXlBm())) { 531 if (lineList.contains(sch.getXlBm())) {
533 mMap.put(sch.getXlBm(), sch); 532 mMap.put(sch.getXlBm(), sch);
@@ -584,24 +583,6 @@ public class DayOfSchedule { @@ -584,24 +583,6 @@ public class DayOfSchedule {
584 return next(list, sch); 583 return next(list, sch);
585 } 584 }
586 585
587 - /**  
588 - * 下一个相同走向的班次  
589 - *  
590 - * @param sch  
591 - * @return  
592 - */  
593 - public ScheduleRealInfo nextSame(final ScheduleRealInfo sch) {  
594 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
595 - Collection<ScheduleRealInfo> subList = Collections2.filter(list, new Predicate<ScheduleRealInfo>() {  
596 -  
597 - @Override  
598 - public boolean apply(ScheduleRealInfo item) {  
599 - return item.getXlDir().equals(sch.getXlDir());  
600 - }  
601 - });  
602 - return next(subList, sch);  
603 - }  
604 -  
605 586
606 /** 587 /**
607 * 下一个班次 588 * 下一个班次
@@ -749,8 +730,7 @@ public class DayOfSchedule { @@ -749,8 +730,7 @@ public class DayOfSchedule {
749 .calcRealDate(sch) 730 .calcRealDate(sch)
750 .calcAllTimeByFcsj(sch); 731 .calcAllTimeByFcsj(sch);
751 732
752 - String nbbm = sch.getClZbh();  
753 - nbbmScheduleMap.put(nbbm, sch); 733 + nbbmScheduleMap.put(sch.getClZbh(), sch);
754 734
755 //主键索引 735 //主键索引
756 id2SchedulMap.put(sch.getId(), sch); 736 id2SchedulMap.put(sch.getId(), sch);
@@ -767,7 +747,6 @@ public class DayOfSchedule { @@ -767,7 +747,6 @@ public class DayOfSchedule {
767 } 747 }
768 748
769 public void delete(ScheduleRealInfo sch) { 749 public void delete(ScheduleRealInfo sch) {
770 - //ScheduleRealInfo sch = id2SchedulMap.get(id);  
771 if (!sch.isSflj()) 750 if (!sch.isSflj())
772 return; 751 return;
773 752
@@ -807,36 +786,6 @@ public class DayOfSchedule { @@ -807,36 +786,6 @@ public class DayOfSchedule {
807 return rs; 786 return rs;
808 } 787 }
809 788
810 - public boolean validTime(ScheduleRealInfo sch, Long ts) {  
811 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
812 - int ci = list.indexOf(sch);  
813 - ScheduleRealInfo prve, next;  
814 - if (ci > 0) {  
815 - //之前班次实际时间不能大于该时间  
816 - for (int i = ci - 1; i >= 0; i--) {  
817 - prve = list.get(i);  
818 - if (prve.getZdsjActualTime() != null && prve.getZdsjActualTime() > ts)  
819 - return false;  
820 -  
821 - if (prve.getFcsjActualTime() != null && prve.getFcsjActualTime() > ts)  
822 - return false;  
823 - }  
824 - }  
825 -  
826 - if (ci < list.size() - 1) {  
827 - //之后班次实际时间不能小于该时间  
828 - for (int i = ci + 1; i < list.size(); i++) {  
829 - next = list.get(i);  
830 - if (next.getFcsjActualTime() != null && next.getFcsjActualTime() < ts)  
831 - return false;  
832 -  
833 - if (next.getZdsjActualTime() != null && next.getZdsjActualTime() < ts)  
834 - return false;  
835 - }  
836 - }  
837 - return true;  
838 - }  
839 -  
840 public void save(ScheduleRealInfo sch) { 789 public void save(ScheduleRealInfo sch) {
841 sch.setUpdateDate(new Date()); 790 sch.setUpdateDate(new Date());
842 pstBuffer.add(sch); 791 pstBuffer.add(sch);
@@ -860,26 +809,6 @@ public class DayOfSchedule { @@ -860,26 +809,6 @@ public class DayOfSchedule {
860 return sch; 809 return sch;
861 } 810 }
862 811
863 - /**  
864 - * @Title: nextByBcType  
865 - * @Description: TODO(获取下一个指定班次类型的班次)  
866 - */  
867 - public ScheduleRealInfo nextByBcType(ScheduleRealInfo sch, String bcType) {  
868 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
869 - Collections.sort(list, schFCSJComparator);  
870 -  
871 - boolean flag = false;  
872 - for (ScheduleRealInfo temp : list) {  
873 -  
874 - if (flag && temp.getBcType().equals(bcType))  
875 - return temp;  
876 -  
877 - if (temp == sch) {  
878 - flag = true;  
879 - }  
880 - }  
881 - return null;  
882 - }  
883 812
884 /** 813 /**
885 * 搜索离当前时间最近的一个指定类型的班次 814 * 搜索离当前时间最近的一个指定类型的班次
@@ -917,7 +846,7 @@ public class DayOfSchedule { @@ -917,7 +846,7 @@ public class DayOfSchedule {
917 } 846 }
918 847
919 public Collection<ScheduleRealInfo> findAll() { 848 public Collection<ScheduleRealInfo> findAll() {
920 - return id2SchedulMap.values(); 849 + return nbbmScheduleMap.values();
921 } 850 }
922 851
923 public boolean addExecPlan(ScheduleRealInfo sch) { 852 public boolean addExecPlan(ScheduleRealInfo sch) {
@@ -949,6 +878,8 @@ public class DayOfSchedule { @@ -949,6 +878,8 @@ public class DayOfSchedule {
949 * @return 878 * @return
950 */ 879 */
951 public ScheduleRealInfo executeCurr(String nbbm) { 880 public ScheduleRealInfo executeCurr(String nbbm) {
  881 + if(StringUtils.isEmpty(nbbm))
  882 + return null;
952 return carExecutePlanMap.get(nbbm); 883 return carExecutePlanMap.get(nbbm);
953 } 884 }
954 885
@@ -984,12 +915,12 @@ public class DayOfSchedule { @@ -984,12 +915,12 @@ public class DayOfSchedule {
984 } 915 }
985 916
986 public void reCalcExecPlan(String nbbm) { 917 public void reCalcExecPlan(String nbbm) {
987 - //logger.info("reCalcExecPlan...: " + nbbm);  
988 List<ScheduleRealInfo> list = nbbmScheduleMap.get(nbbm); 918 List<ScheduleRealInfo> list = nbbmScheduleMap.get(nbbm);
989 Collections.sort(list, schFCSJComparator); 919 Collections.sort(list, schFCSJComparator);
990 920
991 ScheduleRealInfo sch = schAttrCalculator.calcCurrentExecSch(list); 921 ScheduleRealInfo sch = schAttrCalculator.calcCurrentExecSch(list);
992 - carExecutePlanMap.put(nbbm, sch); 922 + if(null != sch)
  923 + carExecutePlanMap.put(nbbm, sch);
993 } 924 }
994 925
995 /** 926 /**
@@ -1130,4 +1061,24 @@ public class DayOfSchedule { @@ -1130,4 +1061,24 @@ public class DayOfSchedule {
1130 } 1061 }
1131 return count; 1062 return count;
1132 } 1063 }
  1064 +
  1065 + /**
  1066 + * 重新计算ID对照map
  1067 + */
  1068 + public int reCalcIdMaps(){
  1069 + Collection<ScheduleRealInfo> all = findAll();
  1070 + Map<Long, ScheduleRealInfo> id2SchedulMapCopy = new ConcurrentHashMap<>();
  1071 +
  1072 + for(ScheduleRealInfo sch : all){
  1073 + id2SchedulMapCopy.put(sch.getId(), sch);
  1074 + }
  1075 +
  1076 + id2SchedulMap = id2SchedulMapCopy;
  1077 +
  1078 + return id2SchedulMap.size();
  1079 + }
  1080 +
  1081 + public String sizeString(){
  1082 + return id2SchedulMap.size() + "/" + nbbmScheduleMap.size();
  1083 + }
1133 } 1084 }
1134 \ No newline at end of file 1085 \ No newline at end of file
src/main/java/com/bsth/data/schedule/thread/SchedulePstThread.java
@@ -7,9 +7,18 @@ import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; @@ -7,9 +7,18 @@ import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
7 import org.slf4j.Logger; 7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
10 -import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;  
11 -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 10 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  11 +import org.springframework.jdbc.core.JdbcTemplate;
  12 +import org.springframework.jdbc.datasource.DataSourceTransactionManager;
12 import org.springframework.stereotype.Component; 13 import org.springframework.stereotype.Component;
  14 +import org.springframework.transaction.TransactionDefinition;
  15 +import org.springframework.transaction.TransactionStatus;
  16 +import org.springframework.transaction.support.DefaultTransactionDefinition;
  17 +
  18 +import java.sql.PreparedStatement;
  19 +import java.sql.SQLException;
  20 +import java.util.ArrayList;
  21 +import java.util.List;
13 22
14 /** 23 /**
15 * @author PanZhao 24 * @author PanZhao
@@ -24,18 +33,20 @@ public class SchedulePstThread extends Thread { @@ -24,18 +33,20 @@ public class SchedulePstThread extends Thread {
24 ScheduleRealInfoRepository scheduleRepository; 33 ScheduleRealInfoRepository scheduleRepository;
25 34
26 @Autowired 35 @Autowired
27 - NamedParameterJdbcTemplate jdbcTemplate; 36 + JdbcTemplate jdbcTemplate;
28 37
29 @Autowired 38 @Autowired
30 DayOfSchedule dayOfSchedule; 39 DayOfSchedule dayOfSchedule;
31 40
32 Logger logger = LoggerFactory.getLogger(this.getClass()); 41 Logger logger = LoggerFactory.getLogger(this.getClass());
33 42
  43 + static List<ScheduleRealInfo> saveList = new ArrayList<>();
  44 +
34 @Override 45 @Override
35 public void run() { 46 public void run() {
36 47
37 ScheduleRealInfo schedule; 48 ScheduleRealInfo schedule;
38 - for (int i = 0; i < 1000; i++) { 49 + for (int i = 0; i < 500; i++) {
39 schedule = DayOfSchedule.pstBuffer.poll(); 50 schedule = DayOfSchedule.pstBuffer.poll();
40 if (null == schedule) 51 if (null == schedule)
41 break; 52 break;
@@ -45,46 +56,106 @@ public class SchedulePstThread extends Thread { @@ -45,46 +56,106 @@ public class SchedulePstThread extends Thread {
45 continue; 56 continue;
46 } 57 }
47 58
48 - save(schedule); 59 + saveList.add(schedule);
49 } 60 }
  61 +
  62 + //写入数据库
  63 + save();
50 } 64 }
51 65
52 - /**  
53 - * 班次更新到数据库,不走jpa  
54 - *  
55 - * @param sch  
56 - */  
57 - public void save(ScheduleRealInfo sch) {  
58 - if (sch.getId() == null) {  
59 - logger.error("入库的班次没有ID, " + JSON.toJSONString(sch));  
60 - return;  
61 - }  
62 66
63 - if(sch.getSaveFailCount() > 5){  
64 - logger.error("入库失败上限, " + JSON.toJSONString(sch));  
65 - return;  
66 - } 67 + private void save(){
  68 + //记录同步数据
  69 + logger.info("real schedule update size: " + saveList.size());
  70 + logger.info(JSON.toJSONString(saveList));
  71 +
  72 + //批量入库
  73 + update2Db();
  74 +
  75 + //清空容器
  76 + saveList.clear();
  77 + }
  78 +
  79 + private void update2Db(){
  80 + final List<ScheduleRealInfo> pstList = saveList;
  81 + //编程式事务
  82 + DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());
  83 + DefaultTransactionDefinition def = new DefaultTransactionDefinition();
  84 + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
  85 + TransactionStatus status = tran.getTransaction(def);
  86 +
  87 + try{
  88 + //更新
  89 + jdbcTemplate.batchUpdate("update bsth_c_s_sp_info_real set bc_type=?,bcs=?,bcsj=?,cl_zbh=?,create_date=?" +
  90 + ",dfsj=?,directive_state=?,fcno=?,fcsj=?,fcsj_actual=?,j_gh=?,j_name=?,jhlc=?,lp_name=?,qdz_code=?" +
  91 + ",qdz_name=?,real_exec_date=?,remarks=?,s_gh=?,s_name=?,schedule_date=?,schedule_date_str=?,sflj=?" +
  92 + ",sp_id=?,status=?,update_date=?,xl_bm=?,xl_dir=?,xl_name=?,zdsj=?,zdsj_actual=?,zdz_code=?,zdz_name=?" +
  93 + ",ccno=?,df_auto=?,fgs_bm=?,fgs_name=?,gs_bm=?,gs_name=?,online=?,adjust_exps=?,reissue=?,jhlc_orig=?" +
  94 + ",sigin_compate=?,drift_status=?,cc_service=?,major_station_name=? where id=?", new BatchPreparedStatementSetter() {
  95 + @Override
  96 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  97 + ScheduleRealInfo sch = pstList.get(i);
  98 + ps.setString(1, sch.getBcType());
  99 + ps.setInt(2, sch.getBcs()==null?0:sch.getBcs());
  100 + ps.setInt(3, sch.getBcsj()==null?0:sch.getBcsj());
  101 + ps.setString(4, sch.getClZbh());
  102 + ps.setTimestamp(5, new java.sql.Timestamp(sch.getCreateDate().getTime()));
  103 + ps.setString(6, sch.getDfsj());
  104 + ps.setInt(7, sch.getDirectiveState());
  105 + ps.setInt(8, sch.getFcno()==null?0:sch.getFcno());
  106 + ps.setString(9, sch.getFcsj());
  107 + ps.setString(10, sch.getFcsjActual());
  108 + ps.setString(11, sch.getjGh());
  109 + ps.setString(12, sch.getjName());
  110 + ps.setDouble(13, sch.getJhlc());
  111 + ps.setString(14, sch.getLpName());
  112 + ps.setString(15, sch.getQdzCode());
  113 + ps.setString(16, sch.getQdzName());
  114 + ps.setString(17, sch.getRealExecDate());
  115 + ps.setString(18, sch.getRemarks());
  116 + ps.setString(19, sch.getsGh());
  117 + ps.setString(20, sch.getsName());
  118 + ps.setTimestamp(21, new java.sql.Timestamp(sch.getScheduleDate().getTime()));
  119 + ps.setString(22, sch.getScheduleDateStr());
  120 + ps.setBoolean(23, sch.isSflj());
  121 + ps.setLong(24, sch.getSpId());
  122 + ps.setInt(25, sch.getStatus());
  123 + ps.setTimestamp(26, new java.sql.Timestamp(sch.getUpdateDate().getTime()));
  124 + ps.setString(27, sch.getXlBm());
  125 + ps.setString(28, sch.getXlDir());
  126 + ps.setString(29, sch.getXlName());
  127 + ps.setString(30, sch.getZdsj());
  128 + ps.setString(31, sch.getZdsjActual());
  129 + ps.setString(32, sch.getZdzCode());
  130 + ps.setString(33, sch.getZdzName());
  131 + ps.setInt(34, sch.getCcno()==null?0:sch.getCcno());
  132 + ps.setBoolean(35, sch.isDfAuto());
  133 + ps.setString(36, sch.getFgsBm());
  134 + ps.setString(37, sch.getFgsName());
  135 + ps.setString(38, sch.getGsBm());
  136 + ps.setString(39, sch.getGsName());
  137 + ps.setBoolean(40, sch.isOnline());
  138 + ps.setString(41, sch.getAdjustExps());
  139 + ps.setBoolean(42, sch.isReissue());
  140 + ps.setDouble(43, sch.getJhlcOrig());
  141 + ps.setInt(44, sch.getSiginCompate());
  142 + ps.setInt(45, sch.getDriftStatus());
  143 + ps.setBoolean(46, sch.isCcService());
  144 + ps.setString(47, sch.getMajorStationName());
  145 +
  146 + ps.setLong(48, sch.getId());
  147 + }
  148 +
  149 + @Override
  150 + public int getBatchSize() {
  151 + return pstList.size();
  152 + }
  153 + });
67 154
68 - try {  
69 - String sql = "UPDATE bsth_c_s_sp_info_real" +  
70 - " SET adjust_exps=:adjustExps, bc_type=:bcType, bcs=:bcs, bcsj=:bcsj, ccno=:ccno, cl_zbh=:clZbh, df_auto=:dfAuto," +  
71 - " dfsj=:dfsj, directive_state=:directiveState, fcno=:fcno, fcsj=:fcsj, fcsj_actual=:fcsjActual, fgs_bm=:fgsBm, fgs_name=:fgsName, gs_bm=:gsBm, gs_name=:gsName," +  
72 - " j_gh=:jGh, j_name=:jName, jhlc=:jhlc, jhlc_orig=:jhlcOrig, lp_name=:lpName, ONLINE=:online, qdz_code=:qdzCode, qdz_name=:qdzName," +  
73 - " real_exec_date=:realExecDate, reissue=:reissue, remarks=:remarks, s_gh=:sGh, s_name=:sName, schedule_date=:scheduleDate," +  
74 - " schedule_date_str=:scheduleDateStr, sflj=:sflj, sp_id=:spId, STATUS=:status, update_date=:updateDate, xl_bm=:xlBm, xl_dir=:xlDir, xl_name=:xlName," +  
75 - " zdsj=:zdsj, zdsj_actual=:zdsjActual, zdz_code=:zdzCode, zdz_name=:zdzName" +  
76 - " WHERE " +  
77 - " id=:id";  
78 -  
79 - jdbcTemplate.update(sql, new BeanPropertySqlParameterSource(sch));  
80 - sch.setSaveFailCount(0);  
81 - } catch (Exception e) {  
82 - //下次入库再试  
83 - sch.setSaveFailCount(sch.getSaveFailCount()+1);  
84 - dayOfSchedule.save(sch);  
85 -  
86 - logger.error("班次 " + sch.getId() + "入库失败," + JSON.toJSONString(sch));  
87 - logger.error("", e); 155 + tran.commit(status);
  156 + }catch (Exception e){
  157 + tran.rollback(status);
  158 + logger.error("同步数据库失败," , e);
88 } 159 }
89 } 160 }
90 } 161 }
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
@@ -77,7 +77,7 @@ import org.springframework.jdbc.core.JdbcTemplate; @@ -77,7 +77,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
77 import org.springframework.jdbc.core.RowMapper; 77 import org.springframework.jdbc.core.RowMapper;
78 import org.springframework.stereotype.Service; 78 import org.springframework.stereotype.Service;
79 79
80 -import java.io.*; 80 +import java.io.File;
81 import java.sql.ResultSet; 81 import java.sql.ResultSet;
82 import java.sql.SQLException; 82 import java.sql.SQLException;
83 import java.text.DecimalFormat; 83 import java.text.DecimalFormat;
@@ -85,8 +85,6 @@ import java.text.ParseException; @@ -85,8 +85,6 @@ import java.text.ParseException;
85 import java.text.SimpleDateFormat; 85 import java.text.SimpleDateFormat;
86 import java.util.*; 86 import java.util.*;
87 import java.util.regex.Pattern; 87 import java.util.regex.Pattern;
88 -import java.util.zip.ZipEntry;  
89 -import java.util.zip.ZipOutputStream;  
90 88
91 @Service 89 @Service
92 public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInfo, Long> 90 public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInfo, Long>
@@ -3346,6 +3344,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -3346,6 +3344,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
3346 if("major".equals(bcType)){ 3344 if("major".equals(bcType)){
3347 sch.setMajorStationName(majorStationName); 3345 sch.setMajorStationName(majorStationName);
3348 } 3346 }
  3347 +
  3348 + dayOfSchedule.save(sch);
3349 } 3349 }
3350 } catch (Exception e) { 3350 } catch (Exception e) {
3351 logger.error("", e); 3351 logger.error("", e);
src/main/resources/logback.xml
@@ -250,6 +250,29 @@ @@ -250,6 +250,29 @@
250 <!--<appender-ref ref="STDOUT" />--> 250 <!--<appender-ref ref="STDOUT" />-->
251 <!--</logger>--> 251 <!--</logger>-->
252 252
  253 + <!-- 实际排班数据库更新日志 -->
  254 + <!-- 消息队列纪录 -->
  255 + <appender name="REAL_SCHEDULE_UPDATE"
  256 + class="ch.qos.logback.core.rolling.RollingFileAppender">
  257 + <file>${LOG_BASE}/real_sch_db/update.log</file>
  258 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  259 + <fileNamePattern>${LOG_BASE}/real_sch_db/update-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  260 + <timeBasedFileNamingAndTriggeringPolicy
  261 + class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  262 + <maxFileSize>100MB</maxFileSize>
  263 + </timeBasedFileNamingAndTriggeringPolicy>
  264 + </rollingPolicy>
  265 +
  266 + <layout class="ch.qos.logback.classic.PatternLayout">
  267 + <pattern>%d{MM-dd HH:mm:ss.SSS} %-5level -%msg%n
  268 + </pattern>
  269 + </layout>
  270 + </appender>
  271 + <logger name="com.bsth.data.schedule.thread.SchedulePstThread"
  272 + level="INFO" additivity="false">
  273 + <appender-ref ref="REAL_SCHEDULE_UPDATE" />
  274 + </logger>
  275 +
253 <!--JdbcTemplate的日志输出器 --> 276 <!--JdbcTemplate的日志输出器 -->
254 <logger name="org.springframework.jdbc.core.StatementCreatorUtils" 277 <logger name="org.springframework.jdbc.core.StatementCreatorUtils"
255 additivity="false" level="INFO"> 278 additivity="false" level="INFO">