FsCourseWatchLogMapper.xml 81 KB

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