<?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.kexue.skills.mapper.SysLogMapper">

    <resultMap type="com.kexue.skills.entity.SysLog" id="SysLogMap">
        <result property="logId" column="LOG_ID" jdbcType="INTEGER"/>
        <result property="userId" column="USER_ID" jdbcType="VARCHAR"/>
        <result property="userName" column="USER_NAME" jdbcType="VARCHAR"/>
        <result property="logType" column="LOG_TYPE" jdbcType="VARCHAR"/>
        <result property="logContent" column="LOG_CONTENT" jdbcType="VARCHAR"/>
        <result property="serverIp" column="SERVER_IP" jdbcType="VARCHAR"/>
        <result property="clientIp" column="CLIENT_IP" jdbcType="VARCHAR"/>
        <result property="logTime" column="LOG_TIME" jdbcType="VARCHAR"/>
        <result property="note" column="NOTE" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="SysLogMap">
        select
          LOG_ID, USER_ID, USER_NAME, LOG_TYPE, LOG_CONTENT, SERVER_IP, CLIENT_IP, LOG_TIME, NOTE
        from sys_log
        where LOG_ID = #{logId}
    </select>

    <!--查询指定行数据-->
    <select id="getPageList" resultMap="SysLogMap">
        select
          LOG_ID, USER_ID, USER_NAME, LOG_TYPE, LOG_CONTENT, SERVER_IP, CLIENT_IP, LOG_TIME, NOTE
        from sys_log
        <where>
            <if test="logId != null">
                and LOG_ID = #{logId}
            </if>
            <if test="userId != null and userId != ''">
                and USER_ID = #{userId}
            </if>
            <if test="userName != null and userName != ''">
                and USER_NAME = #{userName}
            </if>
            <if test="logType != null and logType != ''">
                and LOG_TYPE = #{logType}
            </if>
            <if test="logContent != null and logContent != ''">
                and LOG_CONTENT = #{logContent}
            </if>
            <if test="serverIp != null and serverIp != ''">
                and SERVER_IP = #{serverIp}
            </if>
            <if test="clientIp != null and clientIp != ''">
                and CLIENT_IP = #{clientIp}
            </if>
            <if test="logTime != null and logTime != ''">
                and LOG_TIME = #{logTime}
            </if>
            <if test="note != null and note != ''">
                and NOTE = #{note}
            </if>
        </where>
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="SysLogMap">
        select
          LOG_ID, USER_ID, USER_NAME, LOG_TYPE, LOG_CONTENT, SERVER_IP, CLIENT_IP, LOG_TIME, NOTE
        from sys_log
        limit #{offset}, #{limit}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="SysLogMap">
        select
          LOG_ID, USER_ID, USER_NAME, LOG_TYPE, LOG_CONTENT, SERVER_IP, CLIENT_IP, LOG_TIME, NOTE
        from sys_log
        <where>
            <if test="logId != null">
                and LOG_ID = #{logId}
            </if>
            <if test="userId != null and userId != ''">
                and USER_ID = #{userId}
            </if>
            <if test="userName != null and userName != ''">
                and USER_NAME = #{userName}
            </if>
            <if test="logType != null and logType != ''">
                and LOG_TYPE = #{logType}
            </if>
            <if test="logContent != null and logContent != ''">
                and LOG_CONTENT = #{logContent}
            </if>
            <if test="serverIp != null and serverIp != ''">
                and SERVER_IP = #{serverIp}
            </if>
            <if test="clientIp != null and clientIp != ''">
                and CLIENT_IP = #{clientIp}
            </if>
            <if test="logTime != null and logTime != ''">
                and LOG_TIME = #{logTime}
            </if>
            <if test="note != null and note != ''">
                and NOTE = #{note}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="logId" useGeneratedKeys="true">
        insert into sys_log(USER_ID, USER_NAME, LOG_TYPE, LOG_CONTENT, SERVER_IP, CLIENT_IP, LOG_TIME, NOTE)
        values (#{userId}, #{userName}, #{logType}, #{logContent}, #{serverIp}, #{clientIp}, #{logTime}, #{note})
    </insert>
    
    
    <insert id="insertBatch" parameterType="java.util.List">
    INSERT INTO sys_log (
        <!-- 动态生成列名 -->
        <foreach collection="list" item="item" index="index" open="" close="" separator="" >
            <if test="index == 0">
                <foreach collection="tableInfo.fullColumn" item="column" open="" close="" separator=",">
                    ${column.name}
                </foreach>
            </if>
        </foreach>
    ) VALUES
    <!-- 动态生成值 -->
    <foreach collection="list" item="item" index="index" open="" close="" separator=",">
        (
        <foreach collection="tableInfo.fullColumn" item="column" open="" close="" separator=",">
            #{item.${column.property}}
        </foreach>
        )
    </foreach>
</insert>

    <!--通过主键修改数据-->
    <update id="update">
        update sys_log
        <set>
            <if test="userId != null and userId != ''">
                USER_ID = #{userId},
            </if>
            <if test="userName != null and userName != ''">
                USER_NAME = #{userName},
            </if>
            <if test="logType != null and logType != ''">
                LOG_TYPE = #{logType},
            </if>
            <if test="logContent != null and logContent != ''">
                LOG_CONTENT = #{logContent},
            </if>
            <if test="serverIp != null and serverIp != ''">
                SERVER_IP = #{serverIp},
            </if>
            <if test="clientIp != null and clientIp != ''">
                CLIENT_IP = #{clientIp},
            </if>
            <if test="logTime != null and logTime != ''">
                LOG_TIME = #{logTime},
            </if>
            <if test="note != null and note != ''">
                NOTE = #{note},
            </if>
        </set>
        where LOG_ID = #{logId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from sys_log where LOG_ID = #{logId}
    </delete>

</mapper>
