FsCourseWatchLogMapper.xml 37 KB

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