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

import com.tmerclub.cloud.common.cache.constant.PlatformCacheNames;
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.platform.dto.WebConfigDTO;
import com.tmerclub.cloud.platform.mapper.WebConfigMapper;
import com.tmerclub.cloud.platform.model.WebConfig;
import com.tmerclub.cloud.platform.service.WebConfigService;
import com.tmerclub.cloud.platform.vo.WebConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * 网站配置信息表
 *
 * @author Orange
 * @date 2022-08-01 15:53:50
 */
@Service
public class WebConfigServiceImpl implements WebConfigService {

    @Autowired
    private WebConfigMapper webConfigMapper;

    @Override
    public PageVO<WebConfig> page(PageDTO pageDTO, WebConfigDTO webConfigDTO) {
        return PageUtil.doPage(pageDTO, () -> webConfigMapper.list(webConfigDTO));
    }

    @Override
    public WebConfig getById(Long id) {
        return webConfigMapper.getById(id);
    }

    @Override
    public void save(WebConfig webConfig) {
        webConfigMapper.save(webConfig);
    }

    @Override
    public void update(WebConfig webConfig) {
        webConfigMapper.update(webConfig);
    }

    @Override
    public void deleteById(Long id) {
        webConfigMapper.deleteById(id);
    }

    @Override
    public void updateActivityState(Integer configType) {
        webConfigMapper.updateActivityState(configType);
    }

    @Override
    @Cacheable(cacheNames = PlatformCacheNames.WEB_CONFIG_ACTIVITY, key = "#configType")
    public WebConfigVO getActivityWebConfig(Integer configType) {
        return webConfigMapper.getByType(configType);
    }

    @Override
    @CacheEvict(cacheNames = PlatformCacheNames.WEB_CONFIG_ACTIVITY, key = "#configType")
    public void removeActivityWebConfig(Integer configType) {
    }

    @Override
    public int countByType(Integer configType) {
        return webConfigMapper.countByType(configType);
    }

    @Override
    public WebConfigVO getByConfigType(Integer configType) {
        return webConfigMapper.getByType(configType);
    }
}
