UpstreamEntrance.java
3.61 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
package com.bsth.controller.directive;
import com.bsth.entity.realcontrol.ScheduleRealInfoTag;
import com.bsth.service.directive.DirectiveService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bsth.data.directive.DayOfDirectives;
import com.bsth.data.pilot80.PilotReport;
import com.bsth.entity.directive.D80;
import com.bsth.entity.directive.DC0_A4;
import com.bsth.entity.directive.DirectiveReponse;
import java.util.List;
import java.util.Map;
/**
*
* @ClassName: UpstreamEntrance
* @Description: TODO(车载网关HTTP上行入口)
* @author PanZhao
* @date 2016年6月7日 下午3:00:01
*
*/
@RestController
@RequestMapping("/control")
public class UpstreamEntrance {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
DayOfDirectives dayOfDirectives;
@Autowired
DirectiveService directiveService;
@Autowired
PilotReport pilotReport;
@RequestMapping(value = "/upstream", method = RequestMethod.POST)
public String main(@RequestParam String json) {
logger.info("upstream: " + json);
try {
JSONObject jsonParam = JSONObject.parseObject(json);
// 60协议回复
if (jsonParam.getInteger("operCode") == null && jsonParam.getInteger("status") != null) {
try {
DirectiveReponse reply = JSON.toJavaObject(jsonParam, DirectiveReponse.class);
dayOfDirectives.reply(reply);
} catch (NumberFormatException e) {
logger.error("NumberFormatException ,,,,一般是老数据,msgId太大");
}
}
// 80协议上报
else if (jsonParam.getInteger("operCode") == 0X80) {
try {
JSONObject data = jsonParam.getJSONObject("data");
switch (data.getShort("operCode2")) {
case 0x26:
// 驾驶员上报
D80 d80 = JSON.toJavaObject(jsonParam, D80.class);
if(d80!=null && StringUtils.isNotEmpty(d80.getDeviceId()))
pilotReport.report(d80);
break;
case 0xA4:
data.put("port", data.getString("port").trim());
data.put("posPort", data.getString("posPort").trim());
data.put("posIpAddress", data.getString("posIpAddress").trim());
data.put("ipAddress", data.getString("ipAddress").trim());
DC0_A4 c0a4 = JSON.toJavaObject(jsonParam, DC0_A4.class);
pilotReport.report(c0a4);
break;
}
} catch (Exception e) {
logger.error("", e);
}
}
// 64协议 线路切换回复
else if (jsonParam.getInteger("operCode") == 0X64) {
dayOfDirectives.reply64(jsonParam);
} else
logger.warn("未知的上行数据,p: " + json);
} catch (Exception e) {
logger.error("", e);
}
return "{\"errCode\":0}";
}
@RequestMapping(value = "/stationSigno", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> stationSigno(@RequestBody Map<String, Object> map) {
return directiveService.stationSigno(map);
}
@RequestMapping(value = "/tagByLines", method = RequestMethod.GET)
public List<ScheduleRealInfoTag> tagByLines(@RequestParam String lines) {
return directiveService.tagByLines(lines);
}
}