FsUserMapper.xml 109 KB

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