Commit 636f0761 by Jiang

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

parents 1d2b44b3 71c80445
......@@ -79,6 +79,15 @@ public class SkTrail extends Model<SkTrail> implements Comparable<SkTrail>{
private String isdeleted;
/**
* 开始时间,
*/
private String startTime;
/**
* 结束时间
*/
private String endTime;
/**
* 获取主键值
*
* @return 主键值
......
......@@ -20,8 +20,13 @@ public class TogetherEntity {
private long starttimestamp;
private long endtimestamp;
private long timestamp;//时间戳
private double radius;//两点距离(米)
private int minutes;//时间范围(分钟)
private long timeIterval;//时间间隔
private String timeItervalStr;//时间间隔
}
......@@ -2,8 +2,10 @@ package com.founder.publicapi.controller.SkModelService;
import com.founder.commonutils.newPublicEntity.SkTrail;
import com.founder.commonutils.newPublicEntity.TogetherEntity;
import com.founder.publicapi.service.serviceimpl.TbStAsjServiceImpl;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import java.util.*;
......@@ -13,6 +15,8 @@ import java.util.*;
public class SkbsController {
/**
* 如果是强轨迹则传入时间段StartTime EndTime
* 如果是强轨迹则传入时间点 Time
* 传入设定伴随的两点间可以相隔的时间(分钟)minutes,传入伴随的两点间距离的最大直径(米)radius
* 获得所有轨迹的集合
* 轨迹数据的时间点或者时间段,在前后加减传入时间间隔
......@@ -42,6 +46,7 @@ public class SkbsController {
/**将原数据转为需要的数据*/
public List getYToGjInfo(TogetherEntity requestParams,List<SkTrail> list){
List<TogetherEntity> resultList = new ArrayList<>();
long timeItervalMillns = requestParams.getMinutes() * 60 * 1000;//分钟转毫秒
TogetherEntity a;
for (SkTrail var : list) {
if ( StringUtils.isBlank(var.getTime()) || StringUtils.isBlank(var.getX()) || StringUtils.isBlank(var.getY())) {
......@@ -51,12 +56,54 @@ public class SkbsController {
a.setJ(Double.parseDouble(var.getX()));
a.setW(Double.parseDouble(var.getY()));
a.setAddress(var.getAddress());
a.setStarttimestamp(getDateMinusToStr(var.getTime(), requestParams.getMinutes()));
a.setEndtimestamp(getDateAddToStr(var.getTime(), requestParams.getMinutes()));
a.setObjectValue(var.getObjectvalue());
a.setObjectType(var.getObjecttype());
//如果是强轨迹则传入时间点 Time
if(StringUtils.isNotBlank(var.getTime())){
a.setTimestamp(Long.parseLong(var.getTime()));
resultList.add(a);
}
//如果是强轨迹则传入时间段StartTime EndTime
if (a.getJ() != 0D && a.getW() != 0D && StringUtils.isNotBlank(a.getStartTime()) && StringUtils.isNotBlank(a.getEndTime())) {
a.setStarttimestamp(getDateMinusToStr(a.getStartTime(), 0));
a.setEndtimestamp(getDateMinusToStr(a.getEndTime(), 0));
List<Long> timeList = getTimeSplitList(a.getStarttimestamp(), a.getEndtimestamp(), timeItervalMillns);
if (timeList != null && timeList.size() != 0) {
Iterator<Long> it = timeList.iterator();
while (it.hasNext()) {
a.setTimestamp(it.next());
resultList.add(a);
}
}
} else if (a.getJ() != 0D && a.getW() != 0D && StringUtils.isNotBlank(a.getStartTime())) {
a.setTimestamp(getDateMinusToStr(a.getStartTime(), 0));
resultList.add(a);
} else if (a.getJ() != 0D && a.getW() != 0D && StringUtils.isNotBlank(a.getEndTime())) {
a.setTimestamp(getDateMinusToStr(a.getStartTime(), 0));
resultList.add(a);
}
}
return resultList;
}
/**
* 将开始时间和结束时间的时间段转为时间点*/
public List<Long> getTimeSplitList(long startTime, long endTime, long timeItervalMillns) {
List resultList = new ArrayList();
resultList.add(startTime);
do {
startTime += timeItervalMillns;
if (startTime < endTime) {
resultList.add(startTime);
} else if (startTime >= endTime){
resultList.add(endTime);
break;
}
}
while (startTime < endTime);
return resultList;
}
......@@ -68,17 +115,6 @@ public class SkbsController {
Date date=new Date(Long.parseLong(time));
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.SECOND, -minutes);
return c.getTimeInMillis();
}
/**
* @param time 字符串时间戳
*结束时间加上分钟
* */
public long getDateAddToStr(String time, int minutes) {
Date date=new Date(Long.parseLong(time));
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.SECOND, minutes);
return c.getTimeInMillis();
}
......@@ -92,34 +128,45 @@ public class SkbsController {
* */
public List getSkbsfx(TogetherEntity requestParams,List<TogetherEntity> paramList){
List<TogetherEntity> resultList = new ArrayList<>();
Collections.sort(paramList, Comparator.comparing(TogetherEntity::getStarttimestamp));
long timeItervalMinutes = requestParams.getMinutes() * 60 * 1000;
/**
* list2为所有数据的集合,将集合按轨迹开始时间排序
* */
Collections.sort(paramList, Comparator.comparing(TogetherEntity::getTimestamp));
for (int i = 1; i < paramList.size(); i++) {
TogetherEntity t = paramList.get(i - 1);
TogetherEntity t1 = paramList.get(i);
if(!t.getObjectValue().equals(t1.getObjectValue())){
TogetherEntity a = paramList.get(i - 1);
TogetherEntity a1 = paramList.get(i);
TogetherEntity t = new TogetherEntity();
TogetherEntity t1 = new TogetherEntity();
//复制实体数据
BeanUtils.copyProperties(a, t);
BeanUtils.copyProperties(a1, t1);
if (!t.getObjectValue().equals(t1.getObjectValue())) {
long timeIterval = t1.getTimestamp() - t.getTimestamp();
double s = getDistance(t.getJ(), t.getW(), t1.getJ(), t1.getW());
if (s != 0 && s < requestParams.getRadius()) {
long time1 = t.getStarttimestamp();
long time2 = t.getEndtimestamp();
long time3 = t1.getStarttimestamp();
long time4 = t1.getEndtimestamp();
if ( time4 >= time1 && time2 >= time3){
if(resultList.size()!=0){
TogetherEntity t3 =resultList.get(resultList.size()-1);
if(t.getW()!=t3.getW()||t.getJ()!=t3.getJ()){
if (s < requestParams.getRadius() && timeIterval < timeItervalMinutes) {
resultList.add(t);
}
}else{
resultList.add(t);
}
t1.setDescripText("距离" + t.getAddress() +" 有 "+ s + " 米");
t1.setTimeIterval(timeIterval);
t1.setTimeItervalStr(String.valueOf(timeIterval));
//添加地址
StringBuilder sbdescripText = new StringBuilder();
sbdescripText.append("距离");
sbdescripText.append(t.getAddress());
sbdescripText.append(" 有 ");
sbdescripText.append(s);
sbdescripText.append(" 米");
t1.setDescripText(sbdescripText.toString());
resultList.add(t1);
}
}
}
}
resultList.stream().sorted(Comparator.comparing(TogetherEntity::getTimestamp));
return resultList;
}
......
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