<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dayou.mapper.FinanceInvoiceMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.FinanceInvoice">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="modified" property="modified" />
        <result column="created" property="created" />
        <result column="production_fund_id" property="productionFundId" />
        <result column="title" property="title" />
        <result column="type" property="type" />
        <result column="tax_no" property="taxNo" />
        <result column="plan_amount" property="planAmount" />
        <result column="real_amount" property="realAmount" />
        <result column="plan_make_date" property="planMakeDate" />
        <result column="real_make_date" property="realMakeDate" />
        <result column="state" property="state" />
        <result column="reason" property="reason" />
        <result column="apply_id" property="applyId" />
        <result column="checker_id" property="checkerId" />
        <result column="maker_id" property="makerId" />
        <result column="bank_name" property="bankName" />
        <result column="bank_account" property="bankAccount" />
        <result column="bank_address" property="bankAddress" />
        <result column="bank_tel" property="bankTel" />
        <result column="make_item" property="makeItem" />
        <result column="item_quantity" property="itemQuantity" />
        <result column="item_unit" property="itemUnit" />
        <result column="tax_rate" property="taxRate" />
        <result column="tax_amount" property="taxAmount" />
        <result column="remark" property="remark" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        modified,
        created,
        production_fund_id, title, type, tax_no, plan_amount, real_amount, plan_make_date, real_make_date, state, reason, apply_id, checker_id, maker_id, bank_name, bank_account, bank_address, bank_tel, make_item, item_quantity, item_unit, tax_rate, tax_amount, remark
    </sql>

    <select id="getPage" parameterType="com.dayou.entity.FinanceInvoice" resultType="com.dayou.entity.FinanceInvoice">
        SELECT
            fi.*,
            orf.business_type,
            orf.order_id,
            orf.order_name,
            (orf.should_amount=orf.real_amount) as isPayAll,
            u.name AS applyName
        FROM
            finance_invoice fi
                LEFT JOIN order_fund orf ON fi.order_fund_id = orf.id
                LEFT JOIN user u ON u.id = fi.apply_id
        where fi.deleted = 0 and orf.deleted = 0
        <if test="keyword!=null and keyword!='' ">
            and (
            fi.title like concat ('%',#{keyword},'%')
            or orf.order_name like concat('%',#{keyword},'%')
            or orf.order_id like concat('%',#{keyword},'%')
            or orf.business_type like concat('%',#{keyword},'%')
            or u.name like concat('%',#{keyword},'%')
            or fi.type like concat('%',#{keyword},'%')
            or fi.tax_no like concat('%',#{keyword},'%')
            or fi.plan_amount like concat('%',#{keyword},'%')
            or fi.state like concat('%',#{keyword},'%')
            or fi.remark like concat('%',#{keyword},'%')
            )
        </if>
        <if test="vo!=null and vo.pStartDate!=null and vo.pStartDate!=''">
            and fi.plan_make_date &gt;= #{vo.pStartDate}
        </if>
        <if test="vo!=null and vo.pEndDate!=null and vo.pEndDate!=''">
            and fi.plan_make_date &lt;= #{vo.pEndDate}
        </if>
        <if test="vo!=null and vo.aStartDate!=null and vo.aStartDate!=''">
            and fi.created &gt;= #{vo.aStartDate}
        </if>
        <if test="vo!=null and vo.aEndDate!=null and vo.aEndDate!=''">
            and fi.created &lt;= #{vo.aEndDate}
        </if>
        order by fi.created DESC
    </select>

</mapper>
