| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322 |
- <?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" />
- <result property="level" column="level"/>
- </resultMap>
- <sql id="selectFsUserVo">
- select user_id,qw_ext_id,sex,is_buy,`level`,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="userId != null">and user_id = #{userId}</if>
- <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>
- <if test="companyId != null">
- AND fwl.company_id = #{companyId}
- </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 flog.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId == 0 ">
- and flog.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>
- <if test="companyId != null">
- AND flog.company_id = #{companyId}
- </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_course_answer_logs.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId == 0 ">
- and fs_course_answer_logs.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>
- <if test="companyId != null">
- AND fs_course_answer_logs.company_id = #{companyId}
- </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.user_id,
- fs_user.avatar,
- fs_user.nick_name as nickname,
- fs_user.phone,
- fs_user_course_count.id,
- fs_user_course_count.watch_course_count,
- -- fs_course_watch_log.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_course_watch_log.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,
- fs_user_company_user.project_id,
- fs_user_company_user.`status`,
- ifnull(fs_user_company_user.remark, fs_user.remark) as remark,
- fs_user_company_user.id as userCompanyUserId,
- fs_user_company_user.create_time
- FROM
- fs_user
- INNER JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
- LEFT JOIN fs_user_course_count ON fs_user_company_user.user_id = fs_user_course_count.user_id and fs_user_company_user.project_id = fs_user_course_count.project_id
- left join fs_user_project_tag upt ON upt.user_company_user_id = fs_user_company_user.id
- LEFT JOIN company_tag ON company_tag.tag_id = upt.tag_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.company_user_id = #{userId}
- </if>
- <if test="companyId != null ">
- and fs_user_company_user.company_id = #{companyId}
- </if>
- <if test="status != null">
- AND fs_user_company_user.status = #{status}
- </if>
- <if test="projectId != null">
- AND fs_user_company_user.project_id = #{projectId}
- </if>
- <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_company_user.create_time >= #{registerStartTime}
- </if>
- <if test="registerEndTime != null and registerEndTime !='' ">
- AND fs_user_company_user.create_time <= #{registerEndTime}
- </if>
- <if test="isNullTag">
- and (upt.tag_id is null
- <if test="tagIds != null and tagIds.length > 0">
- or upt.tag_id in
- <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- )
- </if>
- <if test="!isNullTag and tagIds != null and tagIds.length > 0">
- AND upt.tag_id in
- <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="tabValue != null and tabValue !='' ">
- <choose>
- <when test = "tabValue == 1">
- AND fs_user_company_user.create_time >= CURDATE() AND fs_user_company_user.create_time < CURDATE() + INTERVAL 1 DAY
- </when>
- <when test = "tabValue == 2">
- AND fs_user_course_count.complete_watch_date >= CURDATE() AND fs_user_course_count.complete_watch_date < CURDATE() + INTERVAL 1 DAY
- </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, fs_user_company_user.project_id, fs_user_company_user.create_time
- order by
- <choose>
- <when test = "continueMissCourseSort != null and continueMissCourseSort == 0">
- fs_user_company_user.create_time desc,fs_user.user_id desc
- </when>
- <when test = "continueMissCourseSort != null and continueMissCourseSort == 1">
- fs_user.nick_name asc,fs_user.user_id desc
- </when>
- <otherwise>
- fs_user.user_id desc, fs_user_company_user.project_id
- </otherwise>
- </choose>
- </select>
- <select id="selectFsUserPageListNew" resultType="com.fs.store.vo.h5.FsUserPageListVO">
- SELECT
- fs_user.user_id,
- fs_user.nick_name as nickname,
- fs_user.avatar,
- fs_user.phone,
- fs_user.status,
- fs_user.create_time,
- fs_user.remark,
- ucu.company_user_id,
- ucu.company_id,
- ucu.project_id,
- fs_user.integral,
- if(fs_user.pay_count>0,1,0) as isBuy
- FROM
- fs_user
- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- <where>
- fs_user.is_del = 0
- <if test="userId != null">
- AND fs_user.user_id = #{userId}
- </if>
- <if test="companyId != null">
- AND ucu.company_id = #{companyId}
- </if>
- <if test="companyUserId != null and companyUserId != '' ">
- AND ucu.company_user_id = #{companyUserId}
- </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="companyUserIds != null and companyUserIds.size > 0">
- AND ucu.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 like concat('%', #{phone},'%')
- </if>
- <if test="projectId != null">
- AND ucu.project_id = #{projectId}
- </if>
- </where>
- limit ${(pageNum-1)*pageSize},${pageSize}
- </select>
- <select id="selectFsUserPageListCount" resultType="java.lang.Long">
- SELECT
- count(1)
- FROM
- fs_user
- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- <where>
- fs_user.is_del = 0
- <if test="companyId != null">
- AND ucu.company_id = #{companyId}
- </if>
- <if test="companyUserId != null and companyUserId != '' ">
- AND ucu.company_user_id = #{companyUserId}
- </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="companyUserIds != null and companyUserIds.size > 0">
- AND ucu.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>
- <if test="projectId != null">
- AND ucu.project_id = #{projectId}
- </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>
- <select id="selectFsUserVOList" resultType="com.fs.his.vo.FsUserVO">
- SELECT
- b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
- u.*,
- fs_course_watch_log.watch_course_count, fs_course_watch_log.part_course_count, company_user.nick_name AS companyUserNickName, fs_course_watch_log.last_watch_date
- ,company.company_name
- FROM
- fs_user u
- LEFT JOIN (
- SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
- user_id
- FROM
- fs_store_payment
- WHERE
- STATUS = 1
- AND user_id IS NOT NULL
- GROUP BY
- user_id
- ) b ON u.user_id = b.user_id
- LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
- AND b.last_buy_time = p.pay_time
- AND b.payment_id = p.payment_id
- LEFT JOIN (
- SELECT
- fs_course_watch_log.user_id,
- Max( fs_course_watch_log.last_heartbeat_time ) AS last_watch_date,
- count( DISTINCT fs_course_watch_log.video_id ) watch_course_count,
- count( DISTINCT fs_course_watch_log.period_id ) part_course_count
- FROM
- fs_course_watch_log
- GROUP BY
- fs_course_watch_log.user_id
- ) fs_course_watch_log ON fs_course_watch_log.user_id = u.user_id
- LEFT JOIN company_user ON company_user.user_id = u.company_user_id
- LEFT JOIN company on company.company_id = company_user.company_id
- <where>
- 1 = 1
- <if test = "maps.userId != null">
- AND u.user_id LIKE CONCAT("%",#{maps.userId},"%")
- </if >
- <if test = "maps.nickname != null and maps.nickname !='' " >
- AND u.nickname LIKE CONCAT("%",#{maps.nickname},"%")
- </if >
- <if test = "maps.phone != null and maps.phone !='' " >
- AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
- </if >
- <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
- AND (DATE_FORMAT( u.create_time, "%Y-%m-%d" ) >= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
- and DATE_FORMAT( u.create_time, "%Y-%m-%d" ) <= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
- )
- </if >
- <if test = "maps.registerCode != null and maps.registerCode !='' " >
- AND u.register_code = #{maps.registerCode}
- </if >
- <if test = "maps.status != null" >
- AND u.STATUS = #{maps.status}
- </if >
- <if test = "maps.companyUserNickName != null and maps.companyUserNickName != '' " >
- AND company_user.nick_name like CONCAT ("%",#{maps.companyUserNickName},"%")
- </if >
- <if test = "maps.companyName != null and maps.companyName != '' " >
- AND company.company_name like CONCAT ("%",#{maps.companyName},"%")
- </if >
- <if test = "maps.level != null and maps.level !=''" >
- AND u.LEVEL = #{maps.level}
- </if >
- <if test = "maps.isPromoter != null and maps.isPromoter !=''" >
- AND u.is_promoter = #{maps.isPromoter}
- </if >
- </where>
- ORDER BY
- user_id DESC
- </select>
- <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="orderCount != null">order_count,</if>
- <if test="companyId != null">company_id,</if>
- <if test="companyUserId != null">company_user_id,</if>
- <if test="level != null">`level`,</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="orderCount != null">#{orderCount},</if>
- <if test="companyId != null">#{companyId},</if>
- <if test="companyUserId != null">#{companyUserId},</if>
- <if test="level != null">#{level},</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="level != null">level = #{level},</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="isShow != null">is_show = #{isShow},</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="orderCount != null">order_count = #{orderCount},</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>
- <update id="batchUpdateCompanyUserRelation">
- update fs_user_company_user
- set company_id = #{companyId},
- company_user_id = #{companyUserId}
- where is_repeat_fans = 0 and
- <foreach collection="userIds" open="(" close=")" 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
- left join fs_user_company_user ucu on ucu.user_id = u.user_id
- left join company_user cu on cu.user_id = ucu.company_user_id
- where cu.user_id = #{companyUserId}
- </select>
- <select id="getUserNumber" resultType="com.fs.store.vo.h5.UserListCountVO">
- SELECT
- fs_user_company_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 and fs_user_company_user.is_repeat_fans is not null
- <if test="userId != null and userId != 0 ">
- and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and fs_user_company_user.company_id = #{companyId}
- </if>
- GROUP BY
- fs_user_company_user.`status`,fs_user_company_user.project_id
- </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
- inner JOIN fs_user_company_user cu ON cu.user_id = fs_user.user_id and cu.project_id = fs_user_course_count.project_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}
- <if test="userCompanyId!=null">
- and cu.id = #{userCompanyId}
- </if>
- </where>
- GROUP BY
- fs_user.user_id
- </select>
- <select id="getCountAnswer" resultType="com.fs.store.vo.h5.UserDetailsVO">
- SELECT
- (
- SELECT
- ifnull(count( DISTINCT fs_course_answer_logs.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 fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id =fcwl.log_id
- left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_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} and fucu.company_user_id =#{userId}
- </where>
- GROUP BY
- fs_user.user_id
- ) AS answerTime,
- (
- SELECT
- ifnull(count( DISTINCT fs_course_answer_logs.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 fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id =fcwl.log_id
- left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_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} and fucu.company_user_id =#{userId}
- </where>
- GROUP BY
- fs_user.user_id
- ) AS answerRightTime;
- </select>
- <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
- SELECT
- ifnull( count( DISTINCT fs_course_red_packet_log.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 fs_course_watch_log fcwl on fs_course_red_packet_log.watch_log_id =fcwl.log_id
- left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_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} and fucu.company_user_id =#{userId}
- </where>
- GROUP BY
- fs_user.user_id
- </select>
- <select id="getUserTotal" resultType="java.lang.Integer">
- SELECT count(fs_user.user_id) as userTotal
- FROM fs_user
- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
- WHERE fs_user.is_del = 0
- <if test="userId != null and userId != 0 ">
- and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and ucu.company_id = #{companyId}
- </if>
- </select>
- <select id="getTodayNewUser" resultType="java.lang.Integer">
- SELECT count(fs_user.user_id) as todayNewUser
- FROM fs_user
- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
- WHERE fs_user.is_del = 0
- <if test="userId != null and userId != 0 ">
- and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and ucu.company_id = #{companyId}
- </if>
- AND to_days(ucu.create_time) = to_days(now())
- </select>
- <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
- SELECT (SELECT count(fs_user.user_id)
- FROM fs_user
- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
- WHERE fs_user.is_del = 0
- <if test="userId != null and userId != 0 ">
- and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and ucu.company_id = #{companyId}
- </if>
- ) as userTotal,
- (SELECT count(fs_user.user_id)
- FROM fs_user
- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
- WHERE fs_user.is_del = 0
- <if test="userId != null and userId != 0 ">
- and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and ucu.company_id = #{companyId}
- </if>
- AND to_days(ucu.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( ucu.user_id ) AS number
- FROM
- fs_user_project_tag upt
- inner join fs_user_company_user ucu on ucu.id = upt.user_company_user_id
- inner join company_tag ON upt.tag_id = company_tag.tag_id
- left join company_user on company_user.user_id = ucu.company_user_id
- <where>
- <if test="userId != null and userId != 0 ">
- and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="companyId != null ">
- and ucu.company_id = #{companyId}
- </if>
- </where>
- GROUP BY
- company_tag.tag_id
- </select>
- <select id="countUserCourse" resultType="Map">
- SELECT
- (SELECT COUNT(*) FROM (
- SELECT 1
- FROM fs_user_course_count fcc
- JOIN fs_user ON fs_user.user_id = fcc.user_id
- JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
- JOIN company_user ON ucu.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>
- fcc.project_id = ucu.project_id
- <if test="userId != null and userId != 0 ">
- and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and ucu.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(*) FROM (
- SELECT 1
- FROM fs_user_course_count fcc
- JOIN fs_user ON fs_user.user_id = fcc.user_id
- JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
- JOIN company_user ON ucu.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>
- fcc.project_id = ucu.project_id
- <if test="userId != null and userId != 0 ">
- and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and ucu.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>
- GROUP BY fcc.user_id, ucu.project_id
- ) AS complete_counts ) as courseCompleteNum
- </select>
- <select id="countUserStats" resultType="Map">
- SELECT
- -- 观看人数
- (
- SELECT COUNT(DISTINCT l.user_id)
- FROM fs_course_watch_log l
- LEFT JOIN fs_user u ON u.user_id = l.user_id
- LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
- <where>
- l.log_type != 3 AND l.send_type = 1
- <if test="userId != null and userId != 0 ">
- AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
- </if>
- <if test="userId != null and userId == 0 ">
- AND l.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != '' ">
- AND l.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != '' ">
- AND l.video_id = #{videoId}
- </if>
- <if test="startTime != null and startTime != '' ">
- AND l.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != '' ">
- AND l.create_time <= #{endTime}
- </if>
- <if test="companyUserId != null and companyUserId != '' ">
- AND l.company_user_id = #{companyUserId}
- </if>
- </where>
- ) AS courseWatchNum,
- -- 完成人数
- (
- SELECT COUNT(DISTINCT l.user_id)
- FROM fs_course_watch_log l
- LEFT JOIN fs_user u ON u.user_id = l.user_id
- LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
- <where>
- l.log_type = 2 AND l.send_type = 1
- <if test="userId != null and userId != 0 ">
- AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
- </if>
- <if test="userId != null and userId == 0 ">
- AND l.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != '' ">
- AND l.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != '' ">
- AND l.video_id = #{videoId}
- </if>
- <if test="startTime != null and startTime != '' ">
- AND l.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != '' ">
- AND l.create_time <= #{endTime}
- </if>
- <if test="companyUserId != null and companyUserId != '' ">
- AND l.company_user_id = #{companyUserId}
- </if>
- </where>
- ) AS courseCompleteNum,
- -- 答题人数
- (
- SELECT COUNT(distinct a.user_id)
- FROM fs_course_answer_logs a
- LEFT JOIN fs_user u ON u.user_id = a.user_id
- LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
- <where>
- 1=1
- <if test="userId != null and userId != 0 ">
- AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
- </if>
- <if test="userId != null and userId == 0 ">
- AND a.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != '' ">
- AND a.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != '' ">
- AND a.video_id = #{videoId}
- </if>
- <if test="startTime != null and startTime != '' ">
- AND a.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != '' ">
- AND a.create_time <= #{endTime}
- </if>
- <if test="companyUserId != null and companyUserId != '' ">
- AND a.company_user_id = #{companyUserId}
- </if>
- </where>
- ) AS answerNum,
- -- 答对人数
- (
- SELECT COUNT(distinct a.user_id)
- FROM fs_course_answer_logs a
- LEFT JOIN fs_user u ON u.user_id = a.user_id
- LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
- <where>
- a.is_right = 1
- <if test="userId != null and userId != 0 ">
- AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
- </if>
- <if test="userId != null and userId == 0 ">
- AND a.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != '' ">
- AND a.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != '' ">
- AND a.video_id = #{videoId}
- </if>
- <if test="startTime != null and startTime != '' ">
- AND a.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != '' ">
- AND a.create_time <= #{endTime}
- </if>
- <if test="companyUserId != null and companyUserId != '' ">
- AND a.company_user_id = #{companyUserId}
- </if>
- </where>
- ) AS answerRightNum,
- -- 红包数
- (
- SELECT COUNT(flog.log_id)
- FROM fs_course_red_packet_log flog
- LEFT JOIN fs_user u ON u.user_id = flog.user_id
- LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
- <where>
- flog.status = 1
- <if test="userId != null and userId != 0 ">
- AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
- </if>
- <if test="userId != null and userId == 0 ">
- AND flog.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="startTime != null and startTime != '' ">
- AND flog.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != '' ">
- AND flog.create_time <= #{endTime}
- </if>
- <if test="companyUserId != null and companyUserId != '' ">
- AND flog.company_user_id = #{companyUserId}
- </if>
- </where>
- ) AS redPacketNum,
- -- 红包金额
- (
- SELECT IFNULL(SUM(flog.amount), 0)
- FROM fs_course_red_packet_log flog
- LEFT JOIN fs_user u ON u.user_id = flog.user_id
- LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
- <where>
- flog.status = 1
- <if test="userId != null and userId != 0 ">
- AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
- </if>
- <if test="userId != null and userId == 0 ">
- AND flog.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="startTime != null and startTime != '' ">
- AND flog.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != '' ">
- AND flog.create_time <= #{endTime}
- </if>
- <if test="companyUserId != null and companyUserId != '' ">
- AND flog.company_user_id = #{companyUserId}
- </if>
- </where>
- ) AS redPacketAmount
- </select>
- <!-- 查询观看和完成人数 -->
- <select id="countUserWatchStats" resultType="Map">
- SELECT
- COUNT(DISTINCT CASE WHEN l.log_type != 3 AND l.send_type = 1 THEN l.user_id END) AS courseWatchNum,
- COUNT(DISTINCT CASE WHEN l.log_type = 2 AND l.send_type = 1 THEN l.user_id END) AS courseCompleteNum
- FROM fs_course_watch_log l
- LEFT JOIN fs_user u ON u.user_id = l.user_id
- LEFT JOIN company_user cu_l ON l.company_user_id = cu_l.user_id
- <where>
- <if test="userId != null and userId != 0">
- AND (cu_l.user_id = #{userId} OR cu_l.parent_id = #{userId})
- </if>
- <if test="userId != null and userId == 0">
- AND l.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND l.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND l.video_id = #{videoId}
- </if>
- <if test="startTime != null and startTime != ''">
- AND l.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND l.create_time <= #{endTime}
- </if>
- <if test="companyUserId != null and companyUserId != ''">
- AND l.company_user_id = #{companyUserId}
- </if>
- </where>
- </select>
- <!-- 查询答题人数和答对人数 -->
- <select id="countUserAnswerStats" resultType="Map">
- SELECT
- COUNT(DISTINCT CASE WHEN a.user_id THEN a.user_id END) AS answerNum,
- COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS answerRightNum
- FROM fs_course_answer_logs a
- LEFT JOIN fs_user u ON u.user_id = a.user_id
- LEFT JOIN company_user cu_a ON a.company_user_id = cu_a.user_id
- <where>
- <if test="userId != null and userId != 0">
- AND (cu_a.user_id = #{userId} OR cu_a.parent_id = #{userId})
- </if>
- <if test="userId != null and userId == 0">
- AND a.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND a.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND a.video_id = #{videoId}
- </if>
- <if test="startTime != null and startTime != ''">
- AND a.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND a.create_time <= #{endTime}
- </if>
- <if test="companyUserId != null and companyUserId != ''">
- AND a.company_user_id = #{companyUserId}
- </if>
- </where>
- </select>
- <!-- 查询红包数量和红包金额 -->
- <select id="countUserRedPacketStats" resultType="Map">
- SELECT
- COUNT(CASE WHEN flog.status = 1 THEN flog.log_id END) AS redPacketNum,
- IFNULL(SUM(CASE WHEN flog.status = 1 THEN flog.amount END), 0) AS redPacketAmount
- FROM fs_course_red_packet_log flog
- LEFT JOIN fs_user u ON u.user_id = flog.user_id
- LEFT JOIN company_user cu_flog ON flog.company_user_id = cu_flog.user_id
- <where>
- <if test="userId != null and userId != 0">
- AND (cu_flog.user_id = #{userId} OR cu_flog.parent_id = #{userId})
- </if>
- <if test="userId != null and userId == 0">
- AND flog.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="startTime != null and startTime != ''">
- AND flog.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND flog.create_time <= #{endTime}
- </if>
- <if test="companyUserId != null and companyUserId != ''">
- AND flog.company_user_id = #{companyUserId}
- </if>
- </where>
- </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_course_answer_logs.company_user_id
- left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
- left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
- <where>
- <if test="userId != null and userId != 0 ">
- and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_course_answer_logs.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_course_answer_logs.company_user_id
- left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
- left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
- <where>
- <if test="userId != null and userId != 0 ">
- and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_course_answer_logs.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
- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
- AND FIND_IN_SET(#{companyId}, fpd.company_id)
- <if test="userId != null and userId != 0 ">
- AND ucu.company_user_id = #{userId}
- </if>
- <if test="userId != null and userId == 0 ">
- and ucu.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fcpd.period_id = #{periodId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND ucu.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
- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
- AND FIND_IN_SET(#{companyId}, fpd.company_id)
- <if test="userId != null and userId != 0 ">
- AND ucu.company_user_id = #{userId}
- </if>
- <if test="userId != null and userId == 0 ">
- and ucu.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 ucu.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
- left join fs_user_company_user ucu on ucu.user_id = fs_user.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 ucu.company_user_id = #{companyUserId}
- </if>
- <where>
- <if test="userId != null and userId != 0 ">
- AND ucu.company_user_id = #{userId}
- </if>
- <if test="userId != null and userId == 0 ">
- and ucu.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 fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- LEFT JOIN company_user ON ucu.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 ( ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and ucu.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_course_answer_logs.company_user_id
- <where>
- <if test="userId != null and userId != 0 ">
- AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_course_answer_logs.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,
- fcv.video_id,
- ifnull(
- ROUND(
- (
- COUNT( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) / count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.log_id END )) * 100,
- 2
- ),
- 0
- ) AS completeRate
- FROM
- fs_course_watch_log fwl
- LEFT JOIN fs_user ON fs_user.user_id = fwl.user_id
- 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
- -- 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 = fwl.video_id
- <where>
- <if test="userId != null and userId != 0 ">
- AND ( fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_user_company_user.company_id = #{companyId}
- </if>
- <if test="startTime != null and startTime !='' ">
- AND fwl.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND fwl.create_time <= #{endTime}
- </if>
- <if test="periodId != null and periodId != ''">
- AND fwl.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND fwl.video_id = #{videoId}
- </if>
- </where>
- GROUP BY
- fwl.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 fs_course_answer_logs.log_id END ) / count( DISTINCT fs_course_answer_logs.log_id)) * 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 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_course_answer_logs.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_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and fs_course_answer_logs.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 = flog.company_user_id
- left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
- left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
- where flog.status = 1
- <if test="userId != null and userId != 0 ">
- and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and flog.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 = flog.company_user_id
- left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
- left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
- where flog.status = 1
- <if test="userId != null and userId != 0 ">
- and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and flog.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 fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- LEFT JOIN company_user ON ucu.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 ucu.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId == 0 ">
- and ucu.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 fs_user_company_user ucu on ucu.user_id = fs_user.user_id LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
- <where>
- <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
- AND ucu.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
- and ucu.company_id = #{companyId}
- </if>
- </where>
- ) AS userTotal,
- (
- SELECT
- count( fs_user.user_id )
- FROM
- fs_user
- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
- LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
- <where>
- <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
- AND ucu.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
- and ucu.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 flog.company_user_id = #{companyUserId}
- </if>
- <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
- and flog.company_id = #{companyId}
- </if>
- </where>
- </select>
- <select id="countUserCourse2" resultType="java.util.Map">
- SELECT
- (
- SELECT
- count(DISTINCT l.user_id)
- FROM
- fs_course_watch_log l
- LEFT JOIN fs_user on fs_user.user_id = l.user_id
- LEFT JOIN company_user ON l.company_user_id = company_user.user_id
- LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id and l.project =fs_user_company_user.project_id
- where
- l.log_type != 3 and send_type = 1
- <if test="userId != null and userId != 0 ">
- and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and l.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND l.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND l.video_id = #{videoId}
- </if>
- <if test="startTime != null and startTime !='' ">
- and l.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and l.create_time <= #{endTime}
- </if> <if test="companyUserId != null and companyUserId != ''">
- AND l.user_id = #{companyUserId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND l.company_user_id = #{companyUserId}
- </if>
- ) as courseWatchNum,
- (
- SELECT
- count(DISTINCT l.user_id)
- FROM
- fs_course_watch_log l
- LEFT JOIN company_user ON l.company_user_id = company_user.user_id
- LEFT JOIN fs_user ON fs_user.user_id = l.user_id
- LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id and l.project =fs_user_company_user.project_id
- where
- l.log_type = 2 and send_type = 1
- <if test="userId != null and userId != 0 ">
- and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
- </if>
- <if test="userId != null and userId == 0 ">
- and l.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND l.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND l.video_id = #{videoId}
- </if>
- <if test="startTime != null and startTime !='' ">
- and l.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- and l.create_time <= #{endTime}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND l.company_user_id = #{companyUserId}
- </if>
- ) as courseCompleteNum
- </select>
- <select id="countCourseDetailsNew" resultType="Map">
- SELECT
- count( DISTINCT l.period_id ) as courseNum,
- count( DISTINCT l.video_id ) as videoNum,
- count( DISTINCT l.user_id ) as courseUserNum
- FROM
- fs_course_watch_log l
- left join fs_user on fs_user.user_id = l.user_id
- LEFT JOIN company_user ON l.company_user_id = company_user.user_id
- WHERE
- l.log_type != 3
- AND send_type = 1
- <if test="userId != null and userId != 0 ">
- AND l.company_user_id = #{userId}
- </if>
- <if test="userId != null and userId == 0 ">
- and l.company_id = #{companyId}
- </if>
- <if test="periodId != null and periodId != ''">
- AND l.period_id = #{periodId}
- </if>
- <if test="videoId != null and videoId != ''">
- AND l.video_id = #{videoId}
- </if>
- -- 单独通过销售id查询
- <if test="companyUserId != null and companyUserId != ''">
- AND l.company_user_id = #{companyUserId}
- </if>
- </select>
- <select id="selectFsUserVOListByProject" resultType="com.fs.his.vo.FsUserVO">
- SELECT distinct
- b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
- u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
- fcc.watch_course_count, fcc.part_course_count, company_user.nick_name AS companyUserNickName, fcc.last_watch_date
- ,company.company_name,
- ucu.project_id,
- ucu.id as companyUserId,
- ucu.create_time as bindTime,
- ucu.status
- FROM
- fs_user u
- LEFT JOIN (
- SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
- user_id
- FROM
- fs_store_payment
- WHERE
- STATUS = 1
- AND user_id IS NOT NULL
- GROUP BY
- user_id
- ) b ON u.user_id = b.user_id
- LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
- AND b.last_buy_time = p.pay_time
- AND b.payment_id = p.payment_id
- LEFT JOIN (
- SELECT
- fs_user_course_count.user_id,Max( fs_user_course_count.last_watch_date ) AS last_watch_date,fs_user_course_count.watch_course_count,
- fs_user_course_count.part_course_count
- FROM
- fs_user_course_count
- GROUP BY fs_user_course_count.user_id
- ) fcc ON fcc.user_id = u.user_id
- inner join fs_user_company_user ucu on ucu.user_id = u.user_id
- LEFT JOIN company_user ON company_user.user_id = ucu.company_user_id
- LEFT JOIN company on company.company_id = company_user.company_id
- <where>
- 1 = 1 and u.nick_name is not null
- and u.is_del = 0
- <if test = "maps.nickname != null and maps.nickname !='' " >
- AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
- </if >
- <if test = "maps.userId != null and maps.userId !='' " >
- AND u.user_id = #{maps.userId}
- </if >
- <if test = "maps.phone != null and maps.phone !='' " >
- AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
- </if >
- <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
- AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) >= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
- and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) <= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
- )
- </if >
- <if test = "maps.registerCode != null and maps.registerCode !='' " >
- AND u.register_code = #{maps.registerCode}
- </if >
- <if test = "maps.status != null" >
- AND ucu.status = #{maps.status}
- </if >
- <if test = "maps.companyId != null and maps.companyId != '' " >
- AND company.company_id = #{maps.companyId}
- </if >
- <if test = "maps.companyUserId != null" >
- AND company_user.user_id = #{maps.companyUserId}
- </if >
- <if test = "maps.projectId != null" >
- AND ucu.project_id = #{maps.projectId}
- </if >
- </where>
- ORDER BY
- user_id DESC
- </select>
- <select id="selectCompanyAndDoctor" resultType="com.fs.watch.domain.vo.FsUserAndCompanyAndDoctorVo">
- SELECT
- f.*,
- GROUP_CONCAT(c.company_id SEPARATOR ',') AS company_id,
- GROUP_CONCAT(c.company_user_id SEPARATOR ',') AS company_user_id,
- GROUP_CONCAT(o.doctor_id SEPARATOR ',') AS doctor_id
- FROM
- fs_user f
- LEFT JOIN
- company_user_user c ON c.user_id = f.user_id
- LEFT JOIN
- fs_inquiry_order o ON o.user_id = f.user_id AND o.`status` = 4
- WHERE
- f.is_del = 0 AND f.user_id = #{userId}
- GROUP BY
- f.user_id;
- </select>
- <select id="selectUserNameByIds" resultMap="FsUserResult">
- select user_id,nick_name from fs_user where user_id in
- <foreach collection="userIds.split(',')" item="userId" open="(" close=")" separator=",">
- #{userId}
- </foreach>
- </select>
- <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
- SELECT
- count( DISTINCT fs_user.user_id ) as userNum,
- count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
- fs_user_company_user.company_id
- 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
- AND fs_user.`status` = 1
- AND fs_user_company_user.`status` = 1
- AND company_user.user_id IS NOT NULL
- GROUP BY
- fs_user_company_user.company_id
- </select>
- <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
- SELECT
- count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
- count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
- 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 completeWatchRate,
- fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
- FROM
- fs_course_watch_log fwl
- LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fwl.user_id
- WHERE
- fwl.send_type = 1
- AND fs_user_company_user.`status` = 1
- GROUP BY
- fwl.period_id, fwl.video_id, fwl.company_user_id
- </select>
- <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
- SELECT
- count(DISTINCT flog.log_id ) AS redPacketNum,
- ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
- flog.period_id,
- flog.video_id,
- flog.company_user_id,
- flog.company_id
- FROM
- fs_course_red_packet_log flog
- LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = flog.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
- where flog.`status` = 1
- AND fs_user_company_user.`status` = 1
- GROUP BY
- flog.period_id,
- flog.video_id,
- flog.company_user_id
- </select>
- <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
- SELECT
- count( DISTINCT fs_user_company_user.user_id ) AS answerNum,
- COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user_company_user.user_id END ) AS answerRightNum,
- ifnull(
- ROUND(
- (
- COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user_company_user.user_id END ) / count( DISTINCT fs_user_company_user.user_id )) * 100,
- 2
- ),
- 0
- ) AS answerRightRate,
- fs_course_answer_logs.period_id,
- fs_course_answer_logs.video_id,
- fs_course_answer_logs.company_user_id,
- fs_course_answer_logs.company_id
- FROM
- fs_course_answer_logs
- LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_course_answer_logs.user_id
- LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
- where fs_user_company_user.`status` = 1
- GROUP BY
- fs_course_answer_logs.period_id,
- fs_course_answer_logs.video_id,
- fs_course_answer_logs.company_user_id
- </select>
- <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
- SELECT
- count(DISTINCT fs_user.user_id ) as userNum,
- count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
- date(fs_user.create_time) as userCreateDate
- ,company.company_id,
- company.company_name,
- company_user.user_id AS companyUserId,
- company_user.nick_name AS companyUserName
- 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
- LEFT JOIN company ON company.company_id = fs_user_company_user.company_id
- WHERE
- fs_user.is_del = 0
- AND fs_user_company_user.`status` = 1
- AND fs_user.`status` = 1
- AND company_user.user_id is not null
- GROUP BY
- fs_user_company_user.company_user_id, date(fs_user.create_time)
- </select>
- <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
- <include refid="selectFsUserVo"/>
- <where>
- <if test="userName != null and userName != ''">
- AND (
- nickname like concat('%', #{userName}, '%')
- or user_id LIKE concat('%',#{userName},'%')
- )
- </if>
- </where>
- order by user_id desc
- </select>
- <select id="selectFsUserCount" resultType="java.lang.Long">
- select count(1) from fs_user
- where 1=1
- <if test = "type != null and type ==1">
- and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
- </if>
- <if test = "companyId != null">
- and company_id=#{companyId}
- </if>
- <if test="companyUserId != null">
- and company_user_id = #{companyUserId}
- </if>
- </select>
- <select id="selectFsUserListLimit" resultMap="FsUserResult">
- <include refid="selectFsUserVo"/>
- <where>
- <if test="password != null and password != ''">and password = #{password}</if>
- <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
- <if test="birthday != null ">and birthday = #{birthday}</if>
- <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
- <if test="remark != null and remark != ''">and remark = #{remark}</if>
- <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
- <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
- <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
- <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</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="level != null ">and level = #{level}</if>
- <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
- <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
- <if test="userType != null and userType != ''">and user_type = #{userType}</if>
- <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
- <if test="payCount != null ">and pay_count = #{payCount}</if>
- <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
- <if test="addres != null and addres != ''">and addres = #{addres}</if>
- <if test="isDel != null ">and is_del = #{isDel}</if>
- <if test="companyId != null ">and company_id = #{companyId}</if>
- <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
- <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
- DATE_FORMAT(#{registerDate},'%Y-%m-%d')
- </if>
- <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
- <if test="source != null and source != '' ">and source = #{source}</if>
- <if test="isShow != null ">and is_show = #{isShow}</if>
- <if test="(username != null and username != '') or (userId != null and userId != '') or (nickname != null and nickname != '') or (phone != null and phone != '')">
- and (
- <if test="username != null and username != ''">username like concat('%', #{username}, '%')</if>
- <if test="userId != null and userId != ''">or user_id = #{userId}</if>
- <if test="nickname != null and nickname != ''">or nickname like concat('%', #{nickname}, '%')</if>
- <if test="phone != null and phone != ''">or phone like concat('%',#{phone},'%')</if>
- )
- </if>
- <if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
- <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>
- <if test="payOrder != null ">and pay_order = #{payOrder}</if>
- </where>
- order by user_id desc
- limit 10
- </select>
- <select id="findUsersByParam" resultType="com.fs.his.dto.FindUsersByDTO">
- SELECT user_id as id, 0 as type,
- CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
- FROM fs_user
- WHERE user_id = #{keywords}
- UNION
- <!-- fs_user 按nick_name前缀搜索 -->
- SELECT user_id as id, 0 as type,
- CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
- FROM fs_user
- WHERE nick_name LIKE CONCAT(#{keywords}, '%')
- UNION
- <!-- fs_user 按phone精确搜索(仅当keywords是数字时) -->
- <if test="keywords.matches('\\d+')">
- SELECT user_id as id, 0 as type,
- CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
- FROM fs_user
- WHERE phone = #{keywords}
- UNION
- </if>
- <!-- company_user相关查询 -->
- SELECT user_id as id, 1 as type,
- IFNULL(nick_name, '') as name
- FROM company_user
- WHERE user_id = #{keywords}
- UNION
- SELECT user_id as id, 1 as type,
- IFNULL(nick_name, '') as name
- FROM company_user
- WHERE nick_name LIKE CONCAT(#{keywords}, '%')
- <if test="keywords.matches('\\d+')">
- UNION
- SELECT user_id as id, 1 as type,
- IFNULL(nick_name, '') as name
- FROM company_user
- WHERE phonenumber = #{keywords}
- </if>
- </select>
- <select id="countExternalRedPacketStats" resultType="com.fs.store.vo.h5.ExternalRedPacketStatsVO">
- SELECT
- COUNT(red.log_id) AS redPacketNum,
- COALESCE(SUM(red.amount), 0) AS redPacketAmount
- FROM fs_course_red_packet_log log
- WHERE log.status = 1
- AND log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
- <if test="startTime != null and startTime != ''">
- AND log.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND log.create_time <= #{endTime}
- </if>
- </select>
- <select id="countExternalAnswerStats" resultType="com.fs.store.vo.h5.ExternalAnswerStatsVO">
- SELECT
- COUNT(*) AS answerNum,
- SUM(CASE WHEN is_right = 1 THEN 1 ELSE 0 END) AS answerRightNum
- FROM fs_course_answer_logs log
- WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
- <if test="startTime != null and startTime != ''">
- AND log.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND log.create_time <= #{endTime}
- </if>
- </select>
- <select id="countExternalWatchStats" resultType="com.fs.store.vo.h5.ExternalWatchStatsVO">
- SELECT
- COUNT(CASE WHEN log_type != 3 THEN 1 END) AS courseWatchNum,
- COUNT(CASE WHEN log_type = 2 THEN 1 END) AS courseCompleteNum
- FROM fs_course_watch_log log
- WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
- <if test="startTime != null and startTime != ''">
- AND log.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND log.create_time <= #{endTime}
- </if>
- </select>
- </mapper>
|