From aa58aabc306797bf6f92c1eb2cbdfa97d849d25c Mon Sep 17 00:00:00 2001 From: weizhiqiang <598748873@qq.com> Date: Fri, 15 Nov 2024 11:09:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E4=B8=A4=E7=82=B9=E7=9A=84=E5=B7=A8=E9=B9=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/skyeye/store/entity/ShopStore.java | 4 ++++ .../service/impl/ShopStoreServiceImpl.java | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/skyeye-shop/shop-member/src/main/java/com/skyeye/store/entity/ShopStore.java b/skyeye-shop/shop-member/src/main/java/com/skyeye/store/entity/ShopStore.java index e036aa27..4d34f8fa 100644 --- a/skyeye-shop/shop-member/src/main/java/com/skyeye/store/entity/ShopStore.java +++ b/skyeye-shop/shop-member/src/main/java/com/skyeye/store/entity/ShopStore.java @@ -75,6 +75,10 @@ public class ShopStore extends AreaInfo { @ApiModelProperty(value = "纬度") private String latitude; + @TableField(exist = false) + @Property(value = "两点之间的距离,单位:米") + private Double distance; + @TableField("start_time") @ApiModelProperty(value = "开始时间") private String startTime; diff --git a/skyeye-shop/shop-member/src/main/java/com/skyeye/store/service/impl/ShopStoreServiceImpl.java b/skyeye-shop/shop-member/src/main/java/com/skyeye/store/service/impl/ShopStoreServiceImpl.java index a26c62ea..8de0b438 100644 --- a/skyeye-shop/shop-member/src/main/java/com/skyeye/store/service/impl/ShopStoreServiceImpl.java +++ b/skyeye-shop/shop-member/src/main/java/com/skyeye/store/service/impl/ShopStoreServiceImpl.java @@ -16,6 +16,8 @@ import com.skyeye.common.enumeration.WhetherEnum; import com.skyeye.common.object.InputObject; import com.skyeye.common.object.OutputObject; import com.skyeye.common.util.CalculationUtil; +import com.skyeye.common.util.MapUtil; +import com.skyeye.common.util.ToolUtil; import com.skyeye.common.util.mybatisplus.MybatisPlusUtil; import com.skyeye.rest.shopmaterialnorms.rest.IShopMaterialNormsRest; import com.skyeye.store.dao.ShopStoreDao; @@ -61,10 +63,30 @@ public class ShopStoreServiceImpl extends SkyeyeBusinessServiceImpl wrapper) { + if (StrUtil.isNotEmpty(commonPageInfo.getLatitude()) && StrUtil.isNotEmpty(commonPageInfo.getLongitude())) { + // 使用ST_Distance_Sphere函数计算距离并按距离排序 + String orderByClause = "ORDER BY ST_Distance_Sphere(point(longitude, latitude), " + + "point(" + commonPageInfo.getLongitude() + ", " + commonPageInfo.getLatitude() + ")) ASC"; + wrapper.last(orderByClause); + } + } + @Override public List> queryPageDataList(InputObject inputObject) { + CommonPageInfo commonPageInfo = inputObject.getParams(CommonPageInfo.class); List> beans = super.queryPageDataList(inputObject); shopAreaService.setMationForMap(beans, "shopAreaId", "shopAreaMation"); + if (StrUtil.isNotEmpty(commonPageInfo.getLatitude()) && StrUtil.isNotEmpty(commonPageInfo.getLongitude())) { + // 计算距离并添加距离字段 + beans.forEach(bean -> { + double distance = ToolUtil.calculateDistance(Double.parseDouble(commonPageInfo.getLatitude()), Double.parseDouble(commonPageInfo.getLongitude()), + Double.parseDouble(MapUtil.checkKeyIsNull(bean, "latitude") ? "0" : bean.get("latitude").toString()), + Double.parseDouble(MapUtil.checkKeyIsNull(bean, "longitude") ? "0" : bean.get("longitude").toString())); + bean.put("distance", distance); + }); + } return beans; }