ThirdController.java
5.7 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
package com.jkdata.controller;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.jkdata.entity.HistoryPoint;
import com.jkdata.entity.SafeArea;
import com.jkdata.entity.ThirdPosition;
import com.jkdata.service.IThirdService;
import com.jkdata.tool.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/3d")
public class ThirdController {
@Autowired
private IThirdService thirdService;
@ApiOperation(value="接收定位数据", notes="接收定位数据")
@PostMapping("/receivePosition")
public Result<Map<String,Object>> save(HttpServletRequest request, HttpServletResponse response) {
Result<Map<String,Object>> result = new Result<Map<String,Object>>();
Map<String,Object> map = new HashMap<>();
String resMsg = getPostData(request);
JSONObject jsonObject = initData(resMsg);
String type = jsonObject.getString("Type");
//判断消息类型
if("location_pos".equals(type)){
map.put("message",resMsg);
thirdService.savePosition(jsonObject);
result.setResult(map);
result.setSuccess(true);
}else{
result.error500("类型错误!");
}
return result;
}
//初始化数据
private JSONObject initData(String resMsg) {
// resMsg = "{\"Gateway\":\"10030049\"," +
// "\"NodeId\":\"CB8A1DEB\"," +
// "\"SystemId\":\"10990145\"," +
// "\"Type\":\"location_pos\"," +
// "\"group\":\"5\"," +
// "\"groupNumber\":1," +
// "\"position\":{\"x\":214.44541185285127,\"y\":210.15474327170986}," +
// "\"scale\":0}";
System.out.println("***"+System.currentTimeMillis()+"报文***"+resMsg);
JSONObject jsonObject = new JSONObject();
jsonObject = JSONObject.parseObject(resMsg);
return jsonObject;
}
//解析推送报文
private String getPostData(HttpServletRequest request) {
StringBuffer data = new StringBuffer();
String line = null;
BufferedReader reader = null;
try{
reader = request.getReader();
while (null!=(line = reader.readLine())){
data.append(line);
}
}catch (Exception e){
}
return data.toString();
}
/**
* 获取人员实时定位
* @return
*/
@ApiOperation(value="获取人员实时定位", notes="获取人员实时定位")
@GetMapping("/realTimeLocation")
public Result<ThirdPosition> getRealTimeLocation(String deviceId) {
Result<ThirdPosition> result = new Result<ThirdPosition>();
ThirdPosition thirdPosition = thirdService.getRealTimeLocation(deviceId);
result.setSuccess(true);
result.setResult(thirdPosition);
return result;
}
/**
* 获取静态资源信息
* @return
*/
@ApiOperation(value="获取静态资源信息", notes="获取静态资源信息")
@GetMapping("/buildingAllInfo")
public Result<JSONObject> getBuildingAllInfo() {
Result<JSONObject> result = new Result<JSONObject>();
String res = thirdService.getBuildingAllInfo();
JSONObject json = JSONObject.parseObject(res);
result.setSuccess(true);
result.setResult(json);
return result;
}
/**
* 获取历史轨迹
* @param deviceId
* @return
*/
@ApiOperation(value="获取历史轨迹", notes="获取历史轨迹")
@GetMapping("/positionByDeviceId")
public Result<List<HistoryPoint>> getPositionByDeviceId(String deviceId, String startTime, String endTime) {
Result<List<HistoryPoint>> result = new Result<List<HistoryPoint>>();
List<HistoryPoint> list = thirdService.getPositionByDeviceId(deviceId, startTime, endTime);
result.setSuccess(true);
result.setResult(list);
return result;
}
/**
* 获取告警信息-最新 n 条
* @return
*/
@ApiOperation(value="获取告警信息", notes="获取告警信息")
@GetMapping("/alarmListByCount")
public Result<Object> getAlarmListByCount() {
Result<Object> result = new Result<Object>();
String res = thirdService.getAlarmListByCount();
JSONObject json = JSONObject.parseObject(res);
result.setSuccess(true);
result.setResult(json.get("data"));
return result;
}
/**
* 获取最近7天的告警统计数据
* @return
*/
@ApiOperation(value="获取最近7天的告警统计数据", notes="获取最近7天的告警统计数据")
@GetMapping("/weekAlarmState")
public Result<Object> getWeekAlarmState() {
Result<Object> result = new Result<Object>();
String res = thirdService.getWeekAlarmState();
JSONObject json = JSONObject.parseObject(res);
result.setSuccess(true);
result.setResult(json.get("data"));
return result;
}
/**
* 获取安全区域
* @return
*/
@ApiOperation(value="获取安全区域", notes="获取安全区域")
@GetMapping("/safeArea")
public Result<List<SafeArea>> getSafeArea() {
Result<List<SafeArea>> result = new Result<List<SafeArea>>();
List<SafeArea> list = thirdService.getSafeAreaNew();
result.setSuccess(true);
result.setResult(list);
return result;
}
}