package com.clx.performance.sqlProvider.vehiclewarn;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clx.performance.param.pc.vehiclewarn.PageVehicleWarnUserParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

import java.util.Objects;

public class VehicleWarnUserSqlProvider {

    private static final String TABLE = "vehicle_warn_user";

    public String pageByParam(@Param("page") Page page, @Param("param") PageVehicleWarnUserParam param) {

        return new SQL(){{

            SELECT("*");
            FROM(TABLE);
            WHERE("delete_status = 0");
            if (StringUtils.isNotBlank(param.getName())) {WHERE("name = #{param.name}");}
            if (StringUtils.isNotBlank(param.getMobile())) {WHERE("mobile = #{param.mobile}");}
            if (Objects.nonNull(param.getNoticeStatus())) {WHERE("notice_status = #{param.noticeStatus}");}

            ORDER_BY("id desc");
        }}.toString();
    }

}
