Browse Source

feat:运单新增结算里程字段

wangweiyu 4 years ago
parent
commit
812d187b2d

+ 11 - 1
pom.xml

@@ -151,7 +151,17 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-mongodb</artifactId>
         </dependency>
-
+        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.4.10</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.6</version>
+        </dependency>
     </dependencies>
 
     <profiles>

+ 8 - 0
src/main/java/com/aoyang/tms/controller/TestController.java

@@ -35,6 +35,8 @@ public class TestController {
     private WorkSpotService workSpotService;
     @Resource
     private MongoTemplate mongoTemplate;
+    @Resource
+    private CommonService commonService;
 
     @ApiOperation(value = "mongo查询测试接口", notes = "判断输入经纬度是否在围栏内")
     @PostMapping("/mongo")
@@ -52,4 +54,10 @@ public class TestController {
 ////        GeoResults<TmsMongoDoc> geoResults = mongoTemplate.geoNear(nearQuery, TmsMongoDoc.class);
         return new Result<>();
     }
+
+    @ApiOperation(value = "mongo查询测试接口", notes = "判断输入经纬度是否在围栏内")
+    @PostMapping("/mongo")
+    public Result testBaiduApi(@RequestParam String lat, @RequestParam String lon) {
+        return new Result<>(commonService.longitudeToAddress(lat, lon));
+    }
 }

+ 3 - 3
src/main/java/com/aoyang/tms/controller/TruckMongoInfoController.java

@@ -117,8 +117,8 @@ public class TruckMongoInfoController {
         }
 
         Criteria criteria = Criteria.where("clientId").is(truckSimCard.getClientId());
-        criteria.andOperator(Criteria.where("dateTime").gt(format.format(param.getStartTime())));
-        criteria.andOperator(Criteria.where("dateTime").lt(format.format(param.getEndTime())));
+        criteria.andOperator(Criteria.where("createTime").gt(format.format(param.getStartTime())));
+        criteria.andOperator(Criteria.where("createTime").lt(format.format(param.getEndTime())));
         Query query = new Query(criteria);
         List<TmsMongoDoc> tmsMongoDocs = mongoTemplate.find(query, TmsMongoDoc.class);
         List<LocationVO> result = new ArrayList<>();
@@ -157,7 +157,7 @@ public class TruckMongoInfoController {
         Date queryDate = param.getLocalDate();
         String dateStr = format.format(queryDate);
         Criteria criteria = Criteria.where("clientId").is(truckSimCard.getClientId());
-        criteria.andOperator(Criteria.where("dateTime").gt(dateStr));
+        criteria.andOperator(Criteria.where("createTime").gt(dateStr));
         Query query = new Query(criteria);
         query.with(new Sort(Sort.Direction.ASC, "dateTime"));
         TmsMongoDoc tmsMongoDoc = mongoTemplate.findOne(query, TmsMongoDoc.class);

+ 8 - 0
src/main/java/com/aoyang/tms/service/CommonService.java

@@ -116,4 +116,12 @@ public interface CommonService {
      */
     List<String> getLocationtrip(Long truckId, LocalDateTime startDate, LocalDateTime endDate);
 
+    /**
+     * 经纬度转位置信息
+     * @param lat
+     * @param lng
+     * @return
+     */
+    String longitudeToAddress(float lat, float lng);
+
 }

+ 40 - 33
src/main/java/com/aoyang/tms/service/impl/CommonServiceImpl.java

@@ -13,14 +13,20 @@ import com.aoyang.tms.feign.result.TmsMongoDoc;
 import com.aoyang.tms.service.*;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
 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.http.HttpEntity;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -261,7 +267,7 @@ public class CommonServiceImpl implements CommonService {
             return location;
         }
         Criteria criteria = Criteria.where("clientId").is(truckSimCard.getClientId());
-        criteria.andOperator(Criteria.where("dateTime").gt(date));
+        criteria.andOperator(Criteria.where("createTime").gt(date));
         Query query = new Query(criteria);
         query.with(new Sort(Sort.Direction.ASC, "dateTime"));
         TmsMongoDoc tmsMongoDoc = mongoTemplate.findOne(query, TmsMongoDoc.class);
@@ -289,8 +295,8 @@ public class CommonServiceImpl implements CommonService {
             return Collections.EMPTY_LIST;
         }
         Criteria criteria = Criteria.where("clientId").is(truckSimCard.getClientId());
-        criteria.andOperator(Criteria.where("dateTime").gt(startDate));
-        criteria.andOperator(Criteria.where("dateTime").lt(endDate));
+        criteria.andOperator(Criteria.where("createTime").gt(startDate));
+        criteria.andOperator(Criteria.where("createTime").lt(endDate));
         Query query = new Query(criteria);
         List<TmsMongoDoc> tmsMongoDocs = mongoTemplate.find(query, TmsMongoDoc.class);
         List<String> result = new ArrayList<>();
@@ -300,6 +306,7 @@ public class CommonServiceImpl implements CommonService {
         return result;
     }
 
+    @Override
     public String longitudeToAddress(float lat, float lng) {
         //拼接请求路径
         String url = BAIDUMAP_URL + "&ak=" + BAIDUMAP_AK + "&location=" + lat + "," + lng;
@@ -311,35 +318,35 @@ public class CommonServiceImpl implements CommonService {
     }
 
     public static String doGet(String url) {
-//        //创建一个Http客户端
-//        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
-//        //创建一个get请求
-//        HttpGet httpGet = new HttpGet(url);
-//        //响应模型
-//        CloseableHttpResponse response = null;
-//        try {
-//            //由客户端发送get请求
-//            response = httpClient.execute(httpGet);
-//            //从响应模型中获取响应实体
-//            HttpEntity responseEntity = response.getEntity();
-//            if (responseEntity != null) {
-//                return EntityUtils.toString(responseEntity);
-//            }
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//        } finally {
-//            try {
-//                if (httpClient != null) {
-//                    httpClient.close();
-//                }
-//                if (response != null) {
-//                    response.close();
-//                }
-//            } catch (IOException e) {
-//                e.printStackTrace();
-//            }
-//
-//        }
+        //创建一个Http客户端
+        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+        //创建一个get请求
+        HttpGet httpGet = new HttpGet(url);
+        //响应模型
+        CloseableHttpResponse response = null;
+        try {
+            //由客户端发送get请求
+            response = httpClient.execute(httpGet);
+            //从响应模型中获取响应实体
+            HttpEntity responseEntity = response.getEntity();
+            if (responseEntity != null) {
+                return EntityUtils.toString(responseEntity);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (httpClient != null) {
+                    httpClient.close();
+                }
+                if (response != null) {
+                    response.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+        }
         return null;
     }