VideoPostMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. <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="countAdminVideo" 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="userId != null">
  177. and publish_by=#{userId}
  178. </if>
  179. <if test="horizontal != null">
  180. and horizontal=#{horizontal}
  181. </if>
  182. <if test="videoId != null">
  183. and video_id=#{videoId}
  184. </if>
  185. <if test="title != null">
  186. and match(title) against(#{title})
  187. </if>
  188. </where>
  189. </select>
  190. <select id="findAdminVideoByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  191. select *
  192. from vod_video_post
  193. <where>
  194. deleted=0
  195. <if test="videoQuery.status != null">
  196. and `status` in
  197. <foreach collection="videoQuery.status" item="id" index="index" open="(" close=")" separator=",">
  198. #{id}
  199. </foreach>
  200. </if>
  201. <if test="videoQuery.scope != null">
  202. and scope in
  203. <foreach collection="videoQuery.scope" item="id" index="index" open="(" close=")" separator=",">
  204. #{id}
  205. </foreach>
  206. </if>
  207. <if test="videoQuery.categoryPid != null">
  208. and category_pid=#{videoQuery.categoryPid}
  209. </if>
  210. <if test="videoQuery.categoryId != null">
  211. and category_id=#{videoQuery.categoryId}
  212. </if>
  213. <if test="videoQuery.userId != null">
  214. and publish_by=#{videoQuery.userId}
  215. </if>
  216. <if test="videoQuery.horizontal != null">
  217. and horizontal=#{videoQuery.horizontal}
  218. </if>
  219. <if test="videoQuery.title != null">
  220. and match(title) against(#{videoQuery.title})
  221. </if>
  222. </where>
  223. order by #{videoQuery.orderBy} #{videoQuery.orderDirection}
  224. </select>
  225. <resultMap id="videoPostCard" type="cn.reghao.tnb.content.api.dto.VideoPostCard">
  226. <id column="video_id" property="videoId"/>
  227. <result column="title" property="title"/>
  228. <result column="cover_url" property="coverUrl"/>
  229. <result column="duration" property="duration"/>
  230. <result column="horizontal" property="horizontal"/>
  231. <result column="status" property="status"/>
  232. <result column="publish_at" property="publishAt"/>
  233. <result column="publish_by" property="publishBy"/>
  234. <result column="view" property="view"/>
  235. <result column="comment" property="comment"/>
  236. </resultMap>
  237. <select id="findVideoCardByVideoIds" resultMap="videoPostCard">
  238. 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,
  239. statistic.view,statistic.comment
  240. from vod_video_post post
  241. inner join vod_video_statistic statistic
  242. on post.deleted=0 and statistic.video_id=post.video_id and post.status in (2,5,6,7) and post.video_id in
  243. <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
  244. #{id}
  245. </foreach>
  246. </select>
  247. <select id="findByUserIds" resultMap="videoPostCard">
  248. 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,
  249. statistic.view,statistic.comment
  250. from vod_video_post post
  251. inner join vod_video_statistic statistic
  252. on statistic.video_id=post.video_id and post.status in (2,5,6,7) and post.publish_by in
  253. <foreach collection="userIds" item="id" index="index" open="(" close=")" separator=",">
  254. #{id}
  255. </foreach>
  256. where post.deleted=0 and post.id &lt; #{nextId}
  257. order by post.publish_at desc
  258. limit #{pageSize}
  259. </select>
  260. <resultMap id="videoDetail" type="cn.reghao.tnb.content.app.vod.model.vo.VideoDetail">
  261. <id column="video_id" property="videoId"/>
  262. <result column="title" property="title"/>
  263. <result column="description" property="description"/>
  264. <result column="cover_url" property="coverUrl"/>
  265. <result column="duration" property="duration"/>
  266. <result column="publish_at" property="pubDate"/>
  267. <result column="scope" property="scope"/>
  268. <result column="status" property="status"/>
  269. <result column="publish_by" property="userId"/>
  270. <result column="view" property="view"/>
  271. <result column="thumb_up" property="thumbUp"/>
  272. <result column="favorite" property="favorite"/>
  273. <result column="share" property="share"/>
  274. <result column="comment" property="comment"/>
  275. <!--<collection column="tag_name" property="tags" ofType="java.lang.String" select="findVideoTags"/>-->
  276. </resultMap>
  277. <select id="findVideoPostDetail" resultMap="videoDetail">
  278. select post.publish_by,post.video_id,post.title,post.description,post.cover_url,post.duration,post.publish_at,post.scope,post.status,
  279. statistic.view,statistic.danmaku,statistic.comment,statistic.thumb_up,
  280. statistic.favorite,statistic.share
  281. from vod_video_post post
  282. inner join vod_video_statistic statistic
  283. on statistic.video_id=post.video_id
  284. <where>
  285. post.deleted=0
  286. <if test="status != null">
  287. and post.status in
  288. <foreach collection="status" item="id" index="index" open="(" close=")" separator=",">
  289. #{id}
  290. </foreach>
  291. </if>
  292. <if test="scope != null">
  293. and post.scope in
  294. <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
  295. #{id}
  296. </foreach>
  297. </if>
  298. <if test="videoId != null">
  299. and post.video_id=#{videoId}
  300. </if>
  301. </where>
  302. </select>
  303. <select id="findVideoTags" resultType="java.lang.String">
  304. select tag_name
  305. from vod_post_tag
  306. inner join vod_video_tag
  307. on vod_post_tag.tag_id=vod_video_tag.tag_id and vod_video_tag.video_id=#{videoId}
  308. </select>
  309. <select id="findByNextVideos" resultMap="videoPostCard">
  310. select post.id,post.video_id,post.title,post.cover_url,post.duration,post.horizontal,post.publish_at,post.publish_by,post.status,
  311. statistic.view,statistic.comment
  312. from vod_video_post post
  313. inner join vod_video_statistic statistic
  314. on statistic.video_id=post.video_id
  315. <where>
  316. post.deleted=0
  317. <if test="videoQuery.status != null">
  318. and post.status in
  319. <foreach collection="videoQuery.status" item="id" index="index" open="(" close=")" separator=",">
  320. #{id}
  321. </foreach>
  322. </if>
  323. <if test="videoQuery.scope != null">
  324. and post.scope in
  325. <foreach collection="videoQuery.scope" item="id" index="index" open="(" close=")" separator=",">
  326. #{id}
  327. </foreach>
  328. </if>
  329. <if test="videoQuery.userId != null">
  330. and post.publish_by=#{videoQuery.userId}
  331. </if>
  332. and post.publish_at > #{publishAt}
  333. </where>
  334. order by post.publish_at asc
  335. limit 4
  336. </select>
  337. <select id="countBySearchCriteria" resultType="java.lang.Integer">
  338. select count(*)
  339. from vod_video_post
  340. <where>
  341. deleted=0
  342. <if test="status != null">
  343. and `status` in
  344. <foreach collection="status" item="id" index="index" open="(" close=")" separator=",">
  345. #{id}
  346. </foreach>
  347. </if>
  348. <if test="scope != null">
  349. and scope in
  350. <foreach collection="scope" item="id" index="index" open="(" close=")" separator=",">
  351. #{id}
  352. </foreach>
  353. </if>
  354. <if test="title != null">
  355. and match(title) against(#{title})
  356. </if>
  357. </where>
  358. </select>
  359. <select id="findSearchCriteriaByPage" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  360. select *
  361. from vod_video_post
  362. <where>
  363. deleted=0
  364. <if test="searchCriteria.status != null">
  365. and status in
  366. <foreach collection="searchCriteria.status" item="id" index="index" open="(" close=")" separator=",">
  367. #{id}
  368. </foreach>
  369. </if>
  370. <if test="searchCriteria.scope != null">
  371. and scope in
  372. <foreach collection="searchCriteria.scope" item="id" index="index" open="(" close=")" separator=",">
  373. #{id}
  374. </foreach>
  375. </if>
  376. <if test="searchCriteria.title != null">
  377. and match(title) against(#{searchCriteria.title})
  378. </if>
  379. </where>
  380. </select>
  381. <select id="findByVideoId" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  382. select *
  383. from vod_video_post
  384. where deleted=0 and video_id=#{videoId}
  385. </select>
  386. <select id="findAll" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  387. select *
  388. from vod_video_post
  389. where deleted=0 and `status`=2 and category_pid=11
  390. </select>
  391. <select id="findAllById" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  392. select *
  393. from vod_video_post
  394. where deleted=0 and `status` in (2,5) and id > #{nextId}
  395. order by id asc
  396. limit #{pageSize}
  397. </select>
  398. <select id="findBannerVideos" resultType="cn.reghao.tnb.content.app.vod.model.po.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="findPublishByPost" 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="findPublishByImage" resultType="cn.reghao.tnb.common.db.GroupCount">
  413. select user_id as id,count(*) as total
  414. from image_post
  415. where user_id not in
  416. (
  417. select publish_by
  418. from vod_video_post
  419. where category_pid=11
  420. group by publish_by
  421. )
  422. group by user_id
  423. order by total desc
  424. </select>
  425. <select id="findPublishByVideo" resultType="cn.reghao.tnb.common.db.GroupCount">
  426. select publish_by as id,count(*) total
  427. from vod_video_post
  428. where category_pid=11
  429. group by publish_by
  430. order by total desc
  431. </select>
  432. <select id="findRandomVideoIds" resultType="java.lang.String">
  433. SELECT t1.video_id
  434. FROM vod_video_post AS t1
  435. JOIN (SELECT ROUND(RAND()*(SELECT MAX(id) FROM vod_video_post)) AS id) AS t2
  436. WHERE t1.id>=t2.id and t1.scope in
  437. <foreach collection="scopes" item="id" index="index" open="(" close=")" separator=",">
  438. #{id}
  439. </foreach>
  440. ORDER BY t1.id
  441. LIMIT #{size}
  442. </select>
  443. <select id="findShortVideo" resultType="java.lang.String">
  444. SELECT video_id
  445. FROM vod_video_post AS t1
  446. WHERE t1.duration&lt;=120 and t1.`status`=2 and t1.`horizontal`=0 and t1.scope in
  447. <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
  448. #{id}
  449. </foreach>
  450. limit 100000
  451. </select>
  452. <select id="findGroupByUserAndCategory" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  453. select *
  454. from vod_video_post
  455. where `deleted`=0 and `status`=2 and category_pid=#{categoryPid}
  456. group by publish_by,category_id
  457. </select>
  458. <select id="findUserAndCategory" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  459. select *
  460. from vod_video_post
  461. where `deleted`=0 and `status`=2 and publish_by=#{publishBy} and category_id=#{categoryId}
  462. order by publish_at desc
  463. limit 1
  464. </select>
  465. <select id="findByTitle" resultType="cn.reghao.tnb.content.app.vod.model.po.VideoPost">
  466. select *
  467. from vod_video_post
  468. where `deleted`=0 and `status`=2 and category_pid=11 and title like concat(#{title},'%')
  469. </select>
  470. </mapper>