FsCourseWatchLogMapper.xml 53 KB

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