package com.yiqi.app.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yiqi.common.enums.StatusType;
import com.yiqi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yiqi.app.mapper.AppBannerMapper;
import com.yiqi.app.domain.AppBanner;
import com.yiqi.app.service.IAppBannerService;

/**
 * 轮播图及启动页广告配置Service业务层处理
 *
 * @author xiaohei
 * @date 2023-08-08
 */
@Service
public class AppBannerServiceImpl extends ServiceImpl<AppBannerMapper, AppBanner> implements IAppBannerService {

    /**
     * 查询轮播图及启动页广告配置
     *
     * @param id 轮播图及启动页广告配置主键
     * @return 轮播图及启动页广告配置
     */
    @Override
    public AppBanner selectAppBannerById(Long id) {
        return baseMapper.selectAppBannerById(id);
    }

    /**
     * 查询轮播图及启动页广告配置列表
     *
     * @param appBanner 轮播图及启动页广告配置
     * @return 轮播图及启动页广告配置
     */
    @Override
    public List<AppBanner> selectAppBannerList(AppBanner appBanner) {
        return baseMapper.selectAppBannerList(appBanner);
    }

    @Override
    public List<AppBanner> selectAppBannerListByType(String bannerType) {
        return list(new QueryWrapper<AppBanner>().lambda().eq(AppBanner::getStatus, StatusType.OK.getCode()).eq(AppBanner::getBannerType, bannerType).eq(AppBanner::getStatus, StatusType.OK.getCode())
                .orderByDesc(AppBanner::getSort));
    }


    /**
     * 新增轮播图及启动页广告配置
     *
     * @param appBanner 轮播图及启动页广告配置
     * @return 结果
     */
    @Override
    public int insertAppBanner(AppBanner appBanner) {
        appBanner.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insert(appBanner);
    }

    /**
     * 修改轮播图及启动页广告配置
     *
     * @param appBanner 轮播图及启动页广告配置
     * @return 结果
     */
    @Override
    public int updateAppBanner(AppBanner appBanner) {
        appBanner.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateById(appBanner);
    }

    /**
     * 批量删除轮播图及启动页广告配置
     *
     * @param ids 需要删除的轮播图及启动页广告配置主键
     * @return 结果
     */
    @Override
    public int deleteAppBannerByIds(Long[] ids) {
        return baseMapper.deleteAppBannerByIds(ids);
    }

    /**
     * 删除轮播图及启动页广告配置信息
     *
     * @param id 轮播图及启动页广告配置主键
     * @return 结果
     */
    @Override
    public int deleteAppBannerById(Long id) {
        return baseMapper.deleteAppBannerById(id);
    }
}
