<?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.ruoyi.interfaces.mapper.PtServiceLogMapper">
    <resultMap id="BaseResultMap" type="com.ruoyi.interfaces.domain.PtServiceLog">
        <result property="srvMethod" column="SRV_METHOD" jdbcType="VARCHAR"/>
        <result property="msg" column="MSG" jdbcType="VARCHAR"/>
        <result property="id" column="ID" jdbcType="VARCHAR"/>
        <result property="srvId" column="SRV_ID" jdbcType="VARCHAR"/>
        <result property="appId" column="APP_ID" jdbcType="VARCHAR"/>
        <result property="tm" column="TM" jdbcType="TIMESTAMP"/>
        <result property="srvUrl" column="SRV_URL" jdbcType="VARCHAR"/>
        <result property="name" column="NAME" jdbcType="VARCHAR"/>
        <result property="userName" column="USER_NAME" jdbcType="VARCHAR"/>
        <result property="cnt" column="cnt" jdbcType="VARCHAR"/>
        <result property="day" column="day" jdbcType="VARCHAR"/>
        <result property="num" column="num" jdbcType="VARCHAR"/>
        <result property="appName" column="APP_NAME" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
        SRV_METHOD
        ,
		MSG,
		ID,
		SRV_ID,
		APP_ID,
		TM,
		SRV_URL
    </sql>
    <sql id="Blob_Column_List">
        MSG
    </sql>


    <resultMap type="com.ruoyi.interfaces.domain.PtServiceLog" id="ptServiceLogResultMap">
        <result property="id" column="ID"/>
        <result property="srvId" column="SRV_ID"/>
        <result property="appId" column="APP_ID"/>
        <result property="tm" column="TM"/>
        <result property="srvUrl" column="SRV_URL"/>
        <result property="srvMethod" column="SRV_METHOD"/>
        <result property="msg" column="MSG" jdbcType="CLOB"/>
        <result property="execTm" column="EXEC_TM"/>
        <result property="uuid" column="UUID" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="table_columns">
        ID
        ,
            SRV_ID,
            APP_ID,
            TM,
            SRV_URL,
            SRV_METHOD,
            MSG,
            EXEC_TM,
            UUID
    </sql>
    <sql id="entity_properties">
        #{id}
        ,
        #{srvId},
        #{appId},
        #{tm},
        #{srvUrl},
        #{srvMethod},
        #{msg,jdbcType=CLOB},
        #{execTm},
        #{uuid,jdbcType=VARCHAR}
    </sql>

    <!-- 使用like用法：columnName like concat('%',#columnName#,'%') -->
    <sql id="page_where">
        <trim prefix="where" prefixOverrides="and | or ">
            <if test="srvId != null and srvId != ''">and SRV_ID = #{srvId}</if>
            <if test="appId != null and appId != ''">and APP_ID = #{appId}</if>
            <if test="tm != null">and TM = #{tm}</if>
            <if test="srvUrl != null and srvUrl != ''">and SRV_URL = #{srvUrl}</if>
            <if test="srvMethod != null and srvMethod != ''">and SRV_METHOD = #{srvMethod}</if>
            <if test="msg != null and msg != ''">and MSG = #{msg}</if>
            <if test="execTm != null and execTm != ''">and EXEC_TM = #{execTm}</if>
            <if test="uuid != null and uuid != ''">and UUID = #{uuid}</if>
        </trim>
    </sql>

    <select id="get" resultMap="ptServiceLogResultMap" parameterType="String">
        select
        <include refid="table_columns"/>
        from PT_SERVICE_LOG where ID = #{id}
    </select>

    <select id="getBy" resultMap="ptServiceLogResultMap">
        select
        <include refid="table_columns"/>
        from PT_SERVICE_LOG
        <include refid="page_where"/>
    </select>

    <select id="findList" resultMap="ptServiceLogResultMap">
        select
        <include refid="table_columns"/>
        from PT_SERVICE_LOG
        <include refid="page_where"/>
    </select>

    <!--数据列表-->
    <select id="selectAll" parameterType="java.lang.String" resultMap="BaseResultMap">
        <!--select
        <include refid="Base_Column_List" />
        from PT_SERVICE_LOG
        order by TM desc-->

        select psl.*,ps.NAME,pau.USER_NAME
        from PT_SERVICE_LOG psl
        left join PT_SERVICE ps on psl.srv_id = ps.srv_id
        left join PT_APP_USER pau on psl.APP_ID = pau.USER_ID
        order by psl.TM desc

    </select>

    <!--根据主键获取数据-->
    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        ,
        <include refid="Blob_Column_List"/>
        from PT_SERVICE_LOG
        where RID = #{rid,jdbcType=VARCHAR}
    </select>

    <!--根据主键删除数据-->
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
        delete
        from PT_SERVICE_LOG
        where RID = #{rid,jdbcType=VARCHAR}
    </delete>

    <!--根据主键更新数据-->
    <update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.interfaces.domain.PtServiceLog">
        update PT_SERVICE_LOG
        <set>
            <if test="srvId != null">
                SRV_ID = #{srvId,jdbcType=VARCHAR},
            </if>
            <if test="userId != null">
                USER_ID = #{userId,jdbcType=VARCHAR},
            </if>
            <if test="stm != null">
                STM = #{stm,jdbcType=TIMESTAMP},
            </if>
            <if test="etm != null">
                ETM = #{etm,jdbcType=TIMESTAMP},
            </if>
            <if test="err != null">
                ERR = #{err,jdbcType=VARCHAR},
            </if>
            <if test="msg != null">
                MSG = #{msg,jdbcType=CLOB},
            </if>
        </set>
        where RID = #{rid,jdbcType=VARCHAR}
    </update>


    <!-- 一一一一一一一一一一一一按应用统计访问总数一一一一一一一一一一一一 -->
    <!-- 按应用统计访问总数-今天 -->
    <select id="statAllToday" parameterType="java.lang.String" resultMap="BaseResultMap">
        -- select app_id,count(1) cnt from pt_service_log
        -- where tm &gt;= trunc(sysdate) and tm &lt; trunc(sysdate)+1
        -- group by app_id
        -- order by cnt desc
        select t.*, pau.user_name
        from (select app_id, count(1) cnt
              from pt_service_log
              where tm &gt;= trunc(sysdate)
                and tm &lt; trunc(sysdate) + 1
              group by app_id) t
                 left join PT_APP_USER pau on pau.user_id = t.app_id
        order by t.cnt desc
    </select>

    <!-- 最近三天 -->
    <select id="statAppThree" parameterType="java.lang.String" resultMap="BaseResultMap">
        --     select app_id,count(1) cnt from pt_service_log
--     where tm &gt;= trunc(sysdate) - 3
--     group by app_id
--     order by cnt desc
--     select t.* , pau.user_name from
        select t.*, pau.user_name
        from (select app_id, count(1) cnt
              from pt_service_log
              where tm &gt;= trunc(sysdate) - 3
              group by app_id) t
                 left join PT_APP_USER pau on pau.user_id = t.app_id
        order by cnt desc
    </select>

    <!-- 最近一周 -->
    <select id="statAppWeek" parameterType="java.lang.String" resultMap="BaseResultMap">
        --     select app_id,count(1) cnt from pt_service_log
--     where tm &gt;= trunc(sysdate) - 7
--     group by app_id
--     order by cnt desc
        select t.*, pau.user_name
        from (select app_id, count(1) cnt
              from pt_service_log
              where tm &gt;= trunc(sysdate) - 7
              group by app_id) t
                 left join PT_APP_USER pau on pau.user_id = t.app_id
        order by cnt desc
    </select>

    <!-- 按应用统计访问总数-累计 -->
    <select id="statAll" parameterType="java.lang.String" resultMap="BaseResultMap">
        --     select app_id,count(1) cnt from pt_service_log
--     group by app_id
--     order by cnt desc
        select t.*, pau.user_name
        from (select app_id, count(1) cnt
              from pt_service_log
              group by app_id) t
                 left join PT_APP_USER pau on pau.user_id = t.app_id
        order by cnt desc
    </select>

    <!-- 根据应用来按天统计 -->
    <select id="statDayByAppId" parameterType="java.lang.String" resultMap="BaseResultMap">
        select to_char(t.tm, 'YYYY-MM-DD') as day,sum(1) as cnt
        from PT_SERVICE_LOG t
        where app_id = #{appId}
        group by to_char(t.tm, 'YYYY-MM-DD')
    </select>


    <!-- 一一一一一一一一一一一一按服务统计访问总数一一一一一一一一一一一一 -->
    <!-- 按服务统计访问总数-今天 -->
    <select id="statSrvAllToday" parameterType="java.lang.String" resultMap="BaseResultMap">
        --         select srv_id,count(1) cnt from pt_service_log
--         where tm &gt;= trunc(sysdate) and tm &lt; trunc(sysdate)+1
--         group by srv_id order by cnt desc
        select t.*, ps.name
        from (select srv_id, count(1) cnt
              from pt_service_log
              where tm &gt;= trunc(sysdate)
                and tm &lt; trunc(sysdate) + 1
              group by srv_id) t
                 left join PT_SERVICE ps on ps.srv_id = t.srv_id
        order by t.cnt asc
    </select>

    <!-- 最近三天 -->
    <select id="statSrvThree" parameterType="java.lang.String" resultMap="BaseResultMap">
        select t.*, ps.name
        from (select srv_id, count(1) cnt from pt_service_log where tm &gt;= trunc(sysdate) - 3 group by srv_id) t
                 left join PT_SERVICE ps on ps.srv_id = t.srv_id
        order by t.cnt asc
    </select>

    <!-- 最近一周 -->
    <select id="statSrvWeek" parameterType="java.lang.String" resultMap="BaseResultMap">
        select t.*, ps.name
        from (select srv_id, count(1) cnt from pt_service_log where tm &gt;= trunc(sysdate) - 7 group by srv_id) t
                 left join PT_SERVICE ps on ps.srv_id = t.srv_id
        order by t.cnt asc
    </select>

    <!-- 按服务统计访问总数-累计 -->
    <select id="statSrvAll" parameterType="java.lang.String" resultMap="BaseResultMap">
        --         select srv_id,count(1) cnt from pt_service_log
--         group by srv_id order by cnt desc
        select t.*, ps.name
        from (select srv_id, count(1) cnt from pt_service_log group by srv_id) t
                 left join PT_SERVICE ps on ps.srv_id = t.srv_id
        order by t.cnt asc
    </select>

    <!--每天的数据=点击事件 -->
    <select id="statDayBySrvId" parameterType="java.lang.String" resultMap="BaseResultMap">
        select to_char(t.tm, 'YYYY-MM-DD') as day,sum(1) as num
        from PT_SERVICE_LOG t
        where srv_id = #{srvId}
        group by to_char(t.tm, 'YYYY-MM-DD')
        order by day asc
    </select>


    <select id="statMonthByAppId" parameterType="java.lang.String" resultMap="BaseResultMap">
        select to_char(t.tm, 'YYYY-MM') as day,sum(1) as cnt
        from PT_SERVICE_LOG t
        where app_id = #{appId}
        group by to_char(t.tm, 'YYYY-MM')
    </select>

    <select id="statMonthBySrvId" parameterType="java.lang.String" resultMap="BaseResultMap">
        select to_char(t.tm, 'YYYY-MM') as day,sum(1) as cnt
        from PT_SERVICE_LOG t
        where srv_id = #{srvId}
        group by to_char(t.tm, 'YYYY-MM')
    </select>

    <!--根据条件获取数据-->
    <select id="selectByFactor" parameterType="com.ruoyi.interfaces.domain.PtServiceLog" resultMap="BaseResultMap">
        SELECT
        PSL.*, PS.NAME, PAU.USER_NAME, AP.APP_NAME
        FROM PT_SERVICE_LOG PSL
        LEFT JOIN PT_SERVICE PS ON PSL.SRV_ID = PS.SRV_ID
        LEFT JOIN PT_APP AP ON AP.APP_ID = PSL.APP_ID
        LEFT JOIN PT_APP_USER PAU ON AP.USER_ID = PAU.USER_ID
        <where>
            <if test="name != null and name !=''">
                and ps.NAME like CONCAT(CONCAT('%', #{name}), '%')
            </if>
            <if test="userName != null and userName !=''">
                and pau.USER_NAME like CONCAT(CONCAT('%', #{userName}), '%')
            </if>
            <if test="tm != null">
                and psl.TM &gt;= #{tm}
            </if>
            <if test="sttm != null">
                and psl.TM &gt;= #{sttm}
            </if>
            <if test="entm != null">
                and psl.TM &lt;= #{entm}
            </if>
        </where>
        ORDER BY PSL.TM DESC
    </select>


</mapper>
