OutEntrance.java
7.73 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
package com.bsth.data.zndd;
import com.bsth.common.ResponseCode;
import com.bsth.controller.station_signs.carMonitorThread;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.data.schedule.ScheduleComparator;
import com.bsth.data.adjg.domain.LargeGap;
import com.bsth.entity.logger.StationSignsLogger;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.entity.zndd.StationPeopleLogger;
import com.bsth.service.logger.StationSignsLoggerService;
import com.bsth.service.zndd.ZnddLoggerService;
import com.bsth.websocket.handler.SendUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import sun.misc.BASE64Decoder;
import java.io.*;
import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
* 对外接口
* 与站牌、小程序对接接口
* 调度预案通用接口
*/
@RestController
@RequestMapping("/out")
public class OutEntrance {
@Autowired
StationSignsLoggerService stationSignsLoggerService;
@Autowired
SendUtils sendUtils;
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
ZnddLoggerService znddLoggerService;
@Autowired
carMonitorThread carMonitorThread;
@Value("${dc.imgurl}")
private String imgurl; //存储图片地址
@Value("${dc.profile}")
private String profile; //存储图片地址
static String url= "http://58.34.52.130:9777/xxfb/carMonitor?"; //信息发布地址
Logger logger = LoggerFactory.getLogger(this.getClass());
/*
调度屏小程序接口。
*/
@RequestMapping(value = "/OutCar", method = RequestMethod.POST)
public Map OutCarOutCar(@RequestParam Map m,@RequestBody Map<String, String> map) {
Map rtn = new HashMap<>();
try {
ObjectMapper mapper = new ObjectMapper();
m.put("image", uploadBase64Img(map.get("img").toString()));
//map转换实体类
StationSignsLogger ssLogger = mapper.convertValue(m, StationSignsLogger.class);
//stationSignsLoggerService.save(ssLogger);
//线调页面推送
sendUtils.stationcf(m);
//查询班次情况自动回复
//当前日期
//String rq = DateUtils.dqDate();
List<Map> dzList = carMonitorThread.carMonitor(ssLogger.getLineCode(), ssLogger.getDir(), ssLogger.getStation()); //信息发布接口
if (dzList.size() > 0){
rtn.put("message","车辆还有"+dzList.get(0).get("sj")+"抵达,请耐心等待");
}else {
//筛选方向
List<ScheduleRealInfo> rs = dayOfSchedule.findByLineCode(ssLogger.getLineCode());
//排序
Collections.sort(rs,new ScheduleComparator.FCSJ());
SimpleDateFormat sdf= new SimpleDateFormat("HH:ss");
String sjtext = "";
LocalTime t1 = LocalTime.parse(sdf.format(new Date()), DateTimeFormatter.ofPattern("HH:mm"));
for (ScheduleRealInfo sr:rs) {
LocalTime t2 = LocalTime.parse(sr.getFcsj(), DateTimeFormatter.ofPattern("HH:mm"));
//判断上下行
if(t1.isAfter(t2)){
sjtext = sr.getFcsj();
}
}
rtn.put("message","航津路与杨高北路交叉口拥堵,请耐心等待");
rtn.put("message_els","The intersection of Hangjin Road and Yanggao North Road is congested, please be patient and wait");
}
rtn.put("status",ResponseCode.SUCCESS);
} catch (Exception e) {
rtn.put("status", ResponseCode.ERROR);
logger.info(e.getMessage());
}
return rtn;
}
/*
智能调度接口--通用测试接口
*/
@RequestMapping(value="/zjket",method = RequestMethod.GET)
public Map Znddjk(@RequestParam Map m) {
Map rtn = new HashMap<>();
try {
ObjectMapper mapper = new ObjectMapper();
//线调页面推送
sendUtils.sendzndd(m);
rtn.put("status",ResponseCode.SUCCESS);
} catch (Exception e) {
rtn.put("status",ResponseCode.ERROR);
logger.info("智能调度推送----",e);
}
return rtn;
}
/*
智能调度接口-大客流
*/
@RequestMapping(value="/dkl",method = RequestMethod.POST)
public Map ddkl(@RequestParam Map m) {
Map rtn = new HashMap<>();
try {
ObjectMapper mapper = new ObjectMapper();
//map转换实体类
StationPeopleLogger ssLogger = mapper.convertValue(m, StationPeopleLogger.class);
ssLogger.setType("大客流");
//保存记录
znddLoggerService.save(ssLogger);
//线调页面推送
//sendUtils.sendzndd(ssLogger);
rtn.put("status",ResponseCode.SUCCESS);
} catch (Exception e) {
rtn.put("status", ResponseCode.ERROR);
Logger logger = LoggerFactory.getLogger(this.getClass());
}
return rtn;
}
/**
* 保存base64图片
* @param base64Str base64文件
* @param 上传地址(示例:D:\\1.png)
* @return
*/
public String uploadBase64Img(String base) {
//获取年月日
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//将年、月、日存入数组
String[] time = sdf.format(new Date()).split("-");
// 文件保存地址 默认地址为xxxx/年/月/日
String url = "avat/"+time[0]+"/"+time[1]+"/"+time[2];
String destDir = imgurl+"/"+url;
base=base.replaceAll("data:image/png;base64,","");
BASE64Decoder decoder = new BASE64Decoder();
byte[] imageByte = null;
try{
imageByte = decoder.decodeBuffer(base);
for (int i = 0; i < imageByte.length; ++i) {
if (imageByte[i] < 0) {// 调整异常数据
imageByte[i] += 256;
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (imageByte.length>0) {
try {
String filepath = destDir;
File destfile = new File(filepath);
if (!destfile.exists()) {
destfile.mkdirs();
}
//文件新名称
String fileNameNew = "666"+ ".png";
File f = new File(destfile.getAbsoluteFile() + File.separator + fileNameNew);
// 将字符串转换成二进制,用于显示图片
// 将上面生成的图片格式字符串 imgStr,还原成图片显示
InputStream in = new ByteArrayInputStream(imageByte);
FileOutputStream fos = new FileOutputStream(f);
byte[] buf = new byte[1024];
int length;
length = in.read(buf, 0, buf.length);
while (length != -1) {
fos.write(buf, 0, length);
length = in.read(buf);
}
fos.flush();
fos.close();
in.close();
return "/"+profile + "/" + url+"/"+fileNameNew;
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
return null;
}
}