Helius
2021-09-17 1e9b91c0741c9b3005d523ca816d91622bf9759a
add findMallGoodsList
4 files added
3 files modified
172 ■■■■■ changed files
src/main/java/cc/mrbird/febs/mall/controller/ApiMallGoodsController.java 21 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/dto/MallGoodsQueryDto.java 37 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsMapper.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/IApiMallGoodsService.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsServiceImpl.java 31 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/vo/MallGoodsListVo.java 35 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/modules/MallGoodsMapper.xml 28 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/controller/ApiMallGoodsController.java
@@ -1,8 +1,18 @@
package cc.mrbird.febs.mall.controller;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.mall.dto.MallGoodsQueryDto;
import cc.mrbird.febs.mall.service.IApiMallGoodsService;
import cc.mrbird.febs.mall.vo.MallGoodsListVo;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -11,10 +21,21 @@
 * @date 2021-09-17
 **/
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/api/goods")
@Api(value = "ApiMallGoodsController", tags = "商城商品接口类")
public class ApiMallGoodsController {
    private final IApiMallGoodsService mallGoodsService;
    @ApiOperation(value = "findMallGoodsList", notes = "获取商城商品列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "success", response = MallGoodsListVo.class)
    })
    @PostMapping(value = "/findMallGoodsList")
    public FebsResponse findMallGoodsList(@RequestBody MallGoodsQueryDto queryDto) {
        return new FebsResponse().success().data(mallGoodsService.findMallGoodsListInPage(queryDto));
    }
}
src/main/java/cc/mrbird/febs/mall/dto/MallGoodsQueryDto.java
New file
@@ -0,0 +1,37 @@
package cc.mrbird.febs.mall.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
 * @author wzy
 * @date 2021-09-17
 **/
@Data
@ApiModel(value = "MallGoodsQueryDto", description = "商城商品参数接收类")
public class MallGoodsQueryDto {
    @ApiModelProperty(value = "页码", example = "1")
    private Integer pageNow;
    @ApiModelProperty(value = "每页数量", example = "10")
    private Integer pageSize;
    @ApiModelProperty(value = "查询", example = "123")
    private String query;
    @ApiModelProperty(value = "分类ID")
    private Long categoryId;
//    @ApiModelProperty(value = "排序字段, 默认created_time")
//    private String order = "created_time";
//
//    @ApiModelProperty(value = "升序/降序", example = "asc/desc")
//    private String sort = "desc";
    @ApiModelProperty(value = "是否热卖", example = "1是2否")
    private Integer isHot;
}
src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsMapper.java
@@ -1,7 +1,15 @@
package cc.mrbird.febs.mall.mapper;
import cc.mrbird.febs.mall.dto.MallGoodsQueryDto;
import cc.mrbird.febs.mall.entity.MallGoods;
import cc.mrbird.febs.mall.entity.MallGoodsCategory;
import cc.mrbird.febs.mall.vo.MallGoodsListVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
public interface MallGoodsMapper extends BaseMapper<MallGoods> {
    IPage<MallGoodsListVo> selectMallGoodsListQueryInPage(@Param("record") MallGoodsQueryDto queryDto, Page<MallGoodsListVo> page);
}
src/main/java/cc/mrbird/febs/mall/service/IApiMallGoodsService.java
New file
@@ -0,0 +1,12 @@
package cc.mrbird.febs.mall.service;
import cc.mrbird.febs.mall.dto.MallGoodsQueryDto;
import cc.mrbird.febs.mall.entity.MallGoods;
import cc.mrbird.febs.mall.vo.MallGoodsListVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
public interface IApiMallGoodsService extends IService<MallGoods> {
    IPage<MallGoodsListVo> findMallGoodsListInPage(MallGoodsQueryDto queryDto);
}
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallGoodsServiceImpl.java
New file
@@ -0,0 +1,31 @@
package cc.mrbird.febs.mall.service.impl;
import cc.mrbird.febs.mall.dto.MallGoodsQueryDto;
import cc.mrbird.febs.mall.entity.MallGoods;
import cc.mrbird.febs.mall.mapper.MallGoodsMapper;
import cc.mrbird.febs.mall.service.IApiMallGoodsService;
import cc.mrbird.febs.mall.vo.MallGoodsListVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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-17
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class ApiMallGoodsServiceImpl extends ServiceImpl<MallGoodsMapper, MallGoods> implements IApiMallGoodsService {
    @Override
    public IPage<MallGoodsListVo> findMallGoodsListInPage(MallGoodsQueryDto queryDto) {
        Page<MallGoodsListVo> page = new Page<>(queryDto.getPageNow(), queryDto.getPageSize());
        return this.baseMapper.selectMallGoodsListQueryInPage(queryDto, page);
    }
}
src/main/java/cc/mrbird/febs/mall/vo/MallGoodsListVo.java
New file
@@ -0,0 +1,35 @@
package cc.mrbird.febs.mall.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
 * @author wzy
 * @date 2021-09-17
 **/
@Data
@ApiModel(value = "MallGoodsListVo", description = "商城商品列表")
public class MallGoodsListVo {
    @ApiModelProperty(value = "id")
    private Long id;
    @ApiModelProperty(value = "商品名称")
    private String goodsName;
    @ApiModelProperty(value = "商品介绍")
    private String goodsIntroduction;
    @ApiModelProperty(value = "主图")
    private String thumb;
    @ApiModelProperty(value = "原价")
    private String originalPrice;
    @ApiModelProperty(value = "现价")
    private String presentPrice;
    @ApiModelProperty(value = "销量")
    private String saleVolume;
}
src/main/resources/mapper/modules/MallGoodsMapper.xml
@@ -2,4 +2,32 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.mrbird.febs.mall.mapper.MallGoodsMapper">
    <select id="selectMallGoodsListQueryInPage" resultType="cc.mrbird.febs.mall.vo.MallGoodsListVo">
        select
            a.id,
            a.goods_name,
            a.goods_introdution,
            a.thumb,
            a.original_price,
            a.present_price,
            sum(b.sku_volume) saleVolume
        from mall_goods a
             inner join mall_goods_sku b on a.id=b.goods_id
             inner join mall_goods_category c on a.category_id=c.id
        <where>
            a.is_sale=1
            <if test="record != null">
                <if test="record.isHot != null and record.isHot != ''">
                    and a.is_hot = 1
                </if>
                <if test="record.categoryId != null and record.categoryId != ''">
                    and (c.category_id = #{record.categoryId} or c.parent_id=#{record.categoryId})
                </if>
                <if test="record.query != null and record.query != ''">
                    and a.goods_name like CONCAT('%', CONCAT(#{record.query}, '%'))
                </if>
            </if>
        </where>
        order by a.created_time desc
    </select>
</mapper>