xuhy
2025-01-20 c4cfe92baabc797cbaa42d0684b06a4bae90efbe
UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java
@@ -1,6 +1,12 @@
package com.stylefeng.guns.modular.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.util.GpsCoordinateUtils;
import com.stylefeng.guns.core.util.HttpUtil;
import com.stylefeng.guns.core.util.HttpUtils;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.CharteredCar.server.IOrderCharteredCarService;
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
@@ -22,6 +28,7 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
@@ -1396,6 +1403,40 @@
            e.printStackTrace();
        }
    }
    /**
     * 路线规划
     * @param request
     */
    @ResponseBody
    @PostMapping("/base/loadLine")
    public ResultUtil aliPayOrderLogisticsSpread(String startLat, String startLon,
                                           String nextLatitude, String nextLongitude,
                                           HttpServletRequest request, HttpServletResponse response){
        try {
            String url = "https://api.map.baidu.com/directionlite/v1/driving?origin="
                    +startLat+","+startLon+"&destination="+nextLatitude+","+nextLongitude+"&ak=WQhfsluNzEeUHUxoH4jc4JiCQOXw4Mnx&ret_coordtype=bd09ll&coord_type=bd09ll";
            String get = HttpUtil.get(url);
            JSONObject jsonObject = JSON.parseObject(get);
            JSONArray jsonArray = jsonObject.getJSONObject("result").getJSONArray("routes").getJSONObject(0).getJSONArray("steps");
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                JSONObject start_location = jsonObject1.getJSONObject("start_location");
                double[] doubles = GpsCoordinateUtils.calBD09toGCJ02(start_location.getDouble("lat"), start_location.getDouble("lng"));
                start_location.put("lat", doubles[0]);
                start_location.put("lng", doubles[1]);
                JSONObject end_location = jsonObject1.getJSONObject("end_location");
                double[] doubles1 = GpsCoordinateUtils.calBD09toGCJ02(end_location.getDouble("lat"), end_location.getDouble("lng"));
                end_location.put("lat", doubles1[0]);
                end_location.put("lng", doubles1[1]);
            }
            System.out.println(jsonArray);
            return ResultUtil.success(jsonArray);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }