人员定位代码优化修改
正在显示
6 个修改的文件
包含
144 行增加
和
17 行删除
... | @@ -2,6 +2,8 @@ package com.jkdata.controller; | ... | @@ -2,6 +2,8 @@ package com.jkdata.controller; |
2 | 2 | ||
3 | import cn.hutool.http.HttpUtil; | 3 | import cn.hutool.http.HttpUtil; |
4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
5 | import com.jkdata.entity.HistoryPoint; | ||
6 | import com.jkdata.entity.SafeArea; | ||
5 | import com.jkdata.entity.ThirdPosition; | 7 | import com.jkdata.entity.ThirdPosition; |
6 | import com.jkdata.service.IThirdService; | 8 | import com.jkdata.service.IThirdService; |
7 | import com.jkdata.tool.Result; | 9 | import com.jkdata.tool.Result; |
... | @@ -12,6 +14,7 @@ import javax.servlet.http.HttpServletRequest; | ... | @@ -12,6 +14,7 @@ import javax.servlet.http.HttpServletRequest; |
12 | import javax.servlet.http.HttpServletResponse; | 14 | import javax.servlet.http.HttpServletResponse; |
13 | import java.io.BufferedReader; | 15 | import java.io.BufferedReader; |
14 | import java.util.HashMap; | 16 | import java.util.HashMap; |
17 | import java.util.List; | ||
15 | import java.util.Map; | 18 | import java.util.Map; |
16 | 19 | ||
17 | @RestController | 20 | @RestController |
... | @@ -106,12 +109,11 @@ public class ThirdController { | ... | @@ -106,12 +109,11 @@ public class ThirdController { |
106 | * @return | 109 | * @return |
107 | */ | 110 | */ |
108 | @GetMapping("/positionByDeviceId") | 111 | @GetMapping("/positionByDeviceId") |
109 | public Result<JSONObject> getPositionByDeviceId(String deviceId,String startTime,String endTime) { | 112 | public Result<List<HistoryPoint>> getPositionByDeviceId(String deviceId, String startTime, String endTime) { |
110 | Result<JSONObject> result = new Result<JSONObject>(); | 113 | Result<List<HistoryPoint>> result = new Result<List<HistoryPoint>>(); |
111 | String res = thirdService.getPositionByDeviceId(deviceId, startTime, endTime); | 114 | List<HistoryPoint> list = thirdService.getPositionByDeviceId(deviceId, startTime, endTime); |
112 | JSONObject json = JSONObject.parseObject(res); | ||
113 | result.setSuccess(true); | 115 | result.setSuccess(true); |
114 | result.setResult(json); | 116 | result.setResult(list); |
115 | return result; | 117 | return result; |
116 | } | 118 | } |
117 | 119 | ||
... | @@ -144,16 +146,15 @@ public class ThirdController { | ... | @@ -144,16 +146,15 @@ public class ThirdController { |
144 | } | 146 | } |
145 | 147 | ||
146 | /** | 148 | /** |
147 | * 获取最近7天的告警统计数据 | 149 | * 获取安全区域 |
148 | * @return | 150 | * @return |
149 | */ | 151 | */ |
150 | @GetMapping("/safeArea") | 152 | @GetMapping("/safeArea") |
151 | public Result<Object> getSafeArea() { | 153 | public Result<List<SafeArea>> getSafeArea() { |
152 | Result<Object> result = new Result<Object>(); | 154 | Result<List<SafeArea>> result = new Result<List<SafeArea>>(); |
153 | String res = thirdService.getSafeArea(); | 155 | List<SafeArea> list = thirdService.getSafeArea(); |
154 | JSONObject json = JSONObject.parseObject(res); | ||
155 | result.setSuccess(true); | 156 | result.setSuccess(true); |
156 | result.setResult(json.get("data")); | 157 | result.setResult(list); |
157 | return result; | 158 | return result; |
158 | } | 159 | } |
159 | } | 160 | } | ... | ... |
1 | package com.jkdata.entity; | ||
2 | |||
3 | import lombok.Data; | ||
4 | |||
5 | @Data | ||
6 | public class HistoryPoint { | ||
7 | |||
8 | /**主键*/ | ||
9 | private Integer id; | ||
10 | /**楼层编码*/ | ||
11 | private String floorId; | ||
12 | /***/ | ||
13 | private Integer number; | ||
14 | /**定位时间*/ | ||
15 | private String locationTime; | ||
16 | /**X坐标*/ | ||
17 | private Double x; | ||
18 | /**名称*/ | ||
19 | private String name; | ||
20 | /**Y坐标*/ | ||
21 | private Double y; | ||
22 | /**描述*/ | ||
23 | private String comment; | ||
24 | /**设备ID*/ | ||
25 | private String deviceId; | ||
26 | /**项目编码*/ | ||
27 | private String buildingId; | ||
28 | } |
1 | package com.jkdata.entity; | ||
2 | |||
3 | import io.swagger.annotations.ApiModelProperty; | ||
4 | import lombok.Data; | ||
5 | |||
6 | @Data | ||
7 | public class SafeArea { | ||
8 | |||
9 | /**主键*/ | ||
10 | private Integer id; | ||
11 | /**设备ID*/ | ||
12 | private String deviceIds; | ||
13 | /**区域坐标*/ | ||
14 | private String areas; | ||
15 | /**区域名称*/ | ||
16 | private String name; | ||
17 | /**区域简介*/ | ||
18 | private String comment; | ||
19 | /**构筑物描述*/ | ||
20 | private Integer threshold; | ||
21 | /**项目编码*/ | ||
22 | private Integer buildingId; | ||
23 | /**楼层编码*/ | ||
24 | private Integer floorId; | ||
25 | /**报警类型*/ | ||
26 | private String alarmType; | ||
27 | /**创建时间*/ | ||
28 | private String createTime; | ||
29 | /** */ | ||
30 | private Integer isSwitch; | ||
31 | /** */ | ||
32 | private Integer areaType; | ||
33 | /** */ | ||
34 | private Integer typeId; | ||
35 | /** */ | ||
36 | private String startTime; | ||
37 | /** */ | ||
38 | private String endTime; | ||
39 | |||
40 | } |
1 | package com.jkdata.service; | 1 | package com.jkdata.service; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | import com.jkdata.entity.HistoryPoint; | ||
5 | import com.jkdata.entity.SafeArea; | ||
4 | import com.jkdata.entity.ThirdPosition; | 6 | import com.jkdata.entity.ThirdPosition; |
5 | 7 | ||
8 | import java.util.List; | ||
6 | import java.util.Map; | 9 | import java.util.Map; |
7 | 10 | ||
8 | public interface IThirdService { | 11 | public interface IThirdService { |
... | @@ -11,7 +14,7 @@ public interface IThirdService { | ... | @@ -11,7 +14,7 @@ public interface IThirdService { |
11 | 14 | ||
12 | String getBuildingAllInfo(); | 15 | String getBuildingAllInfo(); |
13 | 16 | ||
14 | String getPositionByDeviceId(String deviceId,String startTime,String endTime); | 17 | List<HistoryPoint> getPositionByDeviceId(String deviceId, String startTime, String endTime); |
15 | 18 | ||
16 | String getAlarmListByCount(); | 19 | String getAlarmListByCount(); |
17 | 20 | ||
... | @@ -19,5 +22,5 @@ public interface IThirdService { | ... | @@ -19,5 +22,5 @@ public interface IThirdService { |
19 | 22 | ||
20 | ThirdPosition getRealTimeLocation(String deviceId); | 23 | ThirdPosition getRealTimeLocation(String deviceId); |
21 | 24 | ||
22 | String getSafeArea(); | 25 | List<SafeArea> getSafeArea(); |
23 | } | 26 | } | ... | ... |
... | @@ -2,6 +2,8 @@ package com.jkdata.service.impl; | ... | @@ -2,6 +2,8 @@ package com.jkdata.service.impl; |
2 | 2 | ||
3 | import cn.hutool.http.HttpUtil; | 3 | import cn.hutool.http.HttpUtil; |
4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
5 | import com.jkdata.entity.HistoryPoint; | ||
6 | import com.jkdata.entity.SafeArea; | ||
5 | import com.jkdata.tool.*; | 7 | import com.jkdata.tool.*; |
6 | import com.jkdata.entity.ThirdPosition; | 8 | import com.jkdata.entity.ThirdPosition; |
7 | import com.jkdata.mapper.ThirdMapper; | 9 | import com.jkdata.mapper.ThirdMapper; |
... | @@ -135,7 +137,7 @@ public class IThirdServiceImpl implements IThirdService { | ... | @@ -135,7 +137,7 @@ public class IThirdServiceImpl implements IThirdService { |
135 | } | 137 | } |
136 | 138 | ||
137 | @Override | 139 | @Override |
138 | public String getPositionByDeviceId(String deviceId,String startTime,String endTime) { | 140 | public List<HistoryPoint> getPositionByDeviceId(String deviceId,String startTime,String endTime) { |
139 | HashMap<String,Object> map = new HashMap<>(); | 141 | HashMap<String,Object> map = new HashMap<>(); |
140 | map.put("buildingId",CommonConstant.BLD_ID); | 142 | map.put("buildingId",CommonConstant.BLD_ID); |
141 | map.put("deviceId",deviceId); | 143 | map.put("deviceId",deviceId); |
... | @@ -144,7 +146,17 @@ public class IThirdServiceImpl implements IThirdService { | ... | @@ -144,7 +146,17 @@ public class IThirdServiceImpl implements IThirdService { |
144 | map.put("startTime",startTime); | 146 | map.put("startTime",startTime); |
145 | map.put("endTime",endTime); | 147 | map.put("endTime",endTime); |
146 | String post = HttpUtil.post(CommonConstant.HISTORY_URL,map); | 148 | String post = HttpUtil.post(CommonConstant.HISTORY_URL,map); |
147 | return post; | 149 | JSONObject json = JSONObject.parseObject(post); |
150 | List<HistoryPoint> list = JSONObject.parseArray(json.get("data").toString(), HistoryPoint.class); | ||
151 | for (HistoryPoint historyPoint : list) { | ||
152 | String x1 = String.valueOf(historyPoint.getX()); | ||
153 | String y1 = String.valueOf(historyPoint.getY()); | ||
154 | Map<String,Double> pointMap = new HashMap<>();//初始化 | ||
155 | pointMap = CoordinateUtil.changCoordinate("B1",x1,y1); | ||
156 | historyPoint.setX(pointMap.get("x")); | ||
157 | historyPoint.setY(pointMap.get("y")); | ||
158 | } | ||
159 | return list; | ||
148 | } | 160 | } |
149 | 161 | ||
150 | @Override | 162 | @Override |
... | @@ -184,9 +196,24 @@ public class IThirdServiceImpl implements IThirdService { | ... | @@ -184,9 +196,24 @@ public class IThirdServiceImpl implements IThirdService { |
184 | } | 196 | } |
185 | 197 | ||
186 | @Override | 198 | @Override |
187 | public String getSafeArea() { | 199 | public List<SafeArea> getSafeArea() { |
188 | String get = HttpUtil.get(CommonConstant.SAFE_AREA_URL+"?buildingId="+CommonConstant.BLD_ID); | 200 | String get = HttpUtil.get(CommonConstant.SAFE_AREA_URL+"?buildingId="+CommonConstant.BLD_ID); |
189 | return get; | 201 | JSONObject json = JSONObject.parseObject(get); |
202 | List<SafeArea> list = JSONObject.parseArray(json.get("data").toString(), SafeArea.class); | ||
203 | for (SafeArea safeArea : list) { | ||
204 | String areas = safeArea.getAreas();//66&363,100&348,108&367,74&381 | ||
205 | List<String> arealist = Arrays.asList(areas.split(",")); | ||
206 | StringBuffer data = new StringBuffer(); | ||
207 | for (String area:arealist) { | ||
208 | String x1 = area.split("&")[0]; | ||
209 | String y1 = area.split("&")[1]; | ||
210 | Map<String,Double> map = new HashMap<>();//初始化 | ||
211 | map = CoordinateUtil.changCoordinate("B1",x1,y1); | ||
212 | data.append(String.valueOf(map.get("x"))+"&"+String.valueOf(map.get("y"))).append(","); | ||
213 | } | ||
214 | safeArea.setAreas(data.toString().substring(0,data.toString().length()-1)); | ||
215 | } | ||
216 | return list; | ||
190 | } | 217 | } |
191 | 218 | ||
192 | 219 | ... | ... |
1 | package com.jkdata.tool; | ||
2 | |||
3 | import java.lang.reflect.Field; | ||
4 | import java.util.LinkedHashMap; | ||
5 | import java.util.Map; | ||
6 | |||
7 | public class StringsUtil { | ||
8 | |||
9 | //Object转Map | ||
10 | public static Map<String, Object> getObjectToMap(Object obj) { | ||
11 | Map<String, Object> map = new LinkedHashMap<String, Object>(); | ||
12 | try{ | ||
13 | Class<?> clazz = obj.getClass(); | ||
14 | for (Field field : clazz.getDeclaredFields()) { | ||
15 | field.setAccessible(true); | ||
16 | String fieldName = field.getName(); | ||
17 | Object value = field.get(obj); | ||
18 | if (value == null) { | ||
19 | value = ""; | ||
20 | } | ||
21 | map.put(fieldName, value); | ||
22 | } | ||
23 | return map; | ||
24 | }catch (Exception e){ | ||
25 | return new LinkedHashMap<String, Object>(); | ||
26 | } | ||
27 | } | ||
28 | } |
-
请 注册 或 登录 后发表评论