|
|
@@ -0,0 +1,131 @@
|
|
|
+package com.aoyang.tms.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.aoyang.common.param.PageParam;
|
|
|
+import com.aoyang.common.result.Result;
|
|
|
+import com.aoyang.tms.common.ErrCodeEnum;
|
|
|
+import com.aoyang.tms.controller.param.LocationQueryParam;
|
|
|
+import com.aoyang.tms.controller.param.Truck;
|
|
|
+import com.aoyang.tms.controller.vo.LocationVO;
|
|
|
+import com.aoyang.tms.entity.TruckSimCard;
|
|
|
+import com.aoyang.tms.feign.result.TmsMongoDoc;
|
|
|
+import com.aoyang.tms.service.TruckSimCardService;
|
|
|
+import com.aoyang.tms.service.WorkSpotService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 卡车位置信息获取 控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author guoyong
|
|
|
+ * @since 2022-04-21
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@Slf4j
|
|
|
+@Api(value = "卡车位置信息获取接口")
|
|
|
+@RequestMapping("/tms/location")
|
|
|
+public class TruckMongoInfoController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private WorkSpotService workSpotService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TruckSimCardService truckSimCardService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取卡车位置信息",notes="根据车牌号获取卡车位置信息")
|
|
|
+ @PostMapping("/get_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)) {
|
|
|
+ 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信息");
|
|
|
+ }
|
|
|
+ Query query = new Query(Criteria.where("clientId").is(truckSimCard.getClientId()));
|
|
|
+ query.with(new Sort(Sort.Direction.DESC, "createTime"));
|
|
|
+ TmsMongoDoc tmsMongoDoc = mongoTemplate.findOne(query, TmsMongoDoc.class);
|
|
|
+ // TODO 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取卡车位置信息list",notes="根据车牌号获取卡车位置信息list")
|
|
|
+ @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)) {
|
|
|
+ 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信息");
|
|
|
+ }
|
|
|
+ Criteria criteria = Criteria.where("clientId").is(truckSimCard.getClientId());
|
|
|
+ criteria.andOperator(Criteria.where("dateTime").gt());
|
|
|
+ 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上报数据转换
|
|
|
+ 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());
|
|
|
+ result.add(location);
|
|
|
+ }
|
|
|
+ return new Result<>(result);
|
|
|
+ }
|
|
|
+}
|