
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.SpuConsignmentChangeMapper;
import com.tmerclub.cloud.product.model.SpuConsignmentChange;
import com.tmerclub.cloud.product.service.SpuConsignmentChangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商家代销商品基本信息相对于供应商品是否改变
 *
 * @author tmerclub
 * @date 2022-08-11 22:21:10
 */
@Service
public class SpuConsignmentChangeServiceImpl implements SpuConsignmentChangeService {

    @Autowired
    private SpuConsignmentChangeMapper spuConsignmentChangeMapper;

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

    @Override
    public SpuConsignmentChange getByConsignmentChangeId(Long consignmentChangeId) {
        return spuConsignmentChangeMapper.getByConsignmentChangeId(consignmentChangeId);
    }

    @Override
    public void save(SpuConsignmentChange spuConsignmentChange) {
        spuConsignmentChangeMapper.save(spuConsignmentChange);
    }

    @Override
    public void update(SpuConsignmentChange spuConsignmentChange) {
        spuConsignmentChangeMapper.update(spuConsignmentChange);
    }

    @Override
    public void deleteById(Long consignmentChangeId) {
        spuConsignmentChangeMapper.deleteById(consignmentChangeId);
    }

    @Override
    @Cacheable(cacheNames = CacheNames.SPU_SUPPLIER_CHANGE_LOG, key = "#spuId", sync = true)
    public SpuConsignmentChange getBySpuId(Long spuId) {
        return spuConsignmentChangeMapper.getBySpuId(spuId);
    }

    @Override
    public List<SpuConsignmentChange> batchGetBySpuIdList(List<Long> spuIdList) {
        if (spuIdList.size() == 0) {
            return null;
        }
        return spuConsignmentChangeMapper.batchGetBySpuIdList(spuIdList);
    }

    @Override
    public SpuConsignmentChange consignmentChange(Long spuId) {
        return spuConsignmentChangeMapper.getBySpuId(spuId);
    }
}
