SchedulePlanInfoService.java
24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
package com.bsth.service.schedule;
import com.bsth.entity.schedule.SchedulePlanInfo;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* Created by xu on 16/6/16.
*/
public interface SchedulePlanInfoService extends BService<SchedulePlanInfo, Long> {
/**
* 查找最近的排班的日期。
* @param xlId 线路Id
* @return
*/
List<Date> findLastestPlanDate(Integer xlId);
/**
* 查找排班计划汇总数据。
* @param xlId 线路Id
* @param scheduleDate 排班时间
* @return
*/
List<SchedulePlanGroupInfo> findSchedulePlanGroupInfo(Integer xlId, Date scheduleDate);
/**
* 排班计划分组信息。
*/
static class SchedulePlanGroupInfo implements Comparable<SchedulePlanGroupInfo> {
//------------------ 分组字段 ----------------//
/** 线路Id */
private Integer xlId;
/** 线路名字 */
private String xlName;
/** 排班时间 */
private Date scheduleDate;
/** 路牌Id */
private Long lpId;
/** 路牌名字 */
private String lpName;
//------------------ 聚合数据(按照发车顺序号排序的 asc) ----------------//
/** 车辆自编号s */
private List<String> clZbhs;
/** 出场时间s */
private List<String> ccsjs;
/** 进场时间s */
private List<String> jcsjs;
/** 驾驶员名字s */
private List<String> jsyNames;
/** 驾驶员工号s */
private List<String> jsyGhs;
/** 售票员名字s */
private List<String> spyNames;
/** 售票员工号s */
private List<String> spyGhs;
/** 创建时间 */
private Date createDate;
/** 修改时间 */
private Date updateDate;
/** 修改人名 */
private String updateByName;
/** 时刻表名字 */
private String ttInfoName;
//------------------- 修改yuan原因,描述,次数 ------------------------//
// 修改次数
private Integer m_count;
// 修改原因
private Integer m_reason;
// 修改描述
private String m_desc;
@Override
public int compareTo(SchedulePlanGroupInfo o) {
// 路牌名字排序,数字路牌名在前,非数字在后
// 数字按照从小到大排序,非数字按照字符串从小到大排列
if (StringUtils.isNumeric(this.lpName)) {
if (StringUtils.isNumeric(o.lpName)) {
return Long.valueOf(this.lpName).compareTo(Long.valueOf(o.lpName));
} else {
return -1;
}
} else {
if (StringUtils.isNumeric(o.lpName)) {
return 1;
} else {
return this.lpName.compareTo(o.lpName);
}
}
}
public static String generateSelectSql() {
return "select " +
"info.xl as xlId " +
", info.xl_name as xlName " +
", info.schedule_date as scheduleDate " +
", gbi.id as lpId " +
", info.lp_name as lpName " +
", GROUP_CONCAT(distinct info.cl_zbh order by info.fcno) as clzbhs " +
", GROUP_CONCAT(info.fcsj order by info.fcno) as fcsjs " +
", GROUP_CONCAT(info.bc_type order by info.fcno) as bctypes " +
", GROUP_CONCAT(distinct info.j_name order by info.fcno) as jsyNames " +
", GROUP_CONCAT(distinct info.j_gh order by info.fcno) as jsyGhs " +
", GROUP_CONCAT(distinct info.s_name order by info.fcno) as spyNames " +
", GROUP_CONCAT(distinct info.s_gh order by info.fcno) as spyGhs " +
", max(info.create_date) as createDate " +
", max(info.update_date) as updateDate " +
", max(user.user_name) as updateUserName " +
", max(info.tt_info_name) as ttInfoName " +
", max(info.modify_count) as m_count " +
", max(info.modify_reason) as m_reason " +
", max(info.modify_remark) as m_desc " +
"from bsth_c_s_sp_info info left join bsth_c_sys_user user on info.update_by = user.id " +
"left join bsth_c_s_gbi gbi on info.lp = gbi.id " +
"where info.xl = ? and info.schedule_date = ? " +
"group by info.xl, info.xl_name, info.schedule_date, info.lp, info.lp_name " +
"order by info.xl, info.schedule_date, gbi.lp_no ";
}
public void setFromResult(ResultSet rs) throws SQLException {
this.xlId = rs.getInt("xlId");
this.xlName = rs.getString("xlName");
this.scheduleDate = new Date(rs.getDate("scheduleDate").getTime());
this.lpId = rs.getLong("lpId");
this.lpName = rs.getString("lpName");
// 车辆自编号
this.clZbhs = new ArrayList<>();
String clzbhs_temp = rs.getString("clzbhs");
if (StringUtils.isNotEmpty(clzbhs_temp)) {
this.clZbhs.addAll(Arrays.asList(clzbhs_temp.split(",")));
}
// 出场,进场时间
this.ccsjs = new ArrayList<>();
this.jcsjs = new ArrayList<>();
String fcsjs_temp = rs.getString("fcsjs");
String bctype_temp = rs.getString("bctypes");
if (StringUtils.isNotEmpty(fcsjs_temp) && StringUtils.isNotEmpty(bctype_temp)) {
String[] fcsjs_array = fcsjs_temp.split(",");
String[] bctype_array = bctype_temp.split(",");
if (fcsjs_array.length == bctype_array.length) {
for (int i = 0; i < fcsjs_array.length; i++) {
if ("out".equals(bctype_array[i])) {
this.ccsjs.add(fcsjs_array[i]);
} else if ("in".equals(bctype_array[i])) {
this.jcsjs.add(fcsjs_array[i]);
}
}
}
}
// 驾驶员
this.jsyNames = new ArrayList<>();
String jsyNames_temp = rs.getString("jsyNames");
if (StringUtils.isNotEmpty(jsyNames_temp)) {
this.jsyNames.addAll(Arrays.asList(jsyNames_temp.split(",")));
}
this.jsyGhs = new ArrayList<>();
String jsyGhs_temp = rs.getString("jsyGhs");
if (StringUtils.isNotEmpty(jsyGhs_temp)) {
this.jsyGhs.addAll(Arrays.asList(jsyGhs_temp.split(",")));
}
// 售票员
this.spyNames = new ArrayList<>();
String spyNames_temp = rs.getString("spyNames");
if (StringUtils.isNotEmpty(spyNames_temp)) {
this.spyNames.addAll(Arrays.asList(spyNames_temp.split(",")));
}
this.spyGhs = new ArrayList<>();
String spyGhs_temp = rs.getString("spyGhs");
if (StringUtils.isNotEmpty(spyGhs_temp)) {
this.spyGhs.addAll(Arrays.asList(spyGhs_temp.split(",")));
}
this.createDate = new Date(rs.getTimestamp("createDate").getTime());
this.updateDate = new Date(rs.getTimestamp("updateDate").getTime());
this.updateByName = rs.getString("updateUserName");
this.ttInfoName = rs.getString("ttInfoName");
this.m_count = rs.getInt("m_count");
this.m_reason = rs.getInt("m_reason");
this.m_desc = rs.getString("m_desc");
}
public Integer getXlId() {
return xlId;
}
public void setXlId(Integer xlId) {
this.xlId = xlId;
}
public String getXlName() {
return xlName;
}
public void setXlName(String xlName) {
this.xlName = xlName;
}
public Date getScheduleDate() {
return scheduleDate;
}
public void setScheduleDate(Date scheduleDate) {
this.scheduleDate = scheduleDate;
}
public Long getLpId() {
return lpId;
}
public void setLpId(Long lpId) {
this.lpId = lpId;
}
public String getLpName() {
return lpName;
}
public void setLpName(String lpName) {
this.lpName = lpName;
}
public List<String> getClZbhs() {
return clZbhs;
}
public void setClZbhs(List<String> clZbhs) {
this.clZbhs = clZbhs;
}
public List<String> getCcsjs() {
return ccsjs;
}
public void setCcsjs(List<String> ccsjs) {
this.ccsjs = ccsjs;
}
public List<String> getJcsjs() {
return jcsjs;
}
public void setJcsjs(List<String> jcsjs) {
this.jcsjs = jcsjs;
}
public List<String> getJsyNames() {
return jsyNames;
}
public void setJsyNames(List<String> jsyNames) {
this.jsyNames = jsyNames;
}
public List<String> getJsyGhs() {
return jsyGhs;
}
public void setJsyGhs(List<String> jsyGhs) {
this.jsyGhs = jsyGhs;
}
public List<String> getSpyNames() {
return spyNames;
}
public void setSpyNames(List<String> spyNames) {
this.spyNames = spyNames;
}
public List<String> getSpyGhs() {
return spyGhs;
}
public void setSpyGhs(List<String> spyGhs) {
this.spyGhs = spyGhs;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public String getUpdateByName() {
return updateByName;
}
public void setUpdateByName(String updateByName) {
this.updateByName = updateByName;
}
public String getTtInfoName() {
return ttInfoName;
}
public void setTtInfoName(String ttInfoName) {
this.ttInfoName = ttInfoName;
}
public Integer getM_count() {
return m_count;
}
public void setM_count(Integer m_count) {
this.m_count = m_count;
}
public Integer getM_reason() {
return m_reason;
}
public void setM_reason(Integer m_reason) {
this.m_reason = m_reason;
}
public String getM_desc() {
return m_desc;
}
public void setM_desc(String m_desc) {
this.m_desc = m_desc;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
}
//---------------------------- 以下是过去版本 -------------------------------//
/**
* 查找分组排班信息。
* @param xlid 线路Id
* @param scheduleDate 排班日期
* @return
*/
List<GroupInfo> findGroupInfo(Integer xlid, Date scheduleDate);
/**
* 更新分组信息。
* type=1,替换车辆
* type=2,修改出场班次1时间(首班车时间)
* type=3,替换分组人员(驾驶员1和售票员1)
* type=4,如果分班,修改出场班次2时间(分班后的第一个出场班次时间)
* type=5,如果分班,修改分组人员(驾驶员2和售票员2)
* @param groupInfoUpdate 分组更新信息,包含类型,更新前的信息,更新后的信息
* @return
*/
int updateGroupInfo(GroupInfoUpdate groupInfoUpdate);
/**
* 分组更新信息。
*/
static class GroupInfoUpdate {
/** 类型 */
private int type;
/** 原始分组值 */
private GroupInfo src;
/** 更新分组值 */
private GroupInfo update;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public GroupInfo getSrc() {
return src;
}
public void setSrc(GroupInfo src) {
this.src = src;
}
public GroupInfo getUpdate() {
return update;
}
public void setUpdate(GroupInfo update) {
this.update = update;
}
}
/**
* 分组信息。
*/
static class GroupInfo {
/** 线路Id */
private Integer xlId;
/** 线路名称 */
private String xlName;
/** 排班时间 */
private Date scheduleDate;
/** 路牌名字 */
private String lpName;
/** 车辆Id */
private Integer clId;
/** 车辆自编号 */
private String clZbh;
/** 出场班次1时间 */
private String ccsj1;
/** 出场班次2时间 */
private String ccsj2;
/** 驾驶员1id */
private Integer jsy1Id;
/** 驾驶员1工号 */
private String jsy1Gh;
/** 驾驶员1姓名 */
private String jsy1Name;
/** 驾驶员1id */
private Integer jsy2Id;
/** 驾驶员1工号 */
private String jsy2Gh;
/** 驾驶员1姓名 */
private String jsy2Name;
/** 售票员1id */
private Integer spy1Id;
/** 售票员1工号 */
private String spy1Gh;
/** 售票员1姓名 */
private String spy1Name;
/** 售票员1id */
private Integer spy2Id;
/** 售票员1工号 */
private String spy2Gh;
/** 售票员1姓名 */
private String spy2Name;
/** 修改时间 */
private Date updateDate;
/** 修改人名 */
private String updateByName;
/** 时刻表名字 */
private String ttInfoName;
/** 出场班次1发车的顺序号 */
private Integer fcno1;
/** 出场班次2发车的顺序号 */
private Integer fcno2;
public GroupInfo() {}
public GroupInfo(Object[] datas) {
// 线路Id
this.xlId = Integer.valueOf(String.valueOf(datas[0]));
// 线路名称
this.xlName = String.valueOf(datas[1]);
// 排班时间
this.scheduleDate = new DateTime(datas[2]).toDate();
// 路牌名字
this.lpName = String.valueOf(datas[3]);
// 车辆id
this.clId = Integer.valueOf(String.valueOf(datas[4]));
// 车辆自编号
this.clZbh = String.valueOf(datas[5]);
// 出场时间,出场班次,如果有多个,需要分开
Object ccsj = datas[6];
Object bctype = datas[7];
Object fcno = datas[14];
if (ccsj != null) {
String[] ccsj_array = ((String) ccsj).split(",");
String[] bctype_array = ((String) bctype).split(",");
String[] fcno_array = ((String) fcno).split(",");
List<Integer> bctype_index = new ArrayList<>();
for (int i = 0; i < bctype_array.length; i++) {
if (bctype_index.size() == 2) { // 只记录2个出场
break;
}
if (bctype_array[i].equals("out")) {
bctype_index.add(i);
}
}
if (bctype_index.size() == 1) {
this.ccsj1 = String.valueOf(ccsj_array[bctype_index.get(0)]);
this.fcno1 = Integer.valueOf(fcno_array[bctype_index.get(0)]);
} else if (bctype_index.size() == 2) {
this.ccsj1 = String.valueOf(ccsj_array[bctype_index.get(0)]);
this.ccsj2 = String.valueOf(ccsj_array[bctype_index.get(1)]);
this.fcno1 = Integer.valueOf(fcno_array[bctype_index.get(0)]);
this.fcno2 = Integer.valueOf(fcno_array[bctype_index.get(1)]);
}
}
// 驾驶员id,如果有多个,需要分开
Object jsyId = datas[8];
if (jsyId != null) {
String[] jsyId_array = ((String) jsyId).split(",");
if (jsyId_array.length > 1) {
this.jsy1Id = Integer.valueOf(String.valueOf(jsyId_array[0]));
this.jsy2Id = Integer.valueOf(String.valueOf(jsyId_array[1]));
} else {
this.jsy1Id = Integer.valueOf(String.valueOf(jsyId_array[0]));
}
}
// 驾驶员工号,如果有多个,需要分开
Object jsyGh = datas[9];
if (jsyGh != null) {
String[] jsyGh_array = ((String) jsyGh).split(",");
if (jsyGh_array.length > 1) {
this.jsy1Gh = String.valueOf(jsyGh_array[0]);
this.jsy2Gh = String.valueOf(jsyGh_array[1]);
} else {
this.jsy1Gh = String.valueOf(jsyGh_array[0]);
}
}
// 驾驶员名字,如果有多个,需要分开
Object jsyName = datas[10];
if (jsyName != null) {
String[] jsyName_array = ((String) jsyName).split(",");
if (jsyName_array.length > 1) {
this.jsy1Name = String.valueOf(jsyName_array[0]);
this.jsy2Name = String.valueOf(jsyName_array[1]);
} else {
this.jsy1Name = String.valueOf(jsyName_array[0]);
}
}
// 售票员id,如果有多个,需要分开
Object spyId = datas[11];
if (spyId != null) {
String[] spyId_array = ((String) spyId).split(",");
if (spyId_array.length > 1) {
this.spy1Id = Integer.valueOf(String.valueOf(spyId_array[0]));
this.spy2Id = Integer.valueOf(String.valueOf(spyId_array[1]));
} else {
this.spy1Id = Integer.valueOf(String.valueOf(spyId_array[0]));
}
}
// 售票员工号,如果有多个,需要分开
Object spyGh = datas[12];
if (spyGh != null) {
String[] spyGh_array = ((String) spyGh).split(",");
if (spyGh_array.length > 1) {
this.spy1Gh = String.valueOf(spyGh_array[0]);
this.spy2Gh = String.valueOf(spyGh_array[1]);
} else {
this.spy1Gh = String.valueOf(spyGh_array[0]);
}
}
// 售票员名字,如果有多个,需要分开
Object spyName = datas[13];
if (spyName != null) {
String[] spyName_array = ((String) spyName).split(",");
if (spyName_array.length > 1) {
this.spy1Name = String.valueOf(spyName_array[0]);
this.spy2Name = String.valueOf(spyName_array[1]);
} else {
this.spy1Name = String.valueOf(spyName_array[0]);
}
}
// 修改时间
this.updateDate = new DateTime(datas[15]).toDate();
// 修改人
this.updateByName = String.valueOf(datas[16]);
// 时刻表名字
this.ttInfoName = String.valueOf(datas[17]);
// TODO:可能还有其他字段
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public String getUpdateByName() {
return updateByName;
}
public void setUpdateByName(String updateByName) {
this.updateByName = updateByName;
}
public String getXlName() {
return xlName;
}
public void setXlName(String xlName) {
this.xlName = xlName;
}
public Date getScheduleDate() {
return scheduleDate;
}
public void setScheduleDate(Date scheduleDate) {
this.scheduleDate = scheduleDate;
}
public String getLpName() {
return lpName;
}
public void setLpName(String lpName) {
this.lpName = lpName;
}
public Integer getClId() {
return clId;
}
public void setClId(Integer clId) {
this.clId = clId;
}
public String getClZbh() {
return clZbh;
}
public void setClZbh(String clZbh) {
this.clZbh = clZbh;
}
public String getCcsj1() {
return ccsj1;
}
public void setCcsj1(String ccsj1) {
this.ccsj1 = ccsj1;
}
public String getCcsj2() {
return ccsj2;
}
public void setCcsj2(String ccsj2) {
this.ccsj2 = ccsj2;
}
public Integer getJsy1Id() {
return jsy1Id;
}
public void setJsy1Id(Integer jsy1Id) {
this.jsy1Id = jsy1Id;
}
public String getJsy1Gh() {
return jsy1Gh;
}
public void setJsy1Gh(String jsy1Gh) {
this.jsy1Gh = jsy1Gh;
}
public String getJsy1Name() {
return jsy1Name;
}
public void setJsy1Name(String jsy1Name) {
this.jsy1Name = jsy1Name;
}
public Integer getJsy2Id() {
return jsy2Id;
}
public void setJsy2Id(Integer jsy2Id) {
this.jsy2Id = jsy2Id;
}
public String getJsy2Gh() {
return jsy2Gh;
}
public void setJsy2Gh(String jsy2Gh) {
this.jsy2Gh = jsy2Gh;
}
public String getJsy2Name() {
return jsy2Name;
}
public void setJsy2Name(String jsy2Name) {
this.jsy2Name = jsy2Name;
}
public Integer getSpy1Id() {
return spy1Id;
}
public void setSpy1Id(Integer spy1Id) {
this.spy1Id = spy1Id;
}
public String getSpy1Gh() {
return spy1Gh;
}
public void setSpy1Gh(String spy1Gh) {
this.spy1Gh = spy1Gh;
}
public String getSpy1Name() {
return spy1Name;
}
public void setSpy1Name(String spy1Name) {
this.spy1Name = spy1Name;
}
public Integer getSpy2Id() {
return spy2Id;
}
public void setSpy2Id(Integer spy2Id) {
this.spy2Id = spy2Id;
}
public String getSpy2Gh() {
return spy2Gh;
}
public void setSpy2Gh(String spy2Gh) {
this.spy2Gh = spy2Gh;
}
public String getSpy2Name() {
return spy2Name;
}
public void setSpy2Name(String spy2Name) {
this.spy2Name = spy2Name;
}
public Integer getXlId() {
return xlId;
}
public void setXlId(Integer xlId) {
this.xlId = xlId;
}
public Integer getFcno1() {
return fcno1;
}
public void setFcno1(Integer fcno1) {
this.fcno1 = fcno1;
}
public Integer getFcno2() {
return fcno2;
}
public void setFcno2(Integer fcno2) {
this.fcno2 = fcno2;
}
public String getTtInfoName() {
return ttInfoName;
}
public void setTtInfoName(String ttInfoName) {
this.ttInfoName = ttInfoName;
}
}
}