FsCourseWatchLogMapper.xml 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.course.mapper.FsCourseWatchLogMapper">
  6. <resultMap type="FsCourseWatchLog" id="FsCourseWatchLogResult">
  7. <result property="logId" column="log_id" />
  8. <result property="userId" column="user_id" />
  9. <result property="videoId" column="video_id" />
  10. <result property="logType" column="log_type" />
  11. <result property="createTime" column="create_time" />
  12. <result property="updateTime" column="update_time" />
  13. <result property="qwExternalContactId" column="qw_external_contact_id" />
  14. <result property="duration" column="duration" />
  15. <result property="qwUserId" column="qw_user_id" />
  16. <result property="companyUserId" column="company_user_id" />
  17. <result property="companyId" column="company_id" />
  18. <result property="courseId" column="course_id" />
  19. <result property="sendType" column="send_type" />
  20. <result property="rewardType" column="reward_type" />
  21. <result property="sopId" column="sop_id" />
  22. <result property="finishTime" column="finish_time" />
  23. <result property="sendFinishMsg" column="send_finish_msg" />
  24. <result property="campPeriodTime" column="camp_period_time" />
  25. <result property="lastHeartbeatTime" column="last_heartbeat_time" />
  26. <result property="project" column="project" />
  27. <result property="periodId" column="period_id" />
  28. <result property="watchType" column="watch_type" />
  29. </resultMap>
  30. <sql id="selectFsCourseWatchLogVo">
  31. select log_id, user_id,finish_time,send_finish_msg,sop_id,video_id,reward_type, log_type, create_time,
  32. update_time, qw_external_contact_id, duration, qw_user_id, company_user_id, company_id, course_id,
  33. camp_period_time,project,period_id,watch_type from fs_course_watch_log
  34. </sql>
  35. <select id="selectFsCourseWatchLogList" parameterType="FsCourseWatchLog" resultMap="FsCourseWatchLogResult">
  36. <include refid="selectFsCourseWatchLogVo"/>
  37. <where>
  38. <if test="userId != null "> and user_id = #{userId}</if>
  39. <if test="videoId != null "> and video_id = #{videoId}</if>
  40. <if test="logType != null "> and log_type = #{logType}</if>
  41. <if test="qwExternalContactId != null "> and qw_external_contact_id = #{qwExternalContactId}</if>
  42. <if test="duration != null "> and duration = #{duration}</if>
  43. <if test="qwUserId != null and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
  44. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  45. <if test="companyId != null "> and company_id = #{companyId}</if>
  46. <if test="courseId != null "> and course_id = #{courseId}</if>
  47. <if test="sendType != null "> and send_type = #{sendType}</if>
  48. <if test="campPeriodTime != null "> and camp_period_time = #{campPeriodTime}</if>
  49. <if test="project != null "> and project = #{project}</if>
  50. <if test="watchType != null "> and watch_type = #{watchType}</if>
  51. </where>
  52. </select>
  53. <select id="selectFsCourseWatchLogByLogId" parameterType="Long" resultMap="FsCourseWatchLogResult">
  54. <include refid="selectFsCourseWatchLogVo"/>
  55. where log_id = #{logId}
  56. </select>
  57. <select id="selectFsCourseWatchLogListVO" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  58. select l.log_id,l.project,l.period_id,l.user_id,uc.course_name,v.title as video_name,qec.avatar as external_user_avatar,qec.status as externalStatus,
  59. l.log_type,SEC_TO_TIME(l.duration) as duration,c.company_name,l.camp_period_time,l.finish_time,
  60. cu.nick_name as company_user_name ,l.send_type,l.create_time,l.update_time,l.last_heartbeat_time,
  61. qu.qw_user_name,qec.name as external_user_name,c.company_id,u.avatar as fsAvatar,u.nick_name as fsNickName,qec.create_time as qec_create_time,
  62. u.is_vip isVip,l.reward_type,cu.dept_id, l.watch_type,qec.tag_ids,u.last_ip
  63. from fs_course_watch_log l
  64. left join fs_user_course_video v on v.video_id = l.video_id
  65. left join fs_user_course uc on uc.course_id = l.course_id
  66. left join fs_user u on u.user_id = l.user_id
  67. left join company_user cu on cu.user_id = l.company_user_id
  68. left join company c on c.company_id = l.company_id
  69. LEFT JOIN qw_user qu on qu.id= l.qw_user_id
  70. LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  71. <where>
  72. <if test ='maps.isVip != null and maps.isVip == 0'>
  73. and (l.user_id = 0 or l.user_id is null)
  74. </if>
  75. <if test ='maps.isVip != null and maps.isVip == 1'>
  76. and l.user_id != 0 and l.user_id is not null
  77. </if>
  78. <if test ='maps.sendType !=null'>
  79. and l.send_type = #{maps.sendType}
  80. </if>
  81. <if test ='maps.userId !=null'>
  82. and l.user_id = #{maps.userId}
  83. </if>
  84. <if test ='maps.logId !=null'>
  85. and l.log_id = #{maps.logId}
  86. </if>
  87. <if test ='maps.project !=null'>
  88. and l.project = #{maps.project}
  89. </if>
  90. <if test ='maps.qwExternalContactId !=null'>
  91. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  92. </if>
  93. <if test ='maps.qwUserId !=null'>
  94. and l.qw_user_id = #{maps.qwUserId}
  95. </if>
  96. <if test ='maps.courseId !=null'>
  97. and l.course_id = #{maps.courseId}
  98. </if>
  99. <if test ='maps.videoId !=null'>
  100. and l.video_id = #{maps.videoId}
  101. </if>
  102. <if test ='maps.logType !=null'>
  103. and l.log_type = #{maps.logType}
  104. </if>
  105. <if test ='maps.companyId !=null'>
  106. and l.company_id = #{maps.companyId}
  107. </if>
  108. <if test ='maps.watchType !=null'>
  109. and l.watch_type = #{maps.watchType}
  110. </if>
  111. <if test ='maps.companyUserId !=null'>
  112. and l.company_user_id = #{maps.companyUserId}
  113. </if>
  114. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  115. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  116. </if>
  117. <if test ='maps.nickName !=null and maps.nickName!=""'>
  118. and u.nick_name like concat('%', #{maps.nickName}, '%')
  119. </if>
  120. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  121. and qec.name like concat('%', #{maps.externalUserName}, '%')
  122. </if>
  123. <if test= 'maps.qecSTime != null '>
  124. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  125. </if>
  126. <if test='maps.qecETime != null '>
  127. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  128. </if>
  129. <if test= 'maps.sTime != null '>
  130. and l.create_time &gt;= #{maps.sTime}
  131. </if>
  132. <if test='maps.eTime != null '>
  133. and l.create_time &lt;= #{maps.eTime}
  134. </if>
  135. <if test= 'maps.scheduleStartTime != null '>
  136. and l.camp_period_time &gt;= #{maps.scheduleStartTime}
  137. </if>
  138. <if test='maps.scheduleEndTime != null '>
  139. and l.camp_period_time &lt;= #{maps.scheduleEndTime}
  140. </if>
  141. <if test= 'maps.upSTime != null '>
  142. and l.update_time &gt;= #{maps.upSTime}
  143. </if>
  144. <if test='maps.upETime != null '>
  145. and l.update_time &lt; date_add(#{maps.upETime}, interval 1 day)
  146. </if>
  147. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  148. and l.sop_id in
  149. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  150. #{sopId}
  151. </foreach>
  152. </if>
  153. <if test ='maps.project !=null'>
  154. and l.project = #{maps.project}
  155. </if>
  156. <if test="maps.sopId != null and maps.sopId != '' ">
  157. and l.sop_id = #{maps.sopId}
  158. </if>
  159. <if test="maps.externalStatus != null and maps.externalStatus != '' ">
  160. and qec.status = #{maps.externalStatus}
  161. </if>
  162. <if test="maps.periodId != null">
  163. and l.period_id = #{maps.periodId}
  164. </if>
  165. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  166. and l.period_id in
  167. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  168. #{periodId}
  169. </foreach>
  170. </if>
  171. <if test="maps.qwUserName != null and maps.qwUserName != '' ">
  172. and qu.qw_user_name = #{maps.qwUserName}
  173. </if>
  174. <if test="maps.deptId != null and maps.deptId != '' ">
  175. and cu.dept_id = #{maps.deptId}
  176. </if>
  177. <if test='maps.cuDeptIdList != null and !maps.cuDeptIdList.isEmpty() and maps.userType != "00" '>
  178. AND cu.dept_id IN
  179. <foreach collection='maps.cuDeptIdList' item='item' open='(' separator=',' close=')'>
  180. #{item}
  181. </foreach>
  182. </if>
  183. <if test="maps.userIds != null and !maps.userIds.isEmpty()">
  184. AND cu.user_id IN
  185. <foreach collection='maps.userIds' item='item' open='(' separator=',' close=')'>
  186. #{item}
  187. </foreach>
  188. </if>
  189. </where>
  190. order by l.finish_time desc,l.update_time desc,l.create_time desc
  191. </select>
  192. <select id="selectFsCourseWatchLogListByWatchLogVO" resultType="com.fs.qw.domain.QwExternalContact">
  193. select qec.id,qec.user_id,qec.external_user_id,qec.corp_id,qec.tag_ids,qec.name
  194. from fs_course_watch_log l
  195. left join fs_user u on u.user_id = l.user_id
  196. left join company_user cu on cu.user_id = l.company_user_id
  197. LEFT JOIN qw_user qu on qu.id= l.qw_user_id
  198. LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  199. <where>
  200. <if test ='maps.isVip != null and maps.isVip == 0'>
  201. and (l.user_id = 0 or l.user_id is null)
  202. </if>
  203. <if test ='maps.isVip != null and maps.isVip == 1'>
  204. and l.user_id != 0 and l.user_id is not null
  205. </if>
  206. <if test ='maps.sendType !=null'>
  207. and l.send_type = #{maps.sendType}
  208. </if>
  209. <if test ='maps.userId !=null'>
  210. and l.user_id = #{maps.userId}
  211. </if>
  212. <if test ='maps.logId !=null'>
  213. and l.log_id = #{maps.logId}
  214. </if>
  215. <if test ='maps.project !=null'>
  216. and l.project = #{maps.project}
  217. </if>
  218. <if test ='maps.qwExternalContactId !=null'>
  219. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  220. </if>
  221. <if test ='maps.qwUserId !=null'>
  222. and l.qw_user_id = #{maps.qwUserId}
  223. </if>
  224. <if test ='maps.courseId !=null'>
  225. and l.course_id = #{maps.courseId}
  226. </if>
  227. <if test ='maps.videoId !=null'>
  228. and l.video_id = #{maps.videoId}
  229. </if>
  230. <if test ='maps.logType !=null'>
  231. and l.log_type = #{maps.logType}
  232. </if>
  233. <if test ='maps.companyId !=null'>
  234. and l.company_id = #{maps.companyId}
  235. </if>
  236. <if test ='maps.watchType !=null'>
  237. and l.watch_type = #{maps.watchType}
  238. </if>
  239. <if test ='maps.companyUserId !=null'>
  240. and l.company_user_id = #{maps.companyUserId}
  241. </if>
  242. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  243. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  244. </if>
  245. <if test ='maps.nickName !=null and maps.nickName!=""'>
  246. and u.nick_name like concat('%', #{maps.nickName}, '%')
  247. </if>
  248. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  249. and qec.name like concat('%', #{maps.externalUserName}, '%')
  250. </if>
  251. <if test= 'maps.qecSTime != null '>
  252. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  253. </if>
  254. <if test='maps.qecETime != null '>
  255. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  256. </if>
  257. <if test= 'maps.sTime != null '>
  258. and l.create_time &gt;= #{maps.sTime}
  259. </if>
  260. <if test='maps.eTime != null '>
  261. and l.create_time &lt;= #{maps.eTime}
  262. </if>
  263. <if test= 'maps.scheduleStartTime != null '>
  264. and l.camp_period_time &gt;= #{maps.scheduleStartTime}
  265. </if>
  266. <if test='maps.scheduleEndTime != null '>
  267. and l.camp_period_time &lt;= #{maps.scheduleEndTime}
  268. </if>
  269. <if test= 'maps.upSTime != null '>
  270. and l.update_time &gt;= #{maps.upSTime}
  271. </if>
  272. <if test='maps.upETime != null '>
  273. and l.update_time &lt; date_add(#{maps.upETime}, interval 1 day)
  274. </if>
  275. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  276. and l.sop_id in
  277. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  278. #{sopId}
  279. </foreach>
  280. </if>
  281. <if test ='maps.project !=null'>
  282. and l.project = #{maps.project}
  283. </if>
  284. <if test="maps.sopId != null and maps.sopId != '' ">
  285. and l.sop_id = #{maps.sopId}
  286. </if>
  287. <if test="maps.externalStatus != null and maps.externalStatus != '' ">
  288. and qec.status = #{maps.externalStatus}
  289. </if>
  290. <if test="maps.periodId != null">
  291. and l.period_id = #{maps.periodId}
  292. </if>
  293. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  294. and l.period_id in
  295. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  296. #{periodId}
  297. </foreach>
  298. </if>
  299. <if test="maps.qwUserName != null and maps.qwUserName != '' ">
  300. and qu.qw_user_name = #{maps.qwUserName}
  301. </if>
  302. <if test="maps.deptId != null and maps.deptId != '' ">
  303. and cu.dept_id = #{maps.deptId}
  304. </if>
  305. <if test='maps.cuDeptIdList != null and !maps.cuDeptIdList.isEmpty() and maps.userType != "00" '>
  306. AND cu.dept_id IN
  307. <foreach collection='maps.cuDeptIdList' item='item' open='(' separator=',' close=')'>
  308. #{item}
  309. </foreach>
  310. </if>
  311. <if test="maps.userIds != null and !maps.userIds.isEmpty()">
  312. AND cu.user_id IN
  313. <foreach collection='maps.userIds' item='item' open='(' separator=',' close=')'>
  314. #{item}
  315. </foreach>
  316. </if>
  317. </where>
  318. GROUP BY
  319. qec.user_id,
  320. qec.external_user_id,
  321. qec.corp_id
  322. </select>
  323. <select id="selectFsCourseWatchLogListByParam" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  324. select l.log_id,l.user_id,uc.course_name,v.title as video_name,u.nick_name as fsNickName, u.avatar as fsAvatar,
  325. l.log_type,SEC_TO_TIME(l.duration) as duration,c.company_name,l.camp_period_time,l.finish_time,
  326. cu.nick_name as company_user_name ,l.send_type,l.create_time, qu.qw_user_name,qec.name as external_user_name
  327. from fs_course_watch_log l
  328. left join fs_user_course_video v on v.video_id = l.video_id
  329. left join fs_user_course uc on uc.course_id = l.course_id
  330. left join fs_user u on u.user_id = l.user_id
  331. left join company_user cu on cu.user_id = l.company_user_id
  332. left join company c on c.company_id = l.company_id
  333. LEFT JOIN qw_user qu on qu.id= l.qw_user_id
  334. LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  335. <where>
  336. <if test ='userId !=null'>
  337. and l.user_id = #{userId}
  338. </if>
  339. <if test ='qwUserId !=null'>
  340. and l.qw_user_id = #{qwUserId}
  341. </if>
  342. <if test ='courseId !=null'>
  343. and l.course_id = #{courseId}
  344. </if>
  345. <if test ='videoId !=null'>
  346. and l.video_id = #{videoId}
  347. </if>
  348. <if test ='logType !=null'>
  349. and l.log_type = #{logType}
  350. </if>
  351. <if test ='companyId !=null'>
  352. and l.company_id = #{companyId}
  353. </if>
  354. <if test ='companyUserId !=null'>
  355. and l.company_user_id = #{companyUserId}
  356. </if>
  357. <if test ='companyUserName !=null and maps.companyUserName!=""'>
  358. and cu.nick_name like concat('%', #{companyUserName}, '%')
  359. </if>
  360. <if test ='nickName !=null and maps.nickName!=""'>
  361. and u.nick_name like concat('%', #{nickName}, '%')
  362. </if>
  363. <if test= 'sTime != null '>
  364. and DATE(l.create_time) &gt;= DATE(#{sTime})
  365. </if>
  366. <if test='eTime != null '>
  367. and DATE(l.create_time) &lt;= DATE(#{eTime})
  368. </if>
  369. <if test= 'maps.scheduleStartTime != null '>
  370. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  371. </if>
  372. <if test='maps.scheduleEndTime != null '>
  373. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  374. </if>
  375. <if test="sopIds != null and sopIds.size() > 0">
  376. and l.sop_id in
  377. <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
  378. #{sopId}
  379. </foreach>
  380. </if>
  381. <if test="maps.watchType != null "> and l.watch_type = #{maps.watchType}</if>
  382. </where>
  383. order by l.log_id desc
  384. </select>
  385. <insert id="insertFsCourseWatchLog" parameterType="FsCourseWatchLog" useGeneratedKeys="true" keyProperty="logId">
  386. insert into fs_course_watch_log
  387. <trim prefix="(" suffix=")" suffixOverrides=",">
  388. <if test="userId != null">user_id,</if>
  389. <if test="videoId != null">video_id,</if>
  390. <if test="logType != null">log_type,</if>
  391. <if test="createTime != null">create_time,</if>
  392. <if test="updateTime != null">update_time,</if>
  393. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  394. <if test="duration != null">duration,</if>
  395. <if test="qwUserId != null">qw_user_id,</if>
  396. <if test="companyUserId != null">company_user_id,</if>
  397. <if test="companyId != null">company_id,</if>
  398. <if test="courseId != null">course_id,</if>
  399. <if test="sendType != null">send_type,</if>
  400. <if test="rewardType != null">reward_type,</if>
  401. <if test="sopId != null">sop_id,</if>
  402. <if test="finishTime != null">finish_time,</if>
  403. <if test="sendFinishMsg != null">send_finish_msg,</if>
  404. <if test="campPeriodTime != null">camp_period_time,</if>
  405. <if test="periodId != null">period_id,</if>
  406. <if test="project != null">project,</if>
  407. <if test="watchType != null">watch_type,</if>
  408. </trim>
  409. <trim prefix="values (" suffix=")" suffixOverrides=",">
  410. <if test="userId != null">#{userId},</if>
  411. <if test="videoId != null">#{videoId},</if>
  412. <if test="logType != null">#{logType},</if>
  413. <if test="createTime != null">#{createTime},</if>
  414. <if test="updateTime != null">#{updateTime},</if>
  415. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  416. <if test="duration != null">#{duration},</if>
  417. <if test="qwUserId != null">#{qwUserId},</if>
  418. <if test="companyUserId != null">#{companyUserId},</if>
  419. <if test="companyId != null">#{companyId},</if>
  420. <if test="courseId != null">#{courseId},</if>
  421. <if test="sendType != null">#{sendType},</if>
  422. <if test="rewardType != null">#{rewardType},</if>
  423. <if test="sopId != null">#{sopId},</if>
  424. <if test="finishTime != null">#{finishTime},</if>
  425. <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
  426. <if test="campPeriodTime != null">#{campPeriodTime},</if>
  427. <if test="periodId != null">#{periodId},</if>
  428. <if test="project != null">#{project},</if>
  429. <if test="watchType != null">#{watchType},</if>
  430. </trim>
  431. </insert>
  432. <insert id="insertOrUpdateFsCourseWatchLog" parameterType="FsCourseWatchLog">
  433. insert into fs_course_watch_log
  434. <trim prefix="(" suffix=")" suffixOverrides=",">
  435. <if test="userId != null">user_id,</if>
  436. <if test="videoId != null">video_id,</if>
  437. <if test="logType != null">log_type,</if>
  438. <if test="createTime != null">create_time,</if>
  439. <if test="updateTime != null">update_time,</if>
  440. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  441. <if test="duration != null">duration,</if>
  442. <if test="qwUserId != null">qw_user_id,</if>
  443. <if test="companyUserId != null">company_user_id,</if>
  444. <if test="companyId != null">company_id,</if>
  445. <if test="courseId != null">course_id,</if>
  446. <if test="sendType != null">send_type,</if>
  447. <if test="rewardType != null">reward_type,</if>
  448. <if test="sopId != null">sop_id,</if>
  449. <if test="finishTime != null">finish_time,</if>
  450. <if test="sendFinishMsg != null">send_finish_msg,</if>
  451. <if test="campPeriodTime != null">camp_period_time,</if>
  452. <if test="project != null">project,</if>
  453. <if test="watchType != null">watch_type,</if>
  454. </trim>
  455. <trim prefix="values (" suffix=")" suffixOverrides=",">
  456. <if test="userId != null">#{userId},</if>
  457. <if test="videoId != null">#{videoId},</if>
  458. <if test="logType != null">#{logType},</if>
  459. <if test="createTime != null">#{createTime},</if>
  460. <if test="updateTime != null">#{updateTime},</if>
  461. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  462. <if test="duration != null">#{duration},</if>
  463. <if test="qwUserId != null">#{qwUserId},</if>
  464. <if test="companyUserId != null">#{companyUserId},</if>
  465. <if test="companyId != null">#{companyId},</if>
  466. <if test="courseId != null">#{courseId},</if>
  467. <if test="sendType != null">#{sendType},</if>
  468. <if test="rewardType != null">#{rewardType},</if>
  469. <if test="sopId != null">#{sopId},</if>
  470. <if test="finishTime != null">#{finishTime},</if>
  471. <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
  472. <if test="campPeriodTime != null">#{campPeriodTime},</if>
  473. <if test="project != null">#{project},</if>
  474. <if test="watchType != null">#{watchType},</if>
  475. </trim>
  476. on duplicate key update
  477. <trim suffixOverrides=",">
  478. <if test="updateTime != null">update_time = #{updateTime},</if>
  479. </trim>
  480. </insert>
  481. <insert id="insertFsCourseWatchLogBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="logId">
  482. INSERT INTO fs_course_watch_log (
  483. user_id,
  484. video_id,
  485. log_type,
  486. create_time,
  487. update_time,
  488. qw_external_contact_id,
  489. duration,
  490. qw_user_id,
  491. company_user_id,
  492. company_id,
  493. course_id,
  494. send_type,
  495. reward_type,
  496. sop_id,
  497. camp_period_time,
  498. project,
  499. period_id,
  500. im_msg_send_detail_id,
  501. watch_type,
  502. link_id
  503. )
  504. VALUES
  505. <foreach collection="watchLogs" item="log" separator=",">
  506. (
  507. #{log.userId},
  508. #{log.videoId},
  509. #{log.logType},
  510. #{log.createTime},
  511. #{log.updateTime},
  512. #{log.qwExternalContactId},
  513. #{log.duration},
  514. #{log.qwUserId},
  515. #{log.companyUserId},
  516. #{log.companyId},
  517. #{log.courseId},
  518. #{log.sendType},
  519. #{log.rewardType},
  520. #{log.sopId},
  521. #{log.campPeriodTime},
  522. #{log.project},
  523. #{log.periodId},
  524. #{log.imMsgSendDetailId},
  525. #{log.watchType},
  526. #{log.linkId}
  527. )
  528. </foreach>
  529. ON DUPLICATE KEY UPDATE
  530. update_time = NOW(),
  531. im_msg_send_detail_id = VALUES(im_msg_send_detail_id),
  532. link_id = VALUES(link_id)
  533. </insert>
  534. <update id="updateFsCourseWatchLog" parameterType="FsCourseWatchLog">
  535. update fs_course_watch_log
  536. <trim prefix="SET" suffixOverrides=",">
  537. <if test="userId != null">user_id = #{userId},</if>
  538. <if test="videoId != null">video_id = #{videoId},</if>
  539. <if test="logType != null">log_type = #{logType},</if>
  540. <if test="createTime != null">create_time = #{createTime},</if>
  541. <if test="updateTime != null">update_time = #{updateTime},</if>
  542. <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
  543. <if test="duration != null">duration = #{duration},</if>
  544. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  545. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  546. <if test="companyId != null">company_id = #{companyId},</if>
  547. <if test="courseId != null">course_id = #{courseId},</if>
  548. <if test="sendType != null">send_type = #{sendType},</if>
  549. <if test="rewardType != null">reward_type = #{rewardType},</if>
  550. <if test="sopId != null">sop_id = #{sopId},</if>
  551. <if test="finishTime != null">finish_time = #{finishTime},</if>
  552. <if test="sendFinishMsg != null">send_finish_msg = #{sendFinishMsg},</if>
  553. <if test="lastHeartbeatTime != null">last_heartbeat_time = #{lastHeartbeatTime},</if>
  554. <if test="periodId != null">period_id = #{periodId},</if>
  555. <if test="project != null">project = #{project},</if>
  556. <if test="watchType != null">watch_type = #{watchType},</if>
  557. </trim>
  558. where log_id = #{logId}
  559. </update>
  560. <delete id="deleteFsCourseWatchLogByLogId" parameterType="Long">
  561. delete from fs_course_watch_log where log_id = #{logId}
  562. </delete>
  563. <delete id="deleteFsCourseWatchLogByLogIds" parameterType="String">
  564. delete from fs_course_watch_log where log_id in
  565. <foreach item="logId" collection="array" open="(" separator="," close=")">
  566. #{logId}
  567. </foreach>
  568. </delete>
  569. <select id="selectFsCourseWatchLogByFinishTime" resultType="com.fs.course.param.FsCourseWatchLogByFinishTimeParam">
  570. <![CDATA[
  571. SELECT
  572. fcwl.log_id,
  573. fcwl.create_time,
  574. fcwl.qw_external_contact_id,
  575. fcwl.qw_user_id,
  576. fcwl.user_id,
  577. fcwl.company_user_id,
  578. fcwl.company_id,
  579. fcwl.sop_id,
  580. fcwl.finish_time,
  581. fcwl.camp_period_time,
  582. qec.corp_id,
  583. qec.external_user_id,
  584. qec.tag_ids,
  585. qec.user_id AS qw_user,
  586. qec.name AS external_contact_name
  587. FROM
  588. fs_course_watch_log fcwl
  589. LEFT JOIN qw_external_contact qec ON fcwl.qw_external_contact_id = qec.id
  590. WHERE
  591. DATE(fcwl.finish_time)= '2025-02-09'
  592. and fcwl.camp_period_time is not NULL
  593. ]]>
  594. </select>
  595. <select id="getWatchLogByFsUser" resultType="com.fs.course.domain.FsCourseWatchLog">
  596. SELECT
  597. log_id,
  598. user_id,
  599. video_id,
  600. log_type,
  601. create_time,
  602. update_time,
  603. duration,
  604. company_user_id,
  605. company_id,
  606. course_id,
  607. send_type,
  608. reward_type,
  609. last_heartbeat_time,
  610. sop_id,
  611. finish_time,
  612. send_finish_msg,
  613. camp_period_time,
  614. period_id
  615. FROM
  616. fs_course_watch_log
  617. WHERE
  618. send_type = 1
  619. AND video_id = #{videoId}
  620. AND user_id = #{fsUserId}
  621. AND company_user_id = #{companyUserId} order by log_id desc limit 1
  622. </select>
  623. <select id="getWatchLogByFsUserAndPeriodId" resultType="com.fs.course.domain.FsCourseWatchLog">
  624. SELECT
  625. log_id,
  626. user_id,
  627. video_id,
  628. log_type,
  629. create_time,
  630. update_time,
  631. duration,
  632. company_user_id,
  633. company_id,
  634. course_id,
  635. send_type,
  636. reward_type,
  637. last_heartbeat_time,
  638. sop_id,
  639. finish_time,
  640. send_finish_msg,
  641. camp_period_time,
  642. period_id
  643. FROM
  644. fs_course_watch_log
  645. WHERE
  646. send_type = 1
  647. AND video_id = #{videoId}
  648. AND user_id = #{fsUserId}
  649. AND company_user_id = #{companyUserId}
  650. <if test="periodId != null">
  651. and period_id = #{periodId}
  652. </if>
  653. order by log_id desc limit 1
  654. </select>
  655. <select id="selectFsCourseWatchLogStatisticsListVONew"
  656. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO">
  657. SELECT
  658. o.company_user_id,o.user_id,DATE(o.create_time) create_time,
  659. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  660. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  661. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  662. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4,
  663. o.project as project,
  664. o.course_id as course_id,
  665. o.video_id as video_id
  666. FROM fs_course_watch_log o
  667. <where>
  668. send_type=1
  669. <if test="companyId != null">
  670. and o.company_id=#{companyId}
  671. </if>
  672. <if test= 'sTime != null '>
  673. and DATE(o.create_time) &gt;= #{sTime}
  674. </if>
  675. <if test='eTime != null '>
  676. and DATE(o.create_time) &lt;= #{eTime}
  677. </if>
  678. <if test ='courseId !=null'>
  679. and o.course_id = #{courseId}
  680. </if>
  681. <if test ='videoId !=null'>
  682. and o.video_id = #{videoId}
  683. </if>
  684. <if test="companyUserId != null">
  685. and o.company_user_id = #{companyUserId}
  686. </if>
  687. <if test="project != null">
  688. and o.project = #{project}
  689. </if>
  690. <if test="userId != null">
  691. and o.user_id = #{userId}
  692. </if>
  693. </where>
  694. GROUP BY o.video_id,o.user_id,DATE(o.create_time),o.project,o.course_id
  695. ORDER BY o.video_id ,DATE(o.create_time)
  696. <!-- limit ${(pageNum-1)*pageSize},${pageSize}-->
  697. </select>
  698. <select id="selectFsCourseWatchLogStatisticsListVONewCount" resultType="java.lang.Long">
  699. SELECT COUNT(*)
  700. FROM (
  701. SELECT 1
  702. FROM fs_course_watch_log o
  703. <where>
  704. send_type=2
  705. <if test="companyId != null">
  706. and o.company_id=#{companyId}
  707. </if>
  708. <if test= 'sTime != null '>
  709. and o.create_time &gt;= #{startDate}
  710. </if>
  711. <if test='eTime != null '>
  712. and o.create_time &lt;= #{endDate}
  713. </if>
  714. <if test ='courseId !=null'>
  715. and o.course_id = #{courseId}
  716. </if>
  717. <if test ='videoId !=null'>
  718. and o.video_id = #{videoId}
  719. </if>
  720. <if test="companyUserId != null">
  721. and o.company_user_id = #{companyUserId}
  722. </if>
  723. <if test="project != null">
  724. and o.project = #{project}
  725. </if>
  726. <if test="userId != null">
  727. and o.user_id = #{userId}
  728. </if>
  729. </where>
  730. GROUP BY o.video_id, o.user_id, DATE(o.create_time), o.project, o.course_id
  731. ) AS grouped_results_count
  732. </select>
  733. <!-- 根据条件查询条数 -->
  734. <select id="countByMap" resultType="java.lang.Integer">
  735. select count(fcwl.log_id) from fs_course_watch_log fcwl
  736. <where>
  737. <if test="params.logTypes != null and params.logTypes.size() > 0">
  738. and fcwl.log_type in
  739. <foreach collection="params.logTypes" open="(" close=")" separator="," item="logType">
  740. #{logType}
  741. </foreach>
  742. </if>
  743. <if test="params.companyUserId != null">
  744. and fcwl.company_user_id = #{params.companyUserId}
  745. </if>
  746. <if test="params.date != null">
  747. and date(fcwl.create_time) = #{params.date}
  748. </if>
  749. </where>
  750. </select>
  751. <update id="batchUpdateWatchLog" parameterType="java.util.List">
  752. UPDATE fs_course_watch_log
  753. SET
  754. duration = CASE
  755. <foreach collection="list" item="item" index="index">
  756. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  757. CASE
  758. <!-- 仅当传入的duration > 当前值时才更新 -->
  759. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  760. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  761. END
  762. </foreach>
  763. END,
  764. last_heartbeat_time = CASE
  765. <foreach collection="list" item="item" index="index">
  766. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  767. CASE
  768. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  769. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  770. END
  771. </foreach>
  772. END,
  773. finish_time = CASE
  774. <foreach collection="list" item="item" index="index">
  775. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  776. CASE
  777. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  778. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  779. END
  780. </foreach>
  781. END,
  782. log_type = CASE
  783. <foreach collection="list" item="item" index="index">
  784. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  785. CASE
  786. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  787. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  788. ELSE log_type <!-- 其他情况保持原值 -->
  789. END
  790. </foreach>
  791. END
  792. WHERE
  793. (video_id, qw_external_contact_id, qw_user_id) IN
  794. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  795. (#{item.videoId}, #{item.qwExternalContactId}, #{item.qwUserId})
  796. </foreach>
  797. </update>
  798. <update id="batchUpdateWatchLogSendMsg" parameterType="java.util.List">
  799. UPDATE fs_course_watch_log
  800. SET send_finish_msg = CASE
  801. <foreach collection="list" item="item">
  802. WHEN log_id = #{item.logId} THEN #{item.sendFinishMsg}
  803. </foreach>
  804. ELSE send_finish_msg
  805. END
  806. WHERE log_id IN
  807. <foreach collection="list" item="item" open="(" separator="," close=")">
  808. #{item.logId}
  809. </foreach>
  810. </update>
  811. <update id="batchUpdateFsUserWatchLog" parameterType="java.util.List">
  812. UPDATE fs_course_watch_log
  813. SET
  814. duration = CASE
  815. <foreach collection="list" item="item" index="index">
  816. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  817. CASE
  818. <!-- 仅当传入的duration > 当前值时才更新 -->
  819. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  820. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  821. END
  822. </foreach>
  823. END,
  824. last_heartbeat_time = CASE
  825. <foreach collection="list" item="item" index="index">
  826. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  827. CASE
  828. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  829. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  830. END
  831. </foreach>
  832. END,
  833. finish_time = CASE
  834. <foreach collection="list" item="item" index="index">
  835. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  836. CASE
  837. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  838. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  839. END
  840. </foreach>
  841. END,
  842. log_type = CASE
  843. <foreach collection="list" item="item" index="index">
  844. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  845. CASE
  846. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  847. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  848. ELSE log_type <!-- 其他情况保持原值 -->
  849. END
  850. </foreach>
  851. END
  852. WHERE
  853. (video_id, user_id, company_user_id) IN
  854. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  855. (#{item.videoId}, #{item.userId}, #{item.companyUserId})
  856. </foreach>
  857. </update>
  858. <update id="batchUpdateWatchLogIsOpen">
  859. UPDATE fs_course_watch_log
  860. SET
  861. duration = CASE
  862. <foreach collection="list" item="item" index="index">
  863. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  864. CASE
  865. <!-- 仅当传入的duration > 当前值时才更新 -->
  866. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  867. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  868. END
  869. </foreach>
  870. END,
  871. last_heartbeat_time = CASE
  872. <foreach collection="list" item="item" index="index">
  873. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  874. CASE
  875. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  876. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  877. END
  878. </foreach>
  879. END,
  880. finish_time = CASE
  881. <foreach collection="list" item="item" index="index">
  882. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  883. CASE
  884. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  885. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  886. END
  887. </foreach>
  888. END,
  889. log_type = CASE
  890. <foreach collection="list" item="item" index="index">
  891. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  892. CASE
  893. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  894. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  895. ELSE log_type <!-- 其他情况保持原值 -->
  896. END
  897. </foreach>
  898. END
  899. WHERE
  900. (video_id, user_id) IN
  901. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  902. (#{item.videoId}, #{item.userId})
  903. </foreach>
  904. </update>
  905. <select id="selectListBytrainingCampId" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  906. select
  907. uc.course_name,v.title as video_name,
  908. watch.log_id,
  909. watch.user_id,
  910. watch.finish_time,
  911. watch.send_finish_msg,
  912. watch.sop_id,
  913. watch.video_id,
  914. watch.reward_type,
  915. watch.log_type,
  916. watch.create_time,
  917. watch.update_time,
  918. watch.qw_external_contact_id,
  919. watch.duration,
  920. watch.qw_user_id,
  921. watch.company_user_id,
  922. watch.company_id,
  923. watch.course_id,
  924. watch.camp_period_time,
  925. company_user.nick_name as companyUserName
  926. from
  927. fs_user_course_training_camp camp
  928. left join fs_user_course_period period on
  929. camp.training_camp_id = period.training_camp_id
  930. left join fs_course_watch_log watch on
  931. period.period_id = watch.period_id
  932. left join fs_user_course uc on uc.course_id = watch.course_id
  933. left join fs_user_course_video v on v.video_id = watch.video_id
  934. left join company_user on company_user.user_id = watch.company_user_id
  935. <where>
  936. `period`.del_flag = '0' and watch.log_type &lt;&gt; 3
  937. <if test="trainingCampId != null">and camp.training_camp_id = #{trainingCampId}</if>
  938. <if test="userId != null">and watch.user_id = #{userId}</if>
  939. <if test="periodId != null">and `period`.period_id = #{periodId}</if>
  940. </where>
  941. </select>
  942. <select id="selectFsCourseWatchLogListVOexport" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  943. SELECT
  944. l.log_id,
  945. l.project AS project,
  946. l.period_id,
  947. l.user_id,
  948. l.log_type,
  949. SEC_TO_TIME(l.duration) AS duration,
  950. l.camp_period_time,
  951. l.finish_time,
  952. l.send_type,
  953. l.create_time,
  954. l.update_time,
  955. l.last_heartbeat_time,
  956. l.company_id,
  957. l.company_user_id,
  958. l.course_id,
  959. l.video_id,
  960. l.qw_user_id,
  961. l.qw_external_contact_id,
  962. l.sop_id,
  963. qec.create_time as qec_create_time,
  964. u.last_ip
  965. FROM
  966. fs_course_watch_log l LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  967. left join fs_user u on u.user_id = l.user_id
  968. left join company_user cu on cu.user_id = l.company_user_id
  969. <where>
  970. <if test ='maps.sendType !=null'>
  971. and l.send_type = #{maps.sendType}
  972. </if>
  973. <if test ='maps.userId !=null'>
  974. and l.user_id = #{maps.userId}
  975. </if>
  976. <if test ='maps.qwExternalContactId !=null'>
  977. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  978. </if>
  979. <if test ='maps.qwUserId !=null'>
  980. and l.qw_user_id = #{maps.qwUserId}
  981. </if>
  982. <if test ='maps.courseId !=null'>
  983. and l.course_id = #{maps.courseId}
  984. </if>
  985. <if test ='maps.videoId !=null'>
  986. and l.video_id = #{maps.videoId}
  987. </if>
  988. <if test ='maps.logType !=null'>
  989. and l.log_type = #{maps.logType}
  990. </if>
  991. <if test ='maps.periodId !=null'>
  992. and l.period_id = #{maps.periodId}
  993. </if>
  994. <if test ='maps.companyId !=null'>
  995. and l.company_id = #{maps.companyId}
  996. </if>
  997. <if test ='maps.companyUserId !=null'>
  998. and l.company_user_id = #{maps.companyUserId}
  999. </if>
  1000. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  1001. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  1002. </if>
  1003. <if test ='maps.nickName !=null and maps.nickName!=""'>
  1004. and u.nick_name like concat('%', #{maps.nickName}, '%')
  1005. </if>
  1006. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  1007. and qec.name like concat('%', #{maps.externalUserName}, '%')
  1008. </if>
  1009. <if test= 'maps.qecSTime != null '>
  1010. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  1011. </if>
  1012. <if test='maps.qecETime != null '>
  1013. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  1014. </if>
  1015. <if test= 'maps.sTime != null '>
  1016. and DATE(l.create_time) &gt;= DATE(#{maps.sTime})
  1017. </if>
  1018. <if test='maps.eTime != null '>
  1019. and DATE(l.create_time) &lt;= DATE(#{maps.eTime})
  1020. </if>
  1021. <if test= 'maps.scheduleStartTime != null '>
  1022. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  1023. </if>
  1024. <if test='maps.scheduleEndTime != null '>
  1025. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  1026. </if>
  1027. <if test= 'maps.upSTime != null '>
  1028. and DATE(l.update_time) &gt;= DATE(#{maps.upSTime})
  1029. </if>
  1030. <if test='maps.upETime != null '>
  1031. and DATE(l.update_time) &lt;= DATE(#{maps.upETime})
  1032. </if>
  1033. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  1034. and l.sop_id in
  1035. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  1036. #{sopId}
  1037. </foreach>
  1038. </if>
  1039. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  1040. and l.period_id in
  1041. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  1042. #{periodId}
  1043. </foreach>
  1044. </if>
  1045. </where>
  1046. order by l.finish_time desc,l.update_time desc,l.create_time desc
  1047. </select>
  1048. <select id="getWatchCourseByVideoId" resultType="com.fs.course.domain.FsCourseWatchLog">
  1049. SELECT
  1050. *
  1051. FROM
  1052. fs_course_watch_log
  1053. WHERE
  1054. send_type = 1
  1055. AND video_id = #{videoId}
  1056. AND user_id in
  1057. <foreach item="userId" index="index" collection="userIds" open="(" separator="," close=")">
  1058. #{userId}
  1059. </foreach>
  1060. ORDER BY
  1061. log_id DESC
  1062. </select>
  1063. <select id="getUserCountByCampId" resultType="java.lang.Integer">
  1064. select count(distinct cwl.user_id)
  1065. from fs_user_course_period ucp
  1066. inner join fs_course_watch_log cwl on ucp.period_id = cwl.period_id
  1067. where ucp.training_camp_id = #{trainingCampId}
  1068. </select>
  1069. <select id="selectFsCourseWatchLogStatisticsListByCompanyVO"
  1070. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListByCompanyVO">
  1071. SELECT
  1072. o.video_id,
  1073. o.company_id,
  1074. comp.company_name,
  1075. o.qw_user_id,
  1076. DATE(o.create_time) create_time,
  1077. v.title videoName,
  1078. uc.course_name,
  1079. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  1080. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  1081. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  1082. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4
  1083. FROM
  1084. fs_course_watch_log o
  1085. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1086. LEFT JOIN company comp ON comp.company_id = o.company_id
  1087. LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
  1088. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1089. <where>
  1090. <if test="sendType != null">
  1091. and send_type = #{sendType}
  1092. </if>
  1093. <if test="companyId != null">
  1094. and o.company_id = #{companyId}
  1095. </if>
  1096. <if test="sTime != null">
  1097. AND DATE (o.create_time) &gt;= DATE (#{sTime})
  1098. </if>
  1099. <if test="eTime != null">
  1100. AND DATE (o.create_time) &lt;= DATE (#{eTime})
  1101. </if>
  1102. <if test="courseId != null">
  1103. and o.course_id = #{courseId}
  1104. </if>
  1105. <if test="videoId != null">
  1106. and o.video_id = #{videoId}
  1107. </if>
  1108. </where>
  1109. GROUP BY
  1110. DATE (o.create_time),
  1111. o.company_id
  1112. ORDER BY
  1113. comp.company_id,
  1114. DATE (o.create_time)
  1115. </select>
  1116. <select id="selectQwFsCourseWatchLogStatisticsListVO"
  1117. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO" parameterType="com.fs.qw.param.QwSidebarStatsParam">
  1118. SELECT
  1119. o.project,
  1120. o.course_id AS courseId,
  1121. uc.course_name AS courseName,
  1122. o.video_id AS videoId,
  1123. v.title AS videoName,
  1124. CASE WHEN o.log_type = 1 THEN 1 END AS type1,
  1125. CASE WHEN o.log_type = 2 THEN 1 END AS type2,
  1126. CASE WHEN o.log_type = 3 THEN 1 END AS type3,
  1127. CASE WHEN o.log_type = 4 THEN 1 END AS type4,
  1128. o.qw_user_id,
  1129. o.user_id AS userId,
  1130. o.company_user_id AS companyUserId,
  1131. o.company_id AS companyId,
  1132. o.create_time AS createTime
  1133. FROM
  1134. fs_course_watch_log o
  1135. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1136. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1137. WHERE
  1138. o.qw_external_contact_id=#{data.qwExternalContactId}
  1139. <if test="data.sendType != null">
  1140. AND send_type = #{data.sendType}
  1141. </if>
  1142. <if test="data.startTime != null">
  1143. AND DATE(o.create_time) &gt;= DATE(#{data.startTime})
  1144. </if>
  1145. <if test="data.endTime != null">
  1146. AND DATE(o.create_time) &lt;= DATE(#{data.endTime})
  1147. </if>
  1148. order by o.create_time DESC
  1149. </select>
  1150. <!-- 统计当天各公司的观看人数和完播人数, 存到redis中,定时任务每 ? 分钟执行一次 -->
  1151. <select id="watchCourseStatisticsGroupByCompany" resultType="com.fs.statis.dto.WatchCourseStatisticsResultDTO">
  1152. SELECT
  1153. o.company_id AS companyId,
  1154. c.company_name AS companyName,
  1155. o.send_type,
  1156. COUNT(DISTINCT o.user_id) AS watchUserCount,
  1157. COUNT(o.log_id) AS watchCount,
  1158. sum(case when o.log_type = 2 then 1 else 0 end) AS finishCount,
  1159. COUNT(DISTINCT CASE WHEN o.log_type = 2 THEN o.user_id END) AS finishUserCount
  1160. FROM
  1161. fs_course_watch_log o
  1162. LEFT JOIN company c ON c.company_id = o.company_id
  1163. WHERE
  1164. o.create_time &gt;= #{params.startTime}
  1165. AND o.create_time &lt;= #{params.endTime}
  1166. GROUP BY
  1167. o.company_id,
  1168. o.send_type
  1169. </select>
  1170. <select id="selectFsCourseWatchLogStatisticsListVO_COUNT"
  1171. resultType="java.lang.Long">
  1172. SELECT COUNT(*) FROM (
  1173. SELECT
  1174. o.video_id,
  1175. <!-- 用choose保证sendType逻辑互斥,避免GROUP BY字段缺失 -->
  1176. <choose>
  1177. <when test="sendType != 1">
  1178. o.qw_user_id,
  1179. </when>
  1180. <when test="sendType == 1">
  1181. o.company_user_id,
  1182. </when>
  1183. <!-- sendType为null时兜底,避免空指针 -->
  1184. <otherwise>
  1185. o.qw_user_id,
  1186. </otherwise>
  1187. </choose>
  1188. DATE(o.create_time) create_time
  1189. FROM fs_course_watch_log o
  1190. <!-- 动态关联qw_user表 -->
  1191. <if test="sendType != 1">
  1192. LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
  1193. </if>
  1194. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1195. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1196. <!-- 动态关联company_user表 -->
  1197. <if test="sendType == 1">
  1198. LEFT JOIN company_user cu ON cu.user_id = o.company_user_id
  1199. </if>
  1200. WHERE 1=1
  1201. <if test = 'companyId != null and companyId != 0'>
  1202. and o.company_id=#{companyId}
  1203. </if>
  1204. <if test = 'userIds != null and userIds.size() > 0'>
  1205. and o.company_user_id in
  1206. <foreach collection='userIds' item='id' open='(' separator=',' close=')'>
  1207. #{id}
  1208. </foreach>
  1209. </if>
  1210. <!-- 发送类型筛选 -->
  1211. <if test="sendType != null">
  1212. AND send_type = #{sendType}
  1213. </if>
  1214. <!-- 开始时间筛选:区分String/Date类型,避免类型比较异常 -->
  1215. <if test="sTime != null">
  1216. <choose>
  1217. <!-- sTime是String类型(yyyy-MM-dd) -->
  1218. <when test="sTime instanceof java.lang.String and sTime.trim() != ''">
  1219. AND o.create_time &gt;= STR_TO_DATE(#{sTime}, '%Y-%m-%d')
  1220. </when>
  1221. <!-- sTime是Date类型 -->
  1222. <otherwise>
  1223. AND o.create_time &gt;= #{sTime}
  1224. </otherwise>
  1225. </choose>
  1226. </if>
  1227. <!-- 结束时间筛选:区分String/Date类型 -->
  1228. <if test="eTime != null">
  1229. <choose>
  1230. <when test="eTime instanceof java.lang.String and eTime.trim() != ''">
  1231. AND o.create_time &lt; DATE_ADD(STR_TO_DATE(#{eTime}, '%Y-%m-%d'), INTERVAL 1 DAY)
  1232. </when>
  1233. <otherwise>
  1234. AND o.create_time &lt; DATE_ADD(#{eTime}, INTERVAL 1 DAY)
  1235. </otherwise>
  1236. </choose>
  1237. </if>
  1238. <!-- 昵称筛选:sendType!=1时关联qw_user -->
  1239. <if test="sendType != 1 and nickName != null and nickName.trim() != ''">
  1240. AND qu.qw_user_name LIKE CONCAT(#{nickName}, '%')
  1241. </if>
  1242. <!-- 昵称筛选:sendType==1时关联company_user -->
  1243. <if test="sendType == 1 and nickName != null and nickName.trim() != ''">
  1244. AND cu.nick_name LIKE CONCAT(#{nickName}, '%')
  1245. </if>
  1246. <!-- 课程ID筛选:加>0判断,避免null值拼接 -->
  1247. <if test="courseId != null and courseId > 0">
  1248. AND o.course_id = #{courseId}
  1249. </if>
  1250. <!-- 视频ID筛选:加>0判断 -->
  1251. <if test="videoId != null and videoId > 0">
  1252. AND o.video_id = #{videoId}
  1253. </if>
  1254. <!-- 分组条件:与子查询字段一致 -->
  1255. GROUP BY
  1256. o.video_id,
  1257. <choose>
  1258. <when test="sendType != 1">
  1259. o.qw_user_id,
  1260. </when>
  1261. <when test="sendType == 1">
  1262. o.company_user_id,
  1263. </when>
  1264. <otherwise>
  1265. o.qw_user_id,
  1266. </otherwise>
  1267. </choose>
  1268. DATE(o.create_time)
  1269. ) AS t
  1270. </select>
  1271. <select id="selectCompanyBaseInfo" resultType="com.fs.course.vo.FsCourseReportVO">
  1272. SELECT
  1273. c.company_id AS companyId,
  1274. c.company_name AS companyName
  1275. FROM company c
  1276. <where>
  1277. c.is_del=0
  1278. <if test="companyId != null and companyId != ''">
  1279. AND c.company_id = #{companyId}
  1280. </if>
  1281. </where>
  1282. GROUP BY c.company_id, c.company_name
  1283. ORDER BY c.create_time DESC
  1284. </select>
  1285. <select id="selectWatchStatistics" resultType="com.fs.course.vo.FsCourseReportVO">
  1286. SELECT
  1287. <choose>
  1288. <when test="dimension == 'company'">
  1289. fwl.company_id AS companyId,
  1290. </when>
  1291. <when test="dimension == 'course'">
  1292. fwl.course_id As courseId,
  1293. </when>
  1294. <when test="dimension == 'video'">
  1295. fwl.video_id AS videoId,
  1296. </when>
  1297. </choose>
  1298. COUNT(DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS finishedCount,
  1299. COUNT(CASE WHEN fwl.log_type = 2 THEN fwl.log_id END) AS courseCompleteTimes,
  1300. COUNT(DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END) AS accessCount,
  1301. ifnull(
  1302. ROUND(
  1303. (
  1304. COUNT( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) / count( DISTINCT CASE WHEN fwl.log_type != 3
  1305. THEN fwl.user_id END )) * 100,
  1306. 2
  1307. ),
  1308. 0
  1309. ) AS finishRate
  1310. FROM
  1311. fs_course_watch_log fwl
  1312. <where>
  1313. fwl.send_type = 2
  1314. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1315. AND fwl.create_time &gt;= #{startDate} AND fwl.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1316. </if>
  1317. <choose>
  1318. <when test="dimension == 'company' and companyId != null and companyId > 0">
  1319. AND fwl.company_id = #{companyId}
  1320. </when>
  1321. <when test="dimension == 'video' and videoId != null and videoId > 0">
  1322. AND fwl.video_id = #{videoId}
  1323. </when>
  1324. <when test="dimension == 'course' and courseId != null and courseId != ''">
  1325. AND fwl.course_id = #{courseId}
  1326. </when>
  1327. </choose>
  1328. </where>
  1329. <choose>
  1330. <when test="dimension == 'course'">
  1331. GROUP BY fwl.course_id
  1332. </when>
  1333. <when test="dimension == 'video'">
  1334. GROUP BY fwl.video_id
  1335. </when>
  1336. <otherwise>
  1337. GROUP BY fwl.company_id
  1338. </otherwise>
  1339. </choose>
  1340. ORDER BY accessCount desc
  1341. </select>
  1342. <select id="getSopCourseH5StudyList" resultType="com.fs.course.vo.FsSopMyCourseH5LinkVO">
  1343. select c.img_url courseUrl,v.title courseName,c.title,l.log_id logId,u.qw_user_name qwUserName from fs_course_watch_log l
  1344. left join fs_user_course c on c.course_id = l.course_id
  1345. left join qw_user u on l.qw_user_id = u.id
  1346. left join fs_user_course_video v on l.video_id =v.video_id
  1347. where l.user_id = #{userId} AND l.create_time &gt;= CURDATE()
  1348. AND l.create_time &lt; CURDATE() + INTERVAL 1 DAY
  1349. order by l.create_time desc
  1350. </select>
  1351. <select id="selectFsUserWatchLogByExtId" resultType="com.fs.course.domain.FsCourseWatchLog">
  1352. select log_id logId from fs_course_watch_log where qw_external_contact_id = #{id}
  1353. and qw_user_id = #{qwUserId} and user_id is null
  1354. </select>
  1355. <select id="getSopCourseH5StudyListByQwExId" resultType="com.fs.course.vo.FsSopMyCourseH5LinkVO">
  1356. select c.img_url courseUrl,v.title courseName,c.title,l.log_id logId,u.qw_user_name qwUserName from fs_course_watch_log l
  1357. left join fs_user_course c on c.course_id = l.course_id
  1358. left join qw_user u on l.qw_user_id = u.id
  1359. left join fs_user_course_video v on l.video_id =v.video_id
  1360. where l.qw_external_contact_id = #{qwExternalId} AND l.create_time &gt;= CURDATE()
  1361. AND l.create_time &lt; CURDATE() + INTERVAL 1 DAY
  1362. order by l.create_time desc
  1363. </select>
  1364. <!-- 首次点播数据统计:看课时间在[营期开始时间, 营期开始时间+视频时长]范围内,view_start=COALESCE(finish_time-duration, update_time-duration, create_time) -->
  1365. <select id="selectFirstPlaybackStats" resultType="map">
  1366. SELECT
  1367. COUNT(DISTINCT l.user_id) AS firstWatchCount,
  1368. COUNT(DISTINCT CASE WHEN l.duration &gt;= 1200 THEN l.user_id END) AS firstWatch20MinCount,
  1369. COUNT(DISTINCT CASE WHEN l.duration &gt;= 1800 THEN l.user_id END) AS firstWatch30MinCount
  1370. FROM fs_course_watch_log l
  1371. INNER JOIN fs_user_course_period_days fcpd ON fcpd.period_id = l.period_id AND fcpd.video_id = l.video_id AND fcpd.del_flag = '0'
  1372. INNER JOIN fs_user_course_video v ON v.video_id = l.video_id AND v.is_del = 0
  1373. WHERE l.video_id = #{videoId}
  1374. AND l.period_id = #{periodId}
  1375. AND l.user_id IS NOT NULL
  1376. <if test="companyId != null">
  1377. AND l.company_id = #{companyId}
  1378. </if>
  1379. <if test="companyUserId != null">
  1380. AND l.company_user_id = #{companyUserId}
  1381. </if>
  1382. AND (
  1383. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration, 0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration, 0) SECOND), l.create_time) &gt;= fcpd.start_date_time)
  1384. AND
  1385. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration, 0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration, 0) SECOND), l.create_time) &lt; DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration, 0) SECOND))
  1386. )
  1387. </select>
  1388. <!-- 第2-n次观看数据统计:view_start不在[营期开始时间, 营期开始时间+视频时长]内 -->
  1389. <select id="selectRepeatPlaybackStats" resultType="map">
  1390. SELECT
  1391. COUNT(DISTINCT l.user_id) AS repeatWatchCount,
  1392. COUNT(DISTINCT CASE WHEN l.duration &gt;= 1200 THEN l.user_id END) AS repeatWatch20MinCount,
  1393. COUNT(DISTINCT CASE WHEN l.duration &gt;= 1800 THEN l.user_id END) AS repeatWatch30MinCount
  1394. FROM fs_course_watch_log l
  1395. INNER JOIN fs_user_course_period_days fcpd ON fcpd.period_id = l.period_id AND fcpd.video_id = l.video_id AND fcpd.del_flag = '0'
  1396. INNER JOIN fs_user_course_video v ON v.video_id = l.video_id AND v.is_del = 0
  1397. WHERE l.video_id = #{videoId}
  1398. AND l.period_id = #{periodId}
  1399. AND l.user_id IS NOT NULL
  1400. AND (
  1401. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration, 0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration, 0) SECOND), l.create_time) &lt; fcpd.start_date_time)
  1402. OR
  1403. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration, 0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration, 0) SECOND), l.create_time) &gt;= DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration, 0) SECOND))
  1404. )
  1405. </select>
  1406. <!-- 课程小结-用户详情列表:按user_id分组,区分首次/2-n次观看时长,关联订单,按创建时间倒序 -->
  1407. <select id="selectCourseStatisticsUserDetailList" resultType="com.fs.course.vo.CourseStatisticsUserDetailVO">
  1408. SELECT
  1409. ua.user_id AS userId,
  1410. COALESCE(u.nick_name, u.nickname, '未知用户') AS userName,
  1411. COALESCE(ua.first_dur, 0) AS watchDuration,
  1412. COALESCE(ua.repeat_dur, 0) AS repeatWatchDuration,
  1413. COALESCE(ord.order_count, 0) AS orderCount,
  1414. COALESCE(ord.order_amount, 0) AS orderAmount,
  1415. c.company_name AS companyName,
  1416. cu.nick_name AS salesName
  1417. <if test="param.includeCourseRating != null and param.includeCourseRating">
  1418. , ans.course_rating AS courseRating
  1419. </if>
  1420. FROM (
  1421. SELECT
  1422. l.user_id,
  1423. MAX(l.create_time) AS max_create_time,
  1424. SUM(CASE WHEN
  1425. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &gt;= fcpd.start_date_time)
  1426. AND (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &lt; DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration,0) SECOND))
  1427. THEN COALESCE(l.duration,0) ELSE 0 END) AS first_dur,
  1428. SUM(CASE WHEN
  1429. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &lt; fcpd.start_date_time)
  1430. OR (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &gt;= DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration,0) SECOND))
  1431. THEN COALESCE(l.duration,0) ELSE 0 END) AS repeat_dur,
  1432. MAX(l.company_id) AS company_id,
  1433. MAX(l.company_user_id) AS company_user_id
  1434. FROM fs_course_watch_log l
  1435. INNER JOIN fs_user_course_period_days fcpd ON fcpd.period_id = l.period_id AND fcpd.video_id = l.video_id AND fcpd.del_flag = '0'
  1436. INNER JOIN fs_user_course_video v ON v.video_id = l.video_id AND v.is_del = 0
  1437. WHERE l.video_id = #{param.videoId} AND l.period_id = #{param.periodId} AND l.user_id IS NOT NULL
  1438. <if test="param.companyId != null">
  1439. AND l.company_id = #{param.companyId}
  1440. </if>
  1441. <if test="param.companyUserId != null">
  1442. AND l.company_user_id = #{param.companyUserId}
  1443. </if>
  1444. GROUP BY l.user_id
  1445. ) ua
  1446. LEFT JOIN fs_user u ON u.user_id = ua.user_id
  1447. LEFT JOIN (
  1448. SELECT
  1449. o.user_id,
  1450. COUNT(o.id) AS order_count,
  1451. SUM(IFNULL(o.pay_price, 0)) AS order_amount,
  1452. MIN(o.id) AS min_order_id
  1453. FROM fs_store_order_scrm o
  1454. WHERE o.order_type = 3 AND o.video_id = #{param.videoId} AND o.period_id = #{param.periodId} AND o.paid = 1
  1455. <if test="param.companyId != null">
  1456. AND o.company_id = #{param.companyId}
  1457. </if>
  1458. GROUP BY o.user_id
  1459. ) ord ON ord.user_id = ua.user_id
  1460. LEFT JOIN company c ON c.company_id = ua.company_id
  1461. LEFT JOIN company_user cu ON cu.user_id = ua.company_user_id
  1462. <if test="param.includeCourseRating != null and param.includeCourseRating">
  1463. LEFT JOIN (
  1464. SELECT a.user_id, a.question_json AS course_rating
  1465. FROM fs_course_answer_logs a
  1466. INNER JOIN (
  1467. SELECT user_id, MAX(log_id) AS max_log_id
  1468. FROM fs_course_answer_logs
  1469. WHERE video_id = #{param.videoId} AND period_id = #{param.periodId}
  1470. GROUP BY user_id
  1471. ) latest ON latest.user_id = a.user_id AND latest.max_log_id = a.log_id
  1472. ) ans ON ans.user_id = ua.user_id
  1473. </if>
  1474. ORDER BY ua.max_create_time DESC
  1475. </select>
  1476. <!-- 课程小结-用户详情导出:按创建时间倒序,最多50000条 -->
  1477. <select id="selectCourseStatisticsUserDetailExportList" resultType="com.fs.course.vo.CourseStatisticsUserDetailVO">
  1478. SELECT
  1479. ua.user_id AS userId,
  1480. COALESCE(u.nick_name, u.nickname, '未知用户') AS userName,
  1481. COALESCE(ua.first_dur, 0) AS watchDuration,
  1482. COALESCE(ua.repeat_dur, 0) AS repeatWatchDuration,
  1483. COALESCE(ord.order_count, 0) AS orderCount,
  1484. COALESCE(ord.order_amount, 0) AS orderAmount,
  1485. c.company_name AS companyName,
  1486. cu.nick_name AS salesName
  1487. <if test="param.includeCourseRating != null and param.includeCourseRating">
  1488. , ans.course_rating AS courseRating
  1489. </if>
  1490. FROM (
  1491. SELECT
  1492. l.user_id,
  1493. MAX(l.create_time) AS max_create_time,
  1494. SUM(CASE WHEN
  1495. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &gt;= fcpd.start_date_time)
  1496. AND (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &lt; DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration,0) SECOND))
  1497. THEN COALESCE(l.duration,0) ELSE 0 END) AS first_dur,
  1498. SUM(CASE WHEN
  1499. (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &lt; fcpd.start_date_time)
  1500. OR (COALESCE(DATE_SUB(l.finish_time, INTERVAL COALESCE(l.duration,0) SECOND), DATE_SUB(l.update_time, INTERVAL COALESCE(l.duration,0) SECOND), l.create_time) &gt;= DATE_ADD(fcpd.start_date_time, INTERVAL COALESCE(v.duration,0) SECOND))
  1501. THEN COALESCE(l.duration,0) ELSE 0 END) AS repeat_dur,
  1502. MAX(l.company_id) AS company_id,
  1503. MAX(l.company_user_id) AS company_user_id
  1504. FROM fs_course_watch_log l
  1505. INNER JOIN fs_user_course_period_days fcpd ON fcpd.period_id = l.period_id AND fcpd.video_id = l.video_id AND fcpd.del_flag = '0'
  1506. INNER JOIN fs_user_course_video v ON v.video_id = l.video_id AND v.is_del = 0
  1507. WHERE l.video_id = #{param.videoId} AND l.period_id = #{param.periodId} AND l.user_id IS NOT NULL
  1508. <if test="param.companyId != null">
  1509. AND l.company_id = #{param.companyId}
  1510. </if>
  1511. <if test="param.companyUserId != null">
  1512. AND l.company_user_id = #{param.companyUserId}
  1513. </if>
  1514. GROUP BY l.user_id
  1515. ) ua
  1516. LEFT JOIN fs_user u ON u.user_id = ua.user_id
  1517. LEFT JOIN (
  1518. SELECT
  1519. o.user_id,
  1520. COUNT(o.id) AS order_count,
  1521. SUM(IFNULL(o.pay_price, 0)) AS order_amount,
  1522. MIN(o.id) AS min_order_id
  1523. FROM fs_store_order_scrm o
  1524. WHERE o.order_type = 3 AND o.video_id = #{param.videoId} AND o.period_id = #{param.periodId} AND o.paid = 1
  1525. <if test="param.companyId != null">
  1526. AND o.company_id = #{param.companyId}
  1527. </if>
  1528. GROUP BY o.user_id
  1529. ) ord ON ord.user_id = ua.user_id
  1530. LEFT JOIN company c ON c.company_id = ua.company_id
  1531. LEFT JOIN company_user cu ON cu.user_id = ua.company_user_id
  1532. <if test="param.includeCourseRating != null and param.includeCourseRating">
  1533. LEFT JOIN (
  1534. SELECT a.user_id, a.question_json AS course_rating
  1535. FROM fs_course_answer_logs a
  1536. INNER JOIN (
  1537. SELECT user_id, MAX(log_id) AS max_log_id
  1538. FROM fs_course_answer_logs
  1539. WHERE video_id = #{param.videoId} AND period_id = #{param.periodId}
  1540. GROUP BY user_id
  1541. ) latest ON latest.user_id = a.user_id AND latest.max_log_id = a.log_id
  1542. ) ans ON ans.user_id = ua.user_id
  1543. </if>
  1544. ORDER BY ua.max_create_time DESC
  1545. LIMIT 50000
  1546. </select>
  1547. <!--
  1548. 实际看课数据(按看课记录口径,与 countDistinctWatchUsers / countDistinctCompleteUsers 一致):
  1549. 仅统计 duration > 0 的记录参与时长汇总;到课/时长均以正时长行为准。
  1550. i.1 实际到课人数 = 去重 user_id,且存在至少一条本视频本营期 duration>0 的看课记录(进入点播产生有效观看)
  1551. i.2 实际完课人数 = 去重 user_id,且存在至少一条 log_type=2 且 duration>0 的看课记录(完课记录)
  1552. ii.3 实际完课率 = i.2 / i.1(百分比)
  1553. iv.4 人均看课时长(分钟) = 到课用户各自的「仅 duration>0 记录时长之和」汇总结秒 / 到课人数
  1554. v.5 人均完课时长(分钟) = 完课用户各自的同上累计秒数之和 / 完课人数
  1555. vi.6 人均完课完播率(%) = (v.5 对应的人均秒数) / 素材时长(秒) * 100,即 (完课用户总秒数/完课人数) / video.duration * 100
  1556. -->
  1557. <select id="selectActualCompletionList" resultType="com.fs.course.vo.FSActualCompletionVO">
  1558. SELECT
  1559. COALESCE(agg.total_students, 0) AS totalStudents,
  1560. COALESCE(agg.completed_count, 0) AS completedCount,
  1561. CASE
  1562. WHEN COALESCE(agg.total_students, 0) > 0 THEN
  1563. ROUND((agg.completed_count * 100.0 / agg.total_students), 2)
  1564. ELSE 0
  1565. END AS actualCompletionRate,
  1566. CASE
  1567. WHEN COALESCE(agg.total_students, 0) > 0 THEN
  1568. ROUND((agg.total_viewing_seconds / agg.total_students) , 2)
  1569. ELSE 0
  1570. END AS avgWatchDurationMinutes,
  1571. CASE
  1572. WHEN COALESCE(agg.completed_count, 0) > 0 THEN
  1573. ROUND((agg.total_duration_completers_seconds / agg.completed_count) , 2)
  1574. ELSE 0
  1575. END AS avgCompletedDuration,
  1576. CASE
  1577. WHEN COALESCE(agg.completed_count, 0) > 0
  1578. AND COALESCE(vid.video_duration_sec, 0) > 0 THEN
  1579. ROUND(((agg.total_duration_completers_seconds / agg.completed_count) / vid.video_duration_sec) * 100, 2)
  1580. ELSE 0
  1581. END AS avgCompletionPlaybackRate
  1582. FROM (
  1583. SELECT
  1584. COUNT(*) AS total_students,
  1585. COALESCE(SUM(CASE WHEN u.has_complete_log = 1 THEN 1 ELSE 0 END), 0) AS completed_count,
  1586. COALESCE(SUM(u.sum_pos_duration_sec), 0) AS total_viewing_seconds,
  1587. COALESCE(SUM(CASE WHEN u.has_complete_log = 1 THEN u.sum_pos_duration_sec ELSE 0 END), 0) AS total_duration_completers_seconds
  1588. FROM (
  1589. SELECT
  1590. wl.user_id,
  1591. SUM(CASE WHEN COALESCE(wl.duration, 0) > 0 THEN COALESCE(wl.duration, 0) ELSE 0 END) AS sum_pos_duration_sec,
  1592. MAX(CASE WHEN wl.log_type = 2 AND COALESCE(wl.duration, 0) > 0 THEN 1 ELSE 0 END) AS has_complete_log
  1593. FROM fs_course_watch_log wl
  1594. WHERE wl.video_id = #{videoId}
  1595. AND wl.period_id = #{periodId}
  1596. AND wl.user_id IS NOT NULL
  1597. <if test="companyId != null">
  1598. AND wl.company_id = #{companyId}
  1599. </if>
  1600. <if test="companyUserId != null">
  1601. AND wl.company_user_id = #{companyUserId}
  1602. </if>
  1603. GROUP BY wl.user_id
  1604. HAVING SUM(CASE WHEN COALESCE(wl.duration, 0) > 0 THEN COALESCE(wl.duration, 0) ELSE 0 END) > 0
  1605. ) u
  1606. ) agg
  1607. CROSS JOIN (
  1608. SELECT COALESCE(MAX(v.duration), 0) AS video_duration_sec
  1609. FROM fs_user_course_video v
  1610. WHERE v.video_id = #{videoId} AND v.is_del = 0
  1611. ) vid
  1612. </select>
  1613. <!-- 记录类型 1看课中 2完课 3待看课 4看课中断 -->
  1614. <select id="selectAppSalesCourseStatisticsVO" resultType="com.fs.his.vo.AppSalesCourseStatisticsVO">
  1615. SELECT l.company_user_id,l.course_id,l.video_id,
  1616. cu.nick_name as salesName,fuc.course_name as courseName,fuv.title as videoTitle,
  1617. SUM(CASE WHEN l.log_type = 2 THEN 1 ELSE 0 END) AS finishedCount,
  1618. SUM(CASE WHEN l.log_type = 3 THEN 1 ELSE 0 END) AS notWatchedCount,
  1619. SUM(CASE WHEN l.log_type = 4 THEN 1 ELSE 0 END) AS interruptCount,
  1620. SUM(CASE WHEN l.log_type = 1 THEN 1 ELSE 0 END) AS watchingCount
  1621. from fs_course_watch_log l
  1622. left join company_user cu on l.company_user_id=cu.user_id
  1623. left join fs_user_course fuc on l.course_id=fuc.course_id
  1624. left join fs_user_course_video fuv on l.video_id=fuv.video_id
  1625. where send_type = 1 and watch_type =1
  1626. <if test="companyId != null ">
  1627. and l.company_id = #{companyId}
  1628. </if>
  1629. <if test="companyUserId != null ">
  1630. and l.company_user_id = #{companyUserId}
  1631. </if>
  1632. <if test="courseId != null ">
  1633. and l.course_id = #{courseId}
  1634. </if>
  1635. <if test="videoId != null ">
  1636. and l.video_id = #{videoId}
  1637. </if>
  1638. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1639. and l.create_time &gt;= #{startDate} and l.create_time &lt;= #{endDate}
  1640. </if>
  1641. group by l.company_user_id,l.course_id,l.video_id
  1642. </select>
  1643. <select id="selectAppUserBaseData" resultType="com.fs.his.vo.AppWatchLogReportVO">
  1644. SELECT
  1645. log.user_id userId,
  1646. u.nick_name AS nickName,
  1647. u.source loginChannel,
  1648. cu.nick_name AS salesName,
  1649. c.company_name AS salesCompany,
  1650. cd.dept_name AS salesDept,
  1651. log.period_id periodId,
  1652. log.video_id videoId,
  1653. log.log_id logId,
  1654. log.create_time courseTime,
  1655. log.finish_time finishTime,
  1656. log.duration privateWatchDuration,
  1657. log.log_type privateWatchStatus,
  1658. cv.title AS videoTitle
  1659. FROM
  1660. fs_course_watch_log log
  1661. LEFT JOIN fs_user u ON u.user_id = log.user_id
  1662. LEFT JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
  1663. LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
  1664. LEFT JOIN company c ON log.company_id = c.company_id
  1665. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  1666. LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
  1667. WHERE log.send_type = 1
  1668. AND log.watch_type = 1
  1669. <include refid="commonConditions"/>
  1670. group by log.user_id
  1671. ORDER BY u.register_date DESC
  1672. </select>
  1673. <select id="selectCampPeriodByPeriod" resultType="com.fs.his.vo.WatchLogReportVO">
  1674. SELECT
  1675. cp.period_id periodId,
  1676. cp.period_name periodName,
  1677. camp.training_camp_name
  1678. FROM
  1679. fs_user_course_period cp
  1680. LEFT JOIN fs_user_course_training_camp camp ON camp.training_camp_id = cp.training_camp_id
  1681. WHERE cp.period_id in
  1682. <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
  1683. #{periodId}
  1684. </foreach>
  1685. </select>
  1686. <select id="selectRedPacketStats" resultType="com.fs.his.vo.WatchLogReportVO">
  1687. SELECT
  1688. rp.watch_log_id as logId,
  1689. SUM(rp.amount) AS redPacketAmount
  1690. FROM fs_course_red_packet_log rp
  1691. WHERE rp.watch_log_id IN
  1692. <foreach collection="logIds" item="logId" open="(" separator="," close=")">
  1693. #{logId}
  1694. </foreach>
  1695. GROUP BY rp.watch_log_id
  1696. </select>
  1697. <select id="selectAnswerStats" resultType="com.fs.his.vo.WatchLogReportVO">
  1698. SELECT
  1699. l.watch_log_id AS logId,
  1700. CASE WHEN l.log_id IS NOT NULL THEN '已答题' ELSE '未答题' END AS answerStatus,
  1701. (
  1702. SELECT COUNT(1)
  1703. FROM fs_course_watch_log wl
  1704. WHERE wl.log_id IN
  1705. <foreach collection="logIds" item="logId" open="(" separator="," close=")">
  1706. #{logId}
  1707. </foreach>
  1708. AND wl.log_id NOT IN (
  1709. SELECT watch_log_id
  1710. FROM fs_course_answer_logs
  1711. WHERE watch_log_id IS NOT NULL
  1712. )) AS notAnsweredCount
  1713. FROM fs_course_answer_logs l
  1714. WHERE l.watch_log_id IN
  1715. <foreach collection="logIds" item="logId" open="(" separator="," close=")">
  1716. #{logId}
  1717. </foreach>
  1718. GROUP BY l.watch_log_id
  1719. </select>
  1720. <select id="selectCourseByUserIdForStatusFinish" resultType="com.fs.course.vo.FsUserCourseAppListVO">
  1721. select c.course_name courseName,c.img_url imgUrl,r.title videoName,l.link_id linkId,l.duration,l.video_id videoId,l.user_id userId,l.company_user_id companyUserId,l.log_id logId from fs_course_watch_log l
  1722. left join fs_user_course c on l.course_id =c.course_id
  1723. left join fs_user_course_video r on r.video_id=l.video_id
  1724. WHERE l.user_id = #{userId} and l.log_type = 2
  1725. and l.create_time &gt;= CONCAT(CURDATE(), ' 00:00:00')
  1726. and l.create_time &lt;= CONCAT(CURDATE(), ' 23:59:59')
  1727. </select>
  1728. <select id="selectCourseByUserIdForStatusNotFinish" resultType="com.fs.course.vo.FsUserCourseAppListVO">
  1729. select c.course_name courseName,c.img_url imgUrl,r.title videoName,l.link_id linkId,l.duration,l.video_id videoId,l.user_id userId,l.company_user_id companyUserId,l.log_id logId from fs_course_watch_log l
  1730. left join fs_user_course c on l.course_id =c.course_id
  1731. left join fs_user_course_video r on r.video_id=l.video_id
  1732. WHERE l.user_id = #{userId} and l.log_type != 2
  1733. and l.create_time &gt;= CONCAT(CURDATE(), ' 00:00:00')
  1734. and l.create_time &lt;= CONCAT(CURDATE(), ' 23:59:59')
  1735. </select>
  1736. <select id="getAppCourseLearningOne" resultType="com.fs.course.vo.FsUserCourseAppListVO">
  1737. select c.course_name courseName,c.img_url imgUrl,r.title videoName,l.link_id linkId,l.duration,l.video_id videoId,l.user_id userId,l.company_user_id companyUserId,l.log_id logId
  1738. from fs_course_watch_log l
  1739. left join fs_user_course c on l.course_id =c.course_id
  1740. left join fs_user_course_video r on r.video_id=l.video_id
  1741. WHERE l.user_id = #{userId} and l.update_time is not null
  1742. order by l.update_time DESC LIMIT 1
  1743. </select>
  1744. <!-- 销售维度营期信息 -->
  1745. <select id="selectAppSalesCampPeriod" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  1746. SELECT
  1747. cp.period_id periodId,
  1748. cp.period_name periodName,
  1749. camp.training_camp_name trainingCampName
  1750. FROM
  1751. fs_user_course_period cp
  1752. LEFT JOIN fs_user_course_training_camp camp ON camp.training_camp_id = cp.training_camp_id
  1753. WHERE cp.period_id in
  1754. <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
  1755. #{periodId}
  1756. </foreach>
  1757. </select>
  1758. <!-- 销售部门维度APP会员数统计 -->
  1759. <select id="selectAppDeptUserStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  1760. SELECT
  1761. cd.dept_id AS deptId,
  1762. COUNT(DISTINCT CASE WHEN u.source IS NOT NULL THEN u.user_id END) AS appUserCount,
  1763. <choose>
  1764. <when test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1765. COUNT(DISTINCT CASE WHEN u.source IS NOT NULL AND u.register_date &gt;= #{startDate} AND u.register_date &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY) THEN u.user_id END)
  1766. </when>
  1767. <otherwise>
  1768. COUNT(DISTINCT CASE WHEN u.source IS NOT NULL THEN u.user_id END)
  1769. </otherwise>
  1770. </choose> AS newAppUserCount,
  1771. COUNT(DISTINCT cu.user_id) AS salesCount
  1772. FROM fs_user u
  1773. LEFT JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
  1774. LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
  1775. LEFT JOIN company c ON cuu.company_id = c.company_id
  1776. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  1777. WHERE u.source IS NOT NULL
  1778. <if test="companyId != null and companyId != ''">
  1779. AND cuu.company_id = #{companyId}
  1780. </if>
  1781. <if test="deptId != null and deptId != ''">
  1782. AND cu.dept_id = #{deptId}
  1783. </if>
  1784. <if test="salesId != null and salesId != ''">
  1785. AND cu.user_id = #{salesId}
  1786. </if>
  1787. <if test="project != null and project != ''">
  1788. AND cuu.project_id = #{project}
  1789. </if>
  1790. GROUP BY cd.dept_id
  1791. </select>
  1792. <!-- 销售部门维度基础数据+看课统计(合并查询) -->
  1793. <select id="selectAppDeptWatchStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  1794. SELECT
  1795. cd.dept_id AS deptId,
  1796. cd.dept_name AS salesDept,
  1797. c.company_name AS salesCompany,
  1798. log.period_id AS periodId,
  1799. log.video_id AS videoId,
  1800. cv.title AS videoTitle,
  1801. c.company_id AS companyId,
  1802. COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
  1803. COUNT(DISTINCT CASE WHEN log.log_type = '1' THEN log.log_id END) AS unfinishedCount,
  1804. COUNT(DISTINCT CASE WHEN log.log_type = '3' THEN log.log_id END) AS notWatchedCount,
  1805. COUNT(DISTINCT CASE WHEN a.log_id IS NULL THEN log.log_id END) AS notAnsweredCount,
  1806. COALESCE(SUM(rpl.amount), 0) AS redPacketAmount
  1807. FROM fs_course_watch_log log
  1808. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1809. LEFT JOIN company c ON log.company_id = c.company_id
  1810. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  1811. LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
  1812. LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
  1813. LEFT JOIN fs_course_red_packet_log rpl ON rpl.watch_log_id = log.log_id
  1814. WHERE log.send_type = 1
  1815. AND log.watch_type = 1
  1816. <include refid="commonConditions"/>
  1817. GROUP BY cd.dept_id, log.period_id, log.video_id
  1818. ORDER BY cd.dept_id
  1819. </select>
  1820. <!-- 销售部门维度订单统计 -->
  1821. <select id="selectAppDeptOrderStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  1822. SELECT
  1823. cd.dept_id AS deptId,
  1824. log.period_id AS periodId,
  1825. log.video_id AS videoId,
  1826. COUNT(DISTINCT CASE WHEN po.status = 3 THEN po.order_id END) AS historyOrderCount
  1827. FROM fs_course_watch_log log
  1828. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1829. LEFT JOIN company c ON log.company_id = c.company_id
  1830. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  1831. LEFT JOIN fs_package_order po ON po.user_id = log.user_id
  1832. WHERE log.send_type = 1
  1833. AND log.watch_type = 1
  1834. <include refid="commonConditions"/>
  1835. GROUP BY cd.dept_id, log.period_id, log.video_id
  1836. </select>
  1837. <!-- 销售维度APP会员数统计(直接查fs_user表) -->
  1838. <select id="selectAppSalesUserStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  1839. SELECT
  1840. cu.user_id AS salesId,
  1841. COUNT(DISTINCT CASE WHEN u.source IS NOT NULL THEN u.user_id END) AS appUserCount,
  1842. <choose>
  1843. <when test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1844. COUNT(DISTINCT CASE WHEN u.source IS NOT NULL AND u.register_date &gt;= #{startDate} AND u.register_date &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY) THEN u.user_id END)
  1845. </when>
  1846. <otherwise>
  1847. COUNT(DISTINCT CASE WHEN u.source IS NOT NULL THEN u.user_id END)
  1848. </otherwise>
  1849. </choose> AS newAppUserCount
  1850. FROM fs_user u
  1851. LEFT JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
  1852. LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
  1853. LEFT JOIN company c ON cuu.company_id = c.company_id
  1854. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  1855. WHERE u.source IS NOT NULL
  1856. <if test="companyId != null and companyId != ''">
  1857. AND cuu.company_id = #{companyId}
  1858. </if>
  1859. <if test="deptId != null and deptId != ''">
  1860. AND cu.dept_id = #{deptId}
  1861. </if>
  1862. <if test="salesId != null and salesId != ''">
  1863. AND cu.user_id = #{salesId}
  1864. </if>
  1865. <if test="project != null and project != ''">
  1866. AND cuu.project_id = #{project}
  1867. </if>
  1868. GROUP BY cu.user_id
  1869. </select>
  1870. <!-- 销售维度基础数据+看课统计(合并查询) -->
  1871. <select id="selectAppSalesWatchStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  1872. SELECT
  1873. cu.user_id AS salesId,
  1874. cu.nick_name AS salesName,
  1875. cd.dept_name AS salesDept,
  1876. c.company_name AS salesCompany,
  1877. log.period_id AS periodId,
  1878. log.video_id AS videoId,
  1879. cv.title AS videoTitle,
  1880. cd.dept_id AS deptId,
  1881. c.company_id AS companyId,
  1882. COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
  1883. COUNT(DISTINCT CASE WHEN log.log_type = '1' THEN log.log_id END) AS unfinishedCount,
  1884. COUNT(DISTINCT CASE WHEN log.log_type = '3' THEN log.log_id END) AS notWatchedCount,
  1885. COUNT(DISTINCT CASE WHEN a.log_id IS NULL THEN log.log_id END) AS notAnsweredCount,
  1886. COALESCE(SUM(rpl.amount), 0) AS redPacketAmount
  1887. FROM fs_course_watch_log log
  1888. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1889. LEFT JOIN company c ON log.company_id = c.company_id
  1890. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  1891. LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
  1892. LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
  1893. LEFT JOIN fs_course_red_packet_log rpl ON rpl.watch_log_id = log.log_id
  1894. WHERE log.send_type = 1
  1895. AND log.watch_type = 1
  1896. <include refid="commonConditions"/>
  1897. GROUP BY cu.user_id, log.period_id, log.video_id
  1898. ORDER BY cu.user_id
  1899. </select>
  1900. <select id="selectAppSalesOrderStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO"></select>
  1901. <sql id="commonConditions">
  1902. <!-- 销售公司 -->
  1903. <if test="companyId != null and companyId != ''">
  1904. AND c.company_id = #{companyId}
  1905. </if>
  1906. <!-- 销售部门 -->
  1907. <if test="deptId != null and deptId != ''">
  1908. AND cd.dept_id = #{deptId}
  1909. </if>
  1910. <!-- 所属销售 -->
  1911. <if test="salesId != null and salesId != ''">
  1912. AND cu.user_id = #{salesId}
  1913. </if>
  1914. <!-- 项目 -->
  1915. <if test="project != null and project != ''">
  1916. AND log.project = #{project}
  1917. </if>
  1918. <!-- 时间范围 -->
  1919. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1920. AND log.create_time &gt;= #{startDate} AND log.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1921. </if>
  1922. <!-- 训练营 -->
  1923. <if test="trainingCampId != null and trainingCampId != ''">
  1924. AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  1925. </if>
  1926. <!-- 营期 -->
  1927. <if test="periodId != null and periodId != ''">
  1928. AND log.period_id = #{periodId}
  1929. </if>
  1930. <!-- 会员ID -->
  1931. <if test="userId != null and userId != ''">
  1932. AND u.user_id = #{userId}
  1933. </if>
  1934. <!-- 会员手机号 -->
  1935. <if test="userPhone != null and userPhone != ''">
  1936. AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
  1937. </if>
  1938. <!-- 会员昵称 -->
  1939. <if test="nickName != null and nickName != ''">
  1940. AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
  1941. </if>
  1942. </sql>
  1943. </mapper>