Commit 078baab1f6eaaaf434c78e58154c0bfb1881ac9d

Authored by 潘钊
1 parent ad4380bd

update

Showing 24 changed files with 470 additions and 104 deletions
src/main/java/com/bsth/StartCommand.java
@@ -16,6 +16,7 @@ import com.bsth.service.realcontrol.buffer.GetSchedulePlanThread; @@ -16,6 +16,7 @@ import com.bsth.service.realcontrol.buffer.GetSchedulePlanThread;
16 import com.bsth.service.realcontrol.buffer.SchedulePersistenceThread; 16 import com.bsth.service.realcontrol.buffer.SchedulePersistenceThread;
17 import com.bsth.vehicle.common.CommonRefreshThread; 17 import com.bsth.vehicle.common.CommonRefreshThread;
18 import com.bsth.vehicle.directive.DirectivePersistenceThread; 18 import com.bsth.vehicle.directive.DirectivePersistenceThread;
  19 +import com.bsth.vehicle.directive.FirstScheduleIssuedThread;
19 import com.bsth.vehicle.gpsdata.GpsArrivalStationThread; 20 import com.bsth.vehicle.gpsdata.GpsArrivalStationThread;
20 import com.bsth.vehicle.gpsdata.GpsRefreshThread; 21 import com.bsth.vehicle.gpsdata.GpsRefreshThread;
21 22
@@ -32,7 +33,7 @@ public class StartCommand implements CommandLineRunner{ @@ -32,7 +33,7 @@ public class StartCommand implements CommandLineRunner{
32 @Autowired 33 @Autowired
33 SecurityMetadataSourceService invocationSecurityMetadataSourceService; 34 SecurityMetadataSourceService invocationSecurityMetadataSourceService;
34 35
35 - public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(6); 36 + public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(7);
36 37
37 @Autowired 38 @Autowired
38 GpsRefreshThread gpsRefreshThread; 39 GpsRefreshThread gpsRefreshThread;
@@ -46,6 +47,8 @@ public class StartCommand implements CommandLineRunner{ @@ -46,6 +47,8 @@ public class StartCommand implements CommandLineRunner{
46 SchedulePersistenceThread SchedulePersistenceThread; 47 SchedulePersistenceThread SchedulePersistenceThread;
47 @Autowired 48 @Autowired
48 GpsArrivalStationThread gpsArrivalStationThread; 49 GpsArrivalStationThread gpsArrivalStationThread;
  50 + @Autowired
  51 + FirstScheduleIssuedThread firstScheduleIssuedThread;
49 52
50 @Override 53 @Override
51 public void run(String... arg0){ 54 public void run(String... arg0){
@@ -54,20 +57,48 @@ public class StartCommand implements CommandLineRunner{ @@ -54,20 +57,48 @@ public class StartCommand implements CommandLineRunner{
54 //启动时加载所有资源 57 //启动时加载所有资源
55 invocationSecurityMetadataSourceService.loadResourceDefine(); 58 invocationSecurityMetadataSourceService.loadResourceDefine();
56 59
57 - //GPS实时数据更新线程,每次执行完成4秒后开始下一次  
58 - scheduler.scheduleWithFixedDelay(gpsRefreshThread, 0, 4, TimeUnit.SECONDS);  
59 - //定时0点从计划排班表抓取当天实际排班 60 + /**
  61 + * GPS实时数据更新 线程
  62 + * 每8秒和网关HTTP接口同步一次
  63 + */
  64 + scheduler.scheduleWithFixedDelay(gpsRefreshThread, 0, 8, TimeUnit.SECONDS);
  65 +
  66 + /**
  67 + * 每天 0点 抓取当天实际排班
  68 + */
60 scheduler.scheduleAtFixedRate(getSchedulePlanThread 69 scheduler.scheduleAtFixedRate(getSchedulePlanThread
61 , 0//DateUtils.getTimesnight() + 5 - System.currentTimeMillis() / 1000 70 , 0//DateUtils.getTimesnight() + 5 - System.currentTimeMillis() / 1000
62 , 60 * 60 * 24, TimeUnit.SECONDS); 71 , 60 * 60 * 24, TimeUnit.SECONDS);
63 - //两分钟调度指令入库一次  
64 - scheduler.scheduleWithFixedDelay(directivePersistenceThread, 20, 60 * 1, TimeUnit.SECONDS);  
65 - //两小时刷新一次对照数据 72 +
  73 + /**
  74 + * 调度指令两分钟入库一次
  75 + * 指令会缓存在内存,直到收到所有响应再入库
  76 + */
  77 + scheduler.scheduleWithFixedDelay(directivePersistenceThread, 20, 60 * 2, TimeUnit.SECONDS);
  78 +
  79 + /**
  80 + * 车辆,设备,公司等常用的映射数据,每两小时刷新一次
  81 + */
66 scheduler.scheduleWithFixedDelay(commonRefreshThread, 0, 60 * 60 * 2, TimeUnit.SECONDS); 82 scheduler.scheduleWithFixedDelay(commonRefreshThread, 0, 60 * 60 * 2, TimeUnit.SECONDS);
67 - //一分钟持久化一次实际排班 83 +
  84 + /**
  85 + * 每分钟将有变更的班次入库(不包括子任务)
  86 + * 单纯为了提高 线调操作 的响应速度
  87 + */
68 scheduler.scheduleWithFixedDelay(SchedulePersistenceThread, 60 * 1, 60 * 1, TimeUnit.SECONDS); 88 scheduler.scheduleWithFixedDelay(SchedulePersistenceThread, 60 * 1, 60 * 1, TimeUnit.SECONDS);
69 - //将实际到离站和排班计划进行匹配 12秒一次 89 +
  90 + /**
  91 + * 每15秒从数据库抓取到离站信息和班次匹配
  92 + * (网关生成的到离站数据也是延迟批量入库,所以缩短该线程执行周期并不会提高 “实际到离站” 的实时性)
  93 + */
70 //scheduler.scheduleWithFixedDelay(gpsArrivalStationThread, 5, 1200, TimeUnit.SECONDS); 94 //scheduler.scheduleWithFixedDelay(gpsArrivalStationThread, 5, 1200, TimeUnit.SECONDS);
  95 +
  96 + /**
  97 + * 首个调度指令下发(2分钟运行一次)
  98 + * 每辆车的第一个调度指令由该线程下发
  99 + * 后续班次由 “实际终点到达” 事件触发指令下发
  100 + */
  101 + //scheduler.scheduleWithFixedDelay(firstScheduleIssuedThread, 60 , 60 * 2, TimeUnit.SECONDS);
71 } catch (Exception e) { 102 } catch (Exception e) {
72 e.printStackTrace(); 103 e.printStackTrace();
73 } 104 }
src/main/java/com/bsth/entity/realcontrol/ScheduleRealInfo.java
@@ -3,9 +3,10 @@ package com.bsth.entity.realcontrol; @@ -3,9 +3,10 @@ package com.bsth.entity.realcontrol;
3 import com.bsth.entity.sys.SysUser; 3 import com.bsth.entity.sys.SysUser;
4 4
5 import javax.persistence.*; 5 import javax.persistence.*;
  6 +
  7 +import java.text.ParseException;
  8 +import java.text.SimpleDateFormat;
6 import java.util.Date; 9 import java.util.Date;
7 -import java.util.HashSet;  
8 -import java.util.Set;  
9 10
10 /** 11 /**
11 * 实际排班计划明细。 12 * 实际排班计划明细。
@@ -32,10 +33,10 @@ public class ScheduleRealInfo { @@ -32,10 +33,10 @@ public class ScheduleRealInfo {
32 /** 车辆自编号 */ 33 /** 车辆自编号 */
33 private String clZbh; 34 private String clZbh;
34 35
35 - /** 报道时间(格式 HH:mm) */  
36 - private String bdTime;  
37 - /** 出场时间(格式 HH:mm) */  
38 - private String ccTime; 36 + /** 报道时间(格式 HH:mm)
  37 + private String bdTime; */
  38 + /** 出场时间(格式 HH:mm)
  39 + private String ccTime;*/
39 40
40 /** 驾驶员工号 */ 41 /** 驾驶员工号 */
41 private String jGh; 42 private String jGh;
@@ -80,15 +81,15 @@ public class ScheduleRealInfo { @@ -80,15 +81,15 @@ public class ScheduleRealInfo {
80 private Integer bcsj; 81 private Integer bcsj;
81 82
82 /** 83 /**
83 - * 班次类型 TODO:正常班次、出场、进场、加油、临加班次、区间班次、放空班次、放大站班次、两点间空驶 84 + * 班次类型 TODO:正常班次、出场、进场、加油、区间班次、放空班次、放大站班次、两点间空驶
84 */ 85 */
85 private String bcType; 86 private String bcType;
86 87
87 /** 创建人 */ 88 /** 创建人 */
88 - @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY) 89 + @ManyToOne(fetch = FetchType.LAZY)
89 private SysUser createBy; 90 private SysUser createBy;
90 /** 修改人 */ 91 /** 修改人 */
91 - @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY) 92 + @ManyToOne(fetch = FetchType.LAZY)
92 private SysUser updateBy; 93 private SysUser updateBy;
93 /** 创建日期 */ 94 /** 创建日期 */
94 @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") 95 @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
@@ -133,6 +134,9 @@ public class ScheduleRealInfo { @@ -133,6 +134,9 @@ public class ScheduleRealInfo {
133 @Transient 134 @Transient
134 private Long dfsjT; 135 private Long dfsjT;
135 136
  137 + /** 指令下发状态 60: 已发送, 100: 设备确认收到, 200:驾驶员确认 0:失败 */
  138 + private Integer directiveState;
  139 +
136 public void addRemarks(String remark){ 140 public void addRemarks(String remark){
137 String newRem = this.getRemarks(); 141 String newRem = this.getRemarks();
138 if(null == newRem) 142 if(null == newRem)
@@ -189,22 +193,6 @@ public class ScheduleRealInfo { @@ -189,22 +193,6 @@ public class ScheduleRealInfo {
189 this.clZbh = clZbh; 193 this.clZbh = clZbh;
190 } 194 }
191 195
192 - public String getBdTime() {  
193 - return bdTime;  
194 - }  
195 -  
196 - public void setBdTime(String bdTime) {  
197 - this.bdTime = bdTime;  
198 - }  
199 -  
200 - public String getCcTime() {  
201 - return ccTime;  
202 - }  
203 -  
204 - public void setCcTime(String ccTime) {  
205 - this.ccTime = ccTime;  
206 - }  
207 -  
208 public String getjGh() { 196 public String getjGh() {
209 return jGh; 197 return jGh;
210 } 198 }
@@ -476,4 +464,43 @@ public class ScheduleRealInfo { @@ -476,4 +464,43 @@ public class ScheduleRealInfo {
476 public void setDfsjT(Long dfsjT) { 464 public void setDfsjT(Long dfsjT) {
477 this.dfsjT = dfsjT; 465 this.dfsjT = dfsjT;
478 } 466 }
  467 +
  468 + @Transient
  469 + static SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  470 + @Transient
  471 + static SimpleDateFormat sdfyyyyMMddHHmm = new SimpleDateFormat("yyyy-MM-dd HH:mm");
  472 +
  473 + /**
  474 + * @throws ParseException
  475 + *
  476 + * @Title: syncTime
  477 + * @Description: TODO(计算时间戳,待发时间为计发时间)
  478 + * @param 设定文件
  479 + * @return void 返回类型
  480 + * @throws
  481 + */
  482 + public void syncTime(){
  483 + try{
  484 + this.setDfsj(this.getFcsj());
  485 + //发车时间戳
  486 + this.setFcsjT(sdfyyyyMMddHHmm.parse(sdfyyyyMMdd.format(this.scheduleDate) + " " + this.getFcsj()).getTime());
  487 + //待发时间
  488 + this.setDfsjT(this.getFcsjT());
  489 + }catch(Exception e){
  490 + e.printStackTrace();
  491 + }
  492 + }
  493 +
  494 + public Integer getDirectiveState() {
  495 + return directiveState;
  496 + }
  497 +
  498 + public void setDirectiveState(Integer directiveState) {
  499 + this.directiveState = directiveState;
  500 + }
  501 +
  502 + @Override
  503 + public boolean equals(Object obj) {
  504 + return this.id.equals(((ScheduleRealInfo)obj).getId());
  505 + }
479 } 506 }
src/main/java/com/bsth/entity/sys/Module.java
@@ -11,10 +11,18 @@ import javax.persistence.GeneratedValue; @@ -11,10 +11,18 @@ import javax.persistence.GeneratedValue;
11 import javax.persistence.GenerationType; 11 import javax.persistence.GenerationType;
12 import javax.persistence.Id; 12 import javax.persistence.Id;
13 import javax.persistence.ManyToMany; 13 import javax.persistence.ManyToMany;
  14 +import javax.persistence.NamedAttributeNode;
  15 +import javax.persistence.NamedEntityGraph;
  16 +import javax.persistence.NamedEntityGraphs;
14 import javax.persistence.Table; 17 import javax.persistence.Table;
15 18
16 @Entity 19 @Entity
17 @Table(name = "bsth_c_sys_module") 20 @Table(name = "bsth_c_sys_module")
  21 +@NamedEntityGraphs({
  22 + @NamedEntityGraph(name = "module_roles", attributeNodes = {
  23 + @NamedAttributeNode("roles")
  24 + })
  25 +})
18 public class Module { 26 public class Module {
19 27
20 @Id 28 @Id
@@ -45,7 +53,7 @@ public class Module { @@ -45,7 +53,7 @@ public class Module {
45 */ 53 */
46 private String groupType; 54 private String groupType;
47 55
48 - @ManyToMany(fetch = FetchType.EAGER, mappedBy = "modules") 56 + @ManyToMany(mappedBy = "modules", fetch = FetchType.LAZY)
49 private Set<Role> roles = new LinkedHashSet<>(); 57 private Set<Role> roles = new LinkedHashSet<>();
50 58
51 @Column(updatable = false,name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") 59 @Column(updatable = false,name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
src/main/java/com/bsth/repository/ModuleRepository.java
@@ -3,6 +3,8 @@ package com.bsth.repository; @@ -3,6 +3,8 @@ package com.bsth.repository;
3 import java.util.List; 3 import java.util.List;
4 import java.util.Set; 4 import java.util.Set;
5 5
  6 +import org.springframework.data.jpa.domain.Specification;
  7 +import org.springframework.data.jpa.repository.EntityGraph;
6 import org.springframework.data.jpa.repository.Query; 8 import org.springframework.data.jpa.repository.Query;
7 import org.springframework.stereotype.Repository; 9 import org.springframework.stereotype.Repository;
8 10
@@ -18,4 +20,8 @@ public interface ModuleRepository extends BaseRepository&lt;Module, Integer&gt;{ @@ -18,4 +20,8 @@ public interface ModuleRepository extends BaseRepository&lt;Module, Integer&gt;{
18 20
19 @Query("select m from Module m where m.id in ?1") 21 @Query("select m from Module m where m.id in ?1")
20 Set<Module> findByIds(List<Integer> ids); 22 Set<Module> findByIds(List<Integer> ids);
  23 +
  24 + @EntityGraph(value = "carConfigInfo_xl_cl", type = EntityGraph.EntityGraphType.FETCH)
  25 + @Override
  26 + List<Module> findAll(Specification<Module> spec);
21 } 27 }
src/main/java/com/bsth/service/realcontrol/buffer/GetSchedulePlanThread.java
@@ -36,9 +36,7 @@ public class GetSchedulePlanThread extends Thread{ @@ -36,9 +36,7 @@ public class GetSchedulePlanThread extends Thread{
36 @Autowired 36 @Autowired
37 ScheduleRealInfoRepository scheduleRealInfoRepository; 37 ScheduleRealInfoRepository scheduleRealInfoRepository;
38 38
39 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd")  
40 - ,sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm")  
41 - ,sdf3 = new SimpleDateFormat("HH:mm"); 39 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
42 40
43 @Override 41 @Override
44 public void run() { 42 public void run() {
@@ -51,17 +49,12 @@ public class GetSchedulePlanThread extends Thread{ @@ -51,17 +49,12 @@ public class GetSchedulePlanThread extends Thread{
51 49
52 Date zdDate; 50 Date zdDate;
53 for(ScheduleRealInfo item : realList){ 51 for(ScheduleRealInfo item : realList){
54 - item.setDfsj(item.getFcsj());  
55 - //发车时间戳  
56 - item.setFcsjT(sdf2.parse(dateStr + " " + item.getFcsj()).getTime());  
57 - //待发时间  
58 - item.setDfsjT(item.getFcsjT());  
59 - 52 + item.syncTime();
60 //计划终点时间 53 //计划终点时间
61 if(item.getBcsj() != null){ 54 if(item.getBcsj() != null){
62 zdDate = new Date(item.getFcsjT() + (item.getBcsj() * 60 * 1000)); 55 zdDate = new Date(item.getFcsjT() + (item.getBcsj() * 60 * 1000));
63 item.setZdsjT(zdDate.getTime()); 56 item.setZdsjT(zdDate.getTime());
64 - item.setZdsj(sdf3.format(zdDate)); 57 + item.setZdsj(sdfHHmm.format(zdDate));
65 } 58 }
66 } 59 }
67 60
src/main/java/com/bsth/service/realcontrol/buffer/ScheduleBuffer.java
@@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
12 12
13 import com.bsth.entity.realcontrol.ScheduleRealInfo; 13 import com.bsth.entity.realcontrol.ScheduleRealInfo;
14 import com.google.common.collect.ArrayListMultimap; 14 import com.google.common.collect.ArrayListMultimap;
  15 +import com.google.common.collect.LinkedListMultimap;
15 16
16 /** 17 /**
17 * 18 *
@@ -32,10 +33,17 @@ public class ScheduleBuffer { @@ -32,10 +33,17 @@ public class ScheduleBuffer {
32 public static ArrayListMultimap<String, ScheduleRealInfo> schedulListMap; 33 public static ArrayListMultimap<String, ScheduleRealInfo> schedulListMap;
33 34
34 /** 35 /**
35 - * K: 车辆自编号 V: 班次链表 36 + * K: 车辆自编号 V: 未完成班次链表
36 */ 37 */
37 public static Map<String, LinkedList<ScheduleRealInfo>> vehLinkedMap; 38 public static Map<String, LinkedList<ScheduleRealInfo>> vehLinkedMap;
38 39
  40 +
  41 + /**
  42 + * K: 车辆自编号 V: 已执行班次链表
  43 + */
  44 + public static LinkedListMultimap<String, ScheduleRealInfo> finishLinkedMap;
  45 +
  46 +
39 /** 47 /**
40 * 主键 和 排班映射 48 * 主键 和 排班映射
41 */ 49 */
@@ -46,24 +54,22 @@ public class ScheduleBuffer { @@ -46,24 +54,22 @@ public class ScheduleBuffer {
46 */ 54 */
47 public static LinkedList<ScheduleRealInfo> persistentList; 55 public static LinkedList<ScheduleRealInfo> persistentList;
48 56
  57 + static ScheduleComparator scheduleComparator = new ScheduleComparator();
  58 +
49 static{ 59 static{
50 schedulListMap = ArrayListMultimap.create(); 60 schedulListMap = ArrayListMultimap.create();
51 pkSchedulMap = new HashMap<>(); 61 pkSchedulMap = new HashMap<>();
52 persistentList = new LinkedList<>(); 62 persistentList = new LinkedList<>();
53 vehLinkedMap = new HashMap<>(); 63 vehLinkedMap = new HashMap<>();
  64 +
  65 + finishLinkedMap = LinkedListMultimap.create();
54 } 66 }
55 67
56 public static int init(List<ScheduleRealInfo> list){ 68 public static int init(List<ScheduleRealInfo> list){
57 69
58 try{ 70 try{
59 //发车时间排序 71 //发车时间排序
60 - Collections.sort(list, new Comparator<ScheduleRealInfo>() {  
61 -  
62 - @Override  
63 - public int compare(ScheduleRealInfo o1, ScheduleRealInfo o2) {  
64 - return (int) (o1.getFcsjT() - o2.getFcsjT());  
65 - }  
66 - }); 72 + Collections.sort(list, scheduleComparator);
67 73
68 String zbh; 74 String zbh;
69 for(ScheduleRealInfo schedul : list){ 75 for(ScheduleRealInfo schedul : list){
@@ -83,4 +89,65 @@ public class ScheduleBuffer { @@ -83,4 +89,65 @@ public class ScheduleBuffer {
83 } 89 }
84 return 0; 90 return 0;
85 } 91 }
  92 +
  93 + public static int put(ScheduleRealInfo sch){
  94 + schedulListMap.put(sch.getXlBm(), sch);
  95 + pkSchedulMap.put(sch.getId(), sch);
  96 +
  97 + String zbh = sch.getClZbh();
  98 + if(!vehLinkedMap.containsKey(zbh))
  99 + vehLinkedMap.put(zbh, new LinkedList<ScheduleRealInfo>());
  100 + vehLinkedMap.get(zbh).add(sch);
  101 +
  102 + //重新排序
  103 + Collections.sort(vehLinkedMap.get(zbh), scheduleComparator);
  104 + return 0;
  105 + }
  106 +
  107 + public static class ScheduleComparator implements Comparator<ScheduleRealInfo>{
  108 +
  109 + @Override
  110 + public int compare(ScheduleRealInfo o1, ScheduleRealInfo o2) {
  111 + return (int) (o1.getFcsjT() - o2.getFcsjT());
  112 + }
  113 + }
  114 +
  115 + /**
  116 + *
  117 + * @Title: finishSch
  118 + * @Description: TODO(完成一个班次)
  119 + * @param @param sch
  120 + * @return ScheduleRealInfo 返回 下一个待执行的班次
  121 + * @throws
  122 + */
  123 + public static ScheduleRealInfo finishSch(ScheduleRealInfo sch){
  124 + LinkedList<ScheduleRealInfo> list = vehLinkedMap.get(sch.getClZbh());
  125 + //状态修改为已执行
  126 + sch.setStatus(2);
  127 + persistentList.add(sch);
  128 +
  129 + ScheduleRealInfo temp;
  130 + int len = list.size();
  131 + for(int i = 0; i < len; i ++){
  132 + temp = list.poll();
  133 + if(temp.equals(sch)){
  134 + //加入已执行
  135 + finishLinkedMap.put(sch.getClZbh(), sch);
  136 + break;
  137 + }
  138 + }
  139 +
  140 + return list.getFirst();
  141 + }
  142 +
  143 + /**
  144 + *
  145 + * @Title: getFinishSchNo
  146 + * @Description: TODO(获取车辆已完成的班次数)
  147 + * @param @param nbbm
  148 + * @throws
  149 + */
  150 + public static int getFinishSchNo(String nbbm){
  151 + return finishLinkedMap.get(nbbm) == null ? 0 : finishLinkedMap.get(nbbm).size();
  152 + }
86 } 153 }
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
@@ -8,6 +8,8 @@ import java.util.HashMap; @@ -8,6 +8,8 @@ import java.util.HashMap;
8 import java.util.List; 8 import java.util.List;
9 import java.util.Map; 9 import java.util.Map;
10 10
  11 +import javax.transaction.Transactional;
  12 +
11 import org.slf4j.Logger; 13 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory; 14 import org.slf4j.LoggerFactory;
13 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,9 +21,11 @@ import com.bsth.entity.Personnel; @@ -19,9 +21,11 @@ import com.bsth.entity.Personnel;
19 import com.bsth.entity.realcontrol.ScheduleRealInfo; 21 import com.bsth.entity.realcontrol.ScheduleRealInfo;
20 import com.bsth.entity.schedule.CarConfigInfo; 22 import com.bsth.entity.schedule.CarConfigInfo;
21 import com.bsth.entity.schedule.EmployeeConfigInfo; 23 import com.bsth.entity.schedule.EmployeeConfigInfo;
  24 +import com.bsth.entity.sys.SysUser;
22 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; 25 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
23 import com.bsth.repository.schedule.CarConfigInfoRepository; 26 import com.bsth.repository.schedule.CarConfigInfoRepository;
24 import com.bsth.repository.schedule.EmployeeConfigInfoRepository; 27 import com.bsth.repository.schedule.EmployeeConfigInfoRepository;
  28 +import com.bsth.security.util.SecurityUtils;
25 import com.bsth.service.impl.BaseServiceImpl; 29 import com.bsth.service.impl.BaseServiceImpl;
26 import com.bsth.service.realcontrol.ScheduleRealInfoService; 30 import com.bsth.service.realcontrol.ScheduleRealInfoService;
27 import com.bsth.service.realcontrol.buffer.ScheduleBuffer; 31 import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
@@ -167,7 +171,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -167,7 +171,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
167 if(driver != null){ 171 if(driver != null){
168 map = new HashMap<>(); 172 map = new HashMap<>();
169 code = driver.getJobCode(); 173 code = driver.getJobCode();
170 - map.put("id", code); 174 + map.put("id", code + "/" + driver.getPersonnelName());
171 map.put("text", code + "/" + driver.getPersonnelName()); 175 map.put("text", code + "/" + driver.getPersonnelName());
172 rsList.add(map); 176 rsList.add(map);
173 } 177 }
@@ -190,7 +194,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -190,7 +194,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
190 if(conductor != null){ 194 if(conductor != null){
191 code = conductor.getJobCode(); 195 code = conductor.getJobCode();
192 map = new HashMap<>(); 196 map = new HashMap<>();
193 - map.put("id", code); 197 + map.put("id", code + "/" + conductor.getPersonnelName());
194 map.put("text", code + "/" + conductor.getPersonnelName()); 198 map.put("text", code + "/" + conductor.getPersonnelName());
195 rsList.add(map); 199 rsList.add(map);
196 } 200 }
@@ -220,4 +224,22 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -220,4 +224,22 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
220 } 224 }
221 return rsList; 225 return rsList;
222 } 226 }
  227 +
  228 + /**
  229 + * 临加班次
  230 + */
  231 + @Override
  232 + public Map<String, Object> save(ScheduleRealInfo t) {
  233 + SysUser user = SecurityUtils.getCurrentUser();
  234 +
  235 + t.setScheduleDate(new Date());
  236 + t.setCreateBy(user);
  237 + t.syncTime();
  238 +
  239 + Map<String, Object> map = super.save(t);
  240 +
  241 + //加入缓存
  242 + ScheduleBuffer.put(t);
  243 + return map;
  244 + }
223 } 245 }
src/main/java/com/bsth/util/TestPad.java
@@ -11,13 +11,6 @@ public class TestPad { @@ -11,13 +11,6 @@ public class TestPad {
11 double Ec; 11 double Ec;
12 double Ed; 12 double Ed;
13 13
14 -  
15 - public static void main(String[] args) {  
16 -  
17 - TestPad A = new TestPad(121.60613, 31.270115);  
18 - TestPad B = new TestPad(121.605239 ,31.269705);  
19 - System.out.println(TestPad.angle(A, B));  
20 - }  
21 public TestPad(double longitude, double latitude) 14 public TestPad(double longitude, double latitude)
22 { 15 {
23 m_LoDeg = (int)longitude; 16 m_LoDeg = (int)longitude;
src/main/java/com/bsth/vehicle/directive/FirstScheduleIssuedThread.java 0 → 100644
  1 +package com.bsth.vehicle.directive;
  2 +
  3 +import java.util.LinkedList;
  4 +import java.util.Set;
  5 +
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  10 +import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
  11 +import com.bsth.vehicle.directive.service.DirectiveService;
  12 +
  13 +/**
  14 + *
  15 + * @ClassName: ScheduleIssuedThread
  16 + * @Description: TODO(首班调度指令下发线程)
  17 + * @author PanZhao
  18 + * @date 2016年6月29日 下午11:09:39
  19 + *
  20 + */
  21 +@Component
  22 +public class FirstScheduleIssuedThread extends Thread{
  23 +
  24 + @Autowired
  25 + DirectiveService directiveService;
  26 +
  27 + @Override
  28 + public void run() {
  29 +
  30 + Set<String> keys = ScheduleBuffer.vehLinkedMap.keySet();
  31 + LinkedList<ScheduleRealInfo> linkedList;
  32 + ScheduleRealInfo sch;
  33 + for(String nbbm : keys){
  34 + linkedList = ScheduleBuffer.vehLinkedMap.get(nbbm);
  35 +
  36 + sch = linkedList.getFirst();
  37 +
  38 + if(sch.getFcsjActual() == null)
  39 + directiveService.send60Dispatch(sch, 0);
  40 + }
  41 + }
  42 +}
src/main/java/com/bsth/vehicle/directive/buffer/DirectiveBuffer.java
@@ -105,13 +105,17 @@ public class DirectiveBuffer { @@ -105,13 +105,17 @@ public class DirectiveBuffer {
105 directive.setReply47((short)0); 105 directive.setReply47((short)0);
106 break; 106 break;
107 } 107 }
  108 +
  109 + if(directive.isDispatch()){
  110 + directive.getSch().setDirectiveState(reply.getStatus() * 100);
  111 + }
108 transientList.add(directive); 112 transientList.add(directive);
109 } 113 }
110 114
111 /** 115 /**
112 * 116 *
113 * @Title: reply64 117 * @Title: reply64
114 - * @Description: TODO(64协议响应) 118 + * @Description: TODO(64 协议响应)
115 * @throws 119 * @throws
116 */ 120 */
117 public void reply64(JSONObject json){ 121 public void reply64(JSONObject json){
src/main/java/com/bsth/vehicle/directive/entity/Directive.java
@@ -4,9 +4,12 @@ import javax.persistence.Embeddable; @@ -4,9 +4,12 @@ import javax.persistence.Embeddable;
4 import javax.persistence.Entity; 4 import javax.persistence.Entity;
5 import javax.persistence.GeneratedValue; 5 import javax.persistence.GeneratedValue;
6 import javax.persistence.Id; 6 import javax.persistence.Id;
  7 +import javax.persistence.ManyToOne;
7 import javax.persistence.Table; 8 import javax.persistence.Table;
8 import javax.persistence.Transient; 9 import javax.persistence.Transient;
9 10
  11 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  12 +
10 13
11 /** 14 /**
12 * 15 *
@@ -62,6 +65,17 @@ public class Directive { @@ -62,6 +65,17 @@ public class Directive {
62 */ 65 */
63 private Short reply47; 66 private Short reply47;
64 67
  68 + /**
  69 + * 是否是调度指令
  70 + * 目前调度指令和消息短语都是短语下发,所以从协议上无法区分
  71 + */
  72 + private boolean isDispatch;
  73 +
  74 + /**
  75 + * 如果是调度指令,则关联到相关的班次
  76 + */
  77 + @ManyToOne
  78 + private ScheduleRealInfo sch;
65 79
66 @Embeddable 80 @Embeddable
67 public static class DirectiveData { 81 public static class DirectiveData {
@@ -235,4 +249,20 @@ public class Directive { @@ -235,4 +249,20 @@ public class Directive {
235 public void setReply47(Short reply47) { 249 public void setReply47(Short reply47) {
236 this.reply47 = reply47; 250 this.reply47 = reply47;
237 } 251 }
  252 +
  253 + public boolean isDispatch() {
  254 + return isDispatch;
  255 + }
  256 +
  257 + public void setDispatch(boolean isDispatch) {
  258 + this.isDispatch = isDispatch;
  259 + }
  260 +
  261 + public ScheduleRealInfo getSch() {
  262 + return sch;
  263 + }
  264 +
  265 + public void setSch(ScheduleRealInfo sch) {
  266 + this.sch = sch;
  267 + }
238 } 268 }
src/main/java/com/bsth/vehicle/directive/service/DirectiveService.java
1 package com.bsth.vehicle.directive.service; 1 package com.bsth.vehicle.directive.service;
2 2
3 3
  4 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
4 import com.bsth.service.BaseService; 5 import com.bsth.service.BaseService;
5 import com.bsth.vehicle.directive.entity.Directive; 6 import com.bsth.vehicle.directive.entity.Directive;
6 7
@@ -17,7 +18,15 @@ public interface DirectiveService extends BaseService&lt;Directive, Integer&gt;{ @@ -17,7 +18,15 @@ public interface DirectiveService extends BaseService&lt;Directive, Integer&gt;{
17 */ 18 */
18 int send60Phrase(String nbbm, String text); 19 int send60Phrase(String nbbm, String text);
19 20
20 - int send60Dispatch(String nbbm, String text); 21 + /**
  22 + *
  23 + * @Title: send60Dispatch
  24 + * @Description: TODO(调度指令下发)
  25 + * @param @param sch 要下发的班次
  26 + * @param @param finish 已完成的班次数
  27 + * @throws
  28 + */
  29 + int send60Dispatch(ScheduleRealInfo sch, int finish);
21 30
22 //60营运指令 31 //60营运指令
23 int send60Operation(String nbbm, int state, int upDown); 32 int send60Operation(String nbbm, int state, int upDown);
src/main/java/com/bsth/vehicle/directive/service/DirectiveServiceImpl.java
1 package com.bsth.vehicle.directive.service; 1 package com.bsth.vehicle.directive.service;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
  4 +import java.text.SimpleDateFormat;
  5 +import java.util.Date;
4 6
5 import org.apache.http.client.methods.CloseableHttpResponse; 7 import org.apache.http.client.methods.CloseableHttpResponse;
6 import org.apache.http.client.methods.HttpPost; 8 import org.apache.http.client.methods.HttpPost;
@@ -15,6 +17,7 @@ import org.springframework.stereotype.Service; @@ -15,6 +17,7 @@ import org.springframework.stereotype.Service;
15 17
16 import com.alibaba.fastjson.JSON; 18 import com.alibaba.fastjson.JSON;
17 import com.alibaba.fastjson.JSONObject; 19 import com.alibaba.fastjson.JSONObject;
  20 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
18 import com.bsth.service.impl.BaseServiceImpl; 21 import com.bsth.service.impl.BaseServiceImpl;
19 import com.bsth.vehicle.common.CommonMapped; 22 import com.bsth.vehicle.common.CommonMapped;
20 import com.bsth.vehicle.directive.Consts; 23 import com.bsth.vehicle.directive.Consts;
@@ -44,13 +47,17 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive, Integer&gt; im @@ -44,13 +47,17 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive, Integer&gt; im
44 @Autowired 47 @Autowired
45 LineChangeRepository lineChangeRepository; 48 LineChangeRepository lineChangeRepository;
46 49
  50 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH点mm分");
  51 +
  52 + static Long schDiff = 1000 * 60 * 6L;
  53 +
47 @Override 54 @Override
48 public int send60Phrase(String nbbm, String text) { 55 public int send60Phrase(String nbbm, String text) {
49 Directive directive = null; 56 Directive directive = null;
50 try { 57 try {
51 directive = create60Data(nbbm, text, DispatchInstruct.PHRASE); 58 directive = create60Data(nbbm, text, DispatchInstruct.PHRASE);
52 } catch (Exception e) { 59 } catch (Exception e) {
53 - logger.error("生成调度指令时出现异常", e); 60 + logger.error("发送消息短语出现异常", e);
54 return -1; 61 return -1;
55 } 62 }
56 63
@@ -70,8 +77,40 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive, Integer&gt; im @@ -70,8 +77,40 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive, Integer&gt; im
70 } 77 }
71 78
72 @Override 79 @Override
73 - public int send60Dispatch(String nbbm, String text) {  
74 - return 0; 80 + public int send60Dispatch(ScheduleRealInfo sch, int finish) {
  81 + Directive directive = null;
  82 + try {
  83 + //如果发车时间距当前时间较远,则不发送
  84 + if(Math.abs(sch.getFcsjT() - System.currentTimeMillis()) > schDiff){
  85 + return 0;
  86 + }
  87 +
  88 + String text = "已完成" + finish + "个班次,下一发车时间" + sdfHHmm.format(new Date(sch.getFcsjT()))
  89 + + ",由" + sch.getQdzName() + "发往" + sch.getZdzName();
  90 +
  91 + //目前使用短语协议下发调度指令
  92 + directive = create60Data(sch.getClZbh(), text, DispatchInstruct.PHRASE);
  93 + } catch (Exception e) {
  94 + logger.error("生成调度指令时出现异常", e);
  95 + return -1;
  96 + }
  97 +
  98 + if(null == directive)
  99 + return -1;
  100 +
  101 + //发送指令
  102 + int code = postJson(JSON.toJSONString(directive));
  103 +
  104 + if(code == 0){
  105 + sch.setDirectiveState(60);
  106 + //添加到缓存,等待入库
  107 + directive.setDispatch(true);
  108 + directive.setSch(sch);
  109 + DirectiveBuffer.put(directive);
  110 + }else{
  111 + logger.error("send60Phrase error, code: " + code);
  112 + }
  113 + return code;
75 } 114 }
76 115
77 @Override 116 @Override
src/main/java/com/bsth/vehicle/gpsdata/GpsArrivalStationThread.java
@@ -13,12 +13,14 @@ import java.util.Set; @@ -13,12 +13,14 @@ import java.util.Set;
13 13
14 import org.slf4j.Logger; 14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory; 15 import org.slf4j.LoggerFactory;
  16 +import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.stereotype.Component; 17 import org.springframework.stereotype.Component;
17 18
18 import com.bsth.entity.realcontrol.ScheduleRealInfo; 19 import com.bsth.entity.realcontrol.ScheduleRealInfo;
19 import com.bsth.service.realcontrol.buffer.ScheduleBuffer; 20 import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
20 import com.bsth.util.DateUtils; 21 import com.bsth.util.DateUtils;
21 import com.bsth.util.db.DBUtils_MS; 22 import com.bsth.util.db.DBUtils_MS;
  23 +import com.bsth.vehicle.directive.service.DirectiveService;
22 import com.bsth.vehicle.gpsdata.buffer.GpsArrivalDataBuffer; 24 import com.bsth.vehicle.gpsdata.buffer.GpsArrivalDataBuffer;
23 import com.bsth.vehicle.gpsdata.entity.ArrivalInfo; 25 import com.bsth.vehicle.gpsdata.entity.ArrivalInfo;
24 26
@@ -36,6 +38,9 @@ public class GpsArrivalStationThread extends Thread{ @@ -36,6 +38,9 @@ public class GpsArrivalStationThread extends Thread{
36 Logger logger = LoggerFactory.getLogger(this.getClass()); 38 Logger logger = LoggerFactory.getLogger(this.getClass());
37 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); 39 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
38 40
  41 + @Autowired
  42 + DirectiveService directiveService;
  43 +
39 private static int diff = 1000 * 60 * 20; 44 private static int diff = 1000 * 60 * 20;
40 45
41 @Override 46 @Override
@@ -53,7 +58,7 @@ public class GpsArrivalStationThread extends Thread{ @@ -53,7 +58,7 @@ public class GpsArrivalStationThread extends Thread{
53 System.out.println("开始..."); 58 System.out.println("开始...");
54 List<ScheduleRealInfo> schList; 59 List<ScheduleRealInfo> schList;
55 for(String key : keySet){ 60 for(String key : keySet){
56 - schList = ScheduleBuffer.vehLinkedMap.get(key); 61 + schList = extractSched(ScheduleBuffer.vehLinkedMap.get(key));
57 if(null != schList) 62 if(null != schList)
58 match(GpsArrivalDataBuffer.allMap.get(key), schList); 63 match(GpsArrivalDataBuffer.allMap.get(key), schList);
59 } 64 }
@@ -104,7 +109,7 @@ public class GpsArrivalStationThread extends Thread{ @@ -104,7 +109,7 @@ public class GpsArrivalStationThread extends Thread{
104 */ 109 */
105 public void matchStart(ScheduleRealInfo scInfo, ArrivalInfo arr){ 110 public void matchStart(ScheduleRealInfo scInfo, ArrivalInfo arr){
106 if(scInfo.getFcsjT() == null 111 if(scInfo.getFcsjT() == null
107 - || arr.getInOut() != 1) 112 + || arr.getInOut() != 1 || scInfo.getFcsjActual() != null)
108 return; 113 return;
109 114
110 Long ts = arr.getTs(); 115 Long ts = arr.getTs();
@@ -115,6 +120,8 @@ public class GpsArrivalStationThread extends Thread{ @@ -115,6 +120,8 @@ public class GpsArrivalStationThread extends Thread{
115 scInfo.setFcsjActual(sdf.format(ts)); 120 scInfo.setFcsjActual(sdf.format(ts));
116 121
117 System.out.println("成功匹配一个起点..."); 122 System.out.println("成功匹配一个起点...");
  123 + //班次状态改为正在执行
  124 + scInfo.setStatus(1);
118 ScheduleBuffer.persistentList.add(scInfo); 125 ScheduleBuffer.persistentList.add(scInfo);
119 } 126 }
120 } 127 }
@@ -127,7 +134,7 @@ public class GpsArrivalStationThread extends Thread{ @@ -127,7 +134,7 @@ public class GpsArrivalStationThread extends Thread{
127 */ 134 */
128 public void matchEnd(ScheduleRealInfo scInfo, ArrivalInfo arr){ 135 public void matchEnd(ScheduleRealInfo scInfo, ArrivalInfo arr){
129 if(scInfo.getZdsjT() == null 136 if(scInfo.getZdsjT() == null
130 - || arr.getInOut() != 0) 137 + || arr.getInOut() != 0 || scInfo.getZdsjActual() != null)
131 return; 138 return;
132 139
133 Long ts = arr.getTs(); 140 Long ts = arr.getTs();
@@ -138,7 +145,10 @@ public class GpsArrivalStationThread extends Thread{ @@ -138,7 +145,10 @@ public class GpsArrivalStationThread extends Thread{
138 scInfo.setZdsjActual(sdf.format(ts)); 145 scInfo.setZdsjActual(sdf.format(ts));
139 146
140 System.out.println("成功匹配一个终点..."); 147 System.out.println("成功匹配一个终点...");
141 - ScheduleBuffer.persistentList.add(scInfo); 148 + //完成当前班次
  149 + ScheduleRealInfo nextSch = ScheduleBuffer.finishSch(scInfo);
  150 + //到达终点,发送下一班次的调度指令
  151 + directiveService.send60Dispatch(nextSch, ScheduleBuffer.getFinishSchNo(nextSch.getClZbh()));
142 } 152 }
143 } 153 }
144 154
@@ -190,4 +200,26 @@ public class GpsArrivalStationThread extends Thread{ @@ -190,4 +200,26 @@ public class GpsArrivalStationThread extends Thread{
190 } 200 }
191 return list; 201 return list;
192 } 202 }
  203 +
  204 + Long rang = 1000 * 60 * 60L;
  205 + /**
  206 + *
  207 + * @Title: extractSched
  208 + * @Description: TODO(提取当前时间前后一小时的计划)
  209 + * @param @param allList
  210 + * @throws
  211 + */
  212 + public List<ScheduleRealInfo> extractSched(List<ScheduleRealInfo> allList){
  213 + List<ScheduleRealInfo> subList = new ArrayList<>();
  214 + System.out.println("原计划:" + allList.size());
  215 + Long t = System.currentTimeMillis();
  216 + for(ScheduleRealInfo sch : allList){
  217 + if(Math.abs(sch.getFcsjT() - t) < rang
  218 + || Math.abs(sch.getZdsjT()) - t < rang){
  219 + subList.add(sch);
  220 + }
  221 + }
  222 + System.out.println("按时间提取:" + subList.size());
  223 + return subList;
  224 + }
193 } 225 }
src/main/java/com/bsth/vehicle/gpsdata/GpsRefreshThread.java
@@ -68,7 +68,6 @@ public class GpsRefreshThread extends Thread{ @@ -68,7 +68,6 @@ public class GpsRefreshThread extends Thread{
68 Set<Integer> upLines = new HashSet<>(); 68 Set<Integer> upLines = new HashSet<>();
69 69
70 for(GpsRealData newData : newList){ 70 for(GpsRealData newData : newList){
71 -  
72 oldGps = deviceMap.get(newData.getDeviceId()); 71 oldGps = deviceMap.get(newData.getDeviceId());
73 72
74 //新的GPS点 73 //新的GPS点
@@ -99,8 +98,8 @@ public class GpsRefreshThread extends Thread{ @@ -99,8 +98,8 @@ public class GpsRefreshThread extends Thread{
99 * @throws 98 * @throws
100 */ 99 */
101 public List<GpsRealData> getterRealGpsData() throws Exception{ 100 public List<GpsRealData> getterRealGpsData() throws Exception{
102 - List<GpsRealData> list = new ArrayList<>();  
103 - 101 + List<GpsRealData> list = new ArrayList<>()
  102 + ,rs = new ArrayList<>();
104 CloseableHttpClient httpClient = null; 103 CloseableHttpClient httpClient = null;
105 104
106 try { 105 try {
@@ -122,8 +121,14 @@ public class GpsRefreshThread extends Thread{ @@ -122,8 +121,14 @@ public class GpsRefreshThread extends Thread{
122 121
123 JSONObject jsonObj = JSON.parseObject(stringBuffer.toString()); 122 JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());
124 123
125 - if(jsonObj != null) 124 + if(jsonObj != null){
126 list = JSON.parseArray(jsonObj.getString("data"), GpsRealData.class); 125 list = JSON.parseArray(jsonObj.getString("data"), GpsRealData.class);
  126 + //将无效的经纬度过滤掉
  127 + for(GpsRealData gps : list){
  128 + if(gps.getLat() != 0 && gps.getLon() != 0)
  129 + rs.add(gps);
  130 + }
  131 + }
127 } 132 }
128 else 133 else
129 logger.error("result is null"); 134 logger.error("result is null");
@@ -135,6 +140,6 @@ public class GpsRefreshThread extends Thread{ @@ -135,6 +140,6 @@ public class GpsRefreshThread extends Thread{
135 if(null != httpClient) 140 if(null != httpClient)
136 httpClient.close(); 141 httpClient.close();
137 } 142 }
138 - return list; 143 + return rs;
139 } 144 }
140 } 145 }
src/main/java/com/bsth/vehicle/gpsdata/buffer/GpsArrivalDataBuffer.java
@@ -2,7 +2,6 @@ package com.bsth.vehicle.gpsdata.buffer; @@ -2,7 +2,6 @@ package com.bsth.vehicle.gpsdata.buffer;
2 2
3 import java.util.Collections; 3 import java.util.Collections;
4 import java.util.Comparator; 4 import java.util.Comparator;
5 -import java.util.Date;  
6 import java.util.List; 5 import java.util.List;
7 6
8 import com.bsth.vehicle.common.CommonMapped; 7 import com.bsth.vehicle.common.CommonMapped;
src/main/java/com/bsth/vehicle/gpsdata/service/GpsDataServiceImpl.java
@@ -34,7 +34,7 @@ public class GpsDataServiceImpl implements GpsDataService{ @@ -34,7 +34,7 @@ public class GpsDataServiceImpl implements GpsDataService{
34 return null; 34 return null;
35 }*/ 35 }*/
36 36
37 - String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE from BSTH_C_GPS_INFO where days_year=? and device_id=? and ts > ? and ts < ?"; 37 + String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO from BSTH_C_GPS_INFO where days_year=? and device_id=? and ts > ? and ts < ?";
38 Connection conn = null; 38 Connection conn = null;
39 PreparedStatement ps = null; 39 PreparedStatement ps = null;
40 ResultSet rs = null; 40 ResultSet rs = null;
@@ -68,6 +68,7 @@ public class GpsDataServiceImpl implements GpsDataService{ @@ -68,6 +68,7 @@ public class GpsDataServiceImpl implements GpsDataService{
68 map.put("lon", location.getLng()); 68 map.put("lon", location.getLng());
69 map.put("lat", location.getLat()); 69 map.put("lat", location.getLat());
70 map.put("ts", rs.getLong("TS")); 70 map.put("ts", rs.getLong("TS"));
  71 + map.put("stopNo", rs.getString("STOP_NO"));
71 map.put("inout_stop", rs.getInt("INOUT_STOP")); 72 map.put("inout_stop", rs.getInt("INOUT_STOP"));
72 //上下行 73 //上下行
73 map.put("upDown", upDown); 74 map.put("upDown", upDown);
src/main/resources/static/gpsTest/test.html
@@ -99,6 +99,8 @@ form .item select{ @@ -99,6 +99,8 @@ form .item select{
99 99
100 var inOuts = [outMark, inMark]; 100 var inOuts = [outMark, inMark];
101 101
  102 + var stationCodeMap = {};
  103 +
102 var map = new BMap.Map("mapContainer"); 104 var map = new BMap.Map("mapContainer");
103 map.centerAndZoom(new BMap.Point(121.544336, 31.221315), 15); 105 map.centerAndZoom(new BMap.Point(121.544336, 31.221315), 15);
104 map.enableScrollWheelZoom(); 106 map.enableScrollWheelZoom();
@@ -123,7 +125,9 @@ form .item select{ @@ -123,7 +125,9 @@ form .item select{
123 var array = rs[0].children[0].children 125 var array = rs[0].children[0].children
124 ,coords,circle, cdsArray, points, polygon; 126 ,coords,circle, cdsArray, points, polygon;
125 //画出站点 127 //画出站点
  128 + console.log(array);
126 $.each(array, function(){ 129 $.each(array, function(){
  130 + stationCodeMap[this.stationStationCod] = this.name;
127 if(this.stationShapesType === 'r'){ 131 if(this.stationShapesType === 'r'){
128 //画圆 132 //画圆
129 coords = this.stationBJwpoints.split(' '); 133 coords = this.stationBJwpoints.split(' ');
@@ -158,11 +162,13 @@ form .item select{ @@ -158,11 +162,13 @@ form .item select{
158 point = new BMap.Point(this.lon, this.lat); 162 point = new BMap.Point(this.lon, this.lat);
159 marker = new BMap.Marker(point); 163 marker = new BMap.Marker(point);
160 state = this.inout_stop; 164 state = this.inout_stop;
161 - //inOuts 165 +
162 if(state == 0 || state == 1){ 166 if(state == 0 || state == 1){
163 text = state == 0?'出':'进'; 167 text = state == 0?'出':'进';
164 marker.setIcon(new BMap.Icon(inOuts[this.inout_stop], new BMap.Size(25,25))); 168 marker.setIcon(new BMap.Icon(inOuts[this.inout_stop], new BMap.Size(25,25)));
165 - label = new BMap.Label(moment(this.ts).format('HH:mm') + ' -'+text, {position: point, offset: new BMap.Size(-5,-18)}); 169 + label = new BMap.Label(
  170 + stationCodeMap[this.stopNo] + '/' +moment(this.ts).format('HH:mm') + ' -'+text
  171 + , {position: point, offset: new BMap.Size(-25,-18)});
166 marker.setLabel(label); 172 marker.setLabel(label);
167 } 173 }
168 map.addOverlay(marker); 174 map.addOverlay(marker);
src/main/resources/static/index.html
@@ -281,9 +281,9 @@ tr.row-active td { @@ -281,9 +281,9 @@ tr.row-active td {
281 <script src="http://api.map.baidu.com/api?v=2.0&ak=IGGrr4UjwIYzatoCRFKEL8sT" data-exclude=1></script> 281 <script src="http://api.map.baidu.com/api?v=2.0&ak=IGGrr4UjwIYzatoCRFKEL8sT" data-exclude=1></script>
282 <script src="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.js" data-exclude=1></script> 282 <script src="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.js" data-exclude=1></script>
283 <script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js" data-exclude=1></script> 283 <script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js" data-exclude=1></script>
284 -<script type="text/javascript" src="http://api.map.baidu.com/library/RichMarker/1.2/src/RichMarker_min.js ">  
285 -<script src="/assets/js/baidu/TextIconOverlay.js"></script>  
286 -<script src="/assets/js/baidu//MarkerClusterer.js"></script> 284 +<script type="text/javascript" src="http://api.map.baidu.com/library/RichMarker/1.2/src/RichMarker_min.js " data-exclude=1></script>
  285 +<script src="/assets/js/baidu/TextIconOverlay.js" data-exclude=1></script>
  286 +<script src="/assets/js/baidu//MarkerClusterer.js" data-exclude=1></script>
287 <!-- 高德 --> 287 <!-- 高德 -->
288 <script src="http://webapi.amap.com/maps?v=1.3&key=16cb1c5043847e09ef9edafdd77befda" data-exclude=1></script> 288 <script src="http://webapi.amap.com/maps?v=1.3&key=16cb1c5043847e09ef9edafdd77befda" data-exclude=1></script>
289 289
src/main/resources/static/pages/control/line/child_pages/child_task.html
@@ -325,7 +325,6 @@ $(function(){ @@ -325,7 +325,6 @@ $(function(){
325 lineInformation = _data.getLineInformation(schedul.xlBm); 325 lineInformation = _data.getLineInformation(schedul.xlBm);
326 //线路 ——> 路牌 ——> 班次映射 326 //线路 ——> 路牌 ——> 班次映射
327 scheduleLineMap = _data.getLineLpMap(); 327 scheduleLineMap = _data.getLineLpMap();
328 -  
329 //线路下拉框数据 328 //线路下拉框数据
330 lineCodeMaps = _data.getLineIds(); 329 lineCodeMaps = _data.getLineIds();
331 for(var lineCode in scheduleLineMap){ 330 for(var lineCode in scheduleLineMap){
@@ -369,8 +368,8 @@ $(function(){ @@ -369,8 +368,8 @@ $(function(){
369 refreshMainList(); 368 refreshMainList();
370 }); 369 });
371 } 370 }
372 -  
373 - jsyAndSpyInit(lineCode); 371 + //更新临加表单的车辆和人员下拉框
  372 + carAndPersInit(lineCode);
374 } 373 }
375 374
376 /** 375 /**
@@ -388,7 +387,7 @@ $(function(){ @@ -388,7 +387,7 @@ $(function(){
388 387
389 var schArray = []; 388 var schArray = [];
390 $.each(scheduls, function(){ 389 $.each(scheduls, function(){
391 - schArray[this.fcno] = this; 390 + schArray[this.fcno - 1] = this;
392 }); 391 });
393 392
394 var htmlStr = template('child_task_main_table_temp', {list: schArray}); 393 var htmlStr = template('child_task_main_table_temp', {list: schArray});
@@ -407,16 +406,20 @@ $(function(){ @@ -407,16 +406,20 @@ $(function(){
407 /** ----------- 临加班次相关 ----------*/ 406 /** ----------- 临加班次相关 ----------*/
408 //初始化临加班次表单 407 //初始化临加班次表单
409 $('#schedulTempAddPabel').append(template('schedul_add_form_temp', {})); 408 $('#schedulTempAddPabel').append(template('schedul_add_form_temp', {}));
410 - //初始化驾驶员和售票员下拉框,每次切换线路时调用  
411 - var jsyAndSpyInit = function(lineCode){ 409 + //初始化车辆和人员下拉框,每次切换线路时调用
  410 + var carAndPersInit = function(lineCode){
412 //驾驶员 411 //驾驶员
413 $.get('/realSchedule/driver', {lineCode: lineCode}, function(rs){ 412 $.get('/realSchedule/driver', {lineCode: lineCode}, function(rs){
414 - initPinYinSelect2('select[name=jGh]', rs); 413 + initPinYinSelect2('#schedulTempAddPabel select[name=jGh]', rs);
415 414
416 }); 415 });
417 //售票员 416 //售票员
418 $.get('/realSchedule/conductor', {lineCode: lineCode}, function(rs){ 417 $.get('/realSchedule/conductor', {lineCode: lineCode}, function(rs){
419 - initPinYinSelect2('select[name=sGh]', rs); 418 + initPinYinSelect2('#schedulTempAddPabel select[name=sGh]', rs);
  419 + });
  420 + //车辆
  421 + $.get('/realSchedule/cars', {lineCode: lineCode}, function(rs){
  422 + $('#schedulTempAddPabel select[name=clZbh]').select2({data: rs});
420 }); 423 });
421 }; 424 };
422 425
@@ -429,12 +432,11 @@ $(function(){ @@ -429,12 +432,11 @@ $(function(){
429 schAddPanel.on('show', function(e, tr){ 432 schAddPanel.on('show', function(e, tr){
430 $(this).show(); 433 $(this).show();
431 $('input.no', schAddPanel).val($(tr.cells[0]).text()); 434 $('input.no', schAddPanel).val($(tr.cells[0]).text());
  435 + $('select[name=xlDir]', schAddPanel).trigger('change');
432 }); 436 });
433 //切换上下行 437 //切换上下行
434 $(schAddPanel).on('change', 'select[name=xlDir]', function(){ 438 $(schAddPanel).on('change', 'select[name=xlDir]', function(){
435 var t = $(this).val(); 439 var t = $(this).val();
436 - if(!t)  
437 - return;  
438 440
439 var arr = stationRoute[t] 441 var arr = stationRoute[t]
440 ,ss = arr[0].stationCode 442 ,ss = arr[0].stationCode
@@ -442,7 +444,6 @@ $(function(){ @@ -442,7 +444,6 @@ $(function(){
442 ,ops = createSelectOps(arr, 'stationCode', 'stationName'); 444 ,ops = createSelectOps(arr, 'stationCode', 'stationName');
443 schAddQdz.html(ops).val(ss); 445 schAddQdz.html(ops).val(ss);
444 schAddZdz.html(ops).val(es); 446 schAddZdz.html(ops).val(es);
445 -  
446 //里程 447 //里程
447 var mileage; 448 var mileage;
448 if(t == 0) 449 if(t == 0)
@@ -452,6 +453,51 @@ $(function(){ @@ -452,6 +453,51 @@ $(function(){
452 453
453 $('input[name=jhlc]', schAddPanel).val(mileage); 454 $('input[name=jhlc]', schAddPanel).val(mileage);
454 }); 455 });
  456 + //切换班次类型
  457 + $(schAddPanel).on('change', 'select[name=bcType]', function(){
  458 + var type = $(this).val()
  459 + ,upDown = $('select[name=xlDir]', schAddPanel)
  460 + ,routes = stationRoute[upDown];
  461 + //起点停车场
  462 + switch (type) {
  463 + case 'out':
  464 + schAddQdz.html(parkSelectOps).val(lineInformation.carPark);
  465 + break;
  466 + case 'in':
  467 + schAddZdz.html(parkSelectOps).val(lineInformation.carPark);
  468 + break;
  469 + }
  470 +
  471 + var zdHtml = createSelectOps(routes, 'stationCode', 'stationName');
  472 + //schAddZdz.html(zdHtml).val();
  473 + });
  474 +
  475 + //提交临加班次
  476 + $('.confirm', schAddPanel).on('click', function(){
  477 + var f = $('form', schAddPanel);
  478 + var param = f.serializeJSON();
  479 + /** 页面组装数据 */
  480 + //线路
  481 + param.xlBm = lineSelect.val();
  482 + param.xlName = _data.getLineIds()[param.xlBm];
  483 + //路牌
  484 + param.lpName = lpSelect.val();
  485 + //拆分驾驶员工号和姓名
  486 + param.jName = param.jGh.split('/')[1];
  487 + param.jGh = param.jGh.split('/')[0];
  488 + //拆分售票员工号和姓名
  489 + param.sName = param.sGh.split('/')[1];
  490 + param.sGh = param.sGh.split('/')[0];
  491 + //附加起终点名称
  492 + var route = stationRoute[param.xlDir];
  493 + param.qdzName = searchStationName(route, param.qdzCode);
  494 + param.zdzName = searchStationName(route, param.zdzCode);
  495 +
  496 + $post('/realSchedule', param, function(rs){
  497 + //前端缓存更新
  498 + scheduleLineMap[param.xlBm][param.lpName].push(rs.t);
  499 + });
  500 + });
455 501
456 function createSelectOps(selectData, id, text){ 502 function createSelectOps(selectData, id, text){
457 var ops = ''; 503 var ops = '';
@@ -460,5 +506,13 @@ $(function(){ @@ -460,5 +506,13 @@ $(function(){
460 }); 506 });
461 return ops; 507 return ops;
462 } 508 }
  509 +
  510 + //在路由里根据站点编码搜索站点名
  511 + function searchStationName(route, code){
  512 + for(var i = 0, r; r = route[i++];){
  513 + if(r.stationCode == code)
  514 + return r.stationName;
  515 + }
  516 + }
463 }); 517 });
464 </script> 518 </script>
src/main/resources/static/pages/control/line/js/alone.js
@@ -53,7 +53,7 @@ var _alone = (function(){ @@ -53,7 +53,7 @@ var _alone = (function(){
53 cb && cb(); 53 cb && cb();
54 }); 54 });
55 }, 55 },
56 - //刷新班次 56 + //刷新单个班次
57 refreshSchedule: function(schedule){ 57 refreshSchedule: function(schedule){
58 //xlBm 58 //xlBm
59 var $tr = $('tr[data-id='+schedule.id+']', '#tab_line_' + schedule.xlBm) 59 var $tr = $('tr[data-id='+schedule.id+']', '#tab_line_' + schedule.xlBm)
src/main/resources/static/pages/control/line/js/data.js
@@ -85,16 +85,14 @@ var _data = (function(){ @@ -85,16 +85,14 @@ var _data = (function(){
85 $.each(list, function(){ 85 $.each(list, function(){
86 //发车时间 + 历时 = 终点时间 86 //发车时间 + 历时 = 终点时间
87 if(this.bcsj){ 87 if(this.bcsj){
88 - sm = moment(dateStr + ' ' + this.fcsj, 'YYYY-MM-DD HH:mm'); 88 + sm = moment(this.fcsjT);
89 em = sm.add(this.bcsj, 'minutes'); 89 em = sm.add(this.bcsj, 'minutes');
90 - //发车时间戳  
91 - this.fcsjT = sm.valueOf();  
92 this.zdsj = em.format('HH:mm'); 90 this.zdsj = em.format('HH:mm');
93 //终点时间戳 91 //终点时间戳
94 this.zdsjT = em.valueOf(); 92 this.zdsjT = em.valueOf();
95 } 93 }
96 94
97 - //缓存实际排班计划 95 + //缓存排班计划
98 schedules[this.id] = this; 96 schedules[this.id] = this;
99 scheduleList.push(this); 97 scheduleList.push(this);
100 98
src/main/resources/static/pages/control/line/temps/alone_tp.html
@@ -153,8 +153,8 @@ @@ -153,8 +153,8 @@
153 <td data-name="clZbh">{{item.clZbh}}</td> 153 <td data-name="clZbh">{{item.clZbh}}</td>
154 <td data-name="zdsj">{{item.zdsj}}</td> 154 <td data-name="zdsj">{{item.zdsj}}</td>
155 <td></td> 155 <td></td>
156 - <td data-name="fcsj">{{item.fcsj}}</td>  
157 - <td data-name="dfsj">{{item.dfsj}}</td> 156 + <td data-name="fcsj" data-time="{{item.fcsjT}}">{{item.fcsj}}</td>
  157 + <td data-name="dfsj" data-time="{{item.zdsjT}}">{{item.dfsj}}</td>
158 158
159 {{if item.status == -1}} 159 {{if item.status == -1}}
160 <td class="tl-qrlb">烂班</td> 160 <td class="tl-qrlb">烂班</td>
src/main/resources/static/pages/control/line/temps/child_task_case_tp.html
@@ -421,20 +421,20 @@ @@ -421,20 +421,20 @@
421 <div class="row"> 421 <div class="row">
422 <div class="col-md-4"> 422 <div class="col-md-4">
423 <span class="custom-label">班次类型: </span> 423 <span class="custom-label">班次类型: </span>
424 - <select class="form-control nt-dictionary" data-group="ScheduleType" name="bcType"></select> 424 + <select class="form-control nt-dictionary" data-group="ScheduleType" data-code="normal" name="bcType"></select>
425 </div> 425 </div>
426 <div class="col-md-4"> 426 <div class="col-md-4">
427 </div> 427 </div>
428 <div class="col-md-4"> 428 <div class="col-md-4">
429 <span class="custom-label">上下行: </span> 429 <span class="custom-label">上下行: </span>
430 - <select class="form-control nt-dictionary" data-group="LineTrend" name="xlDir" ></select> 430 + <select class="form-control nt-dictionary" data-group="LineTrend" name="xlDir" data-code=0></select>
431 </div> 431 </div>
432 </div> 432 </div>
433 433
434 <div class="row"> 434 <div class="row">
435 <div class="col-md-4"> 435 <div class="col-md-4">
436 <span class="custom-label">序号: </span> 436 <span class="custom-label">序号: </span>
437 - <input class="form-control no" disabled> 437 + <input class="form-control no" readonly name="fcno" >
438 </div> 438 </div>
439 <div class="col-md-4"> 439 <div class="col-md-4">
440 <span class="custom-label">开始时间: </span> 440 <span class="custom-label">开始时间: </span>