<?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.goodsuse.mapper.GoodsUseMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="goodsUseResultMap" type="org.springblade.bank.goodsuse.entity.GoodsUse">
        <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="date" property="date"/>
        <result column="type" property="type"/>
        <result column="use_number" property="useNumber"/>
        <result column="receipt_number" property="receiptNumber"/>
        <result column="write_off_number" property="writeOffNumber"/>
        <result column="begin_no" property="beginNo"/>
        <result column="end_no" property="endNo"/>
        <result column="last_balance" property="lastBalance"/>
        <result column="balance" property="balance"/>
        <result column="remark" property="remark"/>
        <result column="filling_no" property="fillingNo"/>
        <result column="filling_name" property="fillingName"/>
        <result column="confirm_no" property="confirmNo"/>
        <result column="confirm_name" property="confirmName"/>
        <result column="filling_date" property="fillingDate"/>
        <result column="person_id" property="personId"/>
        <result column="person_no" property="personNo"/>
        <result column="person_name" property="personName"/>
        <result column="approve_time" property="approveTime"/>
        <result column="process" property="process"/>
        <result column="is_completed" property="isCompleted"/>
    </resultMap>


    <select id="selectGoodsUsePage" resultMap="goodsUseResultMap">
        select * from zh_record_goods_use where is_deleted = 0 and id != 1 and bank_no != '000'
        /*and (
        process != 2 or
        (process = 2 and (create_user = '${goodsUse.currentuserId}' or person_id = '${goodsUse.currentuserId}' ))
        )*/
        <if test="goodsUse!=null">
            <if test="!(goodsUse.isManager!=null and goodsUse.isManager == true)">
                and (
                process != 2 or
                (process = 2 and (create_user = '${goodsUse.currentuserId}' or person_id = '${goodsUse.currentuserId}' ))
                )
            </if>
            <if test="goodsUse.createUser!=null">
                AND create_user like '%${goodsUse.createUser}%'
            </if>
            <if test="goodsUse.personNo!=null">
                AND person_no = '${goodsUse.personNo}'
            </if>
            <if test="goodsUse.bankNo!=null">
                AND bank_no = '${goodsUse.bankNo}'
            </if>
            <if test="goodsUse.process!=null">
                AND process = '${goodsUse.process}'
            </if>
            <if test="goodsUse.date_begin!=null and goodsUse.date_end!=null">
                and date BETWEEN '${goodsUse.date_begin}' and '${goodsUse.date_end}'
            </if>

            <if test="goodsUse.type!=null">
                AND type in
                <foreach item="type" collection="goodsUse.types" separator="," open="(" close=")" index="">
                    #{type}
                </foreach>
            </if>
            <if test="goodsUse.orgNos!=null">
                AND org_no in
                <foreach item="orgNo" collection="goodsUse.orgNos" separator="," open="(" close=")" index="">
                    #{orgNo}
                </foreach>
            </if>
        </if>
        ORDER BY create_time DESC
    </select>

</mapper>
