<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.sys.dao.SysLogDAO">
    <resultMap id="SysLogMap" type="com.jpsoft.shinestar.modules.sys.entity.SysLog">
        <id property="id" column="id_"/>
        <result property="remoteIp" column="remote_ip"/>
        <result property="url" column="url_"/>
        <result property="data" column="data_"/>
        <result property="userId" column="user_id"/>
        <result property="createTime" column="create_time"/>
        <result property="remark" column="remark_"/>
        <result property="elapse" column="elapse_"/>
        <result property="pointcut" column="pointcut_"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.sys.entity.SysLog">
        <selectKey resultType="long" keyColumn="id_" keyProperty="id">
            SELECT LAST_INSERT_ID() AS id_
        </selectKey>
        <![CDATA[
		insert into sys_log
	    (remote_ip,url_,data_,user_id,create_time,remark_,elapse_,pointcut_)
		values
		(
            #{remoteIp,jdbcType=VARCHAR}
            ,#{url,jdbcType=VARCHAR}
            ,#{data,jdbcType=VARCHAR}
            ,#{userId,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{remark,jdbcType=VARCHAR}
            ,#{elapse,jdbcType=NUMERIC}
            ,#{pointcut,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from sys_log where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.sys.entity.SysLog">
        update sys_log
        <set>
            <if test="remoteIp!=null">
                remote_ip=#{remoteIp,jdbcType=VARCHAR},
            </if>
            <if test="url!=null">
                url_=#{url,jdbcType=VARCHAR},
            </if>
            <if test="data!=null">
                data_=#{data,jdbcType=VARCHAR},
            </if>
            <if test="userId!=null">
                user_id=#{userId,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="SysLogMap">
        select * from sys_log where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from sys_log where id_=#{0}
    </select>
    <select id="list" resultMap="SysLogMap">
        select * from sys_log
    </select>
    <select id="search" parameterType="hashmap" resultMap="SysLogMap">
        <![CDATA[
			select * from sys_log
		]]>
        <where>
            <if test="searchParams.userId != null">
                and user_id = #{searchParams.userId}
            </if>
            <if test="searchParams.remoteIP != null">
                and remote_ip like #{searchParams.remoteIP}
            </if>
            <if test="searchParams.url != null">
                and url_ like #{searchParams.url}
            </if>
            <if test="searchParams.pointcut != null">
                and pointcut_ like #{searchParams.pointcut}
            </if>
            <if test="searchParams.startTime != null">
                and create_time >= #{searchParams.startTime}
            </if>
            <if test="searchParams.endTime != null">
                <![CDATA[
                    and create_time <= #{searchParams.endTime}
                ]]>
            </if>
            <if test="searchParams.elapseMin != null">
                and elapse_ >= #{searchParams.elapseMin}
            </if>
            <if test="searchParams.elapseMax != null">
                <![CDATA[
                    and elapse_ <= #{searchParams.elapseMax}
                ]]>
            </if>
            <if test="searchParams.remark != null">
                and remark_ like #{searchParams.remark}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
</mapper>