package com.clx.performance.sqlProvider.settle;

import cn.hutool.core.util.ObjectUtil;
import com.clx.performance.param.pc.PageOwnerAccountListParam;
import com.clx.performance.param.pc.PageOwnerCaseOutListParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class NetworkDriverAccountProvider {

    public String networkAccountList(@Param("param") PageOwnerAccountListParam param) {
        String sql = new SQL() {{
            SELECT("a.id, a.owner_user_no," +
                    " a.owner_user_name, a.mobile, a.account_type, " +
                    " a.account_balance,a.usable_balance, a.frozen_balance,a.create_by,date_format(a.create_time, '%Y-%m-%d %H:%i:%s') as create_time");
            FROM("owner_account a");


            if (StringUtils.isNotBlank(param.getOwnerUserNo())) {
                WHERE("a.owner_user_no = #{param.ownerUserNo}");
            }
            if (StringUtils.isNotBlank(param.getMobile())) {
                WHERE("a.mobile = #{param.mobile}");
            }
            if (ObjectUtil.isNotNull(param.getAccountType())) {
                WHERE("a.account_type = #{param.accountType}");
            }
            if (StringUtils.isNotBlank(param.getOwnerUserName())) {
                WHERE("a.owner_user_name like CONCAT('%',#{param.ownerUserName},'%')");
            }
            ORDER_BY("a.create_time desc");
        }}.toString();
        return sql;
    }

}
