SearchLogMapper.xml 2.62 KB
<?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.web.controller.business.mapper.SearchLogMapper">
    
    <resultMap type="SearchLog" id="SearchLogResult">
        <result property="id"    column="id"    />
        <result property="searchParams"    column="search_params"    />
        <result property="type"    column="type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectSearchLogVo">
        select id, search_params, type, create_by, create_time from search_log
    </sql>

    <select id="selectSearchLogList" parameterType="SearchLog" resultMap="SearchLogResult">
        <include refid="selectSearchLogVo"/>
        <where>  
            <if test="searchParams != null  and searchParams != ''"> and search_params = #{searchParams}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
    </select>

    <select id="getSearchLogs" parameterType="SearchLog" resultType="SearchLog" >
        select
            a.createTime,
            a.searchParams ,
            a.jsonProperty
        from
            (
                select
                    distinct on(search_params ->> ${jsonProperty}) search_params AS searchParams,
                    search_params ->> ${jsonProperty} as jsonProperty,
                    create_time AS createTime
                from
                    credit_nx.search_log
                where
                    `type` = #{type}
                  and create_by = #{createBy}
                order by search_params ->> ${jsonProperty}  desc )  as a
        order by
            a.createTime desc
    </select>


    <insert id="insertSearchLog" parameterType="SearchLog">
        insert into search_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="searchParams != null">search_params,</if>
            <if test="type != null">type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="searchParams != null">#{searchParams},</if>
            <if test="type != null">#{type},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>


</mapper>