From dc88fd134d48713f0e941ffb5af2d7ce2d475ed7 Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Wed, 20 Apr 2022 08:24:36 +0800
Subject: [PATCH] Merge branch 'developer'

---
 zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/YuyueAction.java |    8 ++++----
 zq-erp/src/main/java/com/matrix/system/common/tools/LocationUtil.java      |    9 ++++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/zq-erp/src/main/java/com/matrix/system/common/tools/LocationUtil.java b/zq-erp/src/main/java/com/matrix/system/common/tools/LocationUtil.java
index a741b00..c9b423e 100644
--- a/zq-erp/src/main/java/com/matrix/system/common/tools/LocationUtil.java
+++ b/zq-erp/src/main/java/com/matrix/system/common/tools/LocationUtil.java
@@ -1,5 +1,7 @@
 package com.matrix.system.common.tools;
 
+import java.math.BigDecimal;
+
 public class LocationUtil {
 
     private static final double EARTH_RADIUS = 6378.137;
@@ -17,7 +19,7 @@
      *  shopX 店铺位置经度
      *  shopY  店铺位置纬度
      */
-    public static double getDistance(double locX, double locY, double shopX, double shopY) {
+    public static BigDecimal getDistance(double locX, double locY, double shopX, double shopY) {
         double a, b, d, sa2, sb2;
         locY = rad(locY);
         shopY = rad(shopY);
@@ -29,12 +31,13 @@
         d = 2   * EARTH_RADIUS
                 * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(locY)
                 * Math.cos(shopY) * sb2 * sb2));
-        return d;
+        return BigDecimal.valueOf(d);
     }
 
     public static void main(String[] args) {
         // 112.886891,28.222562,114.061937,22.626003  -- 634093.3209722887
         // 113.930692,22.939454 -- 597367.3546527711
-        System.out.println(getDistance(112.886891d, 28.222562d, 113.930692, 22.939454));
+//        System.out.println(getDistance(112.886891d, 28.222562d, 113.930692, 22.939454));
+        System.out.println(BigDecimal.ONE.compareTo(BigDecimal.ZERO)>0);
     }
 }
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/YuyueAction.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/YuyueAction.java
index 19fc17f..47420ba 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/YuyueAction.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/YuyueAction.java
@@ -122,7 +122,7 @@
             return new AjaxResult(AjaxResult.STATUS_SUCCESS, shopList);
         }
 
-        Double distance = null;
+        BigDecimal distance = null;
         SysShopInfo nearestShop = null;
 
         AjaxResult ajaxResult = new AjaxResult("200", shopList);
@@ -130,9 +130,9 @@
             for (SysShopInfo shopInfo : shopList) {
                 Double shopX = Double.parseDouble(shopInfo.getLongitude());
                 Double shopY = Double.parseDouble(shopInfo.getLatitude());
-                Double disResult = LocationUtil.getDistance(Double.parseDouble(locX), Double.parseDouble(locY), shopX, shopY);
-                shopInfo.setDistance(new BigDecimal(disResult).setScale(1, BigDecimal.ROUND_HALF_UP));
-                if (distance == null || distance > disResult) {
+                BigDecimal disResult = LocationUtil.getDistance(Double.parseDouble(locX), Double.parseDouble(locY), shopX, shopY);
+                shopInfo.setDistance(disResult);
+                if (distance == null || distance.compareTo(disResult)>0) {
                     distance = disResult;
                     nearestShop = shopInfo;
                 }

--
Gitblit v1.9.1