<?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.system.mapper.ReportQueryLogMapper">

    <resultMap type="ReportQueryLog" id="ReportQueryLogResult">
        <result property="logId" column="log_id"/>
        <result property="reportNumber" column="report_number"/>
        <result property="queryName" column="query_name"/>
        <result property="queryPhone" column="query_phone"/>
        <result property="companyName" column="company_name"/>
        <result property="companyPhone" column="company_phone"/>
        <result property="queryType" column="query_type"/>
        <result property="queryMode" column="query_mode"/>
        <result property="queryNum" column="query_num"/>
        <result property="code" column="code"/>
        <result property="qrImage" column="qr_image"/>
        <result property="isSuccess" column="is_success"/>
        <result property="isDel" column="is_del"/>
        <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="remark" column="remark"/>
    </resultMap>

    <sql id="selectReportQueryLogVo">
        select log_id, report_number, query_name, query_phone, company_name, company_phone, query_type, query_mode, query_num,code, qr_image, is_success, is_del, create_by, create_time, update_by, update_time, remark from report_query_log
    </sql>

    <select id="selectReportQueryLogList" parameterType="ReportQueryLog" resultMap="ReportQueryLogResult">
        <include refid="selectReportQueryLogVo"/>
        <where>
        is_del = 'N'
        <if test="reportNumber != null  and reportNumber != ''">and report_number = #{reportNumber}</if>
        <if test="queryName != null  and queryName != ''">and query_name like concat('%', #{queryName}, '%')</if>
        <if test="queryPhone != null  and queryPhone != ''">and query_phone = #{queryPhone}</if>
        <if test="companyName != null  and companyName != ''">and company_name like concat('%', #{companyName}, '%')
        </if>
        <if test="companyPhone != null  and companyPhone != ''">and company_phone = #{companyPhone}</if>
        <if test="queryType != null  and queryType != ''">and query_type = #{queryType}</if>
        <if test="queryMode != null  and queryMode != ''">and query_mode = #{queryMode}</if>
        <if test="queryNum != null  and queryNum != ''">and query_num = #{queryNum}</if>
        </where>
        order by create_time DESC
    </select>

    <select id="selectReportQueryLogByLogId" parameterType="Long" resultMap="ReportQueryLogResult">
        <include refid="selectReportQueryLogVo"/>
        where log_id = #{logId} and is_del = 'N'
    </select>

    <insert id="insertReportQueryLog" parameterType="ReportQueryLog" useGeneratedKeys="true" keyProperty="logId">
        insert into report_query_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="reportNumber != null and reportNumber != ''">report_number,</if>
            <if test="queryName != null and queryName != ''">query_name,</if>
            <if test="queryPhone != null and queryPhone != ''">query_phone,</if>
            <if test="companyName != null">company_name,</if>
            <if test="companyPhone != null">company_phone,</if>
            <if test="queryType != null">query_type,</if>
            <if test="queryMode != null">query_mode,</if>
            <if test="queryNum != null">query_num,</if>
            <if test="code != null">code,</if>
            <if test="qrImage != null">qr_image,</if>
            <if test="isSuccess != null">is_success,</if>
            <if test="isDel != null">is_del,</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="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="reportNumber != null and reportNumber != ''">#{reportNumber},</if>
            <if test="queryName != null and queryName != ''">#{queryName},</if>
            <if test="queryPhone != null and queryPhone != ''">#{queryPhone},</if>
            <if test="companyName != null">#{companyName},</if>
            <if test="companyPhone != null">#{companyPhone},</if>
            <if test="queryType != null">#{queryType},</if>
            <if test="queryMode != null">#{queryMode},</if>
            <if test="queryNum != null">#{queryNum},</if>
            <if test="code != null">#{code},</if>
            <if test="qrImage != null">#{qrImage},</if>
            <if test="isSuccess != null">#{isSuccess},</if>
            <if test="isDel != null">#{isDel},</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="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateReportQueryLog" parameterType="ReportQueryLog">
        update report_query_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportNumber != null and reportNumber != ''">report_number = #{reportNumber},</if>
            <if test="queryName != null and queryName != ''">query_name = #{queryName},</if>
            <if test="queryPhone != null and queryPhone != ''">query_phone = #{queryPhone},</if>
            <if test="companyName != null">company_name = #{companyName},</if>
            <if test="companyPhone != null">company_phone = #{companyPhone},</if>
            <if test="queryType != null">query_type = #{queryType},</if>
            <if test="queryMode != null">query_mode = #{queryMode},</if>
            <if test="queryNum != null">query_num = #{queryNum},</if>
            <if test="code != null">code = #{code},</if>
            <if test="qrImage != null">qr_image = #{qrImage},</if>
            <if test="isSuccess != null">is_success = #{isSuccess},</if>
            <if test="isDel != null">is_del = #{isDel},</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="remark != null">remark = #{remark},</if>
        </trim>
        where log_id = #{logId}
    </update>

    <delete id="deleteReportQueryLogByLogId" parameterType="Long">
        delete from report_query_log where log_id = #{logId}
    </delete>

    <delete id="deleteReportQueryLogByLogIds" parameterType="String">
        delete from report_query_log where log_id in
        <foreach item="logId" collection="array" open="(" separator="," close=")">
            #{logId}
        </foreach>
    </delete>


    <select id="selectReportQueryLogCount" parameterType="Date" resultType="int">
        select ifnull(count(1),0) as num from report_query_log
        <where>
            is_del = 'N'
            <if test="today != null">and DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT(#{today},'%Y-%m-%d')</if>
            <if test="startTime != null">and DATE_FORMAT(create_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{startTime},'%Y-%m-%d')</if>
            <if test="endTime != null">and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d')</if>
        </where>
    </select>
</mapper>