12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355 |
- <?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.his.mapper.FsUserMapper">
- <resultMap type="FsUser" id="FsUserResult">
- <result property="userId" column="user_id" />
- <result property="nickName" column="nick_name" />
- <result property="avatar" column="avatar" />
- <result property="phone" column="phone" />
- <result property="integral" column="integral" />
- <result property="status" column="status" />
- <result property="tuiUserId" column="tui_user_id" />
- <result property="tuiTime" column="tui_time" />
- <result property="tuiUserCount" column="tui_user_count" />
- <result property="maOpenId" column="ma_open_id" />
- <result property="mpOpenId" column="mp_open_id" />
- <result property="unionId" column="union_id" />
- <result property="isDel" column="is_del" />
- <result property="userCode" column="user_code" />
- <result property="remark" column="remark" />
- <result property="createTime" column="create_time" />
- <result property="updateTime" column="update_time" />
- <result property="lastIp" column="last_ip" />
- <result property="balance" column="balance" />
- <result property="signNum" column="sign_num" />
- <result property="integralStatus" column="integral_status" />
- <result property="isBuy" column="is_buy" />
- <result property="password" column="password" />
- <result property="isVip" column="is_vip" />
- <result property="jpushId" column="jpush_id" />
- <result property="vipStartDate" column="vip_start_date" />
- <result property="vipEndDate" column="vip_end_date" />
- <result property="vipLevel" column="vip_level" />
- <result property="vipStatus" column="vip_status" />
- <result property="sex" column="sex" />
- <result property="storeOpenId" column="store_open_id" />
- <result property="isPush" column="is_push" />
- <result property="isIndividuationPush" column="is_individuation_push" />
- <result property="isWeixinAuth" column="is_weixin_auth" />
- <result property="companyId" column="company_id"/>
- <result property="companyUserId" column="company_user_id"/>
- <result property="loginDevice" column="login_device" />
- <result property="source" column="source" />
- <result property="isAddQw" column="is_add_qw" />
- <result property="parentId" column="parent_id" />
- <result property="courseMaOpenId" column="course_ma_open_id" />
- <result property="qwExtId" column="qw_ext_id" />
- <result property="qwUserId" column="qw_user_id" />
- </resultMap>
- <sql id="selectFsUserVo">
- select user_id,qw_ext_id,sex,is_buy,course_ma_open_id,is_push,is_add_qw,source,login_device,is_individuation_push,store_open_id,password,jpush_id, is_vip,vip_start_date,vip_end_date,vip_level,vip_status,nick_name,integral_status, avatar, phone, integral,sign_num, status, tui_user_id, tui_time, tui_user_count, ma_open_id, mp_open_id, union_id, is_del, user_code, remark, create_time, update_time, last_ip, balance,is_weixin_auth,parent_id,qw_user_id,company_id,company_user_id from fs_user
- </sql>
- <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
- <include refid="selectFsUserVo"/>
- <where>
- <if test="nickName != null and nickName != ''"> and nick_name like concat( #{nickName}, '%')</if>
- <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
- <if test="phone != null and phone != ''"> and phone = #{phone}</if>
- <if test="integral != null "> and integral = #{integral}</if>
- <if test="signNum != null "> and sign_num = #{signNum}</if>
- <if test="status != null "> and status = #{status}</if>
- <if test="tuiUserId != null and tuiUserId != ''"> and tui_user_id = #{tuiUserId}</if>
- <if test="tuiTime != null "> and tui_time = #{tuiTime}</if>
- <if test="tuiUserCount != null "> and tui_user_count = #{tuiUserCount}</if>
- <if test="maOpenId != null and maOpenId != ''"> and ma_open_id = #{maOpenId}</if>
- <if test="mpOpenId != null and mpOpenId != ''"> and mp_open_id = #{mpOpenId}</if>
- <if test="unionId != null and unionId != ''"> and union_id = #{unionId}</if>
- <if test="isDel != null "> and is_del = #{isDel}</if>
- <if test="userCode != null and userCode != ''"> and user_code = #{userCode}</if>
- <if test="lastIp != null and lastIp != ''"> and last_ip = #{lastIp}</if>
- <if test="balance != null "> and balance = #{balance}</if>
- </where>
- </select>
- <select id="selectFsUserByUserId" parameterType="Long" resultMap="FsUserResult">
- <include refid="selectFsUserVo"/>
- where user_id = #{userId}
- </select>
- <select id="courseAnalysisWatchLog" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
- SELECT
- count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS courseWatchNum,
- count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTimes,
- count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS courseCompleteNum,
- count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTimes,
- 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 completeRate,
- fwl.video_id
- FROM
- fs_course_watch_log fwl
- <where>
- <if test="periodId != null and periodId != ''">
- AND fwl.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fwl.video_id = #{videoId}
- </if>
- <if test="videoIdList != null and videoIdList.size > 0 ">
- AND fwl.video_id in
- <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
- #{videoId}
- </foreach>
- </if>
- </where>
- GROUP BY
- fwl.video_id
- </select>
- <select id="courseAnalysisRedPacketCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
- SELECT
- count( flog.log_id ) as redPacketNum,
- ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
- flog.video_id
- FROM
- fs_course_red_packet_log flog
- LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- <where>
- <if test="companyUserId != null and companyUserId != 0 ">
- AND fs_user.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND flog.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND flog.video_id = #{videoId}
- </if>
- <if test="videoIdList != null and videoIdList.size > 0 ">
- AND flog.video_id in
- <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
- #{videoId}
- </foreach>
- </if>
- </where>
- GROUP BY
- flog.video_id
- </select>
- <select id="courseAnalysisAnswerCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
- SELECT
- count( DISTINCT fs_user.user_id ) as answerNum,
- count(fs_course_answer_logs.log_id) answerTimes,
- COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
- COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) as answerRightTimes,
- ifnull(
- ROUND(
- (
- COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
- 2
- ),
- 0
- ) as answerRightRate,
- fs_course_answer_logs.video_id
- FROM
- fs_course_answer_logs
- LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- <where>
- <if test="companyUserId != null and companyUserId != 0 ">
- AND fs_user.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fs_course_answer_logs.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fs_course_answer_logs.video_id = #{videoId}
- </if>
- <if test="videoIdList != null and videoIdList.size > 0 ">
- AND fs_course_answer_logs.video_id in
- <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
- #{videoId}
- </foreach>
- </if>
- </where>
- GROUP BY
- fs_course_answer_logs.video_id
- </select>
- <select id="selectFsUserById" parameterType="Long" resultMap="FsUserResult">
- <include refid="selectFsUserVo"/>
- where user_id = #{userId}
- </select>
- <select id="selectFsUserPageList" resultType="com.fs.store.vo.h5.FsUserPageListVO">
- SELECT
- fs_user.*,
- fs_user_course_count.id,
- fs_user_course_count.watch_course_count,
- fs_user_course_count.miss_course_count,
- fs_user_course_count.miss_course_status,
- fs_user_course_count.course_ids,
- fs_user_course_count.part_course_count,
- fs_user_course_count.last_watch_date,
- fs_user_course_count.STATUS AS courseCountStatus,
- fs_user_course_count.stop_watch_days,
- fs_user_course_count.complete_watch_date,
- GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
- GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
- company_user.nick_name as companyUserNickName,
- fs_user_company_user.is_repeat_fans
- FROM
- fs_user
- LEFT JOIN fs_user_course_count ON fs_user.user_id = fs_user_course_count.user_id
- LEFT JOIN company_tag_user ON fs_user.user_id = company_tag_user.user_id
- LEFT JOIN company_tag ON FIND_IN_SET(company_tag.tag_id, company_tag_user.tag_ids) > 0
- LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
- where fs_user.is_del = 0
- <if test="userId != null and userId!= 0 ">
- and fs_user.company_user_id = #{userId}
- </if>
- <if test="companyId != null ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="companyUserId != null and companyUserId!= '' ">
- and fs_user.company_user_id = #{companyUserId}
- </if>
- <choose>
- <when test = "isBlack">
- AND (fs_user.status = 0 or fs_user_company_user.is_repeat_fans = 1)
- </when>
- <otherwise>
- AND (fs_user.status = 1 and fs_user_company_user.is_repeat_fans = 0)
- </otherwise>
- </choose>
- <if test="keyword != null and keyword !='' ">
- AND (fs_user.nick_name LIKE concat('%',#{keyword},'%')
- or fs_user.phone LIKE concat('%',#{keyword},'%')
- )
- </if>
- <if test="registerStartTime != null and registerStartTime !='' ">
- AND fs_user.create_time >= #{registerStartTime}
- </if>
- <if test="registerEndTime != null and registerEndTime !='' ">
- AND fs_user.create_time <= #{registerEndTime}
- </if>
- <if test="tagIds != null and tagIds.length > 0">
- AND
- <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
- CONCAT(',', company_tag_user.tag_ids, ',') LIKE CONCAT('%,', #{item}, ',%')
- </foreach>
- </if>
- <if test="tabValue != null and tabValue !='' ">
- <choose>
- <when test = "tabValue == 1">
- AND DAY(fs_user.create_time) = DAY(NOW())
- </when>
- <when test = "tabValue == 2">
- AND DAY(fs_user_course_count.complete_watch_date) = DAY(NOW())
- </when>
- <when test = "tabValue == 3">
- AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
- </when>
- </choose>
- </if>
- <if test="watchCourseType != null and watchCourseType !='' ">
- <choose>
- <when test = "watchCourseType == 1">
- AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
- </when>
- <when test = "watchCourseType == 2">
- AND fs_user_course_count.status = 1
- </when>
- <when test = "watchCourseType == 3">
- AND fs_user_course_count.status = 2
- </when>
- </choose>
- </if>
- <if test="missCourseStatus != null and missCourseStatus !='' ">
- <choose>
- <when test = "missCourseStatus == 1">
- AND fs_user_course_count.miss_course_status = 1
- </when>
- <when test = "missCourseStatus == 2">
- AND (fs_user_course_count.miss_course_status = 2 or fs_user_course_count.miss_course_status is null )
- </when>
- </choose>
- </if>
- group by fs_user.user_id
- <if test="continueMissCourseSort != null and continueMissCourseSort !='' ">
- order by
- <choose>
- <when test = "continueMissCourseSort == 0">
- fs_user.create_time desc
- </when>
- <when test = "continueMissCourseSort == 1">
- fs_user.nick_name asc
- </when>
- </choose>
- </if>
- </select>
- <select id="selectFsUserPageListNew" resultType="com.fs.store.vo.h5.FsUserPageListVO">
- SELECT
- fs_user.user_id,
- fs_user.nick_name,
- fs_user.avatar,
- fs_user.phone,
- fs_user.status,
- fs_user.create_time,
- fs_user.remark,
- fs_user.company_user_id,
- fs_user.company_id
- FROM
- fs_user
- <where>
- fs_user.is_del = 0
- <if test="registerStartTime != null and registerStartTime !='' ">
- AND fs_user.create_time >= #{registerStartTime}
- </if>
- <if test="registerEndTime != null and registerEndTime !='' ">
- AND fs_user.create_time <= #{registerEndTime}
- </if>
- <if test="companyUserIds != null and companyUserIds.size > 0">
- AND fs_user.company_user_id in
- <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
- ${item}
- </foreach>
- </if>
- <if test="nickname != null and nickname != ''">
- AND fs_user.nick_name like concat(#{nickname},'%')
- </if>
- <if test="phone != null and phone != ''">
- AND fs_user.phone = #{phone}
- </if>
- </where>
- limit ${(pageNum-1)*pageSize},${pageSize}
- </select>
- <select id="selectFsUserPageListCount" resultType="java.lang.Long">
- SELECT
- count(1)
- FROM
- fs_user
- <where>
- fs_user.is_del = 0
- <if test="registerStartTime != null and registerStartTime !='' ">
- AND fs_user.create_time >= #{registerStartTime}
- </if>
- <if test="registerEndTime != null and registerEndTime !='' ">
- AND fs_user.create_time <= #{registerEndTime}
- </if>
- <if test="companyUserIds != null and companyUserIds.size > 0">
- AND fs_user.company_user_id in
- <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
- ${item}
- </foreach>
- </if>
- <if test="nickname != null and nickname!=''">
- AND fs_user.nick_name like concat(#{nickname},'%')
- </if>
- <if test="phone != null and phone!=''">
- AND fs_user.phone = #{phone}
- </if>
- </where>
- </select>
- <update id="transferCompanyUser">
- update fs_user
- set company_user_id=#{targetCompanyUserId}
- where
- user_id in
- <foreach collection="userIds" open="(" close=")" separator="," item="item">
- ${item}
- </foreach>
- </update>
- <update id="batchUpdateFsUserByIds" parameterType="Long">
- update fs_user
- set status = #{status} where user_id in
- <foreach item="id" collection="ids" open="(" separator="," close=")">
- #{id}
- </foreach>
- </update>
- <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
- insert into fs_user
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="nickName != null">nick_name,</if>
- <if test="avatar != null">avatar,</if>
- <if test="phone != null">phone,</if>
- <if test="integral != null">integral,</if>
- <if test="signNum != null">sign_num,</if>
- <if test="status != null">status,</if>
- <if test="tuiUserId != null">tui_user_id,</if>
- <if test="tuiTime != null">tui_time,</if>
- <if test="tuiUserCount != null">tui_user_count,</if>
- <if test="maOpenId != null">ma_open_id,</if>
- <if test="mpOpenId != null">mp_open_id,</if>
- <if test="unionId != null">union_id,</if>
- <if test="isDel != null">is_del,</if>
- <if test="userCode != null">user_code,</if>
- <if test="remark != null">remark,</if>
- <if test="createTime != null">create_time,</if>
- <if test="updateTime != null">update_time,</if>
- <if test="lastIp != null">last_ip,</if>
- <if test="balance != null">balance,</if>
- <if test="integralStatus != null">integral_status,</if>
- <if test="isBuy != null">is_buy,</if>
- <if test="password != null">password,</if>
- <if test="jpushId != null">jpush_id,</if>
- <if test="isVip != null">is_vip,</if>
- <if test="vipStartDate != null">vip_start_date,</if>
- <if test="vipEndDate != null">vip_end_date,</if>
- <if test="vipLevel != null">vip_level,</if>
- <if test="vipStatus != null">vip_status,</if>
- <if test="sex != null">sex,</if>
- <if test="storeOpenId != null">store_open_id,</if>
- <if test="isPush != null">is_push,</if>
- <if test="isIndividuationPush != null">is_individuation_push,</if>
- <if test="isWeixinAuth != null">is_weixin_auth,</if>
- <if test="loginDevice != null">login_device,</if>
- <if test="source != null">source,</if>
- <if test="isAddQw != null">is_add_qw,</if>
- <if test="courseMaOpenId != null">course_ma_open_id,</if>
- <if test="qwExtId != null">qw_ext_id,</if>
- <if test="companyId != null">company_id,</if>
- <if test="companyUserId != null">company_user_id,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="nickName != null">#{nickName},</if>
- <if test="avatar != null">#{avatar},</if>
- <if test="phone != null">#{phone},</if>
- <if test="integral != null">#{integral},</if>
- <if test="signNum != null">#{signNum},</if>
- <if test="status != null">#{status},</if>
- <if test="tuiUserId != null">#{tuiUserId},</if>
- <if test="tuiTime != null">#{tuiTime},</if>
- <if test="tuiUserCount != null">#{tuiUserCount},</if>
- <if test="maOpenId != null">#{maOpenId},</if>
- <if test="mpOpenId != null">#{mpOpenId},</if>
- <if test="unionId != null">#{unionId},</if>
- <if test="isDel != null">#{isDel},</if>
- <if test="userCode != null">#{userCode},</if>
- <if test="remark != null">#{remark},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="updateTime != null">#{updateTime},</if>
- <if test="lastIp != null">#{lastIp},</if>
- <if test="balance != null">#{balance},</if>
- <if test="integralStatus != null">#{integralStatus},</if>
- <if test="isBuy != null">#{isBuy},</if>
- <if test="password != null">#{password},</if>
- <if test="jpushId != null">#{jpushId},</if>
- <if test="isVip != null">#{isVip},</if>
- <if test="vipStartDate != null">#{vipStartDate},</if>
- <if test="vipEndDate != null">#{vipEndDate},</if>
- <if test="vipLevel != null">#{vipLevel},</if>
- <if test="vipStatus != null">#{vipStatus},</if>
- <if test="sex != null">#{sex},</if>
- <if test="storeOpenId != null">#{storeOpenId},</if>
- <if test="isPush != null">#{isPush},</if>
- <if test="isIndividuationPush != null">#{isIndividuationPush},</if>
- <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
- <if test="loginDevice != null">#{loginDevice},</if>
- <if test="source != null">#{source},</if>
- <if test="isAddQw != null">#{isAddQw},</if>
- <if test="courseMaOpenId != null">#{courseMaOpenId},</if>
- <if test="qwExtId != null">#{qwExtId},</if>
- <if test="companyId != null">#{companyId},</if>
- <if test="companyUserId != null">#{companyUserId},</if>
- </trim>
- </insert>
- <update id="updateFsUser" parameterType="FsUser">
- update fs_user
- <trim prefix="SET" suffixOverrides=",">
- <if test="nickName != null">nick_name = #{nickName},</if>
- <if test="avatar != null">avatar = #{avatar},</if>
- <if test="phone != null">phone = #{phone},</if>
- <if test="integral != null">integral = #{integral},</if>
- <if test="signNum != null">sign_num = #{signNum},</if>
- <if test="status != null">status = #{status},</if>
- <if test="tuiUserId != null">tui_user_id = #{tuiUserId},</if>
- <if test="tuiTime != null">tui_time = #{tuiTime},</if>
- <if test="tuiUserCount != null">tui_user_count = #{tuiUserCount},</if>
- <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
- <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
- <if test="unionId != null">union_id = #{unionId},</if>
- <if test="isDel != null">is_del = #{isDel},</if>
- <if test="userCode != null">user_code = #{userCode},</if>
- <if test="remark != null">remark = #{remark},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="updateTime != null">update_time = #{updateTime},</if>
- <if test="lastIp != null">last_ip = #{lastIp},</if>
- <if test="balance != null">balance = #{balance},</if>
- <if test="integralStatus != null">integral_status = #{integralStatus},</if>
- <if test="isBuy != null">is_buy = #{isBuy},</if>
- <if test="password != null">password = #{password},</if>
- <if test="jpushId != null">jpush_id = #{jpushId},</if>
- <if test="isVip != null">is_vip = #{isVip},</if>
- <if test="vipStartDate != null">vip_start_date = #{vipStartDate},</if>
- <if test="vipEndDate != null">vip_end_date = #{vipEndDate},</if>
- <if test="vipLevel != null">vip_level = #{vipLevel},</if>
- <if test="vipStatus != null">vip_status = #{vipStatus},</if>
- <if test="sex != null">sex = #{sex},</if>
- <if test="storeOpenId != null">store_open_id = #{storeOpenId},</if>
- <if test="isPush != null">is_push = #{isPush},</if>
- <if test="isIndividuationPush != null">is_individuation_push = #{isIndividuationPush},</if>
- <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
- <if test="loginDevice != null">login_device = #{loginDevice},</if>
- <if test="source != null">source = #{source},</if>
- <if test="isAddQw != null">is_add_qw = #{isAddQw},</if>
- <if test="courseMaOpenId != null">course_ma_open_id = #{courseMaOpenId},</if>
- <if test="parentId != null">parent_id = #{parentId},</if>
- <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
- <if test="companyId != null">company_id = #{companyId},</if>
- <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
- </trim>
- where user_id = #{userId}
- </update>
- <delete id="deleteFsUserByUserId" parameterType="Long">
- delete from fs_user where user_id = #{userId}
- </delete>
- <delete id="deleteFsUserByUserIds" parameterType="Long">
- delete from fs_user where user_id in
- <foreach item="userId" collection="array" open="(" separator="," close=")">
- #{userId}
- </foreach>
- </delete>
- <update id="batchUpdateUserCompanyUser">
- update fs_user
- set company_id = #{companyId},
- company_user_id = #{companyUserId}
- where
- <foreach collection="userIds" separator="or" item="userId" index="index">
- user_id = #{userId}
- </foreach>
- </update>
- <select id="selectUserListByMap" resultType="com.fs.his.vo.OptionsVO">
- select
- u.user_id dictValue,
- u.nick_name dictLabel
- from fs_user u
- <where>
- <if test="params.nickName != null and params.nickName != ''">
- u.nick_name like concat('%', #{params.nickName}, '%')
- </if>
- </where>
- </select>
- <select id ="selectFsUserByUserIds" resultType="Integer">
- select count(1) from fs_user_company_user
- LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
- where is_repeat_fans = 1
- and (fs_user_company_user.company_user_id = #{companyUserId} OR company_user.parent_id = #{companyUserId})
- <if test="userIds != null and userIds.length > 0 ">
- and fs_user_company_user.user_id in
- <foreach collection="userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- </if>
- </select>
- <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
- select
- count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
- count(u.user_id) vipCount
- from fs_user u
- where u.company_user_id = #{companyUserId}
- </select>
- <select id="getUserNumber" resultType="com.fs.store.vo.h5.UserListCountVO">
- SELECT
- fs_user.`status` as status,
- count( DISTINCT fs_user.user_id ) AS num
- FROM
- fs_user
- LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
- WHERE fs_user.is_del = 0
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and fs_user.company_id = #{companyId}
- </if>
- GROUP BY
- fs_user.`status`
- </select>
- <select id="getRepeatUserNumber" resultType="int">
- SELECT
- count( DISTINCT fs_user.user_id ) AS num
- FROM
- fs_user
- LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
- WHERE
- ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
- AND fs_user.is_del = 0
- AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
- </select>
- <select id="getCountWatchCourse" resultType="com.fs.store.vo.h5.UserDetailsVO">
- SELECT
- <if test="dateTag == null or dateTag =='' or dateTag == '近七天' ">
- ifnull( sum(complete_watch_count), 0 ) AS completeWatchCount ,
- ifnull( sum(watch_times), 0 ) AS watchTimes,
- </if>
- <if test="dateTag != null and dateTag !='' and dateTag != '近七天' ">
- ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
- ifnull( watch_times, 0 ) AS watchTimes,
- </if>
- fs_user.user_id
- FROM
- fs_user_course_count
- LEFT JOIN fs_user ON fs_user.user_id = fs_user_course_count.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- <where>
- <if test="dateTag != null and dateTag !='' ">
- <choose>
- <when test = "dateTag == '今天'">
- and to_days(fs_user_course_count.create_time) = to_days(now())
- </when>
- <when test = "dateTag == '昨天'">
- and fs_user_course_count.create_time >= CURDATE() - INTERVAL 1 DAY AND fs_user_course_count.create_time < CURDATE()
- </when>
- <when test = "dateTag == '前天'">
- and fs_user_course_count.create_time >= CURDATE() - INTERVAL 2 DAY AND fs_user_course_count.create_time < CURDATE() - INTERVAL 1 DAY
- </when>
- <when test = "dateTag == '近七天'">
- and fs_user_course_count.create_time >= CURDATE() - INTERVAL 7 DAY
- </when>
- </choose>
- </if>
- and fs_user.user_id = #{fsUserId}
- </where>
- GROUP BY
- fs_user.user_id
- </select>
- <select id="getCountAnswer" resultType="com.fs.store.vo.h5.UserDetailsVO">
- SELECT
- (
- SELECT
- ifnull(count( DISTINCT log_id ), 0) AS answerTime
- FROM
- fs_course_answer_logs
- LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- <where>
- <if test="dateTag != null and dateTag !='' ">
- <choose>
- <when test = "dateTag == '今天'">
- and to_days(fs_course_answer_logs.create_time) = to_days(now())
- </when>
- <when test = "dateTag == '昨天'">
- and fs_course_answer_logs.create_time >= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time < CURDATE()
- </when>
- <when test = "dateTag == '前天'">
- and fs_course_answer_logs.create_time >= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time < CURDATE() - INTERVAL 1 DAY
- </when>
- <when test = "dateTag == '近七天'">
- and fs_course_answer_logs.create_time >= CURDATE() - INTERVAL 7 DAY
- </when>
- </choose>
- </if>
- and fs_user.user_id = #{fsUserId}
- </where>
- GROUP BY
- fs_user.user_id
- ) AS answerTime,
- (
- SELECT
- ifnull(count( DISTINCT log_id ), 0) AS answerRightTime
- FROM
- fs_course_answer_logs
- LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- <where>
- fs_course_answer_logs.is_right = 1
- <if test="dateTag != null and dateTag !='' ">
- <choose>
- <when test = "dateTag == '今天'">
- and to_days(fs_course_answer_logs.create_time) = to_days(now())
- </when>
- <when test = "dateTag == '昨天'">
- and fs_course_answer_logs.create_time >= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time < CURDATE()
- </when>
- <when test = "dateTag == '前天'">
- and fs_course_answer_logs.create_time >= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time < CURDATE() - INTERVAL 1 DAY
- </when>
- <when test = "dateTag == '近七天'">
- and fs_course_answer_logs.create_time >= CURDATE() - INTERVAL 7 DAY
- </when>
- </choose>
- </if>
- and fs_user.user_id = #{fsUserId}
- </where>
- GROUP BY
- fs_user.user_id
- ) AS answerRightTime;
- </select>
- <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
- SELECT
- ifnull( count( DISTINCT log_id ), 0 ) AS answerRedPacketTime,
- ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
- fs_user.user_id
- FROM
- fs_course_red_packet_log
- LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- <where>
- fs_course_red_packet_log.status = 1
- <if test="dateTag != null and dateTag !='' ">
- <choose>
- <when test = "dateTag == '今天'">
- and to_days(fs_course_red_packet_log.create_time) = to_days(now())
- </when>
- <when test = "dateTag == '昨天'">
- and fs_course_red_packet_log.create_time >= CURDATE() - INTERVAL 1 DAY AND fs_course_red_packet_log.create_time < CURDATE()
- </when>
- <when test = "dateTag == '前天'">
- and fs_course_red_packet_log.create_time >= CURDATE() - INTERVAL 2 DAY AND fs_course_red_packet_log.create_time < CURDATE() - INTERVAL 1 DAY
- </when>
- <when test = "dateTag == '近七天'">
- and fs_course_red_packet_log.create_time >= CURDATE() - INTERVAL 7 DAY
- </when>
- </choose>
- </if>
- and fs_user.user_id = #{fsUserId}
- </where>
- GROUP BY
- fs_user.user_id
- </select>
- <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
- SELECT (SELECT count(fs_user.user_id)
- FROM fs_user
- LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- WHERE fs_user.is_del = 0
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and fs_user.company_id = #{companyId}
- </if>
- ) as userTotal,
- (SELECT count(fs_user.user_id)
- FROM fs_user
- LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- WHERE fs_user.is_del = 0
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and fs_user.company_id = #{companyId}
- </if>
- AND to_days(fs_user.create_time) = to_days(now())) as todayNewUser
- </select>
- <select id="countTag" resultType="com.fs.store.vo.h5.FsUserSummaryCountTagVO">
- SELECT
- company_tag.tag AS tagName,
- count( fs_user.user_id ) AS number
- FROM
- company_tag_user
- LEFT JOIN fs_user ON fs_user.user_id = company_tag_user.user_id
- LEFT JOIN company_tag ON FIND_IN_SET( company_tag.tag_id, company_tag_user.tag_ids ) > 0
- LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- <where>
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and fs_user.company_id = #{companyId}
- </if>
- and company_tag.tag_id is not null
- </where>
- GROUP BY
- company_tag.tag_id
- </select>
- <select id="countUserCourse" resultType="Map">
- SELECT
- (
- SELECT
- count(distinct fcc.user_id )
- FROM
- fs_user_course_count fcc
- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
- LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
- <where>
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="startTime != null and startTime !='' ">
- and fcc.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and fcc.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fcpd.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fcpd.video_id = #{videoId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND company_user.user_id = #{companyUserId}
- </if>
- </where>
- ) as courseWatchNum,
- (
- SELECT
- count(distinct fcc.user_id )
- FROM
- fs_user_course_count fcc
- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
- LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
- <where>
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- AND fcc.complete_watch_count > 0
- <if test="startTime != null and startTime !='' ">
- and fcc.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and fcc.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fcpd.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fcpd.video_id = #{videoId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND company_user.user_id = #{companyUserId}
- </if>
- </where>
- ) as courseCompleteNum
- </select>
- <select id="countUserAnswer" resultType="Map">
- SELECT
- (
- SELECT
- count(distinct fs_user.user_id )
- FROM
- fs_course_answer_logs
- LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- <where>
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="startTime != null and startTime !='' ">
- AND fs_course_answer_logs.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND fs_course_answer_logs.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fs_course_answer_logs.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fs_course_answer_logs.video_id = #{videoId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND company_user.user_id = #{companyUserId}
- </if>
- </where>
- ) AS answerNum,
- (
- SELECT
- count(distinct fs_user.user_id )
- FROM
- fs_course_answer_logs
- LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- <where>
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- AND fs_course_answer_logs.is_right = 1
- <if test="startTime != null and startTime !='' ">
- AND fs_course_answer_logs.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND fs_course_answer_logs.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fs_course_answer_logs.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fs_course_answer_logs.video_id = #{videoId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND company_user.user_id = #{companyUserId}
- </if>
- </where>
- ) AS answerRightNum
- </select>
- <select id="countCourseDetails" resultType="Map">
- select (SELECT
- count( DISTINCT fcpd.period_id )
- FROM
- fs_user_course_period_days fcpd
- LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
- LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
- WHERE 1=1
- AND FIND_IN_SET(#{companyId}, fpd.company_id)
- <if test="userId != null and userId != 0 ">
- AND fs_user.company_user_id = #{userId}
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fcpd.period_id = #{periodId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND fs_user.company_user_id = #{companyUserId}
- </if>
- ) as courseNum,
- (SELECT count(DISTINCT fcpd.video_id)
- FROM fs_user_course_period_days fcpd
- LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
- LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
- WHERE 1=1
- AND FIND_IN_SET(#{companyId}, fpd.company_id)
- <if test="userId != null and userId != 0 ">
- AND fs_user.company_user_id = #{userId}
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fcpd.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fcpd.video_id = #{videoId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND fs_user.company_user_id = #{companyUserId}
- </if>
- ) as videoNum,
- ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
- <if test="periodId != null and periodId != ''">
- AND fcpd.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fcpd.video_id = #{videoId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND fs_user.company_user_id = #{companyUserId}
- </if>
- <where>
- <if test="userId != null and userId != 0 ">
- AND fs_user.company_user_id = #{userId}
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- </where>
- ) as courseUserNum
- </select>
- <select id="countUserRankingByComplete" resultType="com.fs.store.vo.h5.FsUserRankingVO">
- SELECT
- company_user.nick_name as userName,
- ifnull(
- ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
- ) as completeRate
- FROM
- fs_user_course_count fcc
- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
- LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
- <where>
- <if test="userId != null and userId != 0 ">
- AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="startTime != null and startTime !='' ">
- AND fcc.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND fcc.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fcpd.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fcpd.video_id = #{videoId}
- </if>
- </where>
- group by fcc.user_id
- <choose>
- <when test="order != null and order == 'asc'">
- order by completeRate asc
- </when>
- <when test="order != null and order == 'desc'">
- order by completeRate desc
- </when>
- <otherwise>
- order by completeRate desc
- </otherwise>
- </choose>
- limit 20
- </select>
- <select id="countUserRankingByRight" resultType="com.fs.store.vo.h5.FsUserRankingVO">
- SELECT
- company_user.nick_name as userName,
- ifnull(ROUND(
- (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
- *100,2),0
- ) as answerRightRate
- FROM
- fs_course_answer_logs
- LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- <where>
- <if test="userId != null and userId != 0 ">
- AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="startTime != null and startTime !='' ">
- AND fs_course_answer_logs.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND fs_course_answer_logs.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fs_course_answer_logs.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fs_course_answer_logs.video_id = #{videoId}
- </if>
- </where>
- group by fs_user.user_id
- <choose>
- <when test="order != null and order == 'asc'">
- order by answerRightRate asc
- </when>
- <when test="order != null and order == 'desc'">
- order by answerRightRate desc
- </when>
- <otherwise>
- order by answerRightRate desc
- </otherwise>
- </choose>
- limit 20
- </select>
- <select id="countCourseRankingByComplete" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
- SELECT
- fcv.title AS videoName,
- ifnull(
- ROUND((
- COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))* 100,
- 2
- ),
- 0
- ) AS completeRate
- FROM
- fs_user_course_count fcc
- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
- LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
- LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fcpd.video_id
- <where>
- <if test="userId != null and userId != 0 ">
- AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="startTime != null and startTime !='' ">
- AND fcc.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND fcc.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fcpd.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fcpd.video_id = #{videoId}
- </if>
- </where>
- GROUP BY
- fcpd.video_id
- <choose>
- <when test="order != null and order == 'asc'">
- ORDER BY completeRate asc
- </when>
- <when test="order != null and order == 'desc'">
- ORDER BY completeRate desc
- </when>
- <otherwise>
- ORDER BY completeRate desc
- </otherwise>
- </choose>
- LIMIT 20
- </select>
- <select id="countCourseRankingByRight" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
- SELECT
- fcv.title AS videoName,
- ifnull(
- ROUND(
- (
- COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1)) * 100,
- 2
- ),
- 0
- ) AS answerRightRate
- FROM
- fs_course_answer_logs
- LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
- <where>
- <if test="userId != null and userId != 0 ">
- AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="startTime != null and startTime !='' ">
- AND fs_course_answer_logs.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND fs_course_answer_logs.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fs_course_answer_logs.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fs_course_answer_logs.video_id = #{videoId}
- </if>
- </where>
- GROUP BY
- fs_course_answer_logs.video_id
- <choose>
- <when test="order != null and order == 'asc'">
- ORDER BY answerRightRate asc
- </when>
- <when test="order != null and order == 'desc'">
- ORDER BY answerRightRate desc
- </when>
- <otherwise>
- ORDER BY answerRightRate desc
- </otherwise>
- </choose>
- LIMIT 20
- </select>
- <select id="countUserRedPacket" resultType="Map">
- SELECT
- (
- SELECT
- count( flog.log_id )
- FROM
- fs_course_red_packet_log flog
- LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- where flog.status = 1
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="startTime != null and startTime !='' ">
- AND flog.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND flog.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND flog.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND flog.video_id = #{videoId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND company_user.user_id = #{companyUserId}
- </if>
- ) AS redPacketNum,
- (
- SELECT
- ifnull (sum( flog.amount ), 0)
- FROM
- fs_course_red_packet_log flog
- LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
- where flog.status = 1
- <if test="userId != null and userId != 0 ">
- and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="startTime != null and startTime !='' ">
- AND flog.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND flog.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND flog.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND flog.video_id = #{videoId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND company_user.user_id = #{companyUserId}
- </if>
- ) AS redPacketAmount
- </select>
- <select id="courseAnalysisCourseCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
- SELECT
- count( DISTINCT fcc.user_id ) as courseWatchNum,
- COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
- ifnull(
- ROUND(
- (
- COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
- 2
- ),
- 0
- ) as completeRate,
- fcpd.video_id
- FROM
- fs_user_course_count fcc
- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
- LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
- <where>
- <if test="companyUserId != null and companyUserId != 0 ">
- AND fs_user.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId == 0 ">
- and fs_user.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fcpd.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fcpd.video_id = #{videoId}
- </if>
- </where>
- GROUP BY
- fcpd.video_id
- </select>
- <select id="companyUserCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
- SELECT
- (
- SELECT count( fs_user.user_id ) FROM fs_user LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- <where>
- <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
- AND fs_user.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
- and fs_user.company_id = #{companyId}
- </if>
- </where>
- ) AS userTotal,
- (
- SELECT
- count( fs_user.user_id )
- FROM
- fs_user
- LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
- <where>
- <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
- AND fs_user.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
- and fs_user.company_id = #{companyId}
- </if>
- and fs_user.is_del = 0
- AND to_days( fs_user.create_time ) = to_days(
- now())
- </where>
- ) AS todayNewUser
- </select>
- <select id="newUserRedPacketCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
- SELECT
- count(flog.log_id) as userRedPacketNum,
- ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
- FROM
- fs_course_red_packet_log flog
- LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
- <where>
- <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
- AND fs_user.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
- and fs_user.company_id = #{companyId}
- </if>
- </where>
- </select>
- </mapper>
|