| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791 |
- <?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>
- </mapper>
|