FsCourseWatchLogMapper.xml 50 KB

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