<?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="com.ruoyi.invest.mapper.CreditReportQueryRecordMapper">

    <resultMap type="CreditReportQueryRecordVo" id="CreditReportQueryRecordResult">
        <result property="id"    column="id"    />
        <result property="queryInstitution"    column="query_institution"    />
        <result property="type"    column="type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="remark"    column="remark"    />
        <result property="queryDate"    column="query_date"    />
        <result property="queryType"    column="query_type"    />
        <result property="queryCount"    column="query_count"    />
    </resultMap>

    <sql id="selectCreditReportQueryRecordVo">
        select a.id, a.query_institution,a.query_count, a.type,a.query_type, a.create_by, a.create_time, a.update_by, a.update_time, a.del_flag, a.remark, a.query_date from credit_report_query_record a
    </sql>

    <select id="selectCreditReportQueryRecordList" parameterType="CreditReportQueryRecordDto" resultMap="CreditReportQueryRecordResult">
        <include refid="selectCreditReportQueryRecordVo"/>
        <where>
            a.del_flag='0'
            <if test="queryInstitution != null  and queryInstitution != ''"> and a.query_institution like '%'|| #{queryInstitution}||'%'</if>
            <if test="type != null  and type != ''"> and a.type = #{type}</if>
            <if test="queryType != null  and queryType != ''"> and a.query_type= #{queryType}</if>
            <if test="queryDateStart!=null and queryDateStart !=''">
                and to_char(a.query_date, 'yyyy-MM-dd')>=#{queryDateStart}
            </if>
            <if test="queryDateEnd!=null and queryDateEnd !=''">
                and #{queryDateEnd}>=to_char(a.query_date, 'yyyy-MM-dd')
            </if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by a.query_date desc
    </select>

    <select id="selectCreditReportQueryRecordById" parameterType="Long" resultMap="CreditReportQueryRecordResult">
        <include refid="selectCreditReportQueryRecordVo"/>
        where a.id = #{id}
    </select>

    <insert id="insertCreditReportQueryRecord" parameterType="CreditReportQueryRecord">
        insert into credit_report_query_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="queryInstitution != null">query_institution,</if>
            <if test="type != null">type,</if>
            <if test="queryType != null">query_type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="queryDate != null">query_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="queryInstitution != null">#{queryInstitution},</if>
            <if test="type != null">#{type},</if>
            <if test="queryType != null">#{queryType},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="queryDate != null">#{queryDate},</if>
         </trim>
    </insert>

    <update id="updateCreditReportQueryRecord" parameterType="CreditReportQueryRecord">
        update credit_report_query_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="queryInstitution != null">query_institution = #{queryInstitution},</if>
            <if test="type != null">type = #{type},</if>
            <if test="queryType != null">query_type = #{queryType},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="queryDate != null">query_date = #{queryDate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCreditReportQueryRecordById" parameterType="Long">
        delete from credit_report_query_record where id = #{id}
    </delete>

    <delete id="deleteCreditReportQueryRecordByIds" parameterType="String">
        delete from credit_report_query_record where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <update id="removeCreditReportQueryRecordById" parameterType="Long">
         update credit_report_query_record set del_flag='1' where id = #{id}
    </update>

    <update id="removeCreditReportQueryRecordByIds" parameterType="String">
        update credit_report_query_record set del_flag='1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <select id="selectQueryInstitutionList" parameterType="CreditReportQueryRecordDto" resultMap="CreditReportQueryRecordResult">
        select
        distinct
        a.query_institution
        from
        credit_report_query_record a
        where
        a.del_flag = '0'
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by
        a.query_institution desc

    </select>
</mapper>
