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.center.taUser.entity.TaUser;
import com.huiju.estateagents.property.model.BillInvoice;
import com.huiju.estateagents.property.model.TpBillOrder;
import org.apache.ibatis.annotations.*;

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

/**
 * <p>
 * 缴费单 Mapper 接口
 * </p>
 *
 * @author weiximei
 * @since 2019-02-13
 */
@Mapper
public interface BillInvoiceMapper extends BaseMapper<BillInvoice> {

    /**
     * 查询有效的缴费单
     * @param page
     * @param map
     * @return
     */
    IPage<BillInvoice> selectBillInvoice(Page page, @Param("map") Map<String, Object> map);

    /**
     * 查询作废的缴费单
     *      前台批量添加的缴费单, 默认是 作废
     * @param map
     * @return
     */
    List<BillInvoice> selectBillInvoiceTemp(@Param("map") Map<String, Object> map);

    /**
     * 查询有效的缴费单
     * @param page
     * @return
     */
    IPage<BillInvoice> selectBillInvoiceEffective(Page page, @Param("map") Map<String, Object> map);
	
	List<Map<String, Object>> getPriceCount();


    /**
     * 分页获取缴费和未缴费的数据
     * @param orgId
     * @param personId
     * @param payType
     * @return
     */
    IPage<Map<String, Object>> getBillsList(IPage<Map<String, Object>> pg, @Param("orgId") Integer orgId, @Param("personId") String personId, @Param("payType") Integer payType);

    /**
     * 获取账单的详细信息
     * @param billInvoiceId
     * @return
     */
    Map<String, Object> getBillInvoiceDetail(@Param("orgId") Integer orgId,@Param("billInvoiceId") Integer billInvoiceId);

    /**
     * 获取需要支付的金额
     * @param billInvoiceId
     * @param buildingOwnerInfoId
     * @param communityId
     * @return
     */
    BillInvoice selectByIdAndroomNoId(@Param("id") Integer billInvoiceId,@Param("roomNoId") Integer buildingOwnerInfoId,@Param("orgId") Integer orgId);

    BillInvoice selectByOutTradeNo(@Param("outTradeNo") String outTradeNo);

    List<BillInvoice> selectByBuildingOwnerInfoId(@Param("buildingOwnerInfoId") Integer buildingOwnerInfoId);

    int updateBeach(Map<String, Object> map);

    /**
     * 根据 id 查询缴费单
     * @param billId
     * @return
     */
    @ResultType(BillInvoice.class)
    @Select("select " +
            "t.* ," +
            "b.bill_name as billName " +
            "from " +
            "tp_bill_invoice t " +
            "LEFT JOIN tp_bill b ON t.bill_id = b.id " +
            "where t.id = #{billId}")
    BillInvoice selectByIdBillInvoiceInfo(Integer billId);
}
