FsUserMapper.xml 109 KB

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