| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793 |
- <?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,link_id 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>
- <if test="beginTime != null "> and create_time >= #{beginTime}</if>
- <if test="endTime != null "> and create_time < #{endTime}</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,cu.dept_id
- 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.logId !=null'>
- and l.log_id = #{maps.logId}
- </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.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.watchType !=null'>
- and l.watch_type = #{maps.watchType}
- </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 <= #{maps.eTime}
- </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 < date_add(#{maps.upETime}, interval 1 day)
- </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.periodId != null">
- and l.period_id = #{maps.periodId}
- </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.deptId != null and maps.deptId != '' ">
- and cu.dept_id = #{maps.deptId}
- </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>
- <if test="maps.userIds != null and !maps.userIds.isEmpty()">
- AND cu.user_id IN
- <foreach collection='maps.userIds' 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,
- link_id
- )
- 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},
- #{log.linkId}
- )
- </foreach>
- ON DUPLICATE KEY UPDATE
- update_time = NOW(),
- im_msg_send_detail_id = VALUES(im_msg_send_detail_id),
- link_id = VALUES(link_id)
- </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,
- period_id,
- watch_type
- 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.FsCourseWatchLogListVO">
- 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.periodId !=null'>
- and l.period_id = #{maps.periodId}
- </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="selectFsCourseWatchLogStatisticsListVO_COUNT"
- resultType="java.lang.Long">
- SELECT COUNT(*) FROM (
- SELECT
- o.video_id,
- <!-- 用choose保证sendType逻辑互斥,避免GROUP BY字段缺失 -->
- <choose>
- <when test="sendType != 1">
- o.qw_user_id,
- </when>
- <when test="sendType == 1">
- o.company_user_id,
- </when>
- <!-- sendType为null时兜底,避免空指针 -->
- <otherwise>
- o.qw_user_id,
- </otherwise>
- </choose>
- DATE(o.create_time) create_time
- FROM fs_course_watch_log o
- <!-- 动态关联qw_user表 -->
- <if test="sendType != 1">
- LEFT JOIN qw_user qu ON qu.id = o.qw_user_id
- </if>
- 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
- <!-- 动态关联company_user表 -->
- <if test="sendType == 1">
- LEFT JOIN company_user cu ON cu.user_id = o.company_user_id
- </if>
- WHERE 1=1
- <if test = 'companyId != null and companyId != 0'>
- and o.company_id=#{companyId}
- </if>
- <if test = 'userIds != null and userIds.size() > 0'>
- and o.company_user_id in
- <foreach collection='userIds' item='id' open='(' separator=',' close=')'>
- #{id}
- </foreach>
- </if>
- <!-- 发送类型筛选 -->
- <if test="sendType != null">
- AND send_type = #{sendType}
- </if>
- <!-- 开始时间筛选:区分String/Date类型,避免类型比较异常 -->
- <if test="sTime != null">
- <choose>
- <!-- sTime是String类型(yyyy-MM-dd) -->
- <when test="sTime instanceof java.lang.String and sTime.trim() != ''">
- AND o.create_time >= STR_TO_DATE(#{sTime}, '%Y-%m-%d')
- </when>
- <!-- sTime是Date类型 -->
- <otherwise>
- AND o.create_time >= #{sTime}
- </otherwise>
- </choose>
- </if>
- <!-- 结束时间筛选:区分String/Date类型 -->
- <if test="eTime != null">
- <choose>
- <when test="eTime instanceof java.lang.String and eTime.trim() != ''">
- AND o.create_time < DATE_ADD(STR_TO_DATE(#{eTime}, '%Y-%m-%d'), INTERVAL 1 DAY)
- </when>
- <otherwise>
- AND o.create_time < DATE_ADD(#{eTime}, INTERVAL 1 DAY)
- </otherwise>
- </choose>
- </if>
- <!-- 昵称筛选:sendType!=1时关联qw_user -->
- <if test="sendType != 1 and nickName != null and nickName.trim() != ''">
- AND qu.qw_user_name LIKE CONCAT(#{nickName}, '%')
- </if>
- <!-- 昵称筛选:sendType==1时关联company_user -->
- <if test="sendType == 1 and nickName != null and nickName.trim() != ''">
- AND cu.nick_name LIKE CONCAT(#{nickName}, '%')
- </if>
- <!-- 课程ID筛选:加>0判断,避免null值拼接 -->
- <if test="courseId != null and courseId > 0">
- AND o.course_id = #{courseId}
- </if>
- <!-- 视频ID筛选:加>0判断 -->
- <if test="videoId != null and videoId > 0">
- AND o.video_id = #{videoId}
- </if>
- <!-- 分组条件:与子查询字段一致 -->
- GROUP BY
- o.video_id,
- <choose>
- <when test="sendType != 1">
- o.qw_user_id,
- </when>
- <when test="sendType == 1">
- o.company_user_id,
- </when>
- <otherwise>
- o.qw_user_id,
- </otherwise>
- </choose>
- DATE(o.create_time)
- ) AS t
- </select>
- <select id="selectWatchLogForDelete" resultType="com.fs.course.domain.FsCourseWatchLog">
- SELECT
- t1.*,
- t2.duplicate_count
- FROM fs_course_watch_log t1
- INNER JOIN (
- SELECT
- video_id,
- user_id,
- period_id,
- COUNT(*) as duplicate_count,
- MAX(log_id) as max_log_id
- FROM fs_course_watch_log where create_time >=#{createTime} and create_time < #{createTimeEnd}
- GROUP BY video_id, user_id, period_id
- HAVING COUNT(*) > 1
- ) t2 ON t1.video_id = t2.video_id
- AND t1.user_id = t2.user_id
- AND t1.period_id = t2.period_id
- AND t1.log_id = t2.max_log_id
- where t1.create_time >=#{createTime} and t1.create_time < #{createTimeEnd}
- </select>
- <insert id="batchInsert" parameterType="java.util.List">
- INSERT INTO fs_course_watch_log_1 (
- 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,
- sop_id,
- camp_period_time,
- project,
- period_id,
- im_msg_send_detail_id,
- watch_type
- )
- VALUES
- <foreach collection="list" item="log" separator=",">
- (
- #{log.logId}, <!-- 🔴 如果需要保留原id -->
- #{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>
- </insert>
- <delete id="batchDeleteByIds" parameterType="java.util.List">
- DELETE FROM fs_course_watch_log
- WHERE log_id IN
- <foreach collection="ids" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </delete>
- <select id="selectCourseByUserIdForStatusFinish" resultType="com.fs.course.vo.FsUserCourseAppListVO">
- select c.course_name courseName,c.img_url imgUrl,r.title videoName,l.link_id linkId,l.duration,l.video_id videoId,l.user_id userId,l.company_user_id companyUserId,l.log_id logId from fs_course_watch_log l
- left join fs_user_course c on l.course_id =c.course_id
- left join fs_user_course_video r on r.video_id=l.video_id
- WHERE l.user_id = #{userId} and l.log_type = 2
- and l.create_time >= CONCAT(CURDATE(), ' 00:00:00')
- and l.create_time <= CONCAT(CURDATE(), ' 23:59:59')
- </select>
- <select id="selectCourseByUserIdForStatusNotFinish" resultType="com.fs.course.vo.FsUserCourseAppListVO">
- select c.course_name courseName,c.img_url imgUrl,r.title videoName,l.link_id linkId,l.duration,l.video_id videoId,l.user_id userId,l.company_user_id companyUserId,l.log_id logId from fs_course_watch_log l
- left join fs_user_course c on l.course_id =c.course_id
- left join fs_user_course_video r on r.video_id=l.video_id
- WHERE l.user_id = #{userId} and l.log_type != 2
- and l.create_time >= CONCAT(CURDATE(), ' 00:00:00')
- and l.create_time <= CONCAT(CURDATE(), ' 23:59:59')
- </select>
- <select id="getAppCourseLearningOne" resultType="com.fs.course.vo.FsUserCourseAppListVO">
- select c.course_name courseName,c.img_url imgUrl,r.title videoName,l.link_id linkId,l.duration,l.video_id videoId,l.user_id userId,l.company_user_id companyUserId,l.log_id logId from fs_course_watch_log l
- left join fs_user_course c on l.course_id =c.course_id
- left join fs_user_course_video r on r.video_id=l.video_id
- WHERE l.user_id = #{userId} and l.update_time is not null
- order by l.update_time DESC LIMIT 1
- </select>
- <select id="selectCompanyBaseInfo" resultType="com.fs.course.vo.FsCourseReportVO">
- SELECT
- c.company_id AS companyId,
- c.company_name AS companyName
- FROM company c
- <where>
- c.is_del=0
- <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.course.vo.FsCourseReportVO">
- SELECT
- <choose>
- <when test="dimension == 'company'">
- fwl.company_id AS companyId,
- </when>
- <when test="dimension == 'course'">
- fwl.course_id As courseId,
- </when>
- <when test="dimension == 'video'">
- fwl.video_id AS videoId,
- </when>
- </choose>
- COUNT(DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS finishedCount,
- COUNT(CASE WHEN fwl.log_type = 2 THEN fwl.log_id END) AS courseCompleteTimes,
- COUNT(DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END) AS accessCount,
- ifnull(
- ROUND(
- (
- COUNT( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) / count( DISTINCT CASE WHEN fwl.log_type != 3
- THEN fwl.user_id END )) * 100,
- 2
- ),
- 0
- ) AS finishRate
- FROM
- fs_course_watch_log fwl
- <where>
- fwl.send_type = 2
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- AND fwl.create_time >= #{startDate} AND fwl.create_time < DATE_ADD(#{endDate}, INTERVAL 1 DAY)
- </if>
- <choose>
- <when test="dimension == 'company' and companyId != null and companyId > 0">
- AND fwl.company_id = #{companyId}
- </when>
- <when test="dimension == 'video' and videoId != null and videoId > 0">
- AND fwl.video_id = #{videoId}
- </when>
- <when test="dimension == 'course' and courseId != null and courseId != ''">
- AND fwl.course_id = #{courseId}
- </when>
- </choose>
- </where>
- <choose>
- <when test="dimension == 'course'">
- GROUP BY fwl.course_id
- </when>
- <when test="dimension == 'video'">
- GROUP BY fwl.video_id
- </when>
- <otherwise>
- GROUP BY fwl.company_id
- </otherwise>
- </choose>
- ORDER BY accessCount 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
- company_id AS companyId,
- COUNT(CASE WHEN log_type = 4 THEN log_id END) AS stopCount,
- 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
- WHERE l.company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- and l.watch_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
- WHERE rpl.company_id IN
- <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- and rpl.app_id=#{appId}
- <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.source 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>
- <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="selectRedPacketStats" resultType="com.fs.his.vo.WatchLogReportVO">
- SELECT
- rp.watch_log_id as logId,
- SUM(rp.amount) AS redPacketAmount
- 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="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="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="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,
- log.period_id AS periodId,
- log.video_id AS videoId,
- cv.title AS videoTitle,
- cd.dept_id AS deptId,
- c.company_id AS companyId,
- COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '1' THEN log.log_id END) AS unfinishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '3' THEN log.log_id END) AS notWatchedCount,
- COUNT(DISTINCT CASE WHEN a.log_id IS NULL THEN log.log_id END) AS notAnsweredCount,
- COALESCE(SUM(rpl.amount), 0) AS redPacketAmount
- 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 cu.user_id, log.period_id, log.video_id
- ORDER 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,
- log.period_id AS periodId,
- log.video_id AS videoId,
- cv.title AS videoTitle,
- cd.dept_id AS deptId,
- c.company_id AS companyId,
- COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '1' THEN log.log_id END) AS unfinishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '3' THEN log.log_id END) AS notWatchedCount,
- COUNT(DISTINCT CASE WHEN a.log_id IS NULL THEN log.log_id END) AS notAnsweredCount,
- COALESCE(SUM(rpl.amount), 0) AS redPacketAmount
- 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 cu.user_id, log.period_id, log.video_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 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.register_date >= #{startDate} AND u.register_date < DATE_ADD(#{endDate}, INTERVAL 1 DAY) THEN u.user_id END)
- </when>
- <otherwise>
- COUNT(DISTINCT CASE WHEN u.source IS NOT NULL THEN u.user_id END)
- </otherwise>
- </choose> AS newAppUserCount,
- COUNT(DISTINCT cu.user_id) AS salesCount
- FROM fs_user u
- 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 cuu.company_id = c.company_id
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
- WHERE u.source IS NOT NULL
- <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,
- log.period_id AS periodId,
- log.video_id AS videoId,
- cv.title AS videoTitle,
- c.company_id AS companyId,
- COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '1' THEN log.log_id END) AS unfinishedCount,
- COUNT(DISTINCT CASE WHEN log.log_type = '3' THEN log.log_id END) AS notWatchedCount,
- COUNT(DISTINCT CASE WHEN a.log_id IS NULL THEN log.log_id END) AS notAnsweredCount,
- COALESCE(SUM(rpl.amount), 0) AS redPacketAmount
- 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, log.period_id, log.video_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会员数统计(直接查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 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.register_date >= #{startDate} AND u.register_date < DATE_ADD(#{endDate}, INTERVAL 1 DAY) THEN u.user_id END)
- </when>
- <otherwise>
- COUNT(DISTINCT CASE WHEN u.source IS NOT NULL THEN u.user_id END)
- </otherwise>
- </choose> AS newAppUserCount
- FROM fs_user u
- 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 cuu.company_id = c.company_id
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
- WHERE u.source IS NOT NULL
- <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>
- <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>
- <!-- 记录类型 1看课中 2完课 3待看课 4看课中断 -->
- <select id="selectAppSalesCourseStatisticsVO" resultType="com.fs.his.vo.AppSalesCourseStatisticsVO">
- SELECT l.company_user_id,l.course_id,l.video_id,
- cu.nick_name as salesName,fuc.course_name as courseName,fuv.title as videoTitle,
- SUM(CASE WHEN l.log_type = 2 THEN 1 ELSE 0 END) AS finishedCount,
- SUM(CASE WHEN l.log_type = 3 THEN 1 ELSE 0 END) AS notWatchedCount,
- SUM(CASE WHEN l.log_type = 4 THEN 1 ELSE 0 END) AS interruptCount,
- SUM(CASE WHEN l.log_type = 1 THEN 1 ELSE 0 END) AS watchingCount
- from fs_course_watch_log l
- left join company_user cu on l.company_user_id=cu.user_id
- left join fs_user_course fuc on l.course_id=fuc.course_id
- left join fs_user_course_video fuv on l.video_id=fuv.video_id
- where send_type = 1 and watch_type =1
- <if test="companyId != null ">
- and l.company_id = #{companyId}
- </if>
- <if test="companyUserId != null ">
- and l.company_user_id = #{companyUserId}
- </if>
- <if test="courseId != null ">
- and l.course_id = #{courseId}
- </if>
- <if test="videoId != null ">
- and l.video_id = #{videoId}
- </if>
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- and l.create_time >= #{startDate} and l.create_time <= #{endDate}
- </if>
- group by l.company_user_id,l.course_id,l.video_id
- </select>
- <select id="selectCourseFinishCount" resultType="com.fs.company.vo.CompanyRedPacketStatisticsVO">
- select l.company_user_id,
- SUM(CASE WHEN l.log_type = 2 THEN 1 ELSE 0 END) AS finishCount
- from fs_course_watch_log l
- where l.send_type = 1 and l.log_type = 2
- and l.company_id=#{companyId}
- <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
- and l.create_time >= #{startDate} and l.create_time <= #{endDate}
- </if>
- <if test="companyUserId !=null">
- l.company_user_id = #{companyUserId}
- </if>
- group by l.company_user_id
- </select>
- </mapper>
|