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

import com.tmerclub.cloud.common.cache.constant.CacheNames;
import com.tmerclub.cloud.common.cache.util.RedisUtil;
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.multishop.mapper.ShopTemplateMapper;
import com.tmerclub.cloud.multishop.model.ShopTemplate;
import com.tmerclub.cloud.multishop.service.ShopTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * 商品装修模板表
 *
 * @author Orange
 * @date 2022-08-12 14:04:57
 */
@Service
public class ShopTemplateServiceImpl implements ShopTemplateService {

    @Autowired
    private ShopTemplateMapper shopTemplateMapper;

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

    @Override
    @Cacheable(cacheNames = CacheNames.GET_BY_SHOP_TEMPLATE_ID_KEY, key = "#templateId")
    public ShopTemplate getByTemplateId(Long templateId) {
        return shopTemplateMapper.getByTemplateId(templateId);
    }

    @Override
    public void save(ShopTemplate shopTemplate) {
        shopTemplateMapper.save(shopTemplate);
    }

    @Override
    public void update(ShopTemplate shopTemplate) {
        shopTemplateMapper.update(shopTemplate);
    }

    @Override
    public void deleteById(Long templateId) {
        shopTemplateMapper.deleteById(templateId);
    }

    @Override
    public void removeCache(Long templateId) {
        RedisUtil.del(CacheNames.GET_BY_SHOP_TEMPLATE_ID_KEY + CacheNames.UNION + templateId);
    }
}
