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.AppHeader;
import com.contract.mapper.AppHeaderMapper;
import com.contract.service.AppHeaderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppHeaderServiceImpl extends ServiceImpl<AppHeaderMapper, AppHeader>
        implements AppHeaderService {

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

    @Override
    public List<AppHeader> findActiveHeaders() {
        return baseMapper.findActiveHeaders();
    }
}
