package com.fzm.mall.server.front.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzm.mall.server.front.goods.model.GoodSku;
import com.fzm.mall.server.front.goods.mapper.GoodSkuMapper;
import com.fzm.mall.server.front.goods.model.SkuProp;
import com.fzm.mall.server.front.goods.model.vo.SkuVo;
import com.fzm.mall.server.front.goods.service.IGoodSkuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.mall.server.front.goods.service.ISkuPropService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品规格表 服务实现类
 * </p>
 *
 * @author tdz
 * @since 2021-03-02
 */
@Service
public class GoodSkuServiceImpl extends ServiceImpl<GoodSkuMapper, GoodSku> implements IGoodSkuService {

    @Autowired
    private GoodSkuMapper skuMapper;

    @Autowired
    private ISkuPropService iSkuPropService;
    /**
     * 通过币获取商品销售信息
     */
    @Override
    public GoodSku skuUnitByGidCoin(final String gid, final String coin) {
        QueryWrapper<GoodSku>  qw=new QueryWrapper<>();
        qw.eq("goods_id",gid);
        qw.eq("coin_name",coin);
        qw.eq("status",1);
        return getOne(qw);
    }

    /**
     * 通过skuId查
     */
    @Override
    public GoodSku getBySkuId(final String skuId) {
        QueryWrapper<GoodSku>  qw=new QueryWrapper<>();
        qw.eq("sku_id",skuId);
        qw.eq("status",1);
        return getOne(qw);
    }
    @Override
    public SkuVo getSkuVoBySkuId(String skuId){
        SkuVo skuVo =  skuMapper.getSkuVoBySkuId(skuId);
        List<SkuProp> skuProps = iSkuPropService.getBySkuId(skuVo.getSkuId());
        skuVo.setSkuProps(skuProps);
        return  skuVo;
    }

    @Override
    public int delStock(String skuId, Integer num) {
        return skuMapper.delStock(skuId,num);
    }

    @Override
    public int addStock(String skuId, Integer number) {
        return skuMapper.addStock(skuId,number);
    }

    @Override
    public void delSales(String skuId, Integer number) {
        skuMapper.delSales(skuId,number);
    }

    @Override
    public void addSales(String skuId, Integer number) {
        skuMapper.addSales(skuId,number);
    }

    @Override
    public String getGoodsName(String goodsId) {
        return skuMapper.getGoodsName(goodsId);
    }
}
