Commit 890624bf7f702019f32b02b21dce21740d519770

Authored by 廖磊
2 parents f74ce142 253fa772

Merge branch 'master' of 192.168.168.201:panzhaov5/control_service_data_Interface

src/main/java/com/bsth/CXFConfig.java
... ... @@ -16,6 +16,7 @@ import com.bsth.server_rs.logs.RealLogRestService;
16 16 import com.bsth.server_rs.schedule.plan.SchedulePlanService;
17 17 import com.bsth.server_rs.schedule.real.ScheduleRealService;
18 18 import com.bsth.server_rs.schedule.real.StaffViewRealService;
  19 +import com.bsth.server_rs.waybill.WaybillRestService;
19 20 import com.bsth.server_ws.attendance.AttendanceServiceSoap;
20 21 import com.bsth.server_ws.electric_oil.OilServiceSoap;
21 22 import com.bsth.server_ws.park_station.CompanyServiceSoap;
... ... @@ -101,6 +102,8 @@ public class CXFConfig {
101 102 @Autowired
102 103 GpsRestService gpsRestService;
103 104 @Autowired
  105 + WaybillRestService waybillRestService;
  106 + @Autowired
104 107 DirectiveRestService directiveRestService;
105 108 @Autowired
106 109 LD_RoadSpeedRestService ld_roadSpeedRestService;
... ... @@ -121,6 +124,7 @@ public class CXFConfig {
121 124 new CarRestService(),
122 125 new PersonRestService(),
123 126 gpsRestService,
  127 + waybillRestService,
124 128 scheduleRealService,
125 129 stationRestService,
126 130 ldSectionRestService,
... ...
src/main/java/com/bsth/entity/ScheduleRealInfo.java
1   -package com.bsth.entity;
2   -
3   -import org.joda.time.format.DateTimeFormat;
4   -import org.joda.time.format.DateTimeFormatter;
5   -
6   -import javax.persistence.*;
7   -import java.io.Serializable;
8   -import java.util.Date;
9   -import java.util.HashSet;
10   -import java.util.Set;
11   -
12   -/**
13   - * 实际排班计划明细。
14   - */
15   -@Entity
16   -@Table(name = "bsth_c_s_sp_info_real")
17   -@NamedEntityGraphs({
18   - @NamedEntityGraph(name = "scheduleRealInfo_cTasks", attributeNodes = {
19   - @NamedAttributeNode("cTasks")
20   - })
21   -})
22   -public class ScheduleRealInfo implements Serializable{
23   -
24   -
25   -
26   - /** 主键Id */
27   - @Id
28   - private Long id;
29   -
30   - /** 计划ID */
31   - private Long spId;
32   -
33   - /** 排班计划日期 */
34   - private Date scheduleDate;
35   - private String scheduleDateStr;
36   -
37   - /** 真实执行时间 yyyy-MM-dd */
38   - private String realExecDate;
39   -
40   - /** 线路名称 */
41   - private String xlName;
42   - /** 线路编码 */
43   - private String xlBm;
44   -
45   - /** 路牌名称 */
46   - private String lpName;
47   -
48   - /** 车辆自编号 */
49   - private String clZbh;
50   -
51   - /** 驾驶员工号 */
52   - private String jGh;
53   - /** 驾驶员名字 */
54   - private String jName;
55   - /** 售票员工号 */
56   - private String sGh;
57   - /** 售票员名字 */
58   - private String sName;
59   -
60   - /** 线路方向 */
61   - private String xlDir;
62   - /** 起点站code*/
63   - private String qdzCode;
64   - /** 起点站名字 */
65   - private String qdzName;
66   -
67   - /** 终点站code*/
68   - private String zdzCode;
69   - /** 终点站名字 */
70   - private String zdzName;
71   -
72   - /** 计划发车时间(格式 HH:mm) */
73   - private String fcsj;
74   - /** 计划发车时间戳*/
75   - @Transient
76   - private Long fcsjT;
77   -
78   - /** 计划终点时间(格式 HH:mm) */
79   - private String zdsj;
80   - /** 计划终点时间戳*/
81   - @Transient
82   - private Long zdsjT;
83   -
84   - /** 发车顺序号 */
85   - private Integer fcno;
86   - /** 对应班次数 */
87   - private Integer bcs;
88   - /** 计划里程 */
89   - private Double jhlc;
90   -
91   - /** 原始计划里程 (原计调的数据) */
92   - private Double jhlcOrig;
93   -
94   - /** 班次历时 */
95   - private Integer bcsj;
96   -
97   - /**
98   - * 班次类型 TODO:正常班次、出场、进场、加油、区间班次、放空班次、放大站班次、两点间空驶
99   - */
100   - private String bcType;
101   -
102   - /** 创建日期 */
103   - @Column(name = "create_date")
104   - private Date createDate;
105   - /** 修改日期 */
106   - @Column(name = "update_date")
107   - private Date updateDate;
108   -
109   - /** 实际发车时间*/
110   - private String fcsjActual;
111   - /** 实际发车时间戳*/
112   - @Transient
113   - private Long fcsjActualTime;
114   - /**实际终点时间 */
115   - private String zdsjActual;
116   - /** 实际终点时间戳*/
117   - @Transient
118   - private Long zdsjActualTime;
119   -
120   - /**班次状态 0 未执行 1 正在执行 2 已执行 -1 已烂班 */
121   - private int status;
122   -
123   - private String adjustExps;
124   -
125   - /** 是否是临加班次 */
126   - private boolean sflj;
127   -
128   - /** 是否误点*/
129   - @Transient
130   - private boolean late;
131   -
132   - /** 备注*/
133   - private String remarks;
134   -
135   - /**待发时间(格式 HH:mm) */
136   - private String dfsj;
137   -
138   - /**待发时间戳 */
139   - @Transient
140   - private Long dfsjT;
141   -
142   - /** 指令下发状态 60: 已发送, 100: 设备确认收到, 200:驾驶员确认 0:失败 */
143   - private Integer directiveState = -1;
144   -
145   - /** 起点站计划到达时间 */
146   - @Transient
147   - private String qdzArrDatejh;
148   -
149   - /** 起点站实际到达时间 */
150   - @Transient
151   - private String qdzArrDatesj;
152   -
153   - /** 子任务 */
154   - @OneToMany(fetch = FetchType.LAZY, mappedBy = "schedule")
155   - private Set<ChildTaskPlan> cTasks = new HashSet<>();
156   -
157   - /** 关联的公司名称 */
158   - private String gsName;
159   - /** 关联的公司编码 */
160   - private String gsBm;
161   - /** 关联的分公司名称 */
162   - private String fgsName;
163   - /** 关联的分公司编码 */
164   - private String fgsBm;
165   - /** 出场顺序号 */
166   - private Integer ccno;
167   -
168   - //待发调试(是否自动调整)
169   - private boolean dfAuto;
170   - //是否有GPS信号
171   - private boolean online;
172   -
173   - /** 是否有补发GPS信号 */
174   - private boolean reissue;
175   -
176   - @Override
177   - public int hashCode() {
178   - return (this.id + this.scheduleDateStr + this.xlBm + this.fcsj).hashCode();
179   - }
180   -
181   - @Override
182   - public boolean equals(Object obj) {
183   - return this.id.equals(((ScheduleRealInfo)obj).getId());
184   - }
185   -
186   - public Long getId() {
187   - return id;
188   - }
189   -
190   - public void setId(Long id) {
191   - this.id = id;
192   - }
193   -
194   - public Long getSpId() {
195   - return spId;
196   - }
197   -
198   - public void setSpId(Long spId) {
199   - this.spId = spId;
200   - }
201   -
202   - public Date getScheduleDate() {
203   - return scheduleDate;
204   - }
205   -
206   - public void setScheduleDate(Date scheduleDate) {
207   - this.scheduleDate = scheduleDate;
208   - }
209   -
210   - public String getScheduleDateStr() {
211   - return scheduleDateStr;
212   - }
213   -
214   - public void setScheduleDateStr(String scheduleDateStr) {
215   - this.scheduleDateStr = scheduleDateStr;
216   - }
217   -
218   - public String getRealExecDate() {
219   - return realExecDate;
220   - }
221   -
222   - public void setRealExecDate(String realExecDate) {
223   - this.realExecDate = realExecDate;
224   - }
225   -
226   - public String getXlName() {
227   - return xlName;
228   - }
229   -
230   - public void setXlName(String xlName) {
231   - this.xlName = xlName;
232   - }
233   -
234   - public String getXlBm() {
235   - return xlBm;
236   - }
237   -
238   - public void setXlBm(String xlBm) {
239   - this.xlBm = xlBm;
240   - }
241   -
242   - public String getLpName() {
243   - return lpName;
244   - }
245   -
246   - public void setLpName(String lpName) {
247   - this.lpName = lpName;
248   - }
249   -
250   - public String getClZbh() {
251   - return clZbh;
252   - }
253   -
254   - public void setClZbh(String clZbh) {
255   - this.clZbh = clZbh;
256   - }
257   -
258   - public String getjGh() {
259   - return jGh;
260   - }
261   -
262   - public void setjGh(String jGh) {
263   - this.jGh = jGh;
264   - }
265   -
266   - public String getjName() {
267   - return jName;
268   - }
269   -
270   - public void setjName(String jName) {
271   - this.jName = jName;
272   - }
273   -
274   - public String getsGh() {
275   - return sGh;
276   - }
277   -
278   - public void setsGh(String sGh) {
279   - this.sGh = sGh;
280   - }
281   -
282   - public String getsName() {
283   - return sName;
284   - }
285   -
286   - public void setsName(String sName) {
287   - this.sName = sName;
288   - }
289   -
290   - public String getXlDir() {
291   - return xlDir;
292   - }
293   -
294   - public void setXlDir(String xlDir) {
295   - this.xlDir = xlDir;
296   - }
297   -
298   - public String getQdzCode() {
299   - return qdzCode;
300   - }
301   -
302   - public void setQdzCode(String qdzCode) {
303   - this.qdzCode = qdzCode;
304   - }
305   -
306   - public String getQdzName() {
307   - return qdzName;
308   - }
309   -
310   - public void setQdzName(String qdzName) {
311   - this.qdzName = qdzName;
312   - }
313   -
314   - public String getZdzCode() {
315   - return zdzCode;
316   - }
317   -
318   - public void setZdzCode(String zdzCode) {
319   - this.zdzCode = zdzCode;
320   - }
321   -
322   - public String getZdzName() {
323   - return zdzName;
324   - }
325   -
326   - public void setZdzName(String zdzName) {
327   - this.zdzName = zdzName;
328   - }
329   -
330   - public String getFcsj() {
331   - return fcsj;
332   - }
333   -
334   - public void setFcsj(String fcsj) {
335   - this.fcsj = fcsj;
336   - }
337   -
338   - public Long getFcsjT() {
339   - return fcsjT;
340   - }
341   -
342   - public void setFcsjT(Long fcsjT) {
343   - this.fcsjT = fcsjT;
344   - }
345   -
346   - public String getZdsj() {
347   - return zdsj;
348   - }
349   -
350   - public void setZdsj(String zdsj) {
351   - this.zdsj = zdsj;
352   - }
353   -
354   - public Long getZdsjT() {
355   - return zdsjT;
356   - }
357   -
358   - public void setZdsjT(Long zdsjT) {
359   - this.zdsjT = zdsjT;
360   - }
361   -
362   - public Integer getFcno() {
363   - return fcno;
364   - }
365   -
366   - public void setFcno(Integer fcno) {
367   - this.fcno = fcno;
368   - }
369   -
370   - public Integer getBcs() {
371   - return bcs;
372   - }
373   -
374   - public void setBcs(Integer bcs) {
375   - this.bcs = bcs;
376   - }
377   -
378   - public Double getJhlc() {
379   - return jhlc;
380   - }
381   -
382   - public void setJhlc(Double jhlc) {
383   - this.jhlc = jhlc;
384   - }
385   -
386   - public Integer getBcsj() {
387   - return bcsj;
388   - }
389   -
390   - public void setBcsj(Integer bcsj) {
391   - this.bcsj = bcsj;
392   - }
393   -
394   - public String getBcType() {
395   - return bcType;
396   - }
397   -
398   - public void setBcType(String bcType) {
399   - this.bcType = bcType;
400   - }
401   -
402   - public Date getCreateDate() {
403   - return createDate;
404   - }
405   -
406   - public void setCreateDate(Date createDate) {
407   - this.createDate = createDate;
408   - }
409   -
410   - public Date getUpdateDate() {
411   - return updateDate;
412   - }
413   -
414   - public void setUpdateDate(Date updateDate) {
415   - this.updateDate = updateDate;
416   - }
417   -
418   - public String getFcsjActual() {
419   - return fcsjActual;
420   - }
421   -
422   - public void setFcsjActual(String fcsjActual) {
423   - this.fcsjActual = fcsjActual;
424   - }
425   -
426   - public Long getFcsjActualTime() {
427   - return fcsjActualTime;
428   - }
429   -
430   - public void setFcsjActualTime(Long fcsjActualTime) {
431   - this.fcsjActualTime = fcsjActualTime;
432   - }
433   -
434   - public String getZdsjActual() {
435   - return zdsjActual;
436   - }
437   -
438   - public void setZdsjActual(String zdsjActual) {
439   - this.zdsjActual = zdsjActual;
440   - }
441   -
442   - public Long getZdsjActualTime() {
443   - return zdsjActualTime;
444   - }
445   -
446   - public void setZdsjActualTime(Long zdsjActualTime) {
447   - this.zdsjActualTime = zdsjActualTime;
448   - }
449   -
450   - public int getStatus() {
451   - return status;
452   - }
453   -
454   - public void setStatus(int status) {
455   - this.status = status;
456   - }
457   -
458   - public String getAdjustExps() {
459   - return adjustExps;
460   - }
461   -
462   - public void setAdjustExps(String adjustExps) {
463   - this.adjustExps = adjustExps;
464   - }
465   -
466   - public boolean isSflj() {
467   - return sflj;
468   - }
469   -
470   - public void setSflj(boolean sflj) {
471   - this.sflj = sflj;
472   - }
473   -
474   - public boolean isLate() {
475   - return late;
476   - }
477   -
478   - public void setLate(boolean late) {
479   - this.late = late;
480   - }
481   -
482   - public String getRemarks() {
483   - return remarks;
484   - }
485   -
486   - public void setRemarks(String remarks) {
487   - this.remarks = remarks;
488   - }
489   -
490   - public String getDfsj() {
491   - return dfsj;
492   - }
493   -
494   - public void setDfsj(String dfsj) {
495   - this.dfsj = dfsj;
496   - }
497   -
498   - public Long getDfsjT() {
499   - return dfsjT;
500   - }
501   -
502   - public void setDfsjT(Long dfsjT) {
503   - this.dfsjT = dfsjT;
504   - }
505   -
506   - public Integer getDirectiveState() {
507   - return directiveState;
508   - }
509   -
510   - public void setDirectiveState(Integer directiveState) {
511   - this.directiveState = directiveState;
512   - }
513   -
514   - public String getQdzArrDatejh() {
515   - return qdzArrDatejh;
516   - }
517   -
518   - public void setQdzArrDatejh(String qdzArrDatejh) {
519   - this.qdzArrDatejh = qdzArrDatejh;
520   - }
521   -
522   - public String getQdzArrDatesj() {
523   - return qdzArrDatesj;
524   - }
525   -
526   - public void setQdzArrDatesj(String qdzArrDatesj) {
527   - this.qdzArrDatesj = qdzArrDatesj;
528   - }
529   -
530   - public Set<ChildTaskPlan> getcTasks() {
531   - return cTasks;
532   - }
533   -
534   - public void setcTasks(Set<ChildTaskPlan> cTasks) {
535   - this.cTasks = cTasks;
536   - }
537   -
538   - public String getGsName() {
539   - return gsName;
540   - }
541   -
542   - public void setGsName(String gsName) {
543   - this.gsName = gsName;
544   - }
545   -
546   - public String getGsBm() {
547   - return gsBm;
548   - }
549   -
550   - public void setGsBm(String gsBm) {
551   - this.gsBm = gsBm;
552   - }
553   -
554   - public String getFgsName() {
555   - return fgsName;
556   - }
557   -
558   - public void setFgsName(String fgsName) {
559   - this.fgsName = fgsName;
560   - }
561   -
562   - public String getFgsBm() {
563   - return fgsBm;
564   - }
565   -
566   - public void setFgsBm(String fgsBm) {
567   - this.fgsBm = fgsBm;
568   - }
569   -
570   - public Integer getCcno() {
571   - return ccno;
572   - }
573   -
574   - public void setCcno(Integer ccno) {
575   - this.ccno = ccno;
576   - }
577   -
578   - public boolean isDfAuto() {
579   - return dfAuto;
580   - }
581   -
582   - public void setDfAuto(boolean dfAuto) {
583   - this.dfAuto = dfAuto;
584   - }
585   -
586   - public boolean isOnline() {
587   - return online;
588   - }
589   -
590   - public void setOnline(boolean online) {
591   - this.online = online;
592   - }
593   -
594   - public boolean isReissue() {
595   - return reissue;
596   - }
597   -
598   - public void setReissue(boolean reissue) {
599   - this.reissue = reissue;
600   - }
601   -
602   - public Double getJhlcOrig() {
603   - return jhlcOrig;
604   - }
605   -
606   - public void setJhlcOrig(Double jhlcOrig) {
607   - this.jhlcOrig = jhlcOrig;
608   - }
609   -
610   - @Transient
611   - private static DateTimeFormatter fmtHHmm = DateTimeFormat.forPattern("HH:mm");
612   - /**
613   - *
614   - * @Title: setFcsjActualAll
615   - * @Description: TODO(设置实际发车时间 时间戳)
616   - * @throws
617   - */
618   - public void setFcsjActualAll(Long t){
619   - this.fcsjActualTime = t;
620   - this.fcsjActual = fmtHHmm.print(t);
621   - }
622   -
623   - /**
624   - *
625   - * @Title: setFcsjActualAll
626   - * @Description: TODO(设置实际终点时间)
627   - * @throws
628   - */
629   - public void setZdsjActualAll(Long t){
630   - this.zdsjActualTime = t;
631   - this.zdsjActual = fmtHHmm.print(t);
632   - }
633   -}
  1 +package com.bsth.entity;
  2 +
  3 +import org.joda.time.format.DateTimeFormat;
  4 +import org.joda.time.format.DateTimeFormatter;
  5 +
  6 +import javax.persistence.*;
  7 +import java.io.Serializable;
  8 +import java.util.Date;
  9 +import java.util.HashSet;
  10 +import java.util.Set;
  11 +
  12 +/**
  13 + * 实际排班计划明细。
  14 + */
  15 +@Entity
  16 +@Table(name = "bsth_c_s_sp_info_real")
  17 +@NamedEntityGraphs({
  18 + @NamedEntityGraph(name = "scheduleRealInfo_cTasks", attributeNodes = {
  19 + @NamedAttributeNode("cTasks")
  20 + })
  21 +})
  22 +public class ScheduleRealInfo implements Serializable{
  23 +
  24 +
  25 +
  26 + /** 主键Id */
  27 + @Id
  28 + private Long id;
  29 +
  30 + /** 计划ID */
  31 + private Long spId;
  32 +
  33 + /** 排班计划日期 */
  34 + private Date scheduleDate;
  35 + private String scheduleDateStr;
  36 +
  37 + /** 真实执行时间 yyyy-MM-dd */
  38 + private String realExecDate;
  39 +
  40 + /** 线路名称 */
  41 + private String xlName;
  42 + /** 线路编码 */
  43 + private String xlBm;
  44 +
  45 + /** 路牌名称 */
  46 + private String lpName;
  47 +
  48 + /** 车辆自编号 */
  49 + private String clZbh;
  50 +
  51 + /** 驾驶员工号 */
  52 + private String jGh;
  53 + /** 驾驶员名字 */
  54 + private String jName;
  55 + /** 售票员工号 */
  56 + private String sGh;
  57 + /** 售票员名字 */
  58 + private String sName;
  59 +
  60 + /** 线路方向 */
  61 + private String xlDir;
  62 + /** 起点站code*/
  63 + private String qdzCode;
  64 + /** 起点站名字 */
  65 + private String qdzName;
  66 +
  67 + /** 终点站code*/
  68 + private String zdzCode;
  69 + /** 终点站名字 */
  70 + private String zdzName;
  71 +
  72 + /** 计划发车时间(格式 HH:mm) */
  73 + private String fcsj;
  74 + /** 计划发车时间戳*/
  75 + @Transient
  76 + private Long fcsjT;
  77 +
  78 + /** 计划终点时间(格式 HH:mm) */
  79 + private String zdsj;
  80 + /** 计划终点时间戳*/
  81 + @Transient
  82 + private Long zdsjT;
  83 +
  84 + /** 发车顺序号 */
  85 + private Integer fcno;
  86 + /** 对应班次数 */
  87 + private Integer bcs;
  88 + /** 计划里程 */
  89 + private Double jhlc;
  90 +
  91 + /** 原始计划里程 (原计调的数据) */
  92 + private Double jhlcOrig;
  93 +
  94 + /** 班次历时 */
  95 + private Integer bcsj;
  96 +
  97 + /**
  98 + * 班次类型 TODO:正常班次、出场、进场、加油、区间班次、放空班次、放大站班次、两点间空驶
  99 + */
  100 + private String bcType;
  101 +
  102 + /** 创建日期 */
  103 + @Column(name = "create_date")
  104 + private Date createDate;
  105 + /** 修改日期 */
  106 + @Column(name = "update_date")
  107 + private Date updateDate;
  108 +
  109 + /** 实际发车时间*/
  110 + private String fcsjActual;
  111 + /** 实际发车时间戳*/
  112 + @Transient
  113 + private Long fcsjActualTime;
  114 + /**实际终点时间 */
  115 + private String zdsjActual;
  116 + /** 实际终点时间戳*/
  117 + @Transient
  118 + private Long zdsjActualTime;
  119 +
  120 + /**班次状态 0 未执行 1 正在执行 2 已执行 -1 已烂班 */
  121 + private int status;
  122 +
  123 + private String adjustExps;
  124 +
  125 + /** 是否是临加班次 */
  126 + private boolean sflj;
  127 +
  128 + /** 是否误点*/
  129 + @Transient
  130 + private boolean late;
  131 +
  132 + /** 备注*/
  133 + private String remarks;
  134 +
  135 + /**待发时间(格式 HH:mm) */
  136 + private String dfsj;
  137 +
  138 + /**待发时间戳 */
  139 + @Transient
  140 + private Long dfsjT;
  141 +
  142 + /** 指令下发状态 60: 已发送, 100: 设备确认收到, 200:驾驶员确认 0:失败 */
  143 + private Integer directiveState = -1;
  144 +
  145 + /** 起点站计划到达时间 */
  146 + @Transient
  147 + private String qdzArrDatejh;
  148 +
  149 + /** 起点站实际到达时间 */
  150 + @Transient
  151 + private String qdzArrDatesj;
  152 +
  153 + /** 子任务 */
  154 + @OneToMany(fetch = FetchType.LAZY, mappedBy = "schedule")
  155 + private Set<ChildTaskPlan> cTasks = new HashSet<>();
  156 +
  157 + /** 关联的公司名称 */
  158 + private String gsName;
  159 + /** 关联的公司编码 */
  160 + private String gsBm;
  161 + /** 关联的分公司名称 */
  162 + private String fgsName;
  163 + /** 关联的分公司编码 */
  164 + private String fgsBm;
  165 + /** 出场顺序号 */
  166 + private Integer ccno;
  167 +
  168 + //待发调试(是否自动调整)
  169 + private boolean dfAuto;
  170 + //是否有GPS信号
  171 + private boolean online;
  172 +
  173 + /** 是否有补发GPS信号 */
  174 + private boolean reissue;
  175 +
  176 + @Override
  177 + public int hashCode() {
  178 + return (this.id + this.scheduleDateStr + this.xlBm + this.fcsj).hashCode();
  179 + }
  180 +
  181 + @Override
  182 + public boolean equals(Object obj) {
  183 + return this.id.equals(((ScheduleRealInfo)obj).getId());
  184 + }
  185 +
  186 + public Long getId() {
  187 + return id;
  188 + }
  189 +
  190 + public void setId(Long id) {
  191 + this.id = id;
  192 + }
  193 +
  194 + public Long getSpId() {
  195 + return spId;
  196 + }
  197 +
  198 + public void setSpId(Long spId) {
  199 + this.spId = spId;
  200 + }
  201 +
  202 + public Date getScheduleDate() {
  203 + return scheduleDate;
  204 + }
  205 +
  206 + public void setScheduleDate(Date scheduleDate) {
  207 + this.scheduleDate = scheduleDate;
  208 + }
  209 +
  210 + public String getScheduleDateStr() {
  211 + return scheduleDateStr;
  212 + }
  213 +
  214 + public void setScheduleDateStr(String scheduleDateStr) {
  215 + this.scheduleDateStr = scheduleDateStr;
  216 + }
  217 +
  218 + public String getRealExecDate() {
  219 + return realExecDate;
  220 + }
  221 +
  222 + public void setRealExecDate(String realExecDate) {
  223 + this.realExecDate = realExecDate;
  224 + }
  225 +
  226 + public String getXlName() {
  227 + return xlName;
  228 + }
  229 +
  230 + public void setXlName(String xlName) {
  231 + this.xlName = xlName;
  232 + }
  233 +
  234 + public String getXlBm() {
  235 + return xlBm;
  236 + }
  237 +
  238 + public void setXlBm(String xlBm) {
  239 + this.xlBm = xlBm;
  240 + }
  241 +
  242 + public String getLpName() {
  243 + return lpName;
  244 + }
  245 +
  246 + public void setLpName(String lpName) {
  247 + this.lpName = lpName;
  248 + }
  249 +
  250 + public String getClZbh() {
  251 + return clZbh;
  252 + }
  253 +
  254 + public void setClZbh(String clZbh) {
  255 + this.clZbh = clZbh;
  256 + }
  257 +
  258 + public String getjGh() {
  259 + return jGh;
  260 + }
  261 +
  262 + public void setjGh(String jGh) {
  263 + this.jGh = jGh;
  264 + }
  265 +
  266 + public String getjName() {
  267 + return jName;
  268 + }
  269 +
  270 + public void setjName(String jName) {
  271 + this.jName = jName;
  272 + }
  273 +
  274 + public String getsGh() {
  275 + return sGh;
  276 + }
  277 +
  278 + public void setsGh(String sGh) {
  279 + this.sGh = sGh;
  280 + }
  281 +
  282 + public String getsName() {
  283 + return sName;
  284 + }
  285 +
  286 + public void setsName(String sName) {
  287 + this.sName = sName;
  288 + }
  289 +
  290 + public String getXlDir() {
  291 + return xlDir;
  292 + }
  293 +
  294 + public void setXlDir(String xlDir) {
  295 + this.xlDir = xlDir;
  296 + }
  297 +
  298 + public String getQdzCode() {
  299 + return qdzCode;
  300 + }
  301 +
  302 + public void setQdzCode(String qdzCode) {
  303 + this.qdzCode = qdzCode;
  304 + }
  305 +
  306 + public String getQdzName() {
  307 + return qdzName;
  308 + }
  309 +
  310 + public void setQdzName(String qdzName) {
  311 + this.qdzName = qdzName;
  312 + }
  313 +
  314 + public String getZdzCode() {
  315 + return zdzCode;
  316 + }
  317 +
  318 + public void setZdzCode(String zdzCode) {
  319 + this.zdzCode = zdzCode;
  320 + }
  321 +
  322 + public String getZdzName() {
  323 + return zdzName;
  324 + }
  325 +
  326 + public void setZdzName(String zdzName) {
  327 + this.zdzName = zdzName;
  328 + }
  329 +
  330 + public String getFcsj() {
  331 + return fcsj;
  332 + }
  333 +
  334 + public void setFcsj(String fcsj) {
  335 + this.fcsj = fcsj;
  336 + }
  337 +
  338 + public Long getFcsjT() {
  339 + return fcsjT;
  340 + }
  341 +
  342 + public void setFcsjT(Long fcsjT) {
  343 + this.fcsjT = fcsjT;
  344 + }
  345 +
  346 + public String getZdsj() {
  347 + return zdsj;
  348 + }
  349 +
  350 + public void setZdsj(String zdsj) {
  351 + this.zdsj = zdsj;
  352 + }
  353 +
  354 + public Long getZdsjT() {
  355 + return zdsjT;
  356 + }
  357 +
  358 + public void setZdsjT(Long zdsjT) {
  359 + this.zdsjT = zdsjT;
  360 + }
  361 +
  362 + public Integer getFcno() {
  363 + return fcno;
  364 + }
  365 +
  366 + public void setFcno(Integer fcno) {
  367 + this.fcno = fcno;
  368 + }
  369 +
  370 + public Integer getBcs() {
  371 + return bcs;
  372 + }
  373 +
  374 + public void setBcs(Integer bcs) {
  375 + this.bcs = bcs;
  376 + }
  377 +
  378 + public Double getJhlc() {
  379 + return jhlc;
  380 + }
  381 +
  382 + public void setJhlc(Double jhlc) {
  383 + this.jhlc = jhlc;
  384 + }
  385 +
  386 + public Integer getBcsj() {
  387 + return bcsj;
  388 + }
  389 +
  390 + public void setBcsj(Integer bcsj) {
  391 + this.bcsj = bcsj;
  392 + }
  393 +
  394 + public String getBcType() {
  395 + return bcType;
  396 + }
  397 +
  398 + public void setBcType(String bcType) {
  399 + this.bcType = bcType;
  400 + }
  401 +
  402 + public Date getCreateDate() {
  403 + return createDate;
  404 + }
  405 +
  406 + public void setCreateDate(Date createDate) {
  407 + this.createDate = createDate;
  408 + }
  409 +
  410 + public Date getUpdateDate() {
  411 + return updateDate;
  412 + }
  413 +
  414 + public void setUpdateDate(Date updateDate) {
  415 + this.updateDate = updateDate;
  416 + }
  417 +
  418 + public String getFcsjActual() {
  419 + return fcsjActual;
  420 + }
  421 +
  422 + public void setFcsjActual(String fcsjActual) {
  423 + this.fcsjActual = fcsjActual;
  424 + }
  425 +
  426 + public Long getFcsjActualTime() {
  427 + return fcsjActualTime;
  428 + }
  429 +
  430 + public void setFcsjActualTime(Long fcsjActualTime) {
  431 + this.fcsjActualTime = fcsjActualTime;
  432 + }
  433 +
  434 + public String getZdsjActual() {
  435 + return zdsjActual;
  436 + }
  437 +
  438 + public void setZdsjActual(String zdsjActual) {
  439 + this.zdsjActual = zdsjActual;
  440 + }
  441 +
  442 + public Long getZdsjActualTime() {
  443 + return zdsjActualTime;
  444 + }
  445 +
  446 + public void setZdsjActualTime(Long zdsjActualTime) {
  447 + this.zdsjActualTime = zdsjActualTime;
  448 + }
  449 +
  450 + public int getStatus() {
  451 + return status;
  452 + }
  453 +
  454 + public void setStatus(int status) {
  455 + this.status = status;
  456 + }
  457 +
  458 + public String getAdjustExps() {
  459 + return adjustExps;
  460 + }
  461 +
  462 + public void setAdjustExps(String adjustExps) {
  463 + this.adjustExps = adjustExps;
  464 + }
  465 +
  466 + public boolean isSflj() {
  467 + return sflj;
  468 + }
  469 +
  470 + public void setSflj(boolean sflj) {
  471 + this.sflj = sflj;
  472 + }
  473 +
  474 + public boolean isLate() {
  475 + return late;
  476 + }
  477 +
  478 + public void setLate(boolean late) {
  479 + this.late = late;
  480 + }
  481 +
  482 + public String getRemarks() {
  483 + return remarks;
  484 + }
  485 +
  486 + public void setRemarks(String remarks) {
  487 + this.remarks = remarks;
  488 + }
  489 +
  490 + public String getDfsj() {
  491 + return dfsj;
  492 + }
  493 +
  494 + public void setDfsj(String dfsj) {
  495 + this.dfsj = dfsj;
  496 + }
  497 +
  498 + public Long getDfsjT() {
  499 + return dfsjT;
  500 + }
  501 +
  502 + public void setDfsjT(Long dfsjT) {
  503 + this.dfsjT = dfsjT;
  504 + }
  505 +
  506 + public Integer getDirectiveState() {
  507 + return directiveState;
  508 + }
  509 +
  510 + public void setDirectiveState(Integer directiveState) {
  511 + this.directiveState = directiveState;
  512 + }
  513 +
  514 + public String getQdzArrDatejh() {
  515 + return qdzArrDatejh;
  516 + }
  517 +
  518 + public void setQdzArrDatejh(String qdzArrDatejh) {
  519 + this.qdzArrDatejh = qdzArrDatejh;
  520 + }
  521 +
  522 + public String getQdzArrDatesj() {
  523 + return qdzArrDatesj;
  524 + }
  525 +
  526 + public void setQdzArrDatesj(String qdzArrDatesj) {
  527 + this.qdzArrDatesj = qdzArrDatesj;
  528 + }
  529 +
  530 + public Set<ChildTaskPlan> getcTasks() {
  531 + return cTasks;
  532 + }
  533 +
  534 + public void setcTasks(Set<ChildTaskPlan> cTasks) {
  535 + this.cTasks = cTasks;
  536 + }
  537 +
  538 + public String getGsName() {
  539 + return gsName;
  540 + }
  541 +
  542 + public void setGsName(String gsName) {
  543 + this.gsName = gsName;
  544 + }
  545 +
  546 + public String getGsBm() {
  547 + return gsBm;
  548 + }
  549 +
  550 + public void setGsBm(String gsBm) {
  551 + this.gsBm = gsBm;
  552 + }
  553 +
  554 + public String getFgsName() {
  555 + return fgsName;
  556 + }
  557 +
  558 + public void setFgsName(String fgsName) {
  559 + this.fgsName = fgsName;
  560 + }
  561 +
  562 + public String getFgsBm() {
  563 + return fgsBm;
  564 + }
  565 +
  566 + public void setFgsBm(String fgsBm) {
  567 + this.fgsBm = fgsBm;
  568 + }
  569 +
  570 + public Integer getCcno() {
  571 + return ccno;
  572 + }
  573 +
  574 + public void setCcno(Integer ccno) {
  575 + this.ccno = ccno;
  576 + }
  577 +
  578 + public boolean isDfAuto() {
  579 + return dfAuto;
  580 + }
  581 +
  582 + public void setDfAuto(boolean dfAuto) {
  583 + this.dfAuto = dfAuto;
  584 + }
  585 +
  586 + public boolean isOnline() {
  587 + return online;
  588 + }
  589 +
  590 + public void setOnline(boolean online) {
  591 + this.online = online;
  592 + }
  593 +
  594 + public boolean isReissue() {
  595 + return reissue;
  596 + }
  597 +
  598 + public void setReissue(boolean reissue) {
  599 + this.reissue = reissue;
  600 + }
  601 +
  602 + public Double getJhlcOrig() {
  603 + return jhlcOrig;
  604 + }
  605 +
  606 + public void setJhlcOrig(Double jhlcOrig) {
  607 + this.jhlcOrig = jhlcOrig;
  608 + }
  609 +
  610 + @Transient
  611 + private static DateTimeFormatter fmtHHmm = DateTimeFormat.forPattern("HH:mm");
  612 + /**
  613 + *
  614 + * @Title: setFcsjActualAll
  615 + * @Description: TODO(设置实际发车时间 时间戳)
  616 + * @throws
  617 + */
  618 + public void setFcsjActualAll(Long t){
  619 + this.fcsjActualTime = t;
  620 + this.fcsjActual = fmtHHmm.print(t);
  621 + }
  622 +
  623 + /**
  624 + *
  625 + * @Title: setFcsjActualAll
  626 + * @Description: TODO(设置实际终点时间)
  627 + * @throws
  628 + */
  629 + public void setZdsjActualAll(Long t){
  630 + this.zdsjActualTime = t;
  631 + this.zdsjActual = fmtHHmm.print(t);
  632 + }
  633 +}
... ...
src/main/java/com/bsth/redis/ScheduleRedisService.java
1   -package com.bsth.redis;
2   -
3   -import com.bsth.Application;
4   -import com.bsth.common.BasicData;
5   -import com.bsth.entity.ScheduleRealInfo;
6   -import com.bsth.redis.util.RedisUtils;
7   -import com.bsth.repository.ScheduleRealInfoRepository;
8   -import com.bsth.server_rs.base_info.line.Line;
9   -import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
10   -import com.bsth.util.ConfigUtil;
11   -import com.bsth.util.ConvertUtil;
12   -import com.google.common.collect.ArrayListMultimap;
13   -import org.apache.commons.lang3.StringUtils;
14   -import org.joda.time.DateTime;
15   -import org.joda.time.format.DateTimeFormat;
16   -import org.joda.time.format.DateTimeFormatter;
17   -import org.slf4j.Logger;
18   -import org.slf4j.LoggerFactory;
19   -import org.springframework.beans.factory.annotation.Autowired;
20   -import org.springframework.boot.CommandLineRunner;
21   -import org.springframework.core.annotation.Order;
22   -import org.springframework.data.redis.core.ListOperations;
23   -import org.springframework.data.redis.core.RedisTemplate;
24   -import org.springframework.data.redis.serializer.StringRedisSerializer;
25   -import org.springframework.stereotype.Component;
26   -import org.springframework.stereotype.Service;
27   -
28   -import java.util.ArrayList;
29   -import java.util.Iterator;
30   -import java.util.List;
31   -import java.util.concurrent.TimeUnit;
32   -
33   -/**
34   - * 班次 redis 缓存管理
35   - * Created by panzhao on 2017/3/13.
36   - */
37   -@Service
38   -@Order(2)
39   -public class ScheduleRedisService implements CommandLineRunner {
40   -
41   - @Autowired
42   - ScheduleRealInfoRepository scheduleRealInfoRepository;
43   -
44   - private final static String REDIS_KEY_PREFIX = "schedule:";
45   -
46   - @Autowired
47   - private RedisTemplate redisTemplate;
48   -
49   - @Autowired
50   - RedisUtils redisUtils;
51   -
52   - static Logger logger = LoggerFactory.getLogger(ScheduleRedisService.class);
53   -
54   - private final static long DAY_TIME = 1000 * 60 * 60 * 24L;
55   -
56   - /**
57   - * 将一批班次写入redis
58   - *
59   - * @param list
60   - */
61   - public void wirte(List<ScheduleRealInfo> list) {
62   - ArrayListMultimap<String, ScheduleRealInfo> multimap;
63   - try {
64   - if (list.size() == 0)
65   - return;
66   - //按日期和线路分组数据
67   - Class clazz = ScheduleRealInfo.class;
68   - multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDateStr"));
69   -
70   - //写入redis
71   - Iterator<String> iterator = multimap.keySet().iterator();
72   - String key;
73   - while (iterator.hasNext()) {
74   - key = iterator.next();
75   - replace(key, multimap.get(key));
76   - }
77   - } catch (Exception e) {
78   - logger.error("", e);
79   - }
80   - }
81   -
82   - /**
83   - * 将 list 与redis里的数据合并
84   - *
85   - * @param key
86   - * @param list
87   - */
88   - public void mergeData(String key, List<ScheduleRealInfo> list) {
89   - key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
90   -
91   - ListOperations<String, ScheduleRealInfo> ops = redisTemplate.opsForList();
92   - List<ScheduleRealInfo> cacheList = ops.range(key, 0, -1);
93   -
94   - for (ScheduleRealInfo sch : cacheList) {
95   - if (!list.contains(sch))
96   - list.add(sch);
97   - }
98   -
99   - //更新
100   - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
101   - }
102   -
103   - /**
104   - * 覆盖数据
105   - *
106   - * @param key
107   - * @param list
108   - */
109   - public void replace(String key, List<ScheduleRealInfo> list) {
110   - key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
111   - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
112   - }
113   -
114   - /**
115   - * 删除数据
116   - *
117   - * @param key
118   - */
119   - public void delete(String lineCode, String rq) {
120   - String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", "");
121   - redisTemplate.delete(key);
122   - }
123   -
124   - /**
125   - * 根据日期和线路编码从redis获取班次
126   - *
127   - * @param dateStr
128   - * @param lineCode
129   - * @return
130   - */
131   - public List<ScheduleRealInfo> read(String dateStr, String lineCode) {
132   - return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1);
133   - }
134   -
135   - /**
136   - * 返回指定日期,公司的实际排班,并按线路_车辆分组
137   - *
138   - * @param rq
139   - * @param companyId
140   - * @return
141   - */
142   - public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByNbbm(String rq, String companyId) {
143   - List<String> lineArray = LineBufferData.findCodesByCompany(companyId);
144   - ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();
145   -
146   - rq = rq.replaceAll("-", "");
147   - List<ScheduleRealInfo> list;
148   - for (String lineCode : lineArray) {
149   -
150   - list = read(rq, lineCode);
151   -
152   - for (ScheduleRealInfo sch : list) {
153   - rs.put(sch.getXlBm() + "_" + sch.getClZbh(), sch);
154   - }
155   - }
156   - return rs;
157   - }
158   -
159   - /**
160   - * 返回指定日期,公司的实际排班,并按线路分组
161   - *
162   - * @param rq
163   - * @param companyId
164   - * @return
165   - */
166   - public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByLine(String rq, String companyId) {
167   -
168   - List<String> lineArray = LineBufferData.findCodesByCompany(companyId);
169   - ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();
170   -
171   - rq = rq.replaceAll("-", "");
172   - List<ScheduleRealInfo> list;
173   - for (String lineCode : lineArray) {
174   -
175   - list = read(rq, lineCode);
176   -
177   - for (ScheduleRealInfo sch : list) {
178   - rs.put(sch.getXlBm(), sch);
179   - }
180   - }
181   - return rs;
182   - }
183   -
184   - @Autowired
185   - ScheduleRefreshThread scheduleRefreshThread;
186   - @Autowired
187   - ScheduleClearThread scheduleClearThread;
188   -
189   - @Override
190   - public void run(String... strings) throws Exception {
191   - //用子线程去加载,,不要阻塞
192   - Application.mainServices.schedule(new Runnable() {
193   - @Override
194   - public void run() {
195   - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
196   - //设置key 序列化器
197   - redisTemplate.setKeySerializer(new StringRedisSerializer());
198   -
199   - DateTime dt = new DateTime();
200   - dt = dt.minusDays(cacheDays);
201   - List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDateLT(dt.toString("yyyy-MM-dd"));
202   - calcTime(list);
203   - //写入redis
204   - wirte(list);
205   - logger.info("redis 实际排班 over...");
206   - }
207   - }, 5, TimeUnit.SECONDS);
208   -
209   - //定时刷新一次当日实际排班
210   - int minute = 10;
211   - Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, minute + 4, minute, TimeUnit.MINUTES);
212   - //24小时清理一次实际排班数据
213   - Application.mainServices.scheduleWithFixedDelay(scheduleClearThread, 24, 24, TimeUnit.HOURS);
214   - }
215   -
216   - public List<ScheduleRealInfo> findByMultiLine(List<String> lineArray, String rq) {
217   - rq = rq.replaceAll("-", "");
218   - List<ScheduleRealInfo> rs = new ArrayList<>();
219   - for (String lineCode : lineArray) {
220   - rs.addAll(read(rq, lineCode));
221   - }
222   - return rs;
223   - }
224   -
225   - @Component
226   - public static class ScheduleRefreshThread extends Thread {
227   -
228   - @Autowired
229   - ScheduleRealInfoRepository realInfoRepository;
230   -
231   - @Autowired
232   - ScheduleRedisService scheduleRedisService;
233   -
234   - @Override
235   - public void run() {
236   - try {
237   - DateTime dt = new DateTime();
238   - DateTime yesterday = dt.minusDays(2);
239   -
240   - String rq = yesterday.toString("yyyy-MM-dd");
241   - logger.info("refresh lt yesterday ..." + rq + " -start");
242   - List<ScheduleRealInfo> list = realInfoRepository.findByDateLT(rq);
243   -
244   - //计算时间戳
245   - scheduleRedisService.calcTime(list);
246   - scheduleRedisService.wirte(list);
247   -
248   - logger.info("refresh lt yesterday ..." + rq + " -end### size: " + list.size());
249   - } catch (Exception e) {
250   - logger.error("", e);
251   - }
252   - }
253   - }
254   -
255   - @Component
256   - public static class ScheduleClearThread extends Thread {
257   -
258   - @Autowired
259   - ScheduleRedisService scheduleRedisService;
260   -
261   - @Override
262   - public void run() {
263   - try {
264   - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
265   - DateTime dt = new DateTime();
266   - dt = dt.minusDays(cacheDays);
267   - String rq = dt.toString("yyyy-MM-dd");
268   -
269   - List<Line> lines = LineBufferData.findAll();
270   - for (Line line : lines) {
271   - scheduleRedisService.delete(line.getLineCode(), rq);
272   - }
273   - } catch (Exception e) {
274   - logger.error("", e);
275   - }
276   - }
277   - }
278   -
279   - /**
280   - * ############ 时间戳计算 ##########
281   - */
282   - private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"),
283   - fmtHHmm = DateTimeFormat.forPattern("HH:mm");
284   -
285   - private void calcTime(List<ScheduleRealInfo> list) {
286   - if (list.size() == 0)
287   - return;
288   -
289   - //计算真实执行日期 和 时间戳
290   - for (ScheduleRealInfo sch : list) {
291   - calcRealDate(BasicData.lineStartTimeMap.get(sch.getXlBm()), sch);
292   - }
293   - }
294   -
295   - /**
296   - * @Title: calcRealDate
297   - * @Description: TODO(计算班次的真实执行日期)
298   - */
299   - public void calcRealDate(String startTime, ScheduleRealInfo sch) {
300   - try {
301   - if (null == startTime)
302   - return;
303   -
304   - if (null == sch.getBcsj())
305   - sch.setBcsj(0);
306   -
307   - String rq = sch.getScheduleDateStr();
308   - //计发时间
309   - sch.setFcsjT(parseTime(rq, sch.getFcsj(), startTime));
310   - //待发时间
311   - sch.setDfsjT(parseTime(rq, sch.getDfsj(), startTime));
312   - //计划终点时间
313   - if (StringUtils.isEmpty(sch.getZdsj())) {
314   - sch.setZdsjT(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000));
315   - sch.setZdsj(fmtHHmm.print(sch.getZdsjT()));
316   - } else
317   - sch.setZdsjT(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000));
318   - //实发时间
319   - if (StringUtils.isNotEmpty(sch.getFcsjActual()))
320   - sch.setFcsjActualAll(parseTime(rq, sch.getFcsjActual(), startTime));
321   -
322   - //实达时间
323   - if (StringUtils.isNotEmpty(sch.getZdsjActual()))
324   - sch.setZdsjActualAll(parseTime(rq, sch.getZdsjActual(), startTime));
325   - } catch (Exception e) {
326   - logger.error("", e);
327   - }
328   - }
329   -
330   - private long parseTime(String rq, String sj, String startTime) {
331   - long t = fmtyyyyMMddHHmm.parseMillis(rq + sj);
332   - if (sj.compareTo(startTime) < 0) {
333   - t += DAY_TIME;
334   - }
335   - return t;
336   - }
337   -}
  1 +package com.bsth.redis;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.common.BasicData;
  5 +import com.bsth.entity.ScheduleRealInfo;
  6 +import com.bsth.redis.util.RedisUtils;
  7 +import com.bsth.repository.ScheduleRealInfoRepository;
  8 +import com.bsth.server_rs.base_info.line.Line;
  9 +import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  10 +import com.bsth.util.ConfigUtil;
  11 +import com.bsth.util.ConvertUtil;
  12 +import com.google.common.collect.ArrayListMultimap;
  13 +import org.apache.commons.lang3.StringUtils;
  14 +import org.joda.time.DateTime;
  15 +import org.joda.time.format.DateTimeFormat;
  16 +import org.joda.time.format.DateTimeFormatter;
  17 +import org.slf4j.Logger;
  18 +import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.boot.CommandLineRunner;
  21 +import org.springframework.core.annotation.Order;
  22 +import org.springframework.data.redis.core.ListOperations;
  23 +import org.springframework.data.redis.core.RedisTemplate;
  24 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  25 +import org.springframework.stereotype.Component;
  26 +import org.springframework.stereotype.Service;
  27 +
  28 +import java.util.ArrayList;
  29 +import java.util.Iterator;
  30 +import java.util.List;
  31 +import java.util.concurrent.TimeUnit;
  32 +
  33 +/**
  34 + * 班次 redis 缓存管理
  35 + * Created by panzhao on 2017/3/13.
  36 + */
  37 +@Service
  38 +@Order(2)
  39 +public class ScheduleRedisService implements CommandLineRunner {
  40 +
  41 + @Autowired
  42 + ScheduleRealInfoRepository scheduleRealInfoRepository;
  43 +
  44 + private final static String REDIS_KEY_PREFIX = "schedule:";
  45 +
  46 + @Autowired
  47 + private RedisTemplate redisTemplate;
  48 +
  49 + @Autowired
  50 + RedisUtils redisUtils;
  51 +
  52 + static Logger logger = LoggerFactory.getLogger(ScheduleRedisService.class);
  53 +
  54 + private final static long DAY_TIME = 1000 * 60 * 60 * 24L;
  55 +
  56 + /**
  57 + * 将一批班次写入redis
  58 + *
  59 + * @param list
  60 + */
  61 + public void wirte(List<ScheduleRealInfo> list) {
  62 + ArrayListMultimap<String, ScheduleRealInfo> multimap;
  63 + try {
  64 + if (list.size() == 0)
  65 + return;
  66 + //按日期和线路分组数据
  67 + Class clazz = ScheduleRealInfo.class;
  68 + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDateStr"));
  69 +
  70 + //写入redis
  71 + Iterator<String> iterator = multimap.keySet().iterator();
  72 + String key;
  73 + while (iterator.hasNext()) {
  74 + key = iterator.next();
  75 + replace(key, multimap.get(key));
  76 + }
  77 + } catch (Exception e) {
  78 + logger.error("", e);
  79 + }
  80 + }
  81 +
  82 + /**
  83 + * 将 list 与redis里的数据合并
  84 + *
  85 + * @param key
  86 + * @param list
  87 + */
  88 + public void mergeData(String key, List<ScheduleRealInfo> list) {
  89 + key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
  90 +
  91 + ListOperations<String, ScheduleRealInfo> ops = redisTemplate.opsForList();
  92 + List<ScheduleRealInfo> cacheList = ops.range(key, 0, -1);
  93 +
  94 + for (ScheduleRealInfo sch : cacheList) {
  95 + if (!list.contains(sch))
  96 + list.add(sch);
  97 + }
  98 +
  99 + //更新
  100 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  101 + }
  102 +
  103 + /**
  104 + * 覆盖数据
  105 + *
  106 + * @param key
  107 + * @param list
  108 + */
  109 + public void replace(String key, List<ScheduleRealInfo> list) {
  110 + key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
  111 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  112 + }
  113 +
  114 + /**
  115 + * 删除数据
  116 + *
  117 + * @param key
  118 + */
  119 + public void delete(String lineCode, String rq) {
  120 + String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", "");
  121 + redisTemplate.delete(key);
  122 + }
  123 +
  124 + /**
  125 + * 根据日期和线路编码从redis获取班次
  126 + *
  127 + * @param dateStr
  128 + * @param lineCode
  129 + * @return
  130 + */
  131 + public List<ScheduleRealInfo> read(String dateStr, String lineCode) {
  132 + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1);
  133 + }
  134 +
  135 + /**
  136 + * 返回指定日期,公司的实际排班,并按线路_车辆分组
  137 + *
  138 + * @param rq
  139 + * @param companyId
  140 + * @return
  141 + */
  142 + public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByNbbm(String rq, String companyId) {
  143 + List<String> lineArray = LineBufferData.findCodesByCompany(companyId);
  144 + ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();
  145 +
  146 + rq = rq.replaceAll("-", "");
  147 + List<ScheduleRealInfo> list;
  148 + for (String lineCode : lineArray) {
  149 +
  150 + list = read(rq, lineCode);
  151 +
  152 + for (ScheduleRealInfo sch : list) {
  153 + rs.put(sch.getXlBm() + "_" + sch.getClZbh(), sch);
  154 + }
  155 + }
  156 + return rs;
  157 + }
  158 +
  159 + /**
  160 + * 返回指定日期,公司的实际排班,并按线路分组
  161 + *
  162 + * @param rq
  163 + * @param companyId
  164 + * @return
  165 + */
  166 + public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByLine(String rq, String companyId) {
  167 +
  168 + List<String> lineArray = LineBufferData.findCodesByCompany(companyId);
  169 + ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();
  170 +
  171 + rq = rq.replaceAll("-", "");
  172 + List<ScheduleRealInfo> list;
  173 + for (String lineCode : lineArray) {
  174 +
  175 + list = read(rq, lineCode);
  176 +
  177 + for (ScheduleRealInfo sch : list) {
  178 + rs.put(sch.getXlBm(), sch);
  179 + }
  180 + }
  181 + return rs;
  182 + }
  183 +
  184 + @Autowired
  185 + ScheduleRefreshThread scheduleRefreshThread;
  186 + @Autowired
  187 + ScheduleClearThread scheduleClearThread;
  188 +
  189 + @Override
  190 + public void run(String... strings) throws Exception {
  191 + //用子线程去加载,,不要阻塞
  192 + Application.mainServices.schedule(new Runnable() {
  193 + @Override
  194 + public void run() {
  195 + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
  196 + //设置key 序列化器
  197 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  198 +
  199 + DateTime dt = new DateTime();
  200 + dt = dt.minusDays(cacheDays);
  201 + List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDateLT(dt.toString("yyyy-MM-dd"));
  202 + calcTime(list);
  203 + //写入redis
  204 + wirte(list);
  205 + logger.info("redis 实际排班 over...");
  206 + }
  207 + }, 5, TimeUnit.SECONDS);
  208 +
  209 + //定时刷新一次当日实际排班
  210 + int minute = 10;
  211 + Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, minute + 4, minute, TimeUnit.MINUTES);
  212 + //24小时清理一次实际排班数据
  213 + Application.mainServices.scheduleWithFixedDelay(scheduleClearThread, 24, 24, TimeUnit.HOURS);
  214 + }
  215 +
  216 + public List<ScheduleRealInfo> findByMultiLine(List<String> lineArray, String rq) {
  217 + rq = rq.replaceAll("-", "");
  218 + List<ScheduleRealInfo> rs = new ArrayList<>();
  219 + for (String lineCode : lineArray) {
  220 + rs.addAll(read(rq, lineCode));
  221 + }
  222 + return rs;
  223 + }
  224 +
  225 + @Component
  226 + public static class ScheduleRefreshThread extends Thread {
  227 +
  228 + @Autowired
  229 + ScheduleRealInfoRepository realInfoRepository;
  230 +
  231 + @Autowired
  232 + ScheduleRedisService scheduleRedisService;
  233 +
  234 + @Override
  235 + public void run() {
  236 + try {
  237 + DateTime dt = new DateTime();
  238 + DateTime yesterday = dt.minusDays(2);
  239 +
  240 + String rq = yesterday.toString("yyyy-MM-dd");
  241 + logger.info("refresh lt yesterday ..." + rq + " -start");
  242 + List<ScheduleRealInfo> list = realInfoRepository.findByDateLT(rq);
  243 +
  244 + //计算时间戳
  245 + scheduleRedisService.calcTime(list);
  246 + scheduleRedisService.wirte(list);
  247 +
  248 + logger.info("refresh lt yesterday ..." + rq + " -end### size: " + list.size());
  249 + } catch (Exception e) {
  250 + logger.error("", e);
  251 + }
  252 + }
  253 + }
  254 +
  255 + @Component
  256 + public static class ScheduleClearThread extends Thread {
  257 +
  258 + @Autowired
  259 + ScheduleRedisService scheduleRedisService;
  260 +
  261 + @Override
  262 + public void run() {
  263 + try {
  264 + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
  265 + DateTime dt = new DateTime();
  266 + dt = dt.minusDays(cacheDays);
  267 + String rq = dt.toString("yyyy-MM-dd");
  268 +
  269 + List<Line> lines = LineBufferData.findAll();
  270 + for (Line line : lines) {
  271 + scheduleRedisService.delete(line.getLineCode(), rq);
  272 + }
  273 + } catch (Exception e) {
  274 + logger.error("", e);
  275 + }
  276 + }
  277 + }
  278 +
  279 + /**
  280 + * ############ 时间戳计算 ##########
  281 + */
  282 + private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"),
  283 + fmtHHmm = DateTimeFormat.forPattern("HH:mm");
  284 +
  285 + private void calcTime(List<ScheduleRealInfo> list) {
  286 + if (list.size() == 0)
  287 + return;
  288 +
  289 + //计算真实执行日期 和 时间戳
  290 + for (ScheduleRealInfo sch : list) {
  291 + calcRealDate(BasicData.lineStartTimeMap.get(sch.getXlBm()), sch);
  292 + }
  293 + }
  294 +
  295 + /**
  296 + * @Title: calcRealDate
  297 + * @Description: TODO(计算班次的真实执行日期)
  298 + */
  299 + public void calcRealDate(String startTime, ScheduleRealInfo sch) {
  300 + try {
  301 + if (null == startTime)
  302 + return;
  303 +
  304 + if (null == sch.getBcsj())
  305 + sch.setBcsj(0);
  306 +
  307 + String rq = sch.getScheduleDateStr();
  308 + //计发时间
  309 + sch.setFcsjT(parseTime(rq, sch.getFcsj(), startTime));
  310 + //待发时间
  311 + sch.setDfsjT(parseTime(rq, sch.getDfsj(), startTime));
  312 + //计划终点时间
  313 + if (StringUtils.isEmpty(sch.getZdsj())) {
  314 + sch.setZdsjT(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000));
  315 + sch.setZdsj(fmtHHmm.print(sch.getZdsjT()));
  316 + } else
  317 + sch.setZdsjT(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000));
  318 + //实发时间
  319 + if (StringUtils.isNotEmpty(sch.getFcsjActual()))
  320 + sch.setFcsjActualAll(parseTime(rq, sch.getFcsjActual(), startTime));
  321 +
  322 + //实达时间
  323 + if (StringUtils.isNotEmpty(sch.getZdsjActual()))
  324 + sch.setZdsjActualAll(parseTime(rq, sch.getZdsjActual(), startTime));
  325 + } catch (Exception e) {
  326 + logger.error("", e);
  327 + }
  328 + }
  329 +
  330 + private long parseTime(String rq, String sj, String startTime) {
  331 + long t = fmtyyyyMMddHHmm.parseMillis(rq + sj);
  332 + if (sj.compareTo(startTime) < 0) {
  333 + t += DAY_TIME;
  334 + }
  335 + return t;
  336 + }
  337 +}
