Helius
2021-06-24 7043628d74a26cc09a3735c251567bf36f6219b6
add goods details
7 files modified
119 ■■■■■ changed files
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiGoodsController.java 15 ●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/dto/XcxGoodsListDto.java 3 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreGoodsMapper.java 3 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/service/GoodsService.java 25 ●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/vo/XcxGoodsDetailVo.java 18 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/resources/mapper/shop/ScoreGoodsMapper.xml 49 ●●●●● patch | view | raw | blame | history
pom.xml 6 ●●●●● patch | view | raw | blame | history
gc-shop/src/main/java/com/xzx/gc/shop/controller/ApiGoodsController.java
@@ -6,6 +6,7 @@
import com.xzx.gc.shop.dto.XcxGoodsListDto;
import com.xzx.gc.shop.service.GoodsService;
import com.xzx.gc.shop.vo.GoodsCategoryVo;
import com.xzx.gc.shop.vo.XcxGoodsDetailVo;
import com.xzx.gc.shop.vo.XcxGoodsListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -13,10 +14,7 @@
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@@ -47,4 +45,13 @@
        return JsonResult.success(goodsService.findGoodsListInPage(xcxGoodsListDto));
    }
    @ApiOperation("商品详情")
    @ApiResponses(
            @ApiResponse(code = 200, message = "success", response = XcxGoodsDetailVo.class)
    )
    @PostMapping(value = "/goods/goodsDetails/{id}")
    public JsonResult<XcxGoodsDetailVo> goodsDetails(@PathVariable("id") Long id) {
        return JsonResult.success(goodsService.findGoodsDetails(id));
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/dto/XcxGoodsListDto.java
@@ -11,6 +11,9 @@
@ApiModel(value = "XcxGoodsListDto", description = "小程序商品列表参数接受类")
public class XcxGoodsListDto {
    @ApiModelProperty(hidden = true)
    private Long id;
    @ApiModelProperty(value = "名称搜索")
    private String name;
gc-shop/src/main/java/com/xzx/gc/shop/mapper/ScoreGoodsMapper.java
@@ -5,6 +5,7 @@
import com.xzx.gc.model.order.OrderInfoVo;
import com.xzx.gc.shop.dto.XcxGoodsListDto;
import com.xzx.gc.shop.vo.QueryGoodsListVo;
import com.xzx.gc.shop.vo.XcxGoodsDetailVo;
import com.xzx.gc.shop.vo.XcxGoodsListVo;
import com.xzx.gc.util.GcMapper;
import org.apache.ibatis.annotations.Param;
@@ -20,4 +21,6 @@
    List<QueryGoodsListVo> queryGoodsList(@Param("name")String name, @Param("delFlag")int delFlag);
    List<XcxGoodsListVo> selectXcxGoodsList(@Param("record") XcxGoodsListDto xcxGoodsListDto);
    XcxGoodsDetailVo selectGoodsDetailsById(@Param("id") Long id);
}
gc-shop/src/main/java/com/xzx/gc/shop/service/GoodsService.java
@@ -2,6 +2,8 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -22,10 +24,7 @@
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service
@Transactional
@@ -300,4 +299,22 @@
        return new PageInfo<>(data);
    }
    public XcxGoodsDetailVo findGoodsDetails(Long id) {
        XcxGoodsDetailVo data = scoreGoodsMapper.selectGoodsDetailsById(id);
        XcxGoodsListDto dto = new XcxGoodsListDto();
        dto.setId(id);
        List<XcxGoodsListVo> list = scoreGoodsMapper.selectXcxGoodsList(dto);
        if (CollUtil.isNotEmpty(list)) {
            data.setQuantity(list.get(0).getQuantity());
            data.setStock(list.get(0).getStock());
        }
        if (ScoreGoods.ISQG_YES.equals(data.getIsQg())) {
            Long remain = DateUtil.between(new Date(), data.getQgEndTime(), DateUnit.SECOND, false);
            data.setRemainTime(remain);
        }
        return data;
    }
}
gc-shop/src/main/java/com/xzx/gc/shop/vo/XcxGoodsDetailVo.java
@@ -4,6 +4,7 @@
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
@@ -18,7 +19,7 @@
    private String name;
    @ApiModelProperty(value = "列表缩略图")
    private String image;
    private String thumb;
    @ApiModelProperty(value = "现价")
    private String presentPrice;
