a4031a6d 张雷

Merge remote-tracking branch 'origin/dev' into dev

2 个父辈 043edb56 ee2216dd
......@@ -2,6 +2,8 @@ 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;
......@@ -12,6 +14,7 @@ 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
......@@ -106,12 +109,11 @@ public class ThirdController {
* @return
*/
@GetMapping("/positionByDeviceId")
public Result<JSONObject> getPositionByDeviceId(String deviceId,String startTime,String endTime) {
Result<JSONObject> result = new Result<JSONObject>();
String res = thirdService.getPositionByDeviceId(deviceId, startTime, endTime);
JSONObject json = JSONObject.parseObject(res);
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(json);
result.setResult(list);
return result;
}
......@@ -144,16 +146,15 @@ public class ThirdController {
}
/**
* 获取最近7天的告警统计数据
* 获取安全区域
* @return
*/
@GetMapping("/safeArea")
public Result<Object> getSafeArea() {
Result<Object> result = new Result<Object>();
String res = thirdService.getSafeArea();
JSONObject json = JSONObject.parseObject(res);
public Result<List<SafeArea>> getSafeArea() {
Result<List<SafeArea>> result = new Result<List<SafeArea>>();
List<SafeArea> list = thirdService.getSafeArea();
result.setSuccess(true);
result.setResult(json.get("data"));
result.setResult(list);
return result;
}
}
......
package com.jkdata.entity;
import lombok.Data;
@Data
public class HistoryPoint {
/**主键*/
private Integer id;
/**楼层编码*/
private String floorId;
/***/
private Integer number;
/**定位时间*/
private String locationTime;
/**X坐标*/
private Double x;
/**名称*/
private String name;
/**Y坐标*/
private Double y;
/**描述*/
private String comment;
/**设备ID*/
private String deviceId;
/**项目编码*/
private String buildingId;
}
package com.jkdata.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class SafeArea {
/**主键*/
private Integer id;
/**设备ID*/
private String deviceIds;
/**区域坐标*/
private String areas;
/**区域名称*/
private String name;
/**区域简介*/
private String comment;
/**构筑物描述*/
private Integer threshold;
/**项目编码*/
private Integer buildingId;
/**楼层编码*/
private Integer floorId;
/**报警类型*/
private String alarmType;
/**创建时间*/
private String createTime;
/** */
private Integer isSwitch;
/** */
private Integer areaType;
/** */
private Integer typeId;
/** */
private String startTime;
/** */
private String endTime;
}
package com.jkdata.service;
import com.alibaba.fastjson.JSONObject;
import com.jkdata.entity.HistoryPoint;
import com.jkdata.entity.SafeArea;
import com.jkdata.entity.ThirdPosition;
import java.util.List;
import java.util.Map;
public interface IThirdService {
......@@ -11,7 +14,7 @@ public interface IThirdService {
String getBuildingAllInfo();
String getPositionByDeviceId(String deviceId,String startTime,String endTime);
List<HistoryPoint> getPositionByDeviceId(String deviceId, String startTime, String endTime);
String getAlarmListByCount();
......@@ -19,5 +22,5 @@ public interface IThirdService {
ThirdPosition getRealTimeLocation(String deviceId);
String getSafeArea();
List<SafeArea> getSafeArea();
}
......
......@@ -2,6 +2,8 @@ package com.jkdata.service.impl;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.jkdata.entity.HistoryPoint;
import com.jkdata.entity.SafeArea;
import com.jkdata.tool.*;
import com.jkdata.entity.ThirdPosition;
import com.jkdata.mapper.ThirdMapper;
......@@ -135,7 +137,7 @@ public class IThirdServiceImpl implements IThirdService {
}
@Override
public String getPositionByDeviceId(String deviceId,String startTime,String endTime) {
public List<HistoryPoint> getPositionByDeviceId(String deviceId,String startTime,String endTime) {
HashMap<String,Object> map = new HashMap<>();
map.put("buildingId",CommonConstant.BLD_ID);
map.put("deviceId",deviceId);
......@@ -144,7 +146,17 @@ public class IThirdServiceImpl implements IThirdService {
map.put("startTime",startTime);
map.put("endTime",endTime);
String post = HttpUtil.post(CommonConstant.HISTORY_URL,map);
return post;
JSONObject json = JSONObject.parseObject(post);
List<HistoryPoint> list = JSONObject.parseArray(json.get("data").toString(), HistoryPoint.class);
for (HistoryPoint historyPoint : list) {
String x1 = String.valueOf(historyPoint.getX());
String y1 = String.valueOf(historyPoint.getY());
Map<String,Double> pointMap = new HashMap<>();//初始化
pointMap = CoordinateUtil.changCoordinate("B1",x1,y1);
historyPoint.setX(pointMap.get("x"));
historyPoint.setY(pointMap.get("y"));
}
return list;
}
@Override
......@@ -184,9 +196,24 @@ public class IThirdServiceImpl implements IThirdService {
}
@Override
public String getSafeArea() {
public List<SafeArea> getSafeArea() {
String get = HttpUtil.get(CommonConstant.SAFE_AREA_URL+"?buildingId="+CommonConstant.BLD_ID);
return get;
JSONObject json = JSONObject.parseObject(get);
List<SafeArea> list = JSONObject.parseArray(json.get("data").toString(), SafeArea.class);
for (SafeArea safeArea : list) {
String areas = safeArea.getAreas();//66&363,100&348,108&367,74&381
List<String> arealist = Arrays.asList(areas.split(","));
StringBuffer data = new StringBuffer();
for (String area:arealist) {
String x1 = area.split("&")[0];
String y1 = area.split("&")[1];
Map<String,Double> map = new HashMap<>();//初始化
map = CoordinateUtil.changCoordinate("B1",x1,y1);
data.append(String.valueOf(map.get("x"))+"&"+String.valueOf(map.get("y"))).append(",");
}
safeArea.setAreas(data.toString().substring(0,data.toString().length()-1));
}
return list;
}
......
package com.jkdata.tool;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;
public class StringsUtil {
//Object转Map
public static Map<String, Object> getObjectToMap(Object obj) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
try{
Class<?> clazz = obj.getClass();
for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
String fieldName = field.getName();
Object value = field.get(obj);
if (value == null) {
value = "";
}
map.put(fieldName, value);
}
return map;
}catch (Exception e){
return new LinkedHashMap<String, Object>();
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!