05988c4325
- Replace hardcoded public namespace with NACOS_NAMESPACE - Document nacos init container troubleshooting for 1Panel deploy
73 lines
2.6 KiB
XML
73 lines
2.6 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.nuaa.video.recommend.mapper.RecommendUserBehaviorMapper">
|
|
|
|
<!-- 获取用户行为记录的视频ID列表 -->
|
|
<select id="selectUserBehaviorVideoIds" resultType="java.lang.Long">
|
|
SELECT DISTINCT video_id
|
|
FROM recommend_user_behavior
|
|
WHERE user_id = #{userId}
|
|
<if test="behaviorTypes != null and behaviorTypes.size > 0">
|
|
AND behavior_type IN
|
|
<foreach collection="behaviorTypes" item="type" open="(" separator="," close=")">
|
|
#{type}
|
|
</foreach>
|
|
</if>
|
|
ORDER BY create_time DESC
|
|
LIMIT #{limit}
|
|
</select>
|
|
|
|
<!-- 统计用户分类行为数量 -->
|
|
<select id="countUserCategoryBehaviors" resultType="java.util.Map">
|
|
SELECT c.category_id as categoryId, COUNT(1) as count
|
|
FROM recommend_user_behavior b
|
|
JOIN video_content.content_video v ON b.video_id = v.id
|
|
JOIN video_content.content_category c ON v.category_id = c.id
|
|
WHERE b.user_id = #{userId}
|
|
<if test="startTime != null">
|
|
AND b.create_time >= #{startTime}
|
|
</if>
|
|
GROUP BY c.category_id
|
|
</select>
|
|
|
|
<!-- 统计用户标签行为数量 -->
|
|
<select id="countUserTagBehaviors" resultType="java.util.Map">
|
|
SELECT vt.tag_id as tagId, COUNT(1) as count
|
|
FROM recommend_user_behavior b
|
|
JOIN video_content.content_video_tag vt ON b.video_id = vt.video_id
|
|
WHERE b.user_id = #{userId}
|
|
<if test="startTime != null">
|
|
AND b.create_time >= #{startTime}
|
|
</if>
|
|
GROUP BY vt.tag_id
|
|
</select>
|
|
|
|
<!-- 获取热门视频 -->
|
|
<select id="selectHotVideos" resultType="java.util.Map">
|
|
SELECT
|
|
video_id as videoId,
|
|
SUM(
|
|
CASE
|
|
<foreach collection="weights" index="behaviorType" item="weight">
|
|
WHEN behavior_type = #{behaviorType} THEN behavior_weight * #{weight}
|
|
</foreach>
|
|
ELSE behavior_weight
|
|
END
|
|
) as score
|
|
FROM recommend_user_behavior
|
|
WHERE 1 = 1
|
|
<if test="startTime != null">
|
|
AND create_time >= #{startTime}
|
|
</if>
|
|
<if test="behaviorTypes != null and behaviorTypes.size > 0">
|
|
AND behavior_type IN
|
|
<foreach collection="behaviorTypes" item="type" open="(" separator="," close=")">
|
|
#{type}
|
|
</foreach>
|
|
</if>
|
|
GROUP BY video_id
|
|
ORDER BY score DESC
|
|
LIMIT #{limit}
|
|
</select>
|
|
</mapper>
|