<?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.flossom.common.core.mapper.SiteLogMapper">
    
    <resultMap type="SiteLog" id="SiteLogResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="siteId"    column="site_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectSiteLogVo">
        select id, user_id, site_id, create_by, create_time from site_log
    </sql>

    <select id="selectSiteLogList" parameterType="SiteLog" resultMap="SiteLogResult">
        <include refid="selectSiteLogVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="siteId != null "> and site_id = #{siteId}</if>
            <if test="params != null and params.beginTime != null"> and create_time &gt;= #{params.beginTime}</if>
            <if test="params != null and params.endTime != null"> and create_time &lt;= #{params.endTime}</if>
        </where>
    </select>
    
    <select id="selectSiteLogById" parameterType="Long" resultMap="SiteLogResult">
        <include refid="selectSiteLogVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSiteLog" parameterType="SiteLog" useGeneratedKeys="true" keyProperty="id">
        insert into site_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="siteId != null">site_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="siteId != null">#{siteId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateSiteLog" parameterType="SiteLog">
        update site_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="siteId != null">site_id = #{siteId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSiteLogById" parameterType="Long">
        delete from site_log where id = #{id}
    </delete>

    <delete id="deleteBySiteId" parameterType="Long">
        delete from site_log where site_id = #{siteId}
    </delete>

    <delete id="deleteSiteLogByIds" parameterType="String">
        delete from site_log where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>