
package com.tmerclub.cloud.product.service.impl;

import com.tmerclub.cloud.common.cache.constant.CacheNames;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.util.PageUtil;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.product.mapper.SpuExtensionMapper;
import com.tmerclub.cloud.product.model.SpuExtension;
import com.tmerclub.cloud.product.service.SkuStockService;
import com.tmerclub.cloud.product.service.SpuExtensionService;
import com.tmerclub.cloud.product.vo.SpuExtensionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

/**
 *
 *
 * @author tmerclub
 * @date 2020-11-11 13:49:06
 */
@Service
public class SpuExtensionServiceImpl implements SpuExtensionService {

    @Autowired
    private SpuExtensionMapper spuExtensionMapper;
    @Autowired
    private SkuStockService skuStockService;

    @Override
    public PageVO<SpuExtensionVO> page(PageDTO pageDTO) {
        return PageUtil.doPage(pageDTO, () -> spuExtensionMapper.list());
    }

    @Override
    public SpuExtensionVO getBySpuExtendId(Long spuExtendId) {
        return spuExtensionMapper.getBySpuExtendId(spuExtendId);
    }

    @Override
    public void save(SpuExtension spuExtension) {
        spuExtensionMapper.save(spuExtension);
    }

    @Override
    public void deleteById(Long spuId) {
        spuExtensionMapper.deleteById(spuId);
    }

    @Override
    public SpuExtension getBySpuId(Long spuId) {
        return spuExtensionMapper.getBySpuId(spuId);
    }

    @Override
    @CacheEvict(cacheNames = CacheNames.SPU_EXTENSION_KEY, key = "#spuExtension.spuId")
    public void update(SpuExtension spuExtension) {
        spuExtensionMapper.update(spuExtension);
    }

    @Override
    @CacheEvict(cacheNames = CacheNames.SPU_EXTENSION_KEY, key = "#spuId")
    public void updateWaterSoldNumBySpuId(Long spuId, Integer waterSoldNum) {
        spuExtensionMapper.updateWaterSoldNumBySpuId(spuId, waterSoldNum);
    }

    @Override
    @CacheEvict(cacheNames = CacheNames.SPU_EXTENSION_KEY, key = "#spuId")
    public void changeCommentNum(Long spuId, Integer changeCount) {
        spuExtensionMapper.changeCommentNum(spuId, changeCount);
    }

    @Override
    public void updateSaleNumBySeckillOrder(Long spuId, Integer prodCount) {
        spuExtensionMapper.updateSaleNumBySeckillOrder(spuId, prodCount);
    }
}
