VideoPostMapper.xml 20 KB

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