From e35d81ec77bddf432cbf4dca4d059914ec49bb85 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 16 Sep 2021 19:34:57 +0800
Subject: [PATCH] add mall category interface
---
src/main/resources/mapper/modules/MallGoodsCategoryMapper.xml | 33 +++++++++++
src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsCategoryMapper.java | 7 ++
src/main/java/cc/mrbird/febs/mall/controller/ApiMallGoodsCategoryController.java | 53 +++++++++++++++++
src/main/java/cc/mrbird/febs/mall/service/IApiMallGoodsCategoryService.java | 16 +++++
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsCategoryServiceImpl.java | 38 ++++++++++++
src/main/java/cc/mrbird/febs/mall/vo/MallGoodsCategoryVo.java | 28 +++++++++
6 files changed, 175 insertions(+), 0 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/mall/controller/ApiMallGoodsCategoryController.java b/src/main/java/cc/mrbird/febs/mall/controller/ApiMallGoodsCategoryController.java
new file mode 100644
index 0000000..a7f6555
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/mall/controller/ApiMallGoodsCategoryController.java
@@ -0,0 +1,53 @@
+package cc.mrbird.febs.mall.controller;
+
+import cc.mrbird.febs.common.entity.FebsResponse;
+import cc.mrbird.febs.mall.service.IApiMallGoodsCategoryService;
+import cc.mrbird.febs.mall.vo.MallGoodsCategoryVo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @author wzy
+ * @date 2021-09-16
+ **/
+@Slf4j
+@RestController
+@RequiredArgsConstructor
+@RequestMapping(value = "/api/category")
+@Api(value = "ApiMallGoodsCategoryController", tags = "商品分类参数接收类")
+public class ApiMallGoodsCategoryController {
+
+ private final IApiMallGoodsCategoryService mallGoodsCategoryService;
+
+ @ApiOperation(value = "findAllCategoryList", notes = "获取商品分类列表")
+ @ApiResponses({
+ @ApiResponse(code = 200, message = "success", response = MallGoodsCategoryVo.class)
+ })
+ @GetMapping(value = "/findAllCategoryList")
+ public FebsResponse findAllCategoryList() {
+ return new FebsResponse().success().data(mallGoodsCategoryService.findAllCategoryList());
+ }
+
+ @ApiOperation(value = "findChildCategoryListById", notes = "获取父分类下分类")
+ @GetMapping(value = "/findChildCategoryListById/{id}")
+ public FebsResponse findChildCategoryListById(@PathVariable("id") Long id) {
+ return new FebsResponse().success().data(mallGoodsCategoryService.findChildCategoryListById(id));
+ }
+
+ @ApiOperation(value = "findRecommendCategory", notes = "获取推荐分类")
+ @GetMapping(value = "/findRecommendCategory")
+ public FebsResponse findRecommendCategory() {
+ return new FebsResponse().success().data(mallGoodsCategoryService.findRecommendCategory());
+ }
+
+}
diff --git a/src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsCategoryMapper.java b/src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsCategoryMapper.java
index f02d03d..85d069f 100644
--- a/src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsCategoryMapper.java
+++ b/src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsCategoryMapper.java
@@ -1,6 +1,7 @@
package cc.mrbird.febs.mall.mapper;
import cc.mrbird.febs.mall.entity.MallGoodsCategory;
+import cc.mrbird.febs.mall.vo.MallGoodsCategoryVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -15,4 +16,10 @@
List<MallGoodsCategory> selectCategoryByName(@Param("name")String name);
List<MallGoodsCategory> getCategorys();
+
+ List<MallGoodsCategoryVo> selectAllCategoryList();
+
+ List<MallGoodsCategory> selectCategoryListByParentId(@Param("id") Long id);
+
+ List<MallGoodsCategory> selectRecommendCategoryList();
}
diff --git a/src/main/java/cc/mrbird/febs/mall/service/IApiMallGoodsCategoryService.java b/src/main/java/cc/mrbird/febs/mall/service/IApiMallGoodsCategoryService.java
new file mode 100644
index 0000000..70b88e6
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/mall/service/IApiMallGoodsCategoryService.java
@@ -0,0 +1,16 @@
+package cc.mrbird.febs.mall.service;
+
+import cc.mrbird.febs.mall.entity.MallGoodsCategory;
+import cc.mrbird.febs.mall.vo.MallGoodsCategoryVo;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+
+public interface IApiMallGoodsCategoryService extends IService<MallGoodsCategory> {
+
+ List<MallGoodsCategoryVo> findAllCategoryList();
+
+ List<MallGoodsCategory> findChildCategoryListById(Long id);
+
+ List<MallGoodsCategory> findRecommendCategory();
+}
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsCategoryServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsCategoryServiceImpl.java
new file mode 100644
index 0000000..b2aeb8b
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsCategoryServiceImpl.java
@@ -0,0 +1,38 @@
+package cc.mrbird.febs.mall.service.impl;
+
+import cc.mrbird.febs.mall.entity.MallGoodsCategory;
+import cc.mrbird.febs.mall.mapper.MallGoodsCategoryMapper;
+import cc.mrbird.febs.mall.service.IApiMallGoodsCategoryService;
+import cc.mrbird.febs.mall.vo.MallGoodsCategoryVo;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @author wzy
+ * @date 2021-09-16
+ **/
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class ApiMallGoodsCategoryServiceImpl extends ServiceImpl<MallGoodsCategoryMapper, MallGoodsCategory> implements IApiMallGoodsCategoryService {
+
+
+ @Override
+ public List<MallGoodsCategoryVo> findAllCategoryList() {
+ return this.baseMapper.selectAllCategoryList();
+ }
+
+ @Override
+ public List<MallGoodsCategory> findChildCategoryListById(Long id) {
+ return this.baseMapper.selectCategoryListByParentId(id);
+ }
+
+ @Override
+ public List<MallGoodsCategory> findRecommendCategory() {
+ return this.baseMapper.selectRecommendCategoryList();
+ }
+}
diff --git a/src/main/java/cc/mrbird/febs/mall/vo/MallGoodsCategoryVo.java b/src/main/java/cc/mrbird/febs/mall/vo/MallGoodsCategoryVo.java
new file mode 100644
index 0000000..304b15e
--- /dev/null
+++ b/src/main/java/cc/mrbird/febs/mall/vo/MallGoodsCategoryVo.java
@@ -0,0 +1,28 @@
+package cc.mrbird.febs.mall.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author wzy
+ * @date 2021-09-16
+ **/
+@Data
+@ApiModel(value = "MallGoodsCategoryVo", description = "商品分类返回参数类")
+public class MallGoodsCategoryVo {
+
+ @ApiModelProperty(value = "id")
+ private Long id;
+
+ @ApiModelProperty(value = "分类名称")
+ private String name;
+
+ @ApiModelProperty(value = "父级分类ID")
+ private Long parentId;
+
+ @ApiModelProperty(value = "子类集合")
+ private List<MallGoodsCategoryVo> child;
+}
diff --git a/src/main/resources/mapper/modules/MallGoodsCategoryMapper.xml b/src/main/resources/mapper/modules/MallGoodsCategoryMapper.xml
index d57592e..6d2332d 100644
--- a/src/main/resources/mapper/modules/MallGoodsCategoryMapper.xml
+++ b/src/main/resources/mapper/modules/MallGoodsCategoryMapper.xml
@@ -24,4 +24,37 @@
SELECT * FROM mall_goods_category m where m.parent_id is null
</select>
+ <resultMap id="mallGoodsCategoryVoMap" type="cc.mrbird.febs.mall.vo.MallGoodsCategoryVo">
+ <id column="id" property="id" />
+ <result column="name" property="name" />
+ <result column="parent_id" property="parentId" />
+ <collection property="child" ofType="cc.mrbird.febs.mall.vo.MallGoodsCategoryVo">
+ <id column="child_id" property="id"/>
+ <result column="child_name" property="name" />
+ <result column="child_parent_id" property="parentId" />
+ </collection>
+ </resultMap>
+
+ <select id="selectAllCategoryList" resultMap="mallGoodsCategoryVoMap">
+ select
+ a.id,
+ a.name,
+ a.parent_id,
+ b.id child_id,
+ b.name child_name,
+ b.parent_id child_parent_id
+ from mall_goods_category a
+ inner join mall_goods_category b on a.id=b.parent_id
+ where a.parent_id = 0
+ </select>
+
+ <select id="selectCategoryListByParentId" resultType="cc.mrbird.febs.mall.entity.MallGoodsCategory">
+ select * from mall_goods_category
+ where parent_id=#{id}
+ </select>
+
+ <select id="selectRecommendCategoryList" resultType="cc.mrbird.febs.mall.entity.MallGoodsCategory">
+ select * from mall_goods_category
+ where parent_id=0 and is_recommend = 1
+ </select>
</mapper>
\ No newline at end of file
--
Gitblit v1.9.1