OutEntrance.java
3.65 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
package com.bsth.data.zndd;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.data.BasicData;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.DKLInfo;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.service.DKLInfoService;
import com.bsth.util.SignUtils;
import com.bsth.websocket.handler.SendUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
* 对外接口
* 与站牌、小程序对接接口
* 调度预案通用接口
*/
@RestController
@RequestMapping("/out")
public class OutEntrance {
@Autowired
SendUtils sendUtils;
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
private DKLInfoService dklInfoService;
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
JdbcTemplate jdbcTemplate;
@RequestMapping(value = "/klyj", method = RequestMethod.POST)
public Map klyj(@RequestBody JSONObject jsonObject) {
Map rtn = new HashMap<>();
try {
logger.info("大客流接口调用----");
if(!SignUtils.validation(Long.parseLong(jsonObject.getString("timestamp")),jsonObject.getString("sign"))){
rtn.put("status", "验证失败");
return rtn;
}
String num=jsonObject.getString("num");
JSONArray jsonArray = jsonObject.getJSONArray("stations");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject line=jsonArray.getJSONObject(i);
String lineCode = line.get("lineCode").toString();
String stationCode = line.get("stationCode").toString();
String dir = line.get("dir").toString();
String lineName=BasicData.lineCode2NameMap.get(lineCode);
String stationName=BasicData.stationCode2NameMap.get(lineCode+"_"+dir+"_"+stationCode);
DKLInfo dklInfo =new DKLInfo();
dklInfo.setLineCode(lineCode);
dklInfo.setLineName(lineName);
dklInfo.setStationCode(stationCode);
dklInfo.setStationName(stationName);
dklInfo.setNum(Integer.parseInt(num));
dklInfo.setUpDown(dir);
dklInfoService.save(dklInfo);
Map m = new HashMap();
m.put("stationCode", stationCode);
m.put("lineCode", lineCode);
m.put("stationName",stationName);
m.put("lineName",lineName);
m.put("num",num);
m.put("xlDir",dir);
sendUtils.klyj(m);//推送
}
rtn.put("status",ResponseCode.SUCCESS);
} catch (Exception e) {
rtn.put("err", ResponseCode.ERROR);
logger.error("",e);
}
return rtn;
}
//调度获取站台视频
@RequestMapping(value = "/getStationVideo", method = RequestMethod.GET)
public String getStationVideo(@RequestParam Map m) {
if (m.get("lineCode")==null || m.get("upDown")==null){
return null;
}
String sql="select url from station_video where line_code ='"+m.get("lineCode")+"' and up_down ='"+m.get("upDown")+"'";
String url= null;
try {
url = jdbcTemplate.queryForObject(sql,String.class);
} catch (DataAccessException e) {
return null;
}
return url;
}
}