FsUserMapper.xml 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762
  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. <if test="isBindPhone != null">
  444. <choose>
  445. <when test="isBindPhone == 1">
  446. and fs_user.phone is not null and fs_user.phone != ''
  447. </when>
  448. <when test="isBindPhone == 0">
  449. and fs_user.phone is null or fs_user.phone = ''
  450. </when>
  451. </choose>
  452. </if>
  453. </where>
  454. limit ${(pageNum-1)*pageSize},${pageSize}
  455. </select>
  456. <select id="selectFsUserPageListCount" resultType="java.lang.Long">
  457. SELECT
  458. count(1)
  459. FROM
  460. fs_user
  461. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  462. <where>
  463. fs_user.is_del = 0
  464. <if test="userId != null">
  465. AND fs_user.user_id = #{userId}
  466. </if>
  467. <if test="companyId != null">
  468. AND ucu.company_id = #{companyId}
  469. </if>
  470. <choose>
  471. <when test="companyUserIds != null and companyUserIds.size > 0">
  472. AND ucu.company_user_id in
  473. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  474. ${item}
  475. </foreach>
  476. </when>
  477. <when test="companyUserId != null and companyUserId != '' ">
  478. AND ucu.company_user_id = #{companyUserId}
  479. </when>
  480. </choose>
  481. <if test="registerStartTime != null and registerStartTime !='' ">
  482. AND ucu.update_time >= #{registerStartTime}
  483. </if>
  484. <if test="registerEndTime != null and registerEndTime !='' ">
  485. <![CDATA[
  486. AND ucu.update_time < date_add(#{registerEndTime}, interval 1 day)
  487. ]]>
  488. </if>
  489. <if test="nickname != null and nickname != ''">
  490. AND fs_user.nick_name like concat('%', #{nickname},'%')
  491. </if>
  492. <if test="phone != null and phone != ''">
  493. AND fs_user.phone like concat('%', #{phone},'%')
  494. </if>
  495. <if test="projectId != null">
  496. AND ucu.project_id = #{projectId}
  497. </if>
  498. <if test="appCreateTimeStart != null and appCreateTimeEnd != null">
  499. AND fs_user.app_create_time BETWEEN #{appCreateTimeStart} AND #{appCreateTimeEnd}
  500. </if>
  501. <if test="isDownloadApp != null">
  502. <choose>
  503. <when test="isDownloadApp == 1">
  504. 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)
  505. </when>
  506. <when test="isDownloadApp == 0">
  507. 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)
  508. </when>
  509. </choose>
  510. </if>
  511. <if test="isBindPhone != null">
  512. <choose>
  513. <when test="isBindPhone == 1">
  514. and fs_user.phone is not null and fs_user.phone != ''
  515. </when>
  516. <when test="isBindPhone == 0">
  517. and fs_user.phone is null or fs_user.phone = ''
  518. </when>
  519. </choose>
  520. </if>
  521. </where>
  522. </select>
  523. <update id="transferCompanyUser">
  524. update fs_user
  525. set company_user_id=#{targetCompanyUserId}
  526. where
  527. user_id in
  528. <foreach collection="userIds" open="(" close=")" separator="," item="item">
  529. ${item}
  530. </foreach>
  531. </update>
  532. <update id="batchUpdateFsUserByIds" parameterType="Long">
  533. update fs_user
  534. set status = #{status} where user_id in
  535. <foreach item="id" collection="ids" open="(" separator="," close=")">
  536. #{id}
  537. </foreach>
  538. </update>
  539. <select id="selectFsUserVOList" resultType="com.fs.his.vo.FsUserVO">
  540. SELECT
  541. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  542. u.*,
  543. 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
  544. ,company.company_name
  545. FROM
  546. fs_user u
  547. LEFT JOIN (
  548. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  549. user_id
  550. FROM
  551. fs_store_payment
  552. WHERE
  553. STATUS = 1
  554. AND user_id IS NOT NULL
  555. GROUP BY
  556. user_id
  557. ) b ON u.user_id = b.user_id
  558. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  559. AND b.last_buy_time = p.pay_time
  560. AND b.payment_id = p.payment_id
  561. LEFT JOIN (
  562. SELECT
  563. fs_course_watch_log.user_id,
  564. Max( fs_course_watch_log.last_heartbeat_time ) AS last_watch_date,
  565. count( DISTINCT fs_course_watch_log.video_id ) watch_course_count,
  566. count( DISTINCT fs_course_watch_log.period_id ) part_course_count
  567. FROM
  568. fs_course_watch_log
  569. GROUP BY
  570. fs_course_watch_log.user_id
  571. ) fs_course_watch_log ON fs_course_watch_log.user_id = u.user_id
  572. LEFT JOIN company_user ON company_user.user_id = u.company_user_id
  573. LEFT JOIN company on company.company_id = company_user.company_id
  574. <where>
  575. 1 = 1
  576. <if test = "maps.userId != null">
  577. AND u.user_id LIKE CONCAT("%",#{maps.userId},"%")
  578. </if >
  579. <if test = "maps.nickname != null and maps.nickname !='' " >
  580. AND u.nickname LIKE CONCAT("%",#{maps.nickname},"%")
  581. </if >
  582. <if test = "maps.phone != null and maps.phone !='' " >
  583. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  584. </if >
  585. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  586. AND (DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  587. and DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  588. )
  589. </if >
  590. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  591. AND u.register_code = #{maps.registerCode}
  592. </if >
  593. <if test = "maps.status != null" >
  594. AND u.STATUS = #{maps.status}
  595. </if >
  596. <if test = "maps.companyUserNickName != null and maps.companyUserNickName != '' " >
  597. AND company_user.nick_name like CONCAT ("%",#{maps.companyUserNickName},"%")
  598. </if >
  599. <if test = "maps.companyName != null and maps.companyName != '' " >
  600. AND company.company_name like CONCAT ("%",#{maps.companyName},"%")
  601. </if >
  602. <if test = "maps.level != null and maps.level !=''" >
  603. AND u.LEVEL = #{maps.level}
  604. </if >
  605. <if test = "maps.isPromoter != null and maps.isPromoter !=''" >
  606. AND u.is_promoter = #{maps.isPromoter}
  607. </if >
  608. </where>
  609. ORDER BY
  610. user_id DESC
  611. </select>
  612. <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
  613. insert into fs_user
  614. <trim prefix="(" suffix=")" suffixOverrides=",">
  615. <if test="nickName != null">nick_name,</if>
  616. <if test="avatar != null">avatar,</if>
  617. <if test="phone != null">phone,</if>
  618. <if test="integral != null">integral,</if>
  619. <if test="signNum != null">sign_num,</if>
  620. <if test="status != null">status,</if>
  621. <if test="tuiUserId != null">tui_user_id,</if>
  622. <if test="tuiTime != null">tui_time,</if>
  623. <if test="tuiUserCount != null">tui_user_count,</if>
  624. <if test="maOpenId != null">ma_open_id,</if>
  625. <if test="mpOpenId != null">mp_open_id,</if>
  626. <if test="unionId != null">union_id,</if>
  627. <if test="isDel != null">is_del,</if>
  628. <if test="userCode != null">user_code,</if>
  629. <if test="remark != null">remark,</if>
  630. <if test="createTime != null">create_time,</if>
  631. <if test="updateTime != null">update_time,</if>
  632. <if test="lastIp != null">last_ip,</if>
  633. <if test="balance != null">balance,</if>
  634. <if test="integralStatus != null">integral_status,</if>
  635. <if test="isBuy != null">is_buy,</if>
  636. <if test="password != null">password,</if>
  637. <if test="jpushId != null">jpush_id,</if>
  638. <if test="isVip != null">is_vip,</if>
  639. <if test="vipStartDate != null">vip_start_date,</if>
  640. <if test="vipEndDate != null">vip_end_date,</if>
  641. <if test="vipLevel != null">vip_level,</if>
  642. <if test="vipStatus != null">vip_status,</if>
  643. <if test="sex != null">sex,</if>
  644. <if test="storeOpenId != null">store_open_id,</if>
  645. <if test="isPush != null">is_push,</if>
  646. <if test="isIndividuationPush != null">is_individuation_push,</if>
  647. <if test="isWeixinAuth != null">is_weixin_auth,</if>
  648. <if test="loginDevice != null">login_device,</if>
  649. <if test="source != null">source,</if>
  650. <if test="isAddQw != null">is_add_qw,</if>
  651. <if test="courseMaOpenId != null">course_ma_open_id,</if>
  652. <if test="qwExtId != null">qw_ext_id,</if>
  653. <if test="orderCount != null">order_count,</if>
  654. <if test="companyId != null">company_id,</if>
  655. <if test="companyUserId != null">company_user_id,</if>
  656. <if test="level != null">`level`,</if>
  657. <if test="spreadUserId != null">spread_user_id,</if>
  658. <if test="spreadTime != null">spread_time,</if>
  659. <if test="isPromoter != null">is_promoter,</if>
  660. <if test="payCount != null">pay_count,</if>
  661. <if test="spreadCount != null">spread_count,</if>
  662. <if test="appId != null">app_id,</if>
  663. <if test="appCreateTime != null">app_create_time,</if>
  664. <if test="isExternal != null">is_external,</if>
  665. </trim>
  666. <trim prefix="values (" suffix=")" suffixOverrides=",">
  667. <if test="nickName != null">#{nickName},</if>
  668. <if test="avatar != null">#{avatar},</if>
  669. <if test="phone != null">#{phone},</if>
  670. <if test="integral != null">#{integral},</if>
  671. <if test="signNum != null">#{signNum},</if>
  672. <if test="status != null">#{status},</if>
  673. <if test="tuiUserId != null">#{tuiUserId},</if>
  674. <if test="tuiTime != null">#{tuiTime},</if>
  675. <if test="tuiUserCount != null">#{tuiUserCount},</if>
  676. <if test="maOpenId != null">#{maOpenId},</if>
  677. <if test="mpOpenId != null">#{mpOpenId},</if>
  678. <if test="unionId != null">#{unionId},</if>
  679. <if test="isDel != null">#{isDel},</if>
  680. <if test="userCode != null">#{userCode},</if>
  681. <if test="remark != null">#{remark},</if>
  682. <if test="createTime != null">#{createTime},</if>
  683. <if test="updateTime != null">#{updateTime},</if>
  684. <if test="lastIp != null">#{lastIp},</if>
  685. <if test="balance != null">#{balance},</if>
  686. <if test="integralStatus != null">#{integralStatus},</if>
  687. <if test="isBuy != null">#{isBuy},</if>
  688. <if test="password != null">#{password},</if>
  689. <if test="jpushId != null">#{jpushId},</if>
  690. <if test="isVip != null">#{isVip},</if>
  691. <if test="vipStartDate != null">#{vipStartDate},</if>
  692. <if test="vipEndDate != null">#{vipEndDate},</if>
  693. <if test="vipLevel != null">#{vipLevel},</if>
  694. <if test="vipStatus != null">#{vipStatus},</if>
  695. <if test="sex != null">#{sex},</if>
  696. <if test="storeOpenId != null">#{storeOpenId},</if>
  697. <if test="isPush != null">#{isPush},</if>
  698. <if test="isIndividuationPush != null">#{isIndividuationPush},</if>
  699. <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
  700. <if test="loginDevice != null">#{loginDevice},</if>
  701. <if test="source != null">#{source},</if>
  702. <if test="isAddQw != null">#{isAddQw},</if>
  703. <if test="courseMaOpenId != null">#{courseMaOpenId},</if>
  704. <if test="qwExtId != null">#{qwExtId},</if>
  705. <if test="orderCount != null">#{orderCount},</if>
  706. <if test="companyId != null">#{companyId},</if>
  707. <if test="companyUserId != null">#{companyUserId},</if>
  708. <if test="level != null">#{level},</if>
  709. <if test="spreadUserId != null">#{spreadUserId},</if>
  710. <if test="spreadTime != null">#{spreadTime},</if>
  711. <if test="isPromoter != null">#{isPromoter},</if>
  712. <if test="payCount != null">#{payCount},</if>
  713. <if test="spreadCount != null">#{spreadCount},</if>
  714. <if test="appId != null">#{appId},</if>
  715. <if test="appCreateTime != null">#{appCreateTime},</if>
  716. <if test="isExternal != null">#{isExternal},</if>
  717. </trim>
  718. </insert>
  719. <update id="addIntegral">
  720. UPDATE fs_user
  721. SET integral = integral + #{integral},
  722. withdraw_integral = withdraw_integral + #{integral},
  723. update_time = NOW()
  724. WHERE user_id = #{userId}
  725. </update>
  726. <update id="updateFsUser" parameterType="FsUser">
  727. update fs_user
  728. <trim prefix="SET" suffixOverrides=",">
  729. <if test="nickName != null">nick_name = #{nickName},</if>
  730. <if test="avatar != null">avatar = #{avatar},</if>
  731. <if test="phone != null">phone = #{phone},</if>
  732. <if test="integral != null">integral = #{integral},</if>
  733. <if test="signNum != null">sign_num = #{signNum},</if>
  734. <if test="status != null">status = #{status},</if>
  735. <if test="tuiUserId != null">tui_user_id = #{tuiUserId},</if>
  736. <if test="tuiTime != null">tui_time = #{tuiTime},</if>
  737. <if test="tuiUserCount != null">tui_user_count = #{tuiUserCount},</if>
  738. <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
  739. <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
  740. <if test="unionId != null">union_id = #{unionId},</if>
  741. <if test="isDel != null">is_del = #{isDel},</if>
  742. <if test="userCode != null">user_code = #{userCode},</if>
  743. <if test="remark != null">remark = #{remark},</if>
  744. <if test="level != null">level = #{level},</if>
  745. <if test="createTime != null">create_time = #{createTime},</if>
  746. <if test="updateTime != null">update_time = #{updateTime},</if>
  747. <if test="lastIp != null">last_ip = #{lastIp},</if>
  748. <if test="balance != null">balance = #{balance},</if>
  749. <if test="integralStatus != null">integral_status = #{integralStatus},</if>
  750. <if test="isBuy != null">is_buy = #{isBuy},</if>
  751. <if test="isShow != null">is_show = #{isShow},</if>
  752. <if test="password != null">password = #{password},</if>
  753. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  754. <if test="isVip != null">is_vip = #{isVip},</if>
  755. <if test="vipStartDate != null">vip_start_date = #{vipStartDate},</if>
  756. <if test="vipEndDate != null">vip_end_date = #{vipEndDate},</if>
  757. <if test="vipLevel != null">vip_level = #{vipLevel},</if>
  758. <if test="vipStatus != null">vip_status = #{vipStatus},</if>
  759. <if test="sex != null">sex = #{sex},</if>
  760. <if test="storeOpenId != null">store_open_id = #{storeOpenId},</if>
  761. <if test="isPush != null">is_push = #{isPush},</if>
  762. <if test="isIndividuationPush != null">is_individuation_push = #{isIndividuationPush},</if>
  763. <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
  764. <if test="loginDevice != null">login_device = #{loginDevice},</if>
  765. <if test="source != null">source = #{source},</if>
  766. <if test="isAddQw != null">is_add_qw = #{isAddQw},</if>
  767. <if test="courseMaOpenId != null">course_ma_open_id = #{courseMaOpenId},</if>
  768. <if test="parentId != null">parent_id = #{parentId},</if>
  769. <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
  770. <if test="isPromoter != null">is_promoter = #{isPromoter},</if>
  771. <if test="companyId != null">company_id = #{companyId},</if>
  772. <if test="orderCount != null">order_count = #{orderCount},</if>
  773. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  774. <if test="appId != null">app_id = #{appId},</if>
  775. <if test="appCreateTime != null">app_create_time = #{appCreateTime},</if>
  776. <if test="invitedBySalesId != null">invited_by_sales_id = #{invitedBySalesId},</if>
  777. <if test="withdrawIntegral != null">withdraw_integral = #{withdrawIntegral},</if>
  778. <if test="withdrawFinish != null">withdraw_finish = #{withdrawFinish},</if>
  779. <if test="totalCommission != null">total_commission = #{totalCommission},</if>
  780. <if test="mayWithdraw != null">may_withdraw = #{mayWithdraw},</if>
  781. <if test="isExternal != null">is_external = #{isExternal},</if>
  782. </trim>
  783. where user_id = #{userId}
  784. </update>
  785. <update id="deleteFsUserByUserId" parameterType="Long">
  786. update fs_user set is_del = 1 where user_id = #{userId}
  787. </update>
  788. <delete id="deleteFsUserByUserIds" parameterType="Long">
  789. delete from fs_user where user_id in
  790. <foreach item="userId" collection="array" open="(" separator="," close=")">
  791. #{userId}
  792. </foreach>
  793. </delete>
  794. <update id="batchUpdateUserCompanyUser">
  795. update fs_user
  796. set company_id = #{companyId},
  797. company_user_id = #{companyUserId}
  798. where
  799. <foreach collection="userIds" separator="or" item="userId" index="index">
  800. user_id = #{userId}
  801. </foreach>
  802. </update>
  803. <update id="batchUpdateCompanyUserRelation">
  804. update fs_user_company_user
  805. set company_id = #{companyId},
  806. company_user_id = #{companyUserId}
  807. where is_repeat_fans = 0 and
  808. <foreach collection="userIds" open="(" close=")" separator="or" item="userId" index="index">
  809. user_id = #{userId}
  810. </foreach>
  811. </update>
  812. <update id="updatePasswordByPhone">
  813. update fs_user set password = #{password} where phone = #{encryptPhone}
  814. </update>
  815. <update id="disabledUsers">
  816. UPDATE fs_user
  817. SET status = 0
  818. <choose>
  819. <when test="param.remark != null and param.remark != ''">
  820. ,remark = #{param.remark}
  821. </when>
  822. <otherwise>
  823. ,remark = '风控用户'
  824. </otherwise>
  825. </choose>
  826. WHERE user_id IN
  827. <foreach collection="param.userIds" item="userId" open="(" separator="," close=")">
  828. #{userId}
  829. </foreach>
  830. </update>
  831. <select id="selectUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  832. select
  833. u.user_id dictValue,
  834. u.nick_name dictLabel
  835. from fs_user u
  836. <where>
  837. <if test="params.nickName != null and params.nickName != ''">
  838. u.nick_name like concat('%', #{params.nickName}, '%')
  839. </if>
  840. </where>
  841. </select>
  842. <select id ="selectFsUserByUserIds" resultType="Integer">
  843. select count(1) from fs_user_company_user
  844. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  845. where is_repeat_fans = 1
  846. and (fs_user_company_user.company_user_id = #{companyUserId} OR company_user.parent_id = #{companyUserId})
  847. <if test="userIds != null and userIds.length > 0 ">
  848. and fs_user_company_user.user_id in
  849. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  850. #{userId}
  851. </foreach>
  852. </if>
  853. </select>
  854. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  855. select
  856. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  857. count(u.user_id) vipCount
  858. from fs_user u
  859. left join fs_user_company_user ucu on ucu.user_id = u.user_id
  860. left join company_user cu on cu.user_id = ucu.company_user_id
  861. where cu.user_id = #{companyUserId}
  862. </select>
  863. <select id="getUserNumber" resultType="com.fs.store.vo.h5.UserListCountVO">
  864. SELECT
  865. t.status,
  866. COUNT(DISTINCT CONCAT(t.user_id, '_', t.project_id)) AS num
  867. FROM (
  868. SELECT
  869. fcu.user_id,
  870. fcu.project_id,
  871. fcu.status
  872. FROM fs_user_company_user fcu
  873. INNER JOIN fs_user fu ON fu.user_id = fcu.user_id AND fu.is_del = 0
  874. <where>
  875. <if test="companyId != null">
  876. AND fcu.company_id = #{companyId}
  877. </if>
  878. <if test="userId != null and userId != 0">
  879. AND fcu.company_user_id = #{userId}
  880. </if>
  881. </where>
  882. <if test="userId != null and userId != 0">
  883. UNION ALL
  884. SELECT
  885. fcu.user_id,
  886. fcu.project_id,
  887. fcu.status
  888. FROM company_user cu
  889. INNER JOIN fs_user_company_user fcu ON fcu.company_user_id = cu.user_id
  890. INNER JOIN fs_user fu ON fu.user_id = fcu.user_id AND fu.is_del = 0
  891. WHERE cu.parent_id = #{userId}
  892. <if test="companyId != null">
  893. AND fcu.company_id = #{companyId}
  894. </if>
  895. </if>
  896. ) t
  897. GROUP BY t.status
  898. </select>
  899. <select id="getRepeatUserNumber" resultType="int">
  900. SELECT
  901. count( DISTINCT fs_user.user_id ) AS num
  902. FROM
  903. fs_user
  904. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  905. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  906. WHERE
  907. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  908. AND fs_user.is_del = 0
  909. AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
  910. </select>
  911. <select id="getCountWatchCourse" resultType="com.fs.store.vo.h5.UserDetailsVO">
  912. SELECT
  913. count(distinct if(fcwl.log_type = 2, fcwl.log_id, null)) completeWatchCount,
  914. count(distinct fcwl.log_id) watchTimes,
  915. count(distinct fcal.log_id) answerTime,
  916. count(distinct if(fcal.is_right = 1, fcal.log_id, null)) answerRightTime,
  917. count(distinct fcrpl.log_id) answerRedPacketTime,
  918. (
  919. select sum(pl.amount) from fs_course_watch_log wl
  920. 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
  921. inner join fs_course_red_packet_log pl on wl.log_id = pl.watch_log_id and pl.`status`= 1
  922. <where>
  923. <if test="dateTag != null and dateTag !='' ">
  924. <choose>
  925. <when test = "dateTag == '今天'">
  926. and to_days(wl.create_time) = to_days(now())
  927. </when>
  928. <when test = "dateTag == '昨天'">
  929. and wl.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND wl.create_time &lt; CURDATE()
  930. </when>
  931. <when test = "dateTag == '前天'">
  932. and wl.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND wl.create_time &lt; CURDATE() - INTERVAL 1 DAY
  933. </when>
  934. <when test = "dateTag == '近七天'">
  935. and wl.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  936. </when>
  937. </choose>
  938. </if>
  939. and wl.user_id = #{fsUserId} and wl.company_user_id = #{userId}
  940. <if test="userCompanyId!=null">
  941. and cu.id = #{userCompanyId}
  942. </if>
  943. </where>
  944. ) answerRedPacketAmount
  945. FROM fs_course_watch_log fcwl
  946. 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
  947. left join fs_course_answer_logs fcal on fcal.watch_log_id = fcwl.log_id
  948. left join fs_course_red_packet_log fcrpl on fcrpl.watch_log_id = fcwl.log_id
  949. <where>
  950. <if test="dateTag != null and dateTag !='' ">
  951. <choose>
  952. <when test = "dateTag == '今天'">
  953. and to_days(fcwl.create_time) = to_days(now())
  954. </when>
  955. <when test = "dateTag == '昨天'">
  956. and fcwl.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fcwl.create_time &lt; CURDATE()
  957. </when>
  958. <when test = "dateTag == '前天'">
  959. and fcwl.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fcwl.create_time &lt; CURDATE() - INTERVAL 1 DAY
  960. </when>
  961. <when test = "dateTag == '近七天'">
  962. and fcwl.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  963. </when>
  964. </choose>
  965. </if>
  966. and fcwl.user_id = #{fsUserId} and fucu.company_user_id = #{userId} and fcwl.watch_type=1 and fcwl.send_type=1
  967. <if test="userCompanyId!=null">
  968. and fucu.id = #{userCompanyId}
  969. </if>
  970. </where>
  971. group by fcwl.user_id
  972. </select>
  973. <select id="getUserTotal" resultType="java.lang.Integer">
  974. SELECT count(fs_user.user_id) as userTotal
  975. FROM fs_user
  976. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  977. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  978. WHERE fs_user.is_del = 0
  979. <if test="userId != null and userId != 0 ">
  980. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  981. </if>
  982. <if test="companyId != null ">
  983. and ucu.company_id = #{companyId}
  984. </if>
  985. </select>
  986. <select id="getTodayNewUser" resultType="java.lang.Integer">
  987. SELECT count(fs_user.user_id) as todayNewUser
  988. FROM fs_user
  989. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  990. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  991. WHERE fs_user.is_del = 0
  992. <if test="userId != null and userId != 0 ">
  993. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  994. </if>
  995. <if test="companyId != null ">
  996. and ucu.company_id = #{companyId}
  997. </if>
  998. AND to_days(ucu.create_time) = to_days(now())
  999. </select>
  1000. <select id="getNormalUserCount" resultType="java.lang.Integer">
  1001. SELECT count(fs_user.user_id) as normalUserCount
  1002. FROM fs_user
  1003. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1004. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1005. WHERE fs_user.is_del = 0
  1006. AND ucu.status = 1
  1007. <if test="userId != null and userId != 0 ">
  1008. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1009. </if>
  1010. <if test="companyId != null ">
  1011. and ucu.company_id = #{companyId}
  1012. </if>
  1013. </select>
  1014. <select id="getBlacklistUserCount" resultType="java.lang.Integer">
  1015. SELECT count(fs_user.user_id) as blacklistUserCount
  1016. FROM fs_user
  1017. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1018. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1019. WHERE fs_user.is_del = 0
  1020. AND ucu.status IN (0, 2)
  1021. <if test="userId != null and userId != 0 ">
  1022. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1023. </if>
  1024. <if test="companyId != null ">
  1025. and ucu.company_id = #{companyId}
  1026. </if>
  1027. </select>
  1028. <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
  1029. SELECT (SELECT count(fs_user.user_id)
  1030. FROM fs_user
  1031. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1032. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1033. WHERE fs_user.is_del = 0
  1034. <if test="userId != null and userId != 0 ">
  1035. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1036. </if>
  1037. <if test="companyId != null ">
  1038. and ucu.company_id = #{companyId}
  1039. </if>
  1040. ) as userTotal,
  1041. (SELECT count(fs_user.user_id)
  1042. FROM fs_user
  1043. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1044. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1045. WHERE fs_user.is_del = 0
  1046. <if test="userId != null and userId != 0 ">
  1047. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1048. </if>
  1049. <if test="companyId != null ">
  1050. and ucu.company_id = #{companyId}
  1051. </if>
  1052. AND to_days(ucu.create_time) = to_days(now())) as todayNewUser
  1053. </select>
  1054. <select id="countTag" resultType="com.fs.store.vo.h5.FsUserSummaryCountTagVO">
  1055. SELECT
  1056. company_tag.tag AS tagName,
  1057. count( ucu.user_id ) AS number
  1058. FROM
  1059. fs_user_project_tag upt
  1060. inner join fs_user_company_user ucu on ucu.id = upt.user_company_user_id
  1061. inner join company_tag ON upt.tag_id = company_tag.tag_id
  1062. left join company_user on company_user.user_id = ucu.company_user_id
  1063. <where>
  1064. <if test="userId != null and userId != 0 ">
  1065. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1066. </if>
  1067. <if test="companyId != null ">
  1068. and ucu.company_id = #{companyId}
  1069. </if>
  1070. </where>
  1071. GROUP BY
  1072. company_tag.tag_id
  1073. </select>
  1074. <select id="countUserCourse" resultType="Map">
  1075. SELECT
  1076. (SELECT COUNT(*) FROM (
  1077. SELECT 1
  1078. FROM fs_user_course_count fcc
  1079. JOIN fs_user ON fs_user.user_id = fcc.user_id
  1080. JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
  1081. JOIN company_user ON ucu.company_user_id = company_user.user_id
  1082. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  1083. <where>
  1084. fcc.project_id = ucu.project_id
  1085. <if test="userId != null and userId != 0 ">
  1086. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1087. </if>
  1088. <if test="userId != null and userId == 0 ">
  1089. and ucu.company_id = #{companyId}
  1090. </if>
  1091. <if test="startTime != null and startTime !='' ">
  1092. and fcc.create_time &gt;= #{startTime}
  1093. </if>
  1094. <if test="endTime != null and endTime != ''">
  1095. and fcc.create_time &lt;= #{endTime}
  1096. </if>
  1097. <if test="periodId != null and periodId != ''">
  1098. AND fcpd.period_id = #{periodId}
  1099. </if>
  1100. <if test="videoId != null and videoId != ''">
  1101. AND fcpd.video_id = #{videoId}
  1102. </if>
  1103. -- 单独通过销售id查询
  1104. <if test="companyUserId != null and companyUserId != ''">
  1105. AND company_user.user_id = #{companyUserId}
  1106. </if>
  1107. </where>
  1108. ) as courseWatchNum,
  1109. (SELECT COUNT(*) FROM (
  1110. SELECT 1
  1111. FROM fs_user_course_count fcc
  1112. JOIN fs_user ON fs_user.user_id = fcc.user_id
  1113. JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
  1114. JOIN company_user ON ucu.company_user_id = company_user.user_id
  1115. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  1116. <where>
  1117. fcc.project_id = ucu.project_id
  1118. <if test="userId != null and userId != 0 ">
  1119. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1120. </if>
  1121. <if test="userId != null and userId == 0 ">
  1122. and ucu.company_id = #{companyId}
  1123. </if>
  1124. AND fcc.complete_watch_count > 0
  1125. <if test="startTime != null and startTime !='' ">
  1126. and fcc.create_time &gt;= #{startTime}
  1127. </if>
  1128. <if test="endTime != null and endTime != ''">
  1129. and fcc.create_time &lt;= #{endTime}
  1130. </if>
  1131. <if test="periodId != null and periodId != ''">
  1132. AND fcpd.period_id = #{periodId}
  1133. </if>
  1134. <if test="videoId != null and videoId != ''">
  1135. AND fcpd.video_id = #{videoId}
  1136. </if>
  1137. -- 单独通过销售id查询
  1138. <if test="companyUserId != null and companyUserId != ''">
  1139. AND company_user.user_id = #{companyUserId}
  1140. </if>
  1141. </where>
  1142. GROUP BY fcc.user_id, ucu.project_id
  1143. ) AS complete_counts ) as courseCompleteNum
  1144. </select>
  1145. <select id="countUserStats" resultType="Map">
  1146. SELECT
  1147. -- 观看人数
  1148. (
  1149. SELECT COUNT(DISTINCT l.user_id)
  1150. FROM fs_course_watch_log l
  1151. LEFT JOIN fs_user u ON u.user_id = l.user_id
  1152. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  1153. <where>
  1154. l.log_type != 3 AND l.send_type = 1
  1155. <if test="userId != null and userId != 0 ">
  1156. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1157. </if>
  1158. <if test="userId != null and userId == 0 ">
  1159. AND l.company_id = #{companyId}
  1160. </if>
  1161. <if test="periodId != null and periodId != '' ">
  1162. AND l.period_id = #{periodId}
  1163. </if>
  1164. <if test="videoId != null and videoId != '' ">
  1165. AND l.video_id = #{videoId}
  1166. </if>
  1167. <if test="startTime != null and startTime != '' ">
  1168. AND l.create_time &gt;= #{startTime}
  1169. </if>
  1170. <if test="endTime != null and endTime != '' ">
  1171. AND l.create_time &lt;= #{endTime}
  1172. </if>
  1173. <if test="companyUserId != null and companyUserId != '' ">
  1174. AND l.company_user_id = #{companyUserId}
  1175. </if>
  1176. </where>
  1177. ) AS courseWatchNum,
  1178. -- 完成人数
  1179. (
  1180. SELECT COUNT(DISTINCT l.user_id)
  1181. FROM fs_course_watch_log l
  1182. LEFT JOIN fs_user u ON u.user_id = l.user_id
  1183. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  1184. <where>
  1185. l.log_type = 2 AND l.send_type = 1
  1186. <if test="userId != null and userId != 0 ">
  1187. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1188. </if>
  1189. <if test="userId != null and userId == 0 ">
  1190. AND l.company_id = #{companyId}
  1191. </if>
  1192. <if test="periodId != null and periodId != '' ">
  1193. AND l.period_id = #{periodId}
  1194. </if>
  1195. <if test="videoId != null and videoId != '' ">
  1196. AND l.video_id = #{videoId}
  1197. </if>
  1198. <if test="startTime != null and startTime != '' ">
  1199. AND l.create_time &gt;= #{startTime}
  1200. </if>
  1201. <if test="endTime != null and endTime != '' ">
  1202. AND l.create_time &lt;= #{endTime}
  1203. </if>
  1204. <if test="companyUserId != null and companyUserId != '' ">
  1205. AND l.company_user_id = #{companyUserId}
  1206. </if>
  1207. </where>
  1208. ) AS courseCompleteNum,
  1209. -- 答题人数
  1210. (
  1211. SELECT COUNT(distinct a.user_id)
  1212. FROM fs_course_answer_logs a
  1213. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1214. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  1215. <where>
  1216. 1=1
  1217. <if test="userId != null and userId != 0 ">
  1218. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1219. </if>
  1220. <if test="userId != null and userId == 0 ">
  1221. AND a.company_id = #{companyId}
  1222. </if>
  1223. <if test="periodId != null and periodId != '' ">
  1224. AND a.period_id = #{periodId}
  1225. </if>
  1226. <if test="videoId != null and videoId != '' ">
  1227. AND a.video_id = #{videoId}
  1228. </if>
  1229. <if test="startTime != null and startTime != '' ">
  1230. AND a.create_time &gt;= #{startTime}
  1231. </if>
  1232. <if test="endTime != null and endTime != '' ">
  1233. AND a.create_time &lt;= #{endTime}
  1234. </if>
  1235. <if test="companyUserId != null and companyUserId != '' ">
  1236. AND a.company_user_id = #{companyUserId}
  1237. </if>
  1238. </where>
  1239. ) AS answerNum,
  1240. -- 答对人数
  1241. (
  1242. SELECT COUNT(distinct a.user_id)
  1243. FROM fs_course_answer_logs a
  1244. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1245. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  1246. <where>
  1247. a.is_right = 1
  1248. <if test="userId != null and userId != 0 ">
  1249. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1250. </if>
  1251. <if test="userId != null and userId == 0 ">
  1252. AND a.company_id = #{companyId}
  1253. </if>
  1254. <if test="periodId != null and periodId != '' ">
  1255. AND a.period_id = #{periodId}
  1256. </if>
  1257. <if test="videoId != null and videoId != '' ">
  1258. AND a.video_id = #{videoId}
  1259. </if>
  1260. <if test="startTime != null and startTime != '' ">
  1261. AND a.create_time &gt;= #{startTime}
  1262. </if>
  1263. <if test="endTime != null and endTime != '' ">
  1264. AND a.create_time &lt;= #{endTime}
  1265. </if>
  1266. <if test="companyUserId != null and companyUserId != '' ">
  1267. AND a.company_user_id = #{companyUserId}
  1268. </if>
  1269. </where>
  1270. ) AS answerRightNum,
  1271. -- 红包数
  1272. (
  1273. SELECT COUNT(flog.log_id)
  1274. FROM fs_course_red_packet_log flog
  1275. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1276. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1277. <where>
  1278. flog.status = 1
  1279. <if test="userId != null and userId != 0 ">
  1280. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1281. </if>
  1282. <if test="userId != null and userId == 0 ">
  1283. AND flog.company_id = #{companyId}
  1284. </if>
  1285. <if test="periodId != null and periodId != '' ">
  1286. AND flog.period_id = #{periodId}
  1287. </if>
  1288. <if test="videoId != null and videoId != '' ">
  1289. AND flog.video_id = #{videoId}
  1290. </if>
  1291. <if test="startTime != null and startTime != '' ">
  1292. AND flog.create_time &gt;= #{startTime}
  1293. </if>
  1294. <if test="endTime != null and endTime != '' ">
  1295. AND flog.create_time &lt;= #{endTime}
  1296. </if>
  1297. <if test="companyUserId != null and companyUserId != '' ">
  1298. AND flog.company_user_id = #{companyUserId}
  1299. </if>
  1300. </where>
  1301. ) AS redPacketNum,
  1302. -- 红包金额
  1303. (
  1304. SELECT IFNULL(SUM(flog.amount), 0)
  1305. FROM fs_course_red_packet_log flog
  1306. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1307. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1308. <where>
  1309. flog.status = 1
  1310. <if test="userId != null and userId != 0 ">
  1311. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1312. </if>
  1313. <if test="userId != null and userId == 0 ">
  1314. AND flog.company_id = #{companyId}
  1315. </if>
  1316. <if test="periodId != null and periodId != '' ">
  1317. AND flog.period_id = #{periodId}
  1318. </if>
  1319. <if test="videoId != null and videoId != '' ">
  1320. AND flog.video_id = #{videoId}
  1321. </if>
  1322. <if test="startTime != null and startTime != '' ">
  1323. AND flog.create_time &gt;= #{startTime}
  1324. </if>
  1325. <if test="endTime != null and endTime != '' ">
  1326. AND flog.create_time &lt;= #{endTime}
  1327. </if>
  1328. <if test="companyUserId != null and companyUserId != '' ">
  1329. AND flog.company_user_id = #{companyUserId}
  1330. </if>
  1331. </where>
  1332. ) AS redPacketAmount
  1333. </select>
  1334. <!-- 查询观看和完成人数 -->
  1335. <select id="countUserWatchStats" resultType="Map">
  1336. SELECT
  1337. COUNT(DISTINCT CASE WHEN l.log_type != 3 AND l.send_type = 1 THEN l.user_id END) AS courseWatchNum,
  1338. COUNT(DISTINCT CASE WHEN l.log_type = 2 AND l.send_type = 1 THEN l.user_id END) AS courseCompleteNum
  1339. FROM fs_course_watch_log l
  1340. LEFT JOIN fs_user u ON u.user_id = l.user_id
  1341. LEFT JOIN company_user cu_l ON l.company_user_id = cu_l.user_id
  1342. <where>
  1343. <if test="userId != null and userId != 0">
  1344. AND (cu_l.user_id = #{userId} OR cu_l.parent_id = #{userId})
  1345. </if>
  1346. <if test="userId != null and userId == 0">
  1347. AND l.company_id = #{companyId}
  1348. </if>
  1349. <if test="periodId != null and periodId != ''">
  1350. AND l.period_id = #{periodId}
  1351. </if>
  1352. <if test="videoId != null and videoId != ''">
  1353. AND l.video_id = #{videoId}
  1354. </if>
  1355. <if test="startTime != null and startTime != ''">
  1356. AND l.create_time &gt;= #{startTime}
  1357. </if>
  1358. <if test="endTime != null and endTime != ''">
  1359. AND l.create_time &lt;= #{endTime}
  1360. </if>
  1361. <if test="companyUserId != null and companyUserId != ''">
  1362. AND l.company_user_id = #{companyUserId}
  1363. </if>
  1364. </where>
  1365. </select>
  1366. <!-- 查询答题人数和答对人数 -->
  1367. <select id="countUserAnswerStats" resultType="Map">
  1368. SELECT
  1369. COUNT(DISTINCT CASE WHEN a.user_id THEN a.user_id END) AS answerNum,
  1370. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS answerRightNum
  1371. FROM fs_course_answer_logs a
  1372. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1373. LEFT JOIN company_user cu_a ON a.company_user_id = cu_a.user_id
  1374. <where>
  1375. <if test="userId != null and userId != 0">
  1376. AND (cu_a.user_id = #{userId} OR cu_a.parent_id = #{userId})
  1377. </if>
  1378. <if test="userId != null and userId == 0">
  1379. AND a.company_id = #{companyId}
  1380. </if>
  1381. <if test="periodId != null and periodId != ''">
  1382. AND a.period_id = #{periodId}
  1383. </if>
  1384. <if test="videoId != null and videoId != ''">
  1385. AND a.video_id = #{videoId}
  1386. </if>
  1387. <if test="startTime != null and startTime != ''">
  1388. AND a.create_time &gt;= #{startTime}
  1389. </if>
  1390. <if test="endTime != null and endTime != ''">
  1391. AND a.create_time &lt;= #{endTime}
  1392. </if>
  1393. <if test="companyUserId != null and companyUserId != ''">
  1394. AND a.company_user_id = #{companyUserId}
  1395. </if>
  1396. </where>
  1397. </select>
  1398. <!-- 查询红包数量和红包金额 -->
  1399. <select id="countUserRedPacketStats" resultType="Map">
  1400. SELECT
  1401. COUNT(CASE WHEN flog.status = 1 THEN flog.log_id END) AS redPacketNum,
  1402. IFNULL(SUM(CASE WHEN flog.status = 1 THEN flog.amount END), 0) AS redPacketAmount
  1403. FROM fs_course_red_packet_log flog
  1404. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1405. LEFT JOIN company_user cu_flog ON flog.company_user_id = cu_flog.user_id
  1406. <where>
  1407. <if test="userId != null and userId != 0">
  1408. AND (cu_flog.user_id = #{userId} OR cu_flog.parent_id = #{userId})
  1409. </if>
  1410. <if test="userId != null and userId == 0">
  1411. AND flog.company_id = #{companyId}
  1412. </if>
  1413. <if test="periodId != null and periodId != ''">
  1414. AND flog.period_id = #{periodId}
  1415. </if>
  1416. <if test="videoId != null and videoId != ''">
  1417. AND flog.video_id = #{videoId}
  1418. </if>
  1419. <if test="startTime != null and startTime != ''">
  1420. AND flog.create_time &gt;= #{startTime}
  1421. </if>
  1422. <if test="endTime != null and endTime != ''">
  1423. AND flog.create_time &lt;= #{endTime}
  1424. </if>
  1425. <if test="companyUserId != null and companyUserId != ''">
  1426. AND flog.company_user_id = #{companyUserId}
  1427. </if>
  1428. </where>
  1429. </select>
  1430. <select id="countUserAnswer" resultType="Map">
  1431. SELECT
  1432. (
  1433. SELECT
  1434. count(distinct fs_user.user_id )
  1435. FROM
  1436. fs_course_answer_logs
  1437. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1438. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1439. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1440. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1441. <where>
  1442. <if test="userId != null and userId != 0 ">
  1443. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1444. </if>
  1445. <if test="userId != null and userId == 0 ">
  1446. and fs_course_answer_logs.company_id = #{companyId}
  1447. </if>
  1448. <if test="startTime != null and startTime !='' ">
  1449. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1450. </if>
  1451. <if test="endTime != null and endTime != ''">
  1452. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1453. </if>
  1454. <if test="periodId != null and periodId != ''">
  1455. AND fs_course_answer_logs.period_id = #{periodId}
  1456. </if>
  1457. <if test="videoId != null and videoId != ''">
  1458. AND fs_course_answer_logs.video_id = #{videoId}
  1459. </if>
  1460. -- 单独通过销售id查询
  1461. <if test="companyUserId != null and companyUserId != ''">
  1462. AND company_user.user_id = #{companyUserId}
  1463. </if>
  1464. </where>
  1465. ) AS answerNum,
  1466. (
  1467. SELECT
  1468. count(distinct fs_user.user_id )
  1469. FROM
  1470. fs_course_answer_logs
  1471. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1472. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1473. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1474. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1475. <where>
  1476. <if test="userId != null and userId != 0 ">
  1477. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1478. </if>
  1479. <if test="userId != null and userId == 0 ">
  1480. and fs_course_answer_logs.company_id = #{companyId}
  1481. </if>
  1482. AND fs_course_answer_logs.is_right = 1
  1483. <if test="startTime != null and startTime !='' ">
  1484. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1485. </if>
  1486. <if test="endTime != null and endTime != ''">
  1487. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1488. </if>
  1489. <if test="periodId != null and periodId != ''">
  1490. AND fs_course_answer_logs.period_id = #{periodId}
  1491. </if>
  1492. <if test="videoId != null and videoId != ''">
  1493. AND fs_course_answer_logs.video_id = #{videoId}
  1494. </if>
  1495. -- 单独通过销售id查询
  1496. <if test="companyUserId != null and companyUserId != ''">
  1497. AND company_user.user_id = #{companyUserId}
  1498. </if>
  1499. </where>
  1500. ) AS answerRightNum
  1501. </select>
  1502. <select id="countCourseDetails" resultType="Map">
  1503. select (SELECT
  1504. count( DISTINCT fcpd.period_id )
  1505. FROM
  1506. fs_user_course_period_days fcpd
  1507. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1508. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1509. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1510. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1511. WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
  1512. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1513. <if test="userId != null and userId != 0 ">
  1514. AND ucu.company_user_id = #{userId}
  1515. </if>
  1516. <if test="userId != null and userId == 0 ">
  1517. and ucu.company_id = #{companyId}
  1518. </if>
  1519. <if test="periodId != null and periodId != ''">
  1520. AND fcpd.period_id = #{periodId}
  1521. </if>
  1522. -- 单独通过销售id查询
  1523. <if test="companyUserId != null and companyUserId != ''">
  1524. AND ucu.company_user_id = #{companyUserId}
  1525. </if>
  1526. ) as courseNum,
  1527. (SELECT count(DISTINCT fcpd.video_id)
  1528. FROM fs_user_course_period_days fcpd
  1529. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1530. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1531. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1532. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1533. WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
  1534. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1535. <if test="userId != null and userId != 0 ">
  1536. AND ucu.company_user_id = #{userId}
  1537. </if>
  1538. <if test="userId != null and userId == 0 ">
  1539. and ucu.company_id = #{companyId}
  1540. </if>
  1541. <if test="periodId != null and periodId != ''">
  1542. AND fcpd.period_id = #{periodId}
  1543. </if>
  1544. <if test="videoId != null and videoId != ''">
  1545. AND fcpd.video_id = #{videoId}
  1546. </if>
  1547. -- 单独通过销售id查询
  1548. <if test="companyUserId != null and companyUserId != ''">
  1549. AND ucu.company_user_id = #{companyUserId}
  1550. </if>
  1551. ) as videoNum,
  1552. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  1553. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1554. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1555. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1556. <if test="periodId != null and periodId != ''">
  1557. AND fcpd.period_id = #{periodId}
  1558. </if>
  1559. <if test="videoId != null and videoId != ''">
  1560. AND fcpd.video_id = #{videoId}
  1561. </if>
  1562. -- 单独通过销售id查询
  1563. <if test="companyUserId != null and companyUserId != ''">
  1564. AND ucu.company_user_id = #{companyUserId}
  1565. </if>
  1566. <where>
  1567. <if test="userId != null and userId != 0 ">
  1568. AND ucu.company_user_id = #{userId}
  1569. </if>
  1570. <if test="userId != null and userId == 0 ">
  1571. and ucu.company_id = #{companyId}
  1572. </if>
  1573. </where>
  1574. ) as courseUserNum
  1575. </select>
  1576. <select id="countUserRankingByComplete" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1577. SELECT
  1578. company_user.nick_name as userName,
  1579. ifnull(
  1580. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  1581. ) as completeRate
  1582. FROM
  1583. fs_user_course_count fcc
  1584. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1585. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1586. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1587. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1588. <where>
  1589. <if test="userId != null and userId != 0 ">
  1590. AND ( ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1591. </if>
  1592. <if test="userId != null and userId == 0 ">
  1593. and ucu.company_id = #{companyId}
  1594. </if>
  1595. <if test="startTime != null and startTime !='' ">
  1596. AND fcc.create_time &gt;= #{startTime}
  1597. </if>
  1598. <if test="endTime != null and endTime != ''">
  1599. AND fcc.create_time &lt;= #{endTime}
  1600. </if>
  1601. <if test="periodId != null and periodId != ''">
  1602. AND fcpd.period_id = #{periodId}
  1603. </if>
  1604. <if test="videoId != null and videoId != ''">
  1605. AND fcpd.video_id = #{videoId}
  1606. </if>
  1607. </where>
  1608. group by fcc.user_id
  1609. <choose>
  1610. <when test="order != null and order == 'asc'">
  1611. order by completeRate asc
  1612. </when>
  1613. <when test="order != null and order == 'desc'">
  1614. order by completeRate desc
  1615. </when>
  1616. <otherwise>
  1617. order by completeRate desc
  1618. </otherwise>
  1619. </choose>
  1620. limit 20
  1621. </select>
  1622. <select id="countUserRankingByRight" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1623. SELECT
  1624. company_user.nick_name as userName,
  1625. ifnull(ROUND(
  1626. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1627. *100,2),0
  1628. ) as answerRightRate
  1629. FROM
  1630. fs_course_answer_logs
  1631. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1632. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1633. <where>
  1634. <if test="userId != null and userId != 0 ">
  1635. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1636. </if>
  1637. <if test="userId != null and userId == 0 ">
  1638. and fs_course_answer_logs.company_id = #{companyId}
  1639. </if>
  1640. <if test="startTime != null and startTime !='' ">
  1641. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1642. </if>
  1643. <if test="endTime != null and endTime != ''">
  1644. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1645. </if>
  1646. <if test="periodId != null and periodId != ''">
  1647. AND fs_course_answer_logs.period_id = #{periodId}
  1648. </if>
  1649. <if test="videoId != null and videoId != ''">
  1650. AND fs_course_answer_logs.video_id = #{videoId}
  1651. </if>
  1652. </where>
  1653. group by fs_user.user_id
  1654. <choose>
  1655. <when test="order != null and order == 'asc'">
  1656. order by answerRightRate asc
  1657. </when>
  1658. <when test="order != null and order == 'desc'">
  1659. order by answerRightRate desc
  1660. </when>
  1661. <otherwise>
  1662. order by answerRightRate desc
  1663. </otherwise>
  1664. </choose>
  1665. limit 20
  1666. </select>
  1667. <select id="countCourseRankingByComplete" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1668. SELECT
  1669. fcv.title AS videoName,
  1670. fcv.video_id,
  1671. ifnull(
  1672. ROUND(
  1673. (
  1674. 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,
  1675. 2
  1676. ),
  1677. 0
  1678. ) AS completeRate
  1679. FROM
  1680. fs_course_watch_log fwl
  1681. LEFT JOIN fs_user ON fs_user.user_id = fwl.user_id
  1682. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1683. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1684. -- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1685. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fwl.video_id
  1686. <where>
  1687. <if test="userId != null and userId != 0 ">
  1688. AND ( fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1689. </if>
  1690. <if test="userId != null and userId == 0 ">
  1691. and fs_user_company_user.company_id = #{companyId}
  1692. </if>
  1693. <if test="startTime != null and startTime !='' ">
  1694. AND fwl.create_time &gt;= #{startTime}
  1695. </if>
  1696. <if test="endTime != null and endTime != ''">
  1697. AND fwl.create_time &lt;= #{endTime}
  1698. </if>
  1699. <if test="periodId != null and periodId != ''">
  1700. AND fwl.period_id = #{periodId}
  1701. </if>
  1702. <if test="videoId != null and videoId != ''">
  1703. AND fwl.video_id = #{videoId}
  1704. </if>
  1705. </where>
  1706. GROUP BY
  1707. fwl.video_id
  1708. <choose>
  1709. <when test="order != null and order == 'asc'">
  1710. ORDER BY completeRate asc
  1711. </when>
  1712. <when test="order != null and order == 'desc'">
  1713. ORDER BY completeRate desc
  1714. </when>
  1715. <otherwise>
  1716. ORDER BY completeRate desc
  1717. </otherwise>
  1718. </choose>
  1719. LIMIT 20
  1720. </select>
  1721. <select id="countCourseRankingByRight" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1722. SELECT
  1723. fcv.title AS videoName,
  1724. ifnull(
  1725. ROUND(
  1726. (
  1727. 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,
  1728. 2
  1729. ),
  1730. 0
  1731. ) AS answerRightRate
  1732. FROM
  1733. fs_course_answer_logs
  1734. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1735. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1736. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1737. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1738. <where>
  1739. <if test="userId != null and userId != 0 ">
  1740. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1741. </if>
  1742. <if test="userId != null and userId == 0 ">
  1743. and fs_course_answer_logs.company_id = #{companyId}
  1744. </if>
  1745. <if test="startTime != null and startTime !='' ">
  1746. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1747. </if>
  1748. <if test="endTime != null and endTime != ''">
  1749. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1750. </if>
  1751. <if test="periodId != null and periodId != ''">
  1752. AND fs_course_answer_logs.period_id = #{periodId}
  1753. </if>
  1754. <if test="videoId != null and videoId != ''">
  1755. AND fs_course_answer_logs.video_id = #{videoId}
  1756. </if>
  1757. </where>
  1758. GROUP BY
  1759. fs_course_answer_logs.video_id
  1760. <choose>
  1761. <when test="order != null and order == 'asc'">
  1762. ORDER BY answerRightRate asc
  1763. </when>
  1764. <when test="order != null and order == 'desc'">
  1765. ORDER BY answerRightRate desc
  1766. </when>
  1767. <otherwise>
  1768. ORDER BY answerRightRate desc
  1769. </otherwise>
  1770. </choose>
  1771. LIMIT 20
  1772. </select>
  1773. <select id="countUserRedPacket" resultType="Map">
  1774. SELECT
  1775. (
  1776. SELECT
  1777. count( flog.log_id )
  1778. FROM
  1779. fs_course_red_packet_log flog
  1780. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1781. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1782. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1783. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1784. where flog.status = 1
  1785. <if test="userId != null and userId != 0 ">
  1786. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1787. </if>
  1788. <if test="userId != null and userId == 0 ">
  1789. and flog.company_id = #{companyId}
  1790. </if>
  1791. <if test="startTime != null and startTime !='' ">
  1792. AND flog.create_time &gt;= #{startTime}
  1793. </if>
  1794. <if test="endTime != null and endTime != ''">
  1795. AND flog.create_time &lt;= #{endTime}
  1796. </if>
  1797. <if test="periodId != null and periodId != ''">
  1798. AND flog.period_id = #{periodId}
  1799. </if>
  1800. <if test="videoId != null and videoId != ''">
  1801. AND flog.video_id = #{videoId}
  1802. </if>
  1803. -- 单独通过销售id查询
  1804. <if test="companyUserId != null and companyUserId != ''">
  1805. AND company_user.user_id = #{companyUserId}
  1806. </if>
  1807. ) AS redPacketNum,
  1808. (
  1809. SELECT
  1810. ifnull (sum( flog.amount ), 0)
  1811. FROM
  1812. fs_course_red_packet_log flog
  1813. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1814. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1815. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1816. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1817. where flog.status = 1
  1818. <if test="userId != null and userId != 0 ">
  1819. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1820. </if>
  1821. <if test="userId != null and userId == 0 ">
  1822. and flog.company_id = #{companyId}
  1823. </if>
  1824. <if test="startTime != null and startTime !='' ">
  1825. AND flog.create_time &gt;= #{startTime}
  1826. </if>
  1827. <if test="endTime != null and endTime != ''">
  1828. AND flog.create_time &lt;= #{endTime}
  1829. </if>
  1830. <if test="periodId != null and periodId != ''">
  1831. AND flog.period_id = #{periodId}
  1832. </if>
  1833. <if test="videoId != null and videoId != ''">
  1834. AND flog.video_id = #{videoId}
  1835. </if>
  1836. -- 单独通过销售id查询
  1837. <if test="companyUserId != null and companyUserId != ''">
  1838. AND company_user.user_id = #{companyUserId}
  1839. </if>
  1840. ) AS redPacketAmount
  1841. </select>
  1842. <select id="courseAnalysisCourseCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  1843. SELECT
  1844. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1845. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1846. ifnull(
  1847. ROUND(
  1848. (
  1849. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1850. 2
  1851. ),
  1852. 0
  1853. ) as completeRate,
  1854. fcpd.video_id
  1855. FROM
  1856. fs_user_course_count fcc
  1857. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1858. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1859. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1860. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1861. <where>
  1862. <if test="companyUserId != null and companyUserId != 0 ">
  1863. AND ucu.company_user_id = #{companyUserId}
  1864. </if>
  1865. <if test="companyUserId != null and companyUserId == 0 ">
  1866. and ucu.company_id = #{companyId}
  1867. </if>
  1868. <if test="periodId != null and periodId != ''">
  1869. AND fcpd.period_id = #{periodId}
  1870. </if>
  1871. <if test="videoId != null and videoId != ''">
  1872. AND fcpd.video_id = #{videoId}
  1873. </if>
  1874. </where>
  1875. GROUP BY
  1876. fcpd.video_id
  1877. </select>
  1878. <select id="companyUserCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1879. SELECT
  1880. (
  1881. 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
  1882. <where>
  1883. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1884. AND ucu.company_user_id = #{companyUserId}
  1885. </if>
  1886. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1887. and ucu.company_id = #{companyId}
  1888. </if>
  1889. </where>
  1890. ) AS userTotal,
  1891. (
  1892. SELECT
  1893. count( fs_user.user_id )
  1894. FROM
  1895. fs_user
  1896. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1897. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1898. <where>
  1899. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1900. AND ucu.company_user_id = #{companyUserId}
  1901. </if>
  1902. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1903. and ucu.company_id = #{companyId}
  1904. </if>
  1905. and fs_user.is_del = 0
  1906. AND to_days( fs_user.create_time ) = to_days(
  1907. now())
  1908. </where>
  1909. ) AS todayNewUser
  1910. </select>
  1911. <select id="newUserRedPacketCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1912. SELECT
  1913. count(flog.log_id) as userRedPacketNum,
  1914. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1915. FROM
  1916. fs_course_red_packet_log flog
  1917. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1918. <where>
  1919. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1920. AND flog.company_user_id = #{companyUserId}
  1921. </if>
  1922. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1923. and flog.company_id = #{companyId}
  1924. </if>
  1925. </where>
  1926. </select>
  1927. <select id="countUserCourse2" resultType="java.util.Map">
  1928. SELECT
  1929. (
  1930. SELECT
  1931. count(DISTINCT l.user_id)
  1932. FROM
  1933. fs_course_watch_log l
  1934. LEFT JOIN fs_user on fs_user.user_id = l.user_id
  1935. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1936. 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
  1937. where
  1938. l.log_type != 3 and send_type = 1
  1939. <if test="userId != null and userId != 0 ">
  1940. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1941. </if>
  1942. <if test="userId != null and userId == 0 ">
  1943. and l.company_id = #{companyId}
  1944. </if>
  1945. <if test="periodId != null and periodId != ''">
  1946. AND l.period_id = #{periodId}
  1947. </if>
  1948. <if test="videoId != null and videoId != ''">
  1949. AND l.video_id = #{videoId}
  1950. </if>
  1951. <if test="startTime != null and startTime !='' ">
  1952. and l.create_time &gt;= #{startTime}
  1953. </if>
  1954. <if test="endTime != null and endTime != ''">
  1955. and l.create_time &lt;= #{endTime}
  1956. </if> <if test="companyUserId != null and companyUserId != ''">
  1957. AND l.user_id = #{companyUserId}
  1958. </if>
  1959. -- 单独通过销售id查询
  1960. <if test="companyUserId != null and companyUserId != ''">
  1961. AND l.company_user_id = #{companyUserId}
  1962. </if>
  1963. ) as courseWatchNum,
  1964. (
  1965. SELECT
  1966. count(DISTINCT l.user_id)
  1967. FROM
  1968. fs_course_watch_log l
  1969. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1970. LEFT JOIN fs_user ON fs_user.user_id = l.user_id
  1971. 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
  1972. where
  1973. l.log_type = 2 and send_type = 1
  1974. <if test="userId != null and userId != 0 ">
  1975. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1976. </if>
  1977. <if test="userId != null and userId == 0 ">
  1978. and l.company_id = #{companyId}
  1979. </if>
  1980. <if test="periodId != null and periodId != ''">
  1981. AND l.period_id = #{periodId}
  1982. </if>
  1983. <if test="videoId != null and videoId != ''">
  1984. AND l.video_id = #{videoId}
  1985. </if>
  1986. <if test="startTime != null and startTime !='' ">
  1987. and l.create_time &gt;= #{startTime}
  1988. </if>
  1989. <if test="endTime != null and endTime != ''">
  1990. and l.create_time &lt;= #{endTime}
  1991. </if>
  1992. -- 单独通过销售id查询
  1993. <if test="companyUserId != null and companyUserId != ''">
  1994. AND l.company_user_id = #{companyUserId}
  1995. </if>
  1996. ) as courseCompleteNum
  1997. </select>
  1998. <select id="countCourseDetailsNew" resultType="Map">
  1999. SELECT
  2000. count( DISTINCT l.period_id ) as courseNum,
  2001. count( DISTINCT l.video_id ) as videoNum,
  2002. count( DISTINCT l.user_id ) as courseUserNum
  2003. FROM
  2004. fs_course_watch_log l
  2005. left join fs_user on fs_user.user_id = l.user_id
  2006. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  2007. WHERE
  2008. l.log_type != 3
  2009. AND send_type = 1
  2010. <if test="userId != null and userId != 0 ">
  2011. AND l.company_user_id = #{userId}
  2012. </if>
  2013. <if test="userId != null and userId == 0 ">
  2014. and l.company_id = #{companyId}
  2015. </if>
  2016. <if test="periodId != null and periodId != ''">
  2017. AND l.period_id = #{periodId}
  2018. </if>
  2019. <if test="videoId != null and videoId != ''">
  2020. AND l.video_id = #{videoId}
  2021. </if>
  2022. -- 单独通过销售id查询
  2023. <if test="companyUserId != null and companyUserId != ''">
  2024. AND l.company_user_id = #{companyUserId}
  2025. </if>
  2026. </select>
  2027. <select id="selectFsUserVOListByProjectNew" resultType="com.fs.his.vo.FsUserVO">
  2028. SELECT
  2029. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  2030. ucu.project_id,ucu.company_user_id as companyUserId,ucu.update_time as bindTime,ucu.status,
  2031. company.company_name,
  2032. cu.nick_name companyUserNickName,
  2033. ucu.id userCompanyUserId,
  2034. u.source, u.login_device, u.app_create_time
  2035. FROM
  2036. fs_user_company_user ucu
  2037. left join
  2038. fs_user u on ucu.user_id = u.user_id
  2039. left join
  2040. company on company.company_id = ucu.company_id
  2041. left join
  2042. company_user cu on cu.user_id = ucu.company_user_id
  2043. <where>
  2044. 1 = 1 and u.nick_name is not null
  2045. and u.is_del = 0
  2046. <if test = "maps.nickname != null and maps.nickname !='' " >
  2047. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  2048. </if >
  2049. <if test = "maps.userId != null and maps.userId !='' " >
  2050. AND u.user_id = #{maps.userId}
  2051. </if >
  2052. <if test = "maps.phone != null and maps.phone !='' " >
  2053. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  2054. </if >
  2055. <if test = "maps.startCreateTime != null" >
  2056. AND ucu.update_time >= #{maps.startCreateTime}
  2057. </if >
  2058. <if test = "maps.endCreateTime != null" >
  2059. <![CDATA[
  2060. AND ucu.update_time < date_add(#{maps.endCreateTime}, interval 1 day)
  2061. ]]>
  2062. </if >
  2063. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  2064. AND u.register_code = #{maps.registerCode}
  2065. </if >
  2066. <if test = "maps.status != null" >
  2067. AND ucu.status = #{maps.status}
  2068. </if >
  2069. <if test = "maps.companyId != null and maps.companyId != '' " >
  2070. AND ucu.company_id = #{maps.companyId}
  2071. </if >
  2072. <if test = "maps.companyUserId != null" >
  2073. AND ucu.company_user_id = #{maps.companyUserId}
  2074. </if >
  2075. <if test = "maps.projectId != null" >
  2076. AND ucu.project_id = #{maps.projectId}
  2077. </if >
  2078. <if test="maps.isDownloadApp != null">
  2079. <choose>
  2080. <when test="maps.isDownloadApp == 1">
  2081. and ((u.source is not null and u.source != '') or u.login_device is not null or u.app_create_time is not null)
  2082. </when>
  2083. <when test="maps.isDownloadApp == 0">
  2084. and ((u.source is null or u.source = '') and u.login_device is null and u.app_create_time is null)
  2085. </when>
  2086. </choose>
  2087. </if>
  2088. </where>
  2089. ORDER BY
  2090. user_id DESC
  2091. </select>
  2092. <select id="selectFsUserVOListByProject" resultType="com.fs.his.vo.FsUserVO">
  2093. SELECT distinct
  2094. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  2095. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  2096. fcc.watch_course_count, fcc.part_course_count, company_user.nick_name AS companyUserNickName, fcc.last_watch_date
  2097. ,company.company_name,
  2098. ucu.project_id,
  2099. ucu.id as companyUserId,
  2100. ucu.create_time as bindTime,
  2101. ucu.status
  2102. FROM
  2103. fs_user u
  2104. LEFT JOIN (
  2105. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  2106. user_id
  2107. FROM
  2108. fs_store_payment
  2109. WHERE
  2110. STATUS = 1
  2111. AND user_id IS NOT NULL
  2112. GROUP BY
  2113. user_id
  2114. ) b ON u.user_id = b.user_id
  2115. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  2116. AND b.last_buy_time = p.pay_time
  2117. AND b.payment_id = p.payment_id
  2118. LEFT JOIN (
  2119. SELECT
  2120. 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,
  2121. fs_user_course_count.part_course_count
  2122. FROM
  2123. fs_user_course_count
  2124. GROUP BY fs_user_course_count.user_id
  2125. ) fcc ON fcc.user_id = u.user_id
  2126. inner join fs_user_company_user ucu on ucu.user_id = u.user_id
  2127. LEFT JOIN company_user ON company_user.user_id = ucu.company_user_id
  2128. LEFT JOIN company on company.company_id = company_user.company_id
  2129. <where>
  2130. 1 = 1 and u.nick_name is not null
  2131. and u.is_del = 0
  2132. <if test = "maps.nickname != null and maps.nickname !='' " >
  2133. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  2134. </if >
  2135. <if test = "maps.userId != null and maps.userId !='' " >
  2136. AND u.user_id = #{maps.userId}
  2137. </if >
  2138. <if test = "maps.phone != null and maps.phone !='' " >
  2139. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  2140. </if >
  2141. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  2142. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  2143. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  2144. )
  2145. </if >
  2146. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  2147. AND u.register_code = #{maps.registerCode}
  2148. </if >
  2149. <if test = "maps.status != null" >
  2150. AND ucu.status = #{maps.status}
  2151. </if >
  2152. <if test = "maps.companyId != null and maps.companyId != '' " >
  2153. AND company.company_id = #{maps.companyId}
  2154. </if >
  2155. <if test = "maps.companyUserId != null" >
  2156. AND company_user.user_id = #{maps.companyUserId}
  2157. </if >
  2158. <if test = "maps.projectId != null" >
  2159. AND ucu.project_id = #{maps.projectId}
  2160. </if >
  2161. </where>
  2162. ORDER BY
  2163. user_id DESC
  2164. </select>
  2165. <select id="selectCompanyAndDoctor" resultType="com.fs.watch.domain.vo.FsUserAndCompanyAndDoctorVo">
  2166. SELECT
  2167. f.*,
  2168. GROUP_CONCAT(c.company_id SEPARATOR ',') AS company_id,
  2169. GROUP_CONCAT(c.company_user_id SEPARATOR ',') AS company_user_id,
  2170. GROUP_CONCAT(o.doctor_id SEPARATOR ',') AS doctor_id
  2171. FROM
  2172. fs_user f
  2173. LEFT JOIN
  2174. company_user_user c ON c.user_id = f.user_id
  2175. LEFT JOIN
  2176. fs_inquiry_order o ON o.user_id = f.user_id AND o.`status` = 4
  2177. WHERE
  2178. f.is_del = 0 AND f.user_id = #{userId}
  2179. GROUP BY
  2180. f.user_id;
  2181. </select>
  2182. <select id="selectUserNameByIds" resultMap="FsUserResult">
  2183. select user_id,nick_name from fs_user where user_id in
  2184. <foreach collection="userIds.split(',')" item="userId" open="(" close=")" separator=",">
  2185. #{userId}
  2186. </foreach>
  2187. </select>
  2188. <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
  2189. SELECT
  2190. count( DISTINCT fs_user.user_id ) as userNum,
  2191. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  2192. fs_user_company_user.company_id
  2193. FROM
  2194. fs_user
  2195. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  2196. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2197. WHERE
  2198. fs_user.is_del = 0
  2199. AND fs_user.`status` = 1
  2200. AND fs_user_company_user.`status` = 1
  2201. AND company_user.user_id IS NOT NULL
  2202. GROUP BY
  2203. fs_user_company_user.company_id
  2204. </select>
  2205. <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
  2206. SELECT
  2207. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  2208. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  2209. ifnull(
  2210. ROUND(
  2211. (
  2212. 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,
  2213. 2
  2214. ),
  2215. 0
  2216. ) AS completeWatchRate,
  2217. fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
  2218. FROM
  2219. fs_course_watch_log fwl
  2220. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fwl.user_id
  2221. WHERE
  2222. fwl.send_type = 1
  2223. AND fs_user_company_user.`status` = 1
  2224. GROUP BY
  2225. fwl.period_id, fwl.video_id, fwl.company_user_id
  2226. </select>
  2227. <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
  2228. SELECT
  2229. count(DISTINCT flog.log_id ) AS redPacketNum,
  2230. ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
  2231. flog.period_id,
  2232. flog.video_id,
  2233. flog.company_user_id,
  2234. flog.company_id
  2235. FROM
  2236. fs_course_red_packet_log flog
  2237. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = flog.user_id
  2238. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2239. where flog.`status` = 1
  2240. AND fs_user_company_user.`status` = 1
  2241. GROUP BY
  2242. flog.period_id,
  2243. flog.video_id,
  2244. flog.company_user_id
  2245. </select>
  2246. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  2247. SELECT
  2248. count( DISTINCT fs_user_company_user.user_id ) AS answerNum,
  2249. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user_company_user.user_id END ) AS answerRightNum,
  2250. ifnull(
  2251. ROUND(
  2252. (
  2253. 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,
  2254. 2
  2255. ),
  2256. 0
  2257. ) AS answerRightRate,
  2258. fs_course_answer_logs.period_id,
  2259. fs_course_answer_logs.video_id,
  2260. fs_course_answer_logs.company_user_id,
  2261. fs_course_answer_logs.company_id
  2262. FROM
  2263. fs_course_answer_logs
  2264. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_course_answer_logs.user_id
  2265. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2266. where fs_user_company_user.`status` = 1
  2267. GROUP BY
  2268. fs_course_answer_logs.period_id,
  2269. fs_course_answer_logs.video_id,
  2270. fs_course_answer_logs.company_user_id
  2271. </select>
  2272. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  2273. SELECT
  2274. count(DISTINCT fs_user.user_id ) as userNum,
  2275. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  2276. date(fs_user.create_time) as userCreateDate
  2277. ,company.company_id,
  2278. company.company_name,
  2279. company_user.user_id AS companyUserId,
  2280. company_user.nick_name AS companyUserName
  2281. FROM
  2282. fs_user
  2283. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  2284. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2285. LEFT JOIN company ON company.company_id = fs_user_company_user.company_id
  2286. WHERE
  2287. fs_user.is_del = 0
  2288. AND fs_user_company_user.`status` = 1
  2289. AND fs_user.`status` = 1
  2290. AND company_user.user_id is not null
  2291. GROUP BY
  2292. fs_user_company_user.company_user_id, date(fs_user.create_time)
  2293. </select>
  2294. <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
  2295. <include refid="selectFsUserVo"/>
  2296. <where>
  2297. <if test="userName != null and userName != ''">
  2298. AND (
  2299. nickname like concat('%', #{userName}, '%')
  2300. or user_id LIKE concat('%',#{userName},'%')
  2301. )
  2302. </if>
  2303. </where>
  2304. order by user_id desc
  2305. </select>
  2306. <select id="selectFsUserCount" resultType="java.lang.Long">
  2307. select count(1) from fs_user
  2308. where 1=1
  2309. <if test = "type != null and type ==1">
  2310. and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
  2311. </if>
  2312. <if test = "companyId != null">
  2313. and company_id=#{companyId}
  2314. </if>
  2315. <if test="companyUserId != null">
  2316. and company_user_id = #{companyUserId}
  2317. </if>
  2318. </select>
  2319. <select id="selectFsUserListLimit" resultMap="FsUserResult">
  2320. <include refid="selectFsUserVo"/>
  2321. <where>
  2322. <if test="password != null and password != ''">and password = #{password}</if>
  2323. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  2324. <if test="birthday != null ">and birthday = #{birthday}</if>
  2325. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  2326. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  2327. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  2328. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  2329. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  2330. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  2331. <if test="integral != null ">and integral = #{integral}</if>
  2332. <if test="signNum != null ">and sign_num = #{signNum}</if>
  2333. <if test="status != null ">and status = #{status}</if>
  2334. <if test="level != null ">and level = #{level}</if>
  2335. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  2336. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  2337. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  2338. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  2339. <if test="payCount != null ">and pay_count = #{payCount}</if>
  2340. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  2341. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  2342. <if test="isDel != null ">and is_del = #{isDel}</if>
  2343. <if test="companyId != null ">and company_id = #{companyId}</if>
  2344. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  2345. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  2346. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  2347. </if>
  2348. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  2349. <if test="source != null and source != '' ">and source = #{source}</if>
  2350. <if test="isShow != null ">and is_show = #{isShow}</if>
  2351. <if test="(username != null and username != '') or (userId != null and userId != '') or (nickname != null and nickname != '') or (phone != null and phone != '')">
  2352. and (
  2353. <if test="username != null and username != ''">username like concat('%', #{username}, '%')</if>
  2354. <if test="userId != null and userId != ''">or user_id = #{userId}</if>
  2355. <if test="nickname != null and nickname != ''">or nickname like concat('%', #{nickname}, '%')</if>
  2356. <if test="phone != null and phone != ''">or phone like concat('%',#{phone},'%')</if>
  2357. )
  2358. </if>
  2359. <if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  2360. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>
  2361. <if test="payOrder != null ">and pay_order = #{payOrder}</if>
  2362. </where>
  2363. order by user_id desc
  2364. limit 10
  2365. </select>
  2366. <select id="findUsersByParam" resultType="com.fs.his.dto.FindUsersByDTO">
  2367. SELECT user_id as id, 0 as type,
  2368. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2369. FROM fs_user
  2370. WHERE user_id = #{keywords}
  2371. UNION
  2372. <!-- fs_user 按nick_name前缀搜索 -->
  2373. SELECT user_id as id, 0 as type,
  2374. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2375. FROM fs_user
  2376. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2377. UNION
  2378. <!-- fs_user 按phone精确搜索(仅当keywords是数字时) -->
  2379. <if test="keywords.matches('\\d+')">
  2380. SELECT user_id as id, 0 as type,
  2381. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2382. FROM fs_user
  2383. WHERE phone = #{keywords}
  2384. UNION
  2385. </if>
  2386. <!-- company_user相关查询 -->
  2387. SELECT user_id as id, 1 as type,
  2388. IFNULL(nick_name, '') as name
  2389. FROM company_user
  2390. WHERE user_id = #{keywords}
  2391. UNION
  2392. SELECT user_id as id, 1 as type,
  2393. IFNULL(nick_name, '') as name
  2394. FROM company_user
  2395. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2396. <if test="keywords.matches('\\d+')">
  2397. UNION
  2398. SELECT user_id as id, 1 as type,
  2399. IFNULL(nick_name, '') as name
  2400. FROM company_user
  2401. WHERE phonenumber = #{keywords}
  2402. </if>
  2403. </select>
  2404. <select id="countExternalRedPacketStats" resultType="com.fs.store.vo.h5.ExternalRedPacketStatsVO">
  2405. SELECT
  2406. COUNT(red.log_id) AS redPacketNum,
  2407. COALESCE(SUM(red.amount), 0) AS redPacketAmount
  2408. FROM fs_course_red_packet_log log
  2409. WHERE log.status = 1
  2410. AND log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2411. <if test="startTime != null and startTime != ''">
  2412. AND log.create_time &gt;= #{startTime}
  2413. </if>
  2414. <if test="endTime != null and endTime != ''">
  2415. AND log.create_time &lt;= #{endTime}
  2416. </if>
  2417. </select>
  2418. <select id="countExternalAnswerStats" resultType="com.fs.store.vo.h5.ExternalAnswerStatsVO">
  2419. SELECT
  2420. COUNT(*) AS answerNum,
  2421. SUM(CASE WHEN is_right = 1 THEN 1 ELSE 0 END) AS answerRightNum
  2422. FROM fs_course_answer_logs log
  2423. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2424. <if test="startTime != null and startTime != ''">
  2425. AND log.create_time &gt;= #{startTime}
  2426. </if>
  2427. <if test="endTime != null and endTime != ''">
  2428. AND log.create_time &lt;= #{endTime}
  2429. </if>
  2430. </select>
  2431. <select id="countExternalWatchStats" resultType="com.fs.store.vo.h5.ExternalWatchStatsVO">
  2432. SELECT
  2433. COUNT(CASE WHEN log_type != 3 THEN 1 END) AS courseWatchNum,
  2434. COUNT(CASE WHEN log_type = 2 THEN 1 END) AS courseCompleteNum
  2435. FROM fs_course_watch_log log
  2436. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2437. <if test="startTime != null and startTime != ''">
  2438. AND log.create_time &gt;= #{startTime}
  2439. </if>
  2440. <if test="endTime != null and endTime != ''">
  2441. AND log.create_time &lt;= #{endTime}
  2442. </if>
  2443. </select>
  2444. <select id="selectLastWatchTimeByUserAndProject" resultType="java.util.Map">
  2445. SELECT
  2446. CONCAT(user_id, '_', project) AS userProjectKey,
  2447. MAX(COALESCE(update_time, create_time)) AS lastWatchTime
  2448. FROM fs_course_watch_log
  2449. WHERE (user_id, project) IN
  2450. <foreach collection="userProjectPairs" item="pair" open="(" close=")" separator=",">
  2451. (#{pair.userId}, #{pair.projectId})
  2452. </foreach>
  2453. GROUP BY user_id, project_id
  2454. </select>
  2455. <select id="findUsersByIdsV2" resultMap="FsUserResult">
  2456. select
  2457. *
  2458. from fs_user
  2459. where user_id in
  2460. <foreach collection="userIds" item="userId" open="(" separator="," close=")">
  2461. #{userId}
  2462. </foreach>
  2463. </select>
  2464. <select id="selectFsPeriodCountVO" resultType="com.fs.course.vo.FsPeriodCountVO">
  2465. SELECT
  2466. COUNT(DISTINCT IF(log_type != 3, user_id, NULL)) AS coursePeriodWatchNum,
  2467. COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS coursePeriodCompleteNum
  2468. FROM fs_course_watch_log
  2469. <where>
  2470. <if test="companyId != null">
  2471. AND company_id = #{companyId}
  2472. </if>
  2473. <if test="periodId != null">
  2474. AND period_id = #{periodId}
  2475. </if>
  2476. <if test="typeFlag != null">
  2477. AND watch_type = #{typeFlag}
  2478. </if>
  2479. <if test="companyUserIds != null and companyUserIds.size > 0">
  2480. AND company_user_id in
  2481. <foreach collection="companyUserIds" open="(" close=")" separator="," item="companyUserId">
  2482. #{companyUserId}
  2483. </foreach>
  2484. </if>
  2485. </where>
  2486. </select>
  2487. <select id="selectFsUserListByPhone" resultType="com.fs.his.domain.FsUser">
  2488. select * from fs_user where phone=#{phone}
  2489. </select>
  2490. <select id="selectProjectUserExportCount" resultType="java.lang.Long">
  2491. SELECT count(1)
  2492. FROM fs_user
  2493. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  2494. <where>
  2495. fs_user.is_del = 0
  2496. <if test="userId != null">
  2497. AND fs_user.user_id = #{userId}
  2498. </if>
  2499. <if test="companyId != null">
  2500. AND ucu.company_id = #{companyId}
  2501. </if>
  2502. <choose>
  2503. <when test="companyUserIds != null and companyUserIds.size > 0">
  2504. AND ucu.company_user_id in
  2505. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  2506. ${item}
  2507. </foreach>
  2508. </when>
  2509. <when test="companyUserId != null and companyUserId != '' ">
  2510. AND ucu.company_user_id = #{companyUserId}
  2511. </when>
  2512. </choose>
  2513. <if test="registerStartTime != null and registerStartTime !='' ">
  2514. AND ucu.update_time >= #{registerStartTime}
  2515. </if>
  2516. <if test="registerEndTime != null and registerEndTime !='' ">
  2517. <![CDATA[
  2518. AND ucu.update_time < date_add(#{registerEndTime}, interval 1 day)
  2519. ]]>
  2520. </if>
  2521. <!-- <if test="companyUserIds != null and companyUserIds.size > 0">-->
  2522. <!-- AND ucu.company_user_id in-->
  2523. <!-- <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">-->
  2524. <!-- ${item}-->
  2525. <!-- </foreach>-->
  2526. <!-- </if>-->
  2527. <if test="nickname != null and nickname != ''">
  2528. AND fs_user.nick_name like concat('%', #{nickname},'%')
  2529. </if>
  2530. <if test="phone != null and phone != ''">
  2531. AND fs_user.phone like concat('%', #{phone},'%')
  2532. </if>
  2533. <if test="projectId != null">
  2534. AND ucu.project_id = #{projectId}
  2535. </if>
  2536. <if test="appCreateTimeStart != null and appCreateTimeEnd != null">
  2537. AND fs_user.app_create_time BETWEEN #{appCreateTimeStart} AND #{appCreateTimeEnd}
  2538. </if>
  2539. <if test="isDownloadApp != null">
  2540. <choose>
  2541. <when test="isDownloadApp == 1">
  2542. 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)
  2543. </when>
  2544. <when test="isDownloadApp == 0">
  2545. 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)
  2546. </when>
  2547. </choose>
  2548. </if>
  2549. </where>
  2550. </select>
  2551. <select id="FsUserPageListExportVO" resultType="com.fs.store.vo.h5.FsUserPageListExportVO">
  2552. SELECT
  2553. fs_user.user_id,
  2554. fs_user.nick_name as nickname,
  2555. fs_user.avatar,
  2556. fs_user.phone,
  2557. fs_user.status,
  2558. ucu.update_time createTime,
  2559. fs_user.remark,
  2560. ucu.company_user_id,
  2561. ucu.company_id,
  2562. ucu.project_id,
  2563. fs_user.integral,
  2564. if(fs_user.pay_count>0,1,0) as isBuy,
  2565. fs_user.source,
  2566. fs_user.login_device as loginDevice,
  2567. fs_user.app_create_time
  2568. FROM fs_user
  2569. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  2570. <where>
  2571. fs_user.is_del = 0
  2572. <if test="userId != null">
  2573. AND fs_user.user_id = #{userId}
  2574. </if>
  2575. <if test="companyId != null">
  2576. AND ucu.company_id = #{companyId}
  2577. </if>
  2578. <choose>
  2579. <when test="companyUserIds != null and companyUserIds.size > 0">
  2580. AND ucu.company_user_id in
  2581. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  2582. ${item}
  2583. </foreach>
  2584. </when>
  2585. <when test="companyUserId != null and companyUserId != '' ">
  2586. AND ucu.company_user_id = #{companyUserId}
  2587. </when>
  2588. </choose>
  2589. <if test="registerStartTime != null and registerStartTime !='' ">
  2590. AND ucu.update_time &gt;= #{registerStartTime}
  2591. </if>
  2592. <if test="registerEndTime != null and registerEndTime !='' ">
  2593. <![CDATA[
  2594. AND ucu.update_time < date_add(#{registerEndTime}, interval 1 day)
  2595. ]]>
  2596. </if>
  2597. <!-- <if test="companyUserIds != null and companyUserIds.size > 0">-->
  2598. <!-- AND ucu.company_user_id in-->
  2599. <!-- <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">-->
  2600. <!-- ${item}-->
  2601. <!-- </foreach>-->
  2602. <!-- </if>-->
  2603. <if test="nickname != null and nickname != ''">
  2604. AND fs_user.nick_name like concat('%', #{nickname},'%')
  2605. </if>
  2606. <if test="phone != null and phone != ''">
  2607. AND fs_user.phone like concat('%', #{phone},'%')
  2608. </if>
  2609. <if test="projectId != null">
  2610. AND ucu.project_id = #{projectId}
  2611. </if>
  2612. <if test="appCreateTimeStart != null and appCreateTimeEnd != null">
  2613. AND fs_user.app_create_time BETWEEN #{appCreateTimeStart} AND #{appCreateTimeEnd}
  2614. </if>
  2615. <if test="isDownloadApp != null">
  2616. <choose>
  2617. <when test="isDownloadApp == 1">
  2618. 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)
  2619. </when>
  2620. <when test="isDownloadApp == 0">
  2621. 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)
  2622. </when>
  2623. </choose>
  2624. </if>
  2625. </where>
  2626. </select>
  2627. <select id="getWallet" resultType="com.fs.his.vo.IntegralExchangeVo">
  2628. SELECT user_id,integral, withdraw_integral, total_commission, withdraw_finish,may_withdraw FROM fs_user WHERE user_id = #{userId}
  2629. </select>
  2630. <select id="selectExternalUserList" parameterType="com.fs.his.param.FsUserParam" resultType="com.fs.his.vo.FsUserVO">
  2631. SELECT
  2632. fu.user_id,
  2633. fu.nick_name,
  2634. fu.avatar,
  2635. fu.phone,
  2636. fu.status,
  2637. fu.source,
  2638. fu.login_device as loginDevice,
  2639. fu.app_create_time as appCreateTime,
  2640. fu.create_time as createTime
  2641. FROM fs_user fu
  2642. WHERE fu.is_external = 0
  2643. AND fu.is_del = 0
  2644. <if test="nickName != null and nickName != ''">
  2645. AND fu.nick_name LIKE CONCAT('%', #{nickName}, '%')
  2646. </if>
  2647. <if test="phone != null and phone != ''">
  2648. AND fu.phone LIKE CONCAT('%', #{phone}, '%')
  2649. </if>
  2650. ORDER BY fu.user_id DESC
  2651. </select>
  2652. <select id="selectInactiveAppUsers" resultType="java.lang.Long">
  2653. SELECT user_id FROM fs_user
  2654. WHERE update_time &lt; #{threeMonthsAgo}
  2655. and ((source is not null and source != '') and login_device is not null or app_create_time is not null)
  2656. </select>
  2657. <!-- 邀请看课数据漏斗统计 -->
  2658. <select id="countCourseInviteFunnel" resultType="Map">
  2659. SELECT
  2660. COUNT(DISTINCT d.user_id) AS inviteTotal,
  2661. COUNT(DISTINCT CASE WHEN d.status = 0 AND d.send_status = 1 THEN d.user_id END) AS sendSuccess,
  2662. COUNT(DISTINCT CASE WHEN d.status = 0 AND d.send_status = 1 AND w.log_id IS NULL THEN d.user_id END) AS notWatched,
  2663. COUNT(DISTINCT CASE WHEN w.log_type IN (1, 4) THEN d.user_id END) AS watchingIncomplete,
  2664. COUNT(DISTINCT CASE WHEN w.log_type = 2 THEN d.user_id END) AS watchedComplete,
  2665. COUNT(DISTINCT CASE WHEN d.status = 0 AND d.send_status = 1 AND w.log_id IS NULL AND pd.status = 2 THEN d.user_id END) AS expiredNotWatched
  2666. FROM fs_im_msg_send_detail d
  2667. JOIN fs_im_msg_send_log l ON l.log_id = d.log_id
  2668. AND l.company_user_id = #{companyUserId}
  2669. AND l.video_id = #{videoId}
  2670. AND l.period_id = #{periodId}
  2671. LEFT JOIN fs_course_watch_log w ON w.user_id = d.user_id
  2672. AND w.video_id = l.video_id
  2673. AND w.course_id = l.course_id
  2674. AND w.period_id = l.period_id
  2675. LEFT JOIN fs_user_course_period_days pd ON pd.id = l.period_days_id
  2676. </select>
  2677. </mapper>