Files
FrameTour-BE/src/main/resources/mapper/VideoReviewMapper.xml
Jerry Yan ee1eb8cde9 feat(video): 添加视频时长和任务参数字段支持
- 在AdminVideoReviewLogRespDTO和VideoReviewRespDTO中新增duration和taskParams字段
- 添加BigDecimal类型导入用于视频时长数据
- 更新VideoReviewMapper.xml映射文件中的结果映射配置
- 新增数据库关联查询以获取视频时长和任务参数信息
- 完善数据传输对象的注释文档说明
2026-01-27 21:48:19 +08:00

322 lines
12 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.ycwl.basic.mapper.VideoReviewMapper">
<!-- 结果映射 -->
<resultMap id="VideoReviewRespMap" type="com.ycwl.basic.model.pc.videoreview.dto.VideoReviewRespDTO">
<id property="id" column="id"/>
<result property="videoId" column="video_id"/>
<result property="videoUrl" column="video_url"/>
<result property="duration" column="duration"/>
<result property="taskParams" column="task_params"/>
<result property="templateId" column="template_id"/>
<result property="templateName" column="template_name"/>
<result property="scenicId" column="scenic_id"/>
<result property="scenicName" column="scenic_name"/>
<result property="creator" column="creator"/>
<result property="creatorName" column="creator_name"/>
<result property="rating" column="rating"/>
<result property="content" column="content"/>
<result property="problemDeviceIds" column="problem_device_ids"
typeHandler="com.ycwl.basic.handler.LongListTypeHandler"/>
<result property="problemTags" column="problem_tags"
typeHandler="com.ycwl.basic.handler.StringListTypeHandler"/>
<result property="source" column="source"/>
<result property="sourceId" column="source_id"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<!-- 分页查询评价列表 -->
<select id="selectReviewList" parameterType="com.ycwl.basic.model.pc.videoreview.dto.VideoReviewListReqDTO"
resultMap="VideoReviewRespMap">
SELECT
vr.id,
vr.video_id,
vr.scenic_id,
vr.creator,
vr.rating,
vr.content,
vr.problem_device_ids,
vr.problem_tags,
vr.source,
vr.source_id,
vr.create_time,
vr.update_time,
v.video_url,
v.duration,
v.template_id,
tk.task_params,
t.name AS template_name,
s.name AS scenic_name,
u.name AS creator_name
FROM video_review vr
LEFT JOIN video v ON vr.video_id = v.id
LEFT JOIN task tk ON v.task_id = tk.id
LEFT JOIN template t ON v.template_id = t.id
LEFT JOIN scenic s ON vr.scenic_id = s.id
LEFT JOIN admin_user u ON vr.creator = u.id
<where>
<if test="videoId != null">
AND vr.video_id = #{videoId}
</if>
<if test="scenicId != null">
AND vr.scenic_id = #{scenicId}
</if>
<if test="creator != null">
AND vr.creator = #{creator}
</if>
<if test="rating != null">
AND vr.rating = #{rating}
</if>
<if test="minRating != null">
AND vr.rating &gt;= #{minRating}
</if>
<if test="maxRating != null">
AND vr.rating &lt;= #{maxRating}
</if>
<if test="startTime != null and startTime != ''">
AND vr.create_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND vr.create_time &lt;= #{endTime}
</if>
<if test="keyword != null and keyword != ''">
AND vr.content LIKE CONCAT('%', #{keyword}, '%')
</if>
<if test="problemDeviceId != null">
AND JSON_CONTAINS(vr.problem_device_ids, CAST(#{problemDeviceId} AS CHAR), '$')
</if>
<if test="problemTag != null and problemTag != ''">
AND JSON_CONTAINS(vr.problem_tags, JSON_QUOTE(#{problemTag}), '$')
</if>
<if test="source != null and source != ''">
AND vr.source = #{source}
</if>
</where>
ORDER BY
<choose>
<when test="orderBy == 'rating'">
vr.rating
</when>
<when test="orderBy == 'update_time'">
vr.update_time
</when>
<otherwise>
vr.create_time
</otherwise>
</choose>
<choose>
<when test="orderDirection == 'ASC'">
ASC
</when>
<otherwise>
DESC
</otherwise>
</choose>
</select>
<!-- 统计总评价数 -->
<select id="countTotal" resultType="java.lang.Long">
SELECT COUNT(*) FROM video_review
</select>
<!-- 计算平均评分 -->
<select id="calculateAverageRating" resultType="java.lang.Double">
SELECT AVG(rating) FROM video_review
</select>
<!-- 统计评分分布 -->
<select id="countRatingDistribution" resultType="java.util.Map">
SELECT
rating AS ratingValue,
COUNT(*) AS count
FROM video_review
GROUP BY rating
ORDER BY rating
</select>
<!-- 统计最近N天的评价趋势 -->
<select id="countRecentTrend" resultType="java.util.Map">
SELECT
DATE_FORMAT(create_time, '%Y-%m-%d') AS dateStr,
COUNT(*) AS count
FROM video_review
WHERE create_time &gt;= DATE_SUB(CURDATE(), INTERVAL #{days} DAY)
GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')
ORDER BY dateStr
</select>
<!-- 统计景区评价排行 -->
<select id="countScenicRank" resultType="com.ycwl.basic.model.pc.videoreview.dto.VideoReviewStatisticsRespDTO$ScenicReviewRank">
SELECT
vr.scenic_id AS scenicId,
s.name AS scenicName,
COUNT(*) AS reviewCount,
AVG(vr.rating) AS averageRating
FROM video_review vr
LEFT JOIN scenic s ON vr.scenic_id = s.id
GROUP BY vr.scenic_id, s.name
ORDER BY reviewCount DESC, averageRating DESC
LIMIT #{limit}
</select>
<!-- 查询所有问题机位ID列表 -->
<select id="selectAllProblemDeviceIds" resultType="java.util.List">
SELECT problem_device_ids
FROM video_review
WHERE problem_device_ids IS NOT NULL
AND problem_device_ids != ''
AND problem_device_ids != '[]'
</select>
<!-- 管理后台评价日志结果映射 -->
<resultMap id="AdminVideoReviewLogRespMap" type="com.ycwl.basic.model.pc.videoreview.dto.AdminVideoReviewLogRespDTO">
<id property="id" column="id"/>
<result property="videoId" column="video_id"/>
<result property="videoUrl" column="video_url"/>
<result property="duration" column="duration"/>
<result property="taskParams" column="task_params"/>
<result property="templateId" column="template_id"/>
<result property="templateName" column="template_name"/>
<result property="scenicId" column="scenic_id"/>
<result property="scenicName" column="scenic_name"/>
<result property="creator" column="creator"/>
<result property="creatorName" column="creator_name"/>
<result property="creatorAccount" column="creator_account"/>
<result property="rating" column="rating"/>
<result property="content" column="content"/>
<result property="problemDeviceIds" column="problem_device_ids"
typeHandler="com.ycwl.basic.handler.LongListTypeHandler"/>
<result property="problemDeviceCount" column="problem_device_count"/>
<result property="problemTags" column="problem_tags"
typeHandler="com.ycwl.basic.handler.StringListTypeHandler"/>
<result property="source" column="source"/>
<result property="sourceId" column="source_id"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="operationDuration" column="operation_duration"/>
</resultMap>
<!-- 管理后台分页查询评价日志 -->
<select id="selectAdminReviewLogList" parameterType="com.ycwl.basic.model.pc.videoreview.dto.AdminVideoReviewLogReqDTO"
resultMap="AdminVideoReviewLogRespMap">
SELECT
vr.id,
vr.video_id,
vr.scenic_id,
vr.creator,
vr.rating,
vr.content,
vr.problem_device_ids,
vr.problem_tags,
vr.source,
vr.source_id,
vr.create_time,
vr.update_time,
v.video_url,
v.duration,
v.template_id,
tk.task_params,
t.name AS template_name,
s.name AS scenic_name,
u.name AS creator_name,
u.account AS creator_account,
<!-- 计算问题机位数量 -->
CASE
WHEN vr.problem_device_ids IS NOT NULL AND vr.problem_device_ids != '' AND vr.problem_device_ids != '[]'
THEN JSON_LENGTH(vr.problem_device_ids)
ELSE 0
END AS problem_device_count,
<!-- 计算操作时长(秒) -->
TIMESTAMPDIFF(SECOND, vr.create_time, vr.update_time) AS operation_duration
FROM video_review vr
LEFT JOIN video v ON vr.video_id = v.id
LEFT JOIN task tk ON v.task_id = tk.id
LEFT JOIN template t ON v.template_id = t.id
LEFT JOIN scenic s ON vr.scenic_id = s.id
LEFT JOIN admin_user u ON vr.creator = u.id
<where>
<if test="id != null">
AND vr.id = #{id}
</if>
<if test="videoId != null">
AND vr.video_id = #{videoId}
</if>
<if test="scenicId != null">
AND vr.scenic_id = #{scenicId}
</if>
<if test="creator != null">
AND vr.creator = #{creator}
</if>
<if test="creatorName != null and creatorName != ''">
AND u.name LIKE CONCAT('%', #{creatorName}, '%')
</if>
<if test="rating != null">
AND vr.rating = #{rating}
</if>
<if test="minRating != null">
AND vr.rating &gt;= #{minRating}
</if>
<if test="maxRating != null">
AND vr.rating &lt;= #{maxRating}
</if>
<if test="startTime != null and startTime != ''">
AND vr.create_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND vr.create_time &lt;= #{endTime}
</if>
<if test="templateId != null">
AND v.template_id = #{templateId}
</if>
<if test="templateName != null and templateName != ''">
AND t.name LIKE CONCAT('%', #{templateName}, '%')
</if>
<if test="keyword != null and keyword != ''">
AND (
vr.content LIKE CONCAT('%', #{keyword}, '%')
OR s.name LIKE CONCAT('%', #{keyword}, '%')
OR t.name LIKE CONCAT('%', #{keyword}, '%')
)
</if>
<if test="hasCameraRating != null">
<!-- hasCameraRating 参数已废弃,保留以兼容旧接口 -->
</if>
<if test="problemDeviceId != null">
AND JSON_CONTAINS(vr.problem_device_ids, CAST(#{problemDeviceId} AS CHAR), '$')
</if>
<if test="problemTag != null and problemTag != ''">
AND JSON_CONTAINS(vr.problem_tags, JSON_QUOTE(#{problemTag}), '$')
</if>
<if test="source != null and source != ''">
AND vr.source = #{source}
</if>
</where>
ORDER BY
<choose>
<when test="orderBy == 'rating'">
vr.rating
</when>
<when test="orderBy == 'update_time'">
vr.update_time
</when>
<when test="orderBy == 'id'">
vr.id
</when>
<otherwise>
vr.create_time
</otherwise>
</choose>
<choose>
<when test="orderDirection == 'ASC'">
ASC
</when>
<otherwise>
DESC
</otherwise>
</choose>
</select>
</mapper>