2025-08-13 17:29:13 +08:00

287 lines
8.3 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.wzj.soopin.content.mapper.VlogMapper">
<!-- 通用更新 -->
<update id="dynamicUpdate">
UPDATE cont_vlog
<set>
<foreach collection="updateFields" index="key" item="value" separator=",">
${key} = #{value}
</foreach>
</set>
WHERE ${primaryKey} = #{idValue}
</update>
<update id="updateVlogByConditions">
UPDATE cont_vlog
<set>
<foreach collection="updates" item="value" index="key" separator=",">
${key} = #{value}
</foreach>
</set>
<where>
<foreach collection="conditions" item="value" index="key" separator=" AND ">
<choose>
<!-- 处理null值条件 -->
<when test="value == null">
${key} IS NULL
</when>
<!-- 处理IN条件 -->
<when test="value instanceof java.util.Collection">
${key} IN
<foreach collection="value" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</when>
<!-- 处理普通条件 -->
<otherwise>
${key} = #{value}
</otherwise>
</choose>
</foreach>
</where>
</update>
<!-- 单条插入 -->
<insert id="dynamicInsert">
INSERT INTO cont_vlog
<foreach collection="vlogData.keys" item="key" open="(" separator="," close=")">
${key}
</foreach>
VALUES
<foreach collection="vlogData.values" item="value" open="(" separator="," close=")">
#{value}
</foreach>
</insert>
<!-- 批量插入 -->
<insert id="dynamicBatchInsert">
INSERT INTO cont_vlog
<foreach collection="vlogList[0].keys" item="key" open="(" separator="," close=")">
${key}
</foreach>
VALUES
<foreach collection="vlogList" item="vlogData" separator=",">
<foreach collection="vlogData.values" item="value" open="(" separator="," close=")">
#{value}
</foreach>
</foreach>
</insert>
<!-- 查询 -->
<select id="selectMyPublic" parameterType="map" resultType="com.wzj.soopin.content.domain.vo.IndexVlogVO">
SELECT
v.id as vlogId,
v.vloger_id as vlogerId,
u.face as vlogerFace,
u.nickname as vlogerName,
v.title as content,
v.url as mediaUrl,
v.cover as cover,
v.width as width,
v.height as height,
v.like_counts as likeCounts,
v.comments_counts as commentCounts,
v.is_private as isPrivate,
v.city_code as cityCode,
v.reason as reason,
v.file_id as fileId,
v.status as status,
v.first_frame_img as firstFrameImg,
v.id as vlogId
FROM
cont_vlog v
LEFT JOIN
cont_users u
ON
v.vloger_id = u.id
WHERE
v.is_private = 0
AND v.vloger_id = #{paramMap.vlogerId}
<choose>
<when test="paramMap.status != null and paramMap.status!=''">
AND v.status = #{paramMap.status}
</when>
<otherwise>
AND v.status = 1
</otherwise>
</choose>
<if test="paramMap.cityCode != null and paramMap.cityCode != ''">
AND v.city_code = #{paramMap.cityCode}
</if>
<if test="paramMap.search != null and paramMap.search != ''">
AND v.title like '%${paramMap.search}%'
</if>
<if test="paramMap.blockVd != null and paramMap.blockVd.size() > 0">
AND v.id NOT IN
<foreach collection="paramMap.blockVd" item="vlogId" open="(" separator="," close=")">
#{vlogId}
</foreach>
</if>
ORDER BY
v.created_time
DESC
</select>
<select id="getVlogDetailFromId" parameterType="map" resultType="com.wzj.soopin.content.domain.vo.IndexVlogVO">
SELECT
v.id as vlogId,
v.vloger_id as vlogerId,
u.face as vlogerFace,
u.nickname as vlogerName,
v.title as content,
v.url as mediaUrl,
v.cover as cover,
v.width as width,
v.height as height,
v.like_counts as likeCounts,
v.comments_counts as commentCounts,
v.is_private as isPrivate,
v.city_code as cityCode,
v.reason as reason,
v.file_id as fileId,
v.status as status,
v.first_frame_img as firstFrameImg,
v.id as vlogId
FROM
cont_vlog v
LEFT JOIN
cont_users u
ON
v.vloger_id = u.id
WHERE
v.id = #{paramMap.vlogId}
AND v.status = 1
AND v.first_frame_img IS NOT NULL
</select>
<!-- 更新视频审核状态 -->
<update id="updateVlogStatus">
UPDATE t_vlog
SET status = #{params.status},
reason = #{params.reason},
audit_time = #{params.auditTime}
WHERE id = #{params.vlogId}
</update>
<!-- 根据fileId查询Vlog信息 -->
<select id="selectByFileId" parameterType="String" resultType="com.wzj.soopin.content.domain.po.Vlog">
/* @SqlParser(filter=true) */
SELECT * FROM cont_vlog WHERE file_id = #{fileId}
</select>
<select id="selectByMobileAndVlogId" resultType="com.wzj.soopin.content.domain.vo.CommentVO">
SELECT
c.id,
c.id as commentId,
c.vloger_id as vlogerId,
c.father_comment_id as fatherCommentId,
c.vlog_id as vlogId,
c.comment_user_id as commentUserId,
u.nickname as commentUserNickname,
u.face as commentUserFace,
c.content,
c.like_counts as likeCounts,
c.create_time as createTime
FROM cont_comment c
LEFT JOIN cont_users u ON c.comment_user_id = u.id
<where>
c.father_comment_id = '0'
<if test="vlogId != null and vlogId != ''">
AND c.vlog_id = #{vlogId}
</if>
<if test="mobile != null and mobile != ''">
AND u.mobile LIKE CONCAT('%', #{mobile}, '%')
</if>
</where>
ORDER BY c.create_time DESC
</select>
<select id="selectVlogListWithAggregatedData" resultType="java.util.Map">
SELECT
v.id,
v.vloger_id,
v.url as mediaUrl,
v.cover,
v.title,
v.width,
v.height,
COUNT(DISTINCT mlv.id) AS likeCounts,
COUNT(DISTINCT c.id) AS commentCounts,
v.file_id as fileId,
v.status,
v.reason,
v.city_code,
v.first_frame_img as coverUrl,
v.create_time as createTime,
v.update_time,
v.create_by,
v.update_by,
u.nickname,
u.mobile
FROM
cont_vlog v
LEFT JOIN
cont_users u ON v.vloger_id = u.id
LEFT JOIN
cont_my_liked_vlog mlv ON v.id = mlv.vlog_id
LEFT JOIN
cont_comment c ON v.id = c.vlog_id AND (c.father_comment_id = '0' OR c.father_comment_id IS NULL)
<where>
<if test="vlogBO.mobile != null and vlogBO.mobile != ''">
AND u.mobile LIKE CONCAT('%', #{vlogBO.mobile}, '%')
</if>
<if test="vlogBO.nickname != null and vlogBO.nickname != ''">
AND u.nickname LIKE CONCAT('%', #{vlogBO.nickname}, '%')
</if>
<if test="vlogBO.titleQuery != null and vlogBO.titleQuery != ''">
AND v.title LIKE CONCAT('%', #{vlogBO.titleQuery}, '%')
</if>
<if test="vlogBO.status != null">
AND v.status = #{vlogBO.status}
</if>
<if test="vlogBO.startTime != null and vlogBO.startTime != '' and vlogBO.endTime != null and vlogBO.endTime != ''">
AND v.create_time BETWEEN #{vlogBO.startTime} AND #{vlogBO.endTime}
</if>
</where>
GROUP BY
v.id,
v.vloger_id,
v.url,
v.cover,
v.title,
v.width,
v.height,
v.file_id,
v.status,
v.reason,
v.city_code,
v.first_frame_img,
v.create_time,
v.update_time,
v.create_by,
v.update_by,
u.nickname,
u.mobile
ORDER BY
<choose>
<when test="vlogBO.column == 'likeCounts'">
likeCounts ${vlogBO.asc ? 'ASC' : 'DESC'}
</when>
<when test="vlogBO.column == 'commentCounts'">
commentCounts ${vlogBO.asc ? 'ASC' : 'DESC'}
</when>
<when test="vlogBO.column == 'status'">
FIELD(v.status, 0, 1, 2, 3) ${vlogBO.asc ? 'ASC' : 'DESC'}
</when>
<otherwise>
v.create_time DESC
</otherwise>
</choose>
</select>
</mapper>