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.SysAppletIndexSlideshow;
import org.dromara.system.domain.bo.SysAppletIndexSlideshowBo;
import org.dromara.system.domain.vo.SysAppletIndexSlideshowVo;
import org.dromara.system.mapper.SysAppletIndexSlideshowMapper;
import org.dromara.system.service.ISysAppletIndexSlideshowService;
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 SysAppletIndexSlideshowServiceImpl implements ISysAppletIndexSlideshowService {

    private final SysAppletIndexSlideshowMapper baseMapper;

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

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

    @CacheEvict(cacheNames = CacheNames.SYS_APPLET_SLIDESHOW, allEntries = true)
    @Override
    public Boolean insertByBo(SysAppletIndexSlideshowBo bo) {
        SysAppletIndexSlideshow entity = MapstructUtils.convert(bo, SysAppletIndexSlideshow.class);
        return baseMapper.insert(entity) > 0;
    }

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

    @CacheEvict(cacheNames = CacheNames.SYS_APPLET_SLIDESHOW, allEntries = true)
    @Override
    public Boolean deleteByIds(List<Long> ids) {
        return baseMapper.deleteBatchIds(ids) > 0;
    }

}
