FsCourseWatchLogMapper.xml 58 KB

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