FsCourseWatchLogMapper.xml 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.course.mapper.FsCourseWatchLogMapper">
  6. <resultMap type="FsCourseWatchLog" id="FsCourseWatchLogResult">
  7. <result property="logId" column="log_id" />
  8. <result property="userId" column="user_id" />
  9. <result property="videoId" column="video_id" />
  10. <result property="logType" column="log_type" />
  11. <result property="createTime" column="create_time" />
  12. <result property="updateTime" column="update_time" />
  13. <result property="qwExternalContactId" column="qw_external_contact_id" />
  14. <result property="duration" column="duration" />
  15. <result property="qwUserId" column="qw_user_id" />
  16. <result property="companyUserId" column="company_user_id" />
  17. <result property="companyId" column="company_id" />
  18. <result property="courseId" column="course_id" />
  19. <result property="sendType" column="send_type" />
  20. <result property="rewardType" column="reward_type" />
  21. <result property="sopId" column="sop_id" />
  22. <result property="finishTime" column="finish_time" />
  23. <result property="sendFinishMsg" column="send_finish_msg" />
  24. <result property="campPeriodTime" column="camp_period_time" />
  25. <result property="lastHeartbeatTime" column="last_heartbeat_time" />
  26. <result property="project" column="project" />
  27. </resultMap>
  28. <sql id="selectFsCourseWatchLogVo">
  29. select log_id, user_id,finish_time,send_finish_msg,sop_id,video_id,reward_type, log_type, create_time, update_time, qw_external_contact_id, duration, qw_user_id, company_user_id, company_id, course_id,camp_period_time,project from fs_course_watch_log
  30. </sql>
  31. <select id="selectFsCourseWatchLogList" parameterType="FsCourseWatchLog" resultMap="FsCourseWatchLogResult">
  32. <include refid="selectFsCourseWatchLogVo"/>
  33. <where>
  34. <if test="userId != null "> and user_id = #{userId}</if>
  35. <if test="videoId != null "> and video_id = #{videoId}</if>
  36. <if test="logType != null "> and log_type = #{logType}</if>
  37. <if test="qwExternalContactId != null "> and qw_external_contact_id = #{qwExternalContactId}</if>
  38. <if test="duration != null "> and duration = #{duration}</if>
  39. <if test="qwUserId != null and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
  40. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  41. <if test="companyId != null "> and company_id = #{companyId}</if>
  42. <if test="courseId != null "> and course_id = #{courseId}</if>
  43. <if test="sendType != null "> and send_type = #{sendType}</if>
  44. <if test="campPeriodTime != null "> and camp_period_time = #{campPeriodTime}</if>
  45. <if test="project != null "> and project = #{project}</if>
  46. </where>
  47. </select>
  48. <select id="selectFsCourseWatchLogByLogId" parameterType="Long" resultMap="FsCourseWatchLogResult">
  49. <include refid="selectFsCourseWatchLogVo"/>
  50. where log_id = #{logId}
  51. </select>
  52. <select id="selectFsCourseWatchLogListVO" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  53. select l.log_id,l.user_id,uc.course_name,v.title as video_name,qec.avatar as external_user_avatar,
  54. l.log_type,SEC_TO_TIME(l.duration) as duration,c.company_name,l.camp_period_time,l.finish_time,
  55. cu.nick_name as company_user_name ,l.send_type,l.create_time,l.update_time,l.last_heartbeat_time,
  56. qu.qw_user_name,qec.name as external_user_name,c.company_id,u.avatar as fsAvatar,u.nick_name as fsNickName,qec.create_time as qec_create_time,
  57. u.is_vip isVip, l.project, l.im_msg_send_detail_id
  58. from fs_course_watch_log l
  59. left join fs_user_course_video v on v.video_id = l.video_id
  60. left join fs_user_course uc on uc.course_id = l.course_id
  61. left join fs_user u on u.user_id = l.user_id
  62. left join company_user cu on cu.user_id = l.company_user_id
  63. left join company c on c.company_id = l.company_id
  64. LEFT JOIN qw_user qu on qu.id= l.qw_user_id
  65. LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  66. <where>
  67. <if test ='maps.isVip != null and maps.isVip == 0'>
  68. and (l.user_id = #{maps.isVip} or l.user_id is null)
  69. </if>
  70. <if test ='maps.isVip != null and maps.isVip == 1'>
  71. and l.user_id != 0 and l.user_id is not null
  72. </if>
  73. <if test ='maps.sendType !=null'>
  74. and l.send_type = #{maps.sendType}
  75. </if>
  76. <if test ='maps.userId !=null'>
  77. and l.user_id = #{maps.userId}
  78. </if>
  79. <if test ='maps.qwExternalContactId !=null'>
  80. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  81. </if>
  82. <if test ='maps.qwUserId !=null'>
  83. and l.qw_user_id = #{maps.qwUserId}
  84. </if>
  85. <if test ='maps.courseId !=null'>
  86. and l.course_id = #{maps.courseId}
  87. </if>
  88. <if test ='maps.videoId !=null'>
  89. and l.video_id = #{maps.videoId}
  90. </if>
  91. <if test ='maps.logType !=null'>
  92. and l.log_type = #{maps.logType}
  93. </if>
  94. <if test ='maps.companyId !=null'>
  95. and l.company_id = #{maps.companyId}
  96. </if>
  97. <if test ='maps.companyUserId !=null'>
  98. and l.company_user_id = #{maps.companyUserId}
  99. </if>
  100. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  101. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  102. </if>
  103. <if test ='maps.nickName !=null and maps.nickName!=""'>
  104. and u.nick_name like concat('%', #{maps.nickName}, '%')
  105. </if>
  106. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  107. and qec.name like concat('%', #{maps.externalUserName}, '%')
  108. </if>
  109. <if test= 'maps.qecSTime != null '>
  110. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  111. </if>
  112. <if test='maps.qecETime != null '>
  113. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  114. </if>
  115. <if test= 'maps.sTime != null '>
  116. and DATE(l.create_time) &gt;= DATE(#{maps.sTime})
  117. </if>
  118. <if test='maps.eTime != null '>
  119. and DATE(l.create_time) &lt;= DATE(#{maps.eTime})
  120. </if>
  121. <if test= 'maps.scheduleStartTime != null '>
  122. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  123. </if>
  124. <if test='maps.scheduleEndTime != null '>
  125. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  126. </if>
  127. <if test= 'maps.upSTime != null '>
  128. and DATE(l.update_time) &gt;= DATE(#{maps.upSTime})
  129. </if>
  130. <if test='maps.upETime != null '>
  131. and DATE(l.update_time) &lt;= DATE(#{maps.upETime})
  132. </if>
  133. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  134. and l.sop_id in
  135. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  136. #{sopId}
  137. </foreach>
  138. </if>
  139. <if test ='maps.project !=null'>
  140. and l.project = #{maps.project}
  141. </if>
  142. <if test="maps.sopId != null and maps.sopId != '' ">
  143. and l.sop_id = #{maps.sopId}
  144. </if>
  145. </where>
  146. order by l.finish_time desc,l.update_time desc,l.create_time desc
  147. </select>
  148. <select id="selectFsCourseWatchLogListByParam" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  149. select l.log_id,l.user_id,uc.course_name,v.title as video_name,u.nick_name as fsNickName, u.avatar as fsAvatar,
  150. l.log_type,SEC_TO_TIME(l.duration) as duration,c.company_name,l.camp_period_time,l.finish_time,
  151. cu.nick_name as company_user_name ,l.send_type,l.create_time, qu.qw_user_name,qec.name as external_user_name
  152. from fs_course_watch_log l
  153. left join fs_user_course_video v on v.video_id = l.video_id
  154. left join fs_user_course uc on uc.course_id = l.course_id
  155. left join fs_user u on u.user_id = l.user_id
  156. left join company_user cu on cu.user_id = l.company_user_id
  157. left join company c on c.company_id = l.company_id
  158. LEFT JOIN qw_user qu on qu.id= l.qw_user_id
  159. LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  160. <where>
  161. <if test ='userId !=null'>
  162. and l.user_id = #{userId}
  163. </if>
  164. <if test ='qwUserId !=null'>
  165. and l.qw_user_id = #{qwUserId}
  166. </if>
  167. <if test ='courseId !=null'>
  168. and l.course_id = #{courseId}
  169. </if>
  170. <if test ='videoId !=null'>
  171. and l.video_id = #{videoId}
  172. </if>
  173. <if test ='logType !=null'>
  174. and l.log_type = #{logType}
  175. </if>
  176. <if test ='companyId !=null'>
  177. and l.company_id = #{companyId}
  178. </if>
  179. <if test ='companyUserId !=null'>
  180. and l.company_user_id = #{companyUserId}
  181. </if>
  182. <if test ='companyUserName !=null and maps.companyUserName!=""'>
  183. and cu.nick_name like concat('%', #{companyUserName}, '%')
  184. </if>
  185. <if test ='nickName !=null and maps.nickName!=""'>
  186. and u.nick_name like concat('%', #{nickName}, '%')
  187. </if>
  188. <if test= 'sTime != null '>
  189. and DATE(l.create_time) &gt;= DATE(#{sTime})
  190. </if>
  191. <if test='eTime != null '>
  192. and DATE(l.create_time) &lt;= DATE(#{eTime})
  193. </if>
  194. <if test= 'maps.scheduleStartTime != null '>
  195. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  196. </if>
  197. <if test='maps.scheduleEndTime != null '>
  198. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  199. </if>
  200. <if test="sopIds != null and sopIds.size() > 0">
  201. and l.sop_id in
  202. <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
  203. #{sopId}
  204. </foreach>
  205. </if>
  206. </where>
  207. order by l.log_id desc
  208. </select>
  209. <insert id="insertFsCourseWatchLog" parameterType="FsCourseWatchLog" useGeneratedKeys="true" keyProperty="logId">
  210. insert into fs_course_watch_log
  211. <trim prefix="(" suffix=")" suffixOverrides=",">
  212. <if test="userId != null">user_id,</if>
  213. <if test="videoId != null">video_id,</if>
  214. <if test="logType != null">log_type,</if>
  215. <if test="createTime != null">create_time,</if>
  216. <if test="updateTime != null">update_time,</if>
  217. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  218. <if test="duration != null">duration,</if>
  219. <if test="qwUserId != null">qw_user_id,</if>
  220. <if test="companyUserId != null">company_user_id,</if>
  221. <if test="companyId != null">company_id,</if>
  222. <if test="courseId != null">course_id,</if>
  223. <if test="sendType != null">send_type,</if>
  224. <if test="rewardType != null">reward_type,</if>
  225. <if test="sopId != null">sop_id,</if>
  226. <if test="finishTime != null">finish_time,</if>
  227. <if test="sendFinishMsg != null">send_finish_msg,</if>
  228. <if test="campPeriodTime != null">camp_period_time,</if>
  229. <if test="periodId != null">period_id,</if>
  230. <if test="project != null">project,</if>
  231. </trim>
  232. <trim prefix="values (" suffix=")" suffixOverrides=",">
  233. <if test="userId != null">#{userId},</if>
  234. <if test="videoId != null">#{videoId},</if>
  235. <if test="logType != null">#{logType},</if>
  236. <if test="createTime != null">#{createTime},</if>
  237. <if test="updateTime != null">#{updateTime},</if>
  238. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  239. <if test="duration != null">#{duration},</if>
  240. <if test="qwUserId != null">#{qwUserId},</if>
  241. <if test="companyUserId != null">#{companyUserId},</if>
  242. <if test="companyId != null">#{companyId},</if>
  243. <if test="courseId != null">#{courseId},</if>
  244. <if test="sendType != null">#{sendType},</if>
  245. <if test="rewardType != null">#{rewardType},</if>
  246. <if test="sopId != null">#{sopId},</if>
  247. <if test="finishTime != null">#{finishTime},</if>
  248. <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
  249. <if test="campPeriodTime != null">#{campPeriodTime},</if>
  250. <if test="periodId != null">#{periodId},</if>
  251. <if test="project != null">#{project},</if>
  252. </trim>
  253. </insert>
  254. <insert id="insertOrUpdateFsCourseWatchLog" parameterType="FsCourseWatchLog">
  255. insert into fs_course_watch_log
  256. <trim prefix="(" suffix=")" suffixOverrides=",">
  257. <if test="userId != null">user_id,</if>
  258. <if test="videoId != null">video_id,</if>
  259. <if test="logType != null">log_type,</if>
  260. <if test="createTime != null">create_time,</if>
  261. <if test="updateTime != null">update_time,</if>
  262. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  263. <if test="duration != null">duration,</if>
  264. <if test="qwUserId != null">qw_user_id,</if>
  265. <if test="companyUserId != null">company_user_id,</if>
  266. <if test="companyId != null">company_id,</if>
  267. <if test="courseId != null">course_id,</if>
  268. <if test="sendType != null">send_type,</if>
  269. <if test="rewardType != null">reward_type,</if>
  270. <if test="sopId != null">sop_id,</if>
  271. <if test="finishTime != null">finish_time,</if>
  272. <if test="sendFinishMsg != null">send_finish_msg,</if>
  273. <if test="campPeriodTime != null">camp_period_time,</if>
  274. <if test="project != null">project,</if>
  275. </trim>
  276. <trim prefix="values (" suffix=")" suffixOverrides=",">
  277. <if test="userId != null">#{userId},</if>
  278. <if test="videoId != null">#{videoId},</if>
  279. <if test="logType != null">#{logType},</if>
  280. <if test="createTime != null">#{createTime},</if>
  281. <if test="updateTime != null">#{updateTime},</if>
  282. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  283. <if test="duration != null">#{duration},</if>
  284. <if test="qwUserId != null">#{qwUserId},</if>
  285. <if test="companyUserId != null">#{companyUserId},</if>
  286. <if test="companyId != null">#{companyId},</if>
  287. <if test="courseId != null">#{courseId},</if>
  288. <if test="sendType != null">#{sendType},</if>
  289. <if test="rewardType != null">#{rewardType},</if>
  290. <if test="sopId != null">#{sopId},</if>
  291. <if test="finishTime != null">#{finishTime},</if>
  292. <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
  293. <if test="campPeriodTime != null">#{campPeriodTime},</if>
  294. <if test="project != null">#{project},</if>
  295. </trim>
  296. on duplicate key update
  297. <trim suffixOverrides=",">
  298. <if test="updateTime != null">update_time = #{updateTime},</if>
  299. </trim>
  300. </insert>
  301. <insert id="insertFsCourseWatchLogBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="logId">
  302. INSERT INTO fs_course_watch_log (
  303. user_id,
  304. video_id,
  305. log_type,
  306. create_time,
  307. update_time,
  308. qw_external_contact_id,
  309. duration,
  310. qw_user_id,
  311. company_user_id,
  312. company_id,
  313. course_id,
  314. send_type,
  315. reward_type,
  316. sop_id,
  317. camp_period_time,
  318. project,
  319. period_id,
  320. im_msg_send_detail_id
  321. )
  322. VALUES
  323. <foreach collection="watchLogs" item="log" separator=",">
  324. (
  325. #{log.userId},
  326. #{log.videoId},
  327. #{log.logType},
  328. #{log.createTime},
  329. #{log.updateTime},
  330. #{log.qwExternalContactId},
  331. #{log.duration},
  332. #{log.qwUserId},
  333. #{log.companyUserId},
  334. #{log.companyId},
  335. #{log.courseId},
  336. #{log.sendType},
  337. #{log.rewardType},
  338. #{log.sopId},
  339. #{log.campPeriodTime},
  340. #{log.project},
  341. #{log.periodId},
  342. #{log.imMsgSendDetailId}
  343. )
  344. </foreach>
  345. ON DUPLICATE KEY UPDATE
  346. update_time = NOW(),
  347. im_msg_send_detail_id = VALUES(im_msg_send_detail_id)
  348. </insert>
  349. <update id="updateFsCourseWatchLog" parameterType="FsCourseWatchLog">
  350. update fs_course_watch_log
  351. <trim prefix="SET" suffixOverrides=",">
  352. <if test="userId != null">user_id = #{userId},</if>
  353. <if test="videoId != null">video_id = #{videoId},</if>
  354. <if test="logType != null">log_type = #{logType},</if>
  355. <if test="createTime != null">create_time = #{createTime},</if>
  356. <if test="updateTime != null">update_time = #{updateTime},</if>
  357. <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
  358. <if test="duration != null">duration = #{duration},</if>
  359. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  360. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  361. <if test="companyId != null">company_id = #{companyId},</if>
  362. <if test="courseId != null">course_id = #{courseId},</if>
  363. <if test="sendType != null">send_type = #{sendType},</if>
  364. <if test="rewardType != null">reward_type = #{rewardType},</if>
  365. <if test="sopId != null">sop_id = #{sopId},</if>
  366. <if test="finishTime != null">finish_time = #{finishTime},</if>
  367. <if test="sendFinishMsg != null">send_finish_msg = #{sendFinishMsg},</if>
  368. <if test="lastHeartbeatTime != null">last_heartbeat_time = #{lastHeartbeatTime},</if>
  369. <if test="periodId != null">period_id = #{periodId},</if>
  370. <if test="project != null">project = #{project},</if>
  371. </trim>
  372. where log_id = #{logId}
  373. </update>
  374. <delete id="deleteFsCourseWatchLogByLogId" parameterType="Long">
  375. delete from fs_course_watch_log where log_id = #{logId}
  376. </delete>
  377. <delete id="deleteFsCourseWatchLogByLogIds" parameterType="String">
  378. delete from fs_course_watch_log where log_id in
  379. <foreach item="logId" collection="array" open="(" separator="," close=")">
  380. #{logId}
  381. </foreach>
  382. </delete>
  383. <select id="selectFsCourseWatchLogByFinishTime" resultType="com.fs.course.param.FsCourseWatchLogByFinishTimeParam">
  384. <![CDATA[
  385. SELECT
  386. fcwl.log_id,
  387. fcwl.create_time,
  388. fcwl.qw_external_contact_id,
  389. fcwl.qw_user_id,
  390. fcwl.user_id,
  391. fcwl.company_user_id,
  392. fcwl.company_id,
  393. fcwl.sop_id,
  394. fcwl.finish_time,
  395. fcwl.camp_period_time,
  396. qec.corp_id,
  397. qec.external_user_id,
  398. qec.tag_ids,
  399. qec.user_id AS qw_user,
  400. qec.name AS external_contact_name
  401. FROM
  402. fs_course_watch_log fcwl
  403. LEFT JOIN qw_external_contact qec ON fcwl.qw_external_contact_id = qec.id
  404. WHERE
  405. DATE(fcwl.finish_time)= '2025-02-09'
  406. and fcwl.camp_period_time is not NULL
  407. ]]>
  408. </select>
  409. <select id="getWatchLogByFsUser" resultType="com.fs.course.domain.FsCourseWatchLog">
  410. SELECT
  411. log_id,
  412. user_id,
  413. video_id,
  414. log_type,
  415. create_time,
  416. update_time,
  417. duration,
  418. company_user_id,
  419. company_id,
  420. course_id,
  421. send_type,
  422. reward_type,
  423. last_heartbeat_time,
  424. sop_id,
  425. finish_time,
  426. send_finish_msg,
  427. camp_period_time
  428. FROM
  429. fs_course_watch_log
  430. WHERE
  431. send_type = 1
  432. AND video_id = #{videoId}
  433. AND user_id = #{fsUserId}
  434. AND company_user_id = #{companyUserId} order by log_id desc limit 1
  435. </select>
  436. <select id="selectFsCourseWatchLogStatisticsListVONew"
  437. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO">
  438. SELECT
  439. o.company_user_id,o.user_id,DATE(o.create_time) create_time,
  440. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  441. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  442. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  443. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4,
  444. o.project as project,
  445. o.course_id as course_id,
  446. o.video_id as video_id
  447. FROM fs_course_watch_log o
  448. <where>
  449. send_type=1
  450. <if test="companyId != null">
  451. and o.company_id=#{companyId}
  452. </if>
  453. <if test= 'sTime != null '>
  454. and o.create_time &gt;= #{sTime}
  455. </if>
  456. <if test='eTime != null '>
  457. and o.create_time &lt;= #{eTime}
  458. </if>
  459. <if test ='courseId !=null'>
  460. and o.course_id = #{courseId}
  461. </if>
  462. <if test ='videoId !=null'>
  463. and o.video_id = #{videoId}
  464. </if>
  465. <if test="companyUserId != null">
  466. and o.company_user_id = #{companyUserId}
  467. </if>
  468. <if test="project != null">
  469. and o.project = #{project}
  470. </if>
  471. <if test="userId != null">
  472. and o.user_id = #{userId}
  473. </if>
  474. </where>
  475. GROUP BY o.video_id,o.user_id,DATE(o.create_time),o.project,o.course_id
  476. ORDER BY o.video_id ,DATE(o.create_time)
  477. limit ${(pageNum-1)*pageSize},${pageSize}
  478. </select>
  479. <select id="selectFsCourseWatchLogStatisticsListVONewCount" resultType="java.lang.Long">
  480. SELECT COUNT(*)
  481. FROM (
  482. SELECT 1
  483. FROM fs_course_watch_log o
  484. <where>
  485. send_type=2
  486. <if test="companyId != null">
  487. and o.company_id=#{companyId}
  488. </if>
  489. <if test= 'sTime != null '>
  490. and o.create_time &gt;= #{startDate}
  491. </if>
  492. <if test='eTime != null '>
  493. and o.create_time &lt;= #{endDate}
  494. </if>
  495. <if test ='courseId !=null'>
  496. and o.course_id = #{courseId}
  497. </if>
  498. <if test ='videoId !=null'>
  499. and o.video_id = #{videoId}
  500. </if>
  501. <if test="companyUserId != null">
  502. and o.company_user_id = #{companyUserId}
  503. </if>
  504. <if test="project != null">
  505. and o.project = #{project}
  506. </if>
  507. <if test="userId != null">
  508. and o.user_id = #{userId}
  509. </if>
  510. </where>
  511. GROUP BY o.video_id, o.user_id, DATE(o.create_time), o.project, o.course_id
  512. ) AS grouped_results_count
  513. </select>
  514. <!-- 根据条件查询条数 -->
  515. <select id="countByMap" resultType="java.lang.Integer">
  516. select count(fcwl.log_id) from fs_course_watch_log fcwl
  517. <where>
  518. <if test="params.logTypes != null and params.logTypes.size() > 0">
  519. and fcwl.log_type in
  520. <foreach collection="params.logTypes" open="(" close=")" separator="," item="logType">
  521. #{logType}
  522. </foreach>
  523. </if>
  524. <if test="params.companyUserId != null">
  525. and fcwl.company_user_id = #{params.companyUserId}
  526. </if>
  527. <if test="params.date != null">
  528. and date(fcwl.create_time) = #{params.date}
  529. </if>
  530. </where>
  531. </select>
  532. <update id="batchUpdateWatchLog" parameterType="java.util.List">
  533. UPDATE fs_course_watch_log
  534. SET
  535. duration = CASE
  536. <foreach collection="list" item="item" index="index">
  537. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  538. CASE
  539. <!-- 仅当传入的duration > 当前值时才更新 -->
  540. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  541. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  542. END
  543. </foreach>
  544. END,
  545. last_heartbeat_time = CASE
  546. <foreach collection="list" item="item" index="index">
  547. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  548. CASE
  549. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  550. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  551. END
  552. </foreach>
  553. END,
  554. finish_time = CASE
  555. <foreach collection="list" item="item" index="index">
  556. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  557. CASE
  558. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  559. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  560. END
  561. </foreach>
  562. END,
  563. log_type = CASE
  564. <foreach collection="list" item="item" index="index">
  565. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  566. CASE
  567. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  568. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  569. ELSE log_type <!-- 其他情况保持原值 -->
  570. END
  571. </foreach>
  572. END
  573. WHERE
  574. (video_id, qw_external_contact_id, qw_user_id) IN
  575. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  576. (#{item.videoId}, #{item.qwExternalContactId}, #{item.qwUserId})
  577. </foreach>
  578. </update>
  579. <update id="batchUpdateWatchLogSendMsg" parameterType="java.util.List">
  580. UPDATE fs_course_watch_log
  581. SET send_finish_msg = CASE
  582. <foreach collection="list" item="item">
  583. WHEN log_id = #{item.logId} THEN #{item.sendFinishMsg}
  584. </foreach>
  585. ELSE send_finish_msg
  586. END
  587. WHERE log_id IN
  588. <foreach collection="list" item="item" open="(" separator="," close=")">
  589. #{item.logId}
  590. </foreach>
  591. </update>
  592. <update id="batchUpdateFsUserWatchLog" parameterType="java.util.List">
  593. UPDATE fs_course_watch_log
  594. SET
  595. duration = CASE
  596. <foreach collection="list" item="item" index="index">
  597. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  598. CASE
  599. <!-- 仅当传入的duration > 当前值时才更新 -->
  600. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  601. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  602. END
  603. </foreach>
  604. END,
  605. last_heartbeat_time = CASE
  606. <foreach collection="list" item="item" index="index">
  607. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  608. CASE
  609. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  610. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  611. END
  612. </foreach>
  613. END,
  614. finish_time = CASE
  615. <foreach collection="list" item="item" index="index">
  616. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  617. CASE
  618. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  619. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  620. END
  621. </foreach>
  622. END,
  623. log_type = CASE
  624. <foreach collection="list" item="item" index="index">
  625. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  626. CASE
  627. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  628. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  629. ELSE log_type <!-- 其他情况保持原值 -->
  630. END
  631. </foreach>
  632. END
  633. WHERE
  634. (video_id, user_id, company_user_id) IN
  635. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  636. (#{item.videoId}, #{item.userId}, #{item.companyUserId})
  637. </foreach>
  638. </update>
  639. <update id="batchUpdateWatchLogIsOpen">
  640. UPDATE fs_course_watch_log
  641. SET
  642. duration = CASE
  643. <foreach collection="list" item="item" index="index">
  644. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  645. CASE
  646. <!-- 仅当传入的duration > 当前值时才更新 -->
  647. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  648. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  649. END
  650. </foreach>
  651. END,
  652. last_heartbeat_time = CASE
  653. <foreach collection="list" item="item" index="index">
  654. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  655. CASE
  656. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  657. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  658. END
  659. </foreach>
  660. END,
  661. finish_time = CASE
  662. <foreach collection="list" item="item" index="index">
  663. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  664. CASE
  665. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  666. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  667. END
  668. </foreach>
  669. END,
  670. log_type = CASE
  671. <foreach collection="list" item="item" index="index">
  672. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  673. CASE
  674. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  675. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  676. ELSE log_type <!-- 其他情况保持原值 -->
  677. END
  678. </foreach>
  679. END
  680. WHERE
  681. (video_id, user_id) IN
  682. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  683. (#{item.videoId}, #{item.userId})
  684. </foreach>
  685. </update>
  686. <select id="selectListBytrainingCampId" resultType="com.fs.course.vo.FsCourseWatchLogVO">
  687. select
  688. uc.course_name,v.title as video_name,
  689. watch.log_id,
  690. watch.user_id,
  691. watch.finish_time,
  692. watch.send_finish_msg,
  693. watch.sop_id,
  694. watch.video_id,
  695. watch.reward_type,
  696. watch.log_type,
  697. watch.create_time,
  698. watch.update_time,
  699. watch.qw_external_contact_id,
  700. watch.duration,
  701. watch.qw_user_id,
  702. watch.company_user_id,
  703. watch.company_id,
  704. watch.course_id,
  705. watch.camp_period_time
  706. from
  707. fs_user_course_training_camp camp
  708. left join fs_user_course_period period on
  709. camp.training_camp_id = period.training_camp_id
  710. left join fs_course_watch_log watch on
  711. period.period_id = watch.period_id
  712. left join fs_user_course uc on uc.course_id = watch.course_id
  713. left join fs_user_course_video v on v.video_id = watch.video_id
  714. <where>
  715. `period`.del_flag = '0' and watch.log_type &lt;&gt; 3
  716. <if test="trainingCampId != null">and camp.training_camp_id = #{trainingCampId}</if>
  717. <if test="userId != null">and watch.user_id = #{userId}</if>
  718. <if test="periodId != null">and `period`.period_id = #{periodId}</if>
  719. </where>
  720. </select>
  721. <select id="selectFsCourseWatchLogListVOexport" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  722. SELECT
  723. l.log_id,
  724. l.project AS project,
  725. l.user_id,
  726. l.log_type,
  727. SEC_TO_TIME(l.duration) AS duration,
  728. l.camp_period_time,
  729. l.finish_time,
  730. l.send_type,
  731. l.create_time,
  732. l.update_time,
  733. l.last_heartbeat_time,
  734. l.company_id,
  735. l.company_user_id,
  736. l.course_id,
  737. l.video_id,
  738. l.qw_user_id,
  739. l.qw_external_contact_id,
  740. qec.create_time as qec_create_time
  741. FROM
  742. fs_course_watch_log l LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  743. left join fs_user u on u.user_id = l.user_id
  744. left join company_user cu on cu.user_id = l.company_user_id
  745. <where>
  746. <if test ='maps.sendType !=null'>
  747. and l.send_type = #{maps.sendType}
  748. </if>
  749. <if test ='maps.userId !=null'>
  750. and l.user_id = #{maps.userId}
  751. </if>
  752. <if test ='maps.qwExternalContactId !=null'>
  753. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  754. </if>
  755. <if test ='maps.qwUserId !=null'>
  756. and l.qw_user_id = #{maps.qwUserId}
  757. </if>
  758. <if test ='maps.courseId !=null'>
  759. and l.course_id = #{maps.courseId}
  760. </if>
  761. <if test ='maps.videoId !=null'>
  762. and l.video_id = #{maps.videoId}
  763. </if>
  764. <if test ='maps.logType !=null'>
  765. and l.log_type = #{maps.logType}
  766. </if>
  767. <if test ='maps.companyId !=null'>
  768. and l.company_id = #{maps.companyId}
  769. </if>
  770. <if test ='maps.companyUserId !=null'>
  771. and l.company_user_id = #{maps.companyUserId}
  772. </if>
  773. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  774. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  775. </if>
  776. <if test ='maps.nickName !=null and maps.nickName!=""'>
  777. and u.nick_name like concat('%', #{maps.nickName}, '%')
  778. </if>
  779. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  780. and qec.name like concat('%', #{maps.externalUserName}, '%')
  781. </if>
  782. <if test= 'maps.qecSTime != null '>
  783. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  784. </if>
  785. <if test='maps.qecETime != null '>
  786. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  787. </if>
  788. <if test= 'maps.sTime != null '>
  789. and DATE(l.create_time) &gt;= DATE(#{maps.sTime})
  790. </if>
  791. <if test='maps.eTime != null '>
  792. and DATE(l.create_time) &lt;= DATE(#{maps.eTime})
  793. </if>
  794. <if test= 'maps.scheduleStartTime != null '>
  795. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  796. </if>
  797. <if test='maps.scheduleEndTime != null '>
  798. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  799. </if>
  800. <if test= 'maps.upSTime != null '>
  801. and DATE(l.update_time) &gt;= DATE(#{maps.upSTime})
  802. </if>
  803. <if test='maps.upETime != null '>
  804. and DATE(l.update_time) &lt;= DATE(#{maps.upETime})
  805. </if>
  806. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  807. and l.sop_id in
  808. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  809. #{sopId}
  810. </foreach>
  811. </if>
  812. </where>
  813. order by l.finish_time desc,l.update_time desc,l.create_time desc
  814. </select>
  815. <select id="getWatchCourseByVideoId" resultType="com.fs.course.domain.FsCourseWatchLog">
  816. SELECT
  817. *
  818. FROM
  819. fs_course_watch_log
  820. WHERE
  821. send_type = 1
  822. AND video_id = #{videoId}
  823. AND user_id in
  824. <foreach item="userId" index="index" collection="userIds" open="(" separator="," close=")">
  825. #{userId}
  826. </foreach>
  827. ORDER BY
  828. log_id DESC
  829. </select>
  830. <select id="getUserCountByCampId" resultType="java.lang.Integer">
  831. select count(distinct cwl.user_id)
  832. from fs_user_course_period ucp
  833. inner join fs_course_watch_log cwl on ucp.period_id = cwl.period_id
  834. where ucp.training_camp_id = #{trainingCampId}
  835. </select>
  836. </mapper>