SqlOperateLogsMapper.xml 3.29 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.monitor.mysql.mapper.SqlOperateLogsMapper" >
    <resultMap id="BaseResultMap" type="com.model.SqlOperateLogs" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <id column="user_id" property="userId" jdbcType="INTEGER" />
        <result column="user_name" property="userName" jdbcType="VARCHAR" />
        <result column="datasource_info" property="dataSourceInfo" jdbcType="VARCHAR" />
        <result column="db_info" property="dbInfo" jdbcType="VARCHAR" />
        <result column="datasource_user" property="dataSourceUser" jdbcType="VARCHAR" />
        <result column="datasource_pwd" property="dataSourcePwd" jdbcType="VARCHAR" />
        <result column="query_content" property="queryContent" jdbcType="VARCHAR" />
        <result column="query_result" property="queryResult" jdbcType="VARCHAR" />
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    </resultMap>

    <sql id="Base_Column_List" >
        id, user_id,user_name,datasource_info,datasource_user, datasource_pwd, query_content,query_result ,create_time
    </sql>

    <insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="com.model.SqlOperateLogs" >
        insert into sql_operate_logs
        (
        user_id,user_name,datasource_info,db_info,datasource_user, datasource_pwd, query_content,query_result ,create_time
        )
        values
        (#{userId,jdbcType=INTEGER},
        #{userName,jdbcType=VARCHAR},
        #{dataSourceInfo,jdbcType=VARCHAR},
        #{dbInfo,jdbcType=VARCHAR},
        #{dataSourceUser,jdbcType=VARCHAR},
        #{dataSourcePwd,jdbcType=VARCHAR},
        #{queryContent,jdbcType=VARCHAR},
        #{queryResult,jdbcType=VARCHAR},
        now())
    </insert>

   <select id="selectCount" resultType="java.lang.Integer">
      select count(*) from sql_operate_logs
      where 1=1
      <if test="params.userName != null &amp;&amp; params.userName != ''">
          and  user_name like CONCAT('%',#{params.userName,jdbcType=VARCHAR},'%')
      </if>
      <if test="params.beginTime !=null &amp;&amp; params.beginTime !=''">
          and  create_time &gt;= CONCAT(#{params.beginTime,jdbcType=TIMESTAMP},' 00:00:00')
      </if>
      <if test="params.endTime !=null &amp;&amp; params.endTime !=''">
           and  create_time &lt;= CONCAT(#{params.endTime,jdbcType=TIMESTAMP},' 23:59:59')
      </if>
       order by create_time desc
   </select>

    <select id="selectPageByParams" resultMap="BaseResultMap">
        select * from sql_operate_logs
        where 1=1
        <if test="params.userName != null &amp;&amp; params.userName != ''">
            and user_name like CONCAT('%',#{params.userName,jdbcType=VARCHAR},'%')
        </if>
        <if test="params.beginTime !=null &amp;&amp; params.beginTime !=''">
            and  create_time &gt;= CONCAT(#{params.beginTime,jdbcType=TIMESTAMP},' 00:00:00')
        </if>
        <if test="params.endTime !=null &amp;&amp; params.endTime !=''">
            and  create_time &lt;= CONCAT(#{params.endTime,jdbcType=TIMESTAMP},' 23:59:59')
        </if>
        order by create_time desc
        limit #{startIndex},#{pageSize}
    </select>
</mapper>