|
|
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.chenhai.vet.mapper.VetTrainingVideoMapper"> <resultMap type="VetTrainingVideo" id="VetTrainingVideoResult"> <result property="id" column="id" /> <result property="userId" column="user_id" /> <result property="title" column="title" /> <result property="description" column="description" /> <result property="videoUrl" column="video_url" /> <result property="coverImage" column="cover_image" /> <result property="category" column="category" /> <result property="tags" column="tags" /> <result property="duration" column="duration" /> <result property="fileSize" column="file_size" /> <result property="viewCount" column="view_count" /> <result property="status" column="status" /> <result property="createTime" column="create_time" /> <result property="updateTime" column="update_time" /> <result property="delFlag" column="del_flag" /> <result property="auditStatus" column="audit_status" /> <result property="auditOpinion" column="audit_opinion" /> <result property="auditUserId" column="audit_user_id" /> <result property="auditTime" column="audit_time" /> <result property="publisherName" column="publisher_name" /> <result property="publisherAvatar" column="publisher_avatar" /> <result property="publishTime" column="publish_time" /> </resultMap>
<sql id="selectVetTrainingVideoVo"> SELECT v.id, v.user_id, v.title, v.description, v.video_url, v.cover_image, v.category, v.tags, v.duration, v.file_size, v.view_count, v.status, v.create_time, v.update_time, v.del_flag, v.audit_status, v.audit_opinion, v.audit_user_id, v.audit_time, v.publish_time, u.nick_name as publisher_name, <!-- 使用用户的昵称作为发布者姓名 --> u.avatar as publisher_avatar FROM vet_training_video v LEFT JOIN sys_user u ON v.user_id = u.user_id </sql>
<select id="selectVetTrainingVideoList" parameterType="VetTrainingVideo" resultMap="VetTrainingVideoResult"> <include refid="selectVetTrainingVideoVo"/> <where> <!-- 使用表别名 v. 来明确指定字段来源 --> <if test="userId != null "> and v.user_id = #{userId}</if> <if test="title != null and title != ''"> <bind name="titleLike" value="'%' + title + '%'" /> and v.title like #{titleLike} </if> <if test="description != null and description != ''"> <bind name="descriptionLike" value="'%' + description + '%'" /> and v.description like #{descriptionLike} </if> <if test="videoUrl != null and videoUrl != ''"> and v.video_url = #{videoUrl}</if> <if test="coverImage != null and coverImage != ''"> and v.cover_image = #{coverImage}</if> <if test="category != null and category != ''"> and v.category = #{category}</if> <if test="tags != null and tags != ''"> <bind name="tagsLike" value="'%' + tags + '%'" /> and v.tags like #{tagsLike} </if> <if test="duration != null "> and v.duration = #{duration}</if> <if test="fileSize != null "> and v.file_size = #{fileSize}</if> <if test="viewCount != null "> and v.view_count = #{viewCount}</if> <if test="status != null and status != ''"> and v.status = #{status}</if> <if test="delFlag != null and delFlag != ''"> and v.del_flag = #{delFlag}</if> <if test="auditStatus != null and auditStatus != ''"> and v.audit_status = #{auditStatus}</if> <if test="auditOpinion != null and auditOpinion != ''"> <bind name="opinionLike" value="'%' + auditOpinion + '%'" /> and v.audit_opinion like #{opinionLike} </if> <if test="auditUserId != null "> and v.audit_user_id = #{auditUserId}</if> <if test="auditTime != null "> and v.audit_time = #{auditTime}</if> <if test="publisherName != null and publisherName != ''"> <bind name="publisherLike" value="'%' + publisherName + '%'" /> and u.nick_name like #{publisherLike} </if> <!-- 搜索关键词:同时搜索标题、描述、标签、发布者姓名 --> <if test="searchKey != null and searchKey != ''"> <bind name="searchKeyLike" value="'%' + searchKey + '%'" /> and ( v.title like #{searchKeyLike} or v.description like #{searchKeyLike} or v.tags like #{searchKeyLike} or v.category like #{searchKeyLike} or u.nick_name like #{searchKeyLike} ) </if> <if test="publishTime != null "> and v.publish_time = #{publishTime}</if> </where> </select> <select id="selectVetTrainingVideoById" parameterType="Long" resultMap="VetTrainingVideoResult"> <include refid="selectVetTrainingVideoVo"/> where id = #{id} </select>
<insert id="insertVetTrainingVideo" parameterType="VetTrainingVideo" useGeneratedKeys="true" keyProperty="id"> insert into vet_training_video <trim prefix="(" suffix=")" suffixOverrides=","> <if test="userId != null">user_id,</if> <if test="title != null and title != ''">title,</if> <if test="description != null">description,</if> <if test="videoUrl != null and videoUrl != ''">video_url,</if> <if test="coverImage != null">cover_image,</if> <if test="category != null">category,</if> <if test="tags != null">tags,</if> <if test="duration != null">duration,</if> <if test="fileSize != null">file_size,</if> <if test="viewCount != null">view_count,</if> <if test="status != null">status,</if> <if test="createTime != null">create_time,</if> <if test="updateTime != null">update_time,</if> <if test="delFlag != null">del_flag,</if> <if test="auditStatus != null">audit_status,</if> <if test="auditOpinion != null">audit_opinion,</if> <if test="auditUserId != null">audit_user_id,</if> <if test="auditTime != null">audit_time,</if> <if test="publishTime != null">publish_time,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="userId != null">#{userId},</if> <if test="title != null and title != ''">#{title},</if> <if test="description != null">#{description},</if> <if test="videoUrl != null and videoUrl != ''">#{videoUrl},</if> <if test="coverImage != null">#{coverImage},</if> <if test="category != null">#{category},</if> <if test="tags != null">#{tags},</if> <if test="duration != null">#{duration},</if> <if test="fileSize != null">#{fileSize},</if> <if test="viewCount != null">#{viewCount},</if> <if test="status != null">#{status},</if> <if test="createTime != null">#{createTime},</if> <if test="updateTime != null">#{updateTime},</if> <if test="delFlag != null">#{delFlag},</if> <if test="auditStatus != null">#{auditStatus},</if> <if test="auditOpinion != null">#{auditOpinion},</if> <if test="auditUserId != null">#{auditUserId},</if> <if test="auditTime != null">#{auditTime},</if> <if test="publishTime != null">#{publishTime},</if> </trim> </insert>
<update id="updateVetTrainingVideo" parameterType="VetTrainingVideo"> update vet_training_video <trim prefix="SET" suffixOverrides=","> <if test="userId != null">user_id = #{userId},</if> <if test="title != null and title != ''">title = #{title},</if> <if test="description != null">description = #{description},</if> <if test="videoUrl != null and videoUrl != ''">video_url = #{videoUrl},</if> <if test="coverImage != null">cover_image = #{coverImage},</if> <if test="category != null">category = #{category},</if> <if test="tags != null">tags = #{tags},</if> <if test="duration != null">duration = #{duration},</if> <if test="fileSize != null">file_size = #{fileSize},</if> <if test="viewCount != null">view_count = #{viewCount},</if> <if test="status != null">status = #{status},</if> <if test="createTime != null">create_time = #{createTime},</if> <if test="updateTime != null">update_time = #{updateTime},</if> <if test="delFlag != null">del_flag = #{delFlag},</if> <if test="auditStatus != null">audit_status = #{auditStatus},</if> <if test="auditOpinion != null">audit_opinion = #{auditOpinion},</if> <if test="auditUserId != null">audit_user_id = #{auditUserId},</if> <if test="auditTime != null">audit_time = #{auditTime},</if> <if test="publishTime != null">publish_time = #{publishTime},</if> </trim> where id = #{id} </update>
<delete id="deleteVetTrainingVideoById" parameterType="Long"> delete from vet_training_video where id = #{id} </delete>
<delete id="deleteVetTrainingVideoByIds" parameterType="String"> delete from vet_training_video where id in <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach> </delete>
<!-- 查询公开视频列表(已上架且已审核通过) --> <select id="selectPublicVideoList" parameterType="VetTrainingVideo" resultMap="VetTrainingVideoResult"> <include refid="selectVetTrainingVideoVo"/> <where> <!-- 强制条件:已上架、审核通过、未删除 --> and v.status = '1' and v.audit_status = '2' and v.del_flag = '0'
<!-- 可选查询条件 --> <if test="userId != null "> and v.user_id = #{userId}</if> <if test="title != null and title != ''"> <bind name="titleLike" value="'%' + title + '%'" /> and v.title like #{titleLike} </if> <if test="description != null and description != ''"> <bind name="descriptionLike" value="'%' + description + '%'" /> and v.description like #{descriptionLike} </if> <if test="category != null and category != ''"> and v.category = #{category}</if> <if test="tags != null and tags != ''"> <bind name="tagsLike" value="'%' + tags + '%'" /> and v.tags like #{tagsLike} </if> <if test="publisherName != null and publisherName != ''"> <bind name="publisherLike" value="'%' + publisherName + '%'" /> and u.nick_name like #{publisherLike} </if> <!-- 搜索关键词:同时搜索标题、描述、标签、发布者姓名 --> <if test="searchKey != null and searchKey != ''"> <bind name="searchKeyLike" value="'%' + searchKey + '%'" /> and ( v.title like #{searchKeyLike} or v.description like #{searchKeyLike} or v.tags like #{searchKeyLike} or v.category like #{searchKeyLike} or u.nick_name like #{searchKeyLike} ) </if> <if test="publishTime != null "> and v.publish_time = #{publishTime}</if> </where> <!-- 默认按创建时间倒序排列 --> order by v.create_time desc </select></mapper>
|