소스 검색

更新商家查询逻辑

woody 1 년 전
부모
커밋
6fff0485f8

+ 20 - 11
src/main/java/com/chelvc/cloud/maintain/controller/IndexController.java

@@ -14,17 +14,18 @@ import com.chelvc.cloud.vehicle.api.param.LocationQueryParam;
 import com.chelvc.cloud.vehicle.api.service.CategoryService;
 import com.chelvc.cloud.vehicle.api.service.MerchantService;
 import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.util.ObjectUtils;
+import com.chelvc.framework.base.context.SessionContextHolder;
 import com.chelvc.framework.location.Address;
-import com.chelvc.framework.location.Area;
 import com.chelvc.framework.location.LocationHandler;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
@@ -60,11 +61,25 @@ public class IndexController {
         return ConfigurationVO.builder().build();
     }
 
+    /**
+     * 获取当前位置,如果经纬度为空则根据客户端IP定位
+     *
+     * @param point 经纬度(如:30.563443,104.009457)
+     * @return 位置信息
+     */
+    @GetMapping("/location")
+    public Address getLocation(@RequestParam(value = "point", required = false) String point) {
+        if (StringUtils.isEmpty(point)) {
+            return this.locationHandler.ip2address(SessionContextHolder.getHost());
+        }
+        return this.locationHandler.location2address(point);
+    }
+
     /**
      * 刷新用户使用记录
      */
     @PostMapping("/usage")
-    public void using() {
+    public void refreshUsage() {
         this.usageService.refresh();
     }
 
@@ -76,12 +91,6 @@ public class IndexController {
      */
     @GetMapping("/customer/index")
     public CustomerIndexVO getCustomerIndex(@Valid LocationQueryParam param) {
-        // 通过经纬度定位所属城市地区
-        Address address = this.locationHandler.location2address(param.getLongitude(), param.getLatitude());
-        int region = ObjectUtils.ifNull(
-                ObjectUtils.ifNull(ObjectUtils.ifNull(address, Address::getCity), Area::getId), 0
-        );
-
         CustomerIndexVO index = CustomerIndexVO.builder().build();
 
         // 加载推荐分类列表
@@ -94,7 +103,7 @@ public class IndexController {
 
         // 加载附近商家列表
         try {
-            List<MerchantDTO> merchants = this.merchantService.listNearbyMerchants(region, param, 4);
+            List<MerchantDTO> merchants = this.merchantService.listNearbyMerchants(param, 4);
             index.setNears(MerchantCopier.INSTANCE.copying(merchants));
         } catch (Exception e) {
             log.error("Load nearby merchants failed", e);
@@ -102,7 +111,7 @@ public class IndexController {
 
         // 加载推荐商家列表
         try {
-            List<MerchantDTO> merchants = this.merchantService.listRecommendMerchants(region, param, 4);
+            List<MerchantDTO> merchants = this.merchantService.listRecommendMerchants(param, 4);
             index.setRecommends(MerchantCopier.INSTANCE.copying(merchants));
         } catch (Exception e) {
             log.error("Load recommend merchants failed", e);

+ 1 - 14
src/main/java/com/chelvc/cloud/maintain/controller/MerchantController.java

@@ -10,10 +10,6 @@ import com.chelvc.cloud.maintain.vo.SimpleMerchantVO;
 import com.chelvc.cloud.vehicle.api.param.MerchantQueryParam;
 import com.chelvc.cloud.vehicle.api.service.MerchantService;
 import com.chelvc.framework.base.annotation.UnifiedResponseBody;
-import com.chelvc.framework.base.util.ObjectUtils;
-import com.chelvc.framework.location.Address;
-import com.chelvc.framework.location.Area;
-import com.chelvc.framework.location.LocationHandler;
 import lombok.RequiredArgsConstructor;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,8 +29,6 @@ import org.springframework.web.bind.annotation.RestController;
 @UnifiedResponseBody
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
 public class MerchantController {
-    private final LocationHandler locationHandler;
-
     @DubboReference
     private MerchantService merchantService;
 
@@ -46,14 +40,7 @@ public class MerchantController {
      */
     @GetMapping("/merchants")
     public List<SimpleMerchantVO> listSimpleMerchants(@Valid MerchantQueryParam param) {
-        // 通过经纬度定位所属城市地区
-        Address address = this.locationHandler.location2address(param.getLongitude(), param.getLatitude());
-        int region = ObjectUtils.ifNull(
-                ObjectUtils.ifNull(ObjectUtils.ifNull(address, Address::getCity), Area::getId), 0
-        );
-
-        // 查询商家信息
-        return MerchantCopier.INSTANCE.copying(this.merchantService.listSimpleMerchants(region, param, 10));
+        return MerchantCopier.INSTANCE.copying(this.merchantService.listSimpleMerchants(param, 10));
     }
 
     /**