FsCourseWatchLogMapper.xml 51 KB

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