package com.contract.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.contract.entity.AppBanner;
import com.contract.mapper.AppBannerMapper;
import com.contract.service.AppBannerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppBannerServiceImpl extends ServiceImpl<AppBannerMapper, AppBanner>
        implements AppBannerService {

    @Override
    public Page<AppBanner> pageQuery(int pageNum, int pageSize, Integer status, String title) {
        LambdaQueryWrapper<AppBanner> wrapper = new LambdaQueryWrapper<>();
        if (status != null) {
            wrapper.eq(AppBanner::getStatus, status);
        }
        if (StringUtils.isNotBlank(title)) {
            wrapper.like(AppBanner::getTitle, title);
        }
        wrapper.orderByDesc(AppBanner::getSort);
        return page(new Page<>(pageNum, pageSize), wrapper);
    }

    @Override
    public List<AppBanner> findActiveBanners() {
        return baseMapper.findActiveBanners();
    }
}
