增加根据用户id获取对应的商铺id 的方法
This commit is contained in:
parent
7a2a155938
commit
e2ec85c7ae
|
|
@ -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<String, Object> 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<Shop> shops = shopService.getShopsByCustomerId(customerId);
|
||||
return AjaxResult.success(shops);
|
||||
}
|
||||
}
|
||||
|
|
@ -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; // 经度
|
||||
}
|
||||
|
|
@ -12,4 +12,9 @@ public interface ShopMapper {
|
|||
int delete(@Param("shopId") Long shopId);
|
||||
Shop select(@Param("shopId") Long shopId);
|
||||
List<Shop> selectAll();
|
||||
|
||||
/**
|
||||
* 根据用户ID查询商铺列表
|
||||
*/
|
||||
List<Shop> selectShopsByCustomerId(@Param("customerId") Long customerId);
|
||||
}
|
||||
|
|
@ -9,4 +9,9 @@ public interface ShopService {
|
|||
int deleteShop(Long shopId);
|
||||
Shop getShop(Long shopId);
|
||||
List<Shop> listShops();
|
||||
|
||||
/**
|
||||
* 根据用户ID查询商铺列表
|
||||
*/
|
||||
List<Shop> getShopsByCustomerId(Long customerId);
|
||||
}
|
||||
|
|
@ -37,4 +37,9 @@ public class ShopServiceImpl implements ShopService {
|
|||
public List<Shop> listShops() {
|
||||
return shopMapper.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Shop> getShopsByCustomerId(Long customerId) {
|
||||
return shopMapper.selectShopsByCustomerId(customerId);
|
||||
}
|
||||
}
|
||||
|
|
@ -64,4 +64,10 @@
|
|||
SELECT * FROM shop
|
||||
</select>
|
||||
|
||||
<select id="selectShopsByCustomerId" resultMap="ShopResultMap">
|
||||
select *
|
||||
from shop
|
||||
where customer_id = #{customerId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue