package com.agileboot.system.post.dto;

import cn.hutool.core.util.StrUtil;
import com.agileboot.common.mybatis.core.page.PageQuery;
import com.agileboot.system.post.entity.SysPost;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Data;

import java.time.LocalDate;
import java.util.Objects;

/**
 * @author valarchie
 */
@Data
public class PostQuery extends PageQuery<SysPost> {

    private String postCode;
    private String postName;
    private Integer status;
    private LocalDate beginTime;
    private LocalDate endTime;

    @Override
    public LambdaQueryWrapper<SysPost> toQueryWrapper() {
        return Wrappers.lambdaQuery(SysPost.class)
                .like(StrUtil.isNotBlank(postCode), SysPost::getPostCode, postCode)
                .like(StrUtil.isNotBlank(postName), SysPost::getPostName, postName)
                .eq(Objects.nonNull(status), SysPost::getStatus, status)
                .between(Objects.nonNull(beginTime) && Objects.nonNull(endTime), SysPost::getCreateTime, beginTime, endTime);
    }
}
