Jelajahi Sumber

Merge remote-tracking branch 'origin/master'

zhangchen 4 bulan lalu
induk
melakukan
083df7d8b2

+ 3 - 1
alien-second/src/main/java/shop/alien/second/service/impl/SecondTradeRecordServiceImpl.java

@@ -348,7 +348,9 @@ public class SecondTradeRecordServiceImpl extends ServiceImpl<SecondTradeRecordM
             alienStoreFeign.sendMsgToClientByPhoneId(receiverId, JSONObject.from(webSocketVo).toJSONString());
 
             return true;
-        } catch (Exception e) {
+        } catch (BusinessException e) {
+            throw new BusinessException(e);
+        }  catch (Exception e) {
             log.error("SecondTradeRecordServiceImpl.tradeSignIn(): Error Msg={}", e.getMessage());
             throw new Exception(e);
         }

+ 35 - 0
alien-store/src/main/java/shop/alien/store/config/GaoDeMapUtil.java

@@ -47,6 +47,9 @@ public class GaoDeMapUtil {
     @Value("${gaode.distanceUrl}")
     private String distanceUrl;
 
+    @Value("${gaode.distanceTypeUrl}")
+    private String distanceTypeUrl;
+
     @Value("${gaode.nearUrl}")
     private String nearUrl;
 
@@ -147,6 +150,38 @@ public class GaoDeMapUtil {
     }
 
     /**
+     * 计算两个经纬度的距离
+     *
+     * @param longitudeOne 经度1
+     * @param latitudeOne  纬度1
+     * @param longitudeTwo 经度2
+     * @param latitudeTwo  纬度2
+     * @return distance
+     */
+    public Double getDistanceStraightLine(String longitudeOne, String latitudeOne, String longitudeTwo, String latitudeTwo) {
+        try {
+            String urlString = String.format(distanceTypeUrl, key, longitudeOne, latitudeOne, longitudeTwo, latitudeTwo, 0);
+            JSONObject obj = getResponse(urlString);
+            if (null != obj && "1".equals(String.valueOf(obj.get("status")))) {
+                JSONArray resultsArray = obj.getJSONArray("results");
+                if (resultsArray != null && !resultsArray.isEmpty()) {
+                    JSONObject resultJSON = resultsArray.getJSONObject(0);
+                    return Double.parseDouble(resultJSON.getString("distance"));
+                } else {
+                    log.error("AddressLocationUtil.getDistance ERROR 计算距离失败,结果为空");
+                    return null;
+                }
+            } else {
+                log.error("AddressLocationUtil.getDistance ERROR 计算距离失败");
+                return null;
+            }
+        } catch (Exception e) {
+            log.error("AddressLocationUtil.getDistance ERROR {}", e.getMessage());
+            return null;
+        }
+    }
+
+    /**
      * 获取附近商家、建筑等信息
      *
      * @param longitude 经度

+ 12 - 0
alien-store/src/main/java/shop/alien/store/controller/GaoDeController.java

@@ -130,4 +130,16 @@ public class GaoDeController {
         return R.data(gaodeMapUtil.getDistance(longitudeOne, latitudeOne, longitudeTwo, latitudeTwo));
     }
 
+    @ApiOperation("获取两个经纬度的距离(直线距离)")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "longitudeOne", value = "经度1", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "latitudeOne", value = "纬度1", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "longitudeTwo", value = "纬度2", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "latitudeTwo", value = "纬度2", dataType = "String", paramType = "query", required = true)
+    })
+    @GetMapping("/getDistanceStraightLine")
+    public R<Double> getDistanceStraightLine(String longitudeOne, String latitudeOne, String longitudeTwo, String latitudeTwo) {
+        return R.data(gaodeMapUtil.getDistanceStraightLine(longitudeOne, latitudeOne, longitudeTwo, latitudeTwo));
+    }
+
 }