package com.cyl.manager.oth.service;

import java.util.Arrays;
import java.util.List;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.manager.oth.domain.entity.SlideshowInfo;
import com.cyl.manager.oth.domain.query.SlideshowInfoQuery;
import com.cyl.manager.oth.mapper.SlideshowInfoMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 轮播图信息Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class SlideshowInfoService {
    @Autowired
    private SlideshowInfoMapper slideshowInfoMapper;

    /**
     * 查询轮播图信息
     *
     * @param id 轮播图信息主键
     * @return 轮播图信息
     */
    public SlideshowInfo selectById(Long id) {
        return slideshowInfoMapper.selectById(id);
    }

    /**
     * 查询轮播图信息列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 轮播图信息
     */
    public List<SlideshowInfo> selectList(SlideshowInfoQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<SlideshowInfo> qw = new QueryWrapper<>();
        qw.eq("del_flag",0);
        String nameLike = query.getNameLike();
        if (!StringUtils.isEmpty(nameLike)) {
            qw.like("name", nameLike);
        }
        qw.orderByAsc("order_num");
        return slideshowInfoMapper.selectList(qw);
    }

    /**
     * 新增轮播图信息
     *
     * @param slideshowInfo 轮播图信息
     * @return 结果
     */
    public int insert(SlideshowInfo slideshowInfo) {
        slideshowInfo.setCreateTime(LocalDateTime.now());
        return slideshowInfoMapper.insert(slideshowInfo);
    }

    /**
     * 修改轮播图信息
     *
     * @param slideshowInfo 轮播图信息
     * @return 结果
     */
    public int update(SlideshowInfo slideshowInfo) {
        return slideshowInfoMapper.updateById(slideshowInfo);
    }

    /**
     * 批量删除轮播图信息
     *
     * @param ids 需要删除的轮播图信息主键
     * @return 结果
     */
    public int deleteByIds(Long id) {
        return slideshowInfoMapper.deleteById(id);
    }

    /**
     * 删除轮播图信息信息
     *
     * @param id 轮播图信息主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return slideshowInfoMapper.updateDelFlagByIds(ids);
    }
}
