package com.fzm.mall.server.front.order.sql;

import com.fzm.mall.server.front.asset.model.po.qo.OrderQO;
import com.fzm.mall.server.front.goods.model.qo.UserAuctionQO;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.CollectionUtils;

import java.util.Collection;

/**
 * @author tdz
 * @date 2021/02/22 11:26
 */

public class UserBidRecordSqlFactory {
    public String countUserBidRecordOrder(UserAuctionQO qo) {
        return new SQL() {{
            SELECT("r.* ");
            FROM("goods_auction a");
            INNER_JOIN("order_bidding_record r on a.auction_id=r.auction_id");
            if (StringUtils.isNotBlank(qo.getUid())) {
                WHERE("r.uid = #{uid}");
            }
            if (StringUtils.isNotBlank(qo.getFinalUid())) {
                WHERE("a.final_uid = #{finalUid}");
            }
            if (!CollectionUtils.isEmpty(qo.getAuctionIds())) {
                WHERE("a.auction_id in(${auctionIds})");
            }
            if (StringUtils.isNotBlank(qo.getStatus())) {
                WHERE("a.status = #{status}");
            }
        }}.toString();
    }

    public String listUserBidRecordOrder(UserAuctionQO qo) {
        return new SQL() {{
            SELECT("r.* ");
            FROM("goods_auction a");
            INNER_JOIN("order_bidding_record r on a.auction_id=r.auction_id");
            if (StringUtils.isNotBlank(qo.getUid())) {
                WHERE("r.uid = #{uid}");
            }
            if (StringUtils.isNotBlank(qo.getFinalUid())) {
                WHERE("a.final_uid = #{finalUid}");
            }
            if (!CollectionUtils.isEmpty(qo.getAuctionIds())) {
                WHERE("a.auction_id in(${auctionIds})");
            }
            if (StringUtils.isNotBlank(qo.getStatus())) {
                WHERE("a.status = #{status}");
            }
            ORDER_BY("r.id desc,r.create_time desc");
        }}.toString() + " limit #{begin},#{size}";
    }
}
