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.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

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.community_id as communityId, " +
            "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);

}
