package com.huiju.estateagents.property.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huiju.estateagents.property.model.TpBillOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 缴费订单表 Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2019-04-18
 */
@Mapper
public interface TpBillOrderMapper extends BaseMapper<TpBillOrder> {

    /**
     * 查询订单数据
     * @param page
     * @param map
     * @return
     */
    IPage<TpBillOrder> getBillOrderAll(Page page, @Param("map") Map<String, Object> map);

    /**
     * 根据订单号，查询所有 缴费组
     * @param orderNumber
     * @return
     */
    @ResultType(TpBillOrder.class)
    @Select("select " +
            "tbo.id as id, " +
            "tbo.org_id as orgId, " +
            "tbo.tp_bill_id as tpBillId, " +
            "tbo.tp_bill_invoice_id as tpBillInvoiceId, " +
            "tbo.order_bumber as orderBumber, " +
            "tbo.create_user as createUser, " +
            "tbo.create_date as createDate, " +
            "tbo.update_user as updateUser, " +
            "tbo.update_date as updateDate, " +
            "tbo.order_status as orderStatus, " +
            "tbo.pay_phone as payPhone, " +
            "tb.bill_name as billName " +
            "from tp_bill_order tbo " +
            "LEFT JOIN tp_bill tb on tbo.tp_bill_id = tb.id " +
            "where tbo.order_bumber = #{orderNumber} " +
            "GROUP BY tbo.tp_bill_id")
    List<TpBillOrder> getByOrderNumberBillInvoice(@Param("orderNumber") String orderNumber);


    /**
     * 根据房间号查询订单
     * @param roomNoId
     * @return
     */
    @ResultType(TpBillOrder.class)
    @Select("SELECT tbo.* FROM tp_bill_order tbo LEFT JOIN tp_bill_invoice tbi on tbo.tp_bill_invoice_id = tbi.id " +
            "WHERE tbi.room_no_id = #{roomNoId} and tbo.order_status = 1 GROUP BY tbo.order_bumber ORDER BY tbo.create_date DESC")
    List<TpBillOrder> selectByRoomNoId(@Param("roomNoId") Integer roomNoId);

    /**
     * 根据订单号 查询缴费组
     * @param orderBumber
     * @return
     */
    @ResultType(TpBillOrder.class)
    @Select("SELECT * FROM tp_bill_order WHERE order_bumber = #{orderBumber} GROUP BY tp_bill_id")
    List<TpBillOrder> selectByOrderNumberBill(@Param("orderBumber") String orderBumber);

    /**
     * 根据订单查询， 所有数据
     * @param orderNumber
     * @return
     */
    @ResultType(TpBillOrder.class)
    @Select("select " +
            "tbo.* from tp_bill_order tbo where tbo.order_bumber=#{orderNumber}")
    List<TpBillOrder> selectByOrderBumber(@Param("orderNumber") String orderNumber);


}
