Переглянути джерело

优化敏感信息配置;更新商家查询逻辑;新增分类图标字段;

woody 1 рік тому
батько
коміт
07ec51e687

+ 7 - 0
pom.xml

@@ -22,6 +22,7 @@
         <framework-upload.version>1.0.0-RELEASE</framework-upload.version>
         <framework-oauth.version>1.0.0-RELEASE</framework-oauth.version>
         <framework-security.version>1.0.0-RELEASE</framework-security.version>
+        <framework-location.version>1.0.0-RELEASE</framework-location.version>
     </properties>
 
     <dependencies>
@@ -61,5 +62,11 @@
             <version>${framework-security.version}</version>
             <optional>true</optional>
         </dependency>
+        <dependency>
+            <groupId>com.chelvc.framework</groupId>
+            <artifactId>framework-location</artifactId>
+            <version>${framework-location.version}</version>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 </project>

+ 26 - 18
src/main/java/com/chelvc/cloud/maintain/controller/IndexController.java

@@ -1,20 +1,27 @@
 package com.chelvc.cloud.maintain.controller;
 
+import java.util.List;
 import javax.validation.Valid;
 
 import com.chelvc.cloud.maintain.copier.CategoryCopier;
 import com.chelvc.cloud.maintain.copier.MerchantCopier;
-import com.chelvc.cloud.maintain.param.CustomerIndexParam;
 import com.chelvc.cloud.maintain.vo.ConfigurationVO;
 import com.chelvc.cloud.maintain.vo.CustomerIndexVO;
 import com.chelvc.cloud.uc.api.service.UsageService;
-import com.chelvc.cloud.vehicle.api.param.NearbyQueryParam;
+import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
+import com.chelvc.cloud.vehicle.api.dto.MerchantDTO;
+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.context.ApplicationContextHolder;
+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 lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -30,7 +37,10 @@ import org.springframework.web.bind.annotation.RestController;
 @Validated
 @RestController
 @UnifiedResponseBody
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
 public class IndexController {
+    private final LocationHandler locationHandler;
+
     @DubboReference
     private UsageService usageService;
 
@@ -40,15 +50,6 @@ public class IndexController {
     @DubboReference
     private MerchantService merchantService;
 
-    /**
-     * 获取附近距离配置
-     *
-     * @return 距离(米)
-     */
-    private int getNearbyDistance() {
-        return ApplicationContextHolder.getSafeProperty("platform.nearby.distance", int.class, 20000);
-    }
-
     /**
      * 获取系统配置
      *
@@ -74,28 +75,35 @@ public class IndexController {
      * @return 首页信息
      */
     @GetMapping("/customer/index")
-    public CustomerIndexVO getCustomerIndex(@Valid CustomerIndexParam param) {
-        NearbyQueryParam query = NearbyQueryParam.builder().longitude(param.getLongitude())
-                .latitude(param.getLatitude()).distance(this.getNearbyDistance()).build();
+    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();
 
         // 加载推荐分类列表
         try {
-            index.setCategories(CategoryCopier.INSTANCE.copying(this.categoryService.listRecommendCategories(15)));
+            List<CategoryDTO> categories = this.categoryService.listRecommendCategories(15);
+            index.setCategories(CategoryCopier.INSTANCE.copying(categories));
         } catch (Exception e) {
             log.error("Load recommend categories failed", e);
         }
 
         // 加载附近商家列表
         try {
-            index.setNears(MerchantCopier.INSTANCE.copying(this.merchantService.listNearbyMerchants(query, 4)));
+            List<MerchantDTO> merchants = this.merchantService.listNearbyMerchants(region, param, 4);
+            index.setNears(MerchantCopier.INSTANCE.copying(merchants));
         } catch (Exception e) {
             log.error("Load nearby merchants failed", e);
         }
 
         // 加载推荐商家列表
         try {
-            index.setRecommends(MerchantCopier.INSTANCE.copying(this.merchantService.listRecommendMerchants(query, 4)));
+            List<MerchantDTO> merchants = this.merchantService.listRecommendMerchants(region, param, 4);
+            index.setRecommends(MerchantCopier.INSTANCE.copying(merchants));
         } catch (Exception e) {
             log.error("Load recommend merchants failed", e);
         }

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

@@ -10,7 +10,13 @@ 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;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -25,7 +31,10 @@ import org.springframework.web.bind.annotation.RestController;
 @Validated
 @RestController
 @UnifiedResponseBody
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
 public class MerchantController {
+    private final LocationHandler locationHandler;
+
     @DubboReference
     private MerchantService merchantService;
 
@@ -37,7 +46,14 @@ public class MerchantController {
      */
     @GetMapping("/merchants")
     public List<SimpleMerchantVO> listSimpleMerchants(@Valid MerchantQueryParam param) {
-        return MerchantCopier.INSTANCE.copying(this.merchantService.listSimpleMerchants(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));
     }
 
     /**

+ 5 - 0
src/main/java/com/chelvc/cloud/maintain/vo/CategoryVO.java

@@ -29,6 +29,11 @@ public class CategoryVO implements Serializable {
      */
     private CategoryType type;
 
+    /**
+     * 分类图标
+     */
+    private String icon;
+
     /**
      * 分类名称
      */

+ 3 - 0
src/main/resources/application-dev.yml

@@ -24,3 +24,6 @@ platform:
     standard:
       path: /home/chelvc/upload
       domain: http://file.chelvc.com
+  location:
+    tencent:
+      key: ENC(jmSWw925Qp8SXWSAnMQ6hxCPBfvVito75hLPJoFaVbGYbXOPYItm6bCQ2uaukwKj)

+ 3 - 0
src/main/resources/application-pre.yml

@@ -24,3 +24,6 @@ platform:
     standard:
       path: /home/chelvc/upload
       domain: http://file.chelvc.com
+  location:
+    tencent:
+      key: ENC(9RJ2ht7DWEdWGdzwHL92tHkJvzfWP/1bBkHtF1vcRnYfKXmOkmqKZTuD2A8VYVW+)

+ 3 - 0
src/main/resources/application-prod.yml

@@ -24,3 +24,6 @@ platform:
     standard:
       path: /home/chelvc/upload
       domain: http://file.chelvc.com
+  location:
+    tencent:
+      key: ENC(9RJ2ht7DWEdWGdzwHL92tHkJvzfWP/1bBkHtF1vcRnYfKXmOkmqKZTuD2A8VYVW+)

+ 3 - 0
src/main/resources/application-test.yml

@@ -24,3 +24,6 @@ platform:
     standard:
       path: /home/chelvc/upload
       domain: http://file.chelvc.com
+  location:
+    tencent:
+      key: ENC(jmSWw925Qp8SXWSAnMQ6hxCPBfvVito75hLPJoFaVbGYbXOPYItm6bCQ2uaukwKj)