FsCourseWatchLogMapper.xml 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495
  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, update_time, qw_external_contact_id, duration, qw_user_id, company_user_id, company_id, course_id,camp_period_time,project,period_id,watch_type from fs_course_watch_log
  32. </sql>
  33. <select id="selectFsCourseWatchLogList" parameterType="FsCourseWatchLog" resultMap="FsCourseWatchLogResult">
  34. <include refid="selectFsCourseWatchLogVo"/>
  35. <where>
  36. <if test="userId != null "> and user_id = #{userId}</if>
  37. <if test="videoId != null "> and video_id = #{videoId}</if>
  38. <if test="logType != null "> and log_type = #{logType}</if>
  39. <if test="qwExternalContactId != null "> and qw_external_contact_id = #{qwExternalContactId}</if>
  40. <if test="duration != null "> and duration = #{duration}</if>
  41. <if test="qwUserId != null and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
  42. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  43. <if test="companyId != null "> and company_id = #{companyId}</if>
  44. <if test="courseId != null "> and course_id = #{courseId}</if>
  45. <if test="sendType != null "> and send_type = #{sendType}</if>
  46. <if test="campPeriodTime != null "> and camp_period_time = #{campPeriodTime}</if>
  47. <if test="project != null "> and project = #{project}</if>
  48. <if test="watchType != null "> and watch_type = #{watchType}</if>
  49. </where>
  50. </select>
  51. <select id="selectFsCourseWatchLogByLogId" parameterType="Long" resultMap="FsCourseWatchLogResult">
  52. <include refid="selectFsCourseWatchLogVo"/>
  53. where log_id = #{logId}
  54. </select>
  55. <select id="selectFsCourseWatchLogListVO" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  56. 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,
  57. l.log_type,SEC_TO_TIME(l.duration) as duration,c.company_name,l.camp_period_time,l.finish_time,
  58. cu.nick_name as company_user_name ,l.send_type,l.create_time,l.update_time,l.last_heartbeat_time,
  59. 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,
  60. u.is_vip isVip,l.reward_type
  61. from fs_course_watch_log l
  62. left join fs_user_course_video v on v.video_id = l.video_id
  63. left join fs_user_course uc on uc.course_id = l.course_id
  64. left join fs_user u on u.user_id = l.user_id
  65. left join company_user cu on cu.user_id = l.company_user_id
  66. left join company c on c.company_id = l.company_id
  67. LEFT JOIN qw_user qu on qu.id= l.qw_user_id
  68. LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  69. <where>
  70. <if test ='maps.isVip != null and maps.isVip == 0'>
  71. and (l.user_id = 0 or l.user_id is null)
  72. </if>
  73. <if test ='maps.isVip != null and maps.isVip == 1'>
  74. and l.user_id != 0 and l.user_id is not null
  75. </if>
  76. <if test ='maps.sendType !=null'>
  77. and l.send_type = #{maps.sendType}
  78. </if>
  79. <if test ='maps.userId !=null'>
  80. and l.user_id = #{maps.userId}
  81. </if>
  82. <if test ='maps.project !=null'>
  83. and l.project = #{maps.project}
  84. </if>
  85. <if test ='maps.qwExternalContactId !=null'>
  86. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  87. </if>
  88. <if test ='maps.qwUserId !=null'>
  89. and l.qw_user_id = #{maps.qwUserId}
  90. </if>
  91. <if test ='maps.courseId !=null'>
  92. and l.course_id = #{maps.courseId}
  93. </if>
  94. <if test ='maps.watchType !=null'>
  95. and l.watch_type = #{maps.watchType}
  96. </if>
  97. <if test ='maps.videoId !=null'>
  98. and l.video_id = #{maps.videoId}
  99. </if>
  100. <if test ='maps.logType !=null'>
  101. and l.log_type = #{maps.logType}
  102. </if>
  103. <if test ='maps.companyId !=null'>
  104. and l.company_id = #{maps.companyId}
  105. </if>
  106. <if test ='maps.companyUserId !=null'>
  107. and l.company_user_id = #{maps.companyUserId}
  108. </if>
  109. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  110. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  111. </if>
  112. <if test ='maps.nickName !=null and maps.nickName!=""'>
  113. and u.nick_name like concat('%', #{maps.nickName}, '%')
  114. </if>
  115. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  116. and qec.name like concat('%', #{maps.externalUserName}, '%')
  117. </if>
  118. <if test= 'maps.qecSTime != null '>
  119. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  120. </if>
  121. <if test='maps.qecETime != null '>
  122. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  123. </if>
  124. <if test= 'maps.sTime != null '>
  125. and l.create_time &gt;= #{maps.sTime}
  126. </if>
  127. <if test='maps.eTime != null '>
  128. and l.create_time &lt;= DATE_ADD(#{maps.eTime}, INTERVAL 1 DAY)
  129. </if>
  130. <if test= 'maps.scheduleStartTime != null '>
  131. and l.camp_period_time &gt;= #{maps.scheduleStartTime}
  132. </if>
  133. <if test='maps.scheduleEndTime != null '>
  134. and l.camp_period_time &lt;= #{maps.scheduleEndTime}
  135. </if>
  136. <if test= 'maps.upSTime != null '>
  137. and l.update_time &gt;= #{maps.upSTime}
  138. </if>
  139. <if test='maps.upETime != null '>
  140. and l.update_time &lt;= #{maps.upETime}
  141. </if>
  142. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  143. and l.sop_id in
  144. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  145. #{sopId}
  146. </foreach>
  147. </if>
  148. <if test ='maps.project !=null'>
  149. and l.project = #{maps.project}
  150. </if>
  151. <if test="maps.sopId != null and maps.sopId != '' ">
  152. and l.sop_id = #{maps.sopId}
  153. </if>
  154. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  155. and l.period_id in
  156. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  157. #{periodId}
  158. </foreach>
  159. </if>
  160. <if test="maps.qwUserName != null and maps.qwUserName != '' ">
  161. and qu.qw_user_name = #{maps.qwUserName}
  162. </if>
  163. <if test='maps.cuDeptIdList != null and !maps.cuDeptIdList.isEmpty() and maps.userType != "00" '>
  164. AND cu.dept_id IN
  165. <foreach collection='maps.cuDeptIdList' item='item' open='(' separator=',' close=')'>
  166. #{item}
  167. </foreach>
  168. </if>
  169. </where>
  170. order by l.finish_time desc,l.update_time desc,l.create_time desc
  171. </select>
  172. <select id="selectFsCourseWatchLogListByParam" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  173. select l.log_id,l.user_id,uc.course_name,v.title as video_name,u.nick_name as fsNickName, u.avatar as fsAvatar,
  174. l.log_type,SEC_TO_TIME(l.duration) as duration,c.company_name,l.camp_period_time,l.finish_time,
  175. cu.nick_name as company_user_name ,l.send_type,l.create_time, qu.qw_user_name,qec.name as external_user_name
  176. from fs_course_watch_log l
  177. left join fs_user_course_video v on v.video_id = l.video_id
  178. left join fs_user_course uc on uc.course_id = l.course_id
  179. left join fs_user u on u.user_id = l.user_id
  180. left join company_user cu on cu.user_id = l.company_user_id
  181. left join company c on c.company_id = l.company_id
  182. LEFT JOIN qw_user qu on qu.id= l.qw_user_id
  183. LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  184. <where>
  185. <if test ='userId !=null'>
  186. and l.user_id = #{userId}
  187. </if>
  188. <if test ='qwUserId !=null'>
  189. and l.qw_user_id = #{qwUserId}
  190. </if>
  191. <if test ='courseId !=null'>
  192. and l.course_id = #{courseId}
  193. </if>
  194. <if test ='videoId !=null'>
  195. and l.video_id = #{videoId}
  196. </if>
  197. <if test ='logType !=null'>
  198. and l.log_type = #{logType}
  199. </if>
  200. <if test ='companyId !=null'>
  201. and l.company_id = #{companyId}
  202. </if>
  203. <if test ='companyUserId !=null'>
  204. and l.company_user_id = #{companyUserId}
  205. </if>
  206. <if test ='companyUserName !=null and maps.companyUserName!=""'>
  207. and cu.nick_name like concat('%', #{companyUserName}, '%')
  208. </if>
  209. <if test ='nickName !=null and maps.nickName!=""'>
  210. and u.nick_name like concat('%', #{nickName}, '%')
  211. </if>
  212. <if test= 'sTime != null '>
  213. and DATE(l.create_time) &gt;= DATE(#{sTime})
  214. </if>
  215. <if test='eTime != null '>
  216. and DATE(l.create_time) &lt;= DATE(#{eTime})
  217. </if>
  218. <if test= 'maps.scheduleStartTime != null '>
  219. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  220. </if>
  221. <if test='maps.scheduleEndTime != null '>
  222. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  223. </if>
  224. <if test="sopIds != null and sopIds.size() > 0">
  225. and l.sop_id in
  226. <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
  227. #{sopId}
  228. </foreach>
  229. </if>
  230. <if test="maps.watchType != null "> and l.watch_type = #{maps.watchType}</if>
  231. </where>
  232. order by l.log_id desc
  233. </select>
  234. <insert id="insertFsCourseWatchLog" parameterType="FsCourseWatchLog" useGeneratedKeys="true" keyProperty="logId">
  235. insert into fs_course_watch_log
  236. <trim prefix="(" suffix=")" suffixOverrides=",">
  237. <if test="userId != null">user_id,</if>
  238. <if test="videoId != null">video_id,</if>
  239. <if test="logType != null">log_type,</if>
  240. <if test="createTime != null">create_time,</if>
  241. <if test="updateTime != null">update_time,</if>
  242. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  243. <if test="duration != null">duration,</if>
  244. <if test="qwUserId != null">qw_user_id,</if>
  245. <if test="companyUserId != null">company_user_id,</if>
  246. <if test="companyId != null">company_id,</if>
  247. <if test="courseId != null">course_id,</if>
  248. <if test="sendType != null">send_type,</if>
  249. <if test="rewardType != null">reward_type,</if>
  250. <if test="sopId != null">sop_id,</if>
  251. <if test="finishTime != null">finish_time,</if>
  252. <if test="sendFinishMsg != null">send_finish_msg,</if>
  253. <if test="campPeriodTime != null">camp_period_time,</if>
  254. <if test="periodId != null">period_id,</if>
  255. <if test="project != null">project,</if>
  256. <if test="watchType != null">watch_type,</if>
  257. </trim>
  258. <trim prefix="values (" suffix=")" suffixOverrides=",">
  259. <if test="userId != null">#{userId},</if>
  260. <if test="videoId != null">#{videoId},</if>
  261. <if test="logType != null">#{logType},</if>
  262. <if test="createTime != null">#{createTime},</if>
  263. <if test="updateTime != null">#{updateTime},</if>
  264. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  265. <if test="duration != null">#{duration},</if>
  266. <if test="qwUserId != null">#{qwUserId},</if>
  267. <if test="companyUserId != null">#{companyUserId},</if>
  268. <if test="companyId != null">#{companyId},</if>
  269. <if test="courseId != null">#{courseId},</if>
  270. <if test="sendType != null">#{sendType},</if>
  271. <if test="rewardType != null">#{rewardType},</if>
  272. <if test="sopId != null">#{sopId},</if>
  273. <if test="finishTime != null">#{finishTime},</if>
  274. <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
  275. <if test="campPeriodTime != null">#{campPeriodTime},</if>
  276. <if test="periodId != null">#{periodId},</if>
  277. <if test="project != null">#{project},</if>
  278. <if test="watchType != null">#{watchType},</if>
  279. </trim>
  280. </insert>
  281. <insert id="insertOrUpdateFsCourseWatchLog" parameterType="FsCourseWatchLog">
  282. insert into fs_course_watch_log
  283. <trim prefix="(" suffix=")" suffixOverrides=",">
  284. <if test="userId != null">user_id,</if>
  285. <if test="videoId != null">video_id,</if>
  286. <if test="logType != null">log_type,</if>
  287. <if test="createTime != null">create_time,</if>
  288. <if test="updateTime != null">update_time,</if>
  289. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  290. <if test="duration != null">duration,</if>
  291. <if test="qwUserId != null">qw_user_id,</if>
  292. <if test="companyUserId != null">company_user_id,</if>
  293. <if test="companyId != null">company_id,</if>
  294. <if test="courseId != null">course_id,</if>
  295. <if test="sendType != null">send_type,</if>
  296. <if test="rewardType != null">reward_type,</if>
  297. <if test="sopId != null">sop_id,</if>
  298. <if test="finishTime != null">finish_time,</if>
  299. <if test="sendFinishMsg != null">send_finish_msg,</if>
  300. <if test="campPeriodTime != null">camp_period_time,</if>
  301. <if test="project != null">project,</if>
  302. <if test="watchType != null">watch_type,</if>
  303. </trim>
  304. <trim prefix="values (" suffix=")" suffixOverrides=",">
  305. <if test="userId != null">#{userId},</if>
  306. <if test="videoId != null">#{videoId},</if>
  307. <if test="logType != null">#{logType},</if>
  308. <if test="createTime != null">#{createTime},</if>
  309. <if test="updateTime != null">#{updateTime},</if>
  310. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  311. <if test="duration != null">#{duration},</if>
  312. <if test="qwUserId != null">#{qwUserId},</if>
  313. <if test="companyUserId != null">#{companyUserId},</if>
  314. <if test="companyId != null">#{companyId},</if>
  315. <if test="courseId != null">#{courseId},</if>
  316. <if test="sendType != null">#{sendType},</if>
  317. <if test="rewardType != null">#{rewardType},</if>
  318. <if test="sopId != null">#{sopId},</if>
  319. <if test="finishTime != null">#{finishTime},</if>
  320. <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
  321. <if test="campPeriodTime != null">#{campPeriodTime},</if>
  322. <if test="project != null">#{project},</if>
  323. <if test="watchType != null">#{watchType},</if>
  324. </trim>
  325. on duplicate key update
  326. <trim suffixOverrides=",">
  327. <if test="updateTime != null">update_time = #{updateTime},</if>
  328. </trim>
  329. </insert>
  330. <insert id="insertFsCourseWatchLogBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="logId">
  331. INSERT INTO fs_course_watch_log (
  332. user_id,
  333. video_id,
  334. log_type,
  335. create_time,
  336. update_time,
  337. qw_external_contact_id,
  338. duration,
  339. qw_user_id,
  340. company_user_id,
  341. company_id,
  342. course_id,
  343. send_type,
  344. reward_type,
  345. sop_id,
  346. camp_period_time,
  347. project,
  348. period_id,
  349. im_msg_send_detail_id,
  350. watch_type
  351. )
  352. VALUES
  353. <foreach collection="watchLogs" item="log" separator=",">
  354. (
  355. #{log.userId},
  356. #{log.videoId},
  357. #{log.logType},
  358. #{log.createTime},
  359. #{log.updateTime},
  360. #{log.qwExternalContactId},
  361. #{log.duration},
  362. #{log.qwUserId},
  363. #{log.companyUserId},
  364. #{log.companyId},
  365. #{log.courseId},
  366. #{log.sendType},
  367. #{log.rewardType},
  368. #{log.sopId},
  369. #{log.campPeriodTime},
  370. #{log.project},
  371. #{log.periodId},
  372. #{log.imMsgSendDetailId},
  373. #{log.watchType}
  374. )
  375. </foreach>
  376. ON DUPLICATE KEY UPDATE
  377. update_time = NOW(),
  378. im_msg_send_detail_id = VALUES(im_msg_send_detail_id)
  379. </insert>
  380. <insert id="insertBackup">
  381. INSERT INTO fs_course_watch_log_bak (
  382. original_log_id,
  383. user_id,
  384. video_id,
  385. log_type,
  386. create_time,
  387. update_time,
  388. qw_external_contact_id,
  389. duration,
  390. qw_user_id,
  391. company_user_id,
  392. company_id,
  393. course_id,
  394. send_type,
  395. reward_type,
  396. last_heartbeat_time,
  397. sop_id,
  398. finish_time,
  399. send_finish_msg,
  400. camp_period_time,
  401. day,
  402. project,
  403. create_by,
  404. update_by,
  405. period_id,
  406. project_id,
  407. im_msg_send_detail_id,
  408. watch_type,
  409. delete_time,
  410. delete_by,
  411. delete_method,
  412. original_data,
  413. backup_operator,
  414. backup_batch_no,
  415. remark
  416. ) VALUES (
  417. #{originalLogId},
  418. #{userId},
  419. #{videoId},
  420. #{logType},
  421. #{createTime},
  422. #{updateTime},
  423. #{qwExternalContactId},
  424. #{duration},
  425. #{qwUserId},
  426. #{companyUserId},
  427. #{companyId},
  428. #{courseId},
  429. #{sendType},
  430. #{rewardType},
  431. #{lastHeartbeatTime},
  432. #{sopId},
  433. #{finishTime},
  434. #{sendFinishMsg},
  435. #{campPeriodTime},
  436. #{day},
  437. #{project},
  438. #{createBy},
  439. #{updateBy},
  440. #{periodId},
  441. #{projectId},
  442. #{imMsgSendDetailId},
  443. #{watchType},
  444. #{deleteTime},
  445. #{deleteBy},
  446. #{deleteMethod},
  447. #{originalData},
  448. #{backupOperator},
  449. #{backupBatchNo},
  450. #{remark}
  451. )
  452. </insert>
  453. <update id="updateFsCourseWatchLog" parameterType="FsCourseWatchLog">
  454. update fs_course_watch_log
  455. <trim prefix="SET" suffixOverrides=",">
  456. <if test="userId != null">user_id = #{userId},</if>
  457. <if test="videoId != null">video_id = #{videoId},</if>
  458. <if test="logType != null">log_type = #{logType},</if>
  459. <if test="createTime != null">create_time = #{createTime},</if>
  460. <if test="updateTime != null">update_time = #{updateTime},</if>
  461. <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
  462. <if test="duration != null">duration = #{duration},</if>
  463. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  464. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  465. <if test="companyId != null">company_id = #{companyId},</if>
  466. <if test="courseId != null">course_id = #{courseId},</if>
  467. <if test="sendType != null">send_type = #{sendType},</if>
  468. <if test="rewardType != null">reward_type = #{rewardType},</if>
  469. <if test="sopId != null">sop_id = #{sopId},</if>
  470. <if test="finishTime != null">finish_time = #{finishTime},</if>
  471. <if test="sendFinishMsg != null">send_finish_msg = #{sendFinishMsg},</if>
  472. <if test="lastHeartbeatTime != null">last_heartbeat_time = #{lastHeartbeatTime},</if>
  473. <if test="periodId != null">period_id = #{periodId},</if>
  474. <if test="project != null">project = #{project},</if>
  475. <if test="watchType != null">watch_type = #{watchType},</if>
  476. </trim>
  477. where log_id = #{logId}
  478. </update>
  479. <delete id="deleteFsCourseWatchLogByLogId" parameterType="Long">
  480. delete from fs_course_watch_log where log_id = #{logId}
  481. </delete>
  482. <delete id="deleteFsCourseWatchLogByLogIds" parameterType="String">
  483. delete from fs_course_watch_log where log_id in
  484. <foreach item="logId" collection="array" open="(" separator="," close=")">
  485. #{logId}
  486. </foreach>
  487. </delete>
  488. <select id="selectFsCourseWatchLogByFinishTime" resultType="com.fs.course.param.FsCourseWatchLogByFinishTimeParam">
  489. <![CDATA[
  490. SELECT
  491. fcwl.log_id,
  492. fcwl.create_time,
  493. fcwl.qw_external_contact_id,
  494. fcwl.qw_user_id,
  495. fcwl.user_id,
  496. fcwl.company_user_id,
  497. fcwl.company_id,
  498. fcwl.sop_id,
  499. fcwl.finish_time,
  500. fcwl.camp_period_time,
  501. qec.corp_id,
  502. qec.external_user_id,
  503. qec.tag_ids,
  504. qec.user_id AS qw_user,
  505. qec.name AS external_contact_name
  506. FROM
  507. fs_course_watch_log fcwl
  508. LEFT JOIN qw_external_contact qec ON fcwl.qw_external_contact_id = qec.id
  509. WHERE
  510. DATE(fcwl.finish_time)= '2025-02-09'
  511. and fcwl.camp_period_time is not NULL
  512. ]]>
  513. </select>
  514. <select id="getWatchLogByFsUser" resultType="com.fs.course.domain.FsCourseWatchLog">
  515. SELECT
  516. log_id,
  517. user_id,
  518. video_id,
  519. log_type,
  520. create_time,
  521. update_time,
  522. duration,
  523. company_user_id,
  524. company_id,
  525. course_id,
  526. send_type,
  527. reward_type,
  528. last_heartbeat_time,
  529. sop_id,
  530. finish_time,
  531. send_finish_msg,
  532. camp_period_time
  533. FROM
  534. fs_course_watch_log
  535. WHERE
  536. send_type = 1
  537. AND video_id = #{videoId}
  538. AND user_id = #{fsUserId}
  539. AND company_user_id = #{companyUserId} order by log_id desc limit 1
  540. </select>
  541. <select id="selectFsCourseWatchLogStatisticsListVONew"
  542. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO">
  543. SELECT
  544. o.company_user_id,o.user_id,DATE(o.create_time) create_time,
  545. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  546. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  547. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  548. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4,
  549. o.project as project,
  550. o.course_id as course_id,
  551. o.video_id as video_id
  552. FROM fs_course_watch_log o
  553. <where>
  554. send_type=1
  555. <if test="companyId != null">
  556. and o.company_id=#{companyId}
  557. </if>
  558. <if test= 'sTime != null '>
  559. and DATE(o.create_time) &gt;= #{sTime}
  560. </if>
  561. <if test='eTime != null '>
  562. and DATE(o.create_time) &lt;= #{eTime}
  563. </if>
  564. <if test ='courseId !=null'>
  565. and o.course_id = #{courseId}
  566. </if>
  567. <if test ='videoId !=null'>
  568. and o.video_id = #{videoId}
  569. </if>
  570. <if test="companyUserId != null">
  571. and o.company_user_id = #{companyUserId}
  572. </if>
  573. <if test="project != null">
  574. and o.project = #{project}
  575. </if>
  576. <if test="userId != null">
  577. and o.user_id = #{userId}
  578. </if>
  579. </where>
  580. GROUP BY o.video_id,o.user_id,DATE(o.create_time),o.project,o.course_id
  581. ORDER BY o.video_id ,DATE(o.create_time)
  582. <!-- limit ${(pageNum-1)*pageSize},${pageSize}-->
  583. </select>
  584. <select id="selectFsCourseWatchLogStatisticsListVONewCount" resultType="java.lang.Long">
  585. SELECT COUNT(*)
  586. FROM (
  587. SELECT 1
  588. FROM fs_course_watch_log o
  589. <where>
  590. send_type=2
  591. <if test="companyId != null">
  592. and o.company_id=#{companyId}
  593. </if>
  594. <if test= 'sTime != null '>
  595. and o.create_time &gt;= #{startDate}
  596. </if>
  597. <if test='eTime != null '>
  598. and o.create_time &lt;= #{endDate}
  599. </if>
  600. <if test ='courseId !=null'>
  601. and o.course_id = #{courseId}
  602. </if>
  603. <if test ='videoId !=null'>
  604. and o.video_id = #{videoId}
  605. </if>
  606. <if test="companyUserId != null">
  607. and o.company_user_id = #{companyUserId}
  608. </if>
  609. <if test="project != null">
  610. and o.project = #{project}
  611. </if>
  612. <if test="userId != null">
  613. and o.user_id = #{userId}
  614. </if>
  615. </where>
  616. GROUP BY o.video_id, o.user_id, DATE(o.create_time), o.project, o.course_id
  617. ) AS grouped_results_count
  618. </select>
  619. <!-- 根据条件查询条数 -->
  620. <select id="countByMap" resultType="java.lang.Integer">
  621. select count(fcwl.log_id) from fs_course_watch_log fcwl
  622. <where>
  623. <if test="params.logTypes != null and params.logTypes.size() > 0">
  624. and fcwl.log_type in
  625. <foreach collection="params.logTypes" open="(" close=")" separator="," item="logType">
  626. #{logType}
  627. </foreach>
  628. </if>
  629. <if test="params.companyUserId != null">
  630. and fcwl.company_user_id = #{params.companyUserId}
  631. </if>
  632. <if test="params.date != null">
  633. and date(fcwl.create_time) = #{params.date}
  634. </if>
  635. </where>
  636. </select>
  637. <update id="batchUpdateWatchLog" parameterType="java.util.List">
  638. UPDATE fs_course_watch_log
  639. SET
  640. duration = CASE
  641. <foreach collection="list" item="item" index="index">
  642. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  643. CASE
  644. <!-- 仅当传入的duration > 当前值时才更新 -->
  645. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  646. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  647. END
  648. </foreach>
  649. END,
  650. last_heartbeat_time = CASE
  651. <foreach collection="list" item="item" index="index">
  652. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  653. CASE
  654. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  655. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  656. END
  657. </foreach>
  658. END,
  659. finish_time = CASE
  660. <foreach collection="list" item="item" index="index">
  661. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  662. CASE
  663. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  664. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  665. END
  666. </foreach>
  667. END,
  668. log_type = CASE
  669. <foreach collection="list" item="item" index="index">
  670. WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
  671. CASE
  672. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  673. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  674. ELSE log_type <!-- 其他情况保持原值 -->
  675. END
  676. </foreach>
  677. END
  678. WHERE
  679. (video_id, qw_external_contact_id, qw_user_id) IN
  680. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  681. (#{item.videoId}, #{item.qwExternalContactId}, #{item.qwUserId})
  682. </foreach>
  683. </update>
  684. <update id="batchUpdateWatchLogSendMsg" parameterType="java.util.List">
  685. UPDATE fs_course_watch_log
  686. SET send_finish_msg = CASE
  687. <foreach collection="list" item="item">
  688. WHEN log_id = #{item.logId} THEN #{item.sendFinishMsg}
  689. </foreach>
  690. ELSE send_finish_msg
  691. END
  692. WHERE log_id IN
  693. <foreach collection="list" item="item" open="(" separator="," close=")">
  694. #{item.logId}
  695. </foreach>
  696. </update>
  697. <update id="batchUpdateFsUserWatchLog" parameterType="java.util.List">
  698. UPDATE fs_course_watch_log
  699. SET
  700. duration = CASE
  701. <foreach collection="list" item="item" index="index">
  702. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  703. CASE
  704. <!-- 仅当传入的duration > 当前值时才更新 -->
  705. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  706. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  707. END
  708. </foreach>
  709. END,
  710. last_heartbeat_time = CASE
  711. <foreach collection="list" item="item" index="index">
  712. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  713. CASE
  714. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  715. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  716. END
  717. </foreach>
  718. END,
  719. finish_time = CASE
  720. <foreach collection="list" item="item" index="index">
  721. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  722. CASE
  723. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  724. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  725. END
  726. </foreach>
  727. END,
  728. log_type = CASE
  729. <foreach collection="list" item="item" index="index">
  730. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
  731. CASE
  732. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  733. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  734. ELSE log_type <!-- 其他情况保持原值 -->
  735. END
  736. </foreach>
  737. END
  738. WHERE
  739. (video_id, user_id, company_user_id) IN
  740. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  741. (#{item.videoId}, #{item.userId}, #{item.companyUserId})
  742. </foreach>
  743. </update>
  744. <update id="batchUpdateWatchLogIsOpen">
  745. UPDATE fs_course_watch_log
  746. SET
  747. duration = CASE
  748. <foreach collection="list" item="item" index="index">
  749. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  750. CASE
  751. <!-- 仅当传入的duration > 当前值时才更新 -->
  752. WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
  753. ELSE duration <!-- 如果 duration 为 null,保持原值 -->
  754. END
  755. </foreach>
  756. END,
  757. last_heartbeat_time = CASE
  758. <foreach collection="list" item="item" index="index">
  759. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  760. CASE
  761. WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
  762. ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
  763. END
  764. </foreach>
  765. END,
  766. finish_time = CASE
  767. <foreach collection="list" item="item" index="index">
  768. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  769. CASE
  770. WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
  771. ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
  772. END
  773. </foreach>
  774. END,
  775. log_type = CASE
  776. <foreach collection="list" item="item" index="index">
  777. WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
  778. CASE
  779. WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
  780. WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
  781. ELSE log_type <!-- 其他情况保持原值 -->
  782. END
  783. </foreach>
  784. END
  785. WHERE
  786. (video_id, user_id) IN
  787. <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
  788. (#{item.videoId}, #{item.userId})
  789. </foreach>
  790. </update>
  791. <select id="selectListBytrainingCampId" resultType="com.fs.course.vo.FsCourseWatchLogVO">
  792. select
  793. uc.course_name,v.title as video_name,
  794. watch.log_id,
  795. watch.user_id,
  796. watch.finish_time,
  797. watch.send_finish_msg,
  798. watch.sop_id,
  799. watch.video_id,
  800. watch.reward_type,
  801. watch.log_type,
  802. watch.create_time,
  803. watch.update_time,
  804. watch.qw_external_contact_id,
  805. watch.duration,
  806. watch.qw_user_id,
  807. watch.company_user_id,
  808. watch.company_id,
  809. watch.course_id,
  810. watch.camp_period_time
  811. from
  812. fs_user_course_training_camp camp
  813. left join fs_user_course_period period on
  814. camp.training_camp_id = period.training_camp_id
  815. left join fs_course_watch_log watch on
  816. period.period_id = watch.period_id
  817. left join fs_user_course uc on uc.course_id = watch.course_id
  818. left join fs_user_course_video v on v.video_id = watch.video_id
  819. <where>
  820. `period`.del_flag = '0' and watch.log_type &lt;&gt; 3
  821. <if test="trainingCampId != null">and camp.training_camp_id = #{trainingCampId}</if>
  822. <if test="userId != null">and watch.user_id = #{userId}</if>
  823. <if test="periodId != null">and `period`.period_id = #{periodId}</if>
  824. </where>
  825. </select>
  826. <select id="selectFsCourseWatchLogListVOexport" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
  827. SELECT
  828. l.log_id,
  829. l.project AS project,
  830. l.period_id,
  831. l.user_id,
  832. l.log_type,
  833. SEC_TO_TIME(l.duration) AS duration,
  834. l.camp_period_time,
  835. l.finish_time,
  836. l.send_type,
  837. l.create_time,
  838. l.update_time,
  839. l.last_heartbeat_time,
  840. l.company_id,
  841. l.company_user_id,
  842. l.course_id,
  843. l.video_id,
  844. l.qw_user_id,
  845. l.qw_external_contact_id,
  846. l.sop_id,
  847. qec.create_time as qec_create_time
  848. FROM
  849. fs_course_watch_log l LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
  850. left join fs_user u on u.user_id = l.user_id
  851. left join company_user cu on cu.user_id = l.company_user_id
  852. <where>
  853. <if test ='maps.sendType !=null'>
  854. and l.send_type = #{maps.sendType}
  855. </if>
  856. <if test ='maps.userId !=null'>
  857. and l.user_id = #{maps.userId}
  858. </if>
  859. <if test ='maps.qwExternalContactId !=null'>
  860. and l.qw_external_contact_id = #{maps.qwExternalContactId}
  861. </if>
  862. <if test ='maps.qwUserId !=null'>
  863. and l.qw_user_id = #{maps.qwUserId}
  864. </if>
  865. <if test ='maps.courseId !=null'>
  866. and l.course_id = #{maps.courseId}
  867. </if>
  868. <if test ='maps.videoId !=null'>
  869. and l.video_id = #{maps.videoId}
  870. </if>
  871. <if test ='maps.logType !=null'>
  872. and l.log_type = #{maps.logType}
  873. </if>
  874. <if test ='maps.companyId !=null'>
  875. and l.company_id = #{maps.companyId}
  876. </if>
  877. <if test ='maps.companyUserId !=null'>
  878. and l.company_user_id = #{maps.companyUserId}
  879. </if>
  880. <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
  881. and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
  882. </if>
  883. <if test ='maps.nickName !=null and maps.nickName!=""'>
  884. and u.nick_name like concat('%', #{maps.nickName}, '%')
  885. </if>
  886. <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
  887. and qec.name like concat('%', #{maps.externalUserName}, '%')
  888. </if>
  889. <if test= 'maps.qecSTime != null '>
  890. and DATE(qec.create_time) &gt;= DATE(#{maps.qecSTime})
  891. </if>
  892. <if test='maps.qecETime != null '>
  893. and DATE(qec.create_time) &lt;= DATE(#{maps.qecETime})
  894. </if>
  895. <if test= 'maps.sTime != null '>
  896. and DATE(l.create_time) &gt;= DATE(#{maps.sTime})
  897. </if>
  898. <if test='maps.eTime != null '>
  899. and DATE(l.create_time) &lt;= DATE(#{maps.eTime})
  900. </if>
  901. <if test= 'maps.scheduleStartTime != null '>
  902. and DATE(l.camp_period_time) &gt;= DATE(#{maps.scheduleStartTime})
  903. </if>
  904. <if test='maps.scheduleEndTime != null '>
  905. and DATE(l.camp_period_time) &lt;= DATE(#{maps.scheduleEndTime})
  906. </if>
  907. <if test= 'maps.upSTime != null '>
  908. and DATE(l.update_time) &gt;= DATE(#{maps.upSTime})
  909. </if>
  910. <if test='maps.upETime != null '>
  911. and DATE(l.update_time) &lt;= DATE(#{maps.upETime})
  912. </if>
  913. <if test="maps.sopIds != null and maps.sopIds.size() > 0">
  914. and l.sop_id in
  915. <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
  916. #{sopId}
  917. </foreach>
  918. </if>
  919. <if test="maps.periodIds != null and maps.periodIds.size() > 0">
  920. and l.period_id in
  921. <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
  922. #{periodId}
  923. </foreach>
  924. </if>
  925. </where>
  926. order by l.finish_time desc,l.update_time desc,l.create_time desc
  927. </select>
  928. <select id="getWatchCourseByVideoId" resultType="com.fs.course.domain.FsCourseWatchLog">
  929. SELECT
  930. *
  931. FROM
  932. fs_course_watch_log
  933. WHERE
  934. send_type = 1
  935. AND video_id = #{videoId}
  936. AND user_id in
  937. <foreach item="userId" index="index" collection="userIds" open="(" separator="," close=")">
  938. #{userId}
  939. </foreach>
  940. ORDER BY
  941. log_id DESC
  942. </select>
  943. <select id="getUserCountByCampId" resultType="java.lang.Integer">
  944. select count(distinct cwl.user_id)
  945. from fs_user_course_period ucp
  946. inner join fs_course_watch_log cwl on ucp.period_id = cwl.period_id
  947. where ucp.training_camp_id = #{trainingCampId}
  948. </select>
  949. <select id="selectFsCourseWatchLogStatisticsListByCompanyVO"
  950. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListByCompanyVO">
  951. SELECT
  952. o.video_id,
  953. o.company_id,
  954. comp.company_name,
  955. o.qw_user_id,
  956. DATE(o.create_time) create_time,
  957. v.title videoName,
  958. uc.course_name,
  959. SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
  960. SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
  961. SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
  962. SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4
  963. FROM
  964. fs_course_watch_log o
  965. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  966. LEFT JOIN company comp ON comp.company_id = o.company_id
  967. LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
  968. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  969. <where>
  970. <if test="sendType != null">
  971. and send_type = #{sendType}
  972. </if>
  973. <if test="companyId != null">
  974. and o.company_id = #{companyId}
  975. </if>
  976. <if test="sTime != null">
  977. AND DATE (o.create_time) &gt;= DATE (#{sTime})
  978. </if>
  979. <if test="eTime != null">
  980. AND DATE (o.create_time) &lt;= DATE (#{eTime})
  981. </if>
  982. <if test="courseId != null">
  983. and o.course_id = #{courseId}
  984. </if>
  985. <if test="videoId != null">
  986. and o.video_id = #{videoId}
  987. </if>
  988. </where>
  989. GROUP BY
  990. DATE (o.create_time),
  991. o.company_id
  992. ORDER BY
  993. comp.company_id,
  994. DATE (o.create_time)
  995. </select>
  996. <select id="selectQwFsCourseWatchLogStatisticsListVO"
  997. resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO" parameterType="com.fs.qw.param.QwSidebarStatsParam">
  998. SELECT
  999. o.project,
  1000. o.course_id AS courseId,
  1001. uc.course_name AS courseName,
  1002. o.video_id AS videoId,
  1003. v.title AS videoName,
  1004. CASE WHEN o.log_type = 1 THEN 1 END AS type1,
  1005. CASE WHEN o.log_type = 2 THEN 1 END AS type2,
  1006. CASE WHEN o.log_type = 3 THEN 1 END AS type3,
  1007. CASE WHEN o.log_type = 4 THEN 1 END AS type4,
  1008. o.qw_user_id,
  1009. o.user_id AS userId,
  1010. o.company_user_id AS companyUserId,
  1011. o.company_id AS companyId,
  1012. o.create_time AS createTime
  1013. FROM
  1014. fs_course_watch_log o
  1015. LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
  1016. LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
  1017. WHERE o.qw_external_contact_id=#{qwExternalContactId}
  1018. <if test="sendType != null">
  1019. AND send_type = #{sendType}
  1020. </if>
  1021. <if test="startTime != null">
  1022. AND DATE(o.create_time) &gt;= DATE(#{startTime})
  1023. </if>
  1024. <if test="endTime != null">
  1025. AND DATE(o.create_time) &lt;= DATE(#{endTime})
  1026. </if>
  1027. o.create_time DESC
  1028. </select>
  1029. <!-- 统计当天各公司的观看人数和完播人数, 存到redis中,定时任务每 ? 分钟执行一次 -->
  1030. <select id="watchCourseStatisticsGroupByCompany" resultType="com.fs.statis.dto.WatchCourseStatisticsResultDTO">
  1031. SELECT
  1032. o.company_id AS companyId,
  1033. c.company_name AS companyName,
  1034. o.send_type,
  1035. COUNT(DISTINCT o.user_id) AS watchUserCount,
  1036. COUNT(o.log_id) AS watchCount,
  1037. sum(case when o.log_type = 2 then 1 else 0 end) AS finishCount,
  1038. COUNT(DISTINCT CASE WHEN o.log_type = 2 THEN o.user_id END) AS finishUserCount
  1039. FROM
  1040. fs_course_watch_log o
  1041. LEFT JOIN company c ON c.company_id = o.company_id
  1042. WHERE
  1043. o.create_time &gt;= #{params.startTime}
  1044. AND o.create_time &lt;= #{params.endTime}
  1045. GROUP BY
  1046. o.company_id,
  1047. o.send_type
  1048. </select>
  1049. <select id="selectUserBaseInfo" resultType="com.fs.his.vo.FsUserReportVO">
  1050. SELECT distinct u.user_id AS userId,
  1051. u.nick_name AS nickName,
  1052. u.integral AS integral,
  1053. CASE
  1054. WHEN u.`status` = '1' THEN '正常'
  1055. WHEN u.`status` = '2' THEN '禁止'
  1056. ELSE '无'
  1057. END AS status,
  1058. u.register_date AS registerDate,
  1059. u.phone,
  1060. cu.nick_name AS companyUserName,
  1061. cuu.company_user_id as companyUserId,
  1062. c.company_name AS companyName
  1063. <if test='dimension == "dept"'>
  1064. ,cd.dept_name AS deptName
  1065. </if>
  1066. FROM fs_user u
  1067. inner JOIN fs_user_company_user cuu ON u.user_id = cuu.user_id
  1068. <if test="sTime != null and eTime != null">
  1069. left join fs_package_order po on po.user_id=u.user_id
  1070. </if>
  1071. LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
  1072. LEFT JOIN company c ON cuu.company_id = c.company_id
  1073. <if test='dimension == "dept"'>
  1074. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  1075. </if>
  1076. <if test="trainingCampId != null or periodId != null ">
  1077. Left Join fs_course_watch_log watch on watch.user_id= cuu.user_id and watch.project=cuu.project_id
  1078. left join fs_user_course_period period on watch.period_id=period.period_id and period.del_flag=0
  1079. left join fs_user_course_training_camp camp on period.training_camp_id= camp.training_camp_id and camp.del_flag=0
  1080. </if>
  1081. WHERE u.user_id IS NOT NULL
  1082. <if test="userId != null">
  1083. AND u.user_id = #{userId}
  1084. </if>
  1085. <if test="userPhone != null and userPhone != ''">
  1086. AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
  1087. </if>
  1088. <if test="nickName != null and nickName != ''">
  1089. AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
  1090. </if>
  1091. <!-- 部门条件 -->
  1092. <if test="deptId != null">
  1093. AND cd.dept_id = #{deptId}
  1094. </if>
  1095. <!-- 销售公司条件 -->
  1096. <if test="companyId != null and companyId != ''">
  1097. AND c.company_id = #{companyId}
  1098. </if>
  1099. <if test="project != null">
  1100. AND cuu.project_id = #{project}
  1101. </if>
  1102. <!-- 训练营条件 -->
  1103. <if test="trainingCampId != null">
  1104. AND camp.training_camp_id = #{trainingCampId}
  1105. </if>
  1106. <!-- 营期条件 -->
  1107. <if test="periodId != null">
  1108. AND period.period_id = #{periodId}
  1109. </if>
  1110. <!-- 时间范围 - 使用BETWEEN -->
  1111. <if test="sTime != null and eTime != null">
  1112. AND DATE(po.create_time) BETWEEN #{sTime} AND #{eTime}
  1113. </if>
  1114. order by u.create_time
  1115. </select>
  1116. <select id="selectWatchStatsByUserIds" resultType="com.fs.his.vo.FsUserReportVO">
  1117. SELECT
  1118. user_id AS userId,
  1119. company_user_id AS companyUserId,
  1120. MAX(
  1121. COALESCE ( update_time, create_time )) AS lastWatchTime,
  1122. COUNT( log_id ) AS watchCount,
  1123. COUNT( DISTINCT period_id ) AS periodCount,
  1124. CASE
  1125. ( SELECT log_type FROM fs_course_watch_log w2 WHERE w2.user_id = w1.user_id ORDER BY create_time DESC LIMIT 1 )
  1126. WHEN '1' THEN
  1127. '看课中'
  1128. WHEN '2' THEN
  1129. '完课'
  1130. WHEN '3' THEN
  1131. '待看课'
  1132. WHEN '4' THEN
  1133. '看课中断' ELSE '无'
  1134. END AS watchStatus
  1135. FROM
  1136. fs_course_watch_log w1
  1137. WHERE (user_id, company_user_id) IN
  1138. <foreach collection="userConditions" item="condition" open="(" close=")" separator=",">
  1139. (#{condition.userId}, #{condition.companyUserId})
  1140. </foreach>
  1141. <if test="watchParam.project != null">
  1142. AND w1.project = #{watchParam.project}
  1143. </if>
  1144. <if test="watchParam.periodId != null">
  1145. AND w1.period_id = #{watchParam.periodId}
  1146. </if>
  1147. GROUP BY user_id,company_user_id
  1148. </select>
  1149. <select id="selectIntegralStatsByUserIds" resultType="com.fs.his.vo.FsUserReportVO">
  1150. SELECT
  1151. user_id AS userId,
  1152. ABS(SUM(CASE WHEN integral &lt; 0 THEN integral ELSE 0 END)) AS consumedIntegral
  1153. from fs_user_integral_logs
  1154. WHERE user_id IN
  1155. <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  1156. #{userId}
  1157. </foreach>
  1158. GROUP BY user_id
  1159. </select>
  1160. <select id="selectRedPacketStatsByUserIds" resultType="com.fs.his.vo.FsUserReportVO">
  1161. SELECT
  1162. user_id AS userId,
  1163. company_user_id AS companyUserId,
  1164. SUM(amount) AS receivedAmount
  1165. FROM fs_course_red_packet_log
  1166. WHERE status = 1
  1167. and (user_id, company_user_id) IN
  1168. <foreach collection="userConditions" item="condition" open="(" close=")" separator=",">
  1169. (#{condition.userId}, #{condition.companyUserId})
  1170. </foreach>
  1171. <if test="watchParam.periodId != null">
  1172. AND period_id = #{watchParam.periodId}
  1173. </if>
  1174. GROUP BY user_id,company_user_id
  1175. </select>
  1176. <select id="selectOrderStatsByUserIds" resultType="com.fs.his.vo.FsUserReportVO">
  1177. SELECT
  1178. user_id AS userId,
  1179. SUM(pay_money) AS orderAmount
  1180. FROM fs_package_order
  1181. WHERE status = 3
  1182. AND user_id IN
  1183. <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  1184. #{userId}
  1185. </foreach>
  1186. <if test="watchParam.sTime != null and watchParam.eTime != null">
  1187. AND create_time BETWEEN #{watchParam.sTime} AND #{watchParam.eTime}
  1188. </if>
  1189. GROUP BY user_id
  1190. </select>
  1191. <select id="selectUserBaseData" resultType="com.fs.his.vo.WatchLogReportVO">
  1192. SELECT
  1193. log.user_id userId,
  1194. u.nick_name AS nickName,
  1195. cu.nick_name AS salesName,
  1196. c.company_name AS salesCompany,
  1197. cd.dept_name AS salesDept,
  1198. log.period_id periodId,
  1199. log.video_id videoId,
  1200. log.log_id logId,
  1201. log.create_time courseTime,
  1202. log.finish_time finishTime,
  1203. log.duration ,
  1204. CASE
  1205. WHEN log.log_type = '1' THEN '看课中'
  1206. WHEN log.log_type = '2' THEN '完课'
  1207. WHEN log.log_type = '3' THEN '待看课'
  1208. WHEN log.log_type = '4' THEN '看课中断'
  1209. ELSE '无'
  1210. END AS watchStatus,
  1211. cv.title AS videoTitle
  1212. FROM
  1213. fs_course_watch_log log
  1214. <if test="orderSTime != null and orderETime != null">
  1215. left join fs_package_order po ON po.user_id = log.user_id
  1216. </if>
  1217. LEFT JOIN fs_user u ON u.user_id = log.user_id
  1218. LEFT JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
  1219. LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
  1220. LEFT JOIN company c ON log.company_id = c.company_id
  1221. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  1222. LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
  1223. WHERE log.send_type =1 and log.watch_type = 2
  1224. <include refid="commonConditions"/>
  1225. <if test="orderSTime != null and orderETime != null">
  1226. AND DATE(po.create_time) BETWEEN #{orderSTime} AND #{orderETime}
  1227. </if>
  1228. group by log.user_id
  1229. ORDER BY u.register_date DESC
  1230. </select>
  1231. <select id="selectSalesBaseData" resultType="com.fs.his.vo.WatchLogReportVO">
  1232. SELECT
  1233. log.user_id userId,
  1234. log.company_user_id companyUserId,
  1235. log.log_id logId,
  1236. log.create_time courseTime,
  1237. cu.nick_name as salesName,
  1238. d.dept_name AS salesDept,
  1239. c.company_name AS salesCompany,
  1240. COUNT( DISTINCT u.user_id ) AS userCount,
  1241. COUNT( DISTINCT CASE WHEN u.STATUS = 1 THEN u.user_id END ) AS onlineUserCount,
  1242. COUNT(DISTINCT log.log_id) AS totalLogCount,
  1243. COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
  1244. COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
  1245. COUNT(DISTINCT log.log_id)-COUNT(DISTINCT log.user_id) AS notWatchedCount,
  1246. COUNT(DISTINCT log.log_id) - COUNT(DISTINCT a.watch_log_id) AS notAnsweredCount
  1247. FROM
  1248. fs_course_watch_log log
  1249. <if test="orderSTime != null and orderETime != null">
  1250. LEFT JOIN fs_package_order po ON po.user_id = log.user_id
  1251. </if>
  1252. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1253. LEFT JOIN fs_user u on log.user_id= u.user_id
  1254. LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
  1255. LEFT JOIN company c ON d.company_id = c.company_id
  1256. LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
  1257. WHERE log.send_type =1 and log.watch_type =2
  1258. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1259. AND log.create_time &gt;= #{startDate} AND log.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1260. </if>
  1261. <if test="orderSTime != null and orderETime != null">
  1262. AND DATE(po.create_time) BETWEEN #{orderSTime} AND #{orderETime}
  1263. </if>
  1264. <!-- 销售公司 -->
  1265. <if test="companyId != null and companyId != ''">
  1266. AND log.company_id = #{companyId}
  1267. </if>
  1268. <if test="deptId != null and deptId != ''">
  1269. AND d.dept_id = #{deptId}
  1270. </if>
  1271. <!-- 训练营 -->
  1272. <if test="trainingCampId != null and trainingCampId != ''">
  1273. AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id =
  1274. #{trainingCampId})
  1275. </if>
  1276. <!-- 营期 -->
  1277. <if test="periodId != null and periodId != ''">
  1278. AND log.period_id = #{periodId}
  1279. </if>
  1280. <!-- 会员id -->
  1281. <if test="userId != null and userId != ''">
  1282. AND log.user_id = #{userId}
  1283. </if>
  1284. <!-- 会员手机号 -->
  1285. <if test="userPhone != null and userPhone != ''">
  1286. AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
  1287. </if>
  1288. <if test="project != null and project != ''">
  1289. AND log.project = #{project}
  1290. </if>
  1291. <!-- 会员昵称 -->
  1292. <if test="nickName != null and nickName != ''">
  1293. AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
  1294. </if>
  1295. GROUP BY cu.user_id
  1296. </select>
  1297. <select id="selectCompanyBaseData" resultType="com.fs.his.vo.WatchLogReportVO">
  1298. SELECT
  1299. log.user_id userId,
  1300. log.period_id periodId,
  1301. log.log_id logId,
  1302. log.create_time courseTime,
  1303. d.dept_id AS deptId,
  1304. d.dept_name AS salesDept,
  1305. c.company_name AS salesCompany,
  1306. COUNT(DISTINCT cu.user_id) AS salesCount,
  1307. COUNT(DISTINCT u.user_id) AS userCount,
  1308. COUNT(DISTINCT CASE WHEN u.STATUS = 1 THEN u.user_id END) AS onlineUserCount,
  1309. cv.title videoTitle,
  1310. COUNT(DISTINCT log.log_id) AS totalLogCount,
  1311. COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
  1312. COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
  1313. COUNT(DISTINCT log.user_id) - COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.user_id END) AS notWatchedCount
  1314. FROM fs_course_watch_log log
  1315. <if test="orderSTime != null and orderETime != null">
  1316. LEFT JOIN fs_package_order po ON po.user_id = log.user_id
  1317. </if>
  1318. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1319. LEFT JOIN fs_user u on log.user_id= u.user_id
  1320. LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
  1321. LEFT JOIN company c ON d.company_id = c.company_id
  1322. LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
  1323. WHERE log.send_type =1
  1324. <if test="sTime != null and eTime != null">
  1325. AND DATE(log.create_time) BETWEEN #{sTime} AND #{eTime}
  1326. </if>
  1327. <if test="orderSTime != null and orderETime != null">
  1328. AND DATE(po.create_time) BETWEEN #{orderSTime} AND #{orderETime}
  1329. </if>
  1330. <!-- 销售公司 -->
  1331. <if test="companyId != null and companyId != ''">
  1332. AND c.company_id = #{companyId}
  1333. </if>
  1334. <!--部门 -->
  1335. <if test="deptId != null and deptId != ''">
  1336. AND d.dept_id = #{deptId}
  1337. </if>
  1338. <!-- 训练营 -->
  1339. <if test="trainingCampId != null and trainingCampId != ''">
  1340. AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  1341. </if>
  1342. <!-- 营期 -->
  1343. <if test="periodId != null and periodId != ''">
  1344. AND log.period_id = #{periodId}
  1345. </if>
  1346. <!-- 会员id -->
  1347. <if test="userId != null and userId != ''">
  1348. AND log.user_id = #{userId}
  1349. </if>
  1350. <!-- 会员手机号 -->
  1351. <if test="userPhone != null and userPhone != ''">
  1352. AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
  1353. </if>
  1354. <if test="project != null and project != ''">
  1355. AND log.project = #{project}
  1356. </if>
  1357. <!-- 会员昵称 -->
  1358. <if test="nickName != null and nickName != ''">
  1359. AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
  1360. </if>
  1361. GROUP BY d.dept_id
  1362. </select>
  1363. <select id="selectUserWatchDetails" resultType="com.fs.his.vo.WatchLogReportVO">
  1364. SELECT
  1365. wl.user_id AS userId,
  1366. wl.company_user_id as companyUserId,
  1367. camp.training_camp_name trainingCampName,
  1368. cp.period_name periodName ,
  1369. cv.title videoTitle ,
  1370. CASE
  1371. WHEN wl.log_type = '1' THEN '看课中'
  1372. WHEN wl.log_type = '2' THEN '完课'
  1373. WHEN wl.log_type = '3' THEN '待看课'
  1374. WHEN wl.log_type = '4' THEN '看课中断'
  1375. ELSE '无'
  1376. END AS watchStatus,
  1377. wl.duration,
  1378. wl.create_time courseTime,
  1379. wl.finish_time finishTime,
  1380. COUNT(DISTINCT log_id) AS totalLogCount,
  1381. COUNT(DISTINCT CASE WHEN wl.log_type = '2' THEN wl.log_id END) AS finishedCount,
  1382. COUNT(DISTINCT CASE WHEN wl.log_type IN ('1', '3', '4') THEN wl.log_id END) AS unfinishedCount,
  1383. (SELECT COUNT(DISTINCT concat(uc.userId, '_', uc.companyUserId))
  1384. FROM (
  1385. <foreach collection="userConditions" item="condition" separator="UNION ALL">
  1386. SELECT #{condition.userId} AS userId, #{condition.companyUserId} AS companyUserId
  1387. </foreach>
  1388. ) uc
  1389. ) - COUNT(DISTINCT concat(wl.user_id, '_', wl.company_user_id)) AS notWatchedCount
  1390. FROM fs_course_watch_log wl
  1391. LEFT JOIN fs_user_course_video cv ON wl.video_id = cv.video_id
  1392. LEFT JOIN fs_user_course_period cp ON wl.period_id = cp.period_id AND cp.del_flag = 0
  1393. LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id and camp.del_flag=0
  1394. WHERE wl.send_type = 1
  1395. and (wl.user_id, wl.company_user_id) IN
  1396. <foreach collection="userConditions" item="condition" open="(" close=")" separator=",">
  1397. (#{condition.userId}, #{condition.companyUserId})
  1398. </foreach>
  1399. <if test="watchParam.trainingCampId != null">
  1400. AND camp.training_camp_id = #{watchParam.trainingCampId}
  1401. </if>
  1402. <if test="watchParam.periodId != null">
  1403. AND cp.period_id = #{watchParam.periodId}
  1404. </if>
  1405. <if test="watchParam.sTime != null and watchParam.eTime != null">
  1406. AND wl.create_time BETWEEN #{watchParam.sTime} AND #{watchParam.eTime}
  1407. </if>
  1408. GROUP BY
  1409. wl.user_id,
  1410. wl.company_user_id,
  1411. camp.training_camp_name,
  1412. cp.period_name,
  1413. cv.title,
  1414. wl.log_type,
  1415. wl.duration,
  1416. wl.create_time,
  1417. wl.finish_time
  1418. </select>
  1419. <select id="selectRedPacketStats" resultType="com.fs.his.vo.WatchLogReportVO">
  1420. SELECT
  1421. rp.watch_log_id as logId,
  1422. SUM(rp.amount) AS redPacketAmount,
  1423. COUNT( rp.log_id) AS redPacketCount
  1424. FROM fs_course_red_packet_log rp
  1425. WHERE rp.watch_log_id IN
  1426. <foreach collection="logIds" item="logId" open="(" separator="," close=")">
  1427. #{logId}
  1428. </foreach>
  1429. GROUP BY rp.watch_log_id
  1430. </select>
  1431. <select id="selectRedPacketStatsByCompanyUserIds" resultType="com.fs.his.vo.WatchLogReportVO">
  1432. SELECT
  1433. w.company_user_id AS companyUserId,
  1434. SUM(rp.amount) AS redPacketAmount,
  1435. COUNT(rp.log_id) AS redPacketCount
  1436. FROM fs_course_red_packet_log rp
  1437. INNER JOIN fs_course_watch_log w ON rp.watch_log_id = w.log_id
  1438. WHERE w.company_user_id IN
  1439. <foreach collection="companyUserIds" item="companyUserId" open="(" separator="," close=")">
  1440. #{companyUserId}
  1441. </foreach>
  1442. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1443. AND w.create_time &gt;= #{startDate} AND w.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1444. </if>
  1445. <if test="periodId != null and periodId != ''">
  1446. AND w.period_id = #{periodId}
  1447. </if>
  1448. <if test="trainingCampId != null and trainingCampId != ''">
  1449. AND w.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  1450. </if>
  1451. GROUP BY w.company_user_id
  1452. </select>
  1453. <select id="selectRedPacketStatsByDeptIds" resultType="com.fs.his.vo.WatchLogReportVO">
  1454. SELECT
  1455. cu.dept_id AS deptId,
  1456. SUM(rp.amount) AS redPacketAmount,
  1457. COUNT(rp.log_id) AS redPacketCount
  1458. FROM fs_course_red_packet_log rp
  1459. INNER JOIN fs_course_watch_log w ON rp.watch_log_id = w.log_id
  1460. INNER JOIN company_user cu ON w.company_user_id = cu.user_id
  1461. WHERE cu.dept_id IN
  1462. <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
  1463. #{deptId}
  1464. </foreach>
  1465. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1466. AND w.create_time &gt;= #{startDate} AND w.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1467. </if>
  1468. <if test="periodId != null and periodId != ''">
  1469. AND w.period_id = #{periodId}
  1470. </if>
  1471. <if test="trainingCampId != null and trainingCampId != ''">
  1472. AND w.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  1473. </if>
  1474. GROUP BY cu.dept_id
  1475. </select>
  1476. <select id="selectOrderStats" resultType="com.fs.his.vo.WatchLogReportVO">
  1477. SELECT
  1478. user_id AS userId,
  1479. COUNT(DISTINCT CASE WHEN status = 3 THEN order_id END) AS historyOrderCount
  1480. FROM fs_package_order
  1481. WHERE user_id IN
  1482. <foreach collection="userIds" item="userId" open="(" separator="," close=")">
  1483. #{userId}
  1484. </foreach>
  1485. <!--下单时间-->
  1486. <if test="watchParam.orderSTime != null and watchParam.orderETime != null">
  1487. AND DATE(create_time) BETWEEN #{watchParam.orderSTime} AND #{watchParam.orderETime}
  1488. </if>
  1489. GROUP BY user_id
  1490. </select>
  1491. <select id="selectAnswerStats" resultType="com.fs.his.vo.WatchLogReportVO">
  1492. SELECT
  1493. l.watch_log_id AS logId,
  1494. CASE WHEN l.log_id IS NOT NULL THEN '已答题' ELSE '未答题' END AS answerStatus,
  1495. (
  1496. SELECT COUNT(1)
  1497. FROM fs_course_watch_log wl
  1498. WHERE wl.log_id IN
  1499. <foreach collection="logIds" item="logId" open="(" separator="," close=")">
  1500. #{logId}
  1501. </foreach>
  1502. AND wl.log_id NOT IN (
  1503. SELECT watch_log_id
  1504. FROM fs_course_answer_logs
  1505. WHERE watch_log_id IS NOT NULL
  1506. )) AS notAnsweredCount
  1507. FROM fs_course_answer_logs l
  1508. WHERE l.watch_log_id IN
  1509. <foreach collection="logIds" item="logId" open="(" separator="," close=")">
  1510. #{logId}
  1511. </foreach>
  1512. GROUP BY l.watch_log_id
  1513. </select>
  1514. <select id="selectCompanyBaseInfo" resultType="com.fs.his.vo.FsCourseReportVO">
  1515. SELECT
  1516. c.company_id AS companyId,
  1517. c.company_name AS companyName
  1518. FROM company c
  1519. <where>
  1520. <if test="companyId != null and companyId != ''">
  1521. AND c.company_id = #{companyId}
  1522. </if>
  1523. </where>
  1524. GROUP BY c.company_id, c.company_name
  1525. ORDER BY c.create_time DESC
  1526. </select>
  1527. <select id="selectWatchStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
  1528. SELECT
  1529. <choose>
  1530. <!-- 公司维度查询 -->
  1531. <when test="dimension == 'company'">
  1532. company_id AS companyId,
  1533. </when>
  1534. <!-- 营期维度查询 -->
  1535. <when test="dimension == 'camp'">
  1536. period_id AS periodId,
  1537. company_id AS companyId,
  1538. </when>
  1539. </choose>
  1540. COUNT(DISTINCT CASE WHEN log_type = 3 THEN user_id END) AS pendingCount,
  1541. COUNT(DISTINCT CASE WHEN log_type != 3 THEN user_id END) AS watchingCount,
  1542. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS finishedCount,
  1543. COUNT(DISTINCT CASE WHEN log_type = 4 THEN user_id END) AS interruptedCount,
  1544. COUNT(DISTINCT user_id) AS accessCount
  1545. FROM fs_course_watch_log
  1546. <where>
  1547. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1548. AND create_time &gt;= #{startDate} AND create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1549. </if>
  1550. <!-- 看课方式筛选 -->
  1551. <if test="watchType != null and watchType != ''">
  1552. AND watch_type = #{watchType}
  1553. </if>
  1554. <choose>
  1555. <!-- 公司维度筛选 -->
  1556. <when test="dimension == 'company'">
  1557. <if test="companyIds != null and companyIds.size() > 0">
  1558. AND company_id IN
  1559. <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
  1560. #{companyId}
  1561. </foreach>
  1562. </if>
  1563. </when>
  1564. <!-- 营期维度筛选 -->
  1565. <when test="dimension == 'camp'">
  1566. <if test="periodIds != null and periodIds.size() > 0">
  1567. AND period_id IN
  1568. <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
  1569. #{periodId}
  1570. </foreach>
  1571. </if>
  1572. <if test="companyIds != null and companyIds.size() > 0">
  1573. AND company_id IN
  1574. <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
  1575. #{companyId}
  1576. </foreach>
  1577. </if>
  1578. </when>
  1579. </choose>
  1580. </where>
  1581. <choose>
  1582. <when test="dimension == 'company'">
  1583. GROUP BY company_id
  1584. </when>
  1585. <when test="dimension == 'camp'">
  1586. GROUP BY period_id,company_id
  1587. </when>
  1588. </choose>
  1589. </select>
  1590. <select id="selectAnswerStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
  1591. SELECT
  1592. <choose>
  1593. <!-- 公司维度查询 -->
  1594. <when test="dimension == 'company'">
  1595. w.company_id AS companyId,
  1596. </when>
  1597. <!-- 营期维度查询 -->
  1598. <when test="dimension == 'camp'">
  1599. w.period_id AS periodId,
  1600. w.company_id AS companyId,
  1601. </when>
  1602. </choose>
  1603. COUNT(DISTINCT a.user_id) AS answerUserCount
  1604. FROM fs_course_answer_logs a
  1605. INNER JOIN fs_course_watch_log w ON a.watch_log_id = w.log_id
  1606. <where>
  1607. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1608. AND w.create_time &gt;= #{startDate} AND w.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1609. </if>
  1610. <!-- 看课方式筛选 -->
  1611. <if test="watchType != null and watchType != ''">
  1612. AND w.watch_type = #{watchType}
  1613. </if>
  1614. <choose>
  1615. <!-- 公司维度筛选 -->
  1616. <when test="dimension == 'company'">
  1617. <if test="companyIds != null and companyIds.size() > 0">
  1618. AND w.company_id IN
  1619. <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
  1620. #{companyId}
  1621. </foreach>
  1622. </if>
  1623. </when>
  1624. <!-- 营期维度筛选 -->
  1625. <when test="dimension == 'camp'">
  1626. <if test="periodIds != null and periodIds.size() > 0">
  1627. AND w.period_id IN
  1628. <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
  1629. #{periodId}
  1630. </foreach>
  1631. </if>
  1632. <if test="companyIds != null and companyIds.size() > 0">
  1633. AND w.company_id IN
  1634. <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
  1635. #{companyId}
  1636. </foreach>
  1637. </if>
  1638. </when>
  1639. </choose>
  1640. </where>
  1641. <choose>
  1642. <when test="dimension == 'company'">
  1643. GROUP BY w.company_id
  1644. </when>
  1645. <when test="dimension == 'camp'">
  1646. GROUP BY w.period_id,w.company_id
  1647. </when>
  1648. </choose>
  1649. </select>
  1650. <select id="selectRedPacketStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
  1651. SELECT
  1652. <choose>
  1653. <!-- 公司维度查询 -->
  1654. <when test="dimension == 'company'">
  1655. w.company_id AS companyId,
  1656. </when>
  1657. <!-- 营期维度查询 -->
  1658. <when test="dimension == 'camp'">
  1659. w.period_id AS periodId,
  1660. w.company_id AS companyId,
  1661. </when>
  1662. </choose>
  1663. COUNT(DISTINCT rpl.user_id) AS packetUserCount,
  1664. COALESCE(SUM(rpl.amount), 0) AS packetAmount
  1665. FROM fs_course_red_packet_log rpl
  1666. INNER JOIN fs_course_watch_log w ON rpl.watch_log_id = w.log_id
  1667. <where>
  1668. rpl.status=1
  1669. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1670. AND w.create_time &gt;= #{startDate} AND w.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1671. </if>
  1672. <!-- 看课方式筛选 -->
  1673. <if test="watchType != null and watchType != ''">
  1674. AND w.watch_type = #{watchType}
  1675. </if>
  1676. <choose>
  1677. <!-- 公司维度筛选 -->
  1678. <when test="dimension == 'company'">
  1679. <if test="companyIds != null and companyIds.size() > 0">
  1680. AND w.company_id IN
  1681. <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
  1682. #{companyId}
  1683. </foreach>
  1684. </if>
  1685. </when>
  1686. <!-- 营期维度筛选 -->
  1687. <when test="dimension == 'camp'">
  1688. <if test="periodIds != null and periodIds.size() > 0">
  1689. AND w.period_id IN
  1690. <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
  1691. #{periodId}
  1692. </foreach>
  1693. </if>
  1694. <if test="companyIds != null and companyIds.size() > 0">
  1695. AND w.company_id IN
  1696. <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
  1697. #{companyId}
  1698. </foreach>
  1699. </if>
  1700. </when>
  1701. </choose>
  1702. </where>
  1703. <choose>
  1704. <when test="dimension == 'company'">
  1705. GROUP BY w.company_id
  1706. </when>
  1707. <when test="dimension == 'camp'">
  1708. GROUP BY w.period_id,w.company_id
  1709. </when>
  1710. </choose>
  1711. </select>
  1712. <select id="selectCampPeriodInfo" resultType="com.fs.his.vo.FsCourseReportVO">
  1713. SELECT
  1714. p.period_id AS periodId,
  1715. p.period_name AS periodName,
  1716. c.training_camp_name AS trainingCampName
  1717. FROM fs_user_course_period p
  1718. LEFT JOIN fs_user_course_training_camp c ON p.training_camp_id = c.training_camp_id
  1719. WHERE p.period_id IN
  1720. <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
  1721. #{periodId}
  1722. </foreach>
  1723. </select>
  1724. <select id="selectCampPeriodByPeriod" resultType="com.fs.his.vo.WatchLogReportVO">
  1725. SELECT
  1726. cp.period_id periodId,
  1727. cp.period_name periodName,
  1728. camp.training_camp_name
  1729. FROM
  1730. fs_user_course_period cp
  1731. LEFT JOIN fs_user_course_training_camp camp ON camp.training_camp_id = cp.training_camp_id
  1732. WHERE cp.period_id in
  1733. <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
  1734. #{periodId}
  1735. </foreach>
  1736. </select>
  1737. <select id="getSalesMemberStats" resultType="com.fs.his.vo.WatchLogReportVO">
  1738. SELECT
  1739. cu.user_id companyUserId,
  1740. cu.nick_name salesName,
  1741. COUNT(DISTINCT u.user_id) AS userCount,
  1742. COUNT(DISTINCT CASE WHEN u.status = 1 THEN u.user_id END) AS onlineUserCount
  1743. FROM fs_user u
  1744. LEFT JOIN fs_user_company_user cuu ON u.user_id = cuu.user_id
  1745. LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
  1746. <where>
  1747. (u.status = 1 OR cu.status = 1)
  1748. <if test="salesIds != null and salesIds.size() > 0">
  1749. AND cu.user_id IN
  1750. <foreach collection="salesIds" item="id" open="(" separator="," close=")">
  1751. #{id}
  1752. </foreach>
  1753. </if>
  1754. </where>
  1755. GROUP BY cu.user_id
  1756. </select>
  1757. <select id="getSalesDeptCompanyInfo" resultType="com.fs.his.vo.WatchLogReportVO">
  1758. SELECT
  1759. cu.user_id AS companyUserId,
  1760. d.dept_name AS salesDept,
  1761. c.company_name AS salesCompany,
  1762. (SELECT COUNT(*)
  1763. FROM company_user cu2
  1764. WHERE cu2.dept_id = cu.dept_id
  1765. AND cu2.del_flag = '0'
  1766. AND cu2.status = '0') AS salesCount
  1767. FROM company_user cu
  1768. LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
  1769. LEFT JOIN company c ON d.company_id = c.company_id
  1770. WHERE cu.user_id IN
  1771. <foreach collection="salesIds" item="salesId" open="(" separator="," close=")">
  1772. #{salesId}
  1773. </foreach>
  1774. <!--部门-->
  1775. <if test="watchParam.deptId != null and watchParam.deptId != ''">
  1776. AND d.dept_id = #{watchParam.deptId}
  1777. </if>
  1778. AND cu.del_flag = '0'
  1779. </select>
  1780. <select id="selectCompanyBaseDataOptimized" resultType="com.fs.his.vo.WatchLogReportVO">
  1781. SELECT
  1782. d.dept_id AS deptId,
  1783. d.dept_name AS salesDept,
  1784. c.company_name AS salesCompany,
  1785. COUNT(DISTINCT cu.user_id) AS salesCount,
  1786. COUNT(DISTINCT u.user_id) AS userCount,
  1787. COUNT( DISTINCT CASE WHEN u.STATUS = 1 THEN u.user_id END ) AS onlineUserCount
  1788. FROM fs_course_watch_log log
  1789. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1790. LEFT JOIN fs_user u ON log.user_id = u.user_id
  1791. LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
  1792. LEFT JOIN company c ON d.company_id = c.company_id
  1793. WHERE log.send_type = 1 and log.watch_type = 2
  1794. <if test="sTime != null and eTime != null">
  1795. AND log.create_time &gt;= #{sTime} AND log.create_time &lt; DATE_ADD(#{eTime}, INTERVAL 1 DAY)
  1796. </if>
  1797. <!-- 销售公司 -->
  1798. <if test="companyId != null and companyId != ''">
  1799. AND c.company_id = #{companyId}
  1800. </if>
  1801. <!--部门 -->
  1802. <if test="deptId != null and deptId != ''">
  1803. AND d.dept_id = #{deptId}
  1804. </if>
  1805. <!-- 训练营 -->
  1806. <if test="trainingCampId != null and trainingCampId != ''">
  1807. AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  1808. </if>
  1809. <!-- 营期 -->
  1810. <if test="periodId != null and periodId != ''">
  1811. AND log.period_id = #{periodId}
  1812. </if>
  1813. <!-- 会员id -->
  1814. <if test="userId != null and userId != ''">
  1815. AND log.user_id = #{userId}
  1816. </if>
  1817. <!-- 会员手机号 -->
  1818. <if test="userPhone != null and userPhone != ''">
  1819. AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
  1820. </if>
  1821. <if test="project != null and project != ''">
  1822. AND log.project = #{project}
  1823. </if>
  1824. <!-- 会员昵称 -->
  1825. <if test="nickName != null and nickName != ''">
  1826. AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
  1827. </if>
  1828. GROUP BY d.dept_id
  1829. </select>
  1830. <!-- 公司维度合并查询(基础数据+统计数据) -->
  1831. <select id="selectCompanyDeptStatsMerged" resultType="com.fs.his.vo.WatchLogReportVO">
  1832. SELECT
  1833. d.dept_id AS deptId,
  1834. d.dept_name AS salesDept,
  1835. c.company_name AS salesCompany,
  1836. COUNT(DISTINCT cu.user_id) AS salesCount,
  1837. COUNT(DISTINCT u.user_id) AS userCount,
  1838. COUNT(DISTINCT CASE WHEN u.STATUS = 1 THEN u.user_id END) AS onlineUserCount,
  1839. COUNT(DISTINCT log.log_id) AS totalLogCount,
  1840. COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
  1841. COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
  1842. COUNT(DISTINCT log.user_id) - COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.user_id END) AS notWatchedCount,
  1843. COUNT(DISTINCT log.log_id) - COUNT(DISTINCT a.watch_log_id) AS notAnsweredCount
  1844. FROM fs_course_watch_log log
  1845. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1846. LEFT JOIN fs_user u ON log.user_id = u.user_id
  1847. LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
  1848. LEFT JOIN company c ON d.company_id = c.company_id
  1849. LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
  1850. WHERE log.send_type = 1 AND log.watch_type = 2
  1851. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  1852. AND log.create_time &gt;= #{startDate} AND log.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  1853. </if>
  1854. <if test="companyId != null and companyId != ''">
  1855. AND c.company_id = #{companyId}
  1856. </if>
  1857. <if test="deptId != null and deptId != ''">
  1858. AND d.dept_id = #{deptId}
  1859. </if>
  1860. <if test="trainingCampId != null and trainingCampId != ''">
  1861. AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  1862. </if>
  1863. <if test="periodId != null and periodId != ''">
  1864. AND log.period_id = #{periodId}
  1865. </if>
  1866. <if test="userId != null and userId != ''">
  1867. AND log.user_id = #{userId}
  1868. </if>
  1869. <if test="userPhone != null and userPhone != ''">
  1870. AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
  1871. </if>
  1872. <if test="project != null and project != ''">
  1873. AND log.project = #{project}
  1874. </if>
  1875. <if test="nickName != null and nickName != ''">
  1876. AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
  1877. </if>
  1878. GROUP BY d.dept_id
  1879. </select>
  1880. <select id="selectAllDeptIds" resultType="java.lang.Long">
  1881. SELECT DISTINCT d.dept_id
  1882. FROM fs_course_watch_log log
  1883. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1884. LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
  1885. LEFT JOIN company c ON d.company_id = c.company_id
  1886. LEFT JOIN fs_user u ON log.user_id = u.user_id
  1887. WHERE log.send_type = 1
  1888. <if test="sTime != null and eTime != null">
  1889. AND DATE(log.create_time) BETWEEN #{sTime} AND #{eTime}
  1890. </if>
  1891. <!-- 销售公司 -->
  1892. <if test="companyId != null and companyId != ''">
  1893. AND c.company_id = #{companyId}
  1894. </if>
  1895. <!--部门 -->
  1896. <if test="deptId != null and deptId != ''">
  1897. AND d.dept_id = #{deptId}
  1898. </if>
  1899. <!-- 训练营 -->
  1900. <if test="trainingCampId != null and trainingCampId != ''">
  1901. AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  1902. </if>
  1903. <!-- 营期 -->
  1904. <if test="periodId != null and periodId != ''">
  1905. AND log.period_id = #{periodId}
  1906. </if>
  1907. <!-- 会员id -->
  1908. <if test="userId != null and userId != ''">
  1909. AND log.user_id = #{userId}
  1910. </if>
  1911. <!-- 会员手机号 -->
  1912. <if test="userPhone != null and userPhone != ''">
  1913. AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
  1914. </if>
  1915. <if test="project != null and project != ''">
  1916. AND log.project = #{project}
  1917. </if>
  1918. <!-- 会员昵称 -->
  1919. <if test="nickName != null and nickName != ''">
  1920. AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
  1921. </if>
  1922. </select>
  1923. <select id="selectWatchStatsByDeptBatch" resultType="com.fs.his.vo.WatchLogReportVO">
  1924. SELECT
  1925. d.dept_id AS deptId,
  1926. log.user_id AS userId,
  1927. log.log_id AS logId,
  1928. COUNT(DISTINCT log.log_id) AS totalLogCount,
  1929. COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
  1930. COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
  1931. COUNT(DISTINCT log.user_id) - COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.user_id END) AS notWatchedCount
  1932. FROM fs_course_watch_log log
  1933. <if test="orderSTime != null and orderETime != null">
  1934. LEFT JOIN fs_package_order po ON po.user_id = log.user_id
  1935. </if>
  1936. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1937. LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
  1938. WHERE log.send_type = 1 and log.watch_type = 2
  1939. AND d.dept_id IN
  1940. <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
  1941. #{deptId}
  1942. </foreach>
  1943. <if test="sTime != null and eTime != null">
  1944. AND log.create_time &gt;= #{sTime} AND log.create_time &lt; DATE_ADD(#{eTime}, INTERVAL 1 DAY)
  1945. </if>
  1946. <if test="orderSTime != null and orderETime != null">
  1947. AND DATE(po.create_time) BETWEEN #{orderSTime} AND #{orderETime}
  1948. </if>
  1949. <!-- 销售公司 -->
  1950. <if test="companyId != null and companyId != ''">
  1951. AND cu.company_id = #{companyId}
  1952. </if>
  1953. <!-- 训练营 -->
  1954. <if test="trainingCampId != null and trainingCampId != ''">
  1955. AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  1956. </if>
  1957. <!-- 营期 -->
  1958. <if test="periodId != null and periodId != ''">
  1959. AND log.period_id = #{periodId}
  1960. </if>
  1961. <!-- 会员id -->
  1962. <if test="userId != null and userId != ''">
  1963. AND log.user_id = #{userId}
  1964. </if>
  1965. GROUP BY d.dept_id
  1966. </select>
  1967. <select id="selectCompanyBaseDataWithIds" resultType="com.fs.his.vo.WatchLogReportVO">
  1968. SELECT
  1969. log.user_id userId,
  1970. log.period_id periodId,
  1971. log.log_id logId,
  1972. d.dept_id AS deptId,
  1973. d.dept_name AS salesDept,
  1974. c.company_name AS salesCompany
  1975. FROM fs_course_watch_log log
  1976. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  1977. LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
  1978. LEFT JOIN company c ON d.company_id = c.company_id
  1979. WHERE log.send_type = 1
  1980. <if test="sTime != null and eTime != null">
  1981. AND DATE(log.create_time) BETWEEN #{sTime} AND #{eTime}
  1982. </if>
  1983. <!-- 销售公司 -->
  1984. <if test="companyId != null and companyId != ''">
  1985. AND c.company_id = #{companyId}
  1986. </if>
  1987. <!--部门 -->
  1988. <if test="deptId != null and deptId != ''">
  1989. AND d.dept_id = #{deptId}
  1990. </if>
  1991. <!-- 训练营 -->
  1992. <if test="trainingCampId != null and trainingCampId != ''">
  1993. AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  1994. </if>
  1995. <!-- 营期 -->
  1996. <if test="periodId != null and periodId != ''">
  1997. AND log.period_id = #{periodId}
  1998. </if>
  1999. <!-- 会员id -->
  2000. <if test="userId != null and userId != ''">
  2001. AND log.user_id = #{userId}
  2002. </if>
  2003. <!-- 会员手机号 -->
  2004. <if test="userPhone != null and userPhone != ''">
  2005. AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
  2006. </if>
  2007. <if test="project != null and project != ''">
  2008. AND log.project = #{project}
  2009. </if>
  2010. <!-- 会员昵称 -->
  2011. <if test="nickName != null and nickName != ''">
  2012. AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
  2013. </if>
  2014. GROUP BY
  2015. d.dept_id,
  2016. d.dept_name,
  2017. c.company_name
  2018. </select>
  2019. <select id="selectPeriodInfo" resultType="com.fs.his.vo.FsCourseReportVO">
  2020. SELECT
  2021. period.period_id periodId,
  2022. period.period_name periodName,
  2023. camp.training_camp_name trainingCampName,
  2024. c.company_name companyName,
  2025. c.company_id companyId
  2026. FROM
  2027. fs_user_course_period period
  2028. LEFT JOIN fs_user_course_training_camp camp
  2029. ON camp.training_camp_id = period.training_camp_id
  2030. LEFT JOIN company c
  2031. ON FIND_IN_SET(c.company_id, period.company_id) > 0
  2032. <where>
  2033. <!-- 只有当传入公司ID参数时才筛选公司 -->
  2034. <if test="companyId != null">
  2035. c.company_id = #{companyId}
  2036. </if>
  2037. <!-- 训练营 -->
  2038. <if test="trainingCampId != null and trainingCampId != ''">
  2039. AND period.training_camp_id= #{trainingCampId}
  2040. </if>
  2041. <!-- 营期 -->
  2042. <if test="periodId != null and periodId != ''">
  2043. AND period.period_id = #{periodId}
  2044. </if>
  2045. </where>
  2046. ORDER BY period.create_time DESC
  2047. </select>
  2048. <select id="selectActiveUserIds" resultType="java.lang.Long">
  2049. SELECT DISTINCT user_id
  2050. FROM fs_course_watch_log
  2051. WHERE user_id IN
  2052. <foreach item="userId" collection="userIds" open="(" separator="," close=")">
  2053. #{userId}
  2054. </foreach>
  2055. and send_type = 1
  2056. and watch_type = 1
  2057. </select>
  2058. <select id="selectAppWatchStatistics" resultType="com.fs.his.vo.AppCourseReportVO">
  2059. SELECT
  2060. log_id logId,
  2061. company_id AS companyId,
  2062. COUNT(CASE WHEN log_type = 3 THEN log_id END) AS pendingCount,
  2063. COUNT(CASE WHEN log_type = 1 THEN log_id END) AS watchingCount,
  2064. COUNT(CASE WHEN log_type = 2 THEN log_id END) AS finishedCount,
  2065. count(log_id) as accessCount
  2066. FROM fs_course_watch_log
  2067. <where>
  2068. watch_type =1 and send_type = 1
  2069. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  2070. AND create_time &gt;= #{startDate} AND create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  2071. </if>
  2072. <if test="companyIds != null and companyIds.size() > 0">
  2073. AND company_id IN
  2074. <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
  2075. #{companyId}
  2076. </foreach>
  2077. </if>
  2078. </where>
  2079. GROUP BY company_id
  2080. </select>
  2081. <select id="selectAppAnswerStatistics" resultType="com.fs.his.vo.AppCourseReportVO">
  2082. SELECT
  2083. l.company_id AS companyId,
  2084. COUNT( l.log_id) AS answerUserCount
  2085. FROM fs_course_answer_logs l
  2086. LEFT JOIN fs_course_watch_log a on l.watch_log_id=a.log_id
  2087. WHERE l.company_id IN
  2088. <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
  2089. #{companyId}
  2090. </foreach>
  2091. and a.watch_type=1 and a.send_type=1
  2092. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  2093. AND l.create_time &gt;= #{startDate} AND l.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  2094. </if>
  2095. GROUP BY l.company_id
  2096. </select>
  2097. <select id="selectAppRedPacketStatistics" resultType="com.fs.his.vo.AppCourseReportVO">
  2098. SELECT
  2099. rpl.company_id AS companyId,
  2100. COUNT( rpl.log_id) AS packetUserCount,
  2101. COALESCE(SUM(rpl.amount), 0) AS packetAmount
  2102. FROM fs_course_red_packet_log rpl
  2103. LEFT JOIN fs_course_watch_log a on rpl.watch_log_id=a.log_id
  2104. WHERE rpl.company_id IN
  2105. <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
  2106. #{companyId}
  2107. </foreach>
  2108. and a.watch_type=1 and a.send_type=1
  2109. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  2110. AND rpl.create_time &gt;= #{startDate} AND rpl.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  2111. </if>
  2112. GROUP BY rpl.company_id
  2113. </select>
  2114. <select id="selectAppUserBaseData" resultType="com.fs.his.vo.AppWatchLogReportVO">
  2115. SELECT
  2116. log.user_id userId,
  2117. u.nick_name AS nickName,
  2118. u.app_create_time loginChannel,
  2119. cu.nick_name AS salesName,
  2120. c.company_name AS salesCompany,
  2121. cd.dept_name AS salesDept,
  2122. log.period_id periodId,
  2123. log.video_id videoId,
  2124. log.log_id logId,
  2125. log.create_time courseTime,
  2126. log.finish_time finishTime,
  2127. log.duration privateWatchDuration,
  2128. log.log_type privateWatchStatus,
  2129. cv.title AS videoTitle
  2130. FROM
  2131. fs_course_watch_log log
  2132. LEFT JOIN fs_user u ON u.user_id = log.user_id
  2133. LEFT JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
  2134. LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
  2135. LEFT JOIN company c ON log.company_id = c.company_id
  2136. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  2137. LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
  2138. WHERE log.send_type = 1
  2139. AND log.watch_type = 1
  2140. <include refid="commonConditions"/>
  2141. group by log.user_id
  2142. ORDER BY u.register_date DESC
  2143. </select>
  2144. <sql id="commonConditions">
  2145. <!-- 销售公司 -->
  2146. <if test="companyId != null and companyId != ''">
  2147. AND c.company_id = #{companyId}
  2148. </if>
  2149. <!-- 销售部门 -->
  2150. <if test="deptId != null and deptId != ''">
  2151. AND cd.dept_id = #{deptId}
  2152. </if>
  2153. <!-- 所属销售 -->
  2154. <if test="salesId != null and salesId != ''">
  2155. AND cu.user_id = #{salesId}
  2156. </if>
  2157. <!-- 项目 -->
  2158. <if test="project != null and project != ''">
  2159. AND log.project = #{project}
  2160. </if>
  2161. <!-- 时间范围 -->
  2162. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  2163. AND log.create_time &gt;= #{startDate} AND log.create_time &lt; DATE_ADD(#{endDate}, INTERVAL 1 DAY)
  2164. </if>
  2165. <!-- 训练营 -->
  2166. <if test="trainingCampId != null and trainingCampId != ''">
  2167. AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
  2168. </if>
  2169. <!-- 营期 -->
  2170. <if test="periodId != null and periodId != ''">
  2171. AND log.period_id = #{periodId}
  2172. </if>
  2173. <!-- 会员ID -->
  2174. <if test="userId != null and userId != ''">
  2175. AND u.user_id = #{userId}
  2176. </if>
  2177. <!-- 会员手机号 -->
  2178. <if test="userPhone != null and userPhone != ''">
  2179. AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
  2180. </if>
  2181. <!-- 会员昵称 -->
  2182. <if test="nickName != null and nickName != ''">
  2183. AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
  2184. </if>
  2185. </sql>
  2186. <!-- 销售维度APP会员数统计(直接查fs_user表) -->
  2187. <select id="selectAppSalesUserStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  2188. SELECT
  2189. cu.user_id AS salesId,
  2190. COUNT(DISTINCT CASE WHEN (u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL THEN u.user_id END) AS appUserCount,
  2191. <choose>
  2192. <when test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  2193. COUNT(DISTINCT CASE WHEN ((u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL) AND u.app_create_time &gt;= #{startDate} AND u.app_create_time &lt; CONCAT(#{endDate}, ' 23:59:59') THEN u.user_id END)
  2194. </when>
  2195. <otherwise>
  2196. COUNT(DISTINCT CASE WHEN (u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL THEN u.user_id END)
  2197. </otherwise>
  2198. </choose> AS newAppUserCount
  2199. FROM fs_user u
  2200. INNER JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
  2201. INNER JOIN company_user cu ON cuu.company_user_id = cu.user_id
  2202. INNER JOIN company c ON cuu.company_id = c.company_id
  2203. WHERE ((u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL)
  2204. AND u.status = 1
  2205. AND u.is_del=0
  2206. AND cuu.status IN (0, 1)
  2207. <if test="companyId != null and companyId != ''">
  2208. AND cuu.company_id = #{companyId}
  2209. </if>
  2210. <if test="deptId != null and deptId != ''">
  2211. AND cu.dept_id = #{deptId}
  2212. </if>
  2213. <if test="salesId != null and salesId != ''">
  2214. AND cu.user_id = #{salesId}
  2215. </if>
  2216. <if test="project != null and project != ''">
  2217. AND cuu.project_id = #{project}
  2218. </if>
  2219. GROUP BY cu.user_id
  2220. </select>
  2221. <!-- 销售维度基础数据+看课统计(合并查询) -->
  2222. <select id="selectAppSalesWatchStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  2223. SELECT
  2224. cu.user_id AS salesId,
  2225. cu.nick_name AS salesName,
  2226. cd.dept_name AS salesDept,
  2227. c.company_name AS salesCompany,
  2228. cd.dept_id AS deptId,
  2229. c.company_id AS companyId,
  2230. COUNT( CASE WHEN log.log_type = 2 THEN log.log_id END ) AS finishedCount,
  2231. COUNT(log.log_id)- COUNT(CASE WHEN log.log_type = 2 THEN log.log_id END )AS unfinishedCount,
  2232. COUNT( CASE WHEN log.log_type = 3 THEN log.log_id END ) AS notWatchedCount,
  2233. COUNT( a.watch_log_id ) answeredCount,
  2234. COALESCE ( SUM( rpl.amount ), 0 ) AS redPacketAmount,
  2235. COUNT( rpl.log_id) AS packetUserCount
  2236. FROM fs_course_watch_log log
  2237. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  2238. LEFT JOIN company c ON log.company_id = c.company_id
  2239. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  2240. LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
  2241. LEFT JOIN fs_course_red_packet_log rpl ON rpl.watch_log_id = log.log_id
  2242. WHERE log.send_type = 1
  2243. AND log.watch_type = 1
  2244. <include refid="commonConditions"/>
  2245. GROUP BY cu.user_id
  2246. ORDER BY cu.user_id
  2247. </select>
  2248. <!-- 销售维度订单统计 -->
  2249. <select id="selectAppSalesOrderStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  2250. SELECT
  2251. cu.user_id AS salesId,
  2252. log.period_id AS periodId,
  2253. log.video_id AS videoId,
  2254. COUNT(DISTINCT CASE WHEN po.status = 3 THEN po.order_id END) AS historyOrderCount
  2255. FROM fs_course_watch_log log
  2256. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  2257. LEFT JOIN company c ON log.company_id = c.company_id
  2258. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  2259. LEFT JOIN fs_package_order po ON po.user_id = log.user_id
  2260. WHERE log.send_type = 1
  2261. AND log.watch_type = 1
  2262. <include refid="commonConditions"/>
  2263. GROUP BY cu.user_id, log.period_id, log.video_id
  2264. </select>
  2265. <!-- 销售维度营期信息 -->
  2266. <select id="selectAppSalesCampPeriod" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  2267. SELECT
  2268. cp.period_id periodId,
  2269. cp.period_name periodName,
  2270. camp.training_camp_name trainingCampName
  2271. FROM
  2272. fs_user_course_period cp
  2273. LEFT JOIN fs_user_course_training_camp camp ON camp.training_camp_id = cp.training_camp_id
  2274. WHERE cp.period_id in
  2275. <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
  2276. #{periodId}
  2277. </foreach>
  2278. </select>
  2279. <!-- 销售部门维度APP会员数统计 -->
  2280. <select id="selectAppDeptUserStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  2281. SELECT
  2282. cd.dept_id AS deptId,
  2283. COUNT(DISTINCT CASE WHEN (u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL THEN u.user_id END) AS appUserCount,
  2284. <choose>
  2285. <when test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  2286. COUNT(DISTINCT CASE WHEN ((u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL) AND u.app_create_time &gt;= #{startDate} AND u.app_create_time &lt; CONCAT(#{endDate}, ' 23:59:59') THEN u.user_id END)
  2287. </when>
  2288. <otherwise>
  2289. COUNT(DISTINCT CASE WHEN (u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL THEN u.user_id END)
  2290. </otherwise>
  2291. </choose> AS newAppUserCount,
  2292. COUNT(DISTINCT cu.user_id) AS salesCount
  2293. FROM fs_user u
  2294. INNER JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
  2295. INNER JOIN company_user cu ON cuu.company_user_id = cu.user_id
  2296. INNER JOIN company c ON cuu.company_id = c.company_id
  2297. INNER JOIN company_dept cd ON cu.dept_id = cd.dept_id
  2298. WHERE ((u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL)
  2299. AND u.status = 1
  2300. and u.is_del=0
  2301. AND u.status = 1
  2302. AND cuu.status IN (0, 1)
  2303. <if test="companyId != null and companyId != ''">
  2304. AND cuu.company_id = #{companyId}
  2305. </if>
  2306. <if test="deptId != null and deptId != ''">
  2307. AND cu.dept_id = #{deptId}
  2308. </if>
  2309. <if test="salesId != null and salesId != ''">
  2310. AND cu.user_id = #{salesId}
  2311. </if>
  2312. <if test="project != null and project != ''">
  2313. AND cuu.project_id = #{project}
  2314. </if>
  2315. GROUP BY cd.dept_id
  2316. </select>
  2317. <!-- 销售部门维度基础数据+看课统计(合并查询) -->
  2318. <select id="selectAppDeptWatchStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  2319. SELECT
  2320. cd.dept_id AS deptId,
  2321. cd.dept_name AS salesDept,
  2322. c.company_name AS salesCompany,
  2323. c.company_id AS companyId,
  2324. COUNT( CASE WHEN log.log_type = 2 THEN log.log_id END ) AS finishedCount,
  2325. COUNT(log.log_id)- COUNT(CASE WHEN log.log_type = 2 THEN log.log_id END )AS unfinishedCount,
  2326. COUNT( CASE WHEN log.log_type = 3 THEN log.log_id END ) AS notWatchedCount,
  2327. COUNT( a.watch_log_id ) anscount,
  2328. COALESCE ( SUM( rpl.amount ), 0 ) AS redPacketAmount,
  2329. COUNT( rpl.log_id) AS packetUserCount
  2330. FROM fs_course_watch_log log
  2331. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  2332. LEFT JOIN company c ON log.company_id = c.company_id
  2333. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  2334. LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
  2335. LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
  2336. LEFT JOIN fs_course_red_packet_log rpl ON rpl.watch_log_id = log.log_id
  2337. WHERE log.send_type = 1
  2338. AND log.watch_type = 1
  2339. <include refid="commonConditions"/>
  2340. GROUP BY cd.dept_id
  2341. ORDER BY cd.dept_id
  2342. </select>
  2343. <!-- 销售部门维度订单统计 -->
  2344. <select id="selectAppDeptOrderStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
  2345. SELECT
  2346. cd.dept_id AS deptId,
  2347. log.period_id AS periodId,
  2348. log.video_id AS videoId,
  2349. COUNT(DISTINCT CASE WHEN po.status = 3 THEN po.order_id END) AS historyOrderCount
  2350. FROM fs_course_watch_log log
  2351. LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
  2352. LEFT JOIN company c ON log.company_id = c.company_id
  2353. LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
  2354. LEFT JOIN fs_package_order po ON po.user_id = log.user_id
  2355. WHERE log.send_type = 1
  2356. AND log.watch_type = 1
  2357. <include refid="commonConditions"/>
  2358. GROUP BY cd.dept_id, log.period_id, log.video_id
  2359. </select>
  2360. <!-- APP用户看课记录列表 -->
  2361. <select id="selectAppUserWatchLogList" resultType="com.fs.course.vo.AppUserWatchLogVO">
  2362. SELECT
  2363. l.log_id AS logId,
  2364. l.course_id AS courseId,
  2365. c.course_name AS courseName,
  2366. c.img_url as imgUrl,
  2367. l.video_id AS videoId,
  2368. v.title AS videoName,
  2369. l.log_type AS logType,
  2370. l.duration AS duration,
  2371. SEC_TO_TIME(l.duration) AS durationFormat,
  2372. l.create_time AS createTime,
  2373. l.finish_time AS finishTime,
  2374. l.watch_type AS watchType
  2375. FROM fs_course_watch_log l
  2376. LEFT JOIN fs_user_course c ON l.course_id = c.course_id
  2377. LEFT JOIN fs_user_course_video v ON l.video_id = v.video_id
  2378. WHERE l.user_id = #{userId} and l.project=#{projectId} and l.company_user_id=#{companyUserId} and l.watch_type=1 and l.send_type=1
  2379. <if test="dateTag != null and dateTag !='' ">
  2380. <choose>
  2381. <when test = "dateTag == '今天'">
  2382. and to_days(l.create_time) = to_days(now())
  2383. </when>
  2384. <when test = "dateTag == '昨天'">
  2385. and l.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND l.create_time &lt; CURDATE()
  2386. </when>
  2387. <when test = "dateTag == '前天'">
  2388. and l.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND l.create_time &lt; CURDATE() - INTERVAL 1 DAY
  2389. </when>
  2390. <when test = "dateTag == '近七天'">
  2391. and l.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  2392. </when>
  2393. </choose>
  2394. </if>
  2395. ORDER BY l.create_time DESC
  2396. </select>
  2397. <!-- 查询用户当日未完课的课程列表 -->
  2398. <select id="selectTodayUnfinishedCourseList" resultType="com.fs.course.vo.TodayUnfinishedCourseVO">
  2399. SELECT
  2400. l.log_id AS logId,
  2401. l.course_id AS courseId,
  2402. l.company_user_id as companyUserId,
  2403. l.company_id as companyId,
  2404. c.course_name AS courseName,
  2405. c.img_url as imgUrl,
  2406. l.video_id AS videoId,
  2407. v.title AS videoName,
  2408. l.log_type AS logType,
  2409. l.duration AS duration,
  2410. v.duration AS totalDuration,
  2411. l.create_time AS createTime,
  2412. l.watch_type AS watchType,
  2413. l.period_id AS periodId,
  2414. l.project as projectId,
  2415. p.period_name AS periodName,
  2416. pd.start_date_time AS startDateTime,
  2417. pd.id as periodDaysId,
  2418. pd.end_date_time AS endDateTime
  2419. FROM fs_course_watch_log l
  2420. LEFT JOIN fs_user_course c ON l.course_id = c.course_id
  2421. LEFT JOIN fs_user_course_video v ON l.video_id = v.video_id
  2422. LEFT JOIN fs_user_course_period_days pd ON l.video_id = pd.video_id AND l.period_id = pd.period_id and pd.del_flag=0
  2423. LEFT JOIN fs_user_course_period p ON l.period_id = p.period_id
  2424. WHERE l.user_id = #{userId}
  2425. AND l.watch_type = 1
  2426. AND l.send_type = 1
  2427. AND l.create_time &gt;= CURDATE()
  2428. AND l.create_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)
  2429. AND l.log_type &lt;&gt; 2
  2430. AND NOT EXISTS (
  2431. SELECT 1 FROM fs_course_watch_log f
  2432. WHERE f.user_id = l.user_id
  2433. AND f.video_id = l.video_id
  2434. AND f.log_type = 2
  2435. )
  2436. GROUP BY l.course_id
  2437. ORDER BY l.create_time DESC
  2438. </select>
  2439. </mapper>