Newer
Older
stockTray / EastLineServer / src / main / resources / mybatis / IndexMapper.xml
bello on 12 Aug 2020 2 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="me.bello.logsys.dao.IndexDao" >

    <!--首页查询用户统计数据-->
    <select id="queryIndexUser" resultType="HashMap">

        SELECT
            *
        FROM
        (
            (
                SELECT
                    COUNT( 1 ) AS allUser
                FROM
                (
                    SELECT
                        DISTINCT ( userId )
                    FROM
                        t_app_log
                    WHERE
                        appId = #{appId}
                        AND userId != ''
                        AND userId IS NOT NULL
                ) t1
            ) a1,

            (
                SELECT
                    COUNT( 1 ) AS todayUser
                FROM
                (
                    SELECT
                        DISTINCT( userId )
                    FROM
                        t_app_log
                    WHERE
                        appId = #{appId}
                        AND userId != ''
                        AND userId IS NOT NULL
                        AND DATE( logTime ) &gt;= #{startDate}
                        AND DATE( logTime ) &lt;= #{endDate}
                ) t2
            ) a2
        );
    </select>


    <!--查询一段时间内的活跃量-->
    <select id="queryDateRangerAction" resultType="HashMap">
        select `date`, max(`sum`) as `sum` from
        (
           SELECT @cdate := date_add(@cdate,interval - 1 day) `date` , 0 as `sum`
           from (SELECT @cdate :=date_add(CURDATE(),interval + 1 day) from t_app_log) t1
           where @cdate > #{startDate}

           union all

           select DATE_FORMAT(logTime,'%Y-%m-%d') as `date`,count(DISTINCT userId)
           from t_app_log
           WHERE appId = #{appId}
            and logTime is not NULL
						and date(logTime) > #{startDate}
					 group by `date`

        ) _tmpAllTable

        group by `date`
		ORDER BY `date`;

    </select>

</mapper>