FsCourseWatchLogMapper.xml 44 KB

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