... ...
src/main/java/com/bsth/server_rs/waybill/WaybillRestService.java 0 → 100644
  1 +package com.bsth.server_rs.waybill;
  2 +
  3 +import java.lang.reflect.Field;
  4 +import java.util.ArrayList;
  5 +import java.util.HashMap;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +import java.util.Set;
  9 +
  10 +import javax.ws.rs.GET;
  11 +import javax.ws.rs.Path;
  12 +import javax.ws.rs.PathParam;
  13 +import javax.ws.rs.Produces;
  14 +import javax.ws.rs.core.MediaType;
  15 +
  16 +import org.apache.commons.lang3.StringUtils;
  17 +import org.joda.time.format.DateTimeFormat;
  18 +import org.joda.time.format.DateTimeFormatter;
  19 +import org.slf4j.Logger;
  20 +import org.slf4j.LoggerFactory;
  21 +import org.springframework.beans.factory.annotation.Autowired;
  22 +import org.springframework.stereotype.Component;
  23 +
  24 +import com.bsth.entity.DutyEmployee;
  25 +import com.bsth.entity.ScheduleRealInfo;
  26 +import com.bsth.redis.ScheduleRedisService;
  27 +import com.bsth.repository.DutyEmployeeRepository;
  28 +import com.bsth.server_ws.util.ScheduleCalculator;
  29 +import com.bsth.util.ConvertUtil;
  30 +import com.google.common.collect.ArrayListMultimap;
  31 +
  32 +import ch.qos.logback.classic.Level;
  33 +import ch.qos.logback.classic.LoggerContext;
  34 +
  35 +/**
  36 + * @author Hill.
  37 + */
  38 +@Component
  39 +@Path("/waybill")
  40 +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  41 +public class WaybillRestService {
  42 +
  43 + @Autowired
  44 + private ScheduleRedisService scheduleRedisService;
  45 + @Autowired
  46 + private DutyEmployeeRepository dutyEmployeeRepository;
  47 +
  48 + private static Logger logger = LoggerFactory.getLogger(WaybillRestService.class);
  49 +
  50 + private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"),
  51 + fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");
  52 +
  53 + @GET
  54 + @Path("/{companyCode}/{rq}")
  55 + public Map<String, Object> waybill(@PathParam("companyCode") String companyCode, @PathParam("rq") String rq) {
  56 + Map<String, Object> map = new HashMap<String, Object>();
  57 + try {
  58 + //日期减一天,老接口是这样的
  59 + String prveRq = fmtyyyyMMdd.print(fmtyyyyMMdd.parseDateTime(rq).minusDays(1));
  60 +
  61 + //实际排班
  62 + ArrayListMultimap<String, ScheduleRealInfo> listMap = scheduleRedisService.findByDateAndGroupByNbbm(prveRq, companyCode);
  63 + //当班调派
  64 + long st = fmtyyyyMMddHHmm.parseMillis(prveRq + "00:00"), et = fmtyyyyMMddHHmm.parseMillis(prveRq + "23:59");
  65 + List<DutyEmployee> des = dutyEmployeeRepository.findByTime(st, et);
  66 + //转换成南汇路单需要的格式
  67 + List<Waybill> data = toNhWaybill(listMap, des);
  68 + map.put("errCode", 0);
  69 + map.put("errMsg", "");
  70 + map.put("data", data);
  71 + } catch (Exception e) {
  72 + logger.error("", e);
  73 + map.put("errCode", 1);
  74 + map.put("errMsg", "服务器出现异常!");
  75 + }
  76 +
  77 + return map;
  78 + }
  79 +
  80 + @GET
  81 + @Path("/level/{level}")
  82 + public Map<String, Object> waybill(@PathParam("level") String level) {
  83 + Map<String, Object> map = new HashMap<>();
  84 + try {
  85 + LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory();
  86 + context.getLogger("root").setLevel(Level.toLevel(level));
  87 + map.put("errCode", 0);
  88 + map.put("errMsg", "成功");
  89 + } catch (Exception e) {
  90 + logger.error("", e);
  91 + map.put("errCode", 1);
  92 + map.put("errMsg", "服务器出现异常!");
  93 + }
  94 +
  95 + return map;
  96 + }
  97 +
  98 + private List<Waybill> toNhWaybill(ArrayListMultimap<String, ScheduleRealInfo> listMap, List<DutyEmployee> des) {
  99 + Set<String> nbbms = listMap.keySet();
  100 + List<Waybill> result = new ArrayList<Waybill>(nbbms.size());
  101 + Field jGhField = null;
  102 + try {
  103 + jGhField = ScheduleRealInfo.class.getDeclaredField("jGh");
  104 + } catch (NoSuchFieldException | SecurityException e) {
  105 + // TODO Auto-generated catch block
  106 + e.printStackTrace();
  107 + }
  108 +
  109 + List<ScheduleRealInfo> list;
  110 + ArrayListMultimap<String, ScheduleRealInfo> jGhListMap;
  111 + ScheduleRealInfo sch;
  112 + for (String nbbm : nbbms) {
  113 + list = listMap.get(nbbm);
  114 + if (list.size() == 0)
  115 + continue;
  116 +
  117 + //按 驾驶员 分组班次,构造路单子项
  118 + jGhListMap = new ConvertUtil<ScheduleRealInfo>().groupMultiList(list, "_", jGhField);
  119 + for (String jGh : jGhListMap.keySet()) {
  120 + list = jGhListMap.get(jGh);
  121 + //班次信息
  122 + Waybill wb = new Waybill();
  123 + sch = list.get(0);
  124 + //日期
  125 + wb.setDate(sch.getScheduleDateStr());
  126 + //车辆自编号
  127 + wb.setInsideCode(sch.getClZbh());
  128 + //线路编码
  129 + wb.setLineCode(sch.getXlBm());
  130 + wb.setLineName(sch.getXlName());
  131 + wb.setCompanyCode(sch.getGsBm());
  132 + wb.setBranchCompanyCode(sch.getFgsBm());
  133 + //营业公里
  134 + wb.setMiles(ScheduleCalculator.calcYYLC(list));
  135 + //驾驶员工号
  136 + wb.setDriverJno(list.get(0).getjGh());
  137 + wb.setDriverName(list.get(0).getjName());
  138 + wb.setDriverId("");
  139 + //售票员工号
  140 + wb.setConductorJno(list.get(0).getsGh());
  141 + wb.setConductorName(list.get(0).getsName());
  142 + wb.setConductorId("");
  143 + for (ScheduleRealInfo sri : list) {
  144 + if (StringUtils.isNotEmpty(sri.getsGh())) {
  145 + wb.setConductorJno(sri.getsGh());
  146 + break;
  147 + }
  148 + }
  149 + result.add(wb);
  150 + }
  151 + }
  152 +
  153 + return result;
  154 + }
  155 +
  156 + final class Waybill {
  157 + // 日期
  158 + private String date;
  159 + // 公司代码
  160 + private String companyCode;
  161 + // 分公司代码
  162 + private String branchCompanyCode;
  163 + // 线路名称
  164 + private String lineName;
  165 + // 线路代码
  166 + private String lineCode;
  167 + // 车辆内部编码
  168 + private String insideCode;
  169 + // 驾驶员工号
  170 + private String driverJno;
  171 + // 驾驶员姓名
  172 + private String driverName;
  173 + // 驾驶员身份证号
  174 + private String driverId;
  175 + // 售票员工号
  176 + private String conductorJno;
  177 + // 售票员姓名
  178 + private String conductorName;
  179 + // 售票员身份证号
  180 + private String conductorId;
  181 + // 营运公里
  182 + private double miles;
  183 +
  184 + public String getDate() {
  185 + return date;
  186 + }
  187 +
  188 + public void setDate(String date) {
  189 + this.date = date;
  190 + }
  191 +
  192 + public String getCompanyCode() {
  193 + return companyCode;
  194 + }
  195 +
  196 + public void setCompanyCode(String companyCode) {
  197 + this.companyCode = companyCode;
  198 + }
  199 +
  200 + public String getBranchCompanyCode() {
  201 + return branchCompanyCode;
  202 + }
  203 +
  204 + public void setBranchCompanyCode(String branchCompanyCode) {
  205 + this.branchCompanyCode = branchCompanyCode;
  206 + }
  207 +
  208 + public String getLineName() {
  209 + return lineName;
  210 + }
  211 +
  212 + public void setLineName(String lineName) {
  213 + this.lineName = lineName;
  214 + }
  215 +
  216 + public String getLineCode() {
  217 + return lineCode;
  218 + }
  219 +
  220 + public void setLineCode(String lineCode) {
  221 + this.lineCode = lineCode;
  222 + }
  223 +
  224 + public String getInsideCode() {
  225 + return insideCode;
  226 + }
  227 +
  228 + public void setInsideCode(String insideCode) {
  229 + this.insideCode = insideCode;
  230 + }
  231 +
  232 + public String getDriverJno() {
  233 + return driverJno;
  234 + }
  235 +
  236 + public void setDriverJno(String driverJno) {
  237 + this.driverJno = driverJno;
  238 + }
  239 +
  240 + public String getDriverName() {
  241 + return driverName;
  242 + }
  243 +
  244 + public void setDriverName(String driverName) {
  245 + this.driverName = driverName;
  246 + }
  247 +
  248 + public String getDriverId() {
  249 + return driverId;
  250 + }
  251 +
  252 + public void setDriverId(String driverId) {
  253 + this.driverId = driverId;
  254 + }
  255 +
  256 + public String getConductorJno() {
  257 + return conductorJno;
  258 + }
  259 +
  260 + public void setConductorJno(String conductorJno) {
  261 + this.conductorJno = conductorJno;
  262 + }
  263 +
  264 + public String getConductorName() {
  265 + return conductorName;
  266 + }
  267 +
  268 + public void setConductorName(String conductorName) {
  269 + this.conductorName = conductorName;
  270 + }
  271 +
  272 + public String getConductorId() {
  273 + return conductorId;
  274 + }
  275 +
  276 + public void setConductorId(String conductorId) {
  277 + this.conductorId = conductorId;
  278 + }
  279 +
  280 + public double getMiles() {
  281 + return miles;
  282 + }
  283 +
  284 + public void setMiles(double miles) {
  285 + this.miles = miles;
  286 + }
  287 + }
  288 +}
... ...