@@ -38,6 +39,21 @@
    @ApiModelProperty(value = "轮播图")
    private List<String> images;
    @ApiModelProperty(value = "上下架 1-上架 2-下架")
    private Integer isSale;
    @ApiModelProperty(value = "是否抢购 1-是 2-否")
    private Integer isQg;
    @ApiModelProperty(value = "抢购开始时间")
    private Date qgStartTime;
    @ApiModelProperty(value = "抢购结束时间")
    private Date qgEndTime;
    @ApiModelProperty(value = "剩余时间")
    private Long remainTime;
    @ApiModelProperty(value = "样式")
    private List<XcxGoodsDetailStyleVo> styles;
gc-shop/src/main/resources/mapper/shop/ScoreGoodsMapper.xml
@@ -43,14 +43,59 @@
        from xzx_score_goods a
        inner join xzx_score_goods_sku b on a.id=b.goods_id and b.del_flag=0
        <where>
            a.del_flag=0
            a.del_flag=0 and a.is_sale=1
            <if test="record.name != null and record.name != ''">
                and a.name like CONCAT(CONCAT(#{record.name}, "%"), "%")
            </if>
            <if test="record.id != null and record.id != ''">
                and a.id=#{record.id}
            </if>
            <if test="record.cateId != null and record.cateId != ''">
                and (a.category_id = #{record.cateId} or a.category in (select id from xzx_score_goods_category where parent_id=#{record.cateId}))
            </if>
        </where>
        order by a.CREATED_TIME desc
        group by a.id
        order by a.id desc
    </select>
    <resultMap id="goodsDetailsMap" type="com.xzx.gc.shop.vo.XcxGoodsDetailVo">
        <result property="name" column="name" />
        <result property="thumb" column="thumb" />
        <result property="presentPrice" column="present_price" />
        <result property="originalPrice" column="original_price" />
        <result property="isSale" column="is_sale" />
        <result property="isQg" column="is_qg" />
        <result property="qgStartTime" column="qg_start_time" />
        <result property="qgEndTime" column="qg_end_time" />
        <result property="details" column="details" />
        <collection property="styles" ofType="com.xzx.gc.shop.vo.XcxGoodsDetailStyleVo" >
            <id property="id" column="s_id" />
            <result property="name" column="s_name" />
            <collection property="skus" ofType="com.xzx.gc.shop.vo.XcxGoodsDetailSkuVo">
                <id property="id" column="sku_id" />
                <result property="name" column="sku_name" />
                <result property="originalPrice" column="sku_original_price" />
                <result property="presentPrice" column="sku_present_price" />
                <result property="stock" column="sku_stock" />
                <result property="quantity" column="sku_quantity" />
            </collection>
        </collection>
    </resultMap>
    <select id="selectGoodsDetailsById" resultMap="goodsDetailsMap">
        select
            a.*,
            b.id s_id,
            b.name s_name,
            c.id sku_id,
            c.name sku_name,
            c.original_price sku_original_price,
            c.present_price sku_present_price,
            c.stock sku_stock,
            c.quantity sku_quantity
        from xzx_score_goods a
        inner join xzx_score_goods_style b on a.id = b.goods_id and b.del_flag = 0
        inner join xzx_score_goods_sku c on a.id = c.goods_id and c.del_flag = 0
        where a.id=#{id}
    </select>
</mapper>
pom.xml
@@ -120,6 +120,12 @@
            <version>1.3.7</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.7.2</version>
        </dependency>
    </dependencies>
    <build>