FsUserMapper.xml 110 KB

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