FsCourseWatchLogMapper.xml 50 KB

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