|
|
@@ -30,7 +30,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@@ -57,8 +59,10 @@ public class TruckMongoInfoController {
|
|
|
@Resource
|
|
|
private TruckSimCardService truckSimCardService;
|
|
|
|
|
|
+ private static final SimpleDateFormat format = new SimpleDateFormat("YYMMddHHmmss");
|
|
|
+
|
|
|
@ApiOperation(value = "获取卡车位置信息",notes="根据车牌号获取卡车位置信息")
|
|
|
- @PostMapping("/get_truck")
|
|
|
+ @PostMapping("/get_by_truck")
|
|
|
public Result<LocationVO> getCurrentTruck(@RequestBody LocationQueryParam param) {
|
|
|
log.info("根据车牌号获取卡车位置信息,调用/tms/location/get_truck param:{} ", JSON.toJSONString(param));
|
|
|
if (param == null || (StringUtils.isBlank(param.getCarNumber()) && param.getTruckId() == null)) {
|
|
|
@@ -94,7 +98,8 @@ public class TruckMongoInfoController {
|
|
|
@PostMapping("/get_truck_trip")
|
|
|
public Result<List<LocationVO>> getTruckTrip(@RequestBody LocationQueryParam param) {
|
|
|
log.info("根据车牌号获取卡车位置信息,调用/tms/location/get_truck param:{} ", JSON.toJSONString(param));
|
|
|
- if (param == null || (StringUtils.isBlank(param.getCarNumber()) && param.getTruckId() == null)) {
|
|
|
+ if (param == null || (StringUtils.isBlank(param.getCarNumber()) && param.getTruckId() == null) ||
|
|
|
+ param.getStartTime() == null || param.getEndTime() == null) {
|
|
|
return new Result<>(ErrCodeEnum.BAD_PARAM.getCode(), ErrCodeEnum.BAD_PARAM.getMessage());
|
|
|
}
|
|
|
QueryWrapper<TruckSimCard> queryWrapper = new QueryWrapper<>();
|
|
|
@@ -108,15 +113,17 @@ public class TruckMongoInfoController {
|
|
|
if (truckSimCard == null) {
|
|
|
return new Result<>(ErrCodeEnum.INVALID_TRUCK.getCode(), "卡车无simcard信息");
|
|
|
}
|
|
|
+
|
|
|
Criteria criteria = Criteria.where("clientId").is(truckSimCard.getClientId());
|
|
|
- criteria.andOperator(Criteria.where("dateTime").gt());
|
|
|
+ criteria.andOperator(Criteria.where("dateTime").gt(format.format(param.getStartTime())));
|
|
|
+ criteria.andOperator(Criteria.where("dateTime").lt(format.format(param.getEndTime())));
|
|
|
Query query = new Query(criteria);
|
|
|
query.with(new Sort(Sort.Direction.DESC, "createTime"));
|
|
|
|
|
|
List<TmsMongoDoc> tmsMongoDocs = mongoTemplate.find(query, TmsMongoDoc.class);
|
|
|
List<LocationVO> result = new ArrayList<>();
|
|
|
for (TmsMongoDoc tmsMongoDoc : tmsMongoDocs) {
|
|
|
- // TODO mongo上报数据转换
|
|
|
+ // mongo上报数据转换
|
|
|
LocationVO location = new LocationVO();
|
|
|
location.setLatitude(tmsMongoDoc.getLatitude() + "");
|
|
|
location.setLongitude(tmsMongoDoc.getLongitude() + "");
|
|
|
@@ -128,4 +135,48 @@ public class TruckMongoInfoController {
|
|
|
}
|
|
|
return new Result<>(result);
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取卡车距时间相近的位置信息",notes="根据车牌号和时间获取卡车位置信息")
|
|
|
+ @PostMapping("/get_by_date")
|
|
|
+ public Result<LocationVO> getTruckLocationByDate(@RequestBody LocationQueryParam param) {
|
|
|
+ log.info("根据车牌号获取卡车位置信息,调用/tms/location/get_truck param:{} ", JSON.toJSONString(param));
|
|
|
+ if (param == null || (StringUtils.isBlank(param.getCarNumber()) && param.getTruckId() == null) ||
|
|
|
+ param.getLocalDate() == null) {
|
|
|
+ return new Result<>(ErrCodeEnum.BAD_PARAM.getCode(), ErrCodeEnum.BAD_PARAM.getMessage());
|
|
|
+ }
|
|
|
+ QueryWrapper<TruckSimCard> queryWrapper = new QueryWrapper<>();
|
|
|
+ if (param.getTruckId() != null) {
|
|
|
+ queryWrapper.eq("truck_id", param.getTruckId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(param.getCarNumber())) {
|
|
|
+ queryWrapper.eq("car_number", param.getCarNumber());
|
|
|
+ }
|
|
|
+ TruckSimCard truckSimCard = truckSimCardService.getOne(queryWrapper);
|
|
|
+ if (truckSimCard == null) {
|
|
|
+ return new Result<>(ErrCodeEnum.INVALID_TRUCK.getCode(), "卡车无simcard信息");
|
|
|
+ }
|
|
|
+ Date queryDate = param.getLocalDate();
|
|
|
+ String dateStr = format.format(queryDate);
|
|
|
+ Criteria criteria = Criteria.where("clientId").is(truckSimCard.getClientId());
|
|
|
+ criteria.andOperator(Criteria.where("dateTime").gt(dateStr));
|
|
|
+ Query query = new Query(criteria);
|
|
|
+ query.with(new Sort(Sort.Direction.ASC, "dateTime"));
|
|
|
+ TmsMongoDoc tmsMongoDoc = mongoTemplate.findOne(query, TmsMongoDoc.class);
|
|
|
+ // mongo上报数据转换
|
|
|
+ LocationVO location = new LocationVO();
|
|
|
+ // 经纬度
|
|
|
+ location.setLatitude(tmsMongoDoc.getLatitude()+"");
|
|
|
+ location.setLongitude(tmsMongoDoc.getLongitude()+"");
|
|
|
+ location.setCarNumber(truckSimCard.getCarNumber());
|
|
|
+ location.setTruckId(truckSimCard.getTruckId());
|
|
|
+ // 时间格式: YYMMDDHHMMSS
|
|
|
+ location.setLocalTime("20" + tmsMongoDoc.getDateTime());
|
|
|
+ return new Result<>(location);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ Date date = new Date();
|
|
|
+ System.out.println("@@" + format.format(date));
|
|
|
+ }
|
|
|
+
|
|
|
}
|