Commit 97b651db by YANGYANG

用户实时轨迹 提交

parent a45b1c62
package com.founder.commonutils.ZdryApiEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author yangyang
* @since 2021-05-31
*/
@Data
@ApiModel(value="locationData对象", description="locationData对象")
public class LocationData implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = " 设备")
private String device ;
@ApiModelProperty(value = "记录时间")
private String created_at;
@ApiModelProperty(value = "发生时间")
private String time_begin;
@ApiModelProperty(value = "0:Gps定位; 1:基站定位")
private String type;
@ApiModelProperty(value = "城市")
private String city;
@ApiModelProperty(value = "地址")
private String address;
@ApiModelProperty(value = "x经度")
private String x;
@ApiModelProperty(value = "y纬度")
private String y;
}
......@@ -5,6 +5,7 @@ import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.zdryapi.service.ZdryApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
......@@ -37,7 +38,8 @@ public class ZdryApiController {
@ApiOperation(value = "查看指定设备接口")
@PostMapping(value = "/getDevice")
public Device getDevice(@RequestParam(value = "deviceId") String deviceId) {
public Device getDevice(@ApiParam(name = "deviceId", value = "设备IMEI", required = true)
@RequestParam(value = "deviceId") String deviceId) {
long startTime=new Date().getTime();
Device result=zdryApiService.getDevice(deviceId);
long endTime=new Date().getTime();
......@@ -51,5 +53,15 @@ public class ZdryApiController {
public String updateDevice(@RequestBody Device deviceParam) {
return zdryApiService.updateDevice(deviceParam);
}
@ApiOperation(value = "查看设备定位数据")
@PostMapping(value = "/locationdata")
public MapRestResult locationdata(@ApiParam(name = "deviceId", value = "设备IMEI", required = true)
@RequestParam(value = "deviceId") String deviceId,
@ApiParam(name = "time_begin", value = "YYYYMMDD,查询指定日期的数据")
@RequestParam(required = false) String time_begin
) {
return zdryApiService.locationdata(deviceId,time_begin);
}
}
......@@ -18,4 +18,7 @@ public interface ZdryApiService {
Device getDevice(String deviceId);
String updateDevice(Device deviceParam);
MapRestResult locationdata(String deviceId,String time_begin);
}
package com.founder.zdryapi.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.founder.commonutils.ZdryApiEntity.Device;
import com.founder.commonutils.ZdryApiEntity.LocationData;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.zdryapi.service.ZdryApiService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,6 +16,11 @@ import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/*
*
* <p>
......@@ -44,6 +52,8 @@ public class ZdryApiServiceImpl implements ZdryApiService {
@Value("${updateSbxxUrl}")
private String updateSbxxUrl;
@Value("${locationUrl}")
private String locationUrl;
@Autowired
private RestTemplate restTemplate;
......@@ -130,6 +140,74 @@ public class ZdryApiServiceImpl implements ZdryApiService {
return "success";
}
@Override
public MapRestResult locationdata(String deviceId, String time_begin) {
List<LocationData> listResult = new ArrayList<>();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String url = "";
if(StringUtils.isNotEmpty(time_begin)){
url = zdryUrl+locationUrl+"?device="+deviceId+"&time_begin="+time_begin;
}else{
url = zdryUrl+locationUrl+"?device="+deviceId;
}
try {
String resultString = restTemplate.getForEntity(url,String.class).getBody();
if (StringUtils.isNotEmpty(resultString)) {
JSONObject result = JSONObject.parseObject(resultString);
// 查看是否登录
if (result.containsKey("error_code")) {
if(getToken().equals("success")){
resultString = restTemplate.getForEntity(url,String.class).getBody();
}else{
return MapRestResult.build(200,"获取轨迹信息失败","1");
};
}
JSONObject resultLast = JSONObject.parseObject(resultString);
if (resultLast.containsKey("objs")) {
JSONArray jsonArray = resultLast.getJSONArray("objs");
for(int i = 0;i<jsonArray.size();i++){
JSONObject obj = jsonArray.getJSONObject(i);
LocationData locationData = new LocationData();
String device = obj.getString("device");
JSONObject time = obj.getJSONObject("created_at");
JSONObject time1 = obj.getJSONObject("time_begin");
String created_at = time.getString("$date");
String time_begins = time1.getString("$date");
String type = obj.getString("type");
String city = obj.getString("city");
String address = obj.getString("address");
JSONObject point = obj.getJSONObject("point");
JSONArray jsonArrayPoint = point.getJSONArray("coordinates");
String x = jsonArrayPoint.get(0).toString();
String y = jsonArrayPoint.get(1).toString();
locationData.setDevice(device);
locationData.setCreated_at(sf.format(new Date(Long.parseLong(created_at))));
locationData.setTime_begin(sf.format(new Date(Long.parseLong(time_begins))));
if(type.equals("1")){
locationData.setType("基站定位");
}else{
locationData.setType("Gps定位");
}
locationData.setCity(city);
locationData.setAddress(address);
locationData.setX(x);
locationData.setY(y);
listResult.add(locationData);
}
return MapRestResult.build(200,"获取轨迹信息成功",listResult,listResult.size());
}
}
}catch (Exception e){
e.printStackTrace();
}
return MapRestResult.build(200,"获取轨迹信息成功",listResult,listResult.size());
}
public String getToken() {
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json");
......@@ -144,7 +222,7 @@ public class ZdryApiServiceImpl implements ZdryApiService {
JSONObject result = JSONObject.parseObject(resultString);
// 查看是否登录
if (result.containsKey("error_code")) {
if (result.containsKey("error_code")) {
return "error";
}else {
return "success";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment