FsCourseWatchLogMapper.xml 42 KB

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