ContentPlatformPlanMapperExt.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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} and datastat.video_id = video.video_id
  110. where video.dt = #{dt} and video.status = 1 and video.score > #{minScore}
  111. <if test="param.title!= null and param.title!= ''">
  112. and video.title like concat('%', #{param.title}, '%')
  113. </if>
  114. <if test="param.category!= null and param.category!= ''">
  115. and video.category = #{param.category}
  116. </if>
  117. order by ${sort}
  118. limit #{offset}, #{pageSize}
  119. </select>
  120. <select id="getVideoMinScoreList" resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
  121. select *
  122. from content_platform_video_agg video
  123. where video.dt = #{dt} and video.status = 1 and video.score > #{minScore}
  124. <if test="excludeVideoIds != null and excludeVideoIds.size() > 0">
  125. and video.video_id not in
  126. <foreach collection="excludeVideoIds" item="item" open="(" close=")" separator=",">
  127. #{item}
  128. </foreach>
  129. </if>
  130. order by ${sort}
  131. limit #{offset}, #{pageSize}
  132. </select>
  133. <select id="getVideoMinDatastatScoreList" resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
  134. select video.*
  135. from content_platform_video_agg video
  136. left join content_platform_video_datastat_agg datastat
  137. on datastat.dt = #{datastatDt} and datastat.type = #{type} and datastat.channel = #{channel} and datastat.video_id = video.video_id
  138. where video.dt = #{dt} and video.status = 1 and datastat.fission_rate > #{minScore}
  139. <if test="excludeVideoIds != null and excludeVideoIds.size() > 0">
  140. and video.video_id not in
  141. <foreach collection="excludeVideoIds" item="item" open="(" close=")" separator=",">
  142. #{item}
  143. </foreach>
  144. </if>
  145. order by ${sort}
  146. limit #{offset}, #{pageSize}
  147. </select>
  148. <select id="getVideoCategoryList" resultType="java.lang.String">
  149. select distinct category
  150. from content_platform_video_agg
  151. where dt = #{dt} and status = 1
  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 from content_platform_video_datastat_agg where dt = #{dt}
  294. </delete>
  295. <delete id="deleteContentPlatformVideoDatastat">
  296. delete from content_platform_video_datastat where dt = #{dt}
  297. </delete>
  298. <insert id="batchInsertContentPlatformVideoDatastat">
  299. insert into content_platform_video_datastat (dt, video_id, `type`, channel, first_level, fission0,
  300. fission_rate, create_timestamp)
  301. values
  302. <foreach collection="records" item="item" separator=",">
  303. (#{item.dt}, #{item.videoId}, #{item.type}, #{item.channel}, #{item.firstLevel},
  304. #{item.fission0}, #{item.fissionRate}, #{item.createTimestamp})
  305. </foreach>
  306. </insert>
  307. <insert id="batchInsertContentPlatformVideoDatastatAgg">
  308. insert into content_platform_video_datastat_agg (dt, video_id, `type`, channel, first_level, fission0,
  309. fission_rate, create_timestamp)
  310. values
  311. <foreach collection="records" item="item" separator=",">
  312. (#{item.dt}, #{item.videoId}, #{item.type}, #{item.channel}, #{item.firstLevel},
  313. #{item.fission0}, #{item.fissionRate}, #{item.createTimestamp})
  314. </foreach>
  315. </insert>
  316. <update id="updateOtherVideoStatus">
  317. update content_platform_video
  318. set status = 0,
  319. update_timestamp = #{now}
  320. where dt = #{dt} and video_id not in
  321. <foreach collection="videoIdList" item="item" open="(" close=")" separator=",">
  322. #{item}
  323. </foreach>
  324. </update>
  325. <select id="getGzhPlanIllegalVideoList"
  326. resultType="com.tzld.piaoquan.api.model.po.contentplatform.PlanIllegalVideoDTO">
  327. select plan.create_account_id as account_id, plan.type, video.video_id, '公众号' as channel,
  328. coalesce(nullif(video.custom_title, ''), video.title) as title
  329. from content_platform_gzh_plan plan
  330. join content_platform_gzh_plan_video video on plan.id = video.plan_id
  331. where video.video_id = #{videoId} and plan.`status` = 1
  332. </select>
  333. <select id="getQwPlanIllegalVideoList"
  334. resultType="com.tzld.piaoquan.api.model.po.contentplatform.PlanIllegalVideoDTO">
  335. select plan.create_account_id as account_id, plan.type, video.video_id, '企微' as channel, video.title
  336. from content_platform_qw_plan plan
  337. join content_platform_qw_plan_video video on plan.id = video.plan_id
  338. where video.video_id = #{videoId} and plan.`status` = 1
  339. </select>
  340. </mapper>