<?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="org.springblade.bank.returns.mapper.ReturnsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="returnsResultMap" type="org.springblade.bank.returns.entity.Returns">
        <result column="id" property="id"/>
        <result column="status" property="status"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="bank_no" property="bankNo"/>
        <result column="org_no" property="orgNo"/>
        <result column="serial_no" property="serialNo"/>
        <result column="bank" property="bank"/>
        <result column="customer_name" property="customerName"/>
        <result column="reason" property="reason"/>
        <result column="remark" property="remark"/>
        <result column="bar_code" property="barCode"/>
        <result column="handling_bank" property="handlingBank"/>
        <result column="handling_bank_review" property="handlingBankReview"/>
        <result column="handling_date" property="handlingDate"/>
        <result column="handler" property="handler"/>
        <result column="handling_status" property="handlingStatus"/>
        <result column="bank_remark" property="bankRemark"/>
        <result column="bank_confirm_no" property="bankConfirmNo"/>
        <result column="bank_confirm_name" property="bankConfirmName"/>
        <result column="bank_confirm_time" property="bankConfirmTime"/>
        <result column="person_id" property="personId"/>
        <result column="person_name" property="personName"/>
        <result column="approve_time" property="approveTime"/>
        <result column="process" property="process"/>
        <result column="is_completed" property="isCompleted"/>
        <result column="is_public" property="isPublic"/>
    </resultMap>


    <select id="selectReturnsPage" resultMap="returnsResultMap">
        select * from zh_input_returns where is_deleted = 0 and id != 1
        and (
        process != 2 or
        (process = 2 and (create_user = '${returns.currentuserId}' or person_id = '${returns.currentuserId}' ))
        )
        <if test="returns!=null">
            <if test="returns.createUser!=null">
                AND create_user like '%${returns.createUser}%'
            </if>
            <if test="returns.process!=null">
                AND process like '%${returns.process}%'
            </if>
            <if test="returns.isPublic!=null">
                AND is_public like '%${returns.isPublic}%'
            </if>
            <if test="returns.bankNo!=null">
                AND bank_no = '${returns.bankNo}'
            </if>
            <if test="returns.customerName!=null">
                AND customer_name = '${returns.customerName}'
            </if>
            <if test="returns.handlingBank!=null">
                AND handling_bank = '${returns.handlingBank}'
            </if>
            <if test="returns.handlingBankReview!=null">
                AND handling_bank_review = '${returns.handlingBankReview}'
            </if>

            <if test="returns.handlingDate_begin!=null and returns.handlingDate_end!=null">
                and handling_date BETWEEN '${returns.handlingDate_begin}' and '${returns.handlingDate_end}'
            </if>
            <if test="returns.orgNos!=null">
                AND org_no in
                <foreach item="orgNo" collection="returns.orgNos" separator="," open="(" close=")" index="">
                    #{orgNo}
                </foreach>
            </if>
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
