<?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.checklist.mapper.ChecklistMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="checklistResultMap" type="org.springblade.bank.checklist.entity.Checklist">
        <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="check_date" property="checkDate"/>
        <result column="type" property="type"/>
        <result column="item" property="item"/>
        <result column="content" property="content"/>
        <result column="is_checked" property="isChecked"/>
        <result column="check_no" property="checkNo"/>
        <result column="check_name" property="checkName"/>
        <result column="remark" property="remark"/>
        <result column="filling_date" property="fillingDate"/>
    </resultMap>

    <select id="selectChecklistPage" resultMap="checklistResultMap">
        select * from zh_record_checklist where is_deleted = 0
        <if test="checklist!=null">
            <if test="checklist.isChecked!=null">
                AND is_checked = '${checklist.isChecked}'
            </if>
            <if test="checklist.dataType!=null">
                <if test="checklist.dataType==1">
                    and date(filling_date) = CURDATE()
                </if>
                <if test="checklist.dataType==2">
                    and filling_date BETWEEN '${checklist.beginDate}' and '${checklist.endDate}'
                </if>
                <if test="checklist.dataType==3">
                    and date_format(filling_date,'%Y-%m')=date_format(now(),'%Y-%m')
                </if>
            </if>
            <if test="checklist.checkDate_begin!=null and checklist.checkDate_end!=null">
                and check_date BETWEEN '${checklist.checkDate_begin}' and '${checklist.checkDate_end}'
            </if>

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

    <select id="getDataList" resultMap="checklistResultMap">
        select * from zh_record_checklist where is_deleted = 0
        <if test="checks!=null">
            <if test="checks.isChecked!=null">
                AND is_checked = '${checks.isChecked}'
            </if>
            <if test="checks.dataType!=null">
                <if test="checks.dataType==1">
                    and date(filling_date) = CURDATE()
                </if>
                <if test="checks.dataType==2">
                    and filling_date BETWEEN '${checks.beginDate}' and '${checks.endDate}'
                </if>
                <if test="checks.dataType==3">
                    and date_format(filling_date,'%Y-%m')=date_format(now(),'%Y-%m')
                </if>
            </if>
            <if test="checks.checkDate_begin!=null and checks.checkDate_end!=null">
                and check_date BETWEEN '${checks.checkDate_begin}' and '${checks.checkDate_end}'
            </if>

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

</mapper>
