Ver Fonte

首页信息新增分类列表字段;新增获取所有分类列表接口;

woody há 1 ano atrás
pai
commit
ed9f7e4e75

+ 36 - 0
src/main/java/com/chelvc/cloud/maintain/controller/CategoryController.java

@@ -0,0 +1,36 @@
+package com.chelvc.cloud.maintain.controller;
+
+import java.util.List;
+
+import com.chelvc.cloud.maintain.copier.CategoryCopier;
+import com.chelvc.cloud.maintain.vo.CategoryVO;
+import com.chelvc.cloud.vehicle.api.service.CategoryService;
+import com.chelvc.framework.base.annotation.UnifiedResponseBody;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 分类接口
+ *
+ * @author Woody
+ * @date 2023/7/17
+ */
+@Validated
+@RestController
+@UnifiedResponseBody
+public class CategoryController {
+    @DubboReference
+    private CategoryService categoryService;
+
+    /**
+     * 获取分类列表
+     *
+     * @return 分类信息列表
+     */
+    @GetMapping("/categories")
+    public List<CategoryVO> listCategories() {
+        return CategoryCopier.INSTANCE.copying(this.categoryService.listActiveCategories());
+    }
+}

+ 14 - 2
src/main/java/com/chelvc/cloud/maintain/controller/IndexController.java

@@ -2,12 +2,14 @@ package com.chelvc.cloud.maintain.controller;
 
 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.service.CategoryService;
 import com.chelvc.cloud.vehicle.api.service.MerchantService;
 import com.chelvc.framework.base.annotation.UnifiedResponseBody;
 import com.chelvc.framework.base.context.ApplicationContextHolder;
@@ -32,6 +34,9 @@ public class IndexController {
     @DubboReference
     private UsageService usageService;
 
+    @DubboReference
+    private CategoryService categoryService;
+
     @DubboReference
     private MerchantService merchantService;
 
@@ -74,18 +79,25 @@ public class IndexController {
                 .latitude(param.getLatitude()).distance(this.getNearbyDistance()).build();
         CustomerIndexVO index = CustomerIndexVO.builder().build();
 
+        // 加载推荐分类列表
+        try {
+            index.setCategories(CategoryCopier.INSTANCE.copying(this.categoryService.listRecommendCategories(15)));
+        } catch (Exception e) {
+            log.error("Load recommend categories failed", e);
+        }
+
         // 加载附近商家列表
         try {
             index.setNears(MerchantCopier.INSTANCE.copying(this.merchantService.listNearbyMerchants(query, 4)));
         } catch (Exception e) {
-            log.error("Nearby merchants load failed", e);
+            log.error("Load nearby merchants failed", e);
         }
 
         // 加载推荐商家列表
         try {
             index.setRecommends(MerchantCopier.INSTANCE.copying(this.merchantService.listRecommendMerchants(query, 4)));
         } catch (Exception e) {
-            log.error("Recommend merchants load failed", e);
+            log.error("Load recommend merchants failed", e);
         }
         return index;
     }

+ 32 - 0
src/main/java/com/chelvc/cloud/maintain/copier/CategoryCopier.java

@@ -0,0 +1,32 @@
+package com.chelvc.cloud.maintain.copier;
+
+import java.util.Collection;
+import java.util.List;
+
+import com.chelvc.cloud.maintain.vo.CategoryVO;
+import com.chelvc.cloud.vehicle.api.dto.CategoryDTO;
+import org.mapstruct.Builder;
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * 分类信息拷贝接口
+ *
+ * @author Woody
+ * @date 2023/7/17
+ */
+@Mapper(builder = @Builder(disableBuilder = true))
+public interface CategoryCopier {
+    /**
+     * 对象拷贝接口实例
+     */
+    CategoryCopier INSTANCE = Mappers.getMapper(CategoryCopier.class);
+
+    /**
+     * 分类信息拷贝
+     *
+     * @param categories 分类信息集合
+     * @return 分类信息列表
+     */
+    List<CategoryVO> copying(Collection<CategoryDTO> categories);
+}

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

@@ -0,0 +1,36 @@
+package com.chelvc.cloud.maintain.vo;
+
+import java.io.Serializable;
+
+import com.chelvc.cloud.vehicle.api.constant.CategoryType;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.SuperBuilder;
+
+/**
+ * 分类信息
+ *
+ * @author Woody
+ * @date 2023/7/17
+ */
+@Data
+@SuperBuilder
+@NoArgsConstructor
+@AllArgsConstructor
+public class CategoryVO implements Serializable {
+    /**
+     * 分类ID
+     */
+    private Long id;
+
+    /**
+     * 分类类型
+     */
+    private CategoryType type;
+
+    /**
+     * 分类名称
+     */
+    private String name;
+}

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

@@ -19,6 +19,11 @@ import lombok.experimental.SuperBuilder;
 @NoArgsConstructor
 @AllArgsConstructor
 public class CustomerIndexVO implements Serializable {
+    /**
+     * 分类列表
+     */
+    private List<CategoryVO> categories;
+
     /**
      * 推荐商家列表
      */

+ 1 - 1
src/main/java/com/chelvc/cloud/maintain/vo/MerchantVO.java

@@ -19,7 +19,7 @@ import lombok.experimental.SuperBuilder;
 @AllArgsConstructor
 public class MerchantVO implements Serializable {
     /**
-     * 主键
+     * 商家ID
      */
     private Long id;
 

+ 1 - 1
src/main/resources/application.yml

@@ -45,4 +45,4 @@ dubbo:
 platform:
   security:
     resource:
-      permit: "/**/index,/**/configuration"
+      permit: "/**/index,/**/configuration,/**/categories"