FsCourseWatchLogMapper.xml 78 KB

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