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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzm.mall.server.front.base.PageVO;
import com.fzm.mall.server.front.goods.mapper.CustomMapper;
import com.fzm.mall.server.front.goods.model.Count;
import com.fzm.mall.server.front.goods.mapper.CountMapper;
import com.fzm.mall.server.front.goods.model.OprationFunction;
import com.fzm.mall.server.front.goods.model.qo.UserAuctionQO;
import com.fzm.mall.server.front.goods.model.vo.PageVo;
import com.fzm.mall.server.front.goods.model.vo.SaleHotVo;
import com.fzm.mall.server.front.goods.service.ICountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.mall.server.front.order.model.BiddingRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品统计信息表 服务实现类
 * </p>
 *
 * @author fzm
 * @since 2021-03-05
 */
@Service
public class CountServiceImpl extends ServiceImpl<CountMapper, Count> implements ICountService {

    @Autowired
    private CountMapper countMapper;

    @Override
    public List<SaleHotVo> getList(PageVo pageVo) {
        int start = (pageVo.getPage() - 1) * pageVo.getSize();
        int end = pageVo.getPage() * pageVo.getSize();
        return countMapper.getList(start, end);
    }

    @Override
    public Count getCountByGid(String goodsId) {
        QueryWrapper<Count> q = new QueryWrapper<>();
        q.eq("goods_id",goodsId);
        return getOne(q);
    }

    /**
     * 查询前十的值得买商品
     */
    @Override
    public List<SaleHotVo> getTopTenSaleHotVo(PageVO pageVo) {
        int start = (pageVo.getPage() - 1) * pageVo.getSize();
        int end = pageVo.getSize();
        List<SaleHotVo> list = countMapper.listTopTenSaleHotVo(start, end);
        return list;
    }

    @Override
    public int getCount() {
        return countMapper.getCount();
    }

    @Override
    public void addSale(String goodsId, Integer number) {
        countMapper.addSale(goodsId, number);
    }
}
