ContentPlatformPlanMapperExt.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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="com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformPlanMapperExt">
  4. <insert id="insertGzhPlanReturnId" useGeneratedKeys="true" keyProperty="id">
  5. insert into content_platform_gzh_plan (`type`, publish_stage, account_id, scene, external_id,
  6. select_video_type, stage_publish_status,
  7. create_account_id, create_timestamp, update_timestamp)
  8. values (#{record.type}, #{record.publishStage}, #{record.accountId}, #{record.scene}, #{record.externalId},
  9. #{record.selectVideoType}, #{record.stagePublishStatus}, #{record.createAccountId},
  10. #{record.createTimestamp}, #{record.updateTimestamp})
  11. </insert>
  12. <select id="getGzhPlanCount" resultType="java.lang.Integer">
  13. select count(*)
  14. from content_platform_gzh_plan
  15. where create_account_id = #{createAccountId} and status = 1
  16. <if test="param.type != null">
  17. and type = #{param.type}
  18. </if>
  19. <if test="param.accountId != null">
  20. and account_id = #{param.accountId}
  21. </if>
  22. <if test="param.publishStage != null">
  23. and publish_stage = #{param.publishStage}
  24. </if>
  25. <if test="param.selectVideoType != null">
  26. and select_video_type = #{param.selectVideoType}
  27. </if>
  28. <if test="param.createTimestampStart != null">
  29. and create_timestamp > #{param.createTimestampStart}
  30. </if>
  31. <if test="param.createTimestampEnd != null">
  32. and create_timestamp &lt; #{param.createTimestampEnd}
  33. </if>
  34. <if test="param.title != null and param.title != ''">
  35. and id in (select plan_id
  36. from content_platform_gzh_plan_video
  37. where (title like concat('%', #{param.title}, '%')
  38. or custom_title like concat('%', #{param.title}, '%'))
  39. and status = 1)
  40. </if>
  41. </select>
  42. <select id="getGzhPlanList"
  43. resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhPlan">
  44. select *
  45. from content_platform_gzh_plan
  46. where create_account_id = #{createAccountId} and status = 1
  47. <if test="param.type != null">
  48. and type = #{param.type}
  49. </if>
  50. <if test="param.accountId != null">
  51. and account_id = #{param.accountId}
  52. </if>
  53. <if test="param.publishStage != null">
  54. and publish_stage = #{param.publishStage}
  55. </if>
  56. <if test="param.selectVideoType != null">
  57. and select_video_type = #{param.selectVideoType}
  58. </if>
  59. <if test="param.createTimestampStart != null">
  60. and create_timestamp > #{param.createTimestampStart}
  61. </if>
  62. <if test="param.createTimestampEnd != null">
  63. and create_timestamp &lt; #{param.createTimestampEnd}
  64. </if>
  65. <if test="param.title != null and param.title != ''">
  66. and id in (select plan_id
  67. from content_platform_gzh_plan_video
  68. where (title like concat('%', #{param.title}, '%')
  69. or custom_title like concat('%', #{param.title}, '%'))
  70. and status = 1)
  71. </if>
  72. order by create_timestamp desc
  73. limit #{offset}, #{pageSize}
  74. </select>
  75. <select id="getGzhPlanExists"
  76. resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhPlan">
  77. select *
  78. from content_platform_gzh_plan
  79. where account_id = #{accountId}
  80. and scene = #{scene}
  81. and type = #{type}
  82. and status = 1
  83. <if test="id != null">
  84. and id != #{id}
  85. </if>
  86. limit 1
  87. </select>
  88. <select id="getVideoMaxDt" resultType="java.lang.String">
  89. select max(dt)
  90. from content_platform_video_agg
  91. </select>
  92. <select id="getVideoDatastatMaxDt" resultType="java.lang.String">
  93. select max(dt)
  94. from content_platform_video_datastat_agg
  95. </select>
  96. <select id="getVideoCount" resultType="java.lang.Integer">
  97. select count(1)
  98. from content_platform_video_agg
  99. where dt = #{dt} and status = 1 and score > #{minScore}
  100. <if test="param.title!= null and param.title!= ''">
  101. and title like concat('%', #{param.title}, '%')
  102. </if>
  103. <if test="param.category!= null and param.category!= ''">
  104. and category = #{param.category}
  105. </if>
  106. </select>
  107. <select id="getApiVideoList" resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
  108. select video.*
  109. from content_platform_video_agg video
  110. left join content_platform_video_datastat_agg datastat
  111. on datastat.dt = #{datastatDt} and datastat.type = #{type} and datastat.channel = #{channel}
  112. and datastat.strategy = #{strategy} and datastat.video_id = video.video_id
  113. where video.dt = #{dt} and video.status = 1 and video.score > #{minScore}
  114. <if test="param.title!= null and param.title!= ''">
  115. and video.title like concat('%', #{param.title}, '%')
  116. </if>
  117. <if test="param.category!= null and param.category!= ''">
  118. and video.category = #{param.category}
  119. </if>
  120. order by ${sort}
  121. limit #{offset}, #{pageSize}
  122. </select>
  123. <select id="getVideoList" resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
  124. select video.*
  125. from content_platform_video_agg video
  126. left join content_platform_video_datastat_agg datastat
  127. on datastat.dt = #{datastatDt} and datastat.type = #{type} and datastat.channel = #{channel}
  128. and datastat.strategy = #{strategy} and datastat.video_id = video.video_id
  129. <if test="excludeVideoTime != null">
  130. left join content_platform_gzh_plan_video gzhPlanVideo
  131. on gzhPlanVideo.video_id = video.video_id and gzhPlanVideo.create_account_id = #{createAccountId}
  132. <if test="excludeVideoTime != 0">
  133. and gzhPlanVideo.create_timestamp > #{excludeVideoTime}
  134. </if>
  135. left join content_platform_qw_plan_video qwPlanVideo
  136. on qwPlanVideo.video_id = video.video_id and qwPlanVideo.create_account_id = #{createAccountId}
  137. <if test="excludeVideoTime != 0">
  138. and qwPlanVideo.create_timestamp > #{excludeVideoTime}
  139. </if>
  140. </if>
  141. <if test="param.tag != null">
  142. join content_platform_video_tag videoTag
  143. on videoTag.dt = video.dt and videoTag.video_id = video.video_id and ${videoTagFilter}
  144. </if>
  145. where video.dt = #{dt} and video.status = 1 and video.score > #{minScore}
  146. and (video.source = 1 or video.video_id in (select video_id
  147. from content_platform_video_account_rel
  148. where dt = #{dt} and account_id = #{createAccountId}))
  149. <if test="param.title!= null and param.title!= ''">
  150. and video.title like concat('%', #{param.title}, '%')
  151. </if>
  152. <if test="param.category!= null and param.category!= ''">
  153. and video.category = #{param.category}
  154. </if>
  155. <if test="excludeVideoTime != null">
  156. and gzhPlanVideo.video_id is null
  157. and qwPlanVideo.video_id is null
  158. </if>
  159. order by ${sort}
  160. limit #{offset}, #{pageSize}
  161. </select>
  162. <select id="getVideoMinScoreList" resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
  163. select *
  164. from content_platform_video_agg video
  165. where video.dt = #{dt} and video.status = 1 and video.score > #{minScore}
  166. <if test="excludeVideoIds != null and excludeVideoIds.size() > 0">
  167. and video.video_id not in
  168. <foreach collection="excludeVideoIds" item="item" open="(" close=")" separator=",">
  169. #{item}
  170. </foreach>
  171. </if>
  172. order by ${sort}
  173. limit #{offset}, #{pageSize}
  174. </select>
  175. <select id="getVideoMinDatastatScoreList" resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
  176. select video.*
  177. from content_platform_video_agg video
  178. left join content_platform_video_datastat_agg datastat
  179. on datastat.dt = #{datastatDt} and datastat.type = #{type} and datastat.channel = #{channel}
  180. and datastat.strategy = #{strategy} and datastat.video_id = video.video_id
  181. where video.dt = #{dt} and video.status = 1 and datastat.fission_rate > #{minScore}
  182. <if test="excludeVideoIds != null and excludeVideoIds.size() > 0">
  183. and video.video_id not in
  184. <foreach collection="excludeVideoIds" item="item" open="(" close=")" separator=",">
  185. #{item}
  186. </foreach>
  187. </if>
  188. order by ${sort}
  189. limit #{offset}, #{pageSize}
  190. </select>
  191. <select id="getVideoCategoryList" resultType="java.lang.String">
  192. select distinct category
  193. from content_platform_video_agg
  194. where dt = #{dt} and status = 1
  195. </select>
  196. <insert id="batchInsertContentPlatformVideo">
  197. insert into content_platform_video (dt, video_id, category, title, cover, video, score, create_timestamp)
  198. values
  199. <foreach collection="records" item="item" separator=",">
  200. (#{item.dt}, #{item.videoId}, #{item.category}, #{item.title}, #{item.cover}, #{item.video}, #{item.score},
  201. #{item.createTimestamp})
  202. </foreach>
  203. </insert>
  204. <insert id="batchInsertContentPlatformIllegalVideo">
  205. insert into content_platform_illegal_video (date_str, video_id, content, title, create_timestamp)
  206. values
  207. <foreach collection="records" item="item" separator=",">
  208. (#{item.dateStr}, #{item.videoId}, #{item.content}, #{item.title}, #{item.createTimestamp})
  209. </foreach>
  210. </insert>
  211. <insert id="batchInsertContentPlatformVideoAgg">
  212. insert into content_platform_video_agg (dt, last_dt, source, video_id, category, title, cover,
  213. video, score, create_timestamp)
  214. values
  215. <foreach collection="records" item="item" separator=",">
  216. (#{item.dt}, #{item.lastDt}, #{item.source}, #{item.videoId}, #{item.category}, #{item.title},
  217. #{item.cover}, #{item.video}, #{item.score}, #{item.createTimestamp})
  218. </foreach>
  219. </insert>
  220. <select id="getQwPlanCount" resultType="java.lang.Integer">
  221. select count(*)
  222. from content_platform_qw_plan
  223. where create_account_id = #{createAccountId}
  224. and type = #{param.type}
  225. and status = 1
  226. <if test="param.scene != null">
  227. and scene = #{param.scene}
  228. </if>
  229. <if test="param.subChannel != null and param.subChannel != ''">
  230. and sub_channel like concat('%', #{param.subChannel}, '%')
  231. </if>
  232. <if test="param.title != null and param.title != ''">
  233. and id in (select plan_id
  234. from content_platform_qw_plan_video
  235. where title like concat('%', #{param.title}, '%') and status = 1)
  236. </if>
  237. </select>
  238. <select id="getQwPlanList"
  239. resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwPlan">
  240. select *
  241. from content_platform_qw_plan
  242. where create_account_id = #{createAccountId}
  243. and type = #{param.type}
  244. and status = 1
  245. <if test="param.scene != null">
  246. and scene = #{param.scene}
  247. </if>
  248. <if test="param.subChannel != null and param.subChannel != ''">
  249. and sub_channel like concat('%', #{param.subChannel}, '%')
  250. </if>
  251. <if test="param.title != null and param.title != ''">
  252. and id in (select plan_id
  253. from content_platform_qw_plan_video
  254. where title like concat('%', #{param.title}, '%') and status = 1)
  255. </if>
  256. order by create_timestamp desc
  257. limit #{offset}, #{pageSize}
  258. </select>
  259. <insert id="batchInsertQwPlan">
  260. insert into content_platform_qw_plan (`type`, scene, page_url, root_source_id,
  261. create_account_id, create_timestamp, update_timestamp
  262. )
  263. values
  264. <foreach collection="records" item="item" separator=",">
  265. (#{item.type}, #{item.scene}, #{item.pageUrl}, #{item.rootSourceId},
  266. #{item.createAccountId}, #{item.createTimestamp}, #{item.updateTimestamp}
  267. )
  268. </foreach>
  269. </insert>
  270. <insert id="insertQwPlanReturnId" useGeneratedKeys="true" keyProperty="id">
  271. insert into content_platform_qw_plan (`type`, sub_channel, scene, page_url, root_source_id, create_account_id,
  272. create_timestamp, update_timestamp)
  273. values (#{record.type}, #{record.subChannel}, #{record.scene}, #{record.pageUrl}, #{record.rootSourceId},
  274. #{record.createAccountId}, #{record.createTimestamp}, #{record.updateTimestamp})
  275. </insert>
  276. <select id="getGzhPlanVideoListByCooperateAccountId"
  277. resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhPlanVideo">
  278. select cpgpv.*
  279. from content_platform_gzh_plan_video cpgpv
  280. join content_platform_gzh_plan cpgp on cpgp.id = cpgpv.plan_id
  281. join content_platform_gzh_account cpgac on cpgac.id = cpgp.account_id
  282. where cpgac.gh_id = #{ghId}
  283. and cpgac.status = 1
  284. and cpgp.scene = 0
  285. and cpgp.status = 1
  286. and cpgpv.status = 1
  287. </select>
  288. <select id="getVideoAggList"
  289. resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideoAgg">
  290. SELECT t.video_id, t.category, t.title, t.cover, t.video, round(t.avg_score, 3) as score, t.dt
  291. FROM (
  292. SELECT video_id, category, title, cover, video, AVG(score) OVER (PARTITION BY video_id) AS avg_score,
  293. ROW_NUMBER() OVER (PARTITION BY video_id ORDER BY dt DESC) AS rn,
  294. MAX(dt) OVER (PARTITION BY video_id) AS dt
  295. FROM content_platform_video
  296. where dt in
  297. <foreach collection="dtList" item="item" open="(" close=")" separator=",">
  298. #{item}
  299. </foreach>
  300. and status = 1
  301. and cover is not null
  302. ) AS t
  303. WHERE t.rn = 1;
  304. </select>
  305. <update id="updateVideoStatusWithOldStatus">
  306. update content_platform_video
  307. set status = #{status},
  308. update_timestamp = #{now}
  309. where video_id = #{videoId}
  310. and status = #{oldStatus}
  311. </update>
  312. <update id="updateVideoAggStatusWithOldStatus">
  313. update content_platform_video_agg
  314. set status = #{status},
  315. update_timestamp = #{now}
  316. where video_id = #{videoId}
  317. and status = #{oldStatus}
  318. </update>
  319. <select id="getVideoListByIds"
  320. resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
  321. SELECT t1.*
  322. FROM content_platform_video t1
  323. INNER JOIN (
  324. SELECT video_id, MAX(dt) AS max_dt
  325. FROM content_platform_video
  326. WHERE video_id IN
  327. <foreach collection="videoIds" item="item" open="(" close=")" separator=",">
  328. #{item}
  329. </foreach>
  330. GROUP BY video_id
  331. ) t2 ON t1.video_id = t2.video_id AND t1.dt = t2.max_dt
  332. ORDER BY t1.dt DESC
  333. </select>
  334. <delete id="deleteContentPlatformVideo">
  335. delete from content_platform_video where dt = #{dt}
  336. </delete>
  337. <delete id="deleteContentPlatformVideoAgg">
  338. delete from content_platform_video_agg where dt = #{dt} and source = #{source}
  339. </delete>
  340. <delete id="deleteContentPlatformVideoDatastatAgg">
  341. delete
  342. from content_platform_video_datastat_agg
  343. where dt = #{dt}
  344. <if test="strategy != null and strategy != ''">
  345. and strategy = #{strategy}
  346. </if>
  347. </delete>
  348. <delete id="deleteContentPlatformVideoDatastat">
  349. delete from content_platform_video_datastat where dt = #{dt}
  350. </delete>
  351. <insert id="batchInsertContentPlatformVideoDatastat">
  352. insert into content_platform_video_datastat (dt, video_id, `type`, channel, first_level, fission0,
  353. fission_rate, create_timestamp)
  354. values
  355. <foreach collection="records" item="item" separator=",">
  356. (#{item.dt}, #{item.videoId}, #{item.type}, #{item.channel}, #{item.firstLevel},
  357. #{item.fission0}, #{item.fissionRate}, #{item.createTimestamp})
  358. </foreach>
  359. </insert>
  360. <insert id="batchInsertContentPlatformVideoDatastatAgg">
  361. insert into content_platform_video_datastat_agg (dt, video_id, `type`, channel, strategy, first_level, fission0,
  362. fission_rate, create_timestamp)
  363. values
  364. <foreach collection="records" item="item" separator=",">
  365. (#{item.dt}, #{item.videoId}, #{item.type}, #{item.channel}, #{item.strategy}, #{item.firstLevel},
  366. #{item.fission0}, #{item.fissionRate}, #{item.createTimestamp})
  367. </foreach>
  368. </insert>
  369. <update id="updateOtherVideoStatus">
  370. update content_platform_video
  371. set status = 0,
  372. update_timestamp = #{now}
  373. where dt = #{dt} and video_id not in
  374. <foreach collection="videoIdList" item="item" open="(" close=")" separator=",">
  375. #{item}
  376. </foreach>
  377. </update>
  378. <select id="getGzhPlanIllegalVideoList"
  379. resultType="com.tzld.piaoquan.api.model.po.contentplatform.PlanIllegalVideoDTO">
  380. select plan.create_account_id as account_id, plan.type, video.video_id, '公众号' as channel,
  381. coalesce(nullif(video.custom_title, ''), video.title) as title
  382. from content_platform_gzh_plan plan
  383. join content_platform_gzh_plan_video video on plan.id = video.plan_id
  384. where video.video_id = #{videoId} and plan.`status` = 1 and video.status = 1
  385. </select>
  386. <select id="getQwPlanIllegalVideoList"
  387. resultType="com.tzld.piaoquan.api.model.po.contentplatform.PlanIllegalVideoDTO">
  388. select plan.create_account_id as account_id, plan.type, video.video_id, '企微' as channel, video.title
  389. from content_platform_qw_plan plan
  390. join content_platform_qw_plan_video video on plan.id = video.plan_id
  391. where video.video_id = #{videoId} and plan.`status` = 1 and video.status = 1
  392. </select>
  393. <select id="getUploadVideoCount" resultType="java.lang.Integer">
  394. select count(1)
  395. from content_platform_upload_video
  396. where audit_status = 2 and create_account_id = #{createAccountId} and is_delete = 0
  397. <if test="param.title!= null and param.title!= ''">
  398. and title like concat('%', #{param.title}, '%')
  399. </if>
  400. </select>
  401. <select id="getUploadVideoList"
  402. resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
  403. select video.*
  404. from content_platform_upload_video video
  405. left join content_platform_video_datastat_agg datastat
  406. on datastat.dt = #{datastatDt} and datastat.type = #{type} and datastat.channel = #{channel}
  407. and datastat.strategy = #{strategy} and datastat.video_id = video.video_id
  408. where video.audit_status = 2 and video.create_account_id = #{createAccountId} and video.is_delete = 0
  409. <if test="param.title!= null and param.title!= ''">
  410. and video.title like concat('%', #{param.title}, '%')
  411. </if>
  412. order by ${sort}
  413. limit #{offset}, #{pageSize}
  414. </select>
  415. <update id="updateUploadVideoStatusWithOldStatus">
  416. update content_platform_upload_video
  417. set audit_status = #{status},
  418. update_timestamp = #{now}
  419. where video_id = #{videoId}
  420. </update>
  421. <delete id="deleteContentPlatformVideoAccountRel">
  422. delete from content_platform_video_account_rel where dt = #{dt}
  423. </delete>
  424. <insert id="batchInsertContentPlatformVideoAccountRel">
  425. insert into content_platform_video_account_rel (dt, account_id, video_id, sim_score, create_timestamp)
  426. values
  427. <foreach collection="records" item="item" separator=",">
  428. (#{item.dt}, #{item.accountId}, #{item.videoId}, #{item.simScore}, #{item.createTimestamp})
  429. </foreach>
  430. </insert>
  431. <select id="getVideoTagList"
  432. resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideoTag">
  433. select *
  434. from content_platform_video_tag
  435. where dt = #{dt} and video_id in
  436. <foreach collection="videoIds" item="item" open="(" close=")" separator=",">
  437. #{item}
  438. </foreach>
  439. and (platform = 1 or account_id = #{accountId} or type = #{type} or channel = #{channel})
  440. </select>
  441. <delete id="deleteContentPlatformVideoTag">
  442. delete from content_platform_video_tag where dt = #{dt}
  443. </delete>
  444. <insert id="batchInsertContentPlatformVideoTag">
  445. insert into content_platform_video_tag (dt, account_id, video_id, platform, type, channel, tag, create_timestamp)
  446. values
  447. <foreach collection="records" item="item" separator=",">
  448. (#{item.dt}, #{item.accountId}, #{item.videoId}, #{item.platform}, #{item.type}, #{item.channel}, #{item.tag}, #{item.createTimestamp})
  449. </foreach>
  450. </insert>
  451. </mapper>