FsUserMapper.xml 111 KB

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