<?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.cardswallow.mapper.CardSwallowMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="cardSwallowResultMap" type="org.springblade.bank.cardswallow.entity.CardSwallow">
        <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="serial_no" property="serialNo"/>
        <result column="send_date" property="sendDate"/>
        <result column="send_bank" property="sendBank"/>
        <result column="card_no" property="cardNo"/>
        <result column="card_serial_no" property="cardSerialNo"/>
        <result column="machine" property="machine"/>
        <result column="machine_no" property="machineNo"/>
        <result column="swallow_date" property="swallowDate"/>
        <result column="card_status" property="cardStatus"/>
        <result column="send_status" property="sendStatus"/>
        <result column="remark" property="remark"/>
        <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_no" property="personNo"/>
        <result column="person_name" property="personName"/>
        <result column="send_org_no" property="sendOrgNo"/>
    </resultMap>


    <select id="selectCardSwallowPage" resultMap="cardSwallowResultMap">

        SELECT c.* FROM
            (select * from zh_input_card_swallow where is_deleted = 0 and id != 1 and bank_no != '000'
            <if test="cardSwallow.deptIdList!=null and cardSwallow.deptIdList.size>0">
                and create_dept in
                <foreach collection="cardSwallow.deptIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>

            UNION
            select * from zh_input_card_swallow where is_deleted = 0 and id != 1 and bank_no != '000'
            and (create_user = '${cardSwallow.currentuserId}' or LOCATE('${cardSwallow.currentuserId}', person_id) > 0 or true = '${cardSwallow.isEquipmentTeam}')
        ) c
        where  1=1

        <if test="cardSwallow!=null">
            <if test="cardSwallow.createUser!=null">
                AND c.create_user = '${cardSwallow.createUser}'
            </if>
            <if test="cardSwallow.process!=null">
                AND c.process like '%${cardSwallow.process}%'
            </if>
            <if test="cardSwallow.personNo!=null">
                AND c.person_no = '${cardSwallow.personNo}'
            </if>
            <if test="cardSwallow.personId!=null">
                AND c.person_id like '%${cardSwallow.personId}%'
            </if>
            <if test="cardSwallow.bankNo!=null">
                AND c.bank_no = '${cardSwallow.bankNo}'
            </if>
            <if test="cardSwallow.cardNo!=null">
                AND c.card_no = '${cardSwallow.cardNo}'
            </if>

            <if test="cardSwallow.orgNos!=null">
                AND c.org_no in
                <foreach item="orgNo" collection="cardSwallow.orgNos" separator="," open="(" close=")" index="">
                    #{orgNo}
                </foreach>
            </if>
            <if test="cardSwallow.sendDate_begin!=null and cardSwallow.sendDate_end!=null">
                and c.send_date BETWEEN '${cardSwallow.sendDate_begin}' and '${cardSwallow.sendDate_end}'
            </if>

            <if test="cardSwallow.sendStatus!=null">
                AND c.send_status in
                <foreach item="sendStatus" collection="cardSwallow.sendStatuss" separator="," open="(" close=")" index="">
                    #{sendStatus}
                </foreach>
            </if>
        </if>
        ORDER BY c.create_time DESC
    </select>

</mapper>
