package com.miaxis.carousel.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaxis.carousel.domain.CarouselChartInfo;
import com.miaxis.carousel.mapper.CarouselChartInfoMapper;
import com.miaxis.carousel.service.ICarouselChartInfoService;
import com.miaxis.carousel.vo.CarouselChartInfoVo;
import com.miaxis.common.core.domain.Response;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 轮播图Service业务层处理
 *
 * @author miaxis
 * @date 2021-03-11
 */
@Service
@RequiredArgsConstructor
public class CarouselChartInfoServiceImpl extends ServiceImpl<CarouselChartInfoMapper, CarouselChartInfo> implements ICarouselChartInfoService {

    private final CarouselChartInfoMapper carouselChartInfoMapper;

    /**
     * 查询轮播图列表
     *
     * @param carouselChartInfo 轮播图
     * @return 轮播图
     */
    @Override
    public List<CarouselChartInfoVo> selectCarouselChartInfoList(CarouselChartInfo carouselChartInfo){
        return carouselChartInfoMapper.selectCarouselChartInfoList(carouselChartInfo);
    }

    /**
     * 删除轮播图(伪删除)
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Response removeCarouselByIds(Long[] ids) {
        try {
            for (Long id : ids) {
                this.update(new UpdateWrapper<CarouselChartInfo>().set("status",1).eq("id",id));
            }
            return Response.success();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

}
