FsCourseWatchLogMapper.xml 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559
  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,qec.status as externalStatus,
  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, l.watch_type,qec.tag_ids,u.last_ip
  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; date_add(#{maps.upETime}, interval 1 day)
  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.externalStatus != null and maps.externalStatus != '' ">
  160. and qec.status = #{maps.externalStatus}
  161. </if>
  162. <if test="maps.periodId != null">
  163. and l.period_id = #{maps.periodId}
  164. </if>
  165. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  166. and l.period_id in
  167. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  168. #{periodId}
  169. </foreach>
  170. </if>
  171. <if test="maps.qwUserName != null and maps.qwUserName != '' ">
  172. and qu.qw_user_name = #{maps.qwUserName}
  173. </if>
  174. <if test="maps.deptId != null and maps.deptId != '' ">
  175. and cu.dept_id = #{maps.deptId}
  176. </if>
  177. <if test='maps.cuDeptIdList != null and !maps.cuDeptIdList.isEmpty() and maps.userType != "00" '>
  178. AND cu.dept_id IN
  179. <foreach collection='maps.cuDeptIdList' item='item' open='(' separator=',' close=')'>
  180. #{item}
  181. </foreach>
  182. </if>
  183. <if test="maps.userIds != null and !maps.userIds.isEmpty()">
  184. AND cu.user_id IN
  185. <foreach collection='maps.userIds' item='item' open='(' separator=',' close=')'>
  186. #{item}
  187. </foreach>
  188. </if>
  189. </where>
  190. order by l.finish_time desc,l.update_time desc,l.create_time desc
  191. </select>
  192. <select id="selectFsCourseWatchLogListByWatchLogVO" resultType="com.fs.qw.domain.QwExternalContact">
  193. select qec.id,qec.user_id,qec.external_user_id,qec.corp_id,qec.tag_ids,qec.name
  194. from fs_course_watch_log l
  195. left join fs_user u on u.user_id = l.user_id
  196. left join company_user cu on cu.user_id = l.company_user_id
  197. LEFT JOIN qw_user qu on qu.id= l.qw_user_id
  198. LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  199. <where>
  200. <if test ='maps.isVip != null and maps.isVip == 0'>
  201. and (l.user_id = 0 or l.user_id is null)
  202. </if>
  203. <if test ='maps.isVip != null and maps.isVip == 1'>
  204. and l.user_id != 0 and l.user_id is not null
  205. </if>
  206. <if test ='maps.sendType !=null'>
  207. and l.send_type = #{maps.sendType}
  208. </if>
  209. <if test ='maps.userId !=null'>
  210. and l.user_id = #{maps.userId}
  211. </if>
  212. <if test ='maps.logId !=null'>
  213. and l.log_id = #{maps.logId}
  214. </if>
  215. <if test ='maps.project !=null'>
  216. and l.project = #{maps.project}
  217. </if>
  218. <if test ='maps.qwExternalContactId !=null'>
  219. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  220. </if>
  221. <if test ='maps.qwUserId !=null'>
  222. and l.qw_user_id = #{maps.qwUserId}
  223. </if>
  224. <if test ='maps.courseId !=null'>
  225. and l.course_id = #{maps.courseId}
  226. </if>
  227. <if test ='maps.videoId !=null'>
  228. and l.video_id = #{maps.videoId}
  229. </if>
  230. <if test ='maps.logType !=null'>
  231. and l.log_type = #{maps.logType}
  232. </if>
  233. <if test ='maps.companyId !=null'>
  234. and l.company_id = #{maps.companyId}
  235. </if>
  236. <if test ='maps.watchType !=null'>
  237. and l.watch_type = #{maps.watchType}
  238. </if>
  239. <if test ='maps.companyUserId !=null'>
  240. and l.company_user_id = #{maps.companyUserId}
  241. </if>
  242. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  243. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  244. </if>
  245. <if test ='maps.nickName !=null and maps.nickName!=""'>
  246. and u.nick_name like concat('%', #{maps.nickName}, '%')
  247. </if>
  248. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  249. and qec.name like concat('%', #{maps.externalUserName}, '%')
  250. </if>
  251. <if test= 'maps.qecSTime != null '>
  252. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  253. </if>
  254. <if test='maps.qecETime != null '>
  255. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  256. </if>
  257. <if test= 'maps.sTime != null '>
  258. and l.create_time &gt;= #{maps.sTime}
  259. </if>
  260. <if test='maps.eTime != null '>
  261. and l.create_time &lt;= #{maps.eTime}
  262. </if>
  263. <if test= 'maps.scheduleStartTime != null '>
  264. and l.camp_period_time &gt;= #{maps.scheduleStartTime}
  265. </if>
  266. <if test='maps.scheduleEndTime != null '>
  267. and l.camp_period_time &lt;= #{maps.scheduleEndTime}
  268. </if>
  269. <if test= 'maps.upSTime != null '>
  270. and l.update_time &gt;= #{maps.upSTime}
  271. </if>
  272. <if test='maps.upETime != null '>
  273. and l.update_time &lt; date_add(#{maps.upETime}, interval 1 day)
  274. </if>
  275. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  276. and l.sop_id in
  277. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  278. #{sopId}
  279. </foreach>
  280. </if>
  281. <if test ='maps.project !=null'>
  282. and l.project = #{maps.project}
  283. </if>
  284. <if test="maps.sopId != null and maps.sopId != '' ">
  285. and l.sop_id = #{maps.sopId}
  286. </if>
  287. <if test="maps.externalStatus != null and maps.externalStatus != '' ">
  288. and qec.status = #{maps.externalStatus}
  289. </if>
  290. <if test="maps.periodId != null">
  291. and l.period_id = #{maps.periodId}
  292. </if>
  293. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  294. and l.period_id in
  295. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  296. #{periodId}
  297. </foreach>
  298. </if>
  299. <if test="maps.qwUserName != null and maps.qwUserName != '' ">
  300. and qu.qw_user_name = #{maps.qwUserName}
  301. </if>
  302. <if test="maps.deptId != null and maps.deptId != '' ">
  303. and cu.dept_id = #{maps.deptId}
  304. </if>
  305. <if test='maps.cuDeptIdList != null and !maps.cuDeptIdList.isEmpty() and maps.userType != "00" '>
  306. AND cu.dept_id IN
  307. <foreach collection='maps.cuDeptIdList' item='item' open='(' separator=',' close=')'>
  308. #{item}
  309. </foreach>
  310. </if>
  311. <if test="maps.userIds != null and !maps.userIds.isEmpty()">
  312. AND cu.user_id IN
  313. <foreach collection='maps.userIds' item='item' open='(' separator=',' close=')'>
  314. #{item}
  315. </foreach>
  316. </if>
  317. </where>
  318. GROUP BY
  319. qec.user_id,
  320. qec.external_user_id,
  321. qec.corp_id
  322. </select>
  323. <select id="selectFsCourseWatchLogListByParam" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  324. select l.log_id,l.user_id,uc.course_name,v.title as video_name,u.nick_name as fsNickName, u.avatar as fsAvatar,
  325. l.log_type,SEC_TO_TIME(l.duration) as duration,c.company_name,l.camp_period_time,l.finish_time,
  326. cu.nick_name as company_user_name ,l.send_type,l.create_time, qu.qw_user_name,qec.name as external_user_name
  327. from fs_course_watch_log l
  328. left join fs_user_course_video v on v.video_id = l.video_id
  329. left join fs_user_course uc on uc.course_id = l.course_id
  330. left join fs_user u on u.user_id = l.user_id
  331. left join company_user cu on cu.user_id = l.company_user_id
  332. left join company c on c.company_id = l.company_id
  333. LEFT JOIN qw_user qu on qu.id= l.qw_user_id
  334. LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  335. <where>
  336. <if test ='userId !=null'>
  337. and l.user_id = #{userId}
  338. </if>
  339. <if test ='qwUserId !=null'>
  340. and l.qw_user_id = #{qwUserId}
  341. </if>
  342. <if test ='courseId !=null'>
  343. and l.course_id = #{courseId}
  344. </if>
  345. <if test ='videoId !=null'>
  346. and l.video_id = #{videoId}
  347. </if>
  348. <if test ='logType !=null'>
  349. and l.log_type = #{logType}
  350. </if>
  351. <if test ='companyId !=null'>
  352. and l.company_id = #{companyId}
  353. </if>
  354. <if test ='companyUserId !=null'>
  355. and l.company_user_id = #{companyUserId}
  356. </if>
  357. <if test ='companyUserName !=null and maps.companyUserName!=""'>
  358. and cu.nick_name like concat('%', #{companyUserName}, '%')
  359. </if>
  360. <if test ='nickName !=null and maps.nickName!=""'>
  361. and u.nick_name like concat('%', #{nickName}, '%')
  362. </if>
  363. <if test= 'sTime != null '>
  364. and DATE(l.create_time) &gt;= DATE(#{sTime})
  365. </if>
  366. <if test='eTime != null '>
  367. and DATE(l.create_time) &lt;= DATE(#{eTime})
  368. </if>
  369. <if test= 'maps.scheduleStartTime != null '>
  370. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  371. </if>
  372. <if test='maps.scheduleEndTime != null '>
  373. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  374. </if>
  375. <if test="sopIds != null and sopIds.size() > 0">
  376. and l.sop_id in
  377. <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
  378. #{sopId}
  379. </foreach>
  380. </if>
  381. <if test="maps.watchType != null "> and l.watch_type = #{maps.watchType}</if>
  382. </where>
  383. order by l.log_id desc
  384. </select>
  385. <insert id="insertFsCourseWatchLog" parameterType="FsCourseWatchLog" useGeneratedKeys="true" keyProperty="logId">
  386. insert into fs_course_watch_log
  387. <trim prefix="(" suffix=")" suffixOverrides=",">
  388. <if test="userId != null">user_id,</if>
  389. <if test="videoId != null">video_id,</if>
  390. <if test="logType != null">log_type,</if>
  391. <if test="createTime != null">create_time,</if>
  392. <if test="updateTime != null">update_time,</if>
  393. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  394. <if test="duration != null">duration,</if>
  395. <if test="qwUserId != null">qw_user_id,</if>
  396. <if test="companyUserId != null">company_user_id,</if>
  397. <if test="companyId != null">company_id,</if>
  398. <if test="courseId != null">course_id,</if>
  399. <if test="sendType != null">send_type,</if>
  400. <if test="rewardType != null">reward_type,</if>
  401. <if test="sopId != null">sop_id,</if>
  402. <if test="finishTime != null">finish_time,</if>
  403. <if test="sendFinishMsg != null">send_finish_msg,</if>
  404. <if test="campPeriodTime != null">camp_period_time,</if>
  405. <if test="periodId != null">period_id,</if>
  406. <if test="project != null">project,</if>
  407. <if test="watchType != null">watch_type,</if>
  408. </trim>
  409. <trim prefix="values (" suffix=")" suffixOverrides=",">
  410. <if test="userId != null">#{userId},</if>
  411. <if test="videoId != null">#{videoId},</if>
  412. <if test="logType != null">#{logType},</if>
  413. <if test="createTime != null">#{createTime},</if>
  414. <if test="updateTime != null">#{updateTime},</if>
  415. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  416. <if test="duration != null">#{duration},</if>
  417. <if test="qwUserId != null">#{qwUserId},</if>
  418. <if test="companyUserId != null">#{companyUserId},</if>
  419. <if test="companyId != null">#{companyId},</if>
  420. <if test="courseId != null">#{courseId},</if>
  421. <if test="sendType != null">#{sendType},</if>
  422. <if test="rewardType != null">#{rewardType},</if>
  423. <if test="sopId != null">#{sopId},</if>
  424. <if test="finishTime != null">#{finishTime},</if>
  425. <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
  426. <if test="campPeriodTime != null">#{campPeriodTime},</if>
  427. <if test="periodId != null">#{periodId},</if>
  428. <if test="project != null">#{project},</if>
  429. <if test="watchType != null">#{watchType},</if>
  430. </trim>
  431. </insert>
  432. <insert id="insertOrUpdateFsCourseWatchLog" parameterType="FsCourseWatchLog">
  433. insert into fs_course_watch_log
  434. <trim prefix="(" suffix=")" suffixOverrides=",">
  435. <if test="userId != null">user_id,</if>
  436. <if test="videoId != null">video_id,</if>
  437. <if test="logType != null">log_type,</if>
  438. <if test="createTime != null">create_time,</if>
  439. <if test="updateTime != null">update_time,</if>
  440. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  441. <if test="duration != null">duration,</if>
  442. <if test="qwUserId != null">qw_user_id,</if>
  443. <if test="companyUserId != null">company_user_id,</if>
  444. <if test="companyId != null">company_id,</if>
  445. <if test="courseId != null">course_id,</if>
  446. <if test="sendType != null">send_type,</if>
  447. <if test="rewardType != null">reward_type,</if>
  448. <if test="sopId != null">sop_id,</if>
  449. <if test="finishTime != null">finish_time,</if>
  450. <if test="sendFinishMsg != null">send_finish_msg,</if>
  451. <if test="campPeriodTime != null">camp_period_time,</if>
  452. <if test="project != null">project,</if>
  453. <if test="watchType != null">watch_type,</if>
  454. </trim>
  455. <trim prefix="values (" suffix=")" suffixOverrides=",">
  456. <if test="userId != null">#{userId},</if>
  457. <if test="videoId != null">#{videoId},</if>
  458. <if test="logType != null">#{logType},</if>
  459. <if test="createTime != null">#{createTime},</if>
  460. <if test="updateTime != null">#{updateTime},</if>
  461. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  462. <if test="duration != null">#{duration},</if>
  463. <if test="qwUserId != null">#{qwUserId},</if>
  464. <if test="companyUserId != null">#{companyUserId},</if>
  465. <if test="companyId != null">#{companyId},</if>
  466. <if test="courseId != null">#{courseId},</if>
  467. <if test="sendType != null">#{sendType},</if>
  468. <if test="rewardType != null">#{rewardType},</if>
  469. <if test="sopId != null">#{sopId},</if>
  470. <if test="finishTime != null">#{finishTime},</if>
  471. <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
  472. <if test="campPeriodTime != null">#{campPeriodTime},</if>
  473. <if test="project != null">#{project},</if>
  474. <if test="watchType != null">#{watchType},</if>
  475. </trim>
  476. on duplicate key update
  477. <trim suffixOverrides=",">
  478. <if test="updateTime != null">update_time = #{updateTime},</if>
  479. </trim>
  480. </insert>
  481. <insert id="insertFsCourseWatchLogBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="logId">
  482. INSERT INTO fs_course_watch_log (
  483. user_id,
  484. video_id,
  485. log_type,
  486. create_time,
  487. update_time,
  488. qw_external_contact_id,
  489. duration,
  490. qw_user_id,
  491. company_user_id,
  492. company_id,
  493. course_id,
  494. send_type,
  495. reward_type,
  496. sop_id,
  497. camp_period_time,
  498. project,
  499. period_id,
  500. im_msg_send_detail_id,
  501. watch_type
  502. )
  503. VALUES
  504. <foreach collection="watchLogs" item="log" separator=",">
  505. (
  506. #{log.userId},
  507. #{log.videoId},
  508. #{log.logType},
  509. #{log.createTime},
  510. #{log.updateTime},
  511. #{log.qwExternalContactId},
  512. #{log.duration},
  513. #{log.qwUserId},
  514. #{log.companyUserId},
  515. #{log.companyId},
  516. #{log.courseId},
  517. #{log.sendType},
  518. #{log.rewardType},
  519. #{log.sopId},
  520. #{log.campPeriodTime},
  521. #{log.project},
  522. #{log.periodId},
  523. #{log.imMsgSendDetailId},
  524. #{log.watchType}
  525. )
  526. </foreach>
  527. ON DUPLICATE KEY UPDATE
  528. update_time = NOW(),
  529. im_msg_send_detail_id = VALUES(im_msg_send_detail_id)
  530. </insert>
  531. <update id="updateFsCourseWatchLog" parameterType="FsCourseWatchLog">
  532. update fs_course_watch_log
  533. <trim prefix="SET" suffixOverrides=",">
  534. <if test="userId != null">user_id = #{userId},</if>
  535. <if test="videoId != null">video_id = #{videoId},</if>
  536. <if test="logType != null">log_type = #{logType},</if>
  537. <if test="createTime != null">create_time = #{createTime},</if>
  538. <if test="updateTime != null">update_time = #{updateTime},</if>
  539. <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
  540. <if test="duration != null">duration = #{duration},</if>
  541. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  542. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  543. <if test="companyId != null">company_id = #{companyId},</if>
  544. <if test="courseId != null">course_id = #{courseId},</if>
  545. <if test="sendType != null">send_type = #{sendType},</if>
  546. <if test="rewardType != null">reward_type = #{rewardType},</if>
  547. <if test="sopId != null">sop_id = #{sopId},</if>
  548. <if test="finishTime != null">finish_time = #{finishTime},</if>
  549. <if test="sendFinishMsg != null">send_finish_msg = #{sendFinishMsg},</if>
  550. <if test="lastHeartbeatTime != null">last_heartbeat_time = #{lastHeartbeatTime},</if>
  551. <if test="periodId != null">period_id = #{periodId},</if>
  552. <if test="project != null">project = #{project},</if>
  553. <if test="watchType != null">watch_type = #{watchType},</if>
  554. </trim>
  555. where log_id = #{logId}
  556. </update>
  557. <delete id="deleteFsCourseWatchLogByLogId" parameterType="Long">
  558. delete from fs_course_watch_log where log_id = #{logId}
  559. </delete>
  560. <delete id="deleteFsCourseWatchLogByLogIds" parameterType="String">
  561. delete from fs_course_watch_log where log_id in
  562. <foreach item="logId" collection="array" open="(" separator="," close=")">
  563. #{logId}
  564. </foreach>
  565. </delete>
  566. <select id="selectFsCourseWatchLogByFinishTime" resultType="com.fs.course.param.FsCourseWatchLogByFinishTimeParam">
  567. <![CDATA[
  568. SELECT
  569. fcwl.log_id,
  570. fcwl.create_time,
  571. fcwl.qw_external_contact_id,
  572. fcwl.qw_user_id,
  573. fcwl.user_id,
  574. fcwl.company_user_id,
  575. fcwl.company_id,
  576. fcwl.sop_id,
  577. fcwl.finish_time,
  578. fcwl.camp_period_time,
  579. qec.corp_id,
  580. qec.external_user_id,
  581. qec.tag_ids,
  582. qec.user_id AS qw_user,
  583. qec.name AS external_contact_name
  584. FROM
  585. fs_course_watch_log fcwl
  586. LEFT JOIN qw_external_contact qec ON fcwl.qw_external_contact_id = qec.id
  587. WHERE
  588. DATE(fcwl.finish_time)= '2025-02-09'
  589. and fcwl.camp_period_time is not NULL
  590. ]]>
  591. </select>
  592. <select id="getWatchLogByFsUser" resultType="com.fs.course.domain.FsCourseWatchLog">
  593. SELECT
  594. log_id,
  595. user_id,
  596. video_id,
  597. log_type,
  598. create_time,
  599. update_time,
  600. duration,
  601. company_user_id,
  602. company_id,
  603. course_id,
  604. send_type,
  605. reward_type,
  606. last_heartbeat_time,
  607. sop_id,
  608. finish_time,
  609. send_finish_msg,
  610. camp_period_time,
  611. period_id
  612. FROM
  613. fs_course_watch_log
  614. WHERE
  615. send_type = 1
  616. AND video_id = #{videoId}
  617. AND user_id = #{fsUserId}
  618. AND company_user_id = #{companyUserId} order by log_id desc limit 1
  619. </select>
  620. <select id="getWatchLogByFsUserAndPeriodId" resultType="com.fs.course.domain.FsCourseWatchLog">
  621. SELECT
  622. log_id,
  623. user_id,
  624. video_id,
  625. log_type,
  626. create_time,
  627. update_time,
  628. duration,
  629. company_user_id,
  630. company_id,
  631. course_id,
  632. send_type,
  633. reward_type,
  634. last_heartbeat_time,
  635. sop_id,
  636. finish_time,
  637. send_finish_msg,
  638. camp_period_time,
  639. period_id
  640. FROM
  641. fs_course_watch_log
  642. WHERE
  643. send_type = 1
  644. AND video_id = #{videoId}
  645. AND user_id = #{fsUserId}
  646. AND company_user_id = #{companyUserId}
  647. <if test="periodId != null">
  648. and period_id = #{periodId}
  649. </if>
  650. order by log_id desc limit 1
  651. </select>
  652. <select id="selectFsCourseWatchLogStatisticsListVONew"
  653. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO">
  654. SELECT
  655. o.company_user_id,o.user_id,DATE(o.create_time) create_time,
  656. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  657. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  658. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  659. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4,
  660. o.project as project,
  661. o.course_id as course_id,
  662. o.video_id as video_id
  663. FROM fs_course_watch_log o
  664. <where>
  665. send_type=1
  666. <if test="companyId != null">
  667. and o.company_id=#{companyId}
  668. </if>
  669. <if test= 'sTime != null '>
  670. and DATE(o.create_time) &gt;= #{sTime}
  671. </if>
  672. <if test='eTime != null '>
  673. and DATE(o.create_time) &lt;= #{eTime}
  674. </if>
  675. <if test ='courseId !=null'>
  676. and o.course_id = #{courseId}
  677. </if>
  678. <if test ='videoId !=null'>
  679. and o.video_id = #{videoId}
  680. </if>
  681. <if test="companyUserId != null">
  682. and o.company_user_id = #{companyUserId}
  683. </if>
  684. <if test="project != null">
  685. and o.project = #{project}
  686. </if>
  687. <if test="userId != null">
  688. and o.user_id = #{userId}
  689. </if>
  690. </where>
  691. GROUP BY o.video_id,o.user_id,DATE(o.create_time),o.project,o.course_id
  692. ORDER BY o.video_id ,DATE(o.create_time)
  693. <!-- limit ${(pageNum-1)*pageSize},${pageSize}-->
  694. </select>
  695. <select id="selectFsCourseWatchLogStatisticsListVONewCount" resultType="java.lang.Long">
  696. SELECT COUNT(*)
  697. FROM (
  698. SELECT 1
  699. FROM fs_course_watch_log o
  700. <where>
  701. send_type=2
  702. <if test="companyId != null">
  703. and o.company_id=#{companyId}
  704. </if>
  705. <if test= 'sTime != null '>
  706. and o.create_time &gt;= #{startDate}
  707. </if>
  708. <if test='eTime != null '>
  709. and o.create_time &lt;= #{endDate}
  710. </if>
  711. <if test ='courseId !=null'>
  712. and o.course_id = #{courseId}
  713. </if>
  714. <if test ='videoId !=null'>
  715. and o.video_id = #{videoId}
  716. </if>
  717. <if test="companyUserId != null">
  718. and o.company_user_id = #{companyUserId}
  719. </if>
  720. <if test="project != null">
  721. and o.project = #{project}
  722. </if>
  723. <if test="userId != null">
  724. and o.user_id = #{userId}
  725. </if>
  726. </where>
  727. GROUP BY o.video_id, o.user_id, DATE(o.create_time), o.project, o.course_id
  728. ) AS grouped_results_count
  729. </select>
  730. <!-- 根据条件查询条数 -->
  731. <select id="countByMap" resultType="java.lang.Integer">
  732. select count(fcwl.log_id) from fs_course_watch_log fcwl
  733. <where>
  734. <if test="params.logTypes != null and params.logTypes.size() > 0">
  735. and fcwl.log_type in
  736. <foreach collection="params.logTypes" open="(" close=")" separator="," item="logType">
  737. #{logType}
  738. </foreach>
  739. </if>
  740. <if test="params.companyUserId != null">
  741. and fcwl.company_user_id = #{params.companyUserId}
  742. </if>
  743. <if test="params.date != null">
  744. and date(fcwl.create_time) = #{params.date}
  745. </if>
  746. </where>
  747. </select>
  748. <update id="batchUpdateWatchLog" parameterType="java.util.List">
  749. UPDATE fs_course_watch_log
  750. SET
  751. duration = CASE
  752. <foreach collection="list" item="item" index="index">
  753. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  754. CASE
  755. <!-- 仅当传入的duration > 当前值时才更新 -->
  756. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  757. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  758. END
  759. </foreach>
  760. END,
  761. last_heartbeat_time = CASE
  762. <foreach collection="list" item="item" index="index">
  763. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  764. CASE
  765. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  766. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  767. END
  768. </foreach>
  769. END,
  770. finish_time = CASE
  771. <foreach collection="list" item="item" index="index">
  772. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  773. CASE
  774. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  775. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  776. END
  777. </foreach>
  778. END,
  779. log_type = CASE
  780. <foreach collection="list" item="item" index="index">
  781. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  782. CASE
  783. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  784. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  785. ELSE log_type <!-- 其他情况保持原值 -->
  786. END
  787. </foreach>
  788. END
  789. WHERE
  790. (video_id, qw_external_contact_id, qw_user_id) IN
  791. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  792. (#{item.videoId}, #{item.qwExternalContactId}, #{item.qwUserId})
  793. </foreach>
  794. </update>
  795. <update id="batchUpdateWatchLogSendMsg" parameterType="java.util.List">
  796. UPDATE fs_course_watch_log
  797. SET send_finish_msg = CASE
  798. <foreach collection="list" item="item">
  799. WHEN log_id = #{item.logId} THEN #{item.sendFinishMsg}
  800. </foreach>
  801. ELSE send_finish_msg
  802. END
  803. WHERE log_id IN
  804. <foreach collection="list" item="item" open="(" separator="," close=")">
  805. #{item.logId}
  806. </foreach>
  807. </update>
  808. <update id="batchUpdateFsUserWatchLog" parameterType="java.util.List">
  809. UPDATE fs_course_watch_log
  810. SET
  811. duration = CASE
  812. <foreach collection="list" item="item" index="index">
  813. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  814. CASE
  815. <!-- 仅当传入的duration > 当前值时才更新 -->
  816. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  817. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  818. END
  819. </foreach>
  820. END,
  821. last_heartbeat_time = CASE
  822. <foreach collection="list" item="item" index="index">
  823. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  824. CASE
  825. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  826. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  827. END
  828. </foreach>
  829. END,
  830. finish_time = CASE
  831. <foreach collection="list" item="item" index="index">
  832. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  833. CASE
  834. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  835. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  836. END
  837. </foreach>
  838. END,
  839. log_type = CASE
  840. <foreach collection="list" item="item" index="index">
  841. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  842. CASE
  843. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  844. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  845. ELSE log_type <!-- 其他情况保持原值 -->
  846. END
  847. </foreach>
  848. END
  849. WHERE
  850. (video_id, user_id, company_user_id) IN
  851. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  852. (#{item.videoId}, #{item.userId}, #{item.companyUserId})
  853. </foreach>
  854. </update>
  855. <update id="batchUpdateWatchLogIsOpen">
  856. UPDATE fs_course_watch_log
  857. SET
  858. duration = CASE
  859. <foreach collection="list" item="item" index="index">
  860. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  861. CASE
  862. <!-- 仅当传入的duration > 当前值时才更新 -->
  863. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  864. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  865. END
  866. </foreach>
  867. END,
  868. last_heartbeat_time = CASE
  869. <foreach collection="list" item="item" index="index">
  870. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  871. CASE
  872. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  873. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  874. END
  875. </foreach>
  876. END,
  877. finish_time = CASE
  878. <foreach collection="list" item="item" index="index">
  879. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  880. CASE
  881. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  882. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  883. END
  884. </foreach>
  885. END,
  886. log_type = CASE
  887. <foreach collection="list" item="item" index="index">
  888. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  889. CASE
  890. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  891. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  892. ELSE log_type <!-- 其他情况保持原值 -->
  893. END
  894. </foreach>
  895. END
  896. WHERE
  897. (video_id, user_id) IN
  898. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  899. (#{item.videoId}, #{item.userId})
  900. </foreach>
  901. </update>
  902. <select id="selectListBytrainingCampId" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  903. select
  904. uc.course_name,v.title as video_name,
  905. watch.log_id,
  906. watch.user_id,
  907. watch.finish_time,
  908. watch.send_finish_msg,
  909. watch.sop_id,
  910. watch.video_id,
  911. watch.reward_type,
  912. watch.log_type,
  913. watch.create_time,
  914. watch.update_time,
  915. watch.qw_external_contact_id,
  916. watch.duration,
  917. watch.qw_user_id,
  918. watch.company_user_id,
  919. watch.company_id,
  920. watch.course_id,
  921. watch.camp_period_time,
  922. company_user.nick_name as companyUserName
  923. from
  924. fs_user_course_training_camp camp
  925. left join fs_user_course_period period on
  926. camp.training_camp_id = period.training_camp_id
  927. left join fs_course_watch_log watch on
  928. period.period_id = watch.period_id
  929. left join fs_user_course uc on uc.course_id = watch.course_id
  930. left join fs_user_course_video v on v.video_id = watch.video_id
  931. left join company_user on company_user.user_id = watch.company_user_id
  932. <where>
  933. `period`.del_flag = '0' and watch.log_type &lt;&gt; 3
  934. <if test="trainingCampId != null">and camp.training_camp_id = #{trainingCampId}</if>
  935. <if test="userId != null">and watch.user_id = #{userId}</if>
  936. <if test="periodId != null">and `period`.period_id = #{periodId}</if>
  937. </where>
  938. </select>
  939. <select id="selectFsCourseWatchLogListVOexport" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  940. SELECT
  941. l.log_id,
  942. l.project AS project,
  943. l.period_id,
  944. l.user_id,
  945. l.log_type,
  946. SEC_TO_TIME(l.duration) AS duration,
  947. l.camp_period_time,
  948. l.finish_time,
  949. l.send_type,
  950. l.create_time,
  951. l.update_time,
  952. l.last_heartbeat_time,
  953. l.company_id,
  954. l.company_user_id,
  955. l.course_id,
  956. l.video_id,
  957. l.qw_user_id,
  958. l.qw_external_contact_id,
  959. l.sop_id,
  960. qec.create_time as qec_create_time,
  961. u.last_ip
  962. FROM
  963. fs_course_watch_log l LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  964. left join fs_user u on u.user_id = l.user_id
  965. left join company_user cu on cu.user_id = l.company_user_id
  966. <where>
  967. <if test ='maps.sendType !=null'>
  968. and l.send_type = #{maps.sendType}
  969. </if>
  970. <if test ='maps.userId !=null'>
  971. and l.user_id = #{maps.userId}
  972. </if>
  973. <if test ='maps.qwExternalContactId !=null'>
  974. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  975. </if>
  976. <if test ='maps.qwUserId !=null'>
  977. and l.qw_user_id = #{maps.qwUserId}
  978. </if>
  979. <if test ='maps.courseId !=null'>
  980. and l.course_id = #{maps.courseId}
  981. </if>
  982. <if test ='maps.videoId !=null'>
  983. and l.video_id = #{maps.videoId}
  984. </if>
  985. <if test ='maps.logType !=null'>
  986. and l.log_type = #{maps.logType}
  987. </if>
  988. <if test ='maps.periodId !=null'>
  989. and l.period_id = #{maps.periodId}
  990. </if>
  991. <if test ='maps.companyId !=null'>
  992. and l.company_id = #{maps.companyId}
  993. </if>
  994. <if test ='maps.companyUserId !=null'>
  995. and l.company_user_id = #{maps.companyUserId}
  996. </if>
  997. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  998. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  999. </if>
  1000. <if test ='maps.nickName !=null and maps.nickName!=""'>
  1001. and u.nick_name like concat('%', #{maps.nickName}, '%')
  1002. </if>
  1003. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  1004. and qec.name like concat('%', #{maps.externalUserName}, '%')
  1005. </if>
  1006. <if test= 'maps.qecSTime != null '>
  1007. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  1008. </if>
  1009. <if test='maps.qecETime != null '>
  1010. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  1011. </if>
  1012. <if test= 'maps.sTime != null '>
  1013. and DATE(l.create_time) &gt;= DATE(#{maps.sTime})
  1014. </if>
  1015. <if test='maps.eTime != null '>
  1016. and DATE(l.create_time) &lt;= DATE(#{maps.eTime})
  1017. </if>
  1018. <if test= 'maps.scheduleStartTime != null '>
  1019. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  1020. </if>
  1021. <if test='maps.scheduleEndTime != null '>
  1022. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  1023. </if>
  1024. <if test= 'maps.upSTime != null '>
  1025. and DATE(l.update_time) &gt;= DATE(#{maps.upSTime})
  1026. </if>
  1027. <if test='maps.upETime != null '>
  1028. and DATE(l.update_time) &lt;= DATE(#{maps.upETime})
  1029. </if>
  1030. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  1031. and l.sop_id in
  1032. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  1033. #{sopId}
  1034. </foreach>
  1035. </if>
  1036. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  1037. and l.period_id in
  1038. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  1039. #{periodId}
  1040. </foreach>
  1041. </if>
  1042. </where>
  1043. order by l.finish_time desc,l.update_time desc,l.create_time desc
  1044. </select>
  1045. <select id="getWatchCourseByVideoId" resultType="com.fs.course.domain.FsCourseWatchLog">
  1046. SELECT
  1047. *
  1048. FROM
  1049. fs_course_watch_log
  1050. WHERE
  1051. send_type = 1
  1052. AND video_id = #{videoId}
  1053. AND user_id in
  1054. <foreach item="userId" index="index" collection="userIds" open="(" separator="," close=")">
  1055. #{userId}
  1056. </foreach>
  1057. ORDER BY
  1058. log_id DESC
  1059. </select>
  1060. <select id="getUserCountByCampId" resultType="java.lang.Integer">
  1061. select count(distinct cwl.user_id)
  1062. from fs_user_course_period ucp
  1063. inner join fs_course_watch_log cwl on ucp.period_id = cwl.period_id
  1064. where ucp.training_camp_id = #{trainingCampId}
  1065. </select>
  1066. <select id="selectFsCourseWatchLogStatisticsListByCompanyVO"
  1067. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListByCompanyVO">
  1068. SELECT
  1069. o.video_id,
  1070. o.company_id,
  1071. comp.company_name,
  1072. o.qw_user_id,
  1073. DATE(o.create_time) create_time,
  1074. v.title videoName,
  1075. uc.course_name,
  1076. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  1077. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  1078. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  1079. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4
  1080. FROM
  1081. fs_course_watch_log o
  1082. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1083. LEFT JOIN company comp ON comp.company_id = o.company_id
  1084. LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
  1085. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1086. <where>
  1087. <if test="sendType != null">
  1088. and send_type = #{sendType}
  1089. </if>
  1090. <if test="companyId != null">
  1091. and o.company_id = #{companyId}
  1092. </if>
  1093. <if test="sTime != null">
  1094. AND DATE (o.create_time) &gt;= DATE (#{sTime})
  1095. </if>
  1096. <if test="eTime != null">
  1097. AND DATE (o.create_time) &lt;= DATE (#{eTime})
  1098. </if>
  1099. <if test="courseId != null">
  1100. and o.course_id = #{courseId}
  1101. </if>
  1102. <if test="videoId != null">
  1103. and o.video_id = #{videoId}
  1104. </if>
  1105. </where>
  1106. GROUP BY
  1107. DATE (o.create_time),
  1108. o.company_id
  1109. ORDER BY
  1110. comp.company_id,
  1111. DATE (o.create_time)
  1112. </select>
  1113. <select id="selectQwFsCourseWatchLogStatisticsListVO"
  1114. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO" parameterType="com.fs.qw.param.QwSidebarStatsParam">
  1115. SELECT
  1116. o.project,
  1117. o.course_id AS courseId,
  1118. uc.course_name AS courseName,
  1119. o.video_id AS videoId,
  1120. v.title AS videoName,
  1121. CASE WHEN o.log_type = 1 THEN 1 END AS type1,
  1122. CASE WHEN o.log_type = 2 THEN 1 END AS type2,
  1123. CASE WHEN o.log_type = 3 THEN 1 END AS type3,
  1124. CASE WHEN o.log_type = 4 THEN 1 END AS type4,
  1125. o.qw_user_id,
  1126. o.user_id AS userId,
  1127. o.company_user_id AS companyUserId,
  1128. o.company_id AS companyId,
  1129. o.create_time AS createTime
  1130. FROM
  1131. fs_course_watch_log o
  1132. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1133. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1134. WHERE
  1135. o.qw_external_contact_id=#{data.qwExternalContactId}
  1136. <if test="data.sendType != null">
  1137. AND send_type = #{data.sendType}
  1138. </if>
  1139. <if test="data.startTime != null">
  1140. AND DATE(o.create_time) &gt;= DATE(#{data.startTime})
  1141. </if>
  1142. <if test="data.endTime != null">
  1143. AND DATE(o.create_time) &lt;= DATE(#{data.endTime})
  1144. </if>
  1145. order by o.create_time DESC
  1146. </select>
  1147. <!-- 统计当天各公司的观看人数和完播人数, 存到redis中,定时任务每 ? 分钟执行一次 -->
  1148. <select id="watchCourseStatisticsGroupByCompany" resultType="com.fs.statis.dto.WatchCourseStatisticsResultDTO">
  1149. SELECT
  1150. o.company_id AS companyId,
  1151. c.company_name AS companyName,
  1152. o.send_type,
  1153. COUNT(DISTINCT o.user_id) AS watchUserCount,
  1154. COUNT(o.log_id) AS watchCount,
  1155. sum(case when o.log_type = 2 then 1 else 0 end) AS finishCount,
  1156. COUNT(DISTINCT CASE WHEN o.log_type = 2 THEN o.user_id END) AS finishUserCount
  1157. FROM
  1158. fs_course_watch_log o
  1159. LEFT JOIN company c ON c.company_id = o.company_id
  1160. WHERE
  1161. o.create_time &gt;= #{params.startTime}
  1162. AND o.create_time &lt;= #{params.endTime}
  1163. GROUP BY
  1164. o.company_id,
  1165. o.send_type
  1166. </select>
  1167. <select id="selectFsCourseWatchLogStatisticsListVO_COUNT"
  1168. resultType="java.lang.Long">
  1169. SELECT COUNT(*) FROM (
  1170. SELECT
  1171. o.video_id,
  1172. <!-- 用choose保证sendType逻辑互斥,避免GROUP BY字段缺失 -->
  1173. <choose>
  1174. <when test="sendType != 1">
  1175. o.qw_user_id,
  1176. </when>
  1177. <when test="sendType == 1">
  1178. o.company_user_id,
  1179. </when>
  1180. <!-- sendType为null时兜底,避免空指针 -->
  1181. <otherwise>
  1182. o.qw_user_id,
  1183. </otherwise>
  1184. </choose>
  1185. DATE(o.create_time) create_time
  1186. FROM fs_course_watch_log o
  1187. <!-- 动态关联qw_user表 -->
  1188. <if test="sendType != 1">
  1189. LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
  1190. </if>
  1191. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1192. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1193. <!-- 动态关联company_user表 -->
  1194. <if test="sendType == 1">
  1195. LEFT JOIN company_user cu ON cu.user_id = o.company_user_id
  1196. </if>
  1197. WHERE 1=1
  1198. <if test = 'companyId != null and companyId != 0'>
  1199. and o.company_id=#{companyId}
  1200. </if>
  1201. <if test = 'userIds != null and userIds.size() > 0'>
  1202. and o.company_user_id in
  1203. <foreach collection='userIds' item='id' open='(' separator=',' close=')'>
  1204. #{id}
  1205. </foreach>
  1206. </if>
  1207. <!-- 发送类型筛选 -->
  1208. <if test="sendType != null">
  1209. AND send_type = #{sendType}
  1210. </if>
  1211. <!-- 开始时间筛选:区分String/Date类型,避免类型比较异常 -->
  1212. <if test="sTime != null">
  1213. <choose>
  1214. <!-- sTime是String类型(yyyy-MM-dd) -->
  1215. <when test="sTime instanceof java.lang.String and sTime.trim() != ''">
  1216. AND o.create_time &gt;= STR_TO_DATE(#{sTime}, '%Y-%m-%d')
  1217. </when>
  1218. <!-- sTime是Date类型 -->
  1219. <otherwise>
  1220. AND o.create_time &gt;= #{sTime}
  1221. </otherwise>
  1222. </choose>
  1223. </if>
  1224. <!-- 结束时间筛选:区分String/Date类型 -->
  1225. <if test="eTime != null">
  1226. <choose>
  1227. <when test="eTime instanceof java.lang.String and eTime.trim() != ''">
  1228. AND o.create_time &lt; DATE_ADD(STR_TO_DATE(#{eTime}, '%Y-%m-%d'), INTERVAL 1 DAY)
  1229. </when>
  1230. <otherwise>
  1231. AND o.create_time &lt; DATE_ADD(#{eTime}, INTERVAL 1 DAY)
  1232. </otherwise>
  1233. </choose>
  1234. </if>
  1235. <!-- 昵称筛选:sendType!=1时关联qw_user -->
  1236. <if test="sendType != 1 and nickName != null and nickName.trim() != ''">
  1237. AND qu.qw_user_name LIKE CONCAT(#{nickName}, '%')
  1238. </if>
  1239. <!-- 昵称筛选:sendType==1时关联company_user -->
  1240. <if test="sendType == 1 and nickName != null and nickName.trim() != ''">
  1241. AND cu.nick_name LIKE CONCAT(#{nickName}, '%')
  1242. </if>
  1243. <!-- 课程ID筛选:加>0判断,避免null值拼接 -->
  1244. <if test="courseId != null and courseId > 0">
  1245. AND o.course_id = #{courseId}
  1246. </if>
  1247. <!-- 视频ID筛选:加>0判断 -->
  1248. <if test="videoId != null and videoId > 0">
  1249. AND o.video_id = #{videoId}
  1250. </if>
  1251. <!-- 分组条件:与子查询字段一致 -->
  1252. GROUP BY
  1253. o.video_id,
  1254. <choose>
  1255. <when test="sendType != 1">
  1256. o.qw_user_id,
  1257. </when>
  1258. <when test="sendType == 1">
  1259. o.company_user_id,
  1260. </when>
  1261. <otherwise>
  1262. o.qw_user_id,
  1263. </otherwise>
  1264. </choose>
  1265. DATE(o.create_time)
  1266. ) AS t
  1267. </select>
  1268. <select id="selectCompanyBaseInfo" resultType="com.fs.course.vo.FsCourseReportVO">
  1269. SELECT
  1270. c.company_id AS companyId,
  1271. c.company_name AS companyName
  1272. FROM company c
  1273. <where>
  1274. c.is_del=0
  1275. <if test="companyId != null and companyId != ''">
  1276. AND c.company_id = #{companyId}
  1277. </if>
  1278. </where>
  1279. GROUP BY c.company_id, c.company_name
  1280. ORDER BY c.create_time DESC
  1281. </select>
  1282. <select id="selectWatchStatistics" resultType="com.fs.course.vo.FsCourseReportVO">
  1283. SELECT
  1284. <choose>
  1285. <when test="dimension == 'company'">
  1286. fwl.company_id AS companyId,
  1287. </when>
  1288. <when test="dimension == 'course'">
  1289. fwl.course_id As courseId,
  1290. </when>
  1291. <when test="dimension == 'video'">
  1292. fwl.video_id AS videoId,
  1293. </when>
  1294. </choose>
  1295. COUNT(DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS finishedCount,
  1296. COUNT(CASE WHEN fwl.log_type = 2 THEN fwl.log_id END) AS courseCompleteTimes,
  1297. COUNT(DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END) AS accessCount,
  1298. ifnull(
  1299. ROUND(
  1300. (
  1301. COUNT( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) / count( DISTINCT CASE WHEN fwl.log_type != 3
  1302. THEN fwl.user_id END )) * 100,
  1303. 2
  1304. ),
  1305. 0
  1306. ) AS finishRate
  1307. FROM
  1308. fs_course_watch_log fwl
  1309. <where>
  1310. fwl.send_type = 2
  1311. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1312. AND fwl.create_time &gt;= #{startDate} AND fwl.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1313. </if>
  1314. <choose>
  1315. <when test="dimension == 'company' and companyId != null and companyId > 0">
  1316. AND fwl.company_id = #{companyId}
  1317. </when>
  1318. <when test="dimension == 'video' and videoId != null and videoId > 0">
  1319. AND fwl.video_id = #{videoId}
  1320. </when>
  1321. <when test="dimension == 'course' and courseId != null and courseId != ''">
  1322. AND fwl.course_id = #{courseId}
  1323. </when>
  1324. </choose>
  1325. </where>
  1326. <choose>
  1327. <when test="dimension == 'course'">
  1328. GROUP BY fwl.course_id
  1329. </when>
  1330. <when test="dimension == 'video'">
  1331. GROUP BY fwl.video_id
  1332. </when>
  1333. <otherwise>
  1334. GROUP BY fwl.company_id
  1335. </otherwise>
  1336. </choose>
  1337. ORDER BY accessCount desc
  1338. </select>
  1339. <select id="getSopCourseH5StudyList" resultType="com.fs.course.vo.FsSopMyCourseH5LinkVO">
  1340. select c.img_url courseUrl,v.title courseName,c.title,l.log_id logId,u.qw_user_name qwUserName from fs_course_watch_log l
  1341. left join fs_user_course c on c.course_id = l.course_id
  1342. left join qw_user u on l.qw_user_id = u.id
  1343. left join fs_user_course_video v on l.video_id =v.video_id
  1344. where l.user_id = #{userId} AND l.create_time &gt;= CURDATE()
  1345. AND l.create_time &lt; CURDATE() + INTERVAL 1 DAY
  1346. order by l.create_time desc
  1347. </select>
  1348. <select id="selectFsUserWatchLogByExtId" resultType="com.fs.course.domain.FsCourseWatchLog">
  1349. select log_id logId from fs_course_watch_log where qw_external_contact_id = #{id}
  1350. and qw_user_id = #{qwUserId} and user_id is null
  1351. </select>
  1352. <select id="getSopCourseH5StudyListByQwExId" resultType="com.fs.course.vo.FsSopMyCourseH5LinkVO">
  1353. select c.img_url courseUrl,v.title courseName,c.title,l.log_id logId,u.qw_user_name qwUserName from fs_course_watch_log l
  1354. left join fs_user_course c on c.course_id = l.course_id
  1355. left join qw_user u on l.qw_user_id = u.id
  1356. left join fs_user_course_video v on l.video_id =v.video_id
  1357. where l.qw_external_contact_id = #{qwExternalId} AND l.create_time &gt;= CURDATE()
  1358. AND l.create_time &lt; CURDATE() + INTERVAL 1 DAY
  1359. order by l.create_time desc
  1360. </select>
  1361. <!-- 首次点播数据统计:看课时间在[营期开始时间, 营期开始时间+视频时长]范围内,view_start=COALESCE(finish_time-duration, update_time-duration, create_time) -->
  1362. <select id="selectFirstPlaybackStats" resultType="map">
  1363. SELECT
  1364. COUNT(DISTINCT l.user_id) AS firstWatchCount,
  1365. COUNT(DISTINCT CASE WHEN l.duration &gt;= 1200 THEN l.user_id END) AS firstWatch20MinCount,
  1366. COUNT(DISTINCT CASE WHEN l.duration &gt;= 1800 THEN l.user_id END) AS firstWatch30MinCount
  1367. FROM fs_course_watch_log l
  1368. INNER JOIN fs_user_course_period_days fcpd ON fcpd.period_id = l.period_id AND fcpd.video_id = l.video_id AND fcpd.del_flag = '0'
  1369. INNER JOIN fs_user_course_video v ON v.video_id = l.video_id AND v.is_del = 0
  1370. WHERE l.video_id = #{videoId}
  1371. AND l.period_id = #{periodId}
  1372. AND l.user_id IS NOT NULL
  1373. AND (
  1374. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration, 0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration, 0) SECOND), l.create_time) &gt;= fcpd.start_date_time)
  1375. AND
  1376. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration, 0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration, 0) SECOND), l.create_time) &lt; DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration, 0) SECOND))
  1377. )
  1378. </select>
  1379. <!-- 第2-n次观看数据统计:view_start不在[营期开始时间, 营期开始时间+视频时长]内 -->
  1380. <select id="selectRepeatPlaybackStats" resultType="map">
  1381. SELECT
  1382. COUNT(DISTINCT l.user_id) AS repeatWatchCount,
  1383. COUNT(DISTINCT CASE WHEN l.duration &gt;= 1200 THEN l.user_id END) AS repeatWatch20MinCount,
  1384. COUNT(DISTINCT CASE WHEN l.duration &gt;= 1800 THEN l.user_id END) AS repeatWatch30MinCount
  1385. FROM fs_course_watch_log l
  1386. INNER JOIN fs_user_course_period_days fcpd ON fcpd.period_id = l.period_id AND fcpd.video_id = l.video_id AND fcpd.del_flag = '0'
  1387. INNER JOIN fs_user_course_video v ON v.video_id = l.video_id AND v.is_del = 0
  1388. WHERE l.video_id = #{videoId}
  1389. AND l.period_id = #{periodId}
  1390. AND l.user_id IS NOT NULL
  1391. AND (
  1392. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration, 0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration, 0) SECOND), l.create_time) &lt; fcpd.start_date_time)
  1393. OR
  1394. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration, 0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration, 0) SECOND), l.create_time) &gt;= DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration, 0) SECOND))
  1395. )
  1396. </select>
  1397. <!-- 课程小结-用户详情列表:按user_id分组,区分首次/2-n次观看时长,关联订单,按创建时间倒序 -->
  1398. <select id="selectCourseStatisticsUserDetailList" resultType="com.fs.course.vo.CourseStatisticsUserDetailVO">
  1399. SELECT
  1400. ua.user_id AS userId,
  1401. COALESCE(u.nick_name, u.nickname, '未知用户') AS userName,
  1402. COALESCE(ua.first_dur, 0) AS watchDuration,
  1403. COALESCE(ua.repeat_dur, 0) AS repeatWatchDuration,
  1404. COALESCE(ord.order_count, 0) AS orderCount,
  1405. COALESCE(ord.order_amount, 0) AS orderAmount,
  1406. c.company_name AS companyName,
  1407. cu.nick_name AS salesName
  1408. FROM (
  1409. SELECT
  1410. l.user_id,
  1411. MAX(l.create_time) AS max_create_time,
  1412. SUM(CASE WHEN
  1413. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &gt;= fcpd.start_date_time)
  1414. AND (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &lt; DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration,0) SECOND))
  1415. THEN COALESCE(l.duration,0) ELSE 0 END) AS first_dur,
  1416. SUM(CASE WHEN
  1417. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &lt; fcpd.start_date_time)
  1418. OR (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &gt;= DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration,0) SECOND))
  1419. THEN COALESCE(l.duration,0) ELSE 0 END) AS repeat_dur,
  1420. MAX(l.company_id) AS company_id,
  1421. MAX(l.company_user_id) AS company_user_id
  1422. FROM fs_course_watch_log l
  1423. INNER JOIN fs_user_course_period_days fcpd ON fcpd.period_id = l.period_id AND fcpd.video_id = l.video_id AND fcpd.del_flag = '0'
  1424. INNER JOIN fs_user_course_video v ON v.video_id = l.video_id AND v.is_del = 0
  1425. WHERE l.video_id = #{param.videoId} AND l.period_id = #{param.periodId} AND l.user_id IS NOT NULL
  1426. GROUP BY l.user_id
  1427. ) ua
  1428. LEFT JOIN fs_user u ON u.user_id = ua.user_id
  1429. LEFT JOIN (
  1430. SELECT
  1431. o.user_id,
  1432. COUNT(o.id) AS order_count,
  1433. SUM(IFNULL(o.pay_price, 0)) AS order_amount,
  1434. MIN(o.id) AS min_order_id
  1435. FROM fs_store_order_scrm o
  1436. WHERE o.order_type = 3 AND o.video_id = #{param.videoId} AND o.period_id = #{param.periodId} AND o.paid = 1
  1437. GROUP BY o.user_id
  1438. ) ord ON ord.user_id = ua.user_id
  1439. LEFT JOIN company c ON c.company_id = ua.company_id
  1440. LEFT JOIN company_user cu ON cu.user_id = ua.company_user_id
  1441. ORDER BY ua.max_create_time DESC
  1442. </select>
  1443. <!-- 课程小结-用户详情导出:按创建时间倒序,最多50000条 -->
  1444. <select id="selectCourseStatisticsUserDetailExportList" resultType="com.fs.course.vo.CourseStatisticsUserDetailVO">
  1445. SELECT
  1446. ua.user_id AS userId,
  1447. COALESCE(u.nick_name, u.nickname, '未知用户') AS userName,
  1448. COALESCE(ua.first_dur, 0) AS watchDuration,
  1449. COALESCE(ua.repeat_dur, 0) AS repeatWatchDuration,
  1450. COALESCE(ord.order_count, 0) AS orderCount,
  1451. COALESCE(ord.order_amount, 0) AS orderAmount,
  1452. c.company_name AS companyName,
  1453. cu.nick_name AS salesName
  1454. FROM (
  1455. SELECT
  1456. l.user_id,
  1457. MAX(l.create_time) AS max_create_time,
  1458. SUM(CASE WHEN
  1459. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &gt;= fcpd.start_date_time)
  1460. AND (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &lt; DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration,0) SECOND))
  1461. THEN COALESCE(l.duration,0) ELSE 0 END) AS first_dur,
  1462. SUM(CASE WHEN
  1463. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &lt; fcpd.start_date_time)
  1464. OR (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &gt;= DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration,0) SECOND))
  1465. THEN COALESCE(l.duration,0) ELSE 0 END) AS repeat_dur,
  1466. MAX(l.company_id) AS company_id,
  1467. MAX(l.company_user_id) AS company_user_id
  1468. FROM fs_course_watch_log l
  1469. INNER JOIN fs_user_course_period_days fcpd ON fcpd.period_id = l.period_id AND fcpd.video_id = l.video_id AND fcpd.del_flag = '0'
  1470. INNER JOIN fs_user_course_video v ON v.video_id = l.video_id AND v.is_del = 0
  1471. WHERE l.video_id = #{param.videoId} AND l.period_id = #{param.periodId} AND l.user_id IS NOT NULL
  1472. GROUP BY l.user_id
  1473. ) ua
  1474. LEFT JOIN fs_user u ON u.user_id = ua.user_id
  1475. LEFT JOIN (
  1476. SELECT
  1477. o.user_id,
  1478. COUNT(o.id) AS order_count,
  1479. SUM(IFNULL(o.pay_price, 0)) AS order_amount,
  1480. MIN(o.id) AS min_order_id
  1481. FROM fs_store_order_scrm o
  1482. WHERE o.order_type = 3 AND o.video_id = #{param.videoId} AND o.period_id = #{param.periodId} AND o.paid = 1
  1483. GROUP BY o.user_id
  1484. ) ord ON ord.user_id = ua.user_id
  1485. LEFT JOIN company c ON c.company_id = ua.company_id
  1486. LEFT JOIN company_user cu ON cu.user_id = ua.company_user_id
  1487. ORDER BY ua.max_create_time DESC
  1488. LIMIT 50000
  1489. </select>
  1490. <select id="selectActualCompletionList" resultType="com.fs.course.vo.FSActualCompletionVO">
  1491. SELECT
  1492. a.totalStudents,
  1493. a.completedCount,
  1494. ROUND((a.completedCount / a.totalStudents) * 100, 2) AS actualCompletionRate,
  1495. ROUND((a.totalViewingDuration / a.totalStudents) / 60, 2) AS avgWatchDurationMinutes,
  1496. ROUND((a.totalDurationOfCompleters/a.completedCount)/60,2) AS avgCompletedDuration,
  1497. ROUND(((a.totalDurationOfCompleters/a.completedCount)/a.duration) * 100,2) AS avgCompletionPlaybackRate
  1498. FROM
  1499. (
  1500. SELECT
  1501. COUNT(*) AS totalStudents,
  1502. SUM(CASE WHEN wl.log_type = 2 THEN 1 ELSE 0 END) AS completedCount,
  1503. SUM(wl.duration) AS totalViewingDuration,
  1504. SUM(CASE WHEN wl.log_type = 2 THEN wl.duration ELSE 0 END) AS totalDurationOfCompleters,
  1505. cv.duration
  1506. FROM
  1507. fs_user_course_period_days pd
  1508. INNER JOIN fs_course_watch_log wl ON pd.period_id = wl.period_id
  1509. INNER JOIN fs_user_course_video cv ON pd.video_id = cv.video_id
  1510. AND pd.video_id = wl.video_id
  1511. WHERE
  1512. pd.period_id = #{periodId}
  1513. AND pd.video_id = #{videoId}
  1514. GROUP BY
  1515. pd.period_id
  1516. ) a
  1517. </select>
  1518. </mapper>