You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
5.9 KiB
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.ruoyi.portal.mapper.HwAnalyticsMapper">
<resultMap id="HwWebVisitDailyResult" type="com.ruoyi.portal.domain.HwWebVisitDaily">
<result property="statDate" column="stat_date"/>
<result property="pv" column="pv"/>
<result property="uv" column="uv"/>
<result property="ipUv" column="ip_uv"/>
<result property="avgStayMs" column="avg_stay_ms"/>
<result property="bounceRate" column="bounce_rate"/>
<result property="searchCount" column="search_count"/>
<result property="downloadCount" column="download_count"/>
<result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/>
</resultMap>
<insert id="insertVisitEvent" parameterType="com.ruoyi.portal.domain.HwWebVisitEvent" useGeneratedKeys="true" keyProperty="id">
INSERT INTO hw_web_visit_event (
event_type, visitor_id, session_id, path, referrer, utm_source, utm_medium, utm_campaign,
keyword, ip_hash, ua, device, browser, os, stay_ms, event_time, created_at
) VALUES (
#{eventType}, #{visitorId}, #{sessionId}, #{path}, #{referrer}, #{utmSource}, #{utmMedium}, #{utmCampaign},
#{keyword}, #{ipHash}, #{ua}, #{device}, #{browser}, #{os}, #{stayMs}, #{eventTime}, NOW()
)
</insert>
<select id="countEventByType" resultType="java.lang.Long">
SELECT COUNT(1)
FROM hw_web_visit_event
WHERE DATE(event_time) = #{statDate}
AND event_type = #{eventType}
</select>
<select id="countDistinctVisitor" resultType="java.lang.Long">
SELECT COUNT(DISTINCT visitor_id)
FROM hw_web_visit_event
WHERE DATE(event_time) = #{statDate}
AND event_type = 'page_view'
AND visitor_id IS NOT NULL
AND visitor_id != ''
</select>
<select id="countDistinctIp" resultType="java.lang.Long">
SELECT COUNT(DISTINCT ip_hash)
FROM hw_web_visit_event
WHERE DATE(event_time) = #{statDate}
AND event_type = 'page_view'
AND ip_hash IS NOT NULL
AND ip_hash != ''
</select>
<select id="avgStayMs" resultType="java.lang.Long">
SELECT COALESCE(ROUND(AVG(stay_ms)), 0)
FROM hw_web_visit_event
WHERE DATE(event_time) = #{statDate}
AND event_type = 'page_leave'
AND stay_ms IS NOT NULL
AND stay_ms >= 0
</select>
<select id="countDistinctSessions" resultType="java.lang.Long">
SELECT COUNT(DISTINCT session_id)
FROM hw_web_visit_event
WHERE DATE(event_time) = #{statDate}
AND event_type = 'page_view'
AND session_id IS NOT NULL
AND session_id != ''
</select>
<select id="countSinglePageSessions" resultType="java.lang.Long">
SELECT COUNT(1)
FROM (
SELECT session_id
FROM hw_web_visit_event
WHERE DATE(event_time) = #{statDate}
AND event_type = 'page_view'
AND session_id IS NOT NULL
AND session_id != ''
GROUP BY session_id
HAVING COUNT(1) = 1
) t
</select>
<select id="selectTopEntryPages" resultType="com.ruoyi.portal.domain.dto.AnalyticsRankItemDTO">
SELECT IFNULL(e.path, '/') AS name, COUNT(1) AS value
FROM hw_web_visit_event e
INNER JOIN (
SELECT session_id, MIN(event_time) AS min_event_time
FROM hw_web_visit_event
WHERE DATE(event_time) = #{statDate}
AND event_type = 'page_view'
AND session_id IS NOT NULL
AND session_id != ''
GROUP BY session_id
) s ON s.session_id = e.session_id AND s.min_event_time = e.event_time
WHERE DATE(e.event_time) = #{statDate}
AND e.event_type = 'page_view'
GROUP BY e.path
ORDER BY value DESC
LIMIT #{limit}
</select>
<select id="selectTopHotPages" resultType="com.ruoyi.portal.domain.dto.AnalyticsRankItemDTO">
SELECT IFNULL(path, '/') AS name, COUNT(1) AS value
FROM hw_web_visit_event
WHERE DATE(event_time) = #{statDate}
AND event_type = 'page_view'
GROUP BY path
ORDER BY value DESC
LIMIT #{limit}
</select>
<select id="selectTopKeywords" resultType="com.ruoyi.portal.domain.dto.AnalyticsRankItemDTO">
SELECT keyword AS name, COUNT(1) AS value
FROM hw_web_visit_event
WHERE DATE(event_time) = #{statDate}
AND event_type = 'search_submit'
AND keyword IS NOT NULL
AND keyword != ''
GROUP BY keyword
ORDER BY value DESC
LIMIT #{limit}
</select>
<insert id="upsertDaily" parameterType="com.ruoyi.portal.domain.HwWebVisitDaily">
INSERT INTO hw_web_visit_daily (
stat_date, pv, uv, ip_uv, avg_stay_ms, bounce_rate, search_count, download_count, created_at, updated_at
) VALUES (
#{statDate}, #{pv}, #{uv}, #{ipUv}, #{avgStayMs}, #{bounceRate}, #{searchCount}, #{downloadCount}, NOW(), NOW()
)
ON DUPLICATE KEY UPDATE
pv = VALUES(pv),
uv = VALUES(uv),
ip_uv = VALUES(ip_uv),
avg_stay_ms = VALUES(avg_stay_ms),
bounce_rate = VALUES(bounce_rate),
search_count = VALUES(search_count),
download_count = VALUES(download_count),
updated_at = NOW()
</insert>
<select id="selectDailyByDate" resultMap="HwWebVisitDailyResult">
SELECT stat_date, pv, uv, ip_uv, avg_stay_ms, bounce_rate, search_count, download_count, created_at, updated_at
FROM hw_web_visit_daily
WHERE stat_date = #{statDate}
</select>
</mapper>