mapper1.xml

<?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.paic.dbaudit.dao.prd.MapperSaMysqlAuditDetailPrgDao">

    <resultMap id="saMysqlAuditDetailStg" type="com.paic.dbaudit.bean.SaMysqlAuditDetailDO">
        <result property="auditId"         column="audit_id"/>        
        <result property="instanceName"    column="instance_name"/>   
        <result property="queryId"         column="query_id"/>        
        <result property="counts"          column="counts"/>          
        <result property="queryTime"       column="query_time"/>      
        <result property="queryTotalTime"  column="query_total_time"/>
        <result property="lockTime"        column="lock_time"/>       
        <result property="lockTotalTime"   column="lock_total_time"/> 
        <result property="logRows"         column="log_rows"/>        
        <result property="totalRows"       column="total_rows"/>      
        <result property="logUser"         column="log_user"/>        
        <result property="logHost"         column="log_host"/>        
        <result property="sqlText"         column="sql_text"/>        
        <result property="createTime"      column="create_time"/> 
    </resultMap>

    <select id="getSAMySqlResult"  resultMap="saMysqlAuditDetailStg">
        SELECT *
          FROM (SELECT A.*, ROWNUM RN
                  FROM (
                                select instance_name, query_id, log_user, 
                                        max(audit_id) audit_id,
                                        sum(counts)  counts,
                                        max(query_time) query_time,
                                        sum(query_total_time)  query_total_time,
                                        sum(query_total_time)/sum(counts) avgQueryTime,
                                        max(sql_text) sql_text                              
                                from SA_MYSQL_AUDIT_DETAIL
                                where  1 = 1
                                    <choose>
                                        <when test="saDo.instanceName != null and saDo.instanceName != ''">
                                            and instance_name = #{saDo.instanceName,jdbcType = VARCHAR}
                                        </when>
                                        <otherwise>
                                            and instance_name in (
                                                       select db_name 
                                                       from sa_mysql_dep_db
                                                       where  phase = '4' 
                                                     <if test="saDo.teamId != null and saDo.teamId != ''">
                                                        and team_id = #{saDo.teamId,jdbcType = VARCHAR}
                                                    </if>
                                                    <if test="saDo.deptId != null and saDo.deptId != ''">
                                                        and dep_id = #{saDo.deptId,jdbcType = VARCHAR}
                                                    </if>
                                           )
                                        </otherwise>
                                    </choose>
                                       <![CDATA[
                                           and create_time >= to_date(#{saDo.beginTime, jdbcType = VARCHAR}, 'yyyymmddHH24:MI:SS')
                                           and create_time < to_date(#{saDo.endTime, jdbcType = VARCHAR}, 'yyyymmddHH24:MI:SS') 
                                       ]]> 
                               group by instance_name, query_id, log_user
                               order by query_total_time desc ,avgQueryTime desc
                          ) A
        <![CDATA[
                 where ROWNUM <= #{endLine} )
         WHERE RN >= #{startLine}
        ]]>   
    </select>

    <select id="getSAMySqlResultCount"  resultType="java.lang.Integer">
        select count(*) from 
        (
            select 1
            from SA_MYSQL_AUDIT_DETAIL
            where 1 = 1
                <choose>
                    <when test="saDo.instanceName != null and saDo.instanceName != ''">
                        and instance_name = #{saDo.instanceName,jdbcType = VARCHAR}
                    </when>
                    <otherwise>
                        and instance_name in (
                                   select db_name 
                                   from sa_mysql_dep_db
                                   where phase = '4' 
                                <if test="saDo.teamId != null and saDo.teamId != ''">
                                    and team_id = #{saDo.teamId,jdbcType = VARCHAR}
                                </if>
                                <if test="saDo.deptId != null and saDo.deptId != ''">
                                    and dep_id = #{saDo.deptId,jdbcType = VARCHAR}
                                </if>
                       )
                    </otherwise>
                </choose>
                <![CDATA[
                  and create_time >= to_date(#{saDo.beginTime, jdbcType = VARCHAR}, 'yyyymmddHH24:MI:SS')
                  and create_time < to_date(#{saDo.endTime, jdbcType = VARCHAR}, 'yyyymmddHH24:MI:SS') 
                 ]]> 
             group by instance_name, query_id, log_user
        )
    </select>

    <select id="getSAMySqlText"  resultMap="saMysqlAuditDetailStg">
        select * from
            SA_MYSQL_AUDIT_DETAIL
        where  1 = 1 
            and audit_id = #{saDo.auditId,jdbcType = NUMERIC}
            and query_id = #{saDo.queryId,jdbcType = VARCHAR}
    </select>

    <select id="getDBNames4MySQL"  resultType="string">
        select 
            db_name 
        from 
            sa_mysql_dep_db 
        where  phase = '4' 
            <if test="teamId != null and teamId != ''">
                and team_id = #{teamId, jdbcType = NUMERIC} 
            </if>
            <if test="dep_id != null and dep_id != ''">
                and dep_id = #{dep_id,jdbcType = NUMERIC}
            </if>
            order by  db_name
    </select>

</mapper>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章