FsUserMapper.xml 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.his.mapper.FsUserMapper">
  6. <resultMap type="FsUser" id="FsUserResult">
  7. <result property="userId" column="user_id" />
  8. <result property="nickName" column="nick_name" />
  9. <result property="avatar" column="avatar" />
  10. <result property="phone" column="phone" />
  11. <result property="integral" column="integral" />
  12. <result property="status" column="status" />
  13. <result property="tuiUserId" column="tui_user_id" />
  14. <result property="tuiTime" column="tui_time" />
  15. <result property="tuiUserCount" column="tui_user_count" />
  16. <result property="maOpenId" column="ma_open_id" />
  17. <result property="mpOpenId" column="mp_open_id" />
  18. <result property="unionId" column="union_id" />
  19. <result property="isDel" column="is_del" />
  20. <result property="userCode" column="user_code" />
  21. <result property="remark" column="remark" />
  22. <result property="createTime" column="create_time" />
  23. <result property="updateTime" column="update_time" />
  24. <result property="lastIp" column="last_ip" />
  25. <result property="balance" column="balance" />
  26. <result property="signNum" column="sign_num" />
  27. <result property="integralStatus" column="integral_status" />
  28. <result property="isBuy" column="is_buy" />
  29. <result property="password" column="password" />
  30. <result property="isVip" column="is_vip" />
  31. <result property="jpushId" column="jpush_id" />
  32. <result property="vipStartDate" column="vip_start_date" />
  33. <result property="vipEndDate" column="vip_end_date" />
  34. <result property="vipLevel" column="vip_level" />
  35. <result property="vipStatus" column="vip_status" />
  36. <result property="sex" column="sex" />
  37. <result property="storeOpenId" column="store_open_id" />
  38. <result property="isPush" column="is_push" />
  39. <result property="isIndividuationPush" column="is_individuation_push" />
  40. <result property="isWeixinAuth" column="is_weixin_auth" />
  41. <result property="companyId" column="company_id"/>
  42. <result property="companyUserId" column="company_user_id"/>
  43. <result property="loginDevice" column="login_device" />
  44. <result property="source" column="source" />
  45. <result property="isAddQw" column="is_add_qw" />
  46. <result property="parentId" column="parent_id" />
  47. <result property="courseMaOpenId" column="course_ma_open_id" />
  48. <result property="qwExtId" column="qw_ext_id" />
  49. <result property="qwUserId" column="qw_user_id" />
  50. <result property="appId" column="app_id" />
  51. <result property="level" column="level"/>
  52. </resultMap>
  53. <sql id="selectFsUserVo">
  54. 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,app_id,company_id,company_user_id,is_promoter,now_money,brokerage_price,spread_user_id, spread_time,pay_count, spread_count,user_type from fs_user
  55. </sql>
  56. <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
  57. <include refid="selectFsUserVo"/>
  58. <where>
  59. <if test="userId != null">and user_id = #{userId}</if>
  60. <if test="nickName != null and nickName != ''"> and nick_name like concat( #{nickName}, '%')</if>
  61. <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
  62. <if test="phone != null and phone != ''"> and phone = #{phone}</if>
  63. <if test="integral != null "> and integral = #{integral}</if>
  64. <if test="signNum != null "> and sign_num = #{signNum}</if>
  65. <if test="status != null "> and status = #{status}</if>
  66. <if test="tuiUserId != null and tuiUserId != ''"> and tui_user_id = #{tuiUserId}</if>
  67. <if test="tuiTime != null "> and tui_time = #{tuiTime}</if>
  68. <if test="tuiUserCount != null "> and tui_user_count = #{tuiUserCount}</if>
  69. <if test="maOpenId != null and maOpenId != ''"> and ma_open_id = #{maOpenId}</if>
  70. <if test="mpOpenId != null and mpOpenId != ''"> and mp_open_id = #{mpOpenId}</if>
  71. <if test="unionId != null and unionId != ''"> and union_id = #{unionId}</if>
  72. <if test="isDel != null "> and is_del = #{isDel}</if>
  73. <if test="userCode != null and userCode != ''"> and user_code = #{userCode}</if>
  74. <if test="lastIp != null and lastIp != ''"> and last_ip = #{lastIp}</if>
  75. <if test="balance != null "> and balance = #{balance}</if>
  76. <if test="level != null ">and level = #{level}</if>
  77. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  78. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  79. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  80. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  81. <if test="payCount != null ">and pay_count = #{payCount}</if>
  82. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  83. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  84. <if test="companyId != null ">and company_id = #{companyId}</if>
  85. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  86. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  87. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  88. </if>
  89. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  90. <if test="source != null and source != '' ">and source = #{source}</if>
  91. <if test="isShow != null ">and is_show = #{isShow}</if>
  92. <!--<if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  93. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>-->
  94. <if test="payOrder != null ">and pay_order = #{payOrder}</if>
  95. </where>
  96. </select>
  97. <select id="selectFsUserByUserId" parameterType="Long" resultMap="FsUserResult">
  98. <include refid="selectFsUserVo"/>
  99. where user_id = #{userId}
  100. </select>
  101. <select id="courseAnalysisWatchLog" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  102. SELECT
  103. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS courseWatchNum,
  104. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTimes,
  105. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS courseCompleteNum,
  106. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTimes,
  107. ifnull(
  108. ROUND(
  109. (
  110. 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,
  111. 2
  112. ),
  113. 0
  114. ) AS completeRate,
  115. fwl.video_id
  116. FROM
  117. fs_course_watch_log fwl
  118. <where>
  119. <if test="periodId != null and periodId != ''">
  120. AND fwl.period_id = #{periodId}
  121. </if>
  122. <if test="videoId != null and videoId != ''">
  123. AND fwl.video_id = #{videoId}
  124. </if>
  125. <if test="videoIdList != null and videoIdList.size > 0 ">
  126. AND fwl.video_id in
  127. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  128. #{videoId}
  129. </foreach>
  130. </if>
  131. <if test="companyId != null">
  132. AND fwl.company_id = #{companyId}
  133. </if>
  134. </where>
  135. GROUP BY
  136. fwl.video_id
  137. </select>
  138. <select id="courseAnalysisRedPacketCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  139. SELECT
  140. count( flog.log_id ) as redPacketNum,
  141. ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
  142. flog.video_id
  143. FROM
  144. fs_course_red_packet_log flog
  145. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  146. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  147. <where>
  148. <if test="companyUserId != null and companyUserId != 0 ">
  149. AND flog.company_user_id = #{companyUserId}
  150. </if>
  151. <if test="companyUserId != null and companyUserId == 0 ">
  152. and flog.company_id = #{companyId}
  153. </if>
  154. <if test="periodId != null and periodId != ''">
  155. AND flog.period_id = #{periodId}
  156. </if>
  157. <if test="videoId != null and videoId != ''">
  158. AND flog.video_id = #{videoId}
  159. </if>
  160. <if test="videoIdList != null and videoIdList.size > 0 ">
  161. AND flog.video_id in
  162. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  163. #{videoId}
  164. </foreach>
  165. </if>
  166. <if test="companyId != null">
  167. AND flog.company_id = #{companyId}
  168. </if>
  169. </where>
  170. GROUP BY
  171. flog.video_id
  172. </select>
  173. <select id="courseAnalysisAnswerCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  174. SELECT
  175. count( DISTINCT fs_user.user_id ) as answerNum,
  176. count(fs_course_answer_logs.log_id) answerTimes,
  177. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
  178. COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) as answerRightTimes,
  179. ifnull(
  180. ROUND(
  181. (
  182. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  183. 2
  184. ),
  185. 0
  186. ) as answerRightRate,
  187. fs_course_answer_logs.video_id
  188. FROM
  189. fs_course_answer_logs
  190. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  191. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  192. <where>
  193. <if test="companyUserId != null and companyUserId != 0 ">
  194. AND fs_course_answer_logs.company_user_id = #{companyUserId}
  195. </if>
  196. <if test="companyUserId != null and companyUserId == 0 ">
  197. and fs_course_answer_logs.company_id = #{companyId}
  198. </if>
  199. <if test="periodId != null and periodId != ''">
  200. AND fs_course_answer_logs.period_id = #{periodId}
  201. </if>
  202. <if test="videoId != null and videoId != ''">
  203. AND fs_course_answer_logs.video_id = #{videoId}
  204. </if>
  205. <if test="videoIdList != null and videoIdList.size > 0 ">
  206. AND fs_course_answer_logs.video_id in
  207. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  208. #{videoId}
  209. </foreach>
  210. </if>
  211. <if test="companyId != null">
  212. AND fs_course_answer_logs.company_id = #{companyId}
  213. </if>
  214. </where>
  215. GROUP BY
  216. fs_course_answer_logs.video_id
  217. </select>
  218. <select id="selectFsUserById" parameterType="Long" resultMap="FsUserResult">
  219. <include refid="selectFsUserVo"/>
  220. where user_id = #{userId}
  221. </select>
  222. <select id="selectFsUserPageList" resultType="com.fs.store.vo.h5.FsUserPageListVO">
  223. SELECT
  224. fs_user.user_id,
  225. fs_user.avatar,
  226. fs_user.nick_name as nickname,
  227. fs_user.phone,
  228. fs_user_course_count.id,
  229. fs_user_course_count.watch_course_count,
  230. -- fs_course_watch_log.watch_course_count,
  231. fs_user_course_count.miss_course_count,
  232. fs_user_course_count.miss_course_status,
  233. fs_user_course_count.course_ids,
  234. fs_user_course_count.part_course_count,
  235. -- fs_course_watch_log.part_course_count,
  236. fs_user_course_count.last_watch_date,
  237. fs_user_course_count.STATUS AS courseCountStatus,
  238. fs_user_course_count.stop_watch_days,
  239. fs_user_course_count.complete_watch_date,
  240. GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
  241. GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
  242. company_user.nick_name as companyUserNickName,
  243. fs_user_company_user.is_repeat_fans,
  244. fs_user_company_user.project_id,
  245. fs_user_company_user.`status`,
  246. ifnull(fs_user_company_user.remark, fs_user.remark) as remark,
  247. fs_user_company_user.id as userCompanyUserId,
  248. fs_user_company_user.create_time
  249. FROM
  250. fs_user
  251. INNER JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  252. 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
  253. left join fs_user_project_tag upt ON upt.user_company_user_id = fs_user_company_user.id
  254. LEFT JOIN company_tag ON company_tag.tag_id = upt.tag_id
  255. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  256. where fs_user.is_del = 0
  257. <if test="userId != null and userId!= 0 ">
  258. and fs_user_company_user.company_user_id = #{userId}
  259. </if>
  260. <if test="companyId != null ">
  261. and fs_user_company_user.company_id = #{companyId}
  262. </if>
  263. <if test="status != null">
  264. AND fs_user_company_user.status = #{status}
  265. </if>
  266. <if test="projectId != null">
  267. AND fs_user_company_user.project_id = #{projectId}
  268. </if>
  269. <if test="keyword != null and keyword !='' ">
  270. AND (fs_user.nick_name LIKE concat('%',#{keyword},'%')
  271. or fs_user.phone LIKE concat('%',#{keyword},'%')
  272. )
  273. </if>
  274. <if test="registerStartTime != null and registerStartTime !='' ">
  275. AND fs_user_company_user.create_time &gt;= #{registerStartTime}
  276. </if>
  277. <if test="registerEndTime != null and registerEndTime !='' ">
  278. AND fs_user_company_user.create_time &lt;= #{registerEndTime}
  279. </if>
  280. <if test="isNullTag">
  281. and (upt.tag_id is null
  282. <if test="tagIds != null and tagIds.length > 0">
  283. or upt.tag_id in
  284. <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
  285. #{item}
  286. </foreach>
  287. </if>
  288. )
  289. </if>
  290. <if test="!isNullTag and tagIds != null and tagIds.length > 0">
  291. AND upt.tag_id in
  292. <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
  293. #{item}
  294. </foreach>
  295. </if>
  296. <if test="tabValue != null and tabValue !='' ">
  297. <choose>
  298. <when test = "tabValue == 1">
  299. AND fs_user_company_user.create_time >= CURDATE() AND fs_user_company_user.create_time &lt; CURDATE() + INTERVAL 1 DAY
  300. </when>
  301. <when test = "tabValue == 2">
  302. AND fs_user_course_count.complete_watch_date >= CURDATE() AND fs_user_course_count.complete_watch_date &lt; CURDATE() + INTERVAL 1 DAY
  303. </when>
  304. <when test = "tabValue == 3">
  305. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  306. </when>
  307. </choose>
  308. </if>
  309. <if test="watchCourseType != null and watchCourseType !='' ">
  310. <choose>
  311. <when test = "watchCourseType == 1">
  312. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  313. </when>
  314. <when test = "watchCourseType == 2">
  315. AND fs_user_course_count.status = 1
  316. </when>
  317. <when test = "watchCourseType == 3">
  318. AND fs_user_course_count.status = 2
  319. </when>
  320. </choose>
  321. </if>
  322. <if test="missCourseStatus != null and missCourseStatus !='' ">
  323. <choose>
  324. <when test = "missCourseStatus == 1">
  325. AND fs_user_course_count.miss_course_status = 1
  326. </when>
  327. <when test = "missCourseStatus == 2">
  328. AND (fs_user_course_count.miss_course_status = 2 or fs_user_course_count.miss_course_status is null )
  329. </when>
  330. </choose>
  331. </if>
  332. group by fs_user.user_id, fs_user_company_user.project_id, fs_user_company_user.create_time
  333. order by
  334. <choose>
  335. <when test = "continueMissCourseSort != null and continueMissCourseSort == 0">
  336. fs_user_company_user.create_time desc,fs_user.user_id desc
  337. </when>
  338. <when test = "continueMissCourseSort != null and continueMissCourseSort == 1">
  339. fs_user.nick_name asc,fs_user.user_id desc
  340. </when>
  341. <otherwise>
  342. fs_user.user_id desc, fs_user_company_user.project_id
  343. </otherwise>
  344. </choose>
  345. </select>
  346. <select id="selectFsUserPageListNew" resultType="com.fs.store.vo.h5.FsUserPageListVO">
  347. SELECT
  348. fs_user.user_id,
  349. fs_user.nick_name as nickname,
  350. fs_user.avatar,
  351. fs_user.phone,
  352. fs_user.status,
  353. fs_user.create_time,
  354. fs_user.remark,
  355. ucu.company_user_id,
  356. ucu.company_id,
  357. ucu.project_id,
  358. fs_user.integral,
  359. if(fs_user.pay_count>0,1,0) as isBuy
  360. FROM
  361. fs_user
  362. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  363. <where>
  364. fs_user.is_del = 0
  365. <if test="userId != null">
  366. AND fs_user.user_id = #{userId}
  367. </if>
  368. <if test="companyId != null">
  369. AND ucu.company_id = #{companyId}
  370. </if>
  371. <if test="companyUserId != null and companyUserId != '' ">
  372. AND ucu.company_user_id = #{companyUserId}
  373. </if>
  374. <if test="registerStartTime != null and registerStartTime !='' ">
  375. AND fs_user.create_time &gt;= #{registerStartTime}
  376. </if>
  377. <if test="registerEndTime != null and registerEndTime !='' ">
  378. AND fs_user.create_time &lt;= #{registerEndTime}
  379. </if>
  380. <if test="companyUserIds != null and companyUserIds.size > 0">
  381. AND ucu.company_user_id in
  382. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  383. ${item}
  384. </foreach>
  385. </if>
  386. <if test="nickname != null and nickname != ''">
  387. AND fs_user.nick_name like concat('%', #{nickname},'%')
  388. </if>
  389. <if test="phone != null and phone != ''">
  390. AND fs_user.phone like concat('%', #{phone},'%')
  391. </if>
  392. <if test="projectId != null">
  393. AND ucu.project_id = #{projectId}
  394. </if>
  395. </where>
  396. limit ${(pageNum-1)*pageSize},${pageSize}
  397. </select>
  398. <select id="selectFsUserPageListCount" resultType="java.lang.Long">
  399. SELECT
  400. count(1)
  401. FROM
  402. fs_user
  403. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  404. <where>
  405. fs_user.is_del = 0
  406. <if test="companyId != null">
  407. AND ucu.company_id = #{companyId}
  408. </if>
  409. <if test="companyUserId != null and companyUserId != '' ">
  410. AND ucu.company_user_id = #{companyUserId}
  411. </if>
  412. <if test="registerStartTime != null and registerStartTime !='' ">
  413. AND fs_user.create_time &gt;= #{registerStartTime}
  414. </if>
  415. <if test="registerEndTime != null and registerEndTime !='' ">
  416. AND fs_user.create_time &lt;= #{registerEndTime}
  417. </if>
  418. <if test="companyUserIds != null and companyUserIds.size > 0">
  419. AND ucu.company_user_id in
  420. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  421. ${item}
  422. </foreach>
  423. </if>
  424. <if test="nickname != null and nickname!=''">
  425. AND fs_user.nick_name like concat(#{nickname},'%')
  426. </if>
  427. <if test="phone != null and phone!=''">
  428. AND fs_user.phone = #{phone}
  429. </if>
  430. <if test="projectId != null">
  431. AND ucu.project_id = #{projectId}
  432. </if>
  433. </where>
  434. </select>
  435. <update id="transferCompanyUser">
  436. update fs_user
  437. set company_user_id=#{targetCompanyUserId}
  438. where
  439. user_id in
  440. <foreach collection="userIds" open="(" close=")" separator="," item="item">
  441. ${item}
  442. </foreach>
  443. </update>
  444. <update id="batchUpdateFsUserByIds" parameterType="Long">
  445. update fs_user
  446. set status = #{status} where user_id in
  447. <foreach item="id" collection="ids" open="(" separator="," close=")">
  448. #{id}
  449. </foreach>
  450. </update>
  451. <select id="selectFsUserVOList" resultType="com.fs.his.vo.FsUserVO">
  452. SELECT
  453. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  454. u.*,
  455. 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
  456. ,company.company_name
  457. FROM
  458. fs_user u
  459. LEFT JOIN (
  460. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  461. user_id
  462. FROM
  463. fs_store_payment
  464. WHERE
  465. STATUS = 1
  466. AND user_id IS NOT NULL
  467. GROUP BY
  468. user_id
  469. ) b ON u.user_id = b.user_id
  470. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  471. AND b.last_buy_time = p.pay_time
  472. AND b.payment_id = p.payment_id
  473. LEFT JOIN (
  474. SELECT
  475. fs_course_watch_log.user_id,
  476. Max( fs_course_watch_log.last_heartbeat_time ) AS last_watch_date,
  477. count( DISTINCT fs_course_watch_log.video_id ) watch_course_count,
  478. count( DISTINCT fs_course_watch_log.period_id ) part_course_count
  479. FROM
  480. fs_course_watch_log
  481. GROUP BY
  482. fs_course_watch_log.user_id
  483. ) fs_course_watch_log ON fs_course_watch_log.user_id = u.user_id
  484. LEFT JOIN company_user ON company_user.user_id = u.company_user_id
  485. LEFT JOIN company on company.company_id = company_user.company_id
  486. <where>
  487. 1 = 1
  488. <if test = "maps.userId != null">
  489. AND u.user_id LIKE CONCAT("%",#{maps.userId},"%")
  490. </if >
  491. <if test = "maps.nickname != null and maps.nickname !='' " >
  492. AND u.nickname LIKE CONCAT("%",#{maps.nickname},"%")
  493. </if >
  494. <if test = "maps.phone != null and maps.phone !='' " >
  495. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  496. </if >
  497. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  498. AND (DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  499. and DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  500. )
  501. </if >
  502. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  503. AND u.register_code = #{maps.registerCode}
  504. </if >
  505. <if test = "maps.status != null" >
  506. AND u.STATUS = #{maps.status}
  507. </if >
  508. <if test = "maps.companyUserNickName != null and maps.companyUserNickName != '' " >
  509. AND company_user.nick_name like CONCAT ("%",#{maps.companyUserNickName},"%")
  510. </if >
  511. <if test = "maps.companyName != null and maps.companyName != '' " >
  512. AND company.company_name like CONCAT ("%",#{maps.companyName},"%")
  513. </if >
  514. <if test = "maps.level != null and maps.level !=''" >
  515. AND u.LEVEL = #{maps.level}
  516. </if >
  517. <if test = "maps.isPromoter != null and maps.isPromoter !=''" >
  518. AND u.is_promoter = #{maps.isPromoter}
  519. </if >
  520. </where>
  521. ORDER BY
  522. user_id DESC
  523. </select>
  524. <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
  525. insert into fs_user
  526. <trim prefix="(" suffix=")" suffixOverrides=",">
  527. <if test="nickName != null">nick_name,</if>
  528. <if test="avatar != null">avatar,</if>
  529. <if test="phone != null">phone,</if>
  530. <if test="integral != null">integral,</if>
  531. <if test="signNum != null">sign_num,</if>
  532. <if test="status != null">status,</if>
  533. <if test="tuiUserId != null">tui_user_id,</if>
  534. <if test="tuiTime != null">tui_time,</if>
  535. <if test="tuiUserCount != null">tui_user_count,</if>
  536. <if test="maOpenId != null">ma_open_id,</if>
  537. <if test="mpOpenId != null">mp_open_id,</if>
  538. <if test="unionId != null">union_id,</if>
  539. <if test="isDel != null">is_del,</if>
  540. <if test="userCode != null">user_code,</if>
  541. <if test="remark != null">remark,</if>
  542. <if test="createTime != null">create_time,</if>
  543. <if test="updateTime != null">update_time,</if>
  544. <if test="lastIp != null">last_ip,</if>
  545. <if test="balance != null">balance,</if>
  546. <if test="integralStatus != null">integral_status,</if>
  547. <if test="isBuy != null">is_buy,</if>
  548. <if test="password != null">password,</if>
  549. <if test="jpushId != null">jpush_id,</if>
  550. <if test="isVip != null">is_vip,</if>
  551. <if test="vipStartDate != null">vip_start_date,</if>
  552. <if test="vipEndDate != null">vip_end_date,</if>
  553. <if test="vipLevel != null">vip_level,</if>
  554. <if test="vipStatus != null">vip_status,</if>
  555. <if test="sex != null">sex,</if>
  556. <if test="storeOpenId != null">store_open_id,</if>
  557. <if test="isPush != null">is_push,</if>
  558. <if test="isIndividuationPush != null">is_individuation_push,</if>
  559. <if test="isWeixinAuth != null">is_weixin_auth,</if>
  560. <if test="loginDevice != null">login_device,</if>
  561. <if test="source != null">source,</if>
  562. <if test="isAddQw != null">is_add_qw,</if>
  563. <if test="courseMaOpenId != null">course_ma_open_id,</if>
  564. <if test="qwExtId != null">qw_ext_id,</if>
  565. <if test="orderCount != null">order_count,</if>
  566. <if test="companyId != null">company_id,</if>
  567. <if test="companyUserId != null">company_user_id,</if>
  568. <if test="level != null">`level`,</if>
  569. <if test="spreadUserId != null">spread_user_id,</if>
  570. <if test="spreadTime != null">spread_time,</if>
  571. <if test="isPromoter != null">is_promoter,</if>
  572. <if test="payCount != null">pay_count,</if>
  573. <if test="spreadCount != null">spread_count,</if>
  574. <if test="appId != null">app_id,</if>
  575. </trim>
  576. <trim prefix="values (" suffix=")" suffixOverrides=",">
  577. <if test="nickName != null">#{nickName},</if>
  578. <if test="avatar != null">#{avatar},</if>
  579. <if test="phone != null">#{phone},</if>
  580. <if test="integral != null">#{integral},</if>
  581. <if test="signNum != null">#{signNum},</if>
  582. <if test="status != null">#{status},</if>
  583. <if test="tuiUserId != null">#{tuiUserId},</if>
  584. <if test="tuiTime != null">#{tuiTime},</if>
  585. <if test="tuiUserCount != null">#{tuiUserCount},</if>
  586. <if test="maOpenId != null">#{maOpenId},</if>
  587. <if test="mpOpenId != null">#{mpOpenId},</if>
  588. <if test="unionId != null">#{unionId},</if>
  589. <if test="isDel != null">#{isDel},</if>
  590. <if test="userCode != null">#{userCode},</if>
  591. <if test="remark != null">#{remark},</if>
  592. <if test="createTime != null">#{createTime},</if>
  593. <if test="updateTime != null">#{updateTime},</if>
  594. <if test="lastIp != null">#{lastIp},</if>
  595. <if test="balance != null">#{balance},</if>
  596. <if test="integralStatus != null">#{integralStatus},</if>
  597. <if test="isBuy != null">#{isBuy},</if>
  598. <if test="password != null">#{password},</if>
  599. <if test="jpushId != null">#{jpushId},</if>
  600. <if test="isVip != null">#{isVip},</if>
  601. <if test="vipStartDate != null">#{vipStartDate},</if>
  602. <if test="vipEndDate != null">#{vipEndDate},</if>
  603. <if test="vipLevel != null">#{vipLevel},</if>
  604. <if test="vipStatus != null">#{vipStatus},</if>
  605. <if test="sex != null">#{sex},</if>
  606. <if test="storeOpenId != null">#{storeOpenId},</if>
  607. <if test="isPush != null">#{isPush},</if>
  608. <if test="isIndividuationPush != null">#{isIndividuationPush},</if>
  609. <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
  610. <if test="loginDevice != null">#{loginDevice},</if>
  611. <if test="source != null">#{source},</if>
  612. <if test="isAddQw != null">#{isAddQw},</if>
  613. <if test="courseMaOpenId != null">#{courseMaOpenId},</if>
  614. <if test="qwExtId != null">#{qwExtId},</if>
  615. <if test="orderCount != null">#{orderCount},</if>
  616. <if test="companyId != null">#{companyId},</if>
  617. <if test="companyUserId != null">#{companyUserId},</if>
  618. <if test="level != null">#{level},</if>
  619. <if test="spreadUserId != null">#{spreadUserId},</if>
  620. <if test="spreadTime != null">#{spreadTime},</if>
  621. <if test="isPromoter != null">#{isPromoter},</if>
  622. <if test="payCount != null">#{payCount},</if>
  623. <if test="spreadCount != null">#{spreadCount},</if>
  624. <if test="appId != null">#{appId},</if>
  625. </trim>
  626. </insert>
  627. <update id="updateFsUser" parameterType="FsUser">
  628. update fs_user
  629. <trim prefix="SET" suffixOverrides=",">
  630. <if test="nickName != null">nick_name = #{nickName},</if>
  631. <if test="avatar != null">avatar = #{avatar},</if>
  632. <if test="phone != null">phone = #{phone},</if>
  633. <if test="integral != null">integral = #{integral},</if>
  634. <if test="signNum != null">sign_num = #{signNum},</if>
  635. <if test="status != null">status = #{status},</if>
  636. <if test="tuiUserId != null">tui_user_id = #{tuiUserId},</if>
  637. <if test="tuiTime != null">tui_time = #{tuiTime},</if>
  638. <if test="tuiUserCount != null">tui_user_count = #{tuiUserCount},</if>
  639. <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
  640. <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
  641. <if test="unionId != null">union_id = #{unionId},</if>
  642. <if test="isDel != null">is_del = #{isDel},</if>
  643. <if test="userCode != null">user_code = #{userCode},</if>
  644. <if test="remark != null">remark = #{remark},</if>
  645. <if test="level != null">level = #{level},</if>
  646. <if test="createTime != null">create_time = #{createTime},</if>
  647. <if test="updateTime != null">update_time = #{updateTime},</if>
  648. <if test="lastIp != null">last_ip = #{lastIp},</if>
  649. <if test="balance != null">balance = #{balance},</if>
  650. <if test="integralStatus != null">integral_status = #{integralStatus},</if>
  651. <if test="isBuy != null">is_buy = #{isBuy},</if>
  652. <if test="isShow != null">is_show = #{isShow},</if>
  653. <if test="password != null">password = #{password},</if>
  654. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  655. <if test="isVip != null">is_vip = #{isVip},</if>
  656. <if test="vipStartDate != null">vip_start_date = #{vipStartDate},</if>
  657. <if test="vipEndDate != null">vip_end_date = #{vipEndDate},</if>
  658. <if test="vipLevel != null">vip_level = #{vipLevel},</if>
  659. <if test="vipStatus != null">vip_status = #{vipStatus},</if>
  660. <if test="sex != null">sex = #{sex},</if>
  661. <if test="storeOpenId != null">store_open_id = #{storeOpenId},</if>
  662. <if test="isPush != null">is_push = #{isPush},</if>
  663. <if test="isIndividuationPush != null">is_individuation_push = #{isIndividuationPush},</if>
  664. <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
  665. <if test="loginDevice != null">login_device = #{loginDevice},</if>
  666. <if test="source != null">source = #{source},</if>
  667. <if test="isAddQw != null">is_add_qw = #{isAddQw},</if>
  668. <if test="courseMaOpenId != null">course_ma_open_id = #{courseMaOpenId},</if>
  669. <if test="parentId != null">parent_id = #{parentId},</if>
  670. <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
  671. <if test="isPromoter != null">is_promoter = #{isPromoter},</if>
  672. <if test="companyId != null">company_id = #{companyId},</if>
  673. <if test="orderCount != null">order_count = #{orderCount},</if>
  674. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  675. <if test="appId != null">app_id = #{appId},</if>
  676. </trim>
  677. where user_id = #{userId}
  678. </update>
  679. <delete id="deleteFsUserByUserId" parameterType="Long">
  680. delete from fs_user where user_id = #{userId}
  681. </delete>
  682. <delete id="deleteFsUserByUserIds" parameterType="Long">
  683. delete from fs_user where user_id in
  684. <foreach item="userId" collection="array" open="(" separator="," close=")">
  685. #{userId}
  686. </foreach>
  687. </delete>
  688. <update id="batchUpdateUserCompanyUser">
  689. update fs_user
  690. set company_id = #{companyId},
  691. company_user_id = #{companyUserId}
  692. where
  693. <foreach collection="userIds" separator="or" item="userId" index="index">
  694. user_id = #{userId}
  695. </foreach>
  696. </update>
  697. <update id="batchUpdateCompanyUserRelation">
  698. update fs_user_company_user
  699. set company_id = #{companyId},
  700. company_user_id = #{companyUserId}
  701. where is_repeat_fans = 0 and
  702. <foreach collection="userIds" open="(" close=")" separator="or" item="userId" index="index">
  703. user_id = #{userId}
  704. </foreach>
  705. </update>
  706. <select id="selectUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  707. select
  708. u.user_id dictValue,
  709. u.nick_name dictLabel
  710. from fs_user u
  711. <where>
  712. <if test="params.nickName != null and params.nickName != ''">
  713. u.nick_name like concat('%', #{params.nickName}, '%')
  714. </if>
  715. </where>
  716. </select>
  717. <select id ="selectFsUserByUserIds" resultType="Integer">
  718. select count(1) from fs_user_company_user
  719. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  720. where is_repeat_fans = 1
  721. and (fs_user_company_user.company_user_id = #{companyUserId} OR company_user.parent_id = #{companyUserId})
  722. <if test="userIds != null and userIds.length > 0 ">
  723. and fs_user_company_user.user_id in
  724. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  725. #{userId}
  726. </foreach>
  727. </if>
  728. </select>
  729. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  730. select
  731. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  732. count(u.user_id) vipCount
  733. from fs_user u
  734. left join fs_user_company_user ucu on ucu.user_id = u.user_id
  735. left join company_user cu on cu.user_id = ucu.company_user_id
  736. where cu.user_id = #{companyUserId}
  737. </select>
  738. <select id="getUserNumber" resultType="com.fs.store.vo.h5.UserListCountVO">
  739. SELECT
  740. fs_user_company_user.`status` as status,
  741. count( DISTINCT fs_user.user_id ) AS num
  742. FROM
  743. fs_user
  744. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  745. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  746. WHERE fs_user.is_del = 0 and fs_user_company_user.is_repeat_fans is not null
  747. <if test="userId != null and userId != 0 ">
  748. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  749. </if>
  750. <if test="companyId != null ">
  751. and fs_user_company_user.company_id = #{companyId}
  752. </if>
  753. GROUP BY
  754. fs_user_company_user.`status`,fs_user_company_user.project_id
  755. </select>
  756. <select id="getRepeatUserNumber" resultType="int">
  757. SELECT
  758. count( DISTINCT fs_user.user_id ) AS num
  759. FROM
  760. fs_user
  761. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  762. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  763. WHERE
  764. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  765. AND fs_user.is_del = 0
  766. AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
  767. </select>
  768. <select id="getCountWatchCourse" resultType="com.fs.store.vo.h5.UserDetailsVO">
  769. SELECT
  770. <if test="dateTag == null or dateTag =='' or dateTag == '近七天' ">
  771. ifnull( sum(complete_watch_count), 0 ) AS completeWatchCount ,
  772. ifnull( sum(watch_times), 0 ) AS watchTimes,
  773. </if>
  774. <if test="dateTag != null and dateTag !='' and dateTag != '近七天' ">
  775. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  776. ifnull( watch_times, 0 ) AS watchTimes,
  777. </if>
  778. fs_user.user_id
  779. FROM
  780. fs_user_course_count
  781. LEFT JOIN fs_user ON fs_user.user_id = fs_user_course_count.user_id
  782. 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
  783. <where>
  784. <if test="dateTag != null and dateTag !='' ">
  785. <choose>
  786. <when test = "dateTag == '今天'">
  787. and to_days(fs_user_course_count.create_time) = to_days(now())
  788. </when>
  789. <when test = "dateTag == '昨天'">
  790. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_user_course_count.create_time &lt; CURDATE()
  791. </when>
  792. <when test = "dateTag == '前天'">
  793. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_user_course_count.create_time &lt; CURDATE() - INTERVAL 1 DAY
  794. </when>
  795. <when test = "dateTag == '近七天'">
  796. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  797. </when>
  798. </choose>
  799. </if>
  800. and fs_user.user_id = #{fsUserId}
  801. <if test="userCompanyId!=null">
  802. and cu.id = #{userCompanyId}
  803. </if>
  804. </where>
  805. GROUP BY
  806. fs_user.user_id
  807. </select>
  808. <select id="getCountAnswer" resultType="com.fs.store.vo.h5.UserDetailsVO">
  809. SELECT
  810. (
  811. SELECT
  812. ifnull(count( DISTINCT fs_course_answer_logs.log_id ), 0) AS answerTime
  813. FROM
  814. fs_course_answer_logs
  815. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  816. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id =fcwl.log_id
  817. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  818. <where>
  819. <if test="dateTag != null and dateTag !='' ">
  820. <choose>
  821. <when test = "dateTag == '今天'">
  822. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  823. </when>
  824. <when test = "dateTag == '昨天'">
  825. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  826. </when>
  827. <when test = "dateTag == '前天'">
  828. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  829. </when>
  830. <when test = "dateTag == '近七天'">
  831. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  832. </when>
  833. </choose>
  834. </if>
  835. and fs_user.user_id = #{fsUserId} and fucu.company_user_id =#{userId}
  836. </where>
  837. GROUP BY
  838. fs_user.user_id
  839. ) AS answerTime,
  840. (
  841. SELECT
  842. ifnull(count( DISTINCT fs_course_answer_logs.log_id ), 0) AS answerRightTime
  843. FROM
  844. fs_course_answer_logs
  845. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  846. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id =fcwl.log_id
  847. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  848. <where>
  849. fs_course_answer_logs.is_right = 1
  850. <if test="dateTag != null and dateTag !='' ">
  851. <choose>
  852. <when test = "dateTag == '今天'">
  853. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  854. </when>
  855. <when test = "dateTag == '昨天'">
  856. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  857. </when>
  858. <when test = "dateTag == '前天'">
  859. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  860. </when>
  861. <when test = "dateTag == '近七天'">
  862. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  863. </when>
  864. </choose>
  865. </if>
  866. and fs_user.user_id = #{fsUserId} and fucu.company_user_id =#{userId}
  867. </where>
  868. GROUP BY
  869. fs_user.user_id
  870. ) AS answerRightTime;
  871. </select>
  872. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  873. SELECT
  874. ifnull( count( DISTINCT fs_course_red_packet_log.log_id ), 0 ) AS answerRedPacketTime,
  875. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  876. fs_user.user_id
  877. FROM
  878. fs_course_red_packet_log
  879. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  880. left join fs_course_watch_log fcwl on fs_course_red_packet_log.watch_log_id =fcwl.log_id
  881. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  882. <where>
  883. fs_course_red_packet_log.status = 1
  884. <if test="dateTag != null and dateTag !='' ">
  885. <choose>
  886. <when test = "dateTag == '今天'">
  887. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  888. </when>
  889. <when test = "dateTag == '昨天'">
  890. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE()
  891. </when>
  892. <when test = "dateTag == '前天'">
  893. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE() - INTERVAL 1 DAY
  894. </when>
  895. <when test = "dateTag == '近七天'">
  896. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  897. </when>
  898. </choose>
  899. </if>
  900. and fs_user.user_id = #{fsUserId} and fucu.company_user_id =#{userId}
  901. </where>
  902. GROUP BY
  903. fs_user.user_id
  904. </select>
  905. <select id="getUserTotal" resultType="java.lang.Integer">
  906. SELECT count(fs_user.user_id) as userTotal
  907. FROM fs_user
  908. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  909. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  910. WHERE fs_user.is_del = 0
  911. <if test="userId != null and userId != 0 ">
  912. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  913. </if>
  914. <if test="companyId != null ">
  915. and ucu.company_id = #{companyId}
  916. </if>
  917. </select>
  918. <select id="getTodayNewUser" resultType="java.lang.Integer">
  919. SELECT count(fs_user.user_id) as todayNewUser
  920. FROM fs_user
  921. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  922. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  923. WHERE fs_user.is_del = 0
  924. <if test="userId != null and userId != 0 ">
  925. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  926. </if>
  927. <if test="companyId != null ">
  928. and ucu.company_id = #{companyId}
  929. </if>
  930. AND to_days(ucu.create_time) = to_days(now())
  931. </select>
  932. <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
  933. SELECT (SELECT count(fs_user.user_id)
  934. FROM fs_user
  935. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  936. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  937. WHERE fs_user.is_del = 0
  938. <if test="userId != null and userId != 0 ">
  939. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  940. </if>
  941. <if test="companyId != null ">
  942. and ucu.company_id = #{companyId}
  943. </if>
  944. ) as userTotal,
  945. (SELECT count(fs_user.user_id)
  946. FROM fs_user
  947. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  948. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  949. WHERE fs_user.is_del = 0
  950. <if test="userId != null and userId != 0 ">
  951. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  952. </if>
  953. <if test="companyId != null ">
  954. and ucu.company_id = #{companyId}
  955. </if>
  956. AND to_days(ucu.create_time) = to_days(now())) as todayNewUser
  957. </select>
  958. <select id="countTag" resultType="com.fs.store.vo.h5.FsUserSummaryCountTagVO">
  959. SELECT
  960. company_tag.tag AS tagName,
  961. count( ucu.user_id ) AS number
  962. FROM
  963. fs_user_project_tag upt
  964. inner join fs_user_company_user ucu on ucu.id = upt.user_company_user_id
  965. inner join company_tag ON upt.tag_id = company_tag.tag_id
  966. left join company_user on company_user.user_id = ucu.company_user_id
  967. <where>
  968. <if test="userId != null and userId != 0 ">
  969. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  970. </if>
  971. <if test="companyId != null ">
  972. and ucu.company_id = #{companyId}
  973. </if>
  974. </where>
  975. GROUP BY
  976. company_tag.tag_id
  977. </select>
  978. <select id="countUserCourse" resultType="Map">
  979. SELECT
  980. (SELECT COUNT(*) FROM (
  981. SELECT 1
  982. FROM fs_user_course_count fcc
  983. JOIN fs_user ON fs_user.user_id = fcc.user_id
  984. JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
  985. JOIN company_user ON ucu.company_user_id = company_user.user_id
  986. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  987. <where>
  988. fcc.project_id = ucu.project_id
  989. <if test="userId != null and userId != 0 ">
  990. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  991. </if>
  992. <if test="userId != null and userId == 0 ">
  993. and ucu.company_id = #{companyId}
  994. </if>
  995. <if test="startTime != null and startTime !='' ">
  996. and fcc.create_time &gt;= #{startTime}
  997. </if>
  998. <if test="endTime != null and endTime != ''">
  999. and fcc.create_time &lt;= #{endTime}
  1000. </if>
  1001. <if test="periodId != null and periodId != ''">
  1002. AND fcpd.period_id = #{periodId}
  1003. </if>
  1004. <if test="videoId != null and videoId != ''">
  1005. AND fcpd.video_id = #{videoId}
  1006. </if>
  1007. -- 单独通过销售id查询
  1008. <if test="companyUserId != null and companyUserId != ''">
  1009. AND company_user.user_id = #{companyUserId}
  1010. </if>
  1011. </where>
  1012. ) as courseWatchNum,
  1013. (SELECT COUNT(*) FROM (
  1014. SELECT 1
  1015. FROM fs_user_course_count fcc
  1016. JOIN fs_user ON fs_user.user_id = fcc.user_id
  1017. JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
  1018. JOIN company_user ON ucu.company_user_id = company_user.user_id
  1019. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  1020. <where>
  1021. fcc.project_id = ucu.project_id
  1022. <if test="userId != null and userId != 0 ">
  1023. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1024. </if>
  1025. <if test="userId != null and userId == 0 ">
  1026. and ucu.company_id = #{companyId}
  1027. </if>
  1028. AND fcc.complete_watch_count > 0
  1029. <if test="startTime != null and startTime !='' ">
  1030. and fcc.create_time &gt;= #{startTime}
  1031. </if>
  1032. <if test="endTime != null and endTime != ''">
  1033. and fcc.create_time &lt;= #{endTime}
  1034. </if>
  1035. <if test="periodId != null and periodId != ''">
  1036. AND fcpd.period_id = #{periodId}
  1037. </if>
  1038. <if test="videoId != null and videoId != ''">
  1039. AND fcpd.video_id = #{videoId}
  1040. </if>
  1041. -- 单独通过销售id查询
  1042. <if test="companyUserId != null and companyUserId != ''">
  1043. AND company_user.user_id = #{companyUserId}
  1044. </if>
  1045. </where>
  1046. GROUP BY fcc.user_id, ucu.project_id
  1047. ) AS complete_counts ) as courseCompleteNum
  1048. </select>
  1049. <select id="countUserStats" resultType="Map">
  1050. SELECT
  1051. -- 观看人数
  1052. (
  1053. SELECT COUNT(DISTINCT l.user_id)
  1054. FROM fs_course_watch_log l
  1055. LEFT JOIN fs_user u ON u.user_id = l.user_id
  1056. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  1057. <where>
  1058. l.log_type != 3 AND l.send_type = 1
  1059. <if test="userId != null and userId != 0 ">
  1060. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1061. </if>
  1062. <if test="userId != null and userId == 0 ">
  1063. AND l.company_id = #{companyId}
  1064. </if>
  1065. <if test="periodId != null and periodId != '' ">
  1066. AND l.period_id = #{periodId}
  1067. </if>
  1068. <if test="videoId != null and videoId != '' ">
  1069. AND l.video_id = #{videoId}
  1070. </if>
  1071. <if test="startTime != null and startTime != '' ">
  1072. AND l.create_time &gt;= #{startTime}
  1073. </if>
  1074. <if test="endTime != null and endTime != '' ">
  1075. AND l.create_time &lt;= #{endTime}
  1076. </if>
  1077. <if test="companyUserId != null and companyUserId != '' ">
  1078. AND l.company_user_id = #{companyUserId}
  1079. </if>
  1080. </where>
  1081. ) AS courseWatchNum,
  1082. -- 完成人数
  1083. (
  1084. SELECT COUNT(DISTINCT l.user_id)
  1085. FROM fs_course_watch_log l
  1086. LEFT JOIN fs_user u ON u.user_id = l.user_id
  1087. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  1088. <where>
  1089. l.log_type = 2 AND l.send_type = 1
  1090. <if test="userId != null and userId != 0 ">
  1091. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1092. </if>
  1093. <if test="userId != null and userId == 0 ">
  1094. AND l.company_id = #{companyId}
  1095. </if>
  1096. <if test="periodId != null and periodId != '' ">
  1097. AND l.period_id = #{periodId}
  1098. </if>
  1099. <if test="videoId != null and videoId != '' ">
  1100. AND l.video_id = #{videoId}
  1101. </if>
  1102. <if test="startTime != null and startTime != '' ">
  1103. AND l.create_time &gt;= #{startTime}
  1104. </if>
  1105. <if test="endTime != null and endTime != '' ">
  1106. AND l.create_time &lt;= #{endTime}
  1107. </if>
  1108. <if test="companyUserId != null and companyUserId != '' ">
  1109. AND l.company_user_id = #{companyUserId}
  1110. </if>
  1111. </where>
  1112. ) AS courseCompleteNum,
  1113. -- 答题人数
  1114. (
  1115. SELECT COUNT(distinct a.user_id)
  1116. FROM fs_course_answer_logs a
  1117. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1118. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  1119. <where>
  1120. 1=1
  1121. <if test="userId != null and userId != 0 ">
  1122. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1123. </if>
  1124. <if test="userId != null and userId == 0 ">
  1125. AND a.company_id = #{companyId}
  1126. </if>
  1127. <if test="periodId != null and periodId != '' ">
  1128. AND a.period_id = #{periodId}
  1129. </if>
  1130. <if test="videoId != null and videoId != '' ">
  1131. AND a.video_id = #{videoId}
  1132. </if>
  1133. <if test="startTime != null and startTime != '' ">
  1134. AND a.create_time &gt;= #{startTime}
  1135. </if>
  1136. <if test="endTime != null and endTime != '' ">
  1137. AND a.create_time &lt;= #{endTime}
  1138. </if>
  1139. <if test="companyUserId != null and companyUserId != '' ">
  1140. AND a.company_user_id = #{companyUserId}
  1141. </if>
  1142. </where>
  1143. ) AS answerNum,
  1144. -- 答对人数
  1145. (
  1146. SELECT COUNT(distinct a.user_id)
  1147. FROM fs_course_answer_logs a
  1148. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1149. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  1150. <where>
  1151. a.is_right = 1
  1152. <if test="userId != null and userId != 0 ">
  1153. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1154. </if>
  1155. <if test="userId != null and userId == 0 ">
  1156. AND a.company_id = #{companyId}
  1157. </if>
  1158. <if test="periodId != null and periodId != '' ">
  1159. AND a.period_id = #{periodId}
  1160. </if>
  1161. <if test="videoId != null and videoId != '' ">
  1162. AND a.video_id = #{videoId}
  1163. </if>
  1164. <if test="startTime != null and startTime != '' ">
  1165. AND a.create_time &gt;= #{startTime}
  1166. </if>
  1167. <if test="endTime != null and endTime != '' ">
  1168. AND a.create_time &lt;= #{endTime}
  1169. </if>
  1170. <if test="companyUserId != null and companyUserId != '' ">
  1171. AND a.company_user_id = #{companyUserId}
  1172. </if>
  1173. </where>
  1174. ) AS answerRightNum,
  1175. -- 红包数
  1176. (
  1177. SELECT COUNT(flog.log_id)
  1178. FROM fs_course_red_packet_log flog
  1179. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1180. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1181. <where>
  1182. flog.status = 1
  1183. <if test="userId != null and userId != 0 ">
  1184. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1185. </if>
  1186. <if test="userId != null and userId == 0 ">
  1187. AND flog.company_id = #{companyId}
  1188. </if>
  1189. <if test="periodId != null and periodId != '' ">
  1190. AND flog.period_id = #{periodId}
  1191. </if>
  1192. <if test="videoId != null and videoId != '' ">
  1193. AND flog.video_id = #{videoId}
  1194. </if>
  1195. <if test="startTime != null and startTime != '' ">
  1196. AND flog.create_time &gt;= #{startTime}
  1197. </if>
  1198. <if test="endTime != null and endTime != '' ">
  1199. AND flog.create_time &lt;= #{endTime}
  1200. </if>
  1201. <if test="companyUserId != null and companyUserId != '' ">
  1202. AND flog.company_user_id = #{companyUserId}
  1203. </if>
  1204. </where>
  1205. ) AS redPacketNum,
  1206. -- 红包金额
  1207. (
  1208. SELECT IFNULL(SUM(flog.amount), 0)
  1209. FROM fs_course_red_packet_log flog
  1210. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1211. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1212. <where>
  1213. flog.status = 1
  1214. <if test="userId != null and userId != 0 ">
  1215. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1216. </if>
  1217. <if test="userId != null and userId == 0 ">
  1218. AND flog.company_id = #{companyId}
  1219. </if>
  1220. <if test="periodId != null and periodId != '' ">
  1221. AND flog.period_id = #{periodId}
  1222. </if>
  1223. <if test="videoId != null and videoId != '' ">
  1224. AND flog.video_id = #{videoId}
  1225. </if>
  1226. <if test="startTime != null and startTime != '' ">
  1227. AND flog.create_time &gt;= #{startTime}
  1228. </if>
  1229. <if test="endTime != null and endTime != '' ">
  1230. AND flog.create_time &lt;= #{endTime}
  1231. </if>
  1232. <if test="companyUserId != null and companyUserId != '' ">
  1233. AND flog.company_user_id = #{companyUserId}
  1234. </if>
  1235. </where>
  1236. ) AS redPacketAmount
  1237. </select>
  1238. <!-- 查询观看和完成人数 -->
  1239. <select id="countUserWatchStats" resultType="Map">
  1240. SELECT
  1241. COUNT(DISTINCT CASE WHEN l.log_type != 3 AND l.send_type = 1 THEN l.user_id END) AS courseWatchNum,
  1242. COUNT(DISTINCT CASE WHEN l.log_type = 2 AND l.send_type = 1 THEN l.user_id END) AS courseCompleteNum
  1243. FROM fs_course_watch_log l
  1244. LEFT JOIN fs_user u ON u.user_id = l.user_id
  1245. LEFT JOIN company_user cu_l ON l.company_user_id = cu_l.user_id
  1246. <where>
  1247. <if test="userId != null and userId != 0">
  1248. AND (cu_l.user_id = #{userId} OR cu_l.parent_id = #{userId})
  1249. </if>
  1250. <if test="userId != null and userId == 0">
  1251. AND l.company_id = #{companyId}
  1252. </if>
  1253. <if test="periodId != null and periodId != ''">
  1254. AND l.period_id = #{periodId}
  1255. </if>
  1256. <if test="videoId != null and videoId != ''">
  1257. AND l.video_id = #{videoId}
  1258. </if>
  1259. <if test="startTime != null and startTime != ''">
  1260. AND l.create_time &gt;= #{startTime}
  1261. </if>
  1262. <if test="endTime != null and endTime != ''">
  1263. AND l.create_time &lt;= #{endTime}
  1264. </if>
  1265. <if test="companyUserId != null and companyUserId != ''">
  1266. AND l.company_user_id = #{companyUserId}
  1267. </if>
  1268. </where>
  1269. </select>
  1270. <!-- 查询答题人数和答对人数 -->
  1271. <select id="countUserAnswerStats" resultType="Map">
  1272. SELECT
  1273. COUNT(DISTINCT CASE WHEN a.user_id THEN a.user_id END) AS answerNum,
  1274. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS answerRightNum
  1275. FROM fs_course_answer_logs a
  1276. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1277. LEFT JOIN company_user cu_a ON a.company_user_id = cu_a.user_id
  1278. <where>
  1279. <if test="userId != null and userId != 0">
  1280. AND (cu_a.user_id = #{userId} OR cu_a.parent_id = #{userId})
  1281. </if>
  1282. <if test="userId != null and userId == 0">
  1283. AND a.company_id = #{companyId}
  1284. </if>
  1285. <if test="periodId != null and periodId != ''">
  1286. AND a.period_id = #{periodId}
  1287. </if>
  1288. <if test="videoId != null and videoId != ''">
  1289. AND a.video_id = #{videoId}
  1290. </if>
  1291. <if test="startTime != null and startTime != ''">
  1292. AND a.create_time &gt;= #{startTime}
  1293. </if>
  1294. <if test="endTime != null and endTime != ''">
  1295. AND a.create_time &lt;= #{endTime}
  1296. </if>
  1297. <if test="companyUserId != null and companyUserId != ''">
  1298. AND a.company_user_id = #{companyUserId}
  1299. </if>
  1300. </where>
  1301. </select>
  1302. <!-- 查询红包数量和红包金额 -->
  1303. <select id="countUserRedPacketStats" resultType="Map">
  1304. SELECT
  1305. COUNT(CASE WHEN flog.status = 1 THEN flog.log_id END) AS redPacketNum,
  1306. IFNULL(SUM(CASE WHEN flog.status = 1 THEN flog.amount END), 0) AS redPacketAmount
  1307. FROM fs_course_red_packet_log flog
  1308. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1309. LEFT JOIN company_user cu_flog ON flog.company_user_id = cu_flog.user_id
  1310. <where>
  1311. <if test="userId != null and userId != 0">
  1312. AND (cu_flog.user_id = #{userId} OR cu_flog.parent_id = #{userId})
  1313. </if>
  1314. <if test="userId != null and userId == 0">
  1315. AND flog.company_id = #{companyId}
  1316. </if>
  1317. <if test="periodId != null and periodId != ''">
  1318. AND flog.period_id = #{periodId}
  1319. </if>
  1320. <if test="videoId != null and videoId != ''">
  1321. AND flog.video_id = #{videoId}
  1322. </if>
  1323. <if test="startTime != null and startTime != ''">
  1324. AND flog.create_time &gt;= #{startTime}
  1325. </if>
  1326. <if test="endTime != null and endTime != ''">
  1327. AND flog.create_time &lt;= #{endTime}
  1328. </if>
  1329. <if test="companyUserId != null and companyUserId != ''">
  1330. AND flog.company_user_id = #{companyUserId}
  1331. </if>
  1332. </where>
  1333. </select>
  1334. <select id="countUserAnswer" resultType="Map">
  1335. SELECT
  1336. (
  1337. SELECT
  1338. count(distinct fs_user.user_id )
  1339. FROM
  1340. fs_course_answer_logs
  1341. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1342. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1343. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1344. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1345. <where>
  1346. <if test="userId != null and userId != 0 ">
  1347. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1348. </if>
  1349. <if test="userId != null and userId == 0 ">
  1350. and fs_course_answer_logs.company_id = #{companyId}
  1351. </if>
  1352. <if test="startTime != null and startTime !='' ">
  1353. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1354. </if>
  1355. <if test="endTime != null and endTime != ''">
  1356. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1357. </if>
  1358. <if test="periodId != null and periodId != ''">
  1359. AND fs_course_answer_logs.period_id = #{periodId}
  1360. </if>
  1361. <if test="videoId != null and videoId != ''">
  1362. AND fs_course_answer_logs.video_id = #{videoId}
  1363. </if>
  1364. -- 单独通过销售id查询
  1365. <if test="companyUserId != null and companyUserId != ''">
  1366. AND company_user.user_id = #{companyUserId}
  1367. </if>
  1368. </where>
  1369. ) AS answerNum,
  1370. (
  1371. SELECT
  1372. count(distinct fs_user.user_id )
  1373. FROM
  1374. fs_course_answer_logs
  1375. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1376. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1377. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1378. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1379. <where>
  1380. <if test="userId != null and userId != 0 ">
  1381. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1382. </if>
  1383. <if test="userId != null and userId == 0 ">
  1384. and fs_course_answer_logs.company_id = #{companyId}
  1385. </if>
  1386. AND fs_course_answer_logs.is_right = 1
  1387. <if test="startTime != null and startTime !='' ">
  1388. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1389. </if>
  1390. <if test="endTime != null and endTime != ''">
  1391. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1392. </if>
  1393. <if test="periodId != null and periodId != ''">
  1394. AND fs_course_answer_logs.period_id = #{periodId}
  1395. </if>
  1396. <if test="videoId != null and videoId != ''">
  1397. AND fs_course_answer_logs.video_id = #{videoId}
  1398. </if>
  1399. -- 单独通过销售id查询
  1400. <if test="companyUserId != null and companyUserId != ''">
  1401. AND company_user.user_id = #{companyUserId}
  1402. </if>
  1403. </where>
  1404. ) AS answerRightNum
  1405. </select>
  1406. <select id="countCourseDetails" resultType="Map">
  1407. select (SELECT
  1408. count( DISTINCT fcpd.period_id )
  1409. FROM
  1410. fs_user_course_period_days fcpd
  1411. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1412. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1413. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1414. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1415. WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
  1416. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1417. <if test="userId != null and userId != 0 ">
  1418. AND ucu.company_user_id = #{userId}
  1419. </if>
  1420. <if test="userId != null and userId == 0 ">
  1421. and ucu.company_id = #{companyId}
  1422. </if>
  1423. <if test="periodId != null and periodId != ''">
  1424. AND fcpd.period_id = #{periodId}
  1425. </if>
  1426. -- 单独通过销售id查询
  1427. <if test="companyUserId != null and companyUserId != ''">
  1428. AND ucu.company_user_id = #{companyUserId}
  1429. </if>
  1430. ) as courseNum,
  1431. (SELECT count(DISTINCT fcpd.video_id)
  1432. FROM fs_user_course_period_days fcpd
  1433. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1434. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1435. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1436. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1437. WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
  1438. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1439. <if test="userId != null and userId != 0 ">
  1440. AND ucu.company_user_id = #{userId}
  1441. </if>
  1442. <if test="userId != null and userId == 0 ">
  1443. and ucu.company_id = #{companyId}
  1444. </if>
  1445. <if test="periodId != null and periodId != ''">
  1446. AND fcpd.period_id = #{periodId}
  1447. </if>
  1448. <if test="videoId != null and videoId != ''">
  1449. AND fcpd.video_id = #{videoId}
  1450. </if>
  1451. -- 单独通过销售id查询
  1452. <if test="companyUserId != null and companyUserId != ''">
  1453. AND ucu.company_user_id = #{companyUserId}
  1454. </if>
  1455. ) as videoNum,
  1456. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  1457. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1458. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1459. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1460. <if test="periodId != null and periodId != ''">
  1461. AND fcpd.period_id = #{periodId}
  1462. </if>
  1463. <if test="videoId != null and videoId != ''">
  1464. AND fcpd.video_id = #{videoId}
  1465. </if>
  1466. -- 单独通过销售id查询
  1467. <if test="companyUserId != null and companyUserId != ''">
  1468. AND ucu.company_user_id = #{companyUserId}
  1469. </if>
  1470. <where>
  1471. <if test="userId != null and userId != 0 ">
  1472. AND ucu.company_user_id = #{userId}
  1473. </if>
  1474. <if test="userId != null and userId == 0 ">
  1475. and ucu.company_id = #{companyId}
  1476. </if>
  1477. </where>
  1478. ) as courseUserNum
  1479. </select>
  1480. <select id="countUserRankingByComplete" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1481. SELECT
  1482. company_user.nick_name as userName,
  1483. ifnull(
  1484. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  1485. ) as completeRate
  1486. FROM
  1487. fs_user_course_count fcc
  1488. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1489. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1490. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1491. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1492. <where>
  1493. <if test="userId != null and userId != 0 ">
  1494. AND ( ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1495. </if>
  1496. <if test="userId != null and userId == 0 ">
  1497. and ucu.company_id = #{companyId}
  1498. </if>
  1499. <if test="startTime != null and startTime !='' ">
  1500. AND fcc.create_time &gt;= #{startTime}
  1501. </if>
  1502. <if test="endTime != null and endTime != ''">
  1503. AND fcc.create_time &lt;= #{endTime}
  1504. </if>
  1505. <if test="periodId != null and periodId != ''">
  1506. AND fcpd.period_id = #{periodId}
  1507. </if>
  1508. <if test="videoId != null and videoId != ''">
  1509. AND fcpd.video_id = #{videoId}
  1510. </if>
  1511. </where>
  1512. group by fcc.user_id
  1513. <choose>
  1514. <when test="order != null and order == 'asc'">
  1515. order by completeRate asc
  1516. </when>
  1517. <when test="order != null and order == 'desc'">
  1518. order by completeRate desc
  1519. </when>
  1520. <otherwise>
  1521. order by completeRate desc
  1522. </otherwise>
  1523. </choose>
  1524. limit 20
  1525. </select>
  1526. <select id="countUserRankingByRight" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1527. SELECT
  1528. company_user.nick_name as userName,
  1529. ifnull(ROUND(
  1530. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1531. *100,2),0
  1532. ) as answerRightRate
  1533. FROM
  1534. fs_course_answer_logs
  1535. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1536. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1537. <where>
  1538. <if test="userId != null and userId != 0 ">
  1539. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1540. </if>
  1541. <if test="userId != null and userId == 0 ">
  1542. and fs_course_answer_logs.company_id = #{companyId}
  1543. </if>
  1544. <if test="startTime != null and startTime !='' ">
  1545. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1546. </if>
  1547. <if test="endTime != null and endTime != ''">
  1548. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1549. </if>
  1550. <if test="periodId != null and periodId != ''">
  1551. AND fs_course_answer_logs.period_id = #{periodId}
  1552. </if>
  1553. <if test="videoId != null and videoId != ''">
  1554. AND fs_course_answer_logs.video_id = #{videoId}
  1555. </if>
  1556. </where>
  1557. group by fs_user.user_id
  1558. <choose>
  1559. <when test="order != null and order == 'asc'">
  1560. order by answerRightRate asc
  1561. </when>
  1562. <when test="order != null and order == 'desc'">
  1563. order by answerRightRate desc
  1564. </when>
  1565. <otherwise>
  1566. order by answerRightRate desc
  1567. </otherwise>
  1568. </choose>
  1569. limit 20
  1570. </select>
  1571. <select id="countCourseRankingByComplete" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1572. SELECT
  1573. fcv.title AS videoName,
  1574. fcv.video_id,
  1575. ifnull(
  1576. ROUND(
  1577. (
  1578. 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,
  1579. 2
  1580. ),
  1581. 0
  1582. ) AS completeRate
  1583. FROM
  1584. fs_course_watch_log fwl
  1585. LEFT JOIN fs_user ON fs_user.user_id = fwl.user_id
  1586. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1587. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1588. -- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1589. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fwl.video_id
  1590. <where>
  1591. <if test="userId != null and userId != 0 ">
  1592. AND ( fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1593. </if>
  1594. <if test="userId != null and userId == 0 ">
  1595. and fs_user_company_user.company_id = #{companyId}
  1596. </if>
  1597. <if test="startTime != null and startTime !='' ">
  1598. AND fwl.create_time &gt;= #{startTime}
  1599. </if>
  1600. <if test="endTime != null and endTime != ''">
  1601. AND fwl.create_time &lt;= #{endTime}
  1602. </if>
  1603. <if test="periodId != null and periodId != ''">
  1604. AND fwl.period_id = #{periodId}
  1605. </if>
  1606. <if test="videoId != null and videoId != ''">
  1607. AND fwl.video_id = #{videoId}
  1608. </if>
  1609. </where>
  1610. GROUP BY
  1611. fwl.video_id
  1612. <choose>
  1613. <when test="order != null and order == 'asc'">
  1614. ORDER BY completeRate asc
  1615. </when>
  1616. <when test="order != null and order == 'desc'">
  1617. ORDER BY completeRate desc
  1618. </when>
  1619. <otherwise>
  1620. ORDER BY completeRate desc
  1621. </otherwise>
  1622. </choose>
  1623. LIMIT 20
  1624. </select>
  1625. <select id="countCourseRankingByRight" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1626. SELECT
  1627. fcv.title AS videoName,
  1628. ifnull(
  1629. ROUND(
  1630. (
  1631. 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,
  1632. 2
  1633. ),
  1634. 0
  1635. ) AS answerRightRate
  1636. FROM
  1637. fs_course_answer_logs
  1638. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1639. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1640. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1641. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1642. <where>
  1643. <if test="userId != null and userId != 0 ">
  1644. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1645. </if>
  1646. <if test="userId != null and userId == 0 ">
  1647. and fs_course_answer_logs.company_id = #{companyId}
  1648. </if>
  1649. <if test="startTime != null and startTime !='' ">
  1650. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1651. </if>
  1652. <if test="endTime != null and endTime != ''">
  1653. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1654. </if>
  1655. <if test="periodId != null and periodId != ''">
  1656. AND fs_course_answer_logs.period_id = #{periodId}
  1657. </if>
  1658. <if test="videoId != null and videoId != ''">
  1659. AND fs_course_answer_logs.video_id = #{videoId}
  1660. </if>
  1661. </where>
  1662. GROUP BY
  1663. fs_course_answer_logs.video_id
  1664. <choose>
  1665. <when test="order != null and order == 'asc'">
  1666. ORDER BY answerRightRate asc
  1667. </when>
  1668. <when test="order != null and order == 'desc'">
  1669. ORDER BY answerRightRate desc
  1670. </when>
  1671. <otherwise>
  1672. ORDER BY answerRightRate desc
  1673. </otherwise>
  1674. </choose>
  1675. LIMIT 20
  1676. </select>
  1677. <select id="countUserRedPacket" resultType="Map">
  1678. SELECT
  1679. (
  1680. SELECT
  1681. count( flog.log_id )
  1682. FROM
  1683. fs_course_red_packet_log flog
  1684. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1685. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1686. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1687. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1688. where flog.status = 1
  1689. <if test="userId != null and userId != 0 ">
  1690. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1691. </if>
  1692. <if test="userId != null and userId == 0 ">
  1693. and flog.company_id = #{companyId}
  1694. </if>
  1695. <if test="startTime != null and startTime !='' ">
  1696. AND flog.create_time &gt;= #{startTime}
  1697. </if>
  1698. <if test="endTime != null and endTime != ''">
  1699. AND flog.create_time &lt;= #{endTime}
  1700. </if>
  1701. <if test="periodId != null and periodId != ''">
  1702. AND flog.period_id = #{periodId}
  1703. </if>
  1704. <if test="videoId != null and videoId != ''">
  1705. AND flog.video_id = #{videoId}
  1706. </if>
  1707. -- 单独通过销售id查询
  1708. <if test="companyUserId != null and companyUserId != ''">
  1709. AND company_user.user_id = #{companyUserId}
  1710. </if>
  1711. ) AS redPacketNum,
  1712. (
  1713. SELECT
  1714. ifnull (sum( flog.amount ), 0)
  1715. FROM
  1716. fs_course_red_packet_log flog
  1717. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1718. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1719. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1720. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1721. where flog.status = 1
  1722. <if test="userId != null and userId != 0 ">
  1723. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1724. </if>
  1725. <if test="userId != null and userId == 0 ">
  1726. and flog.company_id = #{companyId}
  1727. </if>
  1728. <if test="startTime != null and startTime !='' ">
  1729. AND flog.create_time &gt;= #{startTime}
  1730. </if>
  1731. <if test="endTime != null and endTime != ''">
  1732. AND flog.create_time &lt;= #{endTime}
  1733. </if>
  1734. <if test="periodId != null and periodId != ''">
  1735. AND flog.period_id = #{periodId}
  1736. </if>
  1737. <if test="videoId != null and videoId != ''">
  1738. AND flog.video_id = #{videoId}
  1739. </if>
  1740. -- 单独通过销售id查询
  1741. <if test="companyUserId != null and companyUserId != ''">
  1742. AND company_user.user_id = #{companyUserId}
  1743. </if>
  1744. ) AS redPacketAmount
  1745. </select>
  1746. <select id="courseAnalysisCourseCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  1747. SELECT
  1748. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1749. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1750. ifnull(
  1751. ROUND(
  1752. (
  1753. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1754. 2
  1755. ),
  1756. 0
  1757. ) as completeRate,
  1758. fcpd.video_id
  1759. FROM
  1760. fs_user_course_count fcc
  1761. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1762. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1763. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1764. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1765. <where>
  1766. <if test="companyUserId != null and companyUserId != 0 ">
  1767. AND ucu.company_user_id = #{companyUserId}
  1768. </if>
  1769. <if test="companyUserId != null and companyUserId == 0 ">
  1770. and ucu.company_id = #{companyId}
  1771. </if>
  1772. <if test="periodId != null and periodId != ''">
  1773. AND fcpd.period_id = #{periodId}
  1774. </if>
  1775. <if test="videoId != null and videoId != ''">
  1776. AND fcpd.video_id = #{videoId}
  1777. </if>
  1778. </where>
  1779. GROUP BY
  1780. fcpd.video_id
  1781. </select>
  1782. <select id="companyUserCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1783. SELECT
  1784. (
  1785. 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
  1786. <where>
  1787. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1788. AND ucu.company_user_id = #{companyUserId}
  1789. </if>
  1790. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1791. and ucu.company_id = #{companyId}
  1792. </if>
  1793. </where>
  1794. ) AS userTotal,
  1795. (
  1796. SELECT
  1797. count( fs_user.user_id )
  1798. FROM
  1799. fs_user
  1800. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1801. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1802. <where>
  1803. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1804. AND ucu.company_user_id = #{companyUserId}
  1805. </if>
  1806. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1807. and ucu.company_id = #{companyId}
  1808. </if>
  1809. and fs_user.is_del = 0
  1810. AND to_days( fs_user.create_time ) = to_days(
  1811. now())
  1812. </where>
  1813. ) AS todayNewUser
  1814. </select>
  1815. <select id="newUserRedPacketCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1816. SELECT
  1817. count(flog.log_id) as userRedPacketNum,
  1818. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1819. FROM
  1820. fs_course_red_packet_log flog
  1821. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1822. <where>
  1823. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1824. AND flog.company_user_id = #{companyUserId}
  1825. </if>
  1826. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1827. and flog.company_id = #{companyId}
  1828. </if>
  1829. </where>
  1830. </select>
  1831. <select id="countUserCourse2" resultType="java.util.Map">
  1832. SELECT
  1833. (
  1834. SELECT
  1835. count(DISTINCT l.user_id)
  1836. FROM
  1837. fs_course_watch_log l
  1838. LEFT JOIN fs_user on fs_user.user_id = l.user_id
  1839. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1840. 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
  1841. where
  1842. l.log_type != 3 and send_type = 1
  1843. <if test="userId != null and userId != 0 ">
  1844. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1845. </if>
  1846. <if test="userId != null and userId == 0 ">
  1847. and l.company_id = #{companyId}
  1848. </if>
  1849. <if test="periodId != null and periodId != ''">
  1850. AND l.period_id = #{periodId}
  1851. </if>
  1852. <if test="videoId != null and videoId != ''">
  1853. AND l.video_id = #{videoId}
  1854. </if>
  1855. <if test="startTime != null and startTime !='' ">
  1856. and l.create_time &gt;= #{startTime}
  1857. </if>
  1858. <if test="endTime != null and endTime != ''">
  1859. and l.create_time &lt;= #{endTime}
  1860. </if> <if test="companyUserId != null and companyUserId != ''">
  1861. AND l.user_id = #{companyUserId}
  1862. </if>
  1863. -- 单独通过销售id查询
  1864. <if test="companyUserId != null and companyUserId != ''">
  1865. AND l.company_user_id = #{companyUserId}
  1866. </if>
  1867. ) as courseWatchNum,
  1868. (
  1869. SELECT
  1870. count(DISTINCT l.user_id)
  1871. FROM
  1872. fs_course_watch_log l
  1873. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1874. LEFT JOIN fs_user ON fs_user.user_id = l.user_id
  1875. 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
  1876. where
  1877. l.log_type = 2 and send_type = 1
  1878. <if test="userId != null and userId != 0 ">
  1879. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1880. </if>
  1881. <if test="userId != null and userId == 0 ">
  1882. and l.company_id = #{companyId}
  1883. </if>
  1884. <if test="periodId != null and periodId != ''">
  1885. AND l.period_id = #{periodId}
  1886. </if>
  1887. <if test="videoId != null and videoId != ''">
  1888. AND l.video_id = #{videoId}
  1889. </if>
  1890. <if test="startTime != null and startTime !='' ">
  1891. and l.create_time &gt;= #{startTime}
  1892. </if>
  1893. <if test="endTime != null and endTime != ''">
  1894. and l.create_time &lt;= #{endTime}
  1895. </if>
  1896. -- 单独通过销售id查询
  1897. <if test="companyUserId != null and companyUserId != ''">
  1898. AND l.company_user_id = #{companyUserId}
  1899. </if>
  1900. ) as courseCompleteNum
  1901. </select>
  1902. <select id="countCourseDetailsNew" resultType="Map">
  1903. SELECT
  1904. count( DISTINCT l.period_id ) as courseNum,
  1905. count( DISTINCT l.video_id ) as videoNum,
  1906. count( DISTINCT l.user_id ) as courseUserNum
  1907. FROM
  1908. fs_course_watch_log l
  1909. left join fs_user on fs_user.user_id = l.user_id
  1910. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1911. WHERE
  1912. l.log_type != 3
  1913. AND send_type = 1
  1914. <if test="userId != null and userId != 0 ">
  1915. AND l.company_user_id = #{userId}
  1916. </if>
  1917. <if test="userId != null and userId == 0 ">
  1918. and l.company_id = #{companyId}
  1919. </if>
  1920. <if test="periodId != null and periodId != ''">
  1921. AND l.period_id = #{periodId}
  1922. </if>
  1923. <if test="videoId != null and videoId != ''">
  1924. AND l.video_id = #{videoId}
  1925. </if>
  1926. -- 单独通过销售id查询
  1927. <if test="companyUserId != null and companyUserId != ''">
  1928. AND l.company_user_id = #{companyUserId}
  1929. </if>
  1930. </select>
  1931. <select id="selectFsUserVOListByProjectNew" resultType="com.fs.his.vo.FsUserVO">
  1932. SELECT
  1933. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  1934. ucu.project_id,ucu.company_user_id as companyUserId,ucu.create_time as bindTime,ucu.status,
  1935. company.company_name,
  1936. cu.nick_name companyUserNickName
  1937. FROM
  1938. fs_user_company_user ucu
  1939. left join
  1940. fs_user u on ucu.user_id = u.user_id
  1941. left join
  1942. company on company.company_id = ucu.company_id
  1943. left join
  1944. company_user cu on cu.user_id = ucu.company_user_id
  1945. <where>
  1946. 1 = 1 and u.nick_name is not null
  1947. and u.is_del = 0
  1948. <if test = "maps.nickname != null and maps.nickname !='' " >
  1949. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  1950. </if >
  1951. <if test = "maps.nicknameExact != null and maps.nicknameExact !='' " >
  1952. AND u.nick_name = #{maps.nicknameExact}
  1953. </if >
  1954. <if test = "maps.userId != null and maps.userId !='' " >
  1955. AND u.user_id = #{maps.userId}
  1956. </if >
  1957. <if test = "maps.phone != null and maps.phone !='' " >
  1958. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  1959. </if >
  1960. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  1961. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  1962. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  1963. )
  1964. </if >
  1965. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  1966. AND u.register_code = #{maps.registerCode}
  1967. </if >
  1968. <if test = "maps.status != null" >
  1969. AND ucu.status = #{maps.status}
  1970. </if >
  1971. <if test = "maps.companyId != null and maps.companyId != '' " >
  1972. AND ucu.company_id = #{maps.companyId}
  1973. </if >
  1974. <if test = "maps.companyUserId != null" >
  1975. AND ucu.company_user_id = #{maps.companyUserId}
  1976. </if >
  1977. <if test = "maps.projectId != null" >
  1978. AND ucu.project_id = #{maps.projectId}
  1979. </if >
  1980. <if test = "maps.companyUserIds != null and maps.companyUserIds.length > 0 " >
  1981. AND ucu.company_user_id in
  1982. <foreach collection="maps.companyUserIds" item="item" open="(" close=")" separator=",">
  1983. #{item}
  1984. </foreach>
  1985. </if >
  1986. </where>
  1987. ORDER BY
  1988. user_id DESC
  1989. </select>
  1990. <select id="selectFsUserVOListByProject" resultType="com.fs.his.vo.FsUserVO">
  1991. SELECT distinct
  1992. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  1993. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  1994. fcc.watch_course_count, fcc.part_course_count, company_user.nick_name AS companyUserNickName, fcc.last_watch_date
  1995. ,company.company_name,
  1996. ucu.project_id,
  1997. ucu.id as companyUserId,
  1998. ucu.create_time as bindTime,
  1999. ucu.status
  2000. FROM
  2001. fs_user u
  2002. LEFT JOIN (
  2003. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  2004. user_id
  2005. FROM
  2006. fs_store_payment
  2007. WHERE
  2008. STATUS = 1
  2009. AND user_id IS NOT NULL
  2010. GROUP BY
  2011. user_id
  2012. ) b ON u.user_id = b.user_id
  2013. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  2014. AND b.last_buy_time = p.pay_time
  2015. AND b.payment_id = p.payment_id
  2016. LEFT JOIN (
  2017. SELECT
  2018. 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,
  2019. fs_user_course_count.part_course_count
  2020. FROM
  2021. fs_user_course_count
  2022. GROUP BY fs_user_course_count.user_id
  2023. ) fcc ON fcc.user_id = u.user_id
  2024. inner join fs_user_company_user ucu on ucu.user_id = u.user_id
  2025. LEFT JOIN company_user ON company_user.user_id = ucu.company_user_id
  2026. LEFT JOIN company on company.company_id = company_user.company_id
  2027. <where>
  2028. 1 = 1 and u.nick_name is not null
  2029. and u.is_del = 0
  2030. <if test = "maps.nickname != null and maps.nickname !='' " >
  2031. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  2032. </if >
  2033. <if test = "maps.userId != null and maps.userId !='' " >
  2034. AND u.user_id = #{maps.userId}
  2035. </if >
  2036. <if test = "maps.phone != null and maps.phone !='' " >
  2037. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  2038. </if >
  2039. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  2040. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  2041. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  2042. )
  2043. </if >
  2044. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  2045. AND u.register_code = #{maps.registerCode}
  2046. </if >
  2047. <if test = "maps.status != null" >
  2048. AND ucu.status = #{maps.status}
  2049. </if >
  2050. <if test = "maps.companyId != null and maps.companyId != '' " >
  2051. AND company.company_id = #{maps.companyId}
  2052. </if >
  2053. <if test = "maps.companyUserId != null" >
  2054. AND company_user.user_id = #{maps.companyUserId}
  2055. </if >
  2056. <if test = "maps.projectId != null" >
  2057. AND ucu.project_id = #{maps.projectId}
  2058. </if >
  2059. </where>
  2060. ORDER BY
  2061. user_id DESC
  2062. </select>
  2063. <select id="selectCompanyAndDoctor" resultType="com.fs.watch.domain.vo.FsUserAndCompanyAndDoctorVo">
  2064. SELECT
  2065. f.*,
  2066. GROUP_CONCAT(c.company_id SEPARATOR ',') AS company_id,
  2067. GROUP_CONCAT(c.company_user_id SEPARATOR ',') AS company_user_id,
  2068. GROUP_CONCAT(o.doctor_id SEPARATOR ',') AS doctor_id
  2069. FROM
  2070. fs_user f
  2071. LEFT JOIN
  2072. company_user_user c ON c.user_id = f.user_id
  2073. LEFT JOIN
  2074. fs_inquiry_order o ON o.user_id = f.user_id AND o.`status` = 4
  2075. WHERE
  2076. f.is_del = 0 AND f.user_id = #{userId}
  2077. GROUP BY
  2078. f.user_id;
  2079. </select>
  2080. <select id="selectUserNameByIds" resultMap="FsUserResult">
  2081. select user_id,nick_name from fs_user where user_id in
  2082. <foreach collection="userIds.split(',')" item="userId" open="(" close=")" separator=",">
  2083. #{userId}
  2084. </foreach>
  2085. </select>
  2086. <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
  2087. SELECT
  2088. count( DISTINCT fs_user.user_id ) as userNum,
  2089. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  2090. fs_user_company_user.company_id
  2091. FROM
  2092. fs_user
  2093. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  2094. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2095. WHERE
  2096. fs_user.is_del = 0
  2097. AND fs_user.`status` = 1
  2098. AND fs_user_company_user.`status` = 1
  2099. AND company_user.user_id IS NOT NULL
  2100. GROUP BY
  2101. fs_user_company_user.company_id
  2102. </select>
  2103. <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
  2104. SELECT
  2105. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  2106. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  2107. ifnull(
  2108. ROUND(
  2109. (
  2110. 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,
  2111. 2
  2112. ),
  2113. 0
  2114. ) AS completeWatchRate,
  2115. fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
  2116. FROM
  2117. fs_course_watch_log fwl
  2118. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fwl.user_id
  2119. WHERE
  2120. fwl.send_type = 1
  2121. AND fs_user_company_user.`status` = 1
  2122. GROUP BY
  2123. fwl.period_id, fwl.video_id, fwl.company_user_id
  2124. </select>
  2125. <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
  2126. SELECT
  2127. count(DISTINCT flog.log_id ) AS redPacketNum,
  2128. ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
  2129. flog.period_id,
  2130. flog.video_id,
  2131. flog.company_user_id,
  2132. flog.company_id
  2133. FROM
  2134. fs_course_red_packet_log flog
  2135. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = flog.user_id
  2136. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2137. where flog.`status` = 1
  2138. AND fs_user_company_user.`status` = 1
  2139. GROUP BY
  2140. flog.period_id,
  2141. flog.video_id,
  2142. flog.company_user_id
  2143. </select>
  2144. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  2145. SELECT
  2146. count( DISTINCT fs_user_company_user.user_id ) AS answerNum,
  2147. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user_company_user.user_id END ) AS answerRightNum,
  2148. ifnull(
  2149. ROUND(
  2150. (
  2151. 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,
  2152. 2
  2153. ),
  2154. 0
  2155. ) AS answerRightRate,
  2156. fs_course_answer_logs.period_id,
  2157. fs_course_answer_logs.video_id,
  2158. fs_course_answer_logs.company_user_id,
  2159. fs_course_answer_logs.company_id
  2160. FROM
  2161. fs_course_answer_logs
  2162. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_course_answer_logs.user_id
  2163. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2164. where fs_user_company_user.`status` = 1
  2165. GROUP BY
  2166. fs_course_answer_logs.period_id,
  2167. fs_course_answer_logs.video_id,
  2168. fs_course_answer_logs.company_user_id
  2169. </select>
  2170. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  2171. SELECT
  2172. count(DISTINCT fs_user.user_id ) as userNum,
  2173. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  2174. date(fs_user.create_time) as userCreateDate
  2175. ,company.company_id,
  2176. company.company_name,
  2177. company_user.user_id AS companyUserId,
  2178. company_user.nick_name AS companyUserName
  2179. FROM
  2180. fs_user
  2181. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  2182. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2183. LEFT JOIN company ON company.company_id = fs_user_company_user.company_id
  2184. WHERE
  2185. fs_user.is_del = 0
  2186. AND fs_user_company_user.`status` = 1
  2187. AND fs_user.`status` = 1
  2188. AND company_user.user_id is not null
  2189. GROUP BY
  2190. fs_user_company_user.company_user_id, date(fs_user.create_time)
  2191. </select>
  2192. <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
  2193. <include refid="selectFsUserVo"/>
  2194. <where>
  2195. <if test="userName != null and userName != ''">
  2196. AND (
  2197. nickname like concat('%', #{userName}, '%')
  2198. or user_id LIKE concat('%',#{userName},'%')
  2199. )
  2200. </if>
  2201. </where>
  2202. order by user_id desc
  2203. </select>
  2204. <select id="selectFsUserCount" resultType="java.lang.Long">
  2205. select count(1) from fs_user
  2206. where 1=1
  2207. <if test = "type != null and type ==1">
  2208. and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
  2209. </if>
  2210. <if test = "companyId != null">
  2211. and company_id=#{companyId}
  2212. </if>
  2213. <if test="companyUserId != null">
  2214. and company_user_id = #{companyUserId}
  2215. </if>
  2216. </select>
  2217. <select id="selectFsUserListLimit" resultMap="FsUserResult">
  2218. <include refid="selectFsUserVo"/>
  2219. <where>
  2220. <if test="password != null and password != ''">and password = #{password}</if>
  2221. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  2222. <if test="birthday != null ">and birthday = #{birthday}</if>
  2223. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  2224. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  2225. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  2226. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  2227. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  2228. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  2229. <if test="integral != null ">and integral = #{integral}</if>
  2230. <if test="signNum != null ">and sign_num = #{signNum}</if>
  2231. <if test="status != null ">and status = #{status}</if>
  2232. <if test="level != null ">and level = #{level}</if>
  2233. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  2234. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  2235. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  2236. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  2237. <if test="payCount != null ">and pay_count = #{payCount}</if>
  2238. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  2239. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  2240. <if test="isDel != null ">and is_del = #{isDel}</if>
  2241. <if test="companyId != null ">and company_id = #{companyId}</if>
  2242. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  2243. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  2244. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  2245. </if>
  2246. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  2247. <if test="source != null and source != '' ">and source = #{source}</if>
  2248. <if test="isShow != null ">and is_show = #{isShow}</if>
  2249. <if test="(username != null and username != '') or (userId != null and userId != '') or (nickname != null and nickname != '') or (phone != null and phone != '')">
  2250. and (
  2251. <if test="username != null and username != ''">username like concat('%', #{username}, '%')</if>
  2252. <if test="userId != null and userId != ''">or user_id = #{userId}</if>
  2253. <if test="nickname != null and nickname != ''">or nickname like concat('%', #{nickname}, '%')</if>
  2254. <if test="phone != null and phone != ''">or phone like concat('%',#{phone},'%')</if>
  2255. )
  2256. </if>
  2257. <if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  2258. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>
  2259. <if test="payOrder != null ">and pay_order = #{payOrder}</if>
  2260. </where>
  2261. order by user_id desc
  2262. limit 10
  2263. </select>
  2264. <select id="findUsersByParam" resultType="com.fs.his.dto.FindUsersByDTO">
  2265. SELECT user_id as id, 0 as type,
  2266. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2267. FROM fs_user
  2268. WHERE user_id = #{keywords}
  2269. UNION
  2270. <!-- fs_user 按nick_name前缀搜索 -->
  2271. SELECT user_id as id, 0 as type,
  2272. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2273. FROM fs_user
  2274. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2275. UNION
  2276. <!-- fs_user 按phone精确搜索(仅当keywords是数字时) -->
  2277. <if test="keywords.matches('\\d+')">
  2278. SELECT user_id as id, 0 as type,
  2279. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2280. FROM fs_user
  2281. WHERE phone = #{keywords}
  2282. UNION
  2283. </if>
  2284. <!-- company_user相关查询 -->
  2285. SELECT user_id as id, 1 as type,
  2286. IFNULL(nick_name, '') as name
  2287. FROM company_user
  2288. WHERE user_id = #{keywords}
  2289. UNION
  2290. SELECT user_id as id, 1 as type,
  2291. IFNULL(nick_name, '') as name
  2292. FROM company_user
  2293. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2294. <if test="keywords.matches('\\d+')">
  2295. UNION
  2296. SELECT user_id as id, 1 as type,
  2297. IFNULL(nick_name, '') as name
  2298. FROM company_user
  2299. WHERE phonenumber = #{keywords}
  2300. </if>
  2301. </select>
  2302. <select id="countExternalRedPacketStats" resultType="com.fs.store.vo.h5.ExternalRedPacketStatsVO">
  2303. SELECT
  2304. COUNT(red.log_id) AS redPacketNum,
  2305. COALESCE(SUM(red.amount), 0) AS redPacketAmount
  2306. FROM fs_course_red_packet_log log
  2307. WHERE log.status = 1
  2308. AND log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2309. <if test="startTime != null and startTime != ''">
  2310. AND log.create_time &gt;= #{startTime}
  2311. </if>
  2312. <if test="endTime != null and endTime != ''">
  2313. AND log.create_time &lt;= #{endTime}
  2314. </if>
  2315. </select>
  2316. <select id="countExternalAnswerStats" resultType="com.fs.store.vo.h5.ExternalAnswerStatsVO">
  2317. SELECT
  2318. COUNT(*) AS answerNum,
  2319. SUM(CASE WHEN is_right = 1 THEN 1 ELSE 0 END) AS answerRightNum
  2320. FROM fs_course_answer_logs log
  2321. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2322. <if test="startTime != null and startTime != ''">
  2323. AND log.create_time &gt;= #{startTime}
  2324. </if>
  2325. <if test="endTime != null and endTime != ''">
  2326. AND log.create_time &lt;= #{endTime}
  2327. </if>
  2328. </select>
  2329. <select id="countExternalWatchStats" resultType="com.fs.store.vo.h5.ExternalWatchStatsVO">
  2330. SELECT
  2331. COUNT(CASE WHEN log_type != 3 THEN 1 END) AS courseWatchNum,
  2332. COUNT(CASE WHEN log_type = 2 THEN 1 END) AS courseCompleteNum
  2333. FROM fs_course_watch_log log
  2334. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2335. <if test="startTime != null and startTime != ''">
  2336. AND log.create_time &gt;= #{startTime}
  2337. </if>
  2338. <if test="endTime != null and endTime != ''">
  2339. AND log.create_time &lt;= #{endTime}
  2340. </if>
  2341. </select>
  2342. <select id="selectFsUserListByPhone" resultType="com.fs.his.domain.FsUser">
  2343. select * from fs_user where phone=#{phone}
  2344. </select>
  2345. </mapper>