ScheduleRealInfoServiceImpl.java
6.72 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
package com.bsth.service.realcontrol.impl;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Cars;
import com.bsth.entity.Personnel;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.entity.schedule.CarConfigInfo;
import com.bsth.entity.schedule.EmployeeConfigInfo;
import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
import com.bsth.repository.schedule.CarConfigInfoRepository;
import com.bsth.repository.schedule.EmployeeConfigInfoRepository;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.realcontrol.ScheduleRealInfoService;
import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
import com.google.common.base.Splitter;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
@Service
public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInfo, Long> implements ScheduleRealInfoService{
@Autowired
ScheduleRealInfoRepository scheduleRealInfoRepository;
@Autowired
EmployeeConfigInfoRepository employeeConfigInfoRepository;
@Autowired
CarConfigInfoRepository carConfigInfoRepository;
Logger logger = LoggerFactory.getLogger(this.getClass());
SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd")
, sdfMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm")
, sdfShort = new SimpleDateFormat("HH:mm");
@Override
public Map<String, Collection<ScheduleRealInfo>> findByLines(String lines) {
List<String> lineList = Lists.newArrayList(Splitter.on(',').trimResults().omitEmptyStrings().split(lines));
Multimap<String, ScheduleRealInfo> mMap = ArrayListMultimap.create();
for(String lineCode : lineList){
mMap.putAll(lineCode, ScheduleBuffer.schedulListMap.get(lineCode));
}
return mMap.asMap();
}
@Override
public Map<String, Object> outgoAdjust(Long id, String remarks, String dfsj) {
Map<String, Object> map = new HashMap<>();
try{
ScheduleRealInfo schedule = ScheduleBuffer.pkSchedulMap.get(id);
schedule.setDfsjT(sdfMinute.parse(sdfMonth.format(new Date()) + " " + dfsj).getTime());
schedule.setDfsj(dfsj);
schedule.addRemarks("[待发调整] " + remarks +";");
//持久化到数据库
ScheduleBuffer.persistentList.add(schedule);
map.put("status", ResponseCode.SUCCESS);
map.put("dfsj", dfsj);
map.put("remarks", schedule.getRemarks());
}catch(Exception e){
logger.error("", e);
map.put("status", ResponseCode.ERROR);
}
return map;
}
@Override
public Map<String, Object> destroy(String idsStr, int spaceAdjust, String remarks, String reason, int spaceNum) {
Map<String, Object> map = new HashMap<>();
List<ScheduleRealInfo> rsList = new ArrayList<>();
map.put("list", rsList);
try{
List<String> idList = Lists.newArrayList(Splitter.on(',').trimResults().omitEmptyStrings().split(idsStr));
ScheduleRealInfo schedule = null;
for(String id : idList){
schedule = ScheduleBuffer.pkSchedulMap.get(Long.parseLong(id));
if(null != schedule){
schedule.setStatus(-1);
schedule.setRemarks("计划烂班["+reason+"] " + remarks);
rsList.add(schedule);
}
}
//调整间隔
if(spaceAdjust == 1){
ScheduleRealInfo first = ScheduleBuffer.pkSchedulMap.get(Long.parseLong(idList.get(0)));
String lineCode = first.getXlBm();
String upDown = first.getXlDir();
List<ScheduleRealInfo> schList = ScheduleBuffer.schedulListMap.get(lineCode)
,dirList = new ArrayList<>();
//筛选走向
for(ScheduleRealInfo s : schList){
if(s.getXlDir().equals(upDown)){
dirList.add(s);
}
}
int size = dirList.size();
Long st = null;
int diff = spaceNum * 60 * 1000;
for(int i = 0; i < size; i ++){
schedule = dirList.get(i);
if(schedule.getId() == first.getId()){
if(i == 0)
st = schedule.getDfsjT() - diff;
else
st = dirList.get(i - 1).getDfsjT();
continue;
}
if(null == st || schedule.getStatus() == -1)
continue;
st = st + diff;
schedule.setDfsjT(st);
schedule.setDfsj(sdfShort.format(new Date(st)));
ScheduleBuffer.persistentList.add(schedule);
//将调整的班次返回给页面
rsList.add(schedule);
}
}
map.put("status", ResponseCode.SUCCESS);
}catch(Exception e){
logger.error("", e);
map.put("status", ResponseCode.ERROR);
}
return map;
}
//线路id获取驾驶员
@Override
public List<Map<String, String>> findDriverByLine(String lineCode) {
List<EmployeeConfigInfo> list = employeeConfigInfoRepository.findBylineCode(lineCode);
List<Map<String, String>> rsList = new ArrayList<>();
Map<String, String> map = null;
Personnel driver = null;
String code = null;
for(EmployeeConfigInfo employee : list){
driver = employee.getJsy();
if(driver != null){
map = new HashMap<>();
code = driver.getJobCode();
map.put("id", code);
map.put("text", code + "/" + driver.getPersonnelName());
rsList.add(map);
}
}
return rsList;
}
//线路id获取售票员
@Override
public List<Map<String, String>> findConductorByLine(String lineCode) {
List<EmployeeConfigInfo> list = employeeConfigInfoRepository.findBylineCode(lineCode);
List<Map<String, String>> rsList = new ArrayList<>();
Map<String, String> map = null;
Personnel conductor = null;
String code = null;
for(EmployeeConfigInfo employee : list){
conductor = employee.getSpy();
if(conductor != null){
code = conductor.getJobCode();
map = new HashMap<>();
map.put("id", code);
map.put("text", code + "/" + conductor.getPersonnelName());
rsList.add(map);
}
}
return rsList;
}
@Override
public List<Map<String, String>> findCarByLine(String lineCode) {
List<CarConfigInfo> list = carConfigInfoRepository.findBylineCode(lineCode);
List<Map<String, String>> rsList = new ArrayList<>();
Map<String, String> map = null;
Cars car = null;
String code = null;
for(CarConfigInfo cci : list){
car = cci.getCl();
if(car != null){
code = car.getInsideCode();
map = new HashMap<>();
map.put("id", code);
map.put("text", code);
rsList.add(map);
}
}
return rsList;
}
}