Helius
2021-09-16 e35d81ec77bddf432cbf4dca4d059914ec49bb85
add mall category interface
4 files added
2 files modified
175 ■■■■■ changed files
src/main/java/cc/mrbird/febs/mall/controller/ApiMallGoodsCategoryController.java 53 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsCategoryMapper.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/IApiMallGoodsCategoryService.java 16 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsCategoryServiceImpl.java 38 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/vo/MallGoodsCategoryVo.java 28 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/modules/MallGoodsCategoryMapper.xml 33 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/controller/ApiMallGoodsCategoryController.java
New file
@@ -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());
    }
}
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();
}
src/main/java/cc/mrbird/febs/mall/service/IApiMallGoodsCategoryService.java
New file
@@ -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();
}
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsCategoryServiceImpl.java
New file
@@ -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();
    }
}
src/main/java/cc/mrbird/febs/mall/vo/MallGoodsCategoryVo.java
New file
@@ -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;
}
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>