From e2ec85c7ae5424b67fc6d458bbb070f3bf651753 Mon Sep 17 00:00:00 2001 From: cb <275647614@qq.com> Date: Mon, 16 Jun 2025 17:29:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=B9=E6=8D=AE=E7=94=A8?= =?UTF-8?q?=E6=88=B7id=E8=8E=B7=E5=8F=96=E5=AF=B9=E5=BA=94=E7=9A=84?= =?UTF-8?q?=E5=95=86=E9=93=BAid=20=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ghy/web/controller/ShopController.java | 40 +++++++++++++++++++ .../main/java/com/ghy/shop/domain/Shop.java | 4 ++ .../java/com/ghy/shop/mapper/ShopMapper.java | 5 +++ .../com/ghy/shop/service/ShopService.java | 5 +++ .../shop/service/impl/ShopServiceImpl.java | 5 +++ .../src/main/resources/mapper/ShopMapper.xml | 6 +++ 6 files changed, 65 insertions(+) diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/ShopController.java b/ghy-admin/src/main/java/com/ghy/web/controller/ShopController.java index cde2f668..2e760d4e 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/ShopController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/ShopController.java @@ -8,6 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.HashMap; +import java.util.Map; +import org.springframework.web.client.RestTemplate; /** * 店铺管理接口 @@ -18,6 +21,9 @@ public class ShopController extends BaseController { @Autowired private ShopService shopService; + @Autowired + private RestTemplate restTemplate; + @PostMapping("/add") public AjaxResult addShop(@RequestBody Shop shop) { return toAjax(shopService.addShop(shop)); @@ -44,4 +50,38 @@ public class ShopController extends BaseController { public AjaxResult deleteShop(@PathVariable Long id) { return toAjax(shopService.deleteShop(id)); } + + @GetMapping("/{id}/location") + public AjaxResult getShopLocation(@PathVariable Long id) { + Shop shop = shopService.getShop(id); + if (shop == null) { + return AjaxResult.error("未找到店铺"); + } + Map location = new HashMap<>(); + location.put("address", shop.getAddress()); + location.put("latitude", shop.getLatitude()); + location.put("longitude", shop.getLongitude()); + location.put("provinceName", shop.getProvinceName()); + location.put("cityName", shop.getCityName()); + location.put("countryName", shop.getCountryName()); + location.put("streetName", shop.getStreetName()); + return AjaxResult.success(location); + } + +// @GetMapping("/getCurrentLocation") +// public AjaxResult getCurrentLocation() { +// try { +// // 直接调用百度地图API获取当前位置信息 +// String url = "/tool/baidu/getLocation"; +// return restTemplate.getForObject(url, AjaxResult.class); +// } catch (Exception e) { +// return AjaxResult.error("获取当前位置失败:" + e.getMessage()); +// } +// } + + @GetMapping("/customer/{customerId}") + public AjaxResult getShopsByCustomerId(@PathVariable Long customerId) { + List shops = shopService.getShopsByCustomerId(customerId); + return AjaxResult.success(shops); + } } \ No newline at end of file diff --git a/ghy-shop/src/main/java/com/ghy/shop/domain/Shop.java b/ghy-shop/src/main/java/com/ghy/shop/domain/Shop.java index 0ce647a0..ebdb487d 100644 --- a/ghy-shop/src/main/java/com/ghy/shop/domain/Shop.java +++ b/ghy-shop/src/main/java/com/ghy/shop/domain/Shop.java @@ -11,6 +11,7 @@ public class Shop implements Serializable { private Long shopId; // 店铺ID private String shopName; // 店铺名称 private String imageUrl; // 店铺图片 + private Long customerId; // 用户ID private Long provinceId; private String provinceName; @@ -23,4 +24,7 @@ public class Shop implements Serializable { private String address; // 详细地址 private String phone; // 联系电话 + + private Double latitude; // 纬度 + private Double longitude; // 经度 } \ No newline at end of file diff --git a/ghy-shop/src/main/java/com/ghy/shop/mapper/ShopMapper.java b/ghy-shop/src/main/java/com/ghy/shop/mapper/ShopMapper.java index 8014dd15..fa849dc1 100644 --- a/ghy-shop/src/main/java/com/ghy/shop/mapper/ShopMapper.java +++ b/ghy-shop/src/main/java/com/ghy/shop/mapper/ShopMapper.java @@ -12,4 +12,9 @@ public interface ShopMapper { int delete(@Param("shopId") Long shopId); Shop select(@Param("shopId") Long shopId); List selectAll(); + + /** + * 根据用户ID查询商铺列表 + */ + List selectShopsByCustomerId(@Param("customerId") Long customerId); } \ No newline at end of file diff --git a/ghy-shop/src/main/java/com/ghy/shop/service/ShopService.java b/ghy-shop/src/main/java/com/ghy/shop/service/ShopService.java index 12890ea8..5e65fd25 100644 --- a/ghy-shop/src/main/java/com/ghy/shop/service/ShopService.java +++ b/ghy-shop/src/main/java/com/ghy/shop/service/ShopService.java @@ -9,4 +9,9 @@ public interface ShopService { int deleteShop(Long shopId); Shop getShop(Long shopId); List listShops(); + + /** + * 根据用户ID查询商铺列表 + */ + List getShopsByCustomerId(Long customerId); } \ No newline at end of file diff --git a/ghy-shop/src/main/java/com/ghy/shop/service/impl/ShopServiceImpl.java b/ghy-shop/src/main/java/com/ghy/shop/service/impl/ShopServiceImpl.java index ba6edcdd..faf4c3ab 100644 --- a/ghy-shop/src/main/java/com/ghy/shop/service/impl/ShopServiceImpl.java +++ b/ghy-shop/src/main/java/com/ghy/shop/service/impl/ShopServiceImpl.java @@ -37,4 +37,9 @@ public class ShopServiceImpl implements ShopService { public List listShops() { return shopMapper.selectAll(); } + + @Override + public List getShopsByCustomerId(Long customerId) { + return shopMapper.selectShopsByCustomerId(customerId); + } } \ No newline at end of file diff --git a/ghy-shop/src/main/resources/mapper/ShopMapper.xml b/ghy-shop/src/main/resources/mapper/ShopMapper.xml index 0be9af22..a8915b21 100644 --- a/ghy-shop/src/main/resources/mapper/ShopMapper.xml +++ b/ghy-shop/src/main/resources/mapper/ShopMapper.xml @@ -64,4 +64,10 @@ SELECT * FROM shop + + \ No newline at end of file