<?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.sealhandover.mapper.SealHandoverMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="sealHandoverResultMap" type="org.springblade.bank.sealhandover.entity.SealHandover">
        <result column="id" property="id"/>
        <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="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="bank_no" property="bankNo"/>
        <result column="org_no" property="orgNo"/>
        <result column="org_name" property="orgName"/>
        <result column="seal_type" property="sealType"/>
        <result column="seal_no" property="sealNo"/>
        <result column="handover_person_no" property="handoverPersonNo"/>
        <result column="handover_person_name" property="handoverPersonName"/>
        <result column="handover_date" property="handoverDate"/>
        <result column="receiver_no" property="receiverNo"/>
        <result column="receiver_name" property="receiverName"/>
        <result column="remark" property="remark"/>
        <result column="filling_date" property="fillingDate"/>
        <result column="filling_person" property="fillingPerson"/>
        <result column="is_turn_in" property="isTurnIn"/>

        <result column="receiver_id" property="receiverId"/>
        <result column="handover_person_id" property="handoverPersonId"/>
        <result column="process" property="process"/>
        <result column="sure_time" property="sureTime"/>
        <result column="pid" property="pid"/>
    </resultMap>


    <select id="selectSealHandoverPage" resultMap="sealHandoverResultMap">
        SELECT c.* FROM
        (select * from zh_input_seal_handover where is_deleted = 0
        <if test="sealHandover.deptIdList!=null and sealHandover.deptIdList.size>0">
            and create_dept in
            <foreach collection="sealHandover.deptIdList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        UNION
        select * from zh_input_seal_handover where is_deleted = 0
        and (create_user = '${sealHandover.currentuserId}' or LOCATE('${sealHandover.currentuserId}', receiver_id) > 0)
        ) c
        where  1=1


        <if test="sealHandover!=null">
            <if test="sealHandover.status!=null">
                AND c.status = '${sealHandover.status}'
            </if>
            <if test="sealHandover.createUser!=null">
                AND c.create_user like '%${sealHandover.createUser}%'
            </if>
            <if test="sealHandover.bankNo!=null">
                AND c.bank_no = '${sealHandover.bankNo}'
            </if>
            <if test="sealHandover.sealNo!=null">
                AND c.seal_no = '${sealHandover.sealNo}'
            </if>
            <if test="sealHandover.process!=null">
                AND c.process = '${sealHandover.process}'
            </if>
            <if test="sealHandover.receiverId!=null">
                AND receiver_id = '${sealHandover.receiverId}'
            </if>
           <if test="sealHandover.isTurnIn!=null">
                AND c.is_turn_in = '${sealHandover.isTurnIn}'
            </if>
           <if test="sealHandover.receiverName!=null">
                AND c.receiver_name like '%${sealHandover.receiverName}%'
            </if>
            <if test="sealHandover.sealType!=null">
                AND c.seal_type in
                <foreach item="sealType" collection="sealHandover.sealTypes" separator="," open="(" close=")" index="">
                    #{sealType}
                </foreach>
            </if>
            <if test="sealHandover.orgNos!=null">
                AND c.org_no in
                <foreach item="orgNo" collection="sealHandover.orgNos" separator="," open="(" close=")" index="">
                    #{orgNo}
                </foreach>
            </if>
            <if test="sealHandover.handoverDate_begin!=null and sealHandover.handoverDate_end!=null">
                and c.handover_date BETWEEN '${sealHandover.handoverDate_begin}' and '${sealHandover.handoverDate_end}'
            </if>
            <if test="sealHandover.receiverName!=null and sealHandover.receiverName!=null">
                AND c.receiver_name like '%${sealHandover.receiverName}%'
            </if>
        </if>
        ORDER BY c.handover_date DESC
    </select>

    <select id="selectMySealHandoverPage" resultMap="sealHandoverResultMap">
        select * from zh_input_seal_handover where is_deleted = 0
        <if test="sealHandover!=null">

            <if test="sealHandover.process!=null">
                AND process = '${sealHandover.process}'
            </if>
            <if test="sealHandover.receiverId!=null">
                AND receiver_id = '${sealHandover.receiverId}'
            </if>


            <if test="sealHandover.createUser!=null">
                AND create_user like '%${sealHandover.createUser}%'
            </if>
            <if test="sealHandover.bankNo!=null">
                AND bank_no = '${sealHandover.bankNo}'
            </if>
            <if test="sealHandover.sealNo!=null">
                AND seal_no = '${sealHandover.sealNo}'
            </if>
           <if test="sealHandover.isTurnIn!=null">
                AND is_turn_in = '${sealHandover.isTurnIn}'
            </if>
           <if test="sealHandover.receiverName!=null">
                AND receiver_name like '%${sealHandover.receiverName}%'
            </if>
            <if test="sealHandover.sealType!=null">
                AND seal_type in
                <foreach item="sealType" collection="sealHandover.sealTypes" separator="," open="(" close=")" index="">
                    #{sealType}
                </foreach>
            </if>
            <if test="sealHandover.orgNos!=null">
                AND org_no in
                <foreach item="orgNo" collection="sealHandover.orgNos" separator="," open="(" close=")" index="">
                    #{orgNo}
                </foreach>
            </if>
            <if test="sealHandover.handoverDate_begin!=null and sealHandover.handoverDate_end!=null">
                and handover_date BETWEEN '${sealHandover.handoverDate_begin}' and '${sealHandover.handoverDate_end}'
            </if>
            <if test="sealHandover.receiverName!=null and sealHandover.receiverName!=null">
                AND receiver_name like '%${sealHandover.receiverName}%'
            </if>
        </if>
        ORDER BY handover_date DESC
    </select>



</mapper>
