FsCourseWatchLogMapper.xml 34 KB

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