VideoPostMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="cn.reghao.tnb.content.app.vod.db.mapper.VideoPostMapper">
  4. <insert id="save" useGeneratedKeys="true" keyProperty="id">
  5. insert into vod_video_post
  6. (`video_id`,`video_file_id`,`channel_id`,`title`,`description`,`category_pid`,`category_id`,`cover_url`,`scope`,`status`,`horizontal`,`duration`,`quality`,`codec`,`publish_at`,`publish_by`)
  7. values
  8. (#{videoId},#{videoFileId},#{channelId},#{title},#{description},#{categoryPid},#{categoryId},#{coverUrl},#{scope},#{status},#{horizontal},#{duration},#{quality},#{codec},#{publishAt},#{publishBy})
  9. </insert>
  10. <update id="updateVideoScope">
  11. update vod_video_post
  12. set update_time=now(),scope=#{scope}
  13. where video_id=#{videoId}
  14. </update>
  15. <update id="updateVideoInfo">
  16. update vod_video_post
  17. set update_time=now(),title=#{title},`description`=#{description}
  18. where video_id=#{videoId}
  19. </update>
  20. <update id="updateVideoCover">
  21. update vod_video_post
  22. set update_time=now(),cover_url=#{coverUrl}
  23. where video_id=#{videoId}
  24. </update>
  25. <update id="updateVideoFile">
  26. update vod_video_post
  27. set update_time=now(),video_file_id=#{videoInfo.videoFileId},duration=#{videoInfo.duration},quality=#{videoInfo.quality}
  28. where video_id=#{videoId}
  29. </update>
  30. <update id="updateVideoStatus">
  31. update vod_video_post
  32. set update_time=now(),`status`=#{status}
  33. where video_id=#{videoId}
  34. </update>
  35. <update id="updateVideoPublish">
  36. update vod_video_post
  37. set update_time=now(),`status`=#{status}
  38. where video_id=#{videoId}
  39. </update>
  40. <update id="updateVideoCached">
  41. update vod_video_post
  42. set update_time=now(),video_file_id=#{videoInfo.videoFileId},duration=#{videoInfo.duration},quality=#{videoInfo.quality},channel_id=#{channelId},`status`=2
  43. where video_id=#{videoId}
  44. </update>
  45. <delete id="deleteByVideoId">
  46. delete from vod_video_post
  47. where video_id=#{videoId}
  48. </delete>
  49. <select id="countByCriteria" resultType="java.lang.Integer">
  50. select count(*)
  51. from vod_video_post
  52. <where>
  53. deleted=0
  54. <if test="status != null">
  55. and `status` in
  56. <foreach collection="status" item="id" index="index" open="(" close=")" separator=",">
  57. #{id}
  58. </foreach>
  59. </if>
  60. <if test="scope != null">
  61. and scope in
  62. <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
  63. #{id}
  64. </foreach>
  65. </if>
  66. <if test="categoryPid != null">
  67. and category_pid=#{categoryPid}
  68. </if>
  69. <if test="categoryId != null">
  70. and category_id=#{categoryId}
  71. </if>
  72. <if test="userId != null">
  73. and publish_by=#{userId}
  74. </if>
  75. <if test="horizontal != null">
  76. and horizontal=#{horizontal}
  77. </if>
  78. <if test="videoId != null">
  79. and video_id=#{videoId}
  80. </if>
  81. </where>
  82. </select>
  83. <select id="findVideoPostByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  84. select *
  85. from vod_video_post post
  86. <where>
  87. deleted=0
  88. <if test="videoQuery.status != null">
  89. and post.status in
  90. <foreach collection="videoQuery.status" item="id" index="index" open="(" close=")" separator=",">
  91. #{id}
  92. </foreach>
  93. </if>
  94. <if test="videoQuery.scope != null">
  95. and post.scope in
  96. <foreach collection="videoQuery.scope" item="id" index="index" open="(" close=")" separator=",">
  97. #{id}
  98. </foreach>
  99. </if>
  100. <if test="videoQuery.categoryPid != null">
  101. and post.category_pid=#{videoQuery.categoryPid}
  102. </if>
  103. <if test="videoQuery.categoryId != null">
  104. and post.category_id=#{videoQuery.categoryId}
  105. </if>
  106. <if test="videoQuery.userId != null">
  107. and post.publish_by=#{videoQuery.userId}
  108. </if>
  109. <if test="videoQuery.horizontal != null">
  110. and post.horizontal=#{videoQuery.horizontal}
  111. </if>
  112. </where>
  113. order by post.publish_at desc
  114. </select>
  115. <select id="findVideoCardByPage" resultMap="videoPostCard">
  116. select post.id,post.video_id,post.title,post.cover_url,post.duration,post.horizontal,post.publish_at,post.publish_by,post.status,
  117. statistic.view,statistic.comment
  118. from vod_video_post post
  119. inner join vod_video_statistic statistic
  120. on statistic.video_id=post.video_id
  121. <where>
  122. and post.deleted=0
  123. <if test="videoQuery.status != null">
  124. and post.status in
  125. <foreach collection="videoQuery.status" item="id" index="index" open="(" close=")" separator=",">
  126. #{id}
  127. </foreach>
  128. </if>
  129. <if test="videoQuery.scope != null">
  130. and post.scope in
  131. <foreach collection="videoQuery.scope" item="id" index="index" open="(" close=")" separator=",">
  132. #{id}
  133. </foreach>
  134. </if>
  135. <if test="videoQuery.categoryPid != null">
  136. and post.category_pid=#{videoQuery.categoryPid}
  137. </if>
  138. <if test="videoQuery.categoryId != null">
  139. and post.category_id=#{videoQuery.categoryId}
  140. </if>
  141. <if test="videoQuery.userId != null">
  142. and post.publish_by=#{videoQuery.userId}
  143. </if>
  144. <if test="videoQuery.horizontal != null">
  145. and post.horizontal=#{videoQuery.horizontal}
  146. </if>
  147. <if test="videoQuery.duration != null">
  148. and post.duration &lt; #{videoQuery.duration}
  149. </if>
  150. </where>
  151. order by post.publish_at desc
  152. </select>
  153. <select id="countByCriteriaAndUserGroup" resultType="java.lang.Integer">
  154. select count(*)
  155. from vod_video_post
  156. <where>
  157. deleted=0
  158. <if test="status != null">
  159. and `status` in
  160. <foreach collection="status" item="id" index="index" open="(" close=")" separator=",">
  161. #{id}
  162. </foreach>
  163. </if>
  164. <if test="scope != null">
  165. and scope in
  166. <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
  167. #{id}
  168. </foreach>
  169. </if>
  170. <if test="categoryPid != null">
  171. and category_pid=#{categoryPid}
  172. </if>
  173. <if test="categoryId != null">
  174. and category_id=#{categoryId}
  175. </if>
  176. <if test="duration != null">
  177. and duration &lt;= #{duration}
  178. </if>
  179. <if test="horizontal != null">
  180. and horizontal=#{horizontal}
  181. </if>
  182. </where>
  183. group by publish_by
  184. </select>
  185. <select id="findCriteriaAndUserGroupByPage" resultMap="videoPostCard">
  186. select post.id,post.video_id,post.title,post.cover_url,post.duration,post.horizontal,post.publish_at,post.publish_by,post.status,
  187. statistic.view,statistic.comment
  188. from vod_video_post post
  189. inner join vod_video_statistic statistic
  190. on statistic.video_id=post.video_id
  191. <where>
  192. and post.deleted=0
  193. <if test="videoQuery.status != null">
  194. and post.status in
  195. <foreach collection="videoQuery.status" item="id" index="index" open="(" close=")" separator=",">
  196. #{id}
  197. </foreach>
  198. </if>
  199. <if test="videoQuery.scope != null">
  200. and post.scope in
  201. <foreach collection="videoQuery.scope" item="id" index="index" open="(" close=")" separator=",">
  202. #{id}
  203. </foreach>
  204. </if>
  205. <if test="videoQuery.categoryPid != null">
  206. and post.category_pid=#{videoQuery.categoryPid}
  207. </if>
  208. <if test="videoQuery.categoryId != null">
  209. and post.category_id=#{videoQuery.categoryId}
  210. </if>
  211. <if test="videoQuery.duration != null">
  212. and post.duration &lt;= #{videoQuery.duration}
  213. </if>
  214. <if test="videoQuery.horizontal != null">
  215. and post.horizontal=#{videoQuery.horizontal}
  216. </if>
  217. </where>
  218. group by post.publish_by
  219. </select>
  220. <resultMap id="videoPostCard" type="cn.reghao.tnb.content.api.dto.VideoPostCard">
  221. <id column="video_id" property="videoId"/>
  222. <result column="title" property="title"/>
  223. <result column="cover_url" property="coverUrl"/>
  224. <result column="duration" property="duration"/>
  225. <result column="horizontal" property="horizontal"/>
  226. <result column="status" property="status"/>
  227. <result column="publish_at" property="publishAt"/>
  228. <result column="publish_by" property="publishBy"/>
  229. <result column="view" property="view"/>
  230. <result column="comment" property="comment"/>
  231. </resultMap>
  232. <select id="findVideoCardByVideoIds" resultMap="videoPostCard">
  233. select post.id,post.video_id,post.title,post.cover_url,post.duration,post.horizontal,post.publish_at as publish_at,post.publish_by,post.status,
  234. statistic.view,statistic.comment
  235. from vod_video_post post
  236. inner join vod_video_statistic statistic
  237. on post.deleted=0 and statistic.video_id=post.video_id and post.status in (2,5,6,7) and post.video_id in
  238. <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
  239. #{id}
  240. </foreach>
  241. </select>
  242. <select id="findByUserIds" resultMap="videoPostCard">
  243. select post.id,post.video_id,post.title,post.cover_url,post.duration,post.horizontal,post.publish_at as publish_at,post.publish_by,post.status,
  244. statistic.view,statistic.comment
  245. from vod_video_post post
  246. inner join vod_video_statistic statistic
  247. on statistic.video_id=post.video_id and post.status in (2,5,6,7) and post.publish_by in
  248. <foreach collection="userIds" item="id" index="index" open="(" close=")" separator=",">
  249. #{id}
  250. </foreach>
  251. where post.deleted=0 and post.id &lt; #{nextId}
  252. order by post.publish_at desc
  253. limit #{pageSize}
  254. </select>
  255. <resultMap id="videoDetail" type="cn.reghao.tnb.content.app.vod.model.vo.VideoDetail">
  256. <id column="video_id" property="videoId"/>
  257. <id column="video_file_id" property="videoFileId"/>
  258. <result column="title" property="title"/>
  259. <result column="description" property="description"/>
  260. <result column="cover_url" property="coverUrl"/>
  261. <result column="duration" property="duration"/>
  262. <result column="publish_at" property="pubDate"/>
  263. <result column="scope" property="scope"/>
  264. <result column="status" property="status"/>
  265. <result column="publish_by" property="userId"/>
  266. <result column="view" property="view"/>
  267. <result column="thumb_up" property="thumbUp"/>
  268. <result column="favorite" property="favorite"/>
  269. <result column="share" property="share"/>
  270. <result column="comment" property="comment"/>
  271. <collection column="tag_name" property="tags" ofType="java.lang.String" select="findVideoTags"/>
  272. </resultMap>
  273. <select id="findVideoPostDetail" resultMap="videoDetail">
  274. select post.publish_by,post.video_id,post.video_file_id,post.title,post.description,post.cover_url,post.duration,post.publish_at,post.scope,post.status,
  275. statistic.view,statistic.danmaku,statistic.comment,statistic.thumb_up,
  276. statistic.favorite,statistic.share
  277. from vod_video_post post
  278. inner join vod_video_statistic statistic
  279. on statistic.video_id=post.video_id
  280. <where>
  281. post.deleted=0
  282. <if test="status != null">
  283. and post.status in
  284. <foreach collection="status" item="id" index="index" open="(" close=")" separator=",">
  285. #{id}
  286. </foreach>
  287. </if>
  288. <if test="scope != null">
  289. and post.scope in
  290. <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
  291. #{id}
  292. </foreach>
  293. </if>
  294. <if test="videoId != null">
  295. and post.video_id=#{videoId}
  296. </if>
  297. </where>
  298. </select>
  299. <select id="findVideoTags" resultType="java.lang.String">
  300. select tag_name
  301. from video_tags
  302. inner join video_tag
  303. on video_tag.tag_id=video_tags.tag_id and video_tags.video_id=#{videoId}
  304. </select>
  305. <select id="findByNextVideos" resultMap="videoPostCard">
  306. select post.id,post.video_id,post.title,post.cover_url,post.duration,post.horizontal,post.publish_at,post.publish_by,post.status,
  307. statistic.view,statistic.comment
  308. from vod_video_post post
  309. inner join vod_video_statistic statistic
  310. on statistic.video_id=post.video_id
  311. <where>
  312. post.deleted=0
  313. <if test="videoQuery.status != null">
  314. and post.status in
  315. <foreach collection="videoQuery.status" item="id" index="index" open="(" close=")" separator=",">
  316. #{id}
  317. </foreach>
  318. </if>
  319. <if test="videoQuery.scope != null">
  320. and post.scope in
  321. <foreach collection="videoQuery.scope" item="id" index="index" open="(" close=")" separator=",">
  322. #{id}
  323. </foreach>
  324. </if>
  325. <if test="videoQuery.userId != null">
  326. and post.publish_by=#{videoQuery.userId}
  327. </if>
  328. and post.publish_at > #{publishAt}
  329. </where>
  330. order by post.publish_at asc
  331. limit 4
  332. </select>
  333. <select id="countBySearchCriteria" resultType="java.lang.Integer">
  334. select count(*)
  335. from vod_video_post
  336. <where>
  337. deleted=0
  338. <if test="status != null">
  339. and `status` in
  340. <foreach collection="status" item="id" index="index" open="(" close=")" separator=",">
  341. #{id}
  342. </foreach>
  343. </if>
  344. <if test="scope != null">
  345. and scope in
  346. <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
  347. #{id}
  348. </foreach>
  349. </if>
  350. <if test="title != null">
  351. and match(title) against(#{title})
  352. </if>
  353. </where>
  354. </select>
  355. <select id="findSearchCriteriaByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  356. select *
  357. from vod_video_post
  358. <where>
  359. deleted=0
  360. <if test="searchCriteria.status != null">
  361. and status in
  362. <foreach collection="searchCriteria.status" item="id" index="index" open="(" close=")" separator=",">
  363. #{id}
  364. </foreach>
  365. </if>
  366. <if test="searchCriteria.scope != null">
  367. and scope in
  368. <foreach collection="searchCriteria.scope" item="id" index="index" open="(" close=")" separator=",">
  369. #{id}
  370. </foreach>
  371. </if>
  372. <if test="searchCriteria.title != null">
  373. and match(title) against(#{searchCriteria.title})
  374. </if>
  375. </where>
  376. </select>
  377. <select id="findByVideoId" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  378. select *
  379. from vod_video_post
  380. where deleted=0 and video_id=#{videoId}
  381. </select>
  382. <select id="findByVideoFileId" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  383. select *
  384. from vod_video_post
  385. where deleted=0 and video_file_id=#{videoFileId}
  386. </select>
  387. <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  388. select *
  389. from vod_video_post
  390. where category_id=6
  391. </select>
  392. <select id="findAllById" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  393. select *
  394. from vod_video_post
  395. where deleted=0 and category_id=4 and id > #{nextId}
  396. limit #{pageSize}
  397. </select>
  398. <select id="findBannerVideos" resultType="cn.reghao.tnb.content.api.dto.BannerVideo">
  399. select post.video_id,post.cover_url,post.title
  400. from vod_video_post post
  401. where deleted=0
  402. order by publish_at desc
  403. limit 10
  404. </select>
  405. <select id="findGroupByPublishBy" resultType="cn.reghao.tnb.common.db.GroupCount">
  406. select publish_by as id,count(*) total
  407. from vod_video_post
  408. where deleted=0 and category_pid=11
  409. group by publish_by
  410. order by total desc
  411. </select>
  412. <select id="findGroupByCategoryId" resultType="cn.reghao.tnb.common.db.GroupCount">
  413. select category_id as id,count(*) total
  414. from vod_video_post
  415. where deleted=0
  416. group by category_id
  417. order by total desc
  418. </select>
  419. <select id="findRandomVideoIds" resultType="java.lang.String">
  420. SELECT t1.video_id
  421. FROM vod_video_post AS t1
  422. JOIN (SELECT ROUND(RAND()*(SELECT MAX(id) FROM vod_video_post)) AS id) AS t2
  423. WHERE t1.id>=t2.id and t1.scope in
  424. <foreach collection="scopes" item="id" index="index" open="(" close=")" separator=",">
  425. #{id}
  426. </foreach>
  427. ORDER BY t1.id
  428. LIMIT #{size}
  429. </select>
  430. <select id="findShortVideo" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  431. SELECT t1.*
  432. FROM vod_video_post AS t1
  433. JOIN (SELECT ROUND(RAND()*(SELECT MAX(id) FROM vod_video_post)) AS id) AS t2
  434. WHERE t1.id>=t2.id and t1.duration&lt;=120 and t1.`status`=2 and t1.scope in
  435. <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
  436. #{id}
  437. </foreach>
  438. ORDER BY t1.id
  439. LIMIT 1
  440. </select>
  441. </mapper>