FsCourseWatchLogMapper.xml 48 KB

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