package org.dromara.system.service.impl;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.system.domain.SysAppletIndexCategories;
import org.dromara.system.domain.bo.SysAppletIndexCategoriesBo;
import org.dromara.system.domain.vo.SysAppletIndexCategoriesVo;
import org.dromara.system.mapper.SysAppletIndexCategoriesMapper;
import org.dromara.system.service.ISysAppletIndexCategoriesService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 小程序首页精选分类 Service
 *
 * @Author: Trae
 */
@RequiredArgsConstructor
@Service
public class SysAppletIndexCategoriesServiceImpl implements ISysAppletIndexCategoriesService {

    private final SysAppletIndexCategoriesMapper baseMapper;

    @Cacheable(cacheNames = CacheNames.SYS_APPLET_CATEGORIES, key = "'all'")
    @Override
    public List<SysAppletIndexCategoriesVo> queryAll() {
        return baseMapper.selectVoList();
    }

    @Cacheable(cacheNames = CacheNames.SYS_APPLET_CATEGORIES, key = "#id")
    @Override
    public SysAppletIndexCategoriesVo queryById(Long id) {
        return baseMapper.selectVoById(id);
    }

    @CacheEvict(cacheNames = CacheNames.SYS_APPLET_CATEGORIES, allEntries = true)
    @Override
    public Boolean updateByBo(SysAppletIndexCategoriesBo bo) {
        SysAppletIndexCategories entity = MapstructUtils.convert(bo, SysAppletIndexCategories.class);
        return baseMapper.updateById(entity) > 0;
    }

}
