mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
meiya-rest/src/main/java/com/sinata/rest/modular/mall/controller/MallGoodsController.java
@@ -1,5 +1,6 @@
package com.sinata.rest.modular.mall.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -8,7 +9,6 @@
import com.sinata.rest.common.ApiUtils;
import com.sinata.rest.modular.mall.controller.vo.VoGoods;
import com.sinata.rest.modular.mall.controller.vo.VoGoodsDetail;
import com.sinata.rest.modular.mall.controller.vo.VoGoodsSpec;
import com.sinata.rest.modular.mall.controller.vo.VoGoodsSpecSet;
import com.sinata.rest.modular.mall.model.MallGoods;
import com.sinata.rest.modular.mall.model.MallGoodsSku;
@@ -23,6 +23,11 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -30,7 +35,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -74,10 +78,14 @@
        Page page = new Page<VoGoods>(current, size);
        // 查询商品信息
        List<VoGoods> list = goodsService.listGoods(EnumMallGoodsGroupType.GOODS.index, merchantId, goodsName, firstClassifyId, null, type, sortType, page);
        Map<Integer, BigDecimal> minPriceSale = goodsSkuService.queryPlatMinSalePrice(null).stream()
                .collect(Collectors.toMap(MallGoodsSku::getGoodsId, MallGoodsSku::getPriceSale));
        return ApiUtils.returnOK(
                list.stream()
                        .map(o -> {
                            BigDecimal money = minPriceSale.get(o.getId());
                            o.setTagList(mallTagService.getTagListByGoodsId(mallTags, o.getTagIds()));
                            o.setPriceSale(Optional.ofNullable(money).orElse(o.getPriceSale()));
                            return o;
                        })
                        .collect(Collectors.toList())
@@ -88,7 +96,7 @@
    @ApiOperation(value = "推广商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", defaultValue = "1", dataType = "Int", paramType = "query", required = true),
            @ApiImplicitParam(name = "cityCode", value = "城市code", defaultValue = "1", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "cityCode", value = "城市code", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "current", value = "当前页数", defaultValue = "1", dataType = "Int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页条数", defaultValue = "20", dataType = "Int", required = true, paramType = "query"),
    })
@@ -116,8 +124,17 @@
    })
    public ApiUtils<VoGoodsDetail> detail(@PathVariable("id") Integer id) {
        VoGoodsDetail o = goodsService.goodsDetail(id, null);
        List<MallGoodsSku> skuList = goodsSkuService.queryPlatMinSalePrice(null);
        Map<Integer, BigDecimal> minPriceSale = skuList.stream()
                .collect(Collectors.toMap(MallGoodsSku::getGoodsId, MallGoodsSku::getPriceSale));
        Map<Integer, BigDecimal> minPriceMember = skuList.stream()
                .collect(Collectors.toMap(MallGoodsSku::getGoodsId, MallGoodsSku::getPriceMember));
        if (o != null) {
            BigDecimal money = minPriceSale.get(o.getId());
            BigDecimal minMemberMoney = minPriceMember.get(o.getId());
            o.setTagList(mallTagService.getTagListByGoodsId(null, o.getTagIds()));
            o.setPriceSale(Optional.ofNullable(money).orElse(o.getPriceSale()));
            o.setPriceMember(Optional.ofNullable(minMemberMoney).orElse(o.getPriceMerchant()));
        }
        return ApiUtils.returnOK(o);
    }
@@ -126,7 +143,7 @@
    @ApiOperation(value = "获取商品适用门店")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品ID", dataType = "Int", defaultValue = "1", paramType = "path"),
            @ApiImplicitParam(name = "cityCode", value = "城市code", dataType = "Int", defaultValue = "1", paramType = "query")
            @ApiImplicitParam(name = "cityCode", value = "城市code", dataType = "Int", paramType = "query")
    })
    public ApiUtils<List<MemMerchant>> merchant(@PathVariable("id") Integer id, String cityCode) {
        MallGoods goods = goodsService.getById(id);