FsCourseWatchLogMapper.xml 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  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="selectFsCourseWatchLogStatisticsListVONew"
  621. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO">
  622. SELECT
  623. o.company_user_id,o.user_id,DATE(o.create_time) create_time,
  624. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  625. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  626. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  627. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4,
  628. o.project as project,
  629. o.course_id as course_id,
  630. o.video_id as video_id
  631. FROM fs_course_watch_log o
  632. <where>
  633. send_type=1
  634. <if test="companyId != null">
  635. and o.company_id=#{companyId}
  636. </if>
  637. <if test= 'sTime != null '>
  638. and DATE(o.create_time) &gt;= #{sTime}
  639. </if>
  640. <if test='eTime != null '>
  641. and DATE(o.create_time) &lt;= #{eTime}
  642. </if>
  643. <if test ='courseId !=null'>
  644. and o.course_id = #{courseId}
  645. </if>
  646. <if test ='videoId !=null'>
  647. and o.video_id = #{videoId}
  648. </if>
  649. <if test="companyUserId != null">
  650. and o.company_user_id = #{companyUserId}
  651. </if>
  652. <if test="project != null">
  653. and o.project = #{project}
  654. </if>
  655. <if test="userId != null">
  656. and o.user_id = #{userId}
  657. </if>
  658. </where>
  659. GROUP BY o.video_id,o.user_id,DATE(o.create_time),o.project,o.course_id
  660. ORDER BY o.video_id ,DATE(o.create_time)
  661. <!-- limit ${(pageNum-1)*pageSize},${pageSize}-->
  662. </select>
  663. <select id="selectFsCourseWatchLogStatisticsListVONewCount" resultType="java.lang.Long">
  664. SELECT COUNT(*)
  665. FROM (
  666. SELECT 1
  667. FROM fs_course_watch_log o
  668. <where>
  669. send_type=2
  670. <if test="companyId != null">
  671. and o.company_id=#{companyId}
  672. </if>
  673. <if test= 'sTime != null '>
  674. and o.create_time &gt;= #{startDate}
  675. </if>
  676. <if test='eTime != null '>
  677. and o.create_time &lt;= #{endDate}
  678. </if>
  679. <if test ='courseId !=null'>
  680. and o.course_id = #{courseId}
  681. </if>
  682. <if test ='videoId !=null'>
  683. and o.video_id = #{videoId}
  684. </if>
  685. <if test="companyUserId != null">
  686. and o.company_user_id = #{companyUserId}
  687. </if>
  688. <if test="project != null">
  689. and o.project = #{project}
  690. </if>
  691. <if test="userId != null">
  692. and o.user_id = #{userId}
  693. </if>
  694. </where>
  695. GROUP BY o.video_id, o.user_id, DATE(o.create_time), o.project, o.course_id
  696. ) AS grouped_results_count
  697. </select>
  698. <!-- 根据条件查询条数 -->
  699. <select id="countByMap" resultType="java.lang.Integer">
  700. select count(fcwl.log_id) from fs_course_watch_log fcwl
  701. <where>
  702. <if test="params.logTypes != null and params.logTypes.size() > 0">
  703. and fcwl.log_type in
  704. <foreach collection="params.logTypes" open="(" close=")" separator="," item="logType">
  705. #{logType}
  706. </foreach>
  707. </if>
  708. <if test="params.companyUserId != null">
  709. and fcwl.company_user_id = #{params.companyUserId}
  710. </if>
  711. <if test="params.date != null">
  712. and date(fcwl.create_time) = #{params.date}
  713. </if>
  714. </where>
  715. </select>
  716. <update id="batchUpdateWatchLog" parameterType="java.util.List">
  717. UPDATE fs_course_watch_log
  718. SET
  719. duration = CASE
  720. <foreach collection="list" item="item" index="index">
  721. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  722. CASE
  723. <!-- 仅当传入的duration > 当前值时才更新 -->
  724. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  725. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  726. END
  727. </foreach>
  728. END,
  729. last_heartbeat_time = CASE
  730. <foreach collection="list" item="item" index="index">
  731. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  732. CASE
  733. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  734. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  735. END
  736. </foreach>
  737. END,
  738. finish_time = CASE
  739. <foreach collection="list" item="item" index="index">
  740. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  741. CASE
  742. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  743. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  744. END
  745. </foreach>
  746. END,
  747. log_type = CASE
  748. <foreach collection="list" item="item" index="index">
  749. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  750. CASE
  751. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  752. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  753. ELSE log_type <!-- 其他情况保持原值 -->
  754. END
  755. </foreach>
  756. END
  757. WHERE
  758. (video_id, qw_external_contact_id, qw_user_id) IN
  759. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  760. (#{item.videoId}, #{item.qwExternalContactId}, #{item.qwUserId})
  761. </foreach>
  762. </update>
  763. <update id="batchUpdateWatchLogSendMsg" parameterType="java.util.List">
  764. UPDATE fs_course_watch_log
  765. SET send_finish_msg = CASE
  766. <foreach collection="list" item="item">
  767. WHEN log_id = #{item.logId} THEN #{item.sendFinishMsg}
  768. </foreach>
  769. ELSE send_finish_msg
  770. END
  771. WHERE log_id IN
  772. <foreach collection="list" item="item" open="(" separator="," close=")">
  773. #{item.logId}
  774. </foreach>
  775. </update>
  776. <update id="batchUpdateFsUserWatchLog" parameterType="java.util.List">
  777. UPDATE fs_course_watch_log
  778. SET
  779. duration = CASE
  780. <foreach collection="list" item="item" index="index">
  781. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  782. CASE
  783. <!-- 仅当传入的duration > 当前值时才更新 -->
  784. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  785. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  786. END
  787. </foreach>
  788. END,
  789. last_heartbeat_time = CASE
  790. <foreach collection="list" item="item" index="index">
  791. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  792. CASE
  793. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  794. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  795. END
  796. </foreach>
  797. END,
  798. finish_time = CASE
  799. <foreach collection="list" item="item" index="index">
  800. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  801. CASE
  802. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  803. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  804. END
  805. </foreach>
  806. END,
  807. log_type = CASE
  808. <foreach collection="list" item="item" index="index">
  809. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  810. CASE
  811. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  812. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  813. ELSE log_type <!-- 其他情况保持原值 -->
  814. END
  815. </foreach>
  816. END
  817. WHERE
  818. (video_id, user_id, company_user_id) IN
  819. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  820. (#{item.videoId}, #{item.userId}, #{item.companyUserId})
  821. </foreach>
  822. </update>
  823. <update id="batchUpdateWatchLogIsOpen">
  824. UPDATE fs_course_watch_log
  825. SET
  826. duration = CASE
  827. <foreach collection="list" item="item" index="index">
  828. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  829. CASE
  830. <!-- 仅当传入的duration > 当前值时才更新 -->
  831. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  832. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  833. END
  834. </foreach>
  835. END,
  836. last_heartbeat_time = CASE
  837. <foreach collection="list" item="item" index="index">
  838. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  839. CASE
  840. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  841. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  842. END
  843. </foreach>
  844. END,
  845. finish_time = CASE
  846. <foreach collection="list" item="item" index="index">
  847. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  848. CASE
  849. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  850. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  851. END
  852. </foreach>
  853. END,
  854. log_type = CASE
  855. <foreach collection="list" item="item" index="index">
  856. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  857. CASE
  858. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  859. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  860. ELSE log_type <!-- 其他情况保持原值 -->
  861. END
  862. </foreach>
  863. END
  864. WHERE
  865. (video_id, user_id) IN
  866. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  867. (#{item.videoId}, #{item.userId})
  868. </foreach>
  869. </update>
  870. <select id="selectListBytrainingCampId" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  871. select
  872. uc.course_name,v.title as video_name,
  873. watch.log_id,
  874. watch.user_id,
  875. watch.finish_time,
  876. watch.send_finish_msg,
  877. watch.sop_id,
  878. watch.video_id,
  879. watch.reward_type,
  880. watch.log_type,
  881. watch.create_time,
  882. watch.update_time,
  883. watch.qw_external_contact_id,
  884. watch.duration,
  885. watch.qw_user_id,
  886. watch.company_user_id,
  887. watch.company_id,
  888. watch.course_id,
  889. watch.camp_period_time,
  890. company_user.nick_name as companyUserName
  891. from
  892. fs_user_course_training_camp camp
  893. left join fs_user_course_period period on
  894. camp.training_camp_id = period.training_camp_id
  895. left join fs_course_watch_log watch on
  896. period.period_id = watch.period_id
  897. left join fs_user_course uc on uc.course_id = watch.course_id
  898. left join fs_user_course_video v on v.video_id = watch.video_id
  899. left join company_user on company_user.user_id = watch.company_user_id
  900. <where>
  901. `period`.del_flag = '0' and watch.log_type &lt;&gt; 3
  902. <if test="trainingCampId != null">and camp.training_camp_id = #{trainingCampId}</if>
  903. <if test="userId != null">and watch.user_id = #{userId}</if>
  904. <if test="periodId != null">and `period`.period_id = #{periodId}</if>
  905. </where>
  906. </select>
  907. <select id="selectFsCourseWatchLogListVOexport" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  908. SELECT
  909. l.log_id,
  910. l.project AS project,
  911. l.period_id,
  912. l.user_id,
  913. l.log_type,
  914. SEC_TO_TIME(l.duration) AS duration,
  915. l.camp_period_time,
  916. l.finish_time,
  917. l.send_type,
  918. l.create_time,
  919. l.update_time,
  920. l.last_heartbeat_time,
  921. l.company_id,
  922. l.company_user_id,
  923. l.course_id,
  924. l.video_id,
  925. l.qw_user_id,
  926. l.qw_external_contact_id,
  927. l.sop_id,
  928. qec.create_time as qec_create_time,
  929. u.last_ip
  930. FROM
  931. fs_course_watch_log l LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  932. left join fs_user u on u.user_id = l.user_id
  933. left join company_user cu on cu.user_id = l.company_user_id
  934. <where>
  935. <if test ='maps.sendType !=null'>
  936. and l.send_type = #{maps.sendType}
  937. </if>
  938. <if test ='maps.userId !=null'>
  939. and l.user_id = #{maps.userId}
  940. </if>
  941. <if test ='maps.qwExternalContactId !=null'>
  942. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  943. </if>
  944. <if test ='maps.qwUserId !=null'>
  945. and l.qw_user_id = #{maps.qwUserId}
  946. </if>
  947. <if test ='maps.courseId !=null'>
  948. and l.course_id = #{maps.courseId}
  949. </if>
  950. <if test ='maps.videoId !=null'>
  951. and l.video_id = #{maps.videoId}
  952. </if>
  953. <if test ='maps.logType !=null'>
  954. and l.log_type = #{maps.logType}
  955. </if>
  956. <if test ='maps.periodId !=null'>
  957. and l.period_id = #{maps.periodId}
  958. </if>
  959. <if test ='maps.companyId !=null'>
  960. and l.company_id = #{maps.companyId}
  961. </if>
  962. <if test ='maps.companyUserId !=null'>
  963. and l.company_user_id = #{maps.companyUserId}
  964. </if>
  965. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  966. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  967. </if>
  968. <if test ='maps.nickName !=null and maps.nickName!=""'>
  969. and u.nick_name like concat('%', #{maps.nickName}, '%')
  970. </if>
  971. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  972. and qec.name like concat('%', #{maps.externalUserName}, '%')
  973. </if>
  974. <if test= 'maps.qecSTime != null '>
  975. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  976. </if>
  977. <if test='maps.qecETime != null '>
  978. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  979. </if>
  980. <if test= 'maps.sTime != null '>
  981. and DATE(l.create_time) &gt;= DATE(#{maps.sTime})
  982. </if>
  983. <if test='maps.eTime != null '>
  984. and DATE(l.create_time) &lt;= DATE(#{maps.eTime})
  985. </if>
  986. <if test= 'maps.scheduleStartTime != null '>
  987. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  988. </if>
  989. <if test='maps.scheduleEndTime != null '>
  990. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  991. </if>
  992. <if test= 'maps.upSTime != null '>
  993. and DATE(l.update_time) &gt;= DATE(#{maps.upSTime})
  994. </if>
  995. <if test='maps.upETime != null '>
  996. and DATE(l.update_time) &lt;= DATE(#{maps.upETime})
  997. </if>
  998. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  999. and l.sop_id in
  1000. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  1001. #{sopId}
  1002. </foreach>
  1003. </if>
  1004. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  1005. and l.period_id in
  1006. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  1007. #{periodId}
  1008. </foreach>
  1009. </if>
  1010. </where>
  1011. order by l.finish_time desc,l.update_time desc,l.create_time desc
  1012. </select>
  1013. <select id="getWatchCourseByVideoId" resultType="com.fs.course.domain.FsCourseWatchLog">
  1014. SELECT
  1015. *
  1016. FROM
  1017. fs_course_watch_log
  1018. WHERE
  1019. send_type = 1
  1020. AND video_id = #{videoId}
  1021. AND user_id in
  1022. <foreach item="userId" index="index" collection="userIds" open="(" separator="," close=")">
  1023. #{userId}
  1024. </foreach>
  1025. ORDER BY
  1026. log_id DESC
  1027. </select>
  1028. <select id="getUserCountByCampId" resultType="java.lang.Integer">
  1029. select count(distinct cwl.user_id)
  1030. from fs_user_course_period ucp
  1031. inner join fs_course_watch_log cwl on ucp.period_id = cwl.period_id
  1032. where ucp.training_camp_id = #{trainingCampId}
  1033. </select>
  1034. <select id="selectFsCourseWatchLogStatisticsListByCompanyVO"
  1035. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListByCompanyVO">
  1036. SELECT
  1037. o.video_id,
  1038. o.company_id,
  1039. comp.company_name,
  1040. o.qw_user_id,
  1041. DATE(o.create_time) create_time,
  1042. v.title videoName,
  1043. uc.course_name,
  1044. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  1045. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  1046. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  1047. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4
  1048. FROM
  1049. fs_course_watch_log o
  1050. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1051. LEFT JOIN company comp ON comp.company_id = o.company_id
  1052. LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
  1053. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1054. <where>
  1055. <if test="sendType != null">
  1056. and send_type = #{sendType}
  1057. </if>
  1058. <if test="companyId != null">
  1059. and o.company_id = #{companyId}
  1060. </if>
  1061. <if test="sTime != null">
  1062. AND DATE (o.create_time) &gt;= DATE (#{sTime})
  1063. </if>
  1064. <if test="eTime != null">
  1065. AND DATE (o.create_time) &lt;= DATE (#{eTime})
  1066. </if>
  1067. <if test="courseId != null">
  1068. and o.course_id = #{courseId}
  1069. </if>
  1070. <if test="videoId != null">
  1071. and o.video_id = #{videoId}
  1072. </if>
  1073. </where>
  1074. GROUP BY
  1075. DATE (o.create_time),
  1076. o.company_id
  1077. ORDER BY
  1078. comp.company_id,
  1079. DATE (o.create_time)
  1080. </select>
  1081. <select id="selectQwFsCourseWatchLogStatisticsListVO"
  1082. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO" parameterType="com.fs.qw.param.QwSidebarStatsParam">
  1083. SELECT
  1084. o.project,
  1085. o.course_id AS courseId,
  1086. uc.course_name AS courseName,
  1087. o.video_id AS videoId,
  1088. v.title AS videoName,
  1089. CASE WHEN o.log_type = 1 THEN 1 END AS type1,
  1090. CASE WHEN o.log_type = 2 THEN 1 END AS type2,
  1091. CASE WHEN o.log_type = 3 THEN 1 END AS type3,
  1092. CASE WHEN o.log_type = 4 THEN 1 END AS type4,
  1093. o.qw_user_id,
  1094. o.user_id AS userId,
  1095. o.company_user_id AS companyUserId,
  1096. o.company_id AS companyId,
  1097. o.create_time AS createTime
  1098. FROM
  1099. fs_course_watch_log o
  1100. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1101. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1102. WHERE
  1103. o.qw_external_contact_id=#{data.qwExternalContactId}
  1104. <if test="data.sendType != null">
  1105. AND send_type = #{data.sendType}
  1106. </if>
  1107. <if test="data.startTime != null">
  1108. AND DATE(o.create_time) &gt;= DATE(#{data.startTime})
  1109. </if>
  1110. <if test="data.endTime != null">
  1111. AND DATE(o.create_time) &lt;= DATE(#{data.endTime})
  1112. </if>
  1113. order by o.create_time DESC
  1114. </select>
  1115. <!-- 统计当天各公司的观看人数和完播人数, 存到redis中,定时任务每 ? 分钟执行一次 -->
  1116. <select id="watchCourseStatisticsGroupByCompany" resultType="com.fs.statis.dto.WatchCourseStatisticsResultDTO">
  1117. SELECT
  1118. o.company_id AS companyId,
  1119. c.company_name AS companyName,
  1120. o.send_type,
  1121. COUNT(DISTINCT o.user_id) AS watchUserCount,
  1122. COUNT(o.log_id) AS watchCount,
  1123. sum(case when o.log_type = 2 then 1 else 0 end) AS finishCount,
  1124. COUNT(DISTINCT CASE WHEN o.log_type = 2 THEN o.user_id END) AS finishUserCount
  1125. FROM
  1126. fs_course_watch_log o
  1127. LEFT JOIN company c ON c.company_id = o.company_id
  1128. WHERE
  1129. o.create_time &gt;= #{params.startTime}
  1130. AND o.create_time &lt;= #{params.endTime}
  1131. GROUP BY
  1132. o.company_id,
  1133. o.send_type
  1134. </select>
  1135. <select id="selectFsCourseWatchLogStatisticsListVO_COUNT"
  1136. resultType="java.lang.Long">
  1137. SELECT COUNT(*) FROM (
  1138. SELECT
  1139. o.video_id,
  1140. <!-- 用choose保证sendType逻辑互斥,避免GROUP BY字段缺失 -->
  1141. <choose>
  1142. <when test="sendType != 1">
  1143. o.qw_user_id,
  1144. </when>
  1145. <when test="sendType == 1">
  1146. o.company_user_id,
  1147. </when>
  1148. <!-- sendType为null时兜底,避免空指针 -->
  1149. <otherwise>
  1150. o.qw_user_id,
  1151. </otherwise>
  1152. </choose>
  1153. DATE(o.create_time) create_time
  1154. FROM fs_course_watch_log o
  1155. <!-- 动态关联qw_user表 -->
  1156. <if test="sendType != 1">
  1157. LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
  1158. </if>
  1159. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1160. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1161. <!-- 动态关联company_user表 -->
  1162. <if test="sendType == 1">
  1163. LEFT JOIN company_user cu ON cu.user_id = o.company_user_id
  1164. </if>
  1165. WHERE 1=1
  1166. <if test = 'companyId != null and companyId != 0'>
  1167. and o.company_id=#{companyId}
  1168. </if>
  1169. <if test = 'userIds != null and userIds.size() > 0'>
  1170. and o.company_user_id in
  1171. <foreach collection='userIds' item='id' open='(' separator=',' close=')'>
  1172. #{id}
  1173. </foreach>
  1174. </if>
  1175. <!-- 发送类型筛选 -->
  1176. <if test="sendType != null">
  1177. AND send_type = #{sendType}
  1178. </if>
  1179. <!-- 开始时间筛选:区分String/Date类型,避免类型比较异常 -->
  1180. <if test="sTime != null">
  1181. <choose>
  1182. <!-- sTime是String类型(yyyy-MM-dd) -->
  1183. <when test="sTime instanceof java.lang.String and sTime.trim() != ''">
  1184. AND o.create_time &gt;= STR_TO_DATE(#{sTime}, '%Y-%m-%d')
  1185. </when>
  1186. <!-- sTime是Date类型 -->
  1187. <otherwise>
  1188. AND o.create_time &gt;= #{sTime}
  1189. </otherwise>
  1190. </choose>
  1191. </if>
  1192. <!-- 结束时间筛选:区分String/Date类型 -->
  1193. <if test="eTime != null">
  1194. <choose>
  1195. <when test="eTime instanceof java.lang.String and eTime.trim() != ''">
  1196. AND o.create_time &lt; DATE_ADD(STR_TO_DATE(#{eTime}, '%Y-%m-%d'), INTERVAL 1 DAY)
  1197. </when>
  1198. <otherwise>
  1199. AND o.create_time &lt; DATE_ADD(#{eTime}, INTERVAL 1 DAY)
  1200. </otherwise>
  1201. </choose>
  1202. </if>
  1203. <!-- 昵称筛选:sendType!=1时关联qw_user -->
  1204. <if test="sendType != 1 and nickName != null and nickName.trim() != ''">
  1205. AND qu.qw_user_name LIKE CONCAT(#{nickName}, '%')
  1206. </if>
  1207. <!-- 昵称筛选:sendType==1时关联company_user -->
  1208. <if test="sendType == 1 and nickName != null and nickName.trim() != ''">
  1209. AND cu.nick_name LIKE CONCAT(#{nickName}, '%')
  1210. </if>
  1211. <!-- 课程ID筛选:加>0判断,避免null值拼接 -->
  1212. <if test="courseId != null and courseId > 0">
  1213. AND o.course_id = #{courseId}
  1214. </if>
  1215. <!-- 视频ID筛选:加>0判断 -->
  1216. <if test="videoId != null and videoId > 0">
  1217. AND o.video_id = #{videoId}
  1218. </if>
  1219. <!-- 分组条件:与子查询字段一致 -->
  1220. GROUP BY
  1221. o.video_id,
  1222. <choose>
  1223. <when test="sendType != 1">
  1224. o.qw_user_id,
  1225. </when>
  1226. <when test="sendType == 1">
  1227. o.company_user_id,
  1228. </when>
  1229. <otherwise>
  1230. o.qw_user_id,
  1231. </otherwise>
  1232. </choose>
  1233. DATE(o.create_time)
  1234. ) AS t
  1235. </select>
  1236. <select id="selectCompanyBaseInfo" resultType="com.fs.course.vo.FsCourseReportVO">
  1237. SELECT
  1238. c.company_id AS companyId,
  1239. c.company_name AS companyName
  1240. FROM company c
  1241. <where>
  1242. c.is_del=0
  1243. <if test="companyId != null and companyId != ''">
  1244. AND c.company_id = #{companyId}
  1245. </if>
  1246. </where>
  1247. GROUP BY c.company_id, c.company_name
  1248. ORDER BY c.create_time DESC
  1249. </select>
  1250. <select id="selectWatchStatistics" resultType="com.fs.course.vo.FsCourseReportVO">
  1251. SELECT
  1252. <choose>
  1253. <when test="dimension == 'company'">
  1254. fwl.company_id AS companyId,
  1255. </when>
  1256. <when test="dimension == 'course'">
  1257. fwl.course_id As courseId,
  1258. </when>
  1259. <when test="dimension == 'video'">
  1260. fwl.video_id AS videoId,
  1261. </when>
  1262. </choose>
  1263. COUNT(DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS finishedCount,
  1264. COUNT(CASE WHEN fwl.log_type = 2 THEN fwl.log_id END) AS courseCompleteTimes,
  1265. COUNT(DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END) AS accessCount,
  1266. ifnull(
  1267. ROUND(
  1268. (
  1269. COUNT( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) / count( DISTINCT CASE WHEN fwl.log_type != 3
  1270. THEN fwl.user_id END )) * 100,
  1271. 2
  1272. ),
  1273. 0
  1274. ) AS finishRate
  1275. FROM
  1276. fs_course_watch_log fwl
  1277. <where>
  1278. fwl.send_type = 2
  1279. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1280. AND fwl.create_time &gt;= #{startDate} AND fwl.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1281. </if>
  1282. <choose>
  1283. <when test="dimension == 'company' and companyId != null and companyId > 0">
  1284. AND fwl.company_id = #{companyId}
  1285. </when>
  1286. <when test="dimension == 'video' and videoId != null and videoId > 0">
  1287. AND fwl.video_id = #{videoId}
  1288. </when>
  1289. <when test="dimension == 'course' and courseId != null and courseId != ''">
  1290. AND fwl.course_id = #{courseId}
  1291. </when>
  1292. </choose>
  1293. </where>
  1294. <choose>
  1295. <when test="dimension == 'course'">
  1296. GROUP BY fwl.course_id
  1297. </when>
  1298. <when test="dimension == 'video'">
  1299. GROUP BY fwl.video_id
  1300. </when>
  1301. <otherwise>
  1302. GROUP BY fwl.company_id
  1303. </otherwise>
  1304. </choose>
  1305. ORDER BY accessCount desc
  1306. </select>
  1307. <select id="getSopCourseH5StudyList" resultType="com.fs.course.vo.FsSopMyCourseH5LinkVO">
  1308. 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
  1309. left join fs_user_course c on c.course_id = l.course_id
  1310. left join qw_user u on l.qw_user_id = u.id
  1311. left join fs_user_course_video v on l.video_id =v.video_id
  1312. where l.user_id = #{userId} AND l.create_time &gt;= CURDATE()
  1313. AND l.create_time &lt; CURDATE() + INTERVAL 1 DAY
  1314. order by l.create_time desc
  1315. </select>
  1316. <select id="selectFsUserWatchLogByExtId" resultType="com.fs.course.domain.FsCourseWatchLog">
  1317. select log_id logId from fs_course_watch_log where qw_external_contact_id = #{id}
  1318. and qw_user_id = #{qwUserId} and user_id is null
  1319. </select>
  1320. </mapper>