package org.dromara.main.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.main.domain.Banner;
import org.dromara.main.domain.bo.BannerBo;
import org.dromara.main.domain.vo.BannerVo;
import org.dromara.main.mapper.BannerMapper;
import org.dromara.main.service.IBannerService;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Service
public class BannerServiceImpl implements IBannerService {

    private final BannerMapper baseMapper;

    @Override
    public List<BannerVo> queryList(BannerBo bo) {
        LambdaQueryWrapper<Banner> lqw = Wrappers.lambdaQuery();
        lqw.like(bo.getTitle() != null && !bo.getTitle().isBlank(), Banner::getTitle, bo.getTitle());
        lqw.eq(bo.getIsEnabled() != null, Banner::getIsEnabled, bo.getIsEnabled());
        lqw.orderByAsc(Banner::getSortOrder).orderByAsc(Banner::getId);
        return baseMapper.selectVoList(lqw);
    }
}
