package com.clx.performance.sqlProvider.borrower;

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

public class BorrowerSqlProvider {

    public String pageByParam(@Param("page") Page<BorrowerVO> page, @Param("param") PageBorrowerParam param) {
        return new SQL(){{

            SELECT(" id, name, bank_name as bankName, bank_card_no as bankCardNo, " +
                    " delete_status, status, " +
                    " op_user_no as opUserNo, op_user_name as opUserName, date_format(op_time, '%Y-%m-%d %H:%i:%s') as opTime, " +
                    " date_format(create_time, '%Y-%m-%d %H:%i:%s') as createTime, " +
                    " date_format(modified_time, '%Y-%m-%d %H:%i:%s') as modifiedTime "
            );

            FROM("borrower");
            WHERE("delete_status = 0");

            if (StringUtils.isNotBlank(param.getName())) {WHERE("name = #{param.name}");}

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

}
