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.GoodSale;
import com.fzm.mall.server.front.goods.mapper.GoodSaleMapper;
import com.fzm.mall.server.front.goods.service.IGoodSaleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.mall.server.front.redis.GoodRedis;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 商品其他信息表 服务实现类
 * </p>
 *
 * @author tdz
 * @since 2021-03-02
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class GoodSaleServiceImpl extends ServiceImpl<GoodSaleMapper, GoodSale> implements IGoodSaleService {
    private final GoodRedis goodRedis;
    /**
     * 获取商品其他信息
     */
    @Override
    public GoodSale goodSale(final String gid) {
        GoodSale goodSale = goodRedis.getSale(gid);
        if (goodSale != null) {
            return goodSale;
        }
        QueryWrapper<GoodSale> qw=new QueryWrapper<>();
        qw.eq("goods_id",gid);
        goodSale = getOne(qw);
        if (goodSale != null) {
            goodRedis.setSale(gid, goodSale);
        }
        return goodSale;
    }
}
