FsUserMapper.xml 118 KB

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