LineConfigServiceImpl.java
8.48 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
package com.bsth.service.realcontrol.impl;
import com.bsth.common.ResponseCode;
import com.bsth.data.LineConfigData;
import com.bsth.entity.realcontrol.LineConfig;
import com.bsth.repository.realcontrol.LineConfigRepository;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.realcontrol.LineConfigService;
import com.google.common.base.Splitter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class LineConfigServiceImpl extends BaseServiceImpl<LineConfig, Integer> implements LineConfigService {
@Autowired
LineConfigRepository lineConfigRepository;
@Autowired
LineConfigData lineConfigData;
Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public Map<String, Object> check(String[] codeArray) {
Map<String, Object> rs = new HashMap<>();
List<String> notArr = new ArrayList<>();
for (String lineCode : codeArray) {
if (null == lineConfigData.get(lineCode + ""))
notArr.add(lineCode);
}
if (notArr.size() > 0) {
rs.put("status", 1);
rs.put("not", notArr);
} else
rs.put("status", 0);
return rs;
}
@Override
public Integer init(String lineCode) throws Exception {
LineConfig conf = lineConfigData.get(lineCode);
if (conf == null)
lineConfigData.init(lineCode);
return 1;
}
@Override
public Map<String, Object> editStartOptTime(String time, String lineCode) {
Map<String, Object> rs = new HashMap<>();
try {
LineConfig conf = lineConfigData.get(lineCode);
conf.setStartOpt(time);
lineConfigData.set(conf);
rs.put("status", ResponseCode.SUCCESS);
rs.put("time", time);
} catch (Exception e) {
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
logger.error("", e);
}
return rs;
}
@Override
public Map<String, Object> editOutTimeType(String lineCode, int type, String parkCode, String stationCode) {
Map<String, Object> rs = new HashMap<>();
try {
LineConfig conf = lineConfigData.get(lineCode);
conf.setOutConfig(type);
if(type == 2){
conf.setTwinsParks(parkCode);
conf.setTwinsStations(stationCode);
}
lineConfigData.set(conf);
rs.put("status", ResponseCode.SUCCESS);
rs.put("conf", conf);
} catch (Exception e) {
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
logger.error("", e);
}
return rs;
}
@Override
public LineConfig getByLineCode(String lineCode) {
return lineConfigData.get(lineCode);
}
@Override
public Map<String, Object> enableInParkForSource(String lineCode, int enable) {
Map<String, Object> rs = new HashMap<>();
try {
LineConfig conf = lineConfigData.get(lineCode);
conf.setInParkForSource(enable == 1);
lineConfigData.set(conf);
rs.put("status", ResponseCode.SUCCESS);
rs.put("enable", enable);
} catch (Exception e) {
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
logger.error("", e);
}
return rs;
}
@Override
public Map<String, Object> bufferTimeDiff(String lineCode, String field, String value) {
Map<String, Object> rs = new HashMap<>();
try {
LineConfig conf = lineConfigData.get(lineCode);
Field f = conf.getClass().getDeclaredField(field);
f.setAccessible(true);
f.setInt(conf, Integer.parseInt(value));
lineConfigData.set(conf);
rs.put("status", ResponseCode.SUCCESS);
rs.put("field", field);
rs.put("value", value);
} catch (Exception e) {
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
logger.error("", e);
}
return rs;
}
@Override
public Map<String, Object> yjtkSet(Map<String, String> map) {
String lineCode = map.get("lineCode").toString();
int enableYjtk = Integer.parseInt(map.get("enableYjtk").toString());
Map<String, Object> rs = new HashMap<>();
try {
LineConfig conf = lineConfigData.get(lineCode);
if(enableYjtk == 1){
String yjtkStart = map.containsKey("yjtkStart") ? map.get("yjtkStart").toString() : "00:00";
String yjtkEnd = map.containsKey("yjtkEnd") ? map.get("yjtkEnd").toString() : "23:59";
int upStopMinute = Integer.parseInt(map.get("upStopMinute").toString());
int downStopMinute = Integer.parseInt(map.get("downStopMinute").toString());
conf.setEnableYjtk(true);
conf.setYjtkStart(yjtkStart);
conf.setYjtkEnd(yjtkEnd);
conf.setUpStopMinute(upStopMinute);
conf.setDownStopMinute(downStopMinute);
}
else
conf.setEnableYjtk(false);
lineConfigData.set(conf);
rs.put("status", ResponseCode.SUCCESS);
rs.put("conf", conf);
} catch (Exception e) {
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
logger.error("", e);
}
return rs;
}
@Override
public Map<String, Object> parkAndStationSet(Map<String, String> map) {
String lineCode = map.get("lineCode").toString();
String twinsPark = map.get("twinsPark").toString();
String twinsStation = map.get("twinsStation").toString();
Map<String, Object> rs = new HashMap<>();
try {
LineConfig conf = lineConfigData.get(lineCode);
conf.setTwinsParks(twinsPark);
conf.setTwinsStations(twinsStation);
lineConfigData.set(conf);
rs.put("status", ResponseCode.SUCCESS);
rs.put("conf", conf);
} catch (Exception e) {
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
logger.error("", e);
}
return rs;
}
@Override
public Map<String, Object> findByIdx(String idx) {
Map<String, Object> rs = new HashMap();
try{
List<LineConfig> list = new ArrayList<>();
List<String> ids = Splitter.on(",").splitToList(idx);
for(String id : ids){
list.add(lineConfigData.get(id));
}
rs.put("status", ResponseCode.SUCCESS);
rs.put("list", list);
}catch (Exception e){
rs.put("status", ResponseCode.ERROR);
logger.error("", e);
}
return rs;
}
@Override
public Map<String, Object> setAutoExec(Map<String, String> map) {
String lineCode = map.get("lineCode").toString();
boolean autoExec = Boolean.parseBoolean(map.get("autoExec"));
int autoExecOffset = Integer.parseInt(map.get("autoExecOffset"));
Map<String, Object> rs = new HashMap<>();
try {
LineConfig conf = lineConfigData.get(lineCode);
conf.setAutoExec(autoExec);
conf.setAutoExecOffset(autoExecOffset);
lineConfigData.set(conf);
rs.put("status", ResponseCode.SUCCESS);
rs.put("conf", conf);
} catch (Exception e) {
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
logger.error("", e);
}
return rs;
}
@Override
public Map<String, Object> setReadReverse(int status, String lineCode) {
Map<String, Object> rs = new HashMap<>();
try {
LineConfig conf = lineConfigData.get(lineCode);
conf.setReadReverse(status==1?true:false);
lineConfigData.set(conf);
rs.put("status", ResponseCode.SUCCESS);
rs.put("conf", conf);
} catch (Exception e) {
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
logger.error("", e);
}
return rs;
}
}