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

243 lines
12 KiB

2 months ago
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.chenhai.vet.mapper.VetTrainingVideoMapper">
  6. <resultMap type="VetTrainingVideo" id="VetTrainingVideoResult">
  7. <result property="id" column="id" />
  8. <result property="userId" column="user_id" />
  9. <result property="title" column="title" />
  10. <result property="description" column="description" />
  11. <result property="videoUrl" column="video_url" />
  12. <result property="coverImage" column="cover_image" />
  13. <result property="category" column="category" />
  14. <result property="tags" column="tags" />
  15. <result property="duration" column="duration" />
  16. <result property="fileSize" column="file_size" />
  17. <result property="viewCount" column="view_count" />
  18. <result property="status" column="status" />
  19. <result property="createTime" column="create_time" />
  20. <result property="updateTime" column="update_time" />
  21. <result property="delFlag" column="del_flag" />
  22. <result property="auditStatus" column="audit_status" />
  23. <result property="auditOpinion" column="audit_opinion" />
  24. <result property="auditUserId" column="audit_user_id" />
  25. <result property="auditTime" column="audit_time" />
  26. <result property="publisherName" column="publisher_name" />
  27. <result property="publisherAvatar" column="publisher_avatar" />
  28. <result property="publishTime" column="publish_time" />
  29. </resultMap>
  30. <sql id="selectVetTrainingVideoVo">
  31. SELECT
  32. v.id,
  33. v.user_id,
  34. v.title,
  35. v.description,
  36. v.video_url,
  37. v.cover_image,
  38. v.category,
  39. v.tags,
  40. v.duration,
  41. v.file_size,
  42. v.view_count,
  43. v.status,
  44. v.create_time,
  45. v.update_time,
  46. v.del_flag,
  47. v.audit_status,
  48. v.audit_opinion,
  49. v.audit_user_id,
  50. v.audit_time,
  51. v.publish_time,
  52. u.nick_name as publisher_name, <!-- 使用用户的昵称作为发布者姓名 -->
  53. u.avatar as publisher_avatar
  54. FROM vet_training_video v
  55. LEFT JOIN sys_user u ON v.user_id = u.user_id
  56. </sql>
  57. <select id="selectVetTrainingVideoList" parameterType="VetTrainingVideo" resultMap="VetTrainingVideoResult">
  58. <include refid="selectVetTrainingVideoVo"/>
  59. <where>
  60. <!-- 使用表别名 v. 来明确指定字段来源 -->
  61. <if test="userId != null "> and v.user_id = #{userId}</if>
  62. <if test="title != null and title != ''">
  63. <bind name="titleLike" value="'%' + title + '%'" />
  64. and v.title like #{titleLike}
  65. </if>
  66. <if test="description != null and description != ''">
  67. <bind name="descriptionLike" value="'%' + description + '%'" />
  68. and v.description like #{descriptionLike}
  69. </if>
  70. <if test="videoUrl != null and videoUrl != ''"> and v.video_url = #{videoUrl}</if>
  71. <if test="coverImage != null and coverImage != ''"> and v.cover_image = #{coverImage}</if>
  72. <if test="category != null and category != ''"> and v.category = #{category}</if>
  73. <if test="tags != null and tags != ''">
  74. <bind name="tagsLike" value="'%' + tags + '%'" />
  75. and v.tags like #{tagsLike}
  76. </if>
  77. <if test="duration != null "> and v.duration = #{duration}</if>
  78. <if test="fileSize != null "> and v.file_size = #{fileSize}</if>
  79. <if test="viewCount != null "> and v.view_count = #{viewCount}</if>
  80. <if test="status != null and status != ''"> and v.status = #{status}</if>
  81. <if test="delFlag != null and delFlag != ''"> and v.del_flag = #{delFlag}</if>
  82. <if test="auditStatus != null and auditStatus != ''"> and v.audit_status = #{auditStatus}</if>
  83. <if test="auditOpinion != null and auditOpinion != ''">
  84. <bind name="opinionLike" value="'%' + auditOpinion + '%'" />
  85. and v.audit_opinion like #{opinionLike}
  86. </if>
  87. <if test="auditUserId != null "> and v.audit_user_id = #{auditUserId}</if>
  88. <if test="auditTime != null "> and v.audit_time = #{auditTime}</if>
  89. <if test="publisherName != null and publisherName != ''">
  90. <bind name="publisherLike" value="'%' + publisherName + '%'" />
  91. and u.nick_name like #{publisherLike}
  92. </if>
  93. <!-- 搜索关键词:同时搜索标题、描述、标签、发布者姓名 -->
  94. <if test="searchKey != null and searchKey != ''">
  95. <bind name="searchKeyLike" value="'%' + searchKey + '%'" />
  96. and (
  97. v.title like #{searchKeyLike}
  98. or v.description like #{searchKeyLike}
  99. or v.tags like #{searchKeyLike}
  100. or v.category like #{searchKeyLike}
  101. or u.nick_name like #{searchKeyLike}
  102. )
  103. </if>
  104. <if test="publishTime != null "> and v.publish_time = #{publishTime}</if>
  105. </where>
  106. </select>
  107. <select id="selectVetTrainingVideoById" parameterType="Long" resultMap="VetTrainingVideoResult">
  108. <include refid="selectVetTrainingVideoVo"/>
  109. where id = #{id}
  110. </select>
  111. <insert id="insertVetTrainingVideo" parameterType="VetTrainingVideo" useGeneratedKeys="true" keyProperty="id">
  112. insert into vet_training_video
  113. <trim prefix="(" suffix=")" suffixOverrides=",">
  114. <if test="userId != null">user_id,</if>
  115. <if test="title != null and title != ''">title,</if>
  116. <if test="description != null">description,</if>
  117. <if test="videoUrl != null and videoUrl != ''">video_url,</if>
  118. <if test="coverImage != null">cover_image,</if>
  119. <if test="category != null">category,</if>
  120. <if test="tags != null">tags,</if>
  121. <if test="duration != null">duration,</if>
  122. <if test="fileSize != null">file_size,</if>
  123. <if test="viewCount != null">view_count,</if>
  124. <if test="status != null">status,</if>
  125. <if test="createTime != null">create_time,</if>
  126. <if test="updateTime != null">update_time,</if>
  127. <if test="delFlag != null">del_flag,</if>
  128. <if test="auditStatus != null">audit_status,</if>
  129. <if test="auditOpinion != null">audit_opinion,</if>
  130. <if test="auditUserId != null">audit_user_id,</if>
  131. <if test="auditTime != null">audit_time,</if>
  132. <if test="publishTime != null">publish_time,</if>
  133. </trim>
  134. <trim prefix="values (" suffix=")" suffixOverrides=",">
  135. <if test="userId != null">#{userId},</if>
  136. <if test="title != null and title != ''">#{title},</if>
  137. <if test="description != null">#{description},</if>
  138. <if test="videoUrl != null and videoUrl != ''">#{videoUrl},</if>
  139. <if test="coverImage != null">#{coverImage},</if>
  140. <if test="category != null">#{category},</if>
  141. <if test="tags != null">#{tags},</if>
  142. <if test="duration != null">#{duration},</if>
  143. <if test="fileSize != null">#{fileSize},</if>
  144. <if test="viewCount != null">#{viewCount},</if>
  145. <if test="status != null">#{status},</if>
  146. <if test="createTime != null">#{createTime},</if>
  147. <if test="updateTime != null">#{updateTime},</if>
  148. <if test="delFlag != null">#{delFlag},</if>
  149. <if test="auditStatus != null">#{auditStatus},</if>
  150. <if test="auditOpinion != null">#{auditOpinion},</if>
  151. <if test="auditUserId != null">#{auditUserId},</if>
  152. <if test="auditTime != null">#{auditTime},</if>
  153. <if test="publishTime != null">#{publishTime},</if>
  154. </trim>
  155. </insert>
  156. <update id="updateVetTrainingVideo" parameterType="VetTrainingVideo">
  157. update vet_training_video
  158. <trim prefix="SET" suffixOverrides=",">
  159. <if test="userId != null">user_id = #{userId},</if>
  160. <if test="title != null and title != ''">title = #{title},</if>
  161. <if test="description != null">description = #{description},</if>
  162. <if test="videoUrl != null and videoUrl != ''">video_url = #{videoUrl},</if>
  163. <if test="coverImage != null">cover_image = #{coverImage},</if>
  164. <if test="category != null">category = #{category},</if>
  165. <if test="tags != null">tags = #{tags},</if>
  166. <if test="duration != null">duration = #{duration},</if>
  167. <if test="fileSize != null">file_size = #{fileSize},</if>
  168. <if test="viewCount != null">view_count = #{viewCount},</if>
  169. <if test="status != null">status = #{status},</if>
  170. <if test="createTime != null">create_time = #{createTime},</if>
  171. <if test="updateTime != null">update_time = #{updateTime},</if>
  172. <if test="delFlag != null">del_flag = #{delFlag},</if>
  173. <if test="auditStatus != null">audit_status = #{auditStatus},</if>
  174. <if test="auditOpinion != null">audit_opinion = #{auditOpinion},</if>
  175. <if test="auditUserId != null">audit_user_id = #{auditUserId},</if>
  176. <if test="auditTime != null">audit_time = #{auditTime},</if>
  177. <if test="publishTime != null">publish_time = #{publishTime},</if>
  178. </trim>
  179. where id = #{id}
  180. </update>
  181. <delete id="deleteVetTrainingVideoById" parameterType="Long">
  182. delete from vet_training_video where id = #{id}
  183. </delete>
  184. <delete id="deleteVetTrainingVideoByIds" parameterType="String">
  185. delete from vet_training_video where id in
  186. <foreach item="id" collection="array" open="(" separator="," close=")">
  187. #{id}
  188. </foreach>
  189. </delete>
  190. <!-- 查询公开视频列表(已上架且已审核通过) -->
  191. <select id="selectPublicVideoList" parameterType="VetTrainingVideo" resultMap="VetTrainingVideoResult">
  192. <include refid="selectVetTrainingVideoVo"/>
  193. <where>
  194. <!-- 强制条件:已上架、审核通过、未删除 -->
  195. and v.status = '1'
  196. and v.audit_status = '2'
  197. and v.del_flag = '0'
  198. <!-- 可选查询条件 -->
  199. <if test="userId != null "> and v.user_id = #{userId}</if>
  200. <if test="title != null and title != ''">
  201. <bind name="titleLike" value="'%' + title + '%'" />
  202. and v.title like #{titleLike}
  203. </if>
  204. <if test="description != null and description != ''">
  205. <bind name="descriptionLike" value="'%' + description + '%'" />
  206. and v.description like #{descriptionLike}
  207. </if>
  208. <if test="category != null and category != ''"> and v.category = #{category}</if>
  209. <if test="tags != null and tags != ''">
  210. <bind name="tagsLike" value="'%' + tags + '%'" />
  211. and v.tags like #{tagsLike}
  212. </if>
  213. <if test="publisherName != null and publisherName != ''">
  214. <bind name="publisherLike" value="'%' + publisherName + '%'" />
  215. and u.nick_name like #{publisherLike}
  216. </if>
  217. <!-- 搜索关键词:同时搜索标题、描述、标签、发布者姓名 -->
  218. <if test="searchKey != null and searchKey != ''">
  219. <bind name="searchKeyLike" value="'%' + searchKey + '%'" />
  220. and (
  221. v.title like #{searchKeyLike}
  222. or v.description like #{searchKeyLike}
  223. or v.tags like #{searchKeyLike}
  224. or v.category like #{searchKeyLike}
  225. or u.nick_name like #{searchKeyLike}
  226. )
  227. </if>
  228. <if test="publishTime != null "> and v.publish_time = #{publishTime}</if>
  229. </where>
  230. <!-- 默认按创建时间倒序排列 -->
  231. order by v.create_time desc
  232. </select>
  233. </mapper>