FsCourseWatchLogMapper.xml 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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. <insert id="insertBackup">
  398. INSERT INTO fs_course_watch_log_bak (
  399. original_log_id,
  400. user_id,
  401. video_id,
  402. log_type,
  403. create_time,
  404. update_time,
  405. qw_external_contact_id,
  406. duration,
  407. qw_user_id,
  408. company_user_id,
  409. company_id,
  410. course_id,
  411. send_type,
  412. reward_type,
  413. last_heartbeat_time,
  414. sop_id,
  415. finish_time,
  416. send_finish_msg,
  417. camp_period_time,
  418. day,
  419. project,
  420. create_by,
  421. update_by,
  422. period_id,
  423. project_id,
  424. im_msg_send_detail_id,
  425. watch_type,
  426. delete_time,
  427. delete_by,
  428. delete_method,
  429. original_data,
  430. backup_operator,
  431. backup_batch_no,
  432. remark
  433. ) VALUES (
  434. #{originalLogId},
  435. #{userId},
  436. #{videoId},
  437. #{logType},
  438. #{createTime},
  439. #{updateTime},
  440. #{qwExternalContactId},
  441. #{duration},
  442. #{qwUserId},
  443. #{companyUserId},
  444. #{companyId},
  445. #{courseId},
  446. #{sendType},
  447. #{rewardType},
  448. #{lastHeartbeatTime},
  449. #{sopId},
  450. #{finishTime},
  451. #{sendFinishMsg},
  452. #{campPeriodTime},
  453. #{day},
  454. #{project},
  455. #{createBy},
  456. #{updateBy},
  457. #{periodId},
  458. #{projectId},
  459. #{imMsgSendDetailId},
  460. #{watchType},
  461. #{deleteTime},
  462. #{deleteBy},
  463. #{deleteMethod},
  464. #{originalData},
  465. #{backupOperator},
  466. #{backupBatchNo},
  467. #{remark}
  468. )
  469. </insert>
  470. <update id="updateFsCourseWatchLog" parameterType="FsCourseWatchLog">
  471. update fs_course_watch_log
  472. <trim prefix="SET" suffixOverrides=",">
  473. <if test="userId != null">user_id = #{userId},</if>
  474. <if test="videoId != null">video_id = #{videoId},</if>
  475. <if test="logType != null">log_type = #{logType},</if>
  476. <if test="createTime != null">create_time = #{createTime},</if>
  477. <if test="updateTime != null">update_time = #{updateTime},</if>
  478. <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
  479. <if test="duration != null">duration = #{duration},</if>
  480. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  481. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  482. <if test="companyId != null">company_id = #{companyId},</if>
  483. <if test="courseId != null">course_id = #{courseId},</if>
  484. <if test="sendType != null">send_type = #{sendType},</if>
  485. <if test="rewardType != null">reward_type = #{rewardType},</if>
  486. <if test="sopId != null">sop_id = #{sopId},</if>
  487. <if test="finishTime != null">finish_time = #{finishTime},</if>
  488. <if test="sendFinishMsg != null">send_finish_msg = #{sendFinishMsg},</if>
  489. <if test="lastHeartbeatTime != null">last_heartbeat_time = #{lastHeartbeatTime},</if>
  490. <if test="periodId != null">period_id = #{periodId},</if>
  491. <if test="project != null">project = #{project},</if>
  492. <if test="watchType != null">watch_type = #{watchType},</if>
  493. </trim>
  494. where log_id = #{logId}
  495. </update>
  496. <delete id="deleteFsCourseWatchLogByLogId" parameterType="Long">
  497. delete from fs_course_watch_log where log_id = #{logId}
  498. </delete>
  499. <delete id="deleteFsCourseWatchLogByLogIds" parameterType="String">
  500. delete from fs_course_watch_log where log_id in
  501. <foreach item="logId" collection="array" open="(" separator="," close=")">
  502. #{logId}
  503. </foreach>
  504. </delete>
  505. <select id="selectFsCourseWatchLogByFinishTime" resultType="com.fs.course.param.FsCourseWatchLogByFinishTimeParam">
  506. <![CDATA[
  507. SELECT
  508. fcwl.log_id,
  509. fcwl.create_time,
  510. fcwl.qw_external_contact_id,
  511. fcwl.qw_user_id,
  512. fcwl.user_id,
  513. fcwl.company_user_id,
  514. fcwl.company_id,
  515. fcwl.sop_id,
  516. fcwl.finish_time,
  517. fcwl.camp_period_time,
  518. qec.corp_id,
  519. qec.external_user_id,
  520. qec.tag_ids,
  521. qec.user_id AS qw_user,
  522. qec.name AS external_contact_name
  523. FROM
  524. fs_course_watch_log fcwl
  525. LEFT JOIN qw_external_contact qec ON fcwl.qw_external_contact_id = qec.id
  526. WHERE
  527. DATE(fcwl.finish_time)= '2025-02-09'
  528. and fcwl.camp_period_time is not NULL
  529. ]]>
  530. </select>
  531. <select id="getWatchLogByFsUser" resultType="com.fs.course.domain.FsCourseWatchLog">
  532. SELECT
  533. log_id,
  534. user_id,
  535. video_id,
  536. log_type,
  537. create_time,
  538. update_time,
  539. duration,
  540. company_user_id,
  541. company_id,
  542. course_id,
  543. send_type,
  544. reward_type,
  545. last_heartbeat_time,
  546. sop_id,
  547. finish_time,
  548. send_finish_msg,
  549. camp_period_time,
  550. period_id
  551. FROM
  552. fs_course_watch_log
  553. WHERE
  554. send_type = 1
  555. AND video_id = #{videoId}
  556. AND user_id = #{fsUserId}
  557. AND company_user_id = #{companyUserId} order by log_id desc limit 1
  558. </select>
  559. <select id="selectFsCourseWatchLogStatisticsListVONew"
  560. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO">
  561. SELECT
  562. o.company_user_id,o.user_id,DATE(o.create_time) create_time,
  563. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  564. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  565. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  566. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4,
  567. o.project as project,
  568. o.course_id as course_id,
  569. o.video_id as video_id
  570. FROM fs_course_watch_log o
  571. <where>
  572. send_type=1
  573. <if test="companyId != null">
  574. and o.company_id=#{companyId}
  575. </if>
  576. <if test= 'sTime != null '>
  577. and DATE(o.create_time) &gt;= #{sTime}
  578. </if>
  579. <if test='eTime != null '>
  580. and DATE(o.create_time) &lt;= #{eTime}
  581. </if>
  582. <if test ='courseId !=null'>
  583. and o.course_id = #{courseId}
  584. </if>
  585. <if test ='videoId !=null'>
  586. and o.video_id = #{videoId}
  587. </if>
  588. <if test="companyUserId != null">
  589. and o.company_user_id = #{companyUserId}
  590. </if>
  591. <if test="project != null">
  592. and o.project = #{project}
  593. </if>
  594. <if test="userId != null">
  595. and o.user_id = #{userId}
  596. </if>
  597. </where>
  598. GROUP BY o.video_id,o.user_id,DATE(o.create_time),o.project,o.course_id
  599. ORDER BY o.video_id ,DATE(o.create_time)
  600. <!-- limit ${(pageNum-1)*pageSize},${pageSize}-->
  601. </select>
  602. <select id="selectFsCourseWatchLogStatisticsListVONewCount" resultType="java.lang.Long">
  603. SELECT COUNT(*)
  604. FROM (
  605. SELECT 1
  606. FROM fs_course_watch_log o
  607. <where>
  608. send_type=2
  609. <if test="companyId != null">
  610. and o.company_id=#{companyId}
  611. </if>
  612. <if test= 'sTime != null '>
  613. and o.create_time &gt;= #{startDate}
  614. </if>
  615. <if test='eTime != null '>
  616. and o.create_time &lt;= #{endDate}
  617. </if>
  618. <if test ='courseId !=null'>
  619. and o.course_id = #{courseId}
  620. </if>
  621. <if test ='videoId !=null'>
  622. and o.video_id = #{videoId}
  623. </if>
  624. <if test="companyUserId != null">
  625. and o.company_user_id = #{companyUserId}
  626. </if>
  627. <if test="project != null">
  628. and o.project = #{project}
  629. </if>
  630. <if test="userId != null">
  631. and o.user_id = #{userId}
  632. </if>
  633. </where>
  634. GROUP BY o.video_id, o.user_id, DATE(o.create_time), o.project, o.course_id
  635. ) AS grouped_results_count
  636. </select>
  637. <!-- 根据条件查询条数 -->
  638. <select id="countByMap" resultType="java.lang.Integer">
  639. select count(fcwl.log_id) from fs_course_watch_log fcwl
  640. <where>
  641. <if test="params.logTypes != null and params.logTypes.size() > 0">
  642. and fcwl.log_type in
  643. <foreach collection="params.logTypes" open="(" close=")" separator="," item="logType">
  644. #{logType}
  645. </foreach>
  646. </if>
  647. <if test="params.companyUserId != null">
  648. and fcwl.company_user_id = #{params.companyUserId}
  649. </if>
  650. <if test="params.date != null">
  651. and date(fcwl.create_time) = #{params.date}
  652. </if>
  653. </where>
  654. </select>
  655. <update id="batchUpdateWatchLog" parameterType="java.util.List">
  656. UPDATE fs_course_watch_log
  657. SET
  658. duration = CASE
  659. <foreach collection="list" item="item" index="index">
  660. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  661. CASE
  662. <!-- 仅当传入的duration > 当前值时才更新 -->
  663. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  664. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  665. END
  666. </foreach>
  667. END,
  668. last_heartbeat_time = CASE
  669. <foreach collection="list" item="item" index="index">
  670. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  671. CASE
  672. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  673. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  674. END
  675. </foreach>
  676. END,
  677. finish_time = CASE
  678. <foreach collection="list" item="item" index="index">
  679. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  680. CASE
  681. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  682. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  683. END
  684. </foreach>
  685. END,
  686. log_type = CASE
  687. <foreach collection="list" item="item" index="index">
  688. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  689. CASE
  690. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  691. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  692. ELSE log_type <!-- 其他情况保持原值 -->
  693. END
  694. </foreach>
  695. END
  696. WHERE
  697. (video_id, qw_external_contact_id, qw_user_id) IN
  698. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  699. (#{item.videoId}, #{item.qwExternalContactId}, #{item.qwUserId})
  700. </foreach>
  701. </update>
  702. <update id="batchUpdateWatchLogSendMsg" parameterType="java.util.List">
  703. UPDATE fs_course_watch_log
  704. SET send_finish_msg = CASE
  705. <foreach collection="list" item="item">
  706. WHEN log_id = #{item.logId} THEN #{item.sendFinishMsg}
  707. </foreach>
  708. ELSE send_finish_msg
  709. END
  710. WHERE log_id IN
  711. <foreach collection="list" item="item" open="(" separator="," close=")">
  712. #{item.logId}
  713. </foreach>
  714. </update>
  715. <update id="batchUpdateFsUserWatchLog" parameterType="java.util.List">
  716. UPDATE fs_course_watch_log
  717. SET
  718. duration = CASE
  719. <foreach collection="list" item="item" index="index">
  720. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  721. CASE
  722. <!-- 仅当传入的duration > 当前值时才更新 -->
  723. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  724. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  725. END
  726. </foreach>
  727. END,
  728. last_heartbeat_time = CASE
  729. <foreach collection="list" item="item" index="index">
  730. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  731. CASE
  732. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  733. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  734. END
  735. </foreach>
  736. END,
  737. finish_time = CASE
  738. <foreach collection="list" item="item" index="index">
  739. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  740. CASE
  741. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  742. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  743. END
  744. </foreach>
  745. END,
  746. log_type = CASE
  747. <foreach collection="list" item="item" index="index">
  748. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  749. CASE
  750. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  751. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  752. ELSE log_type <!-- 其他情况保持原值 -->
  753. END
  754. </foreach>
  755. END
  756. WHERE
  757. (video_id, user_id, company_user_id) IN
  758. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  759. (#{item.videoId}, #{item.userId}, #{item.companyUserId})
  760. </foreach>
  761. </update>
  762. <update id="batchUpdateWatchLogIsOpen">
  763. UPDATE fs_course_watch_log
  764. SET
  765. duration = CASE
  766. <foreach collection="list" item="item" index="index">
  767. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  768. CASE
  769. <!-- 仅当传入的duration > 当前值时才更新 -->
  770. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  771. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  772. END
  773. </foreach>
  774. END,
  775. last_heartbeat_time = CASE
  776. <foreach collection="list" item="item" index="index">
  777. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  778. CASE
  779. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  780. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  781. END
  782. </foreach>
  783. END,
  784. finish_time = CASE
  785. <foreach collection="list" item="item" index="index">
  786. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  787. CASE
  788. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  789. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  790. END
  791. </foreach>
  792. END,
  793. log_type = CASE
  794. <foreach collection="list" item="item" index="index">
  795. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  796. CASE
  797. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  798. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  799. ELSE log_type <!-- 其他情况保持原值 -->
  800. END
  801. </foreach>
  802. END
  803. WHERE
  804. (video_id, user_id) IN
  805. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  806. (#{item.videoId}, #{item.userId})
  807. </foreach>
  808. </update>
  809. <select id="selectListBytrainingCampId" resultType="com.fs.course.vo.FsCourseWatchLogVO">
  810. select
  811. uc.course_name,v.title as video_name,
  812. watch.log_id,
  813. watch.user_id,
  814. watch.finish_time,
  815. watch.send_finish_msg,
  816. watch.sop_id,
  817. watch.video_id,
  818. watch.reward_type,
  819. watch.log_type,
  820. watch.create_time,
  821. watch.update_time,
  822. watch.qw_external_contact_id,
  823. watch.duration,
  824. watch.qw_user_id,
  825. watch.company_user_id,
  826. watch.company_id,
  827. watch.course_id,
  828. watch.camp_period_time
  829. from
  830. fs_user_course_training_camp camp
  831. left join fs_user_course_period period on
  832. camp.training_camp_id = period.training_camp_id
  833. left join fs_course_watch_log watch on
  834. period.period_id = watch.period_id
  835. left join fs_user_course uc on uc.course_id = watch.course_id
  836. left join fs_user_course_video v on v.video_id = watch.video_id
  837. <where>
  838. `period`.del_flag = '0' and watch.log_type &lt;&gt; 3
  839. <if test="trainingCampId != null">and camp.training_camp_id = #{trainingCampId}</if>
  840. <if test="userId != null">and watch.user_id = #{userId}</if>
  841. <if test="periodId != null">and `period`.period_id = #{periodId}</if>
  842. </where>
  843. </select>
  844. <select id="selectFsCourseWatchLogListVOexport" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  845. SELECT
  846. l.log_id,
  847. l.project AS project,
  848. l.period_id,
  849. l.user_id,
  850. l.log_type,
  851. SEC_TO_TIME(l.duration) AS duration,
  852. l.camp_period_time,
  853. l.finish_time,
  854. l.send_type,
  855. l.create_time,
  856. l.update_time,
  857. l.last_heartbeat_time,
  858. l.company_id,
  859. l.company_user_id,
  860. l.course_id,
  861. l.video_id,
  862. l.qw_user_id,
  863. l.qw_external_contact_id,
  864. l.sop_id,
  865. qec.create_time as qec_create_time
  866. FROM
  867. fs_course_watch_log l LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  868. left join fs_user u on u.user_id = l.user_id
  869. left join company_user cu on cu.user_id = l.company_user_id
  870. <where>
  871. <if test ='maps.sendType !=null'>
  872. and l.send_type = #{maps.sendType}
  873. </if>
  874. <if test ='maps.userId !=null'>
  875. and l.user_id = #{maps.userId}
  876. </if>
  877. <if test ='maps.qwExternalContactId !=null'>
  878. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  879. </if>
  880. <if test ='maps.qwUserId !=null'>
  881. and l.qw_user_id = #{maps.qwUserId}
  882. </if>
  883. <if test ='maps.courseId !=null'>
  884. and l.course_id = #{maps.courseId}
  885. </if>
  886. <if test ='maps.videoId !=null'>
  887. and l.video_id = #{maps.videoId}
  888. </if>
  889. <if test ='maps.logType !=null'>
  890. and l.log_type = #{maps.logType}
  891. </if>
  892. <if test ='maps.periodId !=null'>
  893. and l.period_id = #{maps.periodId}
  894. </if>
  895. <if test ='maps.companyId !=null'>
  896. and l.company_id = #{maps.companyId}
  897. </if>
  898. <if test ='maps.companyUserId !=null'>
  899. and l.company_user_id = #{maps.companyUserId}
  900. </if>
  901. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  902. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  903. </if>
  904. <if test ='maps.nickName !=null and maps.nickName!=""'>
  905. and u.nick_name like concat('%', #{maps.nickName}, '%')
  906. </if>
  907. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  908. and qec.name like concat('%', #{maps.externalUserName}, '%')
  909. </if>
  910. <if test= 'maps.qecSTime != null '>
  911. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  912. </if>
  913. <if test='maps.qecETime != null '>
  914. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  915. </if>
  916. <if test= 'maps.sTime != null '>
  917. and DATE(l.create_time) &gt;= DATE(#{maps.sTime})
  918. </if>
  919. <if test='maps.eTime != null '>
  920. and DATE(l.create_time) &lt;= DATE(#{maps.eTime})
  921. </if>
  922. <if test= 'maps.scheduleStartTime != null '>
  923. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  924. </if>
  925. <if test='maps.scheduleEndTime != null '>
  926. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  927. </if>
  928. <if test= 'maps.upSTime != null '>
  929. and DATE(l.update_time) &gt;= DATE(#{maps.upSTime})
  930. </if>
  931. <if test='maps.upETime != null '>
  932. and DATE(l.update_time) &lt;= DATE(#{maps.upETime})
  933. </if>
  934. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  935. and l.sop_id in
  936. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  937. #{sopId}
  938. </foreach>
  939. </if>
  940. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  941. and l.period_id in
  942. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  943. #{periodId}
  944. </foreach>
  945. </if>
  946. </where>
  947. order by l.finish_time desc,l.update_time desc,l.create_time desc
  948. </select>
  949. <select id="getWatchCourseByVideoId" resultType="com.fs.course.domain.FsCourseWatchLog">
  950. SELECT
  951. *
  952. FROM
  953. fs_course_watch_log
  954. WHERE
  955. send_type = 1
  956. AND video_id = #{videoId}
  957. AND user_id in
  958. <foreach item="userId" index="index" collection="userIds" open="(" separator="," close=")">
  959. #{userId}
  960. </foreach>
  961. ORDER BY
  962. log_id DESC
  963. </select>
  964. <select id="getUserCountByCampId" resultType="java.lang.Integer">
  965. select count(distinct cwl.user_id)
  966. from fs_user_course_period ucp
  967. inner join fs_course_watch_log cwl on ucp.period_id = cwl.period_id
  968. where ucp.training_camp_id = #{trainingCampId}
  969. </select>
  970. <select id="selectFsCourseWatchLogStatisticsListByCompanyVO"
  971. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListByCompanyVO">
  972. SELECT
  973. o.video_id,
  974. o.company_id,
  975. comp.company_name,
  976. o.qw_user_id,
  977. DATE(o.create_time) create_time,
  978. v.title videoName,
  979. uc.course_name,
  980. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  981. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  982. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  983. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4
  984. FROM
  985. fs_course_watch_log o
  986. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  987. LEFT JOIN company comp ON comp.company_id = o.company_id
  988. LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
  989. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  990. <where>
  991. <if test="sendType != null">
  992. and send_type = #{sendType}
  993. </if>
  994. <if test="companyId != null">
  995. and o.company_id = #{companyId}
  996. </if>
  997. <if test="sTime != null">
  998. AND DATE (o.create_time) &gt;= DATE (#{sTime})
  999. </if>
  1000. <if test="eTime != null">
  1001. AND DATE (o.create_time) &lt;= DATE (#{eTime})
  1002. </if>
  1003. <if test="courseId != null">
  1004. and o.course_id = #{courseId}
  1005. </if>
  1006. <if test="videoId != null">
  1007. and o.video_id = #{videoId}
  1008. </if>
  1009. </where>
  1010. GROUP BY
  1011. DATE (o.create_time),
  1012. o.company_id
  1013. ORDER BY
  1014. comp.company_id,
  1015. DATE (o.create_time)
  1016. </select>
  1017. <select id="selectQwFsCourseWatchLogStatisticsListVO"
  1018. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO" parameterType="com.fs.qw.param.QwSidebarStatsParam">
  1019. SELECT
  1020. o.project,
  1021. o.course_id AS courseId,
  1022. uc.course_name AS courseName,
  1023. o.video_id AS videoId,
  1024. v.title AS videoName,
  1025. CASE WHEN o.log_type = 1 THEN 1 END AS type1,
  1026. CASE WHEN o.log_type = 2 THEN 1 END AS type2,
  1027. CASE WHEN o.log_type = 3 THEN 1 END AS type3,
  1028. CASE WHEN o.log_type = 4 THEN 1 END AS type4,
  1029. o.qw_user_id,
  1030. o.user_id AS userId,
  1031. o.company_user_id AS companyUserId,
  1032. o.company_id AS companyId,
  1033. o.create_time AS createTime
  1034. FROM
  1035. fs_course_watch_log o
  1036. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1037. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1038. WHERE o.qw_external_contact_id=#{qwExternalContactId}
  1039. <if test="sendType != null">
  1040. AND send_type = #{sendType}
  1041. </if>
  1042. <if test="startTime != null">
  1043. AND DATE(o.create_time) &gt;= DATE(#{startTime})
  1044. </if>
  1045. <if test="endTime != null">
  1046. AND DATE(o.create_time) &lt;= DATE(#{endTime})
  1047. </if>
  1048. o.create_time DESC
  1049. </select>
  1050. <!-- 统计当天各公司的观看人数和完播人数, 存到redis中,定时任务每 ? 分钟执行一次 -->
  1051. <select id="watchCourseStatisticsGroupByCompany" resultType="com.fs.statis.dto.WatchCourseStatisticsResultDTO">
  1052. SELECT
  1053. o.company_id AS companyId,
  1054. c.company_name AS companyName,
  1055. o.send_type,
  1056. COUNT(DISTINCT o.user_id) AS watchUserCount,
  1057. COUNT(o.log_id) AS watchCount,
  1058. sum(case when o.log_type = 2 then 1 else 0 end) AS finishCount,
  1059. COUNT(DISTINCT CASE WHEN o.log_type = 2 THEN o.user_id END) AS finishUserCount
  1060. FROM
  1061. fs_course_watch_log o
  1062. LEFT JOIN company c ON c.company_id = o.company_id
  1063. WHERE
  1064. o.create_time &gt;= #{params.startTime}
  1065. AND o.create_time &lt;= #{params.endTime}
  1066. <if test="params.companyId != null and params.companyId != ''">
  1067. AND o.company_id = #{params.companyId}
  1068. </if>
  1069. <if test="params.sendType != null and params.sendType != ''">
  1070. AND o.send_type = #{params.sendType}
  1071. </if>
  1072. GROUP BY
  1073. o.company_id,
  1074. o.send_type
  1075. </select>
  1076. <select id="selectWatchLogIMVOListByMap" resultType="com.fs.course.vo.FsCourseWatchLogIMVO">
  1077. select
  1078. fcwl.log_id as logId,
  1079. fucv.thumbnail as thumbnail,
  1080. fcwl.duration as duration,
  1081. fcwl.log_type as logType,
  1082. fcwl.create_time as createTime
  1083. from fs_course_watch_log fcwl
  1084. left join fs_user_course_video fucv on fucv.video_id = fcwl.video_id
  1085. where fcwl.send_type = 2
  1086. <if test="params.externalContactId != null">
  1087. and fcwl.qw_external_contact_id = #{params.externalContactId}
  1088. </if>
  1089. <if test="params.companyId != null">
  1090. and fcwl.company_id = #{params.companyId}
  1091. </if>
  1092. <if test="params.companyUserId != null">
  1093. and fcwl.company_user_id = #{params.companyUserId}
  1094. </if>
  1095. order by fcwl.create_time desc
  1096. </select>
  1097. <select id="selectFsCourseWatchLogStatisticsListVO_COUNT"
  1098. resultType="java.lang.Long">
  1099. SELECT COUNT(*) FROM (
  1100. SELECT
  1101. o.video_id,
  1102. <!-- 用choose保证sendType逻辑互斥,避免GROUP BY字段缺失 -->
  1103. <choose>
  1104. <when test="sendType != 1">
  1105. o.qw_user_id,
  1106. </when>
  1107. <when test="sendType == 1">
  1108. o.company_user_id,
  1109. </when>
  1110. <!-- sendType为null时兜底,避免空指针 -->
  1111. <otherwise>
  1112. o.qw_user_id,
  1113. </otherwise>
  1114. </choose>
  1115. DATE(o.create_time) create_time
  1116. FROM fs_course_watch_log o
  1117. <!-- 动态关联qw_user表 -->
  1118. <if test="sendType != 1">
  1119. LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
  1120. </if>
  1121. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1122. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1123. <!-- 动态关联company_user表 -->
  1124. <if test="sendType == 1">
  1125. LEFT JOIN company_user cu ON cu.user_id = o.company_user_id
  1126. </if>
  1127. WHERE o.company_id = #{companyId}
  1128. <!-- 发送类型筛选 -->
  1129. <if test="sendType != null">
  1130. AND send_type = #{sendType}
  1131. </if>
  1132. <!-- 开始时间筛选:区分String/Date类型,避免类型比较异常 -->
  1133. <if test="sTime != null">
  1134. <choose>
  1135. <!-- sTime是String类型(yyyy-MM-dd) -->
  1136. <when test="sTime instanceof java.lang.String and sTime.trim() != ''">
  1137. AND o.create_time &gt;= STR_TO_DATE(#{sTime}, '%Y-%m-%d')
  1138. </when>
  1139. <!-- sTime是Date类型 -->
  1140. <otherwise>
  1141. AND o.create_time &gt;= #{sTime}
  1142. </otherwise>
  1143. </choose>
  1144. </if>
  1145. <!-- 结束时间筛选:区分String/Date类型 -->
  1146. <if test="eTime != null">
  1147. <choose>
  1148. <when test="eTime instanceof java.lang.String and eTime.trim() != ''">
  1149. AND o.create_time &lt; DATE_ADD(STR_TO_DATE(#{eTime}, '%Y-%m-%d'), INTERVAL 1 DAY)
  1150. </when>
  1151. <otherwise>
  1152. AND o.create_time &lt; DATE_ADD(#{eTime}, INTERVAL 1 DAY)
  1153. </otherwise>
  1154. </choose>
  1155. </if>
  1156. <!-- 昵称筛选:sendType!=1时关联qw_user -->
  1157. <if test="sendType != 1 and nickName != null and nickName.trim() != ''">
  1158. AND qu.qw_user_name LIKE CONCAT(#{nickName}, '%')
  1159. </if>
  1160. <!-- 昵称筛选:sendType==1时关联company_user -->
  1161. <if test="sendType == 1 and nickName != null and nickName.trim() != ''">
  1162. AND cu.nick_name LIKE CONCAT(#{nickName}, '%')
  1163. </if>
  1164. <!-- 课程ID筛选:加>0判断,避免null值拼接 -->
  1165. <if test="courseId != null and courseId > 0">
  1166. AND o.course_id = #{courseId}
  1167. </if>
  1168. <!-- 视频ID筛选:加>0判断 -->
  1169. <if test="videoId != null and videoId > 0">
  1170. AND o.video_id = #{videoId}
  1171. </if>
  1172. <!-- 分组条件:与子查询字段一致 -->
  1173. GROUP BY
  1174. o.video_id,
  1175. <choose>
  1176. <when test="sendType != 1">
  1177. o.qw_user_id,
  1178. </when>
  1179. <when test="sendType == 1">
  1180. o.company_user_id,
  1181. </when>
  1182. <otherwise>
  1183. o.qw_user_id,
  1184. </otherwise>
  1185. </choose>
  1186. DATE(o.create_time)
  1187. ) AS t
  1188. </select>
  1189. <select id="selectFsCourseWatchLogByDaySopId3" resultType="com.fs.course.vo.FsCourseWatchLogTaskVO">
  1190. SELECT
  1191. l.qw_external_contact_id,
  1192. l.company_id,
  1193. l.company_user_id,
  1194. l.log_type,
  1195. ext.`level`,
  1196. l.qw_user_id
  1197. FROM fs_course_watch_log l
  1198. LEFT JOIN qw_external_contact ext ON ext.id = l.qw_external_contact_id
  1199. WHERE l.sop_id = #{sopId}
  1200. AND l.create_time >= #{todayStart}
  1201. AND l.create_time &lt; #{todayEnd}
  1202. AND l.log_type = 3
  1203. AND NOT EXISTS (
  1204. SELECT 1
  1205. FROM fs_user_course_video ucv
  1206. WHERE ucv.video_id = l.video_id
  1207. AND ucv.is_first = 1
  1208. LIMIT 1
  1209. )
  1210. </select>
  1211. <select id="selectFsCourseWatchLogByDaySopId4" resultType="com.fs.course.vo.FsCourseWatchLogTaskVO">
  1212. SELECT
  1213. l.qw_external_contact_id,
  1214. l.company_id,
  1215. l.company_user_id,
  1216. l.log_type,
  1217. ext.`level`,
  1218. l.qw_user_id
  1219. FROM fs_course_watch_log l
  1220. LEFT JOIN qw_external_contact ext ON ext.id = l.qw_external_contact_id
  1221. WHERE l.sop_id = #{sopId}
  1222. AND l.create_time >= #{todayStart}
  1223. AND l.create_time &lt; #{todayEnd}
  1224. AND l.log_type = 4
  1225. AND NOT EXISTS (
  1226. SELECT 1
  1227. FROM fs_user_course_video ucv
  1228. WHERE ucv.video_id = l.video_id
  1229. AND ucv.is_first = 1
  1230. LIMIT 1
  1231. )
  1232. </select>
  1233. <select id="getSopCourseH5StudyList" resultType="com.fs.course.vo.FsSopMyCourseH5LinkVO">
  1234. select c.img_url courseUrl,v.title courseName,c.title,l.log_id logId,u.qw_user_name qwUserName from fs_course_watch_log l
  1235. left join fs_user_course c on c.course_id = l.course_id
  1236. left join qw_user u on l.qw_user_id = u.id
  1237. left join fs_user_course_video v on l.video_id =v.video_id
  1238. where l.user_id = #{userId} AND l.create_time &gt;= CURDATE()
  1239. AND l.create_time &lt; CURDATE() + INTERVAL 1 DAY
  1240. order by l.create_time desc
  1241. </select>
  1242. <select id="findWatchLogsIdExitAndFinish" resultType="com.fs.course.domain.FsCourseWatchLog">
  1243. SELECT log_id,user_id,video_id,qw_user_id,company_user_id,company_id,course_id,qw_external_contact_id,send_type,period_id,watch_type,reward_type
  1244. FROM fs_course_watch_log
  1245. WHERE log_type = 2
  1246. AND finish_time &gt;= NOW() - INTERVAL 30 MINUTE
  1247. AND reward_type IS NULL
  1248. ORDER BY finish_time ASC
  1249. </select>
  1250. </mapper>