| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.fs.course.mapper.FsCourseWatchLogMapper">
- <resultMap type="FsCourseWatchLog" id="FsCourseWatchLogResult">
- <result property="logId" column="log_id" />
- <result property="userId" column="user_id" />
- <result property="videoId" column="video_id" />
- <result property="logType" column="log_type" />
- <result property="createTime" column="create_time" />
- <result property="updateTime" column="update_time" />
- <result property="qwExternalContactId" column="qw_external_contact_id" />
- <result property="duration" column="duration" />
- <result property="qwUserId" column="qw_user_id" />
- <result property="companyUserId" column="company_user_id" />
- <result property="companyId" column="company_id" />
- <result property="courseId" column="course_id" />
- <result property="sendType" column="send_type" />
- <result property="rewardType" column="reward_type" />
- <result property="sopId" column="sop_id" />
- <result property="finishTime" column="finish_time" />
- <result property="sendFinishMsg" column="send_finish_msg" />
- <result property="campPeriodTime" column="camp_period_time" />
- <result property="lastHeartbeatTime" column="last_heartbeat_time" />
- <result property="project" column="project" />
- <result property="periodId" column="period_id" />
- <result property="watchType" column="watch_type" />
- </resultMap>
- <sql id="selectFsCourseWatchLogVo">
- select log_id, user_id,finish_time,send_finish_msg,sop_id,video_id,reward_type, log_type, create_time, update_time, qw_external_contact_id, duration, qw_user_id, company_user_id, company_id, course_id,camp_period_time,project,period_id,watch_type from fs_course_watch_log
- </sql>
- <select id="selectFsCourseWatchLogList" parameterType="FsCourseWatchLog" resultMap="FsCourseWatchLogResult">
- <include refid="selectFsCourseWatchLogVo"/>
- <where>
- <if test="userId != null "> and user_id = #{userId}</if>
- <if test="videoId != null "> and video_id = #{videoId}</if>
- <if test="logType != null "> and log_type = #{logType}</if>
- <if test="qwExternalContactId != null "> and qw_external_contact_id = #{qwExternalContactId}</if>
- <if test="duration != null "> and duration = #{duration}</if>
- <if test="qwUserId != null and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
- <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
- <if test="companyId != null "> and company_id = #{companyId}</if>
- <if test="courseId != null "> and course_id = #{courseId}</if>
- <if test="sendType != null "> and send_type = #{sendType}</if>
- <if test="campPeriodTime != null "> and camp_period_time = #{campPeriodTime}</if>
- <if test="project != null "> and project = #{project}</if>
- <if test="watchType != null "> and watch_type = #{watchType}</if>
- </where>
- </select>
- <select id="selectFsCourseWatchLogByLogId" parameterType="Long" resultMap="FsCourseWatchLogResult">
- <include refid="selectFsCourseWatchLogVo"/>
- where log_id = #{logId}
- </select>
- <select id="selectFsCourseWatchLogListVO" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
- 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,
- l.log_type,SEC_TO_TIME(l.duration) as duration,c.company_name,l.camp_period_time,l.finish_time,
- cu.nick_name as company_user_name ,l.send_type,l.create_time,l.update_time,l.last_heartbeat_time,
- 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,
- u.is_vip isVip,l.reward_type
- from fs_course_watch_log l
- left join fs_user_course_video v on v.video_id = l.video_id
- left join fs_user_course uc on uc.course_id = l.course_id
- left join fs_user u on u.user_id = l.user_id
- left join company_user cu on cu.user_id = l.company_user_id
- left join company c on c.company_id = l.company_id
- LEFT JOIN qw_user qu on qu.id= l.qw_user_id
- LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
- <where>
- <if test ='maps.isVip != null and maps.isVip == 0'>
- and (l.user_id = 0 or l.user_id is null)
- </if>
- <if test ='maps.isVip != null and maps.isVip == 1'>
- and l.user_id != 0 and l.user_id is not null
- </if>
- <if test ='maps.sendType !=null'>
- and l.send_type = #{maps.sendType}
- </if>
- <if test ='maps.userId !=null'>
- and l.user_id = #{maps.userId}
- </if>
- <if test ='maps.project !=null'>
- and l.project = #{maps.project}
- </if>
- <if test ='maps.qwExternalContactId !=null'>
- and l.qw_external_contact_id = #{maps.qwExternalContactId}
- </if>
- <if test ='maps.qwUserId !=null'>
- and l.qw_user_id = #{maps.qwUserId}
- </if>
- <if test ='maps.courseId !=null'>
- and l.course_id = #{maps.courseId}
- </if>
- <if test ='maps.watchType !=null'>
- and l.watch_type = #{maps.watchType}
- </if>
- <if test ='maps.videoId !=null'>
- and l.video_id = #{maps.videoId}
- </if>
- <if test ='maps.logType !=null'>
- and l.log_type = #{maps.logType}
- </if>
- <if test ='maps.companyId !=null'>
- and l.company_id = #{maps.companyId}
- </if>
- <if test ='maps.companyUserId !=null'>
- and l.company_user_id = #{maps.companyUserId}
- </if>
- <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
- and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
- </if>
- <if test ='maps.nickName !=null and maps.nickName!=""'>
- and u.nick_name like concat('%', #{maps.nickName}, '%')
- </if>
- <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
- and qec.name like concat('%', #{maps.externalUserName}, '%')
- </if>
- <if test= 'maps.qecSTime != null '>
- and DATE(qec.create_time) >= DATE(#{maps.qecSTime})
- </if>
- <if test='maps.qecETime != null '>
- and DATE(qec.create_time) <= DATE(#{maps.qecETime})
- </if>
- <if test= 'maps.sTime != null '>
- and l.create_time >= #{maps.sTime}
- </if>
- <if test='maps.eTime != null '>
- and l.create_time <= DATE_ADD(#{maps.eTime}, INTERVAL 1 DAY)
- </if>
- <if test= 'maps.scheduleStartTime != null '>
- and l.camp_period_time >= #{maps.scheduleStartTime}
- </if>
- <if test='maps.scheduleEndTime != null '>
- and l.camp_period_time <= #{maps.scheduleEndTime}
- </if>
- <if test= 'maps.upSTime != null '>
- and l.update_time >= #{maps.upSTime}
- </if>
- <if test='maps.upETime != null '>
- and l.update_time <= #{maps.upETime}
- </if>
- <if test="maps.sopIds != null and maps.sopIds.size() > 0">
- and l.sop_id in
- <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
- #{sopId}
- </foreach>
- </if>
- <if test ='maps.project !=null'>
- and l.project = #{maps.project}
- </if>
- <if test="maps.sopId != null and maps.sopId != '' ">
- and l.sop_id = #{maps.sopId}
- </if>
- <if test="maps.periodIds != null and maps.periodIds.size() > 0">
- and l.period_id in
- <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
- #{periodId}
- </foreach>
- </if>
- <if test="maps.qwUserName != null and maps.qwUserName != '' ">
- and qu.qw_user_name = #{maps.qwUserName}
- </if>
- <if test='maps.cuDeptIdList != null and !maps.cuDeptIdList.isEmpty() and maps.userType != "00" '>
- AND cu.dept_id IN
- <foreach collection='maps.cuDeptIdList' item='item' open='(' separator=',' close=')'>
- #{item}
- </foreach>
- </if>
- </where>
- order by l.finish_time desc,l.update_time desc,l.create_time desc
- </select>
- <select id="selectFsCourseWatchLogListByParam" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
- select l.log_id,l.user_id,uc.course_name,v.title as video_name,u.nick_name as fsNickName, u.avatar as fsAvatar,
- l.log_type,SEC_TO_TIME(l.duration) as duration,c.company_name,l.camp_period_time,l.finish_time,
- cu.nick_name as company_user_name ,l.send_type,l.create_time, qu.qw_user_name,qec.name as external_user_name
- from fs_course_watch_log l
- left join fs_user_course_video v on v.video_id = l.video_id
- left join fs_user_course uc on uc.course_id = l.course_id
- left join fs_user u on u.user_id = l.user_id
- left join company_user cu on cu.user_id = l.company_user_id
- left join company c on c.company_id = l.company_id
- LEFT JOIN qw_user qu on qu.id= l.qw_user_id
- LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
- <where>
- <if test ='userId !=null'>
- and l.user_id = #{userId}
- </if>
- <if test ='qwUserId !=null'>
- and l.qw_user_id = #{qwUserId}
- </if>
- <if test ='courseId !=null'>
- and l.course_id = #{courseId}
- </if>
- <if test ='videoId !=null'>
- and l.video_id = #{videoId}
- </if>
- <if test ='logType !=null'>
- and l.log_type = #{logType}
- </if>
- <if test ='companyId !=null'>
- and l.company_id = #{companyId}
- </if>
- <if test ='companyUserId !=null'>
- and l.company_user_id = #{companyUserId}
- </if>
- <if test ='companyUserName !=null and maps.companyUserName!=""'>
- and cu.nick_name like concat('%', #{companyUserName}, '%')
- </if>
- <if test ='nickName !=null and maps.nickName!=""'>
- and u.nick_name like concat('%', #{nickName}, '%')
- </if>
- <if test= 'sTime != null '>
- and DATE(l.create_time) >= DATE(#{sTime})
- </if>
- <if test='eTime != null '>
- and DATE(l.create_time) <= DATE(#{eTime})
- </if>
- <if test= 'maps.scheduleStartTime != null '>
- and DATE(l.camp_period_time) >= DATE(#{maps.scheduleStartTime})
- </if>
- <if test='maps.scheduleEndTime != null '>
- and DATE(l.camp_period_time) <= DATE(#{maps.scheduleEndTime})
- </if>
- <if test="sopIds != null and sopIds.size() > 0">
- and l.sop_id in
- <foreach item="sopId" index="index" collection="sopIds" open="(" separator="," close=")">
- #{sopId}
- </foreach>
- </if>
- <if test="maps.watchType != null "> and l.watch_type = #{maps.watchType}</if>
- </where>
- order by l.log_id desc
- </select>
- <insert id="insertFsCourseWatchLog" parameterType="FsCourseWatchLog" useGeneratedKeys="true" keyProperty="logId">
- insert into fs_course_watch_log
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="userId != null">user_id,</if>
- <if test="videoId != null">video_id,</if>
- <if test="logType != null">log_type,</if>
- <if test="createTime != null">create_time,</if>
- <if test="updateTime != null">update_time,</if>
- <if test="qwExternalContactId != null">qw_external_contact_id,</if>
- <if test="duration != null">duration,</if>
- <if test="qwUserId != null">qw_user_id,</if>
- <if test="companyUserId != null">company_user_id,</if>
- <if test="companyId != null">company_id,</if>
- <if test="courseId != null">course_id,</if>
- <if test="sendType != null">send_type,</if>
- <if test="rewardType != null">reward_type,</if>
- <if test="sopId != null">sop_id,</if>
- <if test="finishTime != null">finish_time,</if>
- <if test="sendFinishMsg != null">send_finish_msg,</if>
- <if test="campPeriodTime != null">camp_period_time,</if>
- <if test="periodId != null">period_id,</if>
- <if test="project != null">project,</if>
- <if test="watchType != null">watch_type,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="userId != null">#{userId},</if>
- <if test="videoId != null">#{videoId},</if>
- <if test="logType != null">#{logType},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="updateTime != null">#{updateTime},</if>
- <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
- <if test="duration != null">#{duration},</if>
- <if test="qwUserId != null">#{qwUserId},</if>
- <if test="companyUserId != null">#{companyUserId},</if>
- <if test="companyId != null">#{companyId},</if>
- <if test="courseId != null">#{courseId},</if>
- <if test="sendType != null">#{sendType},</if>
- <if test="rewardType != null">#{rewardType},</if>
- <if test="sopId != null">#{sopId},</if>
- <if test="finishTime != null">#{finishTime},</if>
- <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
- <if test="campPeriodTime != null">#{campPeriodTime},</if>
- <if test="periodId != null">#{periodId},</if>
- <if test="project != null">#{project},</if>
- <if test="watchType != null">#{watchType},</if>
- </trim>
- </insert>
- <insert id="insertOrUpdateFsCourseWatchLog" parameterType="FsCourseWatchLog">
- insert into fs_course_watch_log
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="userId != null">user_id,</if>
- <if test="videoId != null">video_id,</if>
- <if test="logType != null">log_type,</if>
- <if test="createTime != null">create_time,</if>
- <if test="updateTime != null">update_time,</if>
- <if test="qwExternalContactId != null">qw_external_contact_id,</if>
- <if test="duration != null">duration,</if>
- <if test="qwUserId != null">qw_user_id,</if>
- <if test="companyUserId != null">company_user_id,</if>
- <if test="companyId != null">company_id,</if>
- <if test="courseId != null">course_id,</if>
- <if test="sendType != null">send_type,</if>
- <if test="rewardType != null">reward_type,</if>
- <if test="sopId != null">sop_id,</if>
- <if test="finishTime != null">finish_time,</if>
- <if test="sendFinishMsg != null">send_finish_msg,</if>
- <if test="campPeriodTime != null">camp_period_time,</if>
- <if test="project != null">project,</if>
- <if test="watchType != null">watch_type,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="userId != null">#{userId},</if>
- <if test="videoId != null">#{videoId},</if>
- <if test="logType != null">#{logType},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="updateTime != null">#{updateTime},</if>
- <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
- <if test="duration != null">#{duration},</if>
- <if test="qwUserId != null">#{qwUserId},</if>
- <if test="companyUserId != null">#{companyUserId},</if>
- <if test="companyId != null">#{companyId},</if>
- <if test="courseId != null">#{courseId},</if>
- <if test="sendType != null">#{sendType},</if>
- <if test="rewardType != null">#{rewardType},</if>
- <if test="sopId != null">#{sopId},</if>
- <if test="finishTime != null">#{finishTime},</if>
- <if test="sendFinishMsg != null">#{sendFinishMsg},</if>
- <if test="campPeriodTime != null">#{campPeriodTime},</if>
- <if test="project != null">#{project},</if>
- <if test="watchType != null">#{watchType},</if>
- </trim>
- on duplicate key update
- <trim suffixOverrides=",">
- <if test="updateTime != null">update_time = #{updateTime},</if>
- </trim>
- </insert>
- <insert id="insertFsCourseWatchLogBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="logId">
- INSERT INTO fs_course_watch_log (
- user_id,
- video_id,
- log_type,
- create_time,
- update_time,
- qw_external_contact_id,
- duration,
- qw_user_id,
- company_user_id,
- company_id,
- course_id,
- send_type,
- reward_type,
- sop_id,
- camp_period_time,
- project,
- period_id,
- im_msg_send_detail_id,
- watch_type
- )
- VALUES
- <foreach collection="watchLogs" item="log" separator=",">
- (
- #{log.userId},
- #{log.videoId},
- #{log.logType},
- #{log.createTime},
- #{log.updateTime},
- #{log.qwExternalContactId},
- #{log.duration},
- #{log.qwUserId},
- #{log.companyUserId},
- #{log.companyId},
- #{log.courseId},
- #{log.sendType},
- #{log.rewardType},
- #{log.sopId},
- #{log.campPeriodTime},
- #{log.project},
- #{log.periodId},
- #{log.imMsgSendDetailId},
- #{log.watchType}
- )
- </foreach>
- ON DUPLICATE KEY UPDATE
- update_time = NOW(),
- im_msg_send_detail_id = VALUES(im_msg_send_detail_id)
- </insert>
- <insert id="insertBackup">
- INSERT INTO fs_course_watch_log_bak (
- original_log_id,
- user_id,
- video_id,
- log_type,
- create_time,
- update_time,
- qw_external_contact_id,
- duration,
- qw_user_id,
- company_user_id,
- company_id,
- course_id,
- send_type,
- reward_type,
- last_heartbeat_time,
- sop_id,
- finish_time,
- send_finish_msg,
- camp_period_time,
- day,
- project,
- create_by,
- update_by,
- period_id,
- project_id,
- im_msg_send_detail_id,
- watch_type,
- delete_time,
- delete_by,
- delete_method,
- original_data,
- backup_operator,
- backup_batch_no,
- remark
- ) VALUES (
- #{originalLogId},
- #{userId},
- #{videoId},
- #{logType},
- #{createTime},
- #{updateTime},
- #{qwExternalContactId},
- #{duration},
- #{qwUserId},
- #{companyUserId},
- #{companyId},
- #{courseId},
- #{sendType},
- #{rewardType},
- #{lastHeartbeatTime},
- #{sopId},
- #{finishTime},
- #{sendFinishMsg},
- #{campPeriodTime},
- #{day},
- #{project},
- #{createBy},
- #{updateBy},
- #{periodId},
- #{projectId},
- #{imMsgSendDetailId},
- #{watchType},
- #{deleteTime},
- #{deleteBy},
- #{deleteMethod},
- #{originalData},
- #{backupOperator},
- #{backupBatchNo},
- #{remark}
- )
- </insert>
- <update id="updateFsCourseWatchLog" parameterType="FsCourseWatchLog">
- update fs_course_watch_log
- <trim prefix="SET" suffixOverrides=",">
- <if test="userId != null">user_id = #{userId},</if>
- <if test="videoId != null">video_id = #{videoId},</if>
- <if test="logType != null">log_type = #{logType},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="updateTime != null">update_time = #{updateTime},</if>
- <if test="qwExternalContactId != null">qw_external_contact_id = #{qwExternalContactId},</if>
- <if test="duration != null">duration = #{duration},</if>
- <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
- <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
- <if test="companyId != null">company_id = #{companyId},</if>
- <if test="courseId != null">course_id = #{courseId},</if>
- <if test="sendType != null">send_type = #{sendType},</if>
- <if test="rewardType != null">reward_type = #{rewardType},</if>
- <if test="sopId != null">sop_id = #{sopId},</if>
- <if test="finishTime != null">finish_time = #{finishTime},</if>
- <if test="sendFinishMsg != null">send_finish_msg = #{sendFinishMsg},</if>
- <if test="lastHeartbeatTime != null">last_heartbeat_time = #{lastHeartbeatTime},</if>
- <if test="periodId != null">period_id = #{periodId},</if>
- <if test="project != null">project = #{project},</if>
- <if test="watchType != null">watch_type = #{watchType},</if>
- </trim>
- where log_id = #{logId}
- </update>
- <delete id="deleteFsCourseWatchLogByLogId" parameterType="Long">
- delete from fs_course_watch_log where log_id = #{logId}
- </delete>
- <delete id="deleteFsCourseWatchLogByLogIds" parameterType="String">
- delete from fs_course_watch_log where log_id in
- <foreach item="logId" collection="array" open="(" separator="," close=")">
- #{logId}
- </foreach>
- </delete>
- <select id="selectFsCourseWatchLogByFinishTime" resultType="com.fs.course.param.FsCourseWatchLogByFinishTimeParam">
- <![CDATA[
- SELECT
- fcwl.log_id,
- fcwl.create_time,
- fcwl.qw_external_contact_id,
- fcwl.qw_user_id,
- fcwl.user_id,
- fcwl.company_user_id,
- fcwl.company_id,
- fcwl.sop_id,
- fcwl.finish_time,
- fcwl.camp_period_time,
- qec.corp_id,
- qec.external_user_id,
- qec.tag_ids,
- qec.user_id AS qw_user,
- qec.name AS external_contact_name
- FROM
- fs_course_watch_log fcwl
- LEFT JOIN qw_external_contact qec ON fcwl.qw_external_contact_id = qec.id
- WHERE
- DATE(fcwl.finish_time)= '2025-02-09'
- and fcwl.camp_period_time is not NULL
- ]]>
- </select>
- <select id="getWatchLogByFsUser" resultType="com.fs.course.domain.FsCourseWatchLog">
- SELECT
- log_id,
- user_id,
- video_id,
- log_type,
- create_time,
- update_time,
- duration,
- company_user_id,
- company_id,
- course_id,
- send_type,
- reward_type,
- last_heartbeat_time,
- sop_id,
- finish_time,
- send_finish_msg,
- camp_period_time
- FROM
- fs_course_watch_log
- WHERE
- send_type = 1
- AND video_id = #{videoId}
- AND user_id = #{fsUserId}
- AND company_user_id = #{companyUserId} order by log_id desc limit 1
- </select>
- <select id="selectFsCourseWatchLogStatisticsListVONew"
- resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO">
- SELECT
- o.company_user_id,o.user_id,DATE(o.create_time) create_time,
- SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
- SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
- SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
- SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4,
- o.project as project,
- o.course_id as course_id,
- o.video_id as video_id
- FROM fs_course_watch_log o
- <where>
- send_type=1
- <if test="companyId != null">
- and o.company_id=#{companyId}
- </if>
- <if test= 'sTime != null '>
- and DATE(o.create_time) >= #{sTime}
- </if>
- <if test='eTime != null '>
- and DATE(o.create_time) <= #{eTime}
- </if>
- <if test ='courseId !=null'>
- and o.course_id = #{courseId}
- </if>
- <if test ='videoId !=null'>
- and o.video_id = #{videoId}
- </if>
- <if test="companyUserId != null">
- and o.company_user_id = #{companyUserId}
- </if>
- <if test="project != null">
- and o.project = #{project}
- </if>
- <if test="userId != null">
- and o.user_id = #{userId}
- </if>
- </where>
- GROUP BY o.video_id,o.user_id,DATE(o.create_time),o.project,o.course_id
- ORDER BY o.video_id ,DATE(o.create_time)
- <!-- limit ${(pageNum-1)*pageSize},${pageSize}-->
- </select>
- <select id="selectFsCourseWatchLogStatisticsListVONewCount" resultType="java.lang.Long">
- SELECT COUNT(*)
- FROM (
- SELECT 1
- FROM fs_course_watch_log o
- <where>
- send_type=2
- <if test="companyId != null">
- and o.company_id=#{companyId}
- </if>
- <if test= 'sTime != null '>
- and o.create_time >= #{startDate}
- </if>
- <if test='eTime != null '>
- and o.create_time <= #{endDate}
- </if>
- <if test ='courseId !=null'>
- and o.course_id = #{courseId}
- </if>
- <if test ='videoId !=null'>
- and o.video_id = #{videoId}
- </if>
- <if test="companyUserId != null">
- and o.company_user_id = #{companyUserId}
- </if>
- <if test="project != null">
- and o.project = #{project}
- </if>
- <if test="userId != null">
- and o.user_id = #{userId}
- </if>
- </where>
- GROUP BY o.video_id, o.user_id, DATE(o.create_time), o.project, o.course_id
- ) AS grouped_results_count
- </select>
- <!-- 根据条件查询条数 -->
- <select id="countByMap" resultType="java.lang.Integer">
- select count(fcwl.log_id) from fs_course_watch_log fcwl
- <where>
- <if test="params.logTypes != null and params.logTypes.size() > 0">
- and fcwl.log_type in
- <foreach collection="params.logTypes" open="(" close=")" separator="," item="logType">
- #{logType}
- </foreach>
- </if>
- <if test="params.companyUserId != null">
- and fcwl.company_user_id = #{params.companyUserId}
- </if>
- <if test="params.date != null">
- and date(fcwl.create_time) = #{params.date}
- </if>
- </where>
- </select>
- <update id="batchUpdateWatchLog" parameterType="java.util.List">
- UPDATE fs_course_watch_log
- SET
- duration = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
- CASE
- <!-- 仅当传入的duration > 当前值时才更新 -->
- WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
- ELSE duration <!-- 如果 duration 为 null,保持原值 -->
- END
- </foreach>
- END,
- last_heartbeat_time = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
- CASE
- WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
- ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
- END
- </foreach>
- END,
- finish_time = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
- CASE
- WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
- ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
- END
- </foreach>
- END,
- log_type = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND qw_external_contact_id = #{item.qwExternalContactId} AND qw_user_id = #{item.qwUserId} THEN
- CASE
- WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
- WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
- ELSE log_type <!-- 其他情况保持原值 -->
- END
- </foreach>
- END
- WHERE
- (video_id, qw_external_contact_id, qw_user_id) IN
- <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
- (#{item.videoId}, #{item.qwExternalContactId}, #{item.qwUserId})
- </foreach>
- </update>
- <update id="batchUpdateWatchLogSendMsg" parameterType="java.util.List">
- UPDATE fs_course_watch_log
- SET send_finish_msg = CASE
- <foreach collection="list" item="item">
- WHEN log_id = #{item.logId} THEN #{item.sendFinishMsg}
- </foreach>
- ELSE send_finish_msg
- END
- WHERE log_id IN
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item.logId}
- </foreach>
- </update>
- <update id="batchUpdateFsUserWatchLog" parameterType="java.util.List">
- UPDATE fs_course_watch_log
- SET
- duration = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
- CASE
- <!-- 仅当传入的duration > 当前值时才更新 -->
- WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
- ELSE duration <!-- 如果 duration 为 null,保持原值 -->
- END
- </foreach>
- END,
- last_heartbeat_time = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
- CASE
- WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
- ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
- END
- </foreach>
- END,
- finish_time = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
- CASE
- WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
- ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
- END
- </foreach>
- END,
- log_type = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND user_id = #{item.userId} AND company_user_id = #{item.companyUserId} THEN
- CASE
- WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
- WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
- ELSE log_type <!-- 其他情况保持原值 -->
- END
- </foreach>
- END
- WHERE
- (video_id, user_id, company_user_id) IN
- <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
- (#{item.videoId}, #{item.userId}, #{item.companyUserId})
- </foreach>
- </update>
- <update id="batchUpdateWatchLogIsOpen">
- UPDATE fs_course_watch_log
- SET
- duration = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
- CASE
- <!-- 仅当传入的duration > 当前值时才更新 -->
- WHEN #{item.duration} IS NOT NULL AND #{item.duration} > duration THEN #{item.duration}
- ELSE duration <!-- 如果 duration 为 null,保持原值 -->
- END
- </foreach>
- END,
- last_heartbeat_time = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
- CASE
- WHEN #{item.lastHeartbeatTime} IS NOT NULL THEN #{item.lastHeartbeatTime}
- ELSE last_heartbeat_time <!-- 如果 last_heartbeat_time 为 null,保持原值 -->
- END
- </foreach>
- END,
- finish_time = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
- CASE
- WHEN finish_time IS NULL THEN #{item.finishTime} <!-- 如果表中 finish_time 为 null,更新为传入的值 -->
- ELSE finish_time <!-- 如果表中 finish_time 不为 null,保持原值 -->
- END
- </foreach>
- END,
- log_type = CASE
- <foreach collection="list" item="item" index="index">
- WHEN video_id = #{item.videoId} AND user_id = #{item.userId} THEN
- CASE
- WHEN log_type = 2 THEN log_type <!-- 如果 log_type 已经是 2,保持原值 -->
- WHEN #{item.logType} IS NOT NULL AND log_type != 2 THEN #{item.logType} <!-- 如果 log_type 不是 2,更新为传入的值 -->
- ELSE log_type <!-- 其他情况保持原值 -->
- END
- </foreach>
- END
- WHERE
- (video_id, user_id) IN
- <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
- (#{item.videoId}, #{item.userId})
- </foreach>
- </update>
- <select id="selectListBytrainingCampId" resultType="com.fs.course.vo.FsCourseWatchLogVO">
- select
- uc.course_name,v.title as video_name,
- watch.log_id,
- watch.user_id,
- watch.finish_time,
- watch.send_finish_msg,
- watch.sop_id,
- watch.video_id,
- watch.reward_type,
- watch.log_type,
- watch.create_time,
- watch.update_time,
- watch.qw_external_contact_id,
- watch.duration,
- watch.qw_user_id,
- watch.company_user_id,
- watch.company_id,
- watch.course_id,
- watch.camp_period_time
- from
- fs_user_course_training_camp camp
- left join fs_user_course_period period on
- camp.training_camp_id = period.training_camp_id
- left join fs_course_watch_log watch on
- period.period_id = watch.period_id
- left join fs_user_course uc on uc.course_id = watch.course_id
- left join fs_user_course_video v on v.video_id = watch.video_id
- <where>
- `period`.del_flag = '0' and watch.log_type <> 3
- <if test="trainingCampId != null">and camp.training_camp_id = #{trainingCampId}</if>
- <if test="userId != null">and watch.user_id = #{userId}</if>
- <if test="periodId != null">and `period`.period_id = #{periodId}</if>
- </where>
- </select>
- <select id="selectFsCourseWatchLogListVOexport" resultType="com.fs.course.vo.FsCourseWatchLogListVO">
- SELECT
- l.log_id,
- l.project AS project,
- l.period_id,
- l.user_id,
- l.log_type,
- SEC_TO_TIME(l.duration) AS duration,
- l.camp_period_time,
- l.finish_time,
- l.send_type,
- l.create_time,
- l.update_time,
- l.last_heartbeat_time,
- l.company_id,
- l.company_user_id,
- l.course_id,
- l.video_id,
- l.qw_user_id,
- l.qw_external_contact_id,
- l.sop_id,
- qec.create_time as qec_create_time
- FROM
- fs_course_watch_log l LEFT JOIN qw_external_contact qec on l.qw_external_contact_id = qec.id
- left join fs_user u on u.user_id = l.user_id
- left join company_user cu on cu.user_id = l.company_user_id
- <where>
- <if test ='maps.sendType !=null'>
- and l.send_type = #{maps.sendType}
- </if>
- <if test ='maps.userId !=null'>
- and l.user_id = #{maps.userId}
- </if>
- <if test ='maps.qwExternalContactId !=null'>
- and l.qw_external_contact_id = #{maps.qwExternalContactId}
- </if>
- <if test ='maps.qwUserId !=null'>
- and l.qw_user_id = #{maps.qwUserId}
- </if>
- <if test ='maps.courseId !=null'>
- and l.course_id = #{maps.courseId}
- </if>
- <if test ='maps.videoId !=null'>
- and l.video_id = #{maps.videoId}
- </if>
- <if test ='maps.logType !=null'>
- and l.log_type = #{maps.logType}
- </if>
- <if test ='maps.companyId !=null'>
- and l.company_id = #{maps.companyId}
- </if>
- <if test ='maps.companyUserId !=null'>
- and l.company_user_id = #{maps.companyUserId}
- </if>
- <if test ='maps.companyUserName !=null and maps.companyUserName!=""'>
- and cu.nick_name like concat('%', #{maps.companyUserName}, '%')
- </if>
- <if test ='maps.nickName !=null and maps.nickName!=""'>
- and u.nick_name like concat('%', #{maps.nickName}, '%')
- </if>
- <if test ='maps.externalUserName !=null and maps.externalUserName!=""'>
- and qec.name like concat('%', #{maps.externalUserName}, '%')
- </if>
- <if test= 'maps.qecSTime != null '>
- and DATE(qec.create_time) >= DATE(#{maps.qecSTime})
- </if>
- <if test='maps.qecETime != null '>
- and DATE(qec.create_time) <= DATE(#{maps.qecETime})
- </if>
- <if test= 'maps.sTime != null '>
- and DATE(l.create_time) >= DATE(#{maps.sTime})
- </if>
- <if test='maps.eTime != null '>
- and DATE(l.create_time) <= DATE(#{maps.eTime})
- </if>
- <if test= 'maps.scheduleStartTime != null '>
- and DATE(l.camp_period_time) >= DATE(#{maps.scheduleStartTime})
- </if>
- <if test='maps.scheduleEndTime != null '>
- and DATE(l.camp_period_time) <= DATE(#{maps.scheduleEndTime})
- </if>
- <if test= 'maps.upSTime != null '>
- and DATE(l.update_time) >= DATE(#{maps.upSTime})
- </if>
- <if test='maps.upETime != null '>
- and DATE(l.update_time) <= DATE(#{maps.upETime})
- </if>
- <if test="maps.sopIds != null and maps.sopIds.size() > 0">
- and l.sop_id in
- <foreach item="sopId" index="index" collection="maps.sopIds" open="(" separator="," close=")">
- #{sopId}
- </foreach>
- </if>
- <if test="maps.periodIds != null and maps.periodIds.size() > 0">
- and l.period_id in
- <foreach item="periodId" index="index" collection="maps.periodIds" open="(" separator="," close=")">
- #{periodId}
- </foreach>
- </if>
- </where>
- order by l.finish_time desc,l.update_time desc,l.create_time desc
- </select>
- <select id="getWatchCourseByVideoId" resultType="com.fs.course.domain.FsCourseWatchLog">
- SELECT
- *
- FROM
- fs_course_watch_log
- WHERE
- send_type = 1
- AND video_id = #{videoId}
- AND user_id in
- <foreach item="userId" index="index" collection="userIds" open="(" separator="," close=")">
- #{userId}
- </foreach>
- ORDER BY
- log_id DESC
- </select>
- <select id="getUserCountByCampId" resultType="java.lang.Integer">
- select count(distinct cwl.user_id)
- from fs_user_course_period ucp
- inner join fs_course_watch_log cwl on ucp.period_id = cwl.period_id
- where ucp.training_camp_id = #{trainingCampId}
- </select>
- <select id="selectFsCourseWatchLogStatisticsListByCompanyVO"
- resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListByCompanyVO">
- SELECT
- o.video_id,
- o.company_id,
- comp.company_name,
- o.qw_user_id,
- DATE(o.create_time) create_time,
- v.title videoName,
- uc.course_name,
- SUM(CASE WHEN o.log_type = '1' THEN 1 ELSE 0 END) AS type1,
- SUM(CASE WHEN o.log_type = '2' THEN 1 ELSE 0 END) AS type2,
- SUM(CASE WHEN o.log_type = '3' THEN 1 ELSE 0 END) AS type3,
- SUM(CASE WHEN o.log_type = '4' THEN 1 ELSE 0 END) AS type4
- FROM
- fs_course_watch_log o
- LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
- LEFT JOIN company comp ON comp.company_id = o.company_id
- LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
- LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
- <where>
- <if test="sendType != null">
- and send_type = #{sendType}
- </if>
- <if test="companyId != null">
- and o.company_id = #{companyId}
- </if>
- <if test="sTime != null">
- AND DATE (o.create_time) >= DATE (#{sTime})
- </if>
- <if test="eTime != null">
- AND DATE (o.create_time) <= DATE (#{eTime})
- </if>
- <if test="courseId != null">
- and o.course_id = #{courseId}
- </if>
- <if test="videoId != null">
- and o.video_id = #{videoId}
- </if>
- </where>
- GROUP BY
- DATE (o.create_time),
- o.company_id
- ORDER BY
- comp.company_id,
- DATE (o.create_time)
- </select>
- <select id="selectQwFsCourseWatchLogStatisticsListVO"
- resultType="com.fs.course.vo.FsCourseWatchLogStatisticsListVO" parameterType="com.fs.qw.param.QwSidebarStatsParam">
- SELECT
- o.project,
- o.course_id AS courseId,
- uc.course_name AS courseName,
- o.video_id AS videoId,
- v.title AS videoName,
- CASE WHEN o.log_type = 1 THEN 1 END AS type1,
- CASE WHEN o.log_type = 2 THEN 1 END AS type2,
- CASE WHEN o.log_type = 3 THEN 1 END AS type3,
- CASE WHEN o.log_type = 4 THEN 1 END AS type4,
- o.qw_user_id,
- o.user_id AS userId,
- o.company_user_id AS companyUserId,
- o.company_id AS companyId,
- o.create_time AS createTime
- FROM
- fs_course_watch_log o
- LEFT JOIN fs_user_course_video v ON v.video_id = o.video_id
- LEFT JOIN fs_user_course uc ON uc.course_id = v.course_id
- WHERE o.qw_external_contact_id=#{qwExternalContactId}
- <if test="sendType != null">
- AND send_type = #{sendType}
- </if>
- <if test="startTime != null">
- AND DATE(o.create_time) >= DATE(#{startTime})
- </if>
- <if test="endTime != null">
- AND DATE(o.create_time) <= DATE(#{endTime})
- </if>
- o.create_time DESC
- </select>
- <!-- 统计当天各公司的观看人数和完播人数, 存到redis中,定时任务每 ? 分钟执行一次 -->
- <select id="watchCourseStatisticsGroupByCompany" resultType="com.fs.statis.dto.WatchCourseStatisticsResultDTO">
- SELECT
- o.company_id AS companyId,
- c.company_name AS companyName,
- o.send_type,
- COUNT(DISTINCT o.user_id) AS watchUserCount,
- COUNT(o.log_id) AS watchCount,
- sum(case when o.log_type = 2 then 1 else 0 end) AS finishCount,
- COUNT(DISTINCT CASE WHEN o.log_type = 2 THEN o.user_id END) AS finishUserCount
- FROM
- fs_course_watch_log o
- LEFT JOIN company c ON c.company_id = o.company_id
- WHERE
- o.create_time >= #{params.startTime}
- AND o.create_time <= #{params.endTime}
- GROUP BY
- o.company_id,
- o.send_type
- </select>
- <select id="selectUserBaseInfo" resultType="com.fs.his.vo.FsUserReportVO">
- SELECT distinct u.user_id AS userId,
- u.nick_name AS nickName,
- u.integral AS integral,
- CASE
- WHEN u.`status` = '1' THEN '正常'
- WHEN u.`status` = '2' THEN '禁止'
- ELSE '无'
- END AS status,
- u.register_date AS registerDate,
- u.phone,
- cu.nick_name AS companyUserName,
- cuu.company_user_id as companyUserId,
- c.company_name AS companyName
- <if test='dimension == "dept"'>
- ,cd.dept_name AS deptName
- </if>
- FROM fs_user u
- inner JOIN fs_user_company_user cuu ON u.user_id = cuu.user_id
- <if test="sTime != null and eTime != null">
- left join fs_package_order po on po.user_id=u.user_id
- </if>
- LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
- LEFT JOIN company c ON cuu.company_id = c.company_id
- <if test='dimension == "dept"'>
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
- </if>
- <if test="trainingCampId != null or periodId != null ">
- Left Join fs_course_watch_log watch on watch.user_id= cuu.user_id and watch.project=cuu.project_id
- left join fs_user_course_period period on watch.period_id=period.period_id and period.del_flag=0
- left join fs_user_course_training_camp camp on period.training_camp_id= camp.training_camp_id and camp.del_flag=0
- </if>
- WHERE u.user_id IS NOT NULL
- <if test="userId != null">
- AND u.user_id = #{userId}
- </if>
- <if test="userPhone != null and userPhone != ''">
- AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
- </if>
- <if test="nickName != null and nickName != ''">
- AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
- </if>
- <!-- 部门条件 -->
- <if test="deptId != null">
- AND cd.dept_id = #{deptId}
- </if>
- <!-- 销售公司条件 -->
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- <if test="project != null">
- AND cuu.project_id = #{project}
- </if>
- <!-- 训练营条件 -->
- <if test="trainingCampId != null">
- AND camp.training_camp_id = #{trainingCampId}
- </if>
- <!-- 营期条件 -->
- <if test="periodId != null">
- AND period.period_id = #{periodId}
- </if>
- <!-- 时间范围 - 使用BETWEEN -->
- <if test="sTime != null and eTime != null">
- AND DATE(po.create_time) BETWEEN #{sTime} AND #{eTime}
- </if>
- order by u.create_time
- </select>
- <select id="selectWatchStatsByUserIds" resultType="com.fs.his.vo.FsUserReportVO">
- SELECT
- user_id AS userId,
- company_user_id AS companyUserId,
- MAX(
- COALESCE ( update_time, create_time )) AS lastWatchTime,
- COUNT( log_id ) AS watchCount,
- COUNT( DISTINCT period_id ) AS periodCount,
- CASE
- ( SELECT log_type FROM fs_course_watch_log w2 WHERE w2.user_id = w1.user_id ORDER BY create_time DESC LIMIT 1 )
- WHEN '1' THEN
- '看课中'
- WHEN '2' THEN
- '完课'
- WHEN '3' THEN
- '待看课'
- WHEN '4' THEN
- '看课中断' ELSE '无'
- END AS watchStatus
- FROM
- fs_course_watch_log w1
- WHERE (user_id, company_user_id) IN
- <foreach collection="userConditions" item="condition" open="(" close=")" separator=",">
- (#{condition.userId}, #{condition.companyUserId})
- </foreach>
- <if test="watchParam.project != null">
- AND w1.project = #{watchParam.project}
- </if>
- <if test="watchParam.periodId != null">
- AND w1.period_id = #{watchParam.periodId}
- </if>
- GROUP BY user_id,company_user_id
- </select>
- <select id="selectIntegralStatsByUserIds" resultType="com.fs.his.vo.FsUserReportVO">
- SELECT
- user_id AS userId,
- ABS(SUM(CASE WHEN integral < 0 THEN integral ELSE 0 END)) AS consumedIntegral
- from fs_user_integral_logs
- WHERE user_id IN
- <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
- #{userId}
- </foreach>
- GROUP BY user_id
- </select>
- <select id="selectRedPacketStatsByUserIds" resultType="com.fs.his.vo.FsUserReportVO">
- SELECT
- user_id AS userId,
- company_user_id AS companyUserId,
- SUM(amount) AS receivedAmount
- FROM fs_course_red_packet_log
- WHERE status = 1
- and (user_id, company_user_id) IN
- <foreach collection="userConditions" item="condition" open="(" close=")" separator=",">
- (#{condition.userId}, #{condition.companyUserId})
- </foreach>
- <if test="watchParam.periodId != null">
- AND period_id = #{watchParam.periodId}
- </if>
- GROUP BY user_id,company_user_id
- </select>
- <select id="selectOrderStatsByUserIds" resultType="com.fs.his.vo.FsUserReportVO">
- SELECT
- user_id AS userId,
- SUM(pay_money) AS orderAmount
- FROM fs_package_order
- WHERE status = 3
- AND user_id IN
- <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
- #{userId}
- </foreach>
- <if test="watchParam.sTime != null and watchParam.eTime != null">
- AND create_time BETWEEN #{watchParam.sTime} AND #{watchParam.eTime}
- </if>
- GROUP BY user_id
- </select>
- <select id="selectUserBaseData" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- log.user_id userId,
- u.nick_name AS nickName,
- cu.nick_name AS salesName,
- c.company_name AS salesCompany,
- cd.dept_name AS salesDept,
- log.period_id periodId,
- log.video_id videoId,
- log.log_id logId,
- log.create_time courseTime,
- log.finish_time finishTime,
- log.duration ,
- CASE
- WHEN log.log_type = '1' THEN '看课中'
- WHEN log.log_type = '2' THEN '完课'
- WHEN log.log_type = '3' THEN '待看课'
- WHEN log.log_type = '4' THEN '看课中断'
- ELSE '无'
- END AS watchStatus,
- cv.title AS videoTitle
- FROM
- fs_course_watch_log log
- <if test="orderSTime != null and orderETime != null">
- left join fs_package_order po ON po.user_id = log.user_id
- </if>
- LEFT JOIN fs_user u ON u.user_id = log.user_id
- LEFT JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
- LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
- LEFT JOIN company c ON log.company_id = c.company_id
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
- LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
- WHERE log.send_type =1 and log.watch_type = 2
- <include refid="commonConditions"/>
- <if test="orderSTime != null and orderETime != null">
- AND DATE(po.create_time) BETWEEN #{orderSTime} AND #{orderETime}
- </if>
- group by log.user_id
- ORDER BY u.register_date DESC
- </select>
- <select id="selectSalesBaseData" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- log.user_id userId,
- log.company_user_id companyUserId,
- log.log_id logId,
- log.create_time courseTime,
- cu.nick_name as salesName,
- d.dept_name AS salesDept,
- c.company_name AS salesCompany,
- COUNT( DISTINCT u.user_id ) AS userCount,
- COUNT( DISTINCT CASE WHEN u.STATUS = 1 THEN u.user_id END ) AS onlineUserCount,
- COUNT(DISTINCT log.log_id) AS totalLogCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
- COUNT(DISTINCT log.log_id)-COUNT(DISTINCT log.user_id) AS notWatchedCount,
- COUNT(DISTINCT log.log_id) - COUNT(DISTINCT a.watch_log_id) AS notAnsweredCount
- FROM
- fs_course_watch_log log
- <if test="orderSTime != null and orderETime != null">
- LEFT JOIN fs_package_order po ON po.user_id = log.user_id
- </if>
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN fs_user u on log.user_id= u.user_id
- LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
- LEFT JOIN company c ON d.company_id = c.company_id
- LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
- WHERE log.send_type =1 and log.watch_type =2
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND log.create_time >= #{startDate} AND log.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <if test="orderSTime != null and orderETime != null">
- AND DATE(po.create_time) BETWEEN #{orderSTime} AND #{orderETime}
- </if>
- <!-- 销售公司 -->
- <if test="companyId != null and companyId != ''">
- AND log.company_id = #{companyId}
- </if>
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- <!-- 训练营 -->
- <if test="trainingCampId != null and trainingCampId != ''">
- AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id =
- #{trainingCampId})
- </if>
- <!-- 营期 -->
- <if test="periodId != null and periodId != ''">
- AND log.period_id = #{periodId}
- </if>
- <!-- 会员id -->
- <if test="userId != null and userId != ''">
- AND log.user_id = #{userId}
- </if>
- <!-- 会员手机号 -->
- <if test="userPhone != null and userPhone != ''">
- AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
- </if>
- <if test="project != null and project != ''">
- AND log.project = #{project}
- </if>
- <!-- 会员昵称 -->
- <if test="nickName != null and nickName != ''">
- AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
- </if>
- GROUP BY cu.user_id
- </select>
- <select id="selectCompanyBaseData" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- log.user_id userId,
- log.period_id periodId,
- log.log_id logId,
- log.create_time courseTime,
- d.dept_id AS deptId,
- d.dept_name AS salesDept,
- c.company_name AS salesCompany,
- COUNT(DISTINCT cu.user_id) AS salesCount,
- COUNT(DISTINCT u.user_id) AS userCount,
- COUNT(DISTINCT CASE WHEN u.STATUS = 1 THEN u.user_id END) AS onlineUserCount,
- cv.title videoTitle,
- COUNT(DISTINCT log.log_id) AS totalLogCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
- COUNT(DISTINCT log.user_id) - COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.user_id END) AS notWatchedCount
- FROM fs_course_watch_log log
- <if test="orderSTime != null and orderETime != null">
- LEFT JOIN fs_package_order po ON po.user_id = log.user_id
- </if>
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN fs_user u on log.user_id= u.user_id
- LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
- LEFT JOIN company c ON d.company_id = c.company_id
- LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
- WHERE log.send_type =1
- <if test="sTime != null and eTime != null">
- AND DATE(log.create_time) BETWEEN #{sTime} AND #{eTime}
- </if>
- <if test="orderSTime != null and orderETime != null">
- AND DATE(po.create_time) BETWEEN #{orderSTime} AND #{orderETime}
- </if>
- <!-- 销售公司 -->
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- <!--部门 -->
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- <!-- 训练营 -->
- <if test="trainingCampId != null and trainingCampId != ''">
- AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
- </if>
- <!-- 营期 -->
- <if test="periodId != null and periodId != ''">
- AND log.period_id = #{periodId}
- </if>
- <!-- 会员id -->
- <if test="userId != null and userId != ''">
- AND log.user_id = #{userId}
- </if>
- <!-- 会员手机号 -->
- <if test="userPhone != null and userPhone != ''">
- AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
- </if>
- <if test="project != null and project != ''">
- AND log.project = #{project}
- </if>
- <!-- 会员昵称 -->
- <if test="nickName != null and nickName != ''">
- AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
- </if>
- GROUP BY d.dept_id
- </select>
- <select id="selectUserWatchDetails" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- wl.user_id AS userId,
- wl.company_user_id as companyUserId,
- camp.training_camp_name trainingCampName,
- cp.period_name periodName ,
- cv.title videoTitle ,
- CASE
- WHEN wl.log_type = '1' THEN '看课中'
- WHEN wl.log_type = '2' THEN '完课'
- WHEN wl.log_type = '3' THEN '待看课'
- WHEN wl.log_type = '4' THEN '看课中断'
- ELSE '无'
- END AS watchStatus,
- wl.duration,
- wl.create_time courseTime,
- wl.finish_time finishTime,
- COUNT(DISTINCT log_id) AS totalLogCount,
- COUNT(DISTINCT CASE WHEN wl.log_type = '2' THEN wl.log_id END) AS finishedCount,
- COUNT(DISTINCT CASE WHEN wl.log_type IN ('1', '3', '4') THEN wl.log_id END) AS unfinishedCount,
- (SELECT COUNT(DISTINCT concat(uc.userId, '_', uc.companyUserId))
- FROM (
- <foreach collection="userConditions" item="condition" separator="UNION ALL">
- SELECT #{condition.userId} AS userId, #{condition.companyUserId} AS companyUserId
- </foreach>
- ) uc
- ) - COUNT(DISTINCT concat(wl.user_id, '_', wl.company_user_id)) AS notWatchedCount
- FROM fs_course_watch_log wl
- LEFT JOIN fs_user_course_video cv ON wl.video_id = cv.video_id
- LEFT JOIN fs_user_course_period cp ON wl.period_id = cp.period_id AND cp.del_flag = 0
- LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id and camp.del_flag=0
- WHERE wl.send_type = 1
- and (wl.user_id, wl.company_user_id) IN
- <foreach collection="userConditions" item="condition" open="(" close=")" separator=",">
- (#{condition.userId}, #{condition.companyUserId})
- </foreach>
- <if test="watchParam.trainingCampId != null">
- AND camp.training_camp_id = #{watchParam.trainingCampId}
- </if>
- <if test="watchParam.periodId != null">
- AND cp.period_id = #{watchParam.periodId}
- </if>
- <if test="watchParam.sTime != null and watchParam.eTime != null">
- AND wl.create_time BETWEEN #{watchParam.sTime} AND #{watchParam.eTime}
- </if>
- GROUP BY
- wl.user_id,
- wl.company_user_id,
- camp.training_camp_name,
- cp.period_name,
- cv.title,
- wl.log_type,
- wl.duration,
- wl.create_time,
- wl.finish_time
- </select>
- <select id="selectRedPacketStats" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- rp.watch_log_id as logId,
- SUM(rp.amount) AS redPacketAmount,
- COUNT( rp.log_id) AS redPacketCount
- FROM fs_course_red_packet_log rp
- WHERE rp.watch_log_id IN
- <foreach collection="logIds" item="logId" open="(" separator="," close=")">
- #{logId}
- </foreach>
- GROUP BY rp.watch_log_id
- </select>
- <select id="selectRedPacketStatsByCompanyUserIds" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- w.company_user_id AS companyUserId,
- SUM(rp.amount) AS redPacketAmount,
- COUNT(rp.log_id) AS redPacketCount
- FROM fs_course_red_packet_log rp
- INNER JOIN fs_course_watch_log w ON rp.watch_log_id = w.log_id
- WHERE w.company_user_id IN
- <foreach collection="companyUserIds" item="companyUserId" open="(" separator="," close=")">
- #{companyUserId}
- </foreach>
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND w.create_time >= #{startDate} AND w.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <if test="periodId != null and periodId != ''">
- AND w.period_id = #{periodId}
- </if>
- <if test="trainingCampId != null and trainingCampId != ''">
- AND w.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
- </if>
- GROUP BY w.company_user_id
- </select>
- <select id="selectRedPacketStatsByDeptIds" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- cu.dept_id AS deptId,
- SUM(rp.amount) AS redPacketAmount,
- COUNT(rp.log_id) AS redPacketCount
- FROM fs_course_red_packet_log rp
- INNER JOIN fs_course_watch_log w ON rp.watch_log_id = w.log_id
- INNER JOIN company_user cu ON w.company_user_id = cu.user_id
- WHERE cu.dept_id IN
- <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND w.create_time >= #{startDate} AND w.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <if test="periodId != null and periodId != ''">
- AND w.period_id = #{periodId}
- </if>
- <if test="trainingCampId != null and trainingCampId != ''">
- AND w.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
- </if>
- GROUP BY cu.dept_id
- </select>
- <select id="selectOrderStats" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- user_id AS userId,
- COUNT(DISTINCT CASE WHEN status = 3 THEN order_id END) AS historyOrderCount
- FROM fs_package_order
- WHERE user_id IN
- <foreach collection="userIds" item="userId" open="(" separator="," close=")">
- #{userId}
- </foreach>
- <!--下单时间-->
- <if test="watchParam.orderSTime != null and watchParam.orderETime != null">
- AND DATE(create_time) BETWEEN #{watchParam.orderSTime} AND #{watchParam.orderETime}
- </if>
- GROUP BY user_id
- </select>
- <select id="selectAnswerStats" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- l.watch_log_id AS logId,
- CASE WHEN l.log_id IS NOT NULL THEN '已答题' ELSE '未答题' END AS answerStatus,
- (
- SELECT COUNT(1)
- FROM fs_course_watch_log wl
- WHERE wl.log_id IN
- <foreach collection="logIds" item="logId" open="(" separator="," close=")">
- #{logId}
- </foreach>
- AND wl.log_id NOT IN (
- SELECT watch_log_id
- FROM fs_course_answer_logs
- WHERE watch_log_id IS NOT NULL
- )) AS notAnsweredCount
- FROM fs_course_answer_logs l
- WHERE l.watch_log_id IN
- <foreach collection="logIds" item="logId" open="(" separator="," close=")">
- #{logId}
- </foreach>
- GROUP BY l.watch_log_id
- </select>
- <select id="selectCompanyBaseInfo" resultType="com.fs.his.vo.FsCourseReportVO">
- SELECT
- c.company_id AS companyId,
- c.company_name AS companyName
- FROM company c
- <where>
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- </where>
- GROUP BY c.company_id, c.company_name
- ORDER BY c.create_time DESC
- </select>
- <select id="selectWatchStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
- SELECT
- <choose>
- <!-- 公司维度查询 -->
- <when test="dimension == 'company'">
- company_id AS companyId,
- </when>
- <!-- 营期维度查询 -->
- <when test="dimension == 'camp'">
- period_id AS periodId,
- company_id AS companyId,
- </when>
- </choose>
- COUNT(DISTINCT CASE WHEN log_type = 3 THEN user_id END) AS pendingCount,
- COUNT(DISTINCT CASE WHEN log_type != 3 THEN user_id END) AS watchingCount,
- COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS finishedCount,
- COUNT(DISTINCT CASE WHEN log_type = 4 THEN user_id END) AS interruptedCount,
- COUNT(DISTINCT user_id) AS accessCount
- FROM fs_course_watch_log
- <where>
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND create_time >= #{startDate} AND create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <!-- 看课方式筛选 -->
- <if test="watchType != null and watchType != ''">
- AND watch_type = #{watchType}
- </if>
- <choose>
- <!-- 公司维度筛选 -->
- <when test="dimension == 'company'">
- <if test="companyIds != null and companyIds.size() > 0">
- AND company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- </if>
- </when>
- <!-- 营期维度筛选 -->
- <when test="dimension == 'camp'">
- <if test="periodIds != null and periodIds.size() > 0">
- AND period_id IN
- <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
- #{periodId}
- </foreach>
- </if>
- <if test="companyIds != null and companyIds.size() > 0">
- AND company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- </if>
- </when>
- </choose>
- </where>
- <choose>
- <when test="dimension == 'company'">
- GROUP BY company_id
- </when>
- <when test="dimension == 'camp'">
- GROUP BY period_id,company_id
- </when>
- </choose>
- </select>
- <select id="selectAnswerStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
- SELECT
- <choose>
- <!-- 公司维度查询 -->
- <when test="dimension == 'company'">
- w.company_id AS companyId,
- </when>
- <!-- 营期维度查询 -->
- <when test="dimension == 'camp'">
- w.period_id AS periodId,
- w.company_id AS companyId,
- </when>
- </choose>
- COUNT(DISTINCT a.user_id) AS answerUserCount
- FROM fs_course_answer_logs a
- INNER JOIN fs_course_watch_log w ON a.watch_log_id = w.log_id
- <where>
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND w.create_time >= #{startDate} AND w.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <!-- 看课方式筛选 -->
- <if test="watchType != null and watchType != ''">
- AND w.watch_type = #{watchType}
- </if>
- <choose>
- <!-- 公司维度筛选 -->
- <when test="dimension == 'company'">
- <if test="companyIds != null and companyIds.size() > 0">
- AND w.company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- </if>
- </when>
- <!-- 营期维度筛选 -->
- <when test="dimension == 'camp'">
- <if test="periodIds != null and periodIds.size() > 0">
- AND w.period_id IN
- <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
- #{periodId}
- </foreach>
- </if>
- <if test="companyIds != null and companyIds.size() > 0">
- AND w.company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- </if>
- </when>
- </choose>
- </where>
- <choose>
- <when test="dimension == 'company'">
- GROUP BY w.company_id
- </when>
- <when test="dimension == 'camp'">
- GROUP BY w.period_id,w.company_id
- </when>
- </choose>
- </select>
- <select id="selectRedPacketStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
- SELECT
- <choose>
- <!-- 公司维度查询 -->
- <when test="dimension == 'company'">
- w.company_id AS companyId,
- </when>
- <!-- 营期维度查询 -->
- <when test="dimension == 'camp'">
- w.period_id AS periodId,
- w.company_id AS companyId,
- </when>
- </choose>
- COUNT(DISTINCT rpl.user_id) AS packetUserCount,
- COALESCE(SUM(rpl.amount), 0) AS packetAmount
- FROM fs_course_red_packet_log rpl
- INNER JOIN fs_course_watch_log w ON rpl.watch_log_id = w.log_id
- <where>
- rpl.status=1
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND w.create_time >= #{startDate} AND w.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <!-- 看课方式筛选 -->
- <if test="watchType != null and watchType != ''">
- AND w.watch_type = #{watchType}
- </if>
- <choose>
- <!-- 公司维度筛选 -->
- <when test="dimension == 'company'">
- <if test="companyIds != null and companyIds.size() > 0">
- AND w.company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- </if>
- </when>
- <!-- 营期维度筛选 -->
- <when test="dimension == 'camp'">
- <if test="periodIds != null and periodIds.size() > 0">
- AND w.period_id IN
- <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
- #{periodId}
- </foreach>
- </if>
- <if test="companyIds != null and companyIds.size() > 0">
- AND w.company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- </if>
- </when>
- </choose>
- </where>
- <choose>
- <when test="dimension == 'company'">
- GROUP BY w.company_id
- </when>
- <when test="dimension == 'camp'">
- GROUP BY w.period_id,w.company_id
- </when>
- </choose>
- </select>
- <select id="selectCampPeriodInfo" resultType="com.fs.his.vo.FsCourseReportVO">
- SELECT
- p.period_id AS periodId,
- p.period_name AS periodName,
- c.training_camp_name AS trainingCampName
- FROM fs_user_course_period p
- LEFT JOIN fs_user_course_training_camp c ON p.training_camp_id = c.training_camp_id
- WHERE p.period_id IN
- <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
- #{periodId}
- </foreach>
- </select>
- <select id="selectCampPeriodByPeriod" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- cp.period_id periodId,
- cp.period_name periodName,
- camp.training_camp_name
- FROM
- fs_user_course_period cp
- LEFT JOIN fs_user_course_training_camp camp ON camp.training_camp_id = cp.training_camp_id
- WHERE cp.period_id in
- <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
- #{periodId}
- </foreach>
- </select>
- <select id="getSalesMemberStats" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- cu.user_id companyUserId,
- cu.nick_name salesName,
- COUNT(DISTINCT u.user_id) AS userCount,
- COUNT(DISTINCT CASE WHEN u.status = 1 THEN u.user_id END) AS onlineUserCount
- FROM fs_user u
- LEFT JOIN fs_user_company_user cuu ON u.user_id = cuu.user_id
- LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
- <where>
- (u.status = 1 OR cu.status = 1)
- <if test="salesIds != null and salesIds.size() > 0">
- AND cu.user_id IN
- <foreach collection="salesIds" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </if>
- </where>
- GROUP BY cu.user_id
- </select>
- <select id="getSalesDeptCompanyInfo" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- cu.user_id AS companyUserId,
- d.dept_name AS salesDept,
- c.company_name AS salesCompany,
- (SELECT COUNT(*)
- FROM company_user cu2
- WHERE cu2.dept_id = cu.dept_id
- AND cu2.del_flag = '0'
- AND cu2.status = '0') AS salesCount
- FROM company_user cu
- LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
- LEFT JOIN company c ON d.company_id = c.company_id
- WHERE cu.user_id IN
- <foreach collection="salesIds" item="salesId" open="(" separator="," close=")">
- #{salesId}
- </foreach>
- <!--部门-->
- <if test="watchParam.deptId != null and watchParam.deptId != ''">
- AND d.dept_id = #{watchParam.deptId}
- </if>
- AND cu.del_flag = '0'
- </select>
- <select id="selectCompanyBaseDataOptimized" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- d.dept_id AS deptId,
- d.dept_name AS salesDept,
- c.company_name AS salesCompany,
- COUNT(DISTINCT cu.user_id) AS salesCount,
- COUNT(DISTINCT u.user_id) AS userCount,
- COUNT( DISTINCT CASE WHEN u.STATUS = 1 THEN u.user_id END ) AS onlineUserCount
- FROM fs_course_watch_log log
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN fs_user u ON log.user_id = u.user_id
- LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
- LEFT JOIN company c ON d.company_id = c.company_id
- WHERE log.send_type = 1 and log.watch_type = 2
- <if test="sTime != null and eTime != null">
- AND log.create_time >= #{sTime} AND log.create_time < DATE_ADD(#{eTime}, INTERVAL 1 DAY)
- </if>
- <!-- 销售公司 -->
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- <!--部门 -->
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- <!-- 训练营 -->
- <if test="trainingCampId != null and trainingCampId != ''">
- AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
- </if>
- <!-- 营期 -->
- <if test="periodId != null and periodId != ''">
- AND log.period_id = #{periodId}
- </if>
- <!-- 会员id -->
- <if test="userId != null and userId != ''">
- AND log.user_id = #{userId}
- </if>
- <!-- 会员手机号 -->
- <if test="userPhone != null and userPhone != ''">
- AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
- </if>
- <if test="project != null and project != ''">
- AND log.project = #{project}
- </if>
- <!-- 会员昵称 -->
- <if test="nickName != null and nickName != ''">
- AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
- </if>
- GROUP BY d.dept_id
- </select>
- <!-- 公司维度合并查询(基础数据+统计数据) -->
- <select id="selectCompanyDeptStatsMerged" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- d.dept_id AS deptId,
- d.dept_name AS salesDept,
- c.company_name AS salesCompany,
- COUNT(DISTINCT cu.user_id) AS salesCount,
- COUNT(DISTINCT u.user_id) AS userCount,
- COUNT(DISTINCT CASE WHEN u.STATUS = 1 THEN u.user_id END) AS onlineUserCount,
- COUNT(DISTINCT log.log_id) AS totalLogCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
- COUNT(DISTINCT log.user_id) - COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.user_id END) AS notWatchedCount,
- COUNT(DISTINCT log.log_id) - COUNT(DISTINCT a.watch_log_id) AS notAnsweredCount
- FROM fs_course_watch_log log
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN fs_user u ON log.user_id = u.user_id
- LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
- LEFT JOIN company c ON d.company_id = c.company_id
- LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
- WHERE log.send_type = 1 AND log.watch_type = 2
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND log.create_time >= #{startDate} AND log.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- <if test="trainingCampId != null and trainingCampId != ''">
- AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
- </if>
- <if test="periodId != null and periodId != ''">
- AND log.period_id = #{periodId}
- </if>
- <if test="userId != null and userId != ''">
- AND log.user_id = #{userId}
- </if>
- <if test="userPhone != null and userPhone != ''">
- AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
- </if>
- <if test="project != null and project != ''">
- AND log.project = #{project}
- </if>
- <if test="nickName != null and nickName != ''">
- AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
- </if>
- GROUP BY d.dept_id
- </select>
- <select id="selectAllDeptIds" resultType="java.lang.Long">
- SELECT DISTINCT d.dept_id
- FROM fs_course_watch_log log
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
- LEFT JOIN company c ON d.company_id = c.company_id
- LEFT JOIN fs_user u ON log.user_id = u.user_id
- WHERE log.send_type = 1
- <if test="sTime != null and eTime != null">
- AND DATE(log.create_time) BETWEEN #{sTime} AND #{eTime}
- </if>
- <!-- 销售公司 -->
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- <!--部门 -->
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- <!-- 训练营 -->
- <if test="trainingCampId != null and trainingCampId != ''">
- AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
- </if>
- <!-- 营期 -->
- <if test="periodId != null and periodId != ''">
- AND log.period_id = #{periodId}
- </if>
- <!-- 会员id -->
- <if test="userId != null and userId != ''">
- AND log.user_id = #{userId}
- </if>
- <!-- 会员手机号 -->
- <if test="userPhone != null and userPhone != ''">
- AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
- </if>
- <if test="project != null and project != ''">
- AND log.project = #{project}
- </if>
- <!-- 会员昵称 -->
- <if test="nickName != null and nickName != ''">
- AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
- </if>
- </select>
- <select id="selectWatchStatsByDeptBatch" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- d.dept_id AS deptId,
- log.user_id AS userId,
- log.log_id AS logId,
- COUNT(DISTINCT log.log_id) AS totalLogCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
- COUNT(DISTINCT log.user_id) - COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.user_id END) AS notWatchedCount
- FROM fs_course_watch_log log
- <if test="orderSTime != null and orderETime != null">
- LEFT JOIN fs_package_order po ON po.user_id = log.user_id
- </if>
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
- WHERE log.send_type = 1 and log.watch_type = 2
- AND d.dept_id IN
- <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- <if test="sTime != null and eTime != null">
- AND log.create_time >= #{sTime} AND log.create_time < DATE_ADD(#{eTime}, INTERVAL 1 DAY)
- </if>
- <if test="orderSTime != null and orderETime != null">
- AND DATE(po.create_time) BETWEEN #{orderSTime} AND #{orderETime}
- </if>
- <!-- 销售公司 -->
- <if test="companyId != null and companyId != ''">
- AND cu.company_id = #{companyId}
- </if>
- <!-- 训练营 -->
- <if test="trainingCampId != null and trainingCampId != ''">
- AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
- </if>
- <!-- 营期 -->
- <if test="periodId != null and periodId != ''">
- AND log.period_id = #{periodId}
- </if>
- <!-- 会员id -->
- <if test="userId != null and userId != ''">
- AND log.user_id = #{userId}
- </if>
- GROUP BY d.dept_id
- </select>
- <select id="selectCompanyBaseDataWithIds" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- log.user_id userId,
- log.period_id periodId,
- log.log_id logId,
- d.dept_id AS deptId,
- d.dept_name AS salesDept,
- c.company_name AS salesCompany
- FROM fs_course_watch_log log
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
- LEFT JOIN company c ON d.company_id = c.company_id
- WHERE log.send_type = 1
- <if test="sTime != null and eTime != null">
- AND DATE(log.create_time) BETWEEN #{sTime} AND #{eTime}
- </if>
- <!-- 销售公司 -->
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- <!--部门 -->
- <if test="deptId != null and deptId != ''">
- AND d.dept_id = #{deptId}
- </if>
- <!-- 训练营 -->
- <if test="trainingCampId != null and trainingCampId != ''">
- AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
- </if>
- <!-- 营期 -->
- <if test="periodId != null and periodId != ''">
- AND log.period_id = #{periodId}
- </if>
- <!-- 会员id -->
- <if test="userId != null and userId != ''">
- AND log.user_id = #{userId}
- </if>
- <!-- 会员手机号 -->
- <if test="userPhone != null and userPhone != ''">
- AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
- </if>
- <if test="project != null and project != ''">
- AND log.project = #{project}
- </if>
- <!-- 会员昵称 -->
- <if test="nickName != null and nickName != ''">
- AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
- </if>
- GROUP BY
- d.dept_id,
- d.dept_name,
- c.company_name
- </select>
- <select id="selectPeriodInfo" resultType="com.fs.his.vo.FsCourseReportVO">
- SELECT
- period.period_id periodId,
- period.period_name periodName,
- camp.training_camp_name trainingCampName,
- c.company_name companyName,
- c.company_id companyId
- FROM
- fs_user_course_period period
- LEFT JOIN fs_user_course_training_camp camp
- ON camp.training_camp_id = period.training_camp_id
- LEFT JOIN company c
- ON FIND_IN_SET(c.company_id, period.company_id) > 0
- <where>
- <!-- 只有当传入公司ID参数时才筛选公司 -->
- <if test="companyId != null">
- c.company_id = #{companyId}
- </if>
- <!-- 训练营 -->
- <if test="trainingCampId != null and trainingCampId != ''">
- AND period.training_camp_id= #{trainingCampId}
- </if>
- <!-- 营期 -->
- <if test="periodId != null and periodId != ''">
- AND period.period_id = #{periodId}
- </if>
- </where>
- ORDER BY period.create_time DESC
- </select>
- <select id="selectActiveUserIds" resultType="java.lang.Long">
- SELECT DISTINCT user_id
- FROM fs_course_watch_log
- WHERE user_id IN
- <foreach item="userId" collection="userIds" open="(" separator="," close=")">
- #{userId}
- </foreach>
- and send_type = 1
- and watch_type = 1
- </select>
- <select id="selectAppWatchStatistics" resultType="com.fs.his.vo.AppCourseReportVO">
- SELECT
- log_id logId,
- company_id AS companyId,
- COUNT(CASE WHEN log_type = 3 THEN log_id END) AS pendingCount,
- COUNT(CASE WHEN log_type = 1 THEN log_id END) AS watchingCount,
- COUNT(CASE WHEN log_type = 2 THEN log_id END) AS finishedCount,
- count(log_id) as accessCount
- FROM fs_course_watch_log
- <where>
- watch_type =1 and send_type = 1
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND create_time >= #{startDate} AND create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <if test="companyIds != null and companyIds.size() > 0">
- AND company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- </if>
- </where>
- GROUP BY company_id
- </select>
- <select id="selectAppAnswerStatistics" resultType="com.fs.his.vo.AppCourseReportVO">
- SELECT
- l.company_id AS companyId,
- COUNT( l.log_id) AS answerUserCount
- FROM fs_course_answer_logs l
- LEFT JOIN fs_course_watch_log a on l.watch_log_id=a.log_id
- WHERE l.company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- and a.watch_type=1 and a.send_type=1
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND l.create_time >= #{startDate} AND l.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- GROUP BY l.company_id
- </select>
- <select id="selectAppRedPacketStatistics" resultType="com.fs.his.vo.AppCourseReportVO">
- SELECT
- rpl.company_id AS companyId,
- COUNT( rpl.log_id) AS packetUserCount,
- COALESCE(SUM(rpl.amount), 0) AS packetAmount
- FROM fs_course_red_packet_log rpl
- LEFT JOIN fs_course_watch_log a on rpl.watch_log_id=a.log_id
- WHERE rpl.company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- and a.watch_type=1 and a.send_type=1
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND rpl.create_time >= #{startDate} AND rpl.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- GROUP BY rpl.company_id
- </select>
- <select id="selectAppUserBaseData" resultType="com.fs.his.vo.AppWatchLogReportVO">
- SELECT
- log.user_id userId,
- u.nick_name AS nickName,
- u.app_create_time loginChannel,
- cu.nick_name AS salesName,
- c.company_name AS salesCompany,
- cd.dept_name AS salesDept,
- log.period_id periodId,
- log.video_id videoId,
- log.log_id logId,
- log.create_time courseTime,
- log.finish_time finishTime,
- log.duration privateWatchDuration,
- log.log_type privateWatchStatus,
- cv.title AS videoTitle
- FROM
- fs_course_watch_log log
- LEFT JOIN fs_user u ON u.user_id = log.user_id
- LEFT JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
- LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
- LEFT JOIN company c ON log.company_id = c.company_id
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
- LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
- WHERE log.send_type = 1
- AND log.watch_type = 1
- <include refid="commonConditions"/>
- group by log.user_id
- ORDER BY u.register_date DESC
- </select>
- <sql id="commonConditions">
- <!-- 销售公司 -->
- <if test="companyId != null and companyId != ''">
- AND c.company_id = #{companyId}
- </if>
- <!-- 销售部门 -->
- <if test="deptId != null and deptId != ''">
- AND cd.dept_id = #{deptId}
- </if>
- <!-- 所属销售 -->
- <if test="salesId != null and salesId != ''">
- AND cu.user_id = #{salesId}
- </if>
- <!-- 项目 -->
- <if test="project != null and project != ''">
- AND log.project = #{project}
- </if>
- <!-- 时间范围 -->
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND log.create_time >= #{startDate} AND log.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <!-- 训练营 -->
- <if test="trainingCampId != null and trainingCampId != ''">
- AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
- </if>
- <!-- 营期 -->
- <if test="periodId != null and periodId != ''">
- AND log.period_id = #{periodId}
- </if>
- <!-- 会员ID -->
- <if test="userId != null and userId != ''">
- AND u.user_id = #{userId}
- </if>
- <!-- 会员手机号 -->
- <if test="userPhone != null and userPhone != ''">
- AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
- </if>
- <!-- 会员昵称 -->
- <if test="nickName != null and nickName != ''">
- AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
- </if>
- </sql>
- <!-- 销售维度APP会员数统计(直接查fs_user表) -->
- <select id="selectAppSalesUserStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
- SELECT
- cu.user_id AS salesId,
- COUNT(DISTINCT CASE WHEN (u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL THEN u.user_id END) AS appUserCount,
- <choose>
- <when test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- COUNT(DISTINCT CASE WHEN ((u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL) AND u.app_create_time >= #{startDate} AND u.app_create_time < CONCAT(#{endDate}, ' 23:59:59') THEN u.user_id END)
- </when>
- <otherwise>
- COUNT(DISTINCT CASE WHEN (u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL THEN u.user_id END)
- </otherwise>
- </choose> AS newAppUserCount
- FROM fs_user u
- INNER JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
- INNER JOIN company_user cu ON cuu.company_user_id = cu.user_id
- INNER JOIN company c ON cuu.company_id = c.company_id
- WHERE ((u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL)
- AND u.status = 1
- AND u.is_del=0
- AND cuu.status IN (0, 1)
- <if test="companyId != null and companyId != ''">
- AND cuu.company_id = #{companyId}
- </if>
- <if test="deptId != null and deptId != ''">
- AND cu.dept_id = #{deptId}
- </if>
- <if test="salesId != null and salesId != ''">
- AND cu.user_id = #{salesId}
- </if>
- <if test="project != null and project != ''">
- AND cuu.project_id = #{project}
- </if>
- GROUP BY cu.user_id
- </select>
- <!-- 销售维度基础数据+看课统计(合并查询) -->
- <select id="selectAppSalesWatchStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
- SELECT
- cu.user_id AS salesId,
- cu.nick_name AS salesName,
- cd.dept_name AS salesDept,
- c.company_name AS salesCompany,
- cd.dept_id AS deptId,
- c.company_id AS companyId,
- COUNT( CASE WHEN log.log_type = 2 THEN log.log_id END ) AS finishedCount,
- COUNT(log.log_id)- COUNT(CASE WHEN log.log_type = 2 THEN log.log_id END )AS unfinishedCount,
- COUNT( CASE WHEN log.log_type = 3 THEN log.log_id END ) AS notWatchedCount,
- COUNT( a.watch_log_id ) answeredCount,
- COALESCE ( SUM( rpl.amount ), 0 ) AS redPacketAmount,
- COUNT( rpl.log_id) AS packetUserCount
- FROM fs_course_watch_log log
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN company c ON log.company_id = c.company_id
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
- LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
- LEFT JOIN fs_course_red_packet_log rpl ON rpl.watch_log_id = log.log_id
- WHERE log.send_type = 1
- AND log.watch_type = 1
- <include refid="commonConditions"/>
- GROUP BY cu.user_id
- ORDER BY cu.user_id
- </select>
- <!-- 销售维度订单统计 -->
- <select id="selectAppSalesOrderStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
- SELECT
- cu.user_id AS salesId,
- log.period_id AS periodId,
- log.video_id AS videoId,
- COUNT(DISTINCT CASE WHEN po.status = 3 THEN po.order_id END) AS historyOrderCount
- FROM fs_course_watch_log log
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN company c ON log.company_id = c.company_id
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
- LEFT JOIN fs_package_order po ON po.user_id = log.user_id
- WHERE log.send_type = 1
- AND log.watch_type = 1
- <include refid="commonConditions"/>
- GROUP BY cu.user_id, log.period_id, log.video_id
- </select>
- <!-- 销售维度营期信息 -->
- <select id="selectAppSalesCampPeriod" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
- SELECT
- cp.period_id periodId,
- cp.period_name periodName,
- camp.training_camp_name trainingCampName
- FROM
- fs_user_course_period cp
- LEFT JOIN fs_user_course_training_camp camp ON camp.training_camp_id = cp.training_camp_id
- WHERE cp.period_id in
- <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
- #{periodId}
- </foreach>
- </select>
- <!-- 销售部门维度APP会员数统计 -->
- <select id="selectAppDeptUserStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
- SELECT
- cd.dept_id AS deptId,
- COUNT(DISTINCT CASE WHEN (u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL THEN u.user_id END) AS appUserCount,
- <choose>
- <when test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- COUNT(DISTINCT CASE WHEN ((u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL) AND u.app_create_time >= #{startDate} AND u.app_create_time < CONCAT(#{endDate}, ' 23:59:59') THEN u.user_id END)
- </when>
- <otherwise>
- COUNT(DISTINCT CASE WHEN (u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL THEN u.user_id END)
- </otherwise>
- </choose> AS newAppUserCount,
- COUNT(DISTINCT cu.user_id) AS salesCount
- FROM fs_user u
- INNER JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
- INNER JOIN company_user cu ON cuu.company_user_id = cu.user_id
- INNER JOIN company c ON cuu.company_id = c.company_id
- INNER JOIN company_dept cd ON cu.dept_id = cd.dept_id
- WHERE ((u.source IS NOT NULL AND u.source != '') OR (u.login_device IS NOT NULL AND u.login_device != '') OR u.app_create_time IS NOT NULL)
- AND u.status = 1
- and u.is_del=0
- AND u.status = 1
- AND cuu.status IN (0, 1)
- <if test="companyId != null and companyId != ''">
- AND cuu.company_id = #{companyId}
- </if>
- <if test="deptId != null and deptId != ''">
- AND cu.dept_id = #{deptId}
- </if>
- <if test="salesId != null and salesId != ''">
- AND cu.user_id = #{salesId}
- </if>
- <if test="project != null and project != ''">
- AND cuu.project_id = #{project}
- </if>
- GROUP BY cd.dept_id
- </select>
- <!-- 销售部门维度基础数据+看课统计(合并查询) -->
- <select id="selectAppDeptWatchStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
- SELECT
- cd.dept_id AS deptId,
- cd.dept_name AS salesDept,
- c.company_name AS salesCompany,
- c.company_id AS companyId,
- COUNT( CASE WHEN log.log_type = 2 THEN log.log_id END ) AS finishedCount,
- COUNT(log.log_id)- COUNT(CASE WHEN log.log_type = 2 THEN log.log_id END )AS unfinishedCount,
- COUNT( CASE WHEN log.log_type = 3 THEN log.log_id END ) AS notWatchedCount,
- COUNT( a.watch_log_id ) anscount,
- COALESCE ( SUM( rpl.amount ), 0 ) AS redPacketAmount,
- COUNT( rpl.log_id) AS packetUserCount
- FROM fs_course_watch_log log
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN company c ON log.company_id = c.company_id
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
- LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
- LEFT JOIN fs_course_answer_logs a ON a.watch_log_id = log.log_id
- LEFT JOIN fs_course_red_packet_log rpl ON rpl.watch_log_id = log.log_id
- WHERE log.send_type = 1
- AND log.watch_type = 1
- <include refid="commonConditions"/>
- GROUP BY cd.dept_id
- ORDER BY cd.dept_id
- </select>
- <!-- 销售部门维度订单统计 -->
- <select id="selectAppDeptOrderStats" resultType="com.fs.his.vo.AppSalesWatchLogReportVO">
- SELECT
- cd.dept_id AS deptId,
- log.period_id AS periodId,
- log.video_id AS videoId,
- COUNT(DISTINCT CASE WHEN po.status = 3 THEN po.order_id END) AS historyOrderCount
- FROM fs_course_watch_log log
- LEFT JOIN company_user cu ON log.company_user_id = cu.user_id
- LEFT JOIN company c ON log.company_id = c.company_id
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
- LEFT JOIN fs_package_order po ON po.user_id = log.user_id
- WHERE log.send_type = 1
- AND log.watch_type = 1
- <include refid="commonConditions"/>
- GROUP BY cd.dept_id, log.period_id, log.video_id
- </select>
- <!-- APP用户看课记录列表 -->
- <select id="selectAppUserWatchLogList" resultType="com.fs.course.vo.AppUserWatchLogVO">
- SELECT
- l.log_id AS logId,
- l.course_id AS courseId,
- c.course_name AS courseName,
- c.img_url as imgUrl,
- l.video_id AS videoId,
- v.title AS videoName,
- l.log_type AS logType,
- l.duration AS duration,
- SEC_TO_TIME(l.duration) AS durationFormat,
- l.create_time AS createTime,
- l.finish_time AS finishTime,
- l.watch_type AS watchType
- FROM fs_course_watch_log l
- LEFT JOIN fs_user_course c ON l.course_id = c.course_id
- LEFT JOIN fs_user_course_video v ON l.video_id = v.video_id
- WHERE l.user_id = #{userId} and l.project=#{projectId} and l.company_user_id=#{companyUserId} and l.watch_type=1 and l.send_type=1
- <if test="dateTag != null and dateTag !='' ">
- <choose>
- <when test = "dateTag == '今天'">
- and to_days(l.create_time) = to_days(now())
- </when>
- <when test = "dateTag == '昨天'">
- and l.create_time >= CURDATE() - INTERVAL 1 DAY AND l.create_time < CURDATE()
- </when>
- <when test = "dateTag == '前天'">
- and l.create_time >= CURDATE() - INTERVAL 2 DAY AND l.create_time < CURDATE() - INTERVAL 1 DAY
- </when>
- <when test = "dateTag == '近七天'">
- and l.create_time >= CURDATE() - INTERVAL 7 DAY
- </when>
- </choose>
- </if>
- ORDER BY l.create_time DESC
- </select>
- <!-- 查询用户当日未完课的课程列表 -->
- <select id="selectTodayUnfinishedCourseList" resultType="com.fs.course.vo.TodayUnfinishedCourseVO">
- SELECT
- l.log_id AS logId,
- l.course_id AS courseId,
- l.company_user_id as companyUserId,
- l.company_id as companyId,
- c.course_name AS courseName,
- c.img_url as imgUrl,
- l.video_id AS videoId,
- v.title AS videoName,
- l.log_type AS logType,
- l.duration AS duration,
- v.duration AS totalDuration,
- l.create_time AS createTime,
- l.watch_type AS watchType,
- l.period_id AS periodId,
- l.project as projectId,
- p.period_name AS periodName,
- pd.start_date_time AS startDateTime,
- pd.id as periodDaysId,
- pd.end_date_time AS endDateTime
- FROM fs_course_watch_log l
- LEFT JOIN fs_user_course c ON l.course_id = c.course_id
- LEFT JOIN fs_user_course_video v ON l.video_id = v.video_id
- LEFT JOIN fs_user_course_period_days pd ON l.video_id = pd.video_id AND l.period_id = pd.period_id and pd.del_flag=0
- LEFT JOIN fs_user_course_period p ON l.period_id = p.period_id
- WHERE l.user_id = #{userId}
- AND l.watch_type = 1
- AND l.send_type = 1
- AND l.create_time >= CURDATE()
- AND l.create_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
- AND l.log_type <> 2
- AND NOT EXISTS (
- SELECT 1 FROM fs_course_watch_log f
- WHERE f.user_id = l.user_id
- AND f.video_id = l.video_id
- AND f.log_type = 2
- )
- GROUP BY l.course_id
- ORDER BY l.create_time DESC
- </select>
- </mapper>
|