FsCourseWatchLogMapper.xml 37 KB

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