Commit bf72abb60cc0daf2ae4d58073e4ac0c2d926cec3

Authored by 潘钊
1 parent 6d4822f7

多配置文件

src/main/java/com/bsth/StartCommand.java
... ... @@ -4,6 +4,7 @@ package com.bsth;
4 4 import com.bsth.security.SecurityMetadataSourceService;
5 5 import com.bsth.service.realcontrol.buffer.GetSchedulePlanThread;
6 6 import com.bsth.service.realcontrol.buffer.SchedulePersistenceThread;
  7 +import com.bsth.util.DateUtils;
7 8 import com.bsth.vehicle.common.CommonRefreshThread;
8 9 import com.bsth.vehicle.directive.thread.DirectivePersistenceThread;
9 10 import com.bsth.vehicle.directive.thread.FirstScheduleIssuedThread;
... ... @@ -63,13 +64,15 @@ public class StartCommand implements CommandLineRunner{
63 64 * GPS实时数据更新 线程
64 65 * 每8秒和网关HTTP接口同步一次
65 66 */
66   - //scheduler.scheduleWithFixedDelay(gpsRefreshThread, 0, 8, TimeUnit.SECONDS);
  67 + scheduler.scheduleWithFixedDelay(gpsRefreshThread, 0, 8, TimeUnit.SECONDS);
67 68  
68 69 /**
69 70 * 每天 0点 抓取当天实际排班
70 71 */
  72 + //启动时先run一次
  73 + getSchedulePlanThread.start();
71 74 scheduler.scheduleAtFixedRate(getSchedulePlanThread
72   - , 0//DateUtils.getTimesnight() + 5 - System.currentTimeMillis() / 1000
  75 + , DateUtils.getTimesnight() + 5 - System.currentTimeMillis() / 1000
73 76 , 60 * 60 * 24, TimeUnit.SECONDS);
74 77  
75 78 /**
... ... @@ -106,7 +109,7 @@ public class StartCommand implements CommandLineRunner{
106 109 * 还车线程(2分钟运行一次)
107 110 * 将借出的车刷回原线路
108 111 */
109   - //scheduler.scheduleWithFixedDelay(revertLineThread, 60 , 60 * 2 , TimeUnit.SECONDS);
  112 + scheduler.scheduleWithFixedDelay(revertLineThread, 60 , 60 * 2 , TimeUnit.SECONDS);
110 113 } catch (Exception e) {
111 114 e.printStackTrace();
112 115 }
... ...
src/main/java/com/bsth/entity/realcontrol/ScheduleRealInfo.java
... ... @@ -18,6 +18,9 @@ public class ScheduleRealInfo {
18 18 @Id
19 19 @GeneratedValue
20 20 private Long id;
  21 +
  22 + /** 计划ID */
  23 + private Long spId;
21 24  
22 25 /** 排班计划日期 */
23 26 private Date scheduleDate;
... ... @@ -141,10 +144,10 @@ public class ScheduleRealInfo {
141 144 private Integer directiveState = -1;
142 145  
143 146 /** 起点站计划到达时间 */
144   - private String qdzArrDateJH;
  147 + private String qdzArrDatejh;
145 148  
146 149 /** 起点站实际到达时间 */
147   - private String qdzArrDateSJ;
  150 + private String qdzArrDatesj;
148 151  
149 152 public void addRemarks(String remark){
150 153 String newRem = this.getRemarks();
... ... @@ -500,8 +503,15 @@ public class ScheduleRealInfo {
500 503 this.setDfsj(this.getFcsj());
501 504 //发车时间戳
502 505 this.setFcsjT(sdfyyyyMMddHHmm.parse(sdfyyyyMMdd.format(this.scheduleDate) + " " + this.getFcsj()).getTime());
503   - //待发时间
  506 + //待发时间
504 507 this.setDfsjT(this.getFcsjT());
  508 +
  509 + //计划终点时间
  510 + if(this.getBcsj() != null){
  511 + Date zdDate = new Date(this.getFcsjT() + (this.getBcsj() * 60 * 1000));
  512 + this.setZdsjT(zdDate.getTime());
  513 + this.setZdsj(sdfHHmm.format(zdDate));
  514 + }
505 515 }catch(Exception e){
506 516 e.printStackTrace();
507 517 }
... ... @@ -521,19 +531,19 @@ public class ScheduleRealInfo {
521 531 }
522 532  
523 533 public String getQdzArrDateJH() {
524   - return qdzArrDateJH;
  534 + return qdzArrDatejh;
525 535 }
526 536  
527 537 public void setQdzArrDateJH(String qdzArrDateJH) {
528   - this.qdzArrDateJH = qdzArrDateJH;
  538 + this.qdzArrDatejh = qdzArrDateJH;
529 539 }
530 540  
531 541 public String getQdzArrDateSJ() {
532   - return qdzArrDateSJ;
  542 + return qdzArrDatesj;
533 543 }
534 544  
535 545 public void setQdzArrDateSJ(String qdzArrDateSJ) {
536   - this.qdzArrDateSJ = qdzArrDateSJ;
  546 + this.qdzArrDatesj = qdzArrDateSJ;
537 547 }
538 548  
539 549 public boolean isSflj() {
... ... @@ -588,5 +598,12 @@ public class ScheduleRealInfo {
588 598 e.printStackTrace();
589 599 }
590 600 }
591   -
  601 +
  602 + public Long getSpId() {
  603 + return spId;
  604 + }
  605 +
  606 + public void setSpId(Long spId) {
  607 + this.spId = spId;
  608 + }
592 609 }
... ...
src/main/java/com/bsth/entity/schedule/SchedulePlanInfo.java
... ... @@ -135,11 +135,11 @@ public class SchedulePlanInfo {
135 135  
136 136  
137 137 @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
138   - @JoinTable(
  138 +/* @JoinTable(
139 139 name = "bsth_c_s_sp_r_info",
140 140 joinColumns = @JoinColumn(name = "sp_info_id"),
141 141 inverseJoinColumns = @JoinColumn(name = "sp_id")
142   - )
  142 + )*/
143 143 private SchedulePlan schedulePlan;
144 144  
145 145 public SchedulePlanInfo() {}
... ...
src/main/java/com/bsth/repository/realcontrol/ScheduleRealInfoRepository.java
1 1 package com.bsth.repository.realcontrol;
2 2  
  3 +import java.util.Date;
3 4 import java.util.List;
4 5 import java.util.Map;
5 6  
... ... @@ -34,4 +35,13 @@ public interface ScheduleRealInfoRepository extends BaseRepository<ScheduleRealI
34 35  
35 36 @Query(value="select s from ScheduleRealInfo s where s.xlName = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 and s.clZbh like ?3")
36 37 List<ScheduleRealInfo> historyMessage(String line,String date,String code);
  38 +
  39 + @Query(value = "select max(id) from ScheduleRealInfo")
  40 + Long getMaxId();
  41 +
  42 + @Query(value = "select count(*) from ScheduleRealInfo s where s.scheduleDate = ?1")
  43 + int countByDate(Date date);
  44 +
  45 + @Query(value = "select s from ScheduleRealInfo s where s.scheduleDate = ?1")
  46 + List<ScheduleRealInfo> findByDate(Date date);
37 47 }
... ...
src/main/java/com/bsth/service/realcontrol/buffer/GetSchedulePlanThread.java
... ... @@ -36,29 +36,39 @@ public class GetSchedulePlanThread extends Thread{
36 36 @Autowired
37 37 ScheduleRealInfoRepository scheduleRealInfoRepository;
38 38  
39   - SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  39 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
40 40  
41 41 @Override
42 42 public void run() {
43 43 try{
  44 + List<ScheduleRealInfo> realList = null;
44 45 String dateStr = /*sdf.format(new Date())*/"2016-06-01";
45   - List<SchedulePlanInfo> list = schedulePlanInfoRepository.findByDate(dateStr);
46   -
47   - //实际排班计划
48   - List<ScheduleRealInfo> realList = JSONArray.parseArray(JSON.toJSONString(list), ScheduleRealInfo.class);
49   -
50   - Date zdDate;
51   - for(ScheduleRealInfo item : realList){
52   - item.syncTime();
53   - //计划终点时间
54   - if(item.getBcsj() != null){
55   - zdDate = new Date(item.getFcsjT() + (item.getBcsj() * 60 * 1000));
56   - item.setZdsjT(zdDate.getTime());
57   - item.setZdsj(sdfHHmm.format(zdDate));
  46 + Date cDate = sdfyyyyMMdd.parse(dateStr);
  47 + //查询数据库是否有今日排班
  48 + int size = scheduleRealInfoRepository.countByDate(cDate);
  49 + if(size > 0){
  50 + //从数据库恢复当日排班
  51 + realList = scheduleRealInfoRepository.findByDate(cDate);
  52 + }
  53 + else{
  54 + List<SchedulePlanInfo> list = schedulePlanInfoRepository.findByDate(dateStr);
  55 +
  56 + //实际排班计划
  57 + realList = JSONArray.parseArray(JSON.toJSONString(list), ScheduleRealInfo.class);
  58 + //查询数据库最大ID
  59 + Long id = scheduleRealInfoRepository.getMaxId();
  60 + if(null == id)
  61 + id = 0L;
  62 + id ++;
  63 +
  64 + for(ScheduleRealInfo item : realList){
  65 + item.setSpId(item.getId());
  66 + item.setId(id ++);//设置ID
58 67 }
  68 + //入库
  69 + new BatchSaveUtils<ScheduleRealInfo>().saveList(realList, ScheduleRealInfo.class);
59 70 }
60 71  
61   - //new BatchSaveUtils<ScheduleRealInfo>().saveList(realList, ScheduleRealInfo.class);
62 72 //写入缓存
63 73 ScheduleBuffer.init(realList);
64 74  
... ...
src/main/java/com/bsth/service/realcontrol/buffer/ScheduleBuffer.java
... ... @@ -77,6 +77,11 @@ public class ScheduleBuffer {
77 77 public static int init(List<ScheduleRealInfo> list){
78 78  
79 79 try{
  80 + //计算时间戳
  81 + for(ScheduleRealInfo schedul : list){
  82 + schedul.syncTime();
  83 + }
  84 +
80 85 //发车时间排序
81 86 Collections.sort(list, scheduleComparator);
82 87  
... ...
src/main/java/com/bsth/util/BatchSaveUtils.java
... ... @@ -36,11 +36,10 @@ public class BatchSaveUtils&lt;T&gt; {
36 36 Logger logger = LoggerFactory.getLogger(this.getClass());
37 37  
38 38 static {
39   - Tools t = new Tools("application.properties");
40   - driver = t.getValue("spring.datasource.driver-class-name");
41   - url = t.getValue("spring.datasource.url");
42   - uname = t.getValue("spring.datasource.username");
43   - pwd = t.getValue("spring.datasource.password");
  39 + driver = ConfigUtil.get("spring.datasource.driver-class-name");
  40 + url = ConfigUtil.get("spring.datasource.url");
  41 + uname = ConfigUtil.get("spring.datasource.username");
  42 + pwd = ConfigUtil.get("spring.datasource.password");
44 43 }
45 44  
46 45 /**
... ...
src/main/java/com/bsth/util/ConfigUtil.java 0 → 100644
  1 +package com.bsth.util;
  2 +
  3 +public class ConfigUtil {
  4 +
  5 + static Tools tools;
  6 +
  7 + static{
  8 + tools = new Tools("application.properties");
  9 + String active = tools.getValue("spring.profiles.active");
  10 + tools = new Tools("application-"+active+".properties");
  11 + }
  12 +
  13 + public static String get(String key){
  14 + return tools.getValue(key);
  15 + }
  16 +}
... ...
src/main/java/com/bsth/vehicle/directive/Consts.java
1 1 package com.bsth.vehicle.directive;
2 2  
3   -import com.bsth.util.Tools;
4 3  
5 4 public class Consts {
6 5  
7   - static Tools tools = new Tools("application.properties");
8   -
9 6 /**
10 7 * 调度指令 -多营运状态 [0][0]上行营运 [0][1]上行非营运 [1][0]下行营运 [1][1]下行非营运
11 8 */
12 9 public static final int[][] SERVICE_STATE = { { 0, 0x02000000 }, { 0x10000000, 0x12000000 } };
13 10  
14   - /**
15   - * 消息下发地址
16   - */
17   - public static final String SEND_DIRECTIVE_URL = tools.getValue("http.send.directive");
18 11 }
... ...
src/main/java/com/bsth/vehicle/directive/util/HttpUtils.java
... ... @@ -13,7 +13,7 @@ import org.slf4j.Logger;
13 13 import org.slf4j.LoggerFactory;
14 14  
15 15 import com.alibaba.fastjson.JSONObject;
16   -import com.bsth.vehicle.directive.Consts;
  16 +import com.bsth.util.ConfigUtil;
17 17  
18 18 /**
19 19 *
... ... @@ -27,6 +27,12 @@ public class HttpUtils {
27 27  
28 28 static Logger logger = LoggerFactory.getLogger(HttpUtils.class);
29 29  
  30 + static String url;
  31 +
  32 + static{
  33 + url = ConfigUtil.get("http.send.directive");
  34 + }
  35 +
30 36 public static int postJson(String jsonStr){
31 37 logger.info("send : " + jsonStr);
32 38  
... ... @@ -40,7 +46,7 @@ public class HttpUtils {
40 46 .setConnectTimeout(3000).setConnectionRequestTimeout(1000)
41 47 .setSocketTimeout(3000).build();
42 48  
43   - HttpPost post = new HttpPost(Consts.SEND_DIRECTIVE_URL);
  49 + HttpPost post = new HttpPost(url);
44 50  
45 51 post.setConfig(requestConfig);
46 52  
... ...
src/main/java/com/bsth/vehicle/gpsdata/GpsRefreshThread.java
... ... @@ -19,7 +19,7 @@ import org.springframework.stereotype.Component;
19 19  
20 20 import com.alibaba.fastjson.JSON;
21 21 import com.alibaba.fastjson.JSONObject;
22   -import com.bsth.util.Tools;
  22 +import com.bsth.util.ConfigUtil;
23 23 import com.bsth.vehicle.gpsdata.buffer.GpsRealDataBuffer;
24 24 import com.bsth.vehicle.gpsdata.entity.GpsRealData;
25 25 import com.google.common.collect.ImmutableMap;
... ... @@ -42,8 +42,7 @@ public class GpsRefreshThread extends Thread{
42 42  
43 43  
44 44 public GpsRefreshThread() {
45   - Tools t = new Tools("application.properties");
46   - url = t.getValue("http.gps.real.url");
  45 + url = ConfigUtil.get("http.gps.real.url");
47 46 }
48 47  
49 48 @Autowired
... ...
src/main/resources/application-dev.properties 0 → 100644
  1 +server.port=9088
  2 +management.port= 9001
  3 +management.address= 127.0.0.1
  4 +
  5 +spring.jpa.hibernate.ddl-auto= update
  6 +spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
  7 +#DATABASE
  8 +spring.jpa.database= MYSQL
  9 +spring.jpa.show-sql= true
  10 +spring.datasource.driver-class-name= com.mysql.jdbc.Driver
  11 +spring.datasource.url= jdbc:mysql://192.168.168.201:3306/control
  12 +spring.datasource.username= root
  13 +spring.datasource.password= 123456
  14 +#DATASOURCE
  15 +spring.datasource.max-active=100
  16 +spring.datasource.max-idle=8
  17 +spring.datasource.min-idle=8
  18 +spring.datasource.initial-size=5
  19 +
  20 +spring.datasource.test-on-borrow=true
  21 +spring.datasource.test-on-connect=true
  22 +spring.datasource.test-on-return=true
  23 +spring.datasource.test-while-idle=true
  24 +spring.datasource.validation-query=select 1
  25 +
  26 +##
  27 +#222.66.0.204:5555
  28 +##\u5B9E\u65F6gps
  29 +http.gps.real.url= http://192.168.168.192:8080/transport_server/rtgps/
  30 +##\u6D88\u606F\u4E0B\u53D1
  31 +http.send.directive = http://192.168.168.192:8080/transport_server/message/
... ...
src/main/resources/application-prod.properties 0 → 100644
  1 +server.port=9088
  2 +management.port= 9001
  3 +management.address= 127.0.0.1
  4 +
  5 +spring.jpa.hibernate.ddl-auto= update
  6 +spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
  7 +#DATABASE
  8 +spring.jpa.database= MYSQL
  9 +spring.jpa.show-sql= true
  10 +spring.datasource.driver-class-name= com.mysql.jdbc.Driver
  11 +spring.datasource.url= jdbc:mysql://192.168.168.171:3306/control
  12 +spring.datasource.username= root
  13 +spring.datasource.password= root2jsp
  14 +#DATASOURCE
  15 +spring.datasource.max-active=100
  16 +spring.datasource.max-idle=8
  17 +spring.datasource.min-idle=8
  18 +spring.datasource.initial-size=5
  19 +
  20 +spring.datasource.test-on-borrow=true
  21 +spring.datasource.test-on-connect=true
  22 +spring.datasource.test-on-return=true
  23 +spring.datasource.test-while-idle=true
  24 +spring.datasource.validation-query=select 1
  25 +
  26 +##
  27 +#222.66.0.204:5555
  28 +##\u5B9E\u65F6gps
  29 +http.gps.real.url= http://192.168.168.171:8080/transport_server/rtgps/
  30 +##\u6D88\u606F\u4E0B\u53D1
  31 +http.send.directive = http://192.168.168.171:8080/transport_server/message/
... ...
src/main/resources/application.properties
1   -server.port=9088
2   -management.port= 9001
3   -management.address= 127.0.0.1
4   -
5   -spring.jpa.hibernate.ddl-auto= update
6   -spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
7   -
8   -#DATABASE
9   -spring.jpa.database= MYSQL
10   -spring.jpa.show-sql= true
11   -spring.datasource.driver-class-name= com.mysql.jdbc.Driver
12   -spring.datasource.url= jdbc:mysql://192.168.168.201:3306/control
13   -spring.datasource.username= root
14   -spring.datasource.password= 123456
15   -
16   -#DATASOURCE
17   -spring.datasource.max-active=100
18   -spring.datasource.max-idle=8
19   -spring.datasource.min-idle=8
20   -spring.datasource.initial-size=5
21   -
22   -spring.datasource.test-on-borrow=true
23   -spring.datasource.test-on-connect=true
24   -spring.datasource.test-on-return=true
25   -spring.datasource.test-while-idle=true
26   -spring.datasource.validation-query=select 1
  1 +spring.profiles: dev,prod
  2 +spring.profiles.active: dev
27 3  
28 4 spring.view.suffix=.html
29   -
30 5 server.session-timeout=-1
31   -
32 6 security.basic.enabled=false
33 7  
34   -# 上传文件大小限制配置
  8 +# \u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F\u9650\u5236\u914D\u7F6E
35 9 # File size limit
36 10 multipart.maxFileSize = -1
37 11 # Total request size for a multipart/form-data
38 12 multipart.maxRequestSize = -1
39 13  
40   -##
41   -#222.66.0.204:5555
42   -##\u5B9E\u65F6gps
43   -http.gps.real.url= http://192.168.168.192:8080/transport_server/rtgps/
44   -##\u6D88\u606F\u4E0B\u53D1
45   -http.send.directive = http://192.168.168.192:8080/transport_server/message/
... ...
src/main/resources/static/pages/control/line/js/drawSvg.js
... ... @@ -49,10 +49,12 @@ var drawSvg = (function(){
49 49 svg = drawSvgObject.init(lineId, data, container, w, 80);
50 50 //线路编码 和 首页SVG对照
51 51 homeSvgMapp[lineId] = svg;
52   - //双击事件
53   - $(svg[0]).dblclick(function(){
54   - $('#top-tabs-wrap .nav-tabs a[data-id='+this.id+']').click();
55   - });
  52 + if(svg && svg.length > 0){
  53 + //双击事件
  54 + $(svg[0]).dblclick(function(){
  55 + $('#top-tabs-wrap .nav-tabs a[data-id='+this.id+']').click();
  56 + });
  57 + }
56 58 },
57 59 initAloneSvg: function(lineId, data, container){
58 60 var w = $(document).width(),
... ...