|
@@ -5,6 +5,7 @@ import com.aoyang.common.result.Result;
|
|
|
import com.aoyang.tms.entity.WorkSpot;
|
|
import com.aoyang.tms.entity.WorkSpot;
|
|
|
import com.aoyang.tms.feign.result.TmsMongoDoc;
|
|
import com.aoyang.tms.feign.result.TmsMongoDoc;
|
|
|
import com.aoyang.tms.service.*;
|
|
import com.aoyang.tms.service.*;
|
|
|
|
|
+import com.aoyang.tms.util.RegionUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -17,6 +18,7 @@ import org.springframework.data.mongodb.core.query.Query;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -38,13 +40,27 @@ public class TestController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private CommonService commonService;
|
|
private CommonService commonService;
|
|
|
|
|
|
|
|
- @ApiOperation(value = "mongo查询测试接口", notes = "判断输入经纬度是否在围栏内")
|
|
|
|
|
- @PostMapping("/mongo")
|
|
|
|
|
|
|
+ @ApiOperation(value = "mongo查询车辆最新位置", notes = "")
|
|
|
|
|
+ @PostMapping("/query_truck")
|
|
|
|
|
+ public Result queryTruck(@RequestParam Long truckId) {
|
|
|
|
|
+ log.info("测试接口 /tms/test/queryTruck,参数:{}", truckId);
|
|
|
|
|
+ return new Result<>(commonService.getLocation(truckId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "mongo查询车辆最新位置", notes = "")
|
|
|
|
|
+ @PostMapping("/query_truck_trip")
|
|
|
|
|
+ public Result queryTruckTrip(@RequestParam Long truckId) {
|
|
|
|
|
+ log.info("测试接口 /tms/test/query_truck_trip,参数:{}", truckId);
|
|
|
|
|
+ return new Result<>(commonService.getLocationtrip(truckId, LocalDateTime.now().minusHours(1), LocalDateTime.now()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "mongo查询测试接口", notes = "判断车辆否在围栏内")
|
|
|
|
|
+ @PostMapping("/mongoCheck")
|
|
|
public Result testMongo(@RequestParam String clientId,
|
|
public Result testMongo(@RequestParam String clientId,
|
|
|
@RequestParam Long spotId) {
|
|
@RequestParam Long spotId) {
|
|
|
-// log.info("测试接口 /tms/test/mongo,参数:{}", spotId);
|
|
|
|
|
-//// WorkSpot spot = workSpotService.getById(spotId);
|
|
|
|
|
-//// Point point = new Point(Double.valueOf(spot.getLongitude()), Double.valueOf(spot.getLatitude()));
|
|
|
|
|
|
|
+ log.info("测试接口 /tms/test/mongo,参数:{}", spotId);
|
|
|
|
|
+ WorkSpot spot = workSpotService.getById(spotId);
|
|
|
|
|
+// Point point = new Point(Double.valueOf(spot.getLongitude()), Double.valueOf(spot.getLatitude()));
|
|
|
//// Criteria criteria = Criteria.where("clientId").is(clientId);
|
|
//// Criteria criteria = Criteria.where("clientId").is(clientId);
|
|
|
//// Query query = new Query(criteria);
|
|
//// Query query = new Query(criteria);
|
|
|
//// query.with(new Sort(Sort.Direction.DESC, "dateTime"));
|
|
//// query.with(new Sort(Sort.Direction.DESC, "dateTime"));
|
|
@@ -52,12 +68,55 @@ public class TestController {
|
|
|
//// .maxDistance(new Distance(spot.getValidDistance(), Metrics.KILOMETERS))
|
|
//// .maxDistance(new Distance(spot.getValidDistance(), Metrics.KILOMETERS))
|
|
|
//// .num(2);
|
|
//// .num(2);
|
|
|
//// GeoResults<TmsMongoDoc> geoResults = mongoTemplate.geoNear(nearQuery, TmsMongoDoc.class);
|
|
//// GeoResults<TmsMongoDoc> geoResults = mongoTemplate.geoNear(nearQuery, TmsMongoDoc.class);
|
|
|
|
|
+ String regionData = spot.getRegionData();
|
|
|
|
|
+ String points = regionData.substring(2, regionData.length() - 2);
|
|
|
|
|
+ String[] dataList = points.split(";");
|
|
|
|
|
+ Double[] lon = new Double[dataList.length];
|
|
|
|
|
+ Double[] lat = new Double[dataList.length];
|
|
|
|
|
+ for (int i=0;i<dataList.length;i++) {
|
|
|
|
|
+ String data = dataList[i];
|
|
|
|
|
+ String[] split = data.split(",");
|
|
|
|
|
+ lon[i] = Double.valueOf(split[0]);
|
|
|
|
|
+ lat[i] = Double.valueOf(split[1]);
|
|
|
|
|
+ }
|
|
|
|
|
+ Criteria criteria = Criteria.where("clientId").is(clientId);
|
|
|
|
|
+ criteria.andOperator(Criteria.where("createTime").gt(LocalDateTime.now().minusDays(1)));
|
|
|
|
|
+ Query query = new Query(criteria);
|
|
|
|
|
+ List<TmsMongoDoc> tmsMongoDocs = mongoTemplate.find(query, TmsMongoDoc.class);
|
|
|
|
|
+ for (TmsMongoDoc doc : tmsMongoDocs) {
|
|
|
|
|
+ boolean flag = RegionUtil.isInPolygon(Double.valueOf(doc.getLongitude()),
|
|
|
|
|
+ Double.valueOf(doc.getLatitude()), lon, lat);
|
|
|
|
|
+ if (flag) {
|
|
|
|
|
+ return new Result<>(doc);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return new Result<>(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "工具类测试", notes = "")
|
|
|
|
|
+ @PostMapping("/testUtil")
|
|
|
|
|
+ public Result testMongo(@RequestParam Float lon, @RequestParam Float lat,
|
|
|
|
|
+ @RequestParam Long spotId){
|
|
|
|
|
+ log.info("测试接口 /tms/test/testUtil,参数:{},{}", lon, lat);
|
|
|
|
|
+ WorkSpot spot = workSpotService.getById(spotId);
|
|
|
|
|
+ String regionData = spot.getRegionData();
|
|
|
|
|
+ String points = regionData.substring(2, regionData.length() - 2);
|
|
|
|
|
+ String[] dataList = points.split(";");
|
|
|
|
|
+ Double[] lons = new Double[dataList.length];
|
|
|
|
|
+ Double[] lats = new Double[dataList.length];
|
|
|
|
|
+ for (int i=0;i<dataList.length;i++) {
|
|
|
|
|
+ String data = dataList[i];
|
|
|
|
|
+ String[] split = data.split(",");
|
|
|
|
|
+ lons[i] = Double.valueOf(split[0]);
|
|
|
|
|
+ lats[i] = Double.valueOf(split[1]);
|
|
|
|
|
+ }
|
|
|
|
|
+ boolean flag = RegionUtil.isInPolygon(lon, lat, lons, lats);
|
|
|
return new Result<>();
|
|
return new Result<>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "mongo查询测试接口", notes = "判断输入经纬度是否在围栏内")
|
|
|
|
|
|
|
+ @ApiOperation(value = "根据经纬度查询位置", notes = "根据经纬度查询位置")
|
|
|
@PostMapping("/baiduapi")
|
|
@PostMapping("/baiduapi")
|
|
|
- public Result testBaiduApi(@RequestParam Float lat, @RequestParam Float lon) {
|
|
|
|
|
|
|
+ public Result testBaiduApi(@RequestParam Float lon, @RequestParam Float lat) {
|
|
|
return new Result<>(commonService.longitudeToAddress(lat, lon));
|
|
return new Result<>(commonService.longitudeToAddress(lat, lon));
|
|
|
}
|
|
}
|
|
|
|
|
|