ContentPlatformPlanMapperExt.xml 18 KB

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