FsUserMapper.xml 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462
  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 fs_user u ON u.user_id = l.user_id
  1083. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  1084. <where>
  1085. l.log_type != 3 AND l.send_type = 1
  1086. <if test="userId != null and userId != 0 ">
  1087. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1088. </if>
  1089. <if test="userId != null and userId == 0 ">
  1090. AND l.company_id = #{companyId}
  1091. </if>
  1092. <if test="periodId != null and periodId != '' ">
  1093. AND l.period_id = #{periodId}
  1094. </if>
  1095. <if test="videoId != null and videoId != '' ">
  1096. AND l.video_id = #{videoId}
  1097. </if>
  1098. <if test="startTime != null and startTime != '' ">
  1099. AND l.create_time &gt;= #{startTime}
  1100. </if>
  1101. <if test="endTime != null and endTime != '' ">
  1102. AND l.create_time &lt;= #{endTime}
  1103. </if>
  1104. <if test="companyUserId != null and companyUserId != '' ">
  1105. AND l.company_user_id = #{companyUserId}
  1106. </if>
  1107. </where>
  1108. ) AS courseWatchNum,
  1109. -- 完成人数
  1110. (
  1111. SELECT COUNT(DISTINCT l.user_id)
  1112. FROM fs_course_watch_log l
  1113. LEFT JOIN fs_user u ON u.user_id = l.user_id
  1114. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  1115. <where>
  1116. l.log_type = 2 AND l.send_type = 1
  1117. <if test="userId != null and userId != 0 ">
  1118. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1119. </if>
  1120. <if test="userId != null and userId == 0 ">
  1121. AND l.company_id = #{companyId}
  1122. </if>
  1123. <if test="periodId != null and periodId != '' ">
  1124. AND l.period_id = #{periodId}
  1125. </if>
  1126. <if test="videoId != null and videoId != '' ">
  1127. AND l.video_id = #{videoId}
  1128. </if>
  1129. <if test="startTime != null and startTime != '' ">
  1130. AND l.create_time &gt;= #{startTime}
  1131. </if>
  1132. <if test="endTime != null and endTime != '' ">
  1133. AND l.create_time &lt;= #{endTime}
  1134. </if>
  1135. <if test="companyUserId != null and companyUserId != '' ">
  1136. AND l.company_user_id = #{companyUserId}
  1137. </if>
  1138. </where>
  1139. ) AS courseCompleteNum,
  1140. -- 答题人数
  1141. (
  1142. SELECT COUNT(distinct a.user_id)
  1143. FROM fs_course_answer_logs a
  1144. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1145. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  1146. <where>
  1147. 1=1
  1148. <if test="userId != null and userId != 0 ">
  1149. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1150. </if>
  1151. <if test="userId != null and userId == 0 ">
  1152. AND a.company_id = #{companyId}
  1153. </if>
  1154. <if test="periodId != null and periodId != '' ">
  1155. AND a.period_id = #{periodId}
  1156. </if>
  1157. <if test="videoId != null and videoId != '' ">
  1158. AND a.video_id = #{videoId}
  1159. </if>
  1160. <if test="startTime != null and startTime != '' ">
  1161. AND a.create_time &gt;= #{startTime}
  1162. </if>
  1163. <if test="endTime != null and endTime != '' ">
  1164. AND a.create_time &lt;= #{endTime}
  1165. </if>
  1166. <if test="companyUserId != null and companyUserId != '' ">
  1167. AND a.company_user_id = #{companyUserId}
  1168. </if>
  1169. </where>
  1170. ) AS answerNum,
  1171. -- 答对人数
  1172. (
  1173. SELECT COUNT(distinct a.user_id)
  1174. FROM fs_course_answer_logs a
  1175. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1176. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  1177. <where>
  1178. a.is_right = 1
  1179. <if test="userId != null and userId != 0 ">
  1180. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1181. </if>
  1182. <if test="userId != null and userId == 0 ">
  1183. AND a.company_id = #{companyId}
  1184. </if>
  1185. <if test="periodId != null and periodId != '' ">
  1186. AND a.period_id = #{periodId}
  1187. </if>
  1188. <if test="videoId != null and videoId != '' ">
  1189. AND a.video_id = #{videoId}
  1190. </if>
  1191. <if test="startTime != null and startTime != '' ">
  1192. AND a.create_time &gt;= #{startTime}
  1193. </if>
  1194. <if test="endTime != null and endTime != '' ">
  1195. AND a.create_time &lt;= #{endTime}
  1196. </if>
  1197. <if test="companyUserId != null and companyUserId != '' ">
  1198. AND a.company_user_id = #{companyUserId}
  1199. </if>
  1200. </where>
  1201. ) AS answerRightNum,
  1202. -- 红包数
  1203. (
  1204. SELECT COUNT(flog.log_id)
  1205. FROM fs_course_red_packet_log flog
  1206. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1207. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1208. <where>
  1209. flog.status = 1
  1210. <if test="userId != null and userId != 0 ">
  1211. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1212. </if>
  1213. <if test="userId != null and userId == 0 ">
  1214. AND flog.company_id = #{companyId}
  1215. </if>
  1216. <if test="periodId != null and periodId != '' ">
  1217. AND flog.period_id = #{periodId}
  1218. </if>
  1219. <if test="videoId != null and videoId != '' ">
  1220. AND flog.video_id = #{videoId}
  1221. </if>
  1222. <if test="startTime != null and startTime != '' ">
  1223. AND flog.create_time &gt;= #{startTime}
  1224. </if>
  1225. <if test="endTime != null and endTime != '' ">
  1226. AND flog.create_time &lt;= #{endTime}
  1227. </if>
  1228. <if test="companyUserId != null and companyUserId != '' ">
  1229. AND flog.company_user_id = #{companyUserId}
  1230. </if>
  1231. </where>
  1232. ) AS redPacketNum,
  1233. -- 红包金额
  1234. (
  1235. SELECT IFNULL(SUM(flog.amount), 0)
  1236. FROM fs_course_red_packet_log flog
  1237. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1238. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1239. <where>
  1240. flog.status = 1
  1241. <if test="userId != null and userId != 0 ">
  1242. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1243. </if>
  1244. <if test="userId != null and userId == 0 ">
  1245. AND flog.company_id = #{companyId}
  1246. </if>
  1247. <if test="periodId != null and periodId != '' ">
  1248. AND flog.period_id = #{periodId}
  1249. </if>
  1250. <if test="videoId != null and videoId != '' ">
  1251. AND flog.video_id = #{videoId}
  1252. </if>
  1253. <if test="startTime != null and startTime != '' ">
  1254. AND flog.create_time &gt;= #{startTime}
  1255. </if>
  1256. <if test="endTime != null and endTime != '' ">
  1257. AND flog.create_time &lt;= #{endTime}
  1258. </if>
  1259. <if test="companyUserId != null and companyUserId != '' ">
  1260. AND flog.company_user_id = #{companyUserId}
  1261. </if>
  1262. </where>
  1263. ) AS redPacketAmount
  1264. </select>
  1265. <!-- 查询观看和完成人数 -->
  1266. <select id="countUserWatchStats" resultType="Map">
  1267. SELECT
  1268. COUNT(DISTINCT CASE WHEN l.log_type != 3 AND l.send_type = 1 THEN l.user_id END) AS courseWatchNum,
  1269. COUNT(DISTINCT CASE WHEN l.log_type = 2 AND l.send_type = 1 THEN l.user_id END) AS courseCompleteNum
  1270. FROM fs_course_watch_log l
  1271. LEFT JOIN fs_user u ON u.user_id = l.user_id
  1272. LEFT JOIN company_user cu_l ON l.company_user_id = cu_l.user_id
  1273. <where>
  1274. <if test="userId != null and userId != 0">
  1275. AND (cu_l.user_id = #{userId} OR cu_l.parent_id = #{userId})
  1276. </if>
  1277. <if test="userId != null and userId == 0">
  1278. AND l.company_id = #{companyId}
  1279. </if>
  1280. <if test="periodId != null and periodId != ''">
  1281. AND l.period_id = #{periodId}
  1282. </if>
  1283. <if test="videoId != null and videoId != ''">
  1284. AND l.video_id = #{videoId}
  1285. </if>
  1286. <if test="startTime != null and startTime != ''">
  1287. AND l.create_time &gt;= #{startTime}
  1288. </if>
  1289. <if test="endTime != null and endTime != ''">
  1290. AND l.create_time &lt;= #{endTime}
  1291. </if>
  1292. <if test="companyUserId != null and companyUserId != ''">
  1293. AND l.company_user_id = #{companyUserId}
  1294. </if>
  1295. </where>
  1296. </select>
  1297. <!-- 查询答题人数和答对人数 -->
  1298. <select id="countUserAnswerStats" resultType="Map">
  1299. SELECT
  1300. COUNT(DISTINCT CASE WHEN a.user_id THEN a.user_id END) AS answerNum,
  1301. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS answerRightNum
  1302. FROM fs_course_answer_logs a
  1303. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1304. LEFT JOIN company_user cu_a ON a.company_user_id = cu_a.user_id
  1305. <where>
  1306. <if test="userId != null and userId != 0">
  1307. AND (cu_a.user_id = #{userId} OR cu_a.parent_id = #{userId})
  1308. </if>
  1309. <if test="userId != null and userId == 0">
  1310. AND a.company_id = #{companyId}
  1311. </if>
  1312. <if test="periodId != null and periodId != ''">
  1313. AND a.period_id = #{periodId}
  1314. </if>
  1315. <if test="videoId != null and videoId != ''">
  1316. AND a.video_id = #{videoId}
  1317. </if>
  1318. <if test="startTime != null and startTime != ''">
  1319. AND a.create_time &gt;= #{startTime}
  1320. </if>
  1321. <if test="endTime != null and endTime != ''">
  1322. AND a.create_time &lt;= #{endTime}
  1323. </if>
  1324. <if test="companyUserId != null and companyUserId != ''">
  1325. AND a.company_user_id = #{companyUserId}
  1326. </if>
  1327. </where>
  1328. </select>
  1329. <!-- 查询红包数量和红包金额 -->
  1330. <select id="countUserRedPacketStats" resultType="Map">
  1331. SELECT
  1332. COUNT(CASE WHEN flog.status = 1 THEN flog.log_id END) AS redPacketNum,
  1333. IFNULL(SUM(CASE WHEN flog.status = 1 THEN flog.amount END), 0) AS redPacketAmount
  1334. FROM fs_course_red_packet_log flog
  1335. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1336. LEFT JOIN company_user cu_flog ON flog.company_user_id = cu_flog.user_id
  1337. <where>
  1338. <if test="userId != null and userId != 0">
  1339. AND (cu_flog.user_id = #{userId} OR cu_flog.parent_id = #{userId})
  1340. </if>
  1341. <if test="userId != null and userId == 0">
  1342. AND flog.company_id = #{companyId}
  1343. </if>
  1344. <if test="periodId != null and periodId != ''">
  1345. AND flog.period_id = #{periodId}
  1346. </if>
  1347. <if test="videoId != null and videoId != ''">
  1348. AND flog.video_id = #{videoId}
  1349. </if>
  1350. <if test="startTime != null and startTime != ''">
  1351. AND flog.create_time &gt;= #{startTime}
  1352. </if>
  1353. <if test="endTime != null and endTime != ''">
  1354. AND flog.create_time &lt;= #{endTime}
  1355. </if>
  1356. <if test="companyUserId != null and companyUserId != ''">
  1357. AND flog.company_user_id = #{companyUserId}
  1358. </if>
  1359. </where>
  1360. </select>
  1361. <select id="countUserAnswer" resultType="Map">
  1362. SELECT
  1363. (
  1364. SELECT
  1365. count(distinct fs_user.user_id )
  1366. FROM
  1367. fs_course_answer_logs
  1368. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1369. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1370. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1371. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1372. <where>
  1373. <if test="userId != null and userId != 0 ">
  1374. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1375. </if>
  1376. <if test="userId != null and userId == 0 ">
  1377. and fs_course_answer_logs.company_id = #{companyId}
  1378. </if>
  1379. <if test="startTime != null and startTime !='' ">
  1380. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1381. </if>
  1382. <if test="endTime != null and endTime != ''">
  1383. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1384. </if>
  1385. <if test="periodId != null and periodId != ''">
  1386. AND fs_course_answer_logs.period_id = #{periodId}
  1387. </if>
  1388. <if test="videoId != null and videoId != ''">
  1389. AND fs_course_answer_logs.video_id = #{videoId}
  1390. </if>
  1391. -- 单独通过销售id查询
  1392. <if test="companyUserId != null and companyUserId != ''">
  1393. AND company_user.user_id = #{companyUserId}
  1394. </if>
  1395. </where>
  1396. ) AS answerNum,
  1397. (
  1398. SELECT
  1399. count(distinct fs_user.user_id )
  1400. FROM
  1401. fs_course_answer_logs
  1402. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1403. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1404. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1405. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1406. <where>
  1407. <if test="userId != null and userId != 0 ">
  1408. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1409. </if>
  1410. <if test="userId != null and userId == 0 ">
  1411. and fs_course_answer_logs.company_id = #{companyId}
  1412. </if>
  1413. AND fs_course_answer_logs.is_right = 1
  1414. <if test="startTime != null and startTime !='' ">
  1415. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1416. </if>
  1417. <if test="endTime != null and endTime != ''">
  1418. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1419. </if>
  1420. <if test="periodId != null and periodId != ''">
  1421. AND fs_course_answer_logs.period_id = #{periodId}
  1422. </if>
  1423. <if test="videoId != null and videoId != ''">
  1424. AND fs_course_answer_logs.video_id = #{videoId}
  1425. </if>
  1426. -- 单独通过销售id查询
  1427. <if test="companyUserId != null and companyUserId != ''">
  1428. AND company_user.user_id = #{companyUserId}
  1429. </if>
  1430. </where>
  1431. ) AS answerRightNum
  1432. </select>
  1433. <!-- <select id="countCourseDetails" resultType="Map">-->
  1434. <!-- select (SELECT-->
  1435. <!-- count( DISTINCT fcpd.period_id )-->
  1436. <!-- FROM-->
  1437. <!-- fs_user_course_period_days fcpd-->
  1438. <!-- LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id-->
  1439. <!-- LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0-->
  1440. <!-- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id-->
  1441. <!-- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id-->
  1442. <!-- WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0-->
  1443. <!-- AND FIND_IN_SET(#{companyId}, fpd.company_id)-->
  1444. <!-- <if test="userId != null and userId != 0 ">-->
  1445. <!-- AND ucu.company_user_id = #{userId}-->
  1446. <!-- </if>-->
  1447. <!-- <if test="userId != null and userId == 0 ">-->
  1448. <!-- and ucu.company_id = #{companyId}-->
  1449. <!-- </if>-->
  1450. <!-- <if test="periodId != null and periodId != ''">-->
  1451. <!-- AND fcpd.period_id = #{periodId}-->
  1452. <!-- </if>-->
  1453. <!-- &#45;&#45; 单独通过销售id查询-->
  1454. <!-- <if test="companyUserId != null and companyUserId != ''">-->
  1455. <!-- AND ucu.company_user_id = #{companyUserId}-->
  1456. <!-- </if>-->
  1457. <!-- ) as courseNum,-->
  1458. <!-- (SELECT count(DISTINCT fcpd.video_id)-->
  1459. <!-- FROM fs_user_course_period_days fcpd-->
  1460. <!-- LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id-->
  1461. <!-- LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0-->
  1462. <!-- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id-->
  1463. <!-- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id-->
  1464. <!-- WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0-->
  1465. <!-- AND FIND_IN_SET(#{companyId}, fpd.company_id)-->
  1466. <!-- <if test="userId != null and userId != 0 ">-->
  1467. <!-- AND ucu.company_user_id = #{userId}-->
  1468. <!-- </if>-->
  1469. <!-- <if test="userId != null and userId == 0 ">-->
  1470. <!-- and ucu.company_id = #{companyId}-->
  1471. <!-- </if>-->
  1472. <!-- <if test="periodId != null and periodId != ''">-->
  1473. <!-- AND fcpd.period_id = #{periodId}-->
  1474. <!-- </if>-->
  1475. <!-- <if test="videoId != null and videoId != ''">-->
  1476. <!-- AND fcpd.video_id = #{videoId}-->
  1477. <!-- </if>-->
  1478. <!-- &#45;&#45; 单独通过销售id查询-->
  1479. <!-- <if test="companyUserId != null and companyUserId != ''">-->
  1480. <!-- AND ucu.company_user_id = #{companyUserId}-->
  1481. <!-- </if>-->
  1482. <!-- ) as videoNum,-->
  1483. <!-- ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc-->
  1484. <!-- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0-->
  1485. <!-- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id-->
  1486. <!-- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id-->
  1487. <!-- <if test="periodId != null and periodId != ''">-->
  1488. <!-- AND fcpd.period_id = #{periodId}-->
  1489. <!-- </if>-->
  1490. <!-- <if test="videoId != null and videoId != ''">-->
  1491. <!-- AND fcpd.video_id = #{videoId}-->
  1492. <!-- </if>-->
  1493. <!-- &#45;&#45; 单独通过销售id查询-->
  1494. <!-- <if test="companyUserId != null and companyUserId != ''">-->
  1495. <!-- AND ucu.company_user_id = #{companyUserId}-->
  1496. <!-- </if>-->
  1497. <!-- <where>-->
  1498. <!-- <if test="userId != null and userId != 0 ">-->
  1499. <!-- AND ucu.company_user_id = #{userId}-->
  1500. <!-- </if>-->
  1501. <!-- <if test="userId != null and userId == 0 ">-->
  1502. <!-- and ucu.company_id = #{companyId}-->
  1503. <!-- </if>-->
  1504. <!-- </where>-->
  1505. <!-- ) as courseUserNum-->
  1506. <!-- </select>-->
  1507. <select id="countUserRankingByComplete" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1508. SELECT
  1509. company_user.nick_name as userName,
  1510. ifnull(
  1511. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  1512. ) as completeRate
  1513. FROM
  1514. fs_user_course_count fcc
  1515. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1516. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1517. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1518. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1519. <where>
  1520. <if test="userId != null and userId != 0 ">
  1521. AND ( ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1522. </if>
  1523. <if test="userId != null and userId == 0 ">
  1524. and ucu.company_id = #{companyId}
  1525. </if>
  1526. <if test="startTime != null and startTime !='' ">
  1527. AND fcc.create_time &gt;= #{startTime}
  1528. </if>
  1529. <if test="endTime != null and endTime != ''">
  1530. AND fcc.create_time &lt;= #{endTime}
  1531. </if>
  1532. <if test="periodId != null and periodId != ''">
  1533. AND fcpd.period_id = #{periodId}
  1534. </if>
  1535. <if test="videoId != null and videoId != ''">
  1536. AND fcpd.video_id = #{videoId}
  1537. </if>
  1538. </where>
  1539. group by fcc.user_id
  1540. <choose>
  1541. <when test="order != null and order == 'asc'">
  1542. order by completeRate asc
  1543. </when>
  1544. <when test="order != null and order == 'desc'">
  1545. order by completeRate desc
  1546. </when>
  1547. <otherwise>
  1548. order by completeRate desc
  1549. </otherwise>
  1550. </choose>
  1551. limit 20
  1552. </select>
  1553. <select id="countUserRankingByRight" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1554. SELECT
  1555. company_user.nick_name as userName,
  1556. ifnull(ROUND(
  1557. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1558. *100,2),0
  1559. ) as answerRightRate
  1560. FROM
  1561. fs_course_answer_logs
  1562. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1563. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1564. <where>
  1565. <if test="userId != null and userId != 0 ">
  1566. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1567. </if>
  1568. <if test="userId != null and userId == 0 ">
  1569. and fs_course_answer_logs.company_id = #{companyId}
  1570. </if>
  1571. <if test="startTime != null and startTime !='' ">
  1572. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1573. </if>
  1574. <if test="endTime != null and endTime != ''">
  1575. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1576. </if>
  1577. <if test="periodId != null and periodId != ''">
  1578. AND fs_course_answer_logs.period_id = #{periodId}
  1579. </if>
  1580. <if test="videoId != null and videoId != ''">
  1581. AND fs_course_answer_logs.video_id = #{videoId}
  1582. </if>
  1583. </where>
  1584. group by fs_user.user_id
  1585. <choose>
  1586. <when test="order != null and order == 'asc'">
  1587. order by answerRightRate asc
  1588. </when>
  1589. <when test="order != null and order == 'desc'">
  1590. order by answerRightRate desc
  1591. </when>
  1592. <otherwise>
  1593. order by answerRightRate desc
  1594. </otherwise>
  1595. </choose>
  1596. limit 20
  1597. </select>
  1598. <select id="countCourseRankingByComplete" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1599. SELECT
  1600. fcv.title AS videoName,
  1601. fcv.video_id,
  1602. ifnull(
  1603. ROUND(
  1604. (
  1605. 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,
  1606. 2
  1607. ),
  1608. 0
  1609. ) AS completeRate
  1610. FROM
  1611. fs_course_watch_log fwl
  1612. LEFT JOIN fs_user ON fs_user.user_id = fwl.user_id
  1613. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1614. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1615. -- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1616. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fwl.video_id
  1617. <where>
  1618. <if test="userId != null and userId != 0 ">
  1619. AND ( fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1620. </if>
  1621. <if test="userId != null and userId == 0 ">
  1622. and fs_user_company_user.company_id = #{companyId}
  1623. </if>
  1624. <if test="startTime != null and startTime !='' ">
  1625. AND fwl.create_time &gt;= #{startTime}
  1626. </if>
  1627. <if test="endTime != null and endTime != ''">
  1628. AND fwl.create_time &lt;= #{endTime}
  1629. </if>
  1630. <if test="periodId != null and periodId != ''">
  1631. AND fwl.period_id = #{periodId}
  1632. </if>
  1633. <if test="videoId != null and videoId != ''">
  1634. AND fwl.video_id = #{videoId}
  1635. </if>
  1636. </where>
  1637. GROUP BY
  1638. fwl.video_id
  1639. <choose>
  1640. <when test="order != null and order == 'asc'">
  1641. ORDER BY completeRate asc
  1642. </when>
  1643. <when test="order != null and order == 'desc'">
  1644. ORDER BY completeRate desc
  1645. </when>
  1646. <otherwise>
  1647. ORDER BY completeRate desc
  1648. </otherwise>
  1649. </choose>
  1650. LIMIT 20
  1651. </select>
  1652. <select id="countCourseRankingByRight" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1653. SELECT
  1654. fcv.title AS videoName,
  1655. ifnull(
  1656. ROUND(
  1657. (
  1658. 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,
  1659. 2
  1660. ),
  1661. 0
  1662. ) AS answerRightRate
  1663. FROM
  1664. fs_course_answer_logs
  1665. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1666. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1667. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1668. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1669. <where>
  1670. <if test="userId != null and userId != 0 ">
  1671. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1672. </if>
  1673. <if test="userId != null and userId == 0 ">
  1674. and fs_course_answer_logs.company_id = #{companyId}
  1675. </if>
  1676. <if test="startTime != null and startTime !='' ">
  1677. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1678. </if>
  1679. <if test="endTime != null and endTime != ''">
  1680. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1681. </if>
  1682. <if test="periodId != null and periodId != ''">
  1683. AND fs_course_answer_logs.period_id = #{periodId}
  1684. </if>
  1685. <if test="videoId != null and videoId != ''">
  1686. AND fs_course_answer_logs.video_id = #{videoId}
  1687. </if>
  1688. </where>
  1689. GROUP BY
  1690. fs_course_answer_logs.video_id
  1691. <choose>
  1692. <when test="order != null and order == 'asc'">
  1693. ORDER BY answerRightRate asc
  1694. </when>
  1695. <when test="order != null and order == 'desc'">
  1696. ORDER BY answerRightRate desc
  1697. </when>
  1698. <otherwise>
  1699. ORDER BY answerRightRate desc
  1700. </otherwise>
  1701. </choose>
  1702. LIMIT 20
  1703. </select>
  1704. <select id="countUserRedPacket" resultType="Map">
  1705. SELECT
  1706. (
  1707. SELECT
  1708. count( flog.log_id )
  1709. FROM
  1710. fs_course_red_packet_log flog
  1711. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1712. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1713. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1714. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1715. where flog.status = 1
  1716. <if test="userId != null and userId != 0 ">
  1717. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1718. </if>
  1719. <if test="userId != null and userId == 0 ">
  1720. and flog.company_id = #{companyId}
  1721. </if>
  1722. <if test="startTime != null and startTime !='' ">
  1723. AND flog.create_time &gt;= #{startTime}
  1724. </if>
  1725. <if test="endTime != null and endTime != ''">
  1726. AND flog.create_time &lt;= #{endTime}
  1727. </if>
  1728. <if test="periodId != null and periodId != ''">
  1729. AND flog.period_id = #{periodId}
  1730. </if>
  1731. <if test="videoId != null and videoId != ''">
  1732. AND flog.video_id = #{videoId}
  1733. </if>
  1734. -- 单独通过销售id查询
  1735. <if test="companyUserId != null and companyUserId != ''">
  1736. AND company_user.user_id = #{companyUserId}
  1737. </if>
  1738. ) AS redPacketNum,
  1739. (
  1740. SELECT
  1741. ifnull (sum( flog.amount ), 0)
  1742. FROM
  1743. fs_course_red_packet_log flog
  1744. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1745. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1746. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1747. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1748. where flog.status = 1
  1749. <if test="userId != null and userId != 0 ">
  1750. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1751. </if>
  1752. <if test="userId != null and userId == 0 ">
  1753. and flog.company_id = #{companyId}
  1754. </if>
  1755. <if test="startTime != null and startTime !='' ">
  1756. AND flog.create_time &gt;= #{startTime}
  1757. </if>
  1758. <if test="endTime != null and endTime != ''">
  1759. AND flog.create_time &lt;= #{endTime}
  1760. </if>
  1761. <if test="periodId != null and periodId != ''">
  1762. AND flog.period_id = #{periodId}
  1763. </if>
  1764. <if test="videoId != null and videoId != ''">
  1765. AND flog.video_id = #{videoId}
  1766. </if>
  1767. -- 单独通过销售id查询
  1768. <if test="companyUserId != null and companyUserId != ''">
  1769. AND company_user.user_id = #{companyUserId}
  1770. </if>
  1771. ) AS redPacketAmount
  1772. </select>
  1773. <select id="courseAnalysisCourseCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  1774. SELECT
  1775. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1776. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1777. ifnull(
  1778. ROUND(
  1779. (
  1780. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1781. 2
  1782. ),
  1783. 0
  1784. ) as completeRate,
  1785. fcpd.video_id
  1786. FROM
  1787. fs_user_course_count fcc
  1788. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1789. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1790. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1791. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1792. <where>
  1793. <if test="companyUserId != null and companyUserId != 0 ">
  1794. AND ucu.company_user_id = #{companyUserId}
  1795. </if>
  1796. <if test="companyUserId != null and companyUserId == 0 ">
  1797. and ucu.company_id = #{companyId}
  1798. </if>
  1799. <if test="periodId != null and periodId != ''">
  1800. AND fcpd.period_id = #{periodId}
  1801. </if>
  1802. <if test="videoId != null and videoId != ''">
  1803. AND fcpd.video_id = #{videoId}
  1804. </if>
  1805. </where>
  1806. GROUP BY
  1807. fcpd.video_id
  1808. </select>
  1809. <select id="companyUserCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1810. SELECT
  1811. (
  1812. 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
  1813. <where>
  1814. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1815. AND ucu.company_user_id = #{companyUserId}
  1816. </if>
  1817. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1818. and ucu.company_id = #{companyId}
  1819. </if>
  1820. </where>
  1821. ) AS userTotal,
  1822. (
  1823. SELECT
  1824. count( fs_user.user_id )
  1825. FROM
  1826. fs_user
  1827. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1828. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1829. <where>
  1830. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1831. AND ucu.company_user_id = #{companyUserId}
  1832. </if>
  1833. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1834. and ucu.company_id = #{companyId}
  1835. </if>
  1836. and fs_user.is_del = 0
  1837. AND to_days( fs_user.create_time ) = to_days(
  1838. now())
  1839. </where>
  1840. ) AS todayNewUser
  1841. </select>
  1842. <select id="newUserRedPacketCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1843. SELECT
  1844. count(flog.log_id) as userRedPacketNum,
  1845. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1846. FROM
  1847. fs_course_red_packet_log flog
  1848. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1849. <where>
  1850. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1851. AND flog.company_user_id = #{companyUserId}
  1852. </if>
  1853. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1854. and flog.company_id = #{companyId}
  1855. </if>
  1856. </where>
  1857. </select>
  1858. <select id="countUserCourse2" resultType="java.util.Map">
  1859. SELECT
  1860. (
  1861. SELECT
  1862. count(DISTINCT l.user_id)
  1863. FROM
  1864. fs_course_watch_log l
  1865. LEFT JOIN fs_user on fs_user.user_id = l.user_id
  1866. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1867. 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
  1868. where
  1869. l.log_type != 3 and send_type = 1
  1870. <if test="userId != null and userId != 0 ">
  1871. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1872. </if>
  1873. <if test="userId != null and userId == 0 ">
  1874. and l.company_id = #{companyId}
  1875. </if>
  1876. <if test="periodId != null and periodId != ''">
  1877. AND l.period_id = #{periodId}
  1878. </if>
  1879. <if test="videoId != null and videoId != ''">
  1880. AND l.video_id = #{videoId}
  1881. </if>
  1882. <if test="startTime != null and startTime !='' ">
  1883. and l.create_time &gt;= #{startTime}
  1884. </if>
  1885. <if test="endTime != null and endTime != ''">
  1886. and l.create_time &lt;= #{endTime}
  1887. </if> <if test="companyUserId != null and companyUserId != ''">
  1888. AND l.user_id = #{companyUserId}
  1889. </if>
  1890. -- 单独通过销售id查询
  1891. <if test="companyUserId != null and companyUserId != ''">
  1892. AND l.company_user_id = #{companyUserId}
  1893. </if>
  1894. ) as courseWatchNum,
  1895. (
  1896. SELECT
  1897. count(DISTINCT l.user_id)
  1898. FROM
  1899. fs_course_watch_log l
  1900. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1901. LEFT JOIN fs_user ON fs_user.user_id = l.user_id
  1902. 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
  1903. where
  1904. l.log_type = 2 and send_type = 1
  1905. <if test="userId != null and userId != 0 ">
  1906. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1907. </if>
  1908. <if test="userId != null and userId == 0 ">
  1909. and l.company_id = #{companyId}
  1910. </if>
  1911. <if test="periodId != null and periodId != ''">
  1912. AND l.period_id = #{periodId}
  1913. </if>
  1914. <if test="videoId != null and videoId != ''">
  1915. AND l.video_id = #{videoId}
  1916. </if>
  1917. <if test="startTime != null and startTime !='' ">
  1918. and l.create_time &gt;= #{startTime}
  1919. </if>
  1920. <if test="endTime != null and endTime != ''">
  1921. and l.create_time &lt;= #{endTime}
  1922. </if>
  1923. -- 单独通过销售id查询
  1924. <if test="companyUserId != null and companyUserId != ''">
  1925. AND l.company_user_id = #{companyUserId}
  1926. </if>
  1927. ) as courseCompleteNum
  1928. </select>
  1929. <select id="countCourseDetailsNew" resultType="Map">
  1930. SELECT
  1931. count( DISTINCT l.period_id ) as courseNum,
  1932. count( DISTINCT l.video_id ) as videoNum,
  1933. count( DISTINCT l.user_id ) as courseUserNum
  1934. FROM
  1935. fs_course_watch_log l
  1936. left join fs_user on fs_user.user_id = l.user_id
  1937. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1938. WHERE
  1939. l.log_type != 3
  1940. AND send_type = 1
  1941. <if test="userId != null and userId != 0 ">
  1942. AND l.company_user_id = #{userId}
  1943. </if>
  1944. <if test="userId != null and userId == 0 ">
  1945. and l.company_id = #{companyId}
  1946. </if>
  1947. <if test="periodId != null and periodId != ''">
  1948. AND l.period_id = #{periodId}
  1949. </if>
  1950. <if test="videoId != null and videoId != ''">
  1951. AND l.video_id = #{videoId}
  1952. </if>
  1953. -- 单独通过销售id查询
  1954. <if test="companyUserId != null and companyUserId != ''">
  1955. AND l.company_user_id = #{companyUserId}
  1956. </if>
  1957. </select>
  1958. <select id="selectFsUserVOListByProjectNew" resultType="com.fs.his.vo.FsUserVO">
  1959. SELECT
  1960. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  1961. ucu.project_id,ucu.id as companyUserId,ucu.create_time as bindTime,ucu.status,
  1962. company.company_name,
  1963. cu.nick_name companyUserNickName
  1964. FROM
  1965. fs_user_company_user ucu
  1966. left join
  1967. fs_user u on ucu.user_id = u.user_id
  1968. left join
  1969. company on company.company_id = ucu.company_id
  1970. left join
  1971. company_user cu on cu.user_id = ucu.company_user_id
  1972. <where>
  1973. 1 = 1 and u.nick_name is not null
  1974. and u.is_del = 0
  1975. <if test = "maps.nickname != null and maps.nickname !='' " >
  1976. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  1977. </if >
  1978. <if test = "maps.nicknameExact != null and maps.nicknameExact !='' " >
  1979. AND u.nick_name = #{maps.nicknameExact}
  1980. </if >
  1981. <if test = "maps.userId != null and maps.userId !='' " >
  1982. AND u.user_id = #{maps.userId}
  1983. </if >
  1984. <if test = "maps.phone != null and maps.phone !='' " >
  1985. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  1986. </if >
  1987. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  1988. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  1989. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  1990. )
  1991. </if >
  1992. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  1993. AND u.register_code = #{maps.registerCode}
  1994. </if >
  1995. <if test = "maps.status != null" >
  1996. AND ucu.status = #{maps.status}
  1997. </if >
  1998. <if test = "maps.companyId != null and maps.companyId != '' " >
  1999. AND ucu.company_id = #{maps.companyId}
  2000. </if >
  2001. <if test = "maps.companyUserId != null" >
  2002. AND ucu.company_user_id = #{maps.companyUserId}
  2003. </if >
  2004. <if test = "maps.projectId != null" >
  2005. AND ucu.project_id = #{maps.projectId}
  2006. </if >
  2007. <if test = "maps.companyUserIds != null and maps.companyUserIds.length > 0 " >
  2008. AND ucu.company_user_id in
  2009. <foreach collection="maps.companyUserIds" item="item" open="(" close=")" separator=",">
  2010. #{item}
  2011. </foreach>
  2012. </if >
  2013. </where>
  2014. ORDER BY
  2015. user_id DESC
  2016. </select>
  2017. <select id="selectFsUserVOListByProject" resultType="com.fs.his.vo.FsUserVO">
  2018. SELECT distinct
  2019. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  2020. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  2021. fcc.watch_course_count, fcc.part_course_count, company_user.nick_name AS companyUserNickName, fcc.last_watch_date
  2022. ,company.company_name,
  2023. ucu.project_id,
  2024. ucu.id as companyUserId,
  2025. ucu.create_time as bindTime,
  2026. ucu.status
  2027. FROM
  2028. fs_user u
  2029. LEFT JOIN (
  2030. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  2031. user_id
  2032. FROM
  2033. fs_store_payment
  2034. WHERE
  2035. STATUS = 1
  2036. AND user_id IS NOT NULL
  2037. GROUP BY
  2038. user_id
  2039. ) b ON u.user_id = b.user_id
  2040. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  2041. AND b.last_buy_time = p.pay_time
  2042. AND b.payment_id = p.payment_id
  2043. LEFT JOIN (
  2044. SELECT
  2045. 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,
  2046. fs_user_course_count.part_course_count
  2047. FROM
  2048. fs_user_course_count
  2049. GROUP BY fs_user_course_count.user_id
  2050. ) fcc ON fcc.user_id = u.user_id
  2051. inner join fs_user_company_user ucu on ucu.user_id = u.user_id
  2052. LEFT JOIN company_user ON company_user.user_id = ucu.company_user_id
  2053. LEFT JOIN company on company.company_id = company_user.company_id
  2054. <where>
  2055. 1 = 1 and u.nick_name is not null
  2056. and u.is_del = 0
  2057. <if test = "maps.nickname != null and maps.nickname !='' " >
  2058. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  2059. </if >
  2060. <if test = "maps.userId != null and maps.userId !='' " >
  2061. AND u.user_id = #{maps.userId}
  2062. </if >
  2063. <if test = "maps.phone != null and maps.phone !='' " >
  2064. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  2065. </if >
  2066. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  2067. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  2068. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  2069. )
  2070. </if >
  2071. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  2072. AND u.register_code = #{maps.registerCode}
  2073. </if >
  2074. <if test = "maps.status != null" >
  2075. AND ucu.status = #{maps.status}
  2076. </if >
  2077. <if test = "maps.companyId != null and maps.companyId != '' " >
  2078. AND company.company_id = #{maps.companyId}
  2079. </if >
  2080. <if test = "maps.companyUserId != null" >
  2081. AND company_user.user_id = #{maps.companyUserId}
  2082. </if >
  2083. <if test = "maps.projectId != null" >
  2084. AND ucu.project_id = #{maps.projectId}
  2085. </if >
  2086. </where>
  2087. ORDER BY
  2088. user_id DESC
  2089. </select>
  2090. <select id="selectCompanyAndDoctor" resultType="com.fs.watch.domain.vo.FsUserAndCompanyAndDoctorVo">
  2091. SELECT
  2092. f.*,
  2093. GROUP_CONCAT(c.company_id SEPARATOR ',') AS company_id,
  2094. GROUP_CONCAT(c.company_user_id SEPARATOR ',') AS company_user_id,
  2095. GROUP_CONCAT(o.doctor_id SEPARATOR ',') AS doctor_id
  2096. FROM
  2097. fs_user f
  2098. LEFT JOIN
  2099. company_user_user c ON c.user_id = f.user_id
  2100. LEFT JOIN
  2101. fs_inquiry_order o ON o.user_id = f.user_id AND o.`status` = 4
  2102. WHERE
  2103. f.is_del = 0 AND f.user_id = #{userId}
  2104. GROUP BY
  2105. f.user_id;
  2106. </select>
  2107. <select id="selectUserNameByIds" resultMap="FsUserResult">
  2108. select user_id,nick_name from fs_user where user_id in
  2109. <foreach collection="userIds.split(',')" item="userId" open="(" close=")" separator=",">
  2110. #{userId}
  2111. </foreach>
  2112. </select>
  2113. <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
  2114. SELECT
  2115. count( DISTINCT fs_user.user_id ) as userNum,
  2116. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  2117. fs_user_company_user.company_id
  2118. FROM
  2119. fs_user
  2120. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  2121. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2122. WHERE
  2123. fs_user.is_del = 0
  2124. AND fs_user.`status` = 1
  2125. AND fs_user_company_user.`status` = 1
  2126. AND company_user.user_id IS NOT NULL
  2127. GROUP BY
  2128. fs_user_company_user.company_id
  2129. </select>
  2130. <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
  2131. SELECT
  2132. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  2133. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  2134. ifnull(
  2135. ROUND(
  2136. (
  2137. 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,
  2138. 2
  2139. ),
  2140. 0
  2141. ) AS completeWatchRate,
  2142. fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
  2143. FROM
  2144. fs_course_watch_log fwl
  2145. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fwl.user_id
  2146. WHERE
  2147. fwl.send_type = 1
  2148. AND fs_user_company_user.`status` = 1
  2149. GROUP BY
  2150. fwl.period_id, fwl.video_id, fwl.company_user_id
  2151. </select>
  2152. <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
  2153. SELECT
  2154. count(DISTINCT flog.log_id ) AS redPacketNum,
  2155. ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
  2156. flog.period_id,
  2157. flog.video_id,
  2158. flog.company_user_id,
  2159. flog.company_id
  2160. FROM
  2161. fs_course_red_packet_log flog
  2162. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = flog.user_id
  2163. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2164. where flog.`status` = 1
  2165. AND fs_user_company_user.`status` = 1
  2166. GROUP BY
  2167. flog.period_id,
  2168. flog.video_id,
  2169. flog.company_user_id
  2170. </select>
  2171. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  2172. SELECT
  2173. count( DISTINCT fs_user_company_user.user_id ) AS answerNum,
  2174. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user_company_user.user_id END ) AS answerRightNum,
  2175. ifnull(
  2176. ROUND(
  2177. (
  2178. 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,
  2179. 2
  2180. ),
  2181. 0
  2182. ) AS answerRightRate,
  2183. fs_course_answer_logs.period_id,
  2184. fs_course_answer_logs.video_id,
  2185. fs_course_answer_logs.company_user_id,
  2186. fs_course_answer_logs.company_id
  2187. FROM
  2188. fs_course_answer_logs
  2189. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_course_answer_logs.user_id
  2190. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2191. where fs_user_company_user.`status` = 1
  2192. GROUP BY
  2193. fs_course_answer_logs.period_id,
  2194. fs_course_answer_logs.video_id,
  2195. fs_course_answer_logs.company_user_id
  2196. </select>
  2197. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  2198. SELECT
  2199. count(DISTINCT fs_user.user_id ) as userNum,
  2200. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  2201. date(fs_user.create_time) as userCreateDate
  2202. ,company.company_id,
  2203. company.company_name,
  2204. company_user.user_id AS companyUserId,
  2205. company_user.nick_name AS companyUserName
  2206. FROM
  2207. fs_user
  2208. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  2209. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2210. LEFT JOIN company ON company.company_id = fs_user_company_user.company_id
  2211. WHERE
  2212. fs_user.is_del = 0
  2213. AND fs_user_company_user.`status` = 1
  2214. AND fs_user.`status` = 1
  2215. AND company_user.user_id is not null
  2216. GROUP BY
  2217. fs_user_company_user.company_user_id, date(fs_user.create_time)
  2218. </select>
  2219. <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
  2220. <include refid="selectFsUserVo"/>
  2221. <where>
  2222. <if test="userName != null and userName != ''">
  2223. AND (
  2224. nickname like concat('%', #{userName}, '%')
  2225. or user_id LIKE concat('%',#{userName},'%')
  2226. )
  2227. </if>
  2228. </where>
  2229. order by user_id desc
  2230. </select>
  2231. <select id="selectFsUserCount" resultType="java.lang.Long">
  2232. select count(1) from fs_user
  2233. where 1=1
  2234. <if test = "type != null and type ==1">
  2235. and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
  2236. </if>
  2237. <if test = "companyId != null">
  2238. and company_id=#{companyId}
  2239. </if>
  2240. <if test="companyUserId != null">
  2241. and company_user_id = #{companyUserId}
  2242. </if>
  2243. </select>
  2244. <select id="selectFsUserListLimit" resultMap="FsUserResult">
  2245. <include refid="selectFsUserVo"/>
  2246. <where>
  2247. <if test="password != null and password != ''">and password = #{password}</if>
  2248. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  2249. <if test="birthday != null ">and birthday = #{birthday}</if>
  2250. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  2251. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  2252. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  2253. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  2254. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  2255. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  2256. <if test="integral != null ">and integral = #{integral}</if>
  2257. <if test="signNum != null ">and sign_num = #{signNum}</if>
  2258. <if test="status != null ">and status = #{status}</if>
  2259. <if test="level != null ">and level = #{level}</if>
  2260. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  2261. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  2262. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  2263. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  2264. <if test="payCount != null ">and pay_count = #{payCount}</if>
  2265. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  2266. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  2267. <if test="isDel != null ">and is_del = #{isDel}</if>
  2268. <if test="companyId != null ">and company_id = #{companyId}</if>
  2269. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  2270. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  2271. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  2272. </if>
  2273. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  2274. <if test="source != null and source != '' ">and source = #{source}</if>
  2275. <if test="isShow != null ">and is_show = #{isShow}</if>
  2276. <if test="(username != null and username != '') or (userId != null and userId != '') or (nickname != null and nickname != '') or (phone != null and phone != '')">
  2277. and (
  2278. <if test="username != null and username != ''">username like concat('%', #{username}, '%')</if>
  2279. <if test="userId != null and userId != ''">or user_id = #{userId}</if>
  2280. <if test="nickname != null and nickname != ''">or nickname like concat('%', #{nickname}, '%')</if>
  2281. <if test="phone != null and phone != ''">or phone like concat('%',#{phone},'%')</if>
  2282. )
  2283. </if>
  2284. <if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  2285. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>
  2286. <if test="payOrder != null ">and pay_order = #{payOrder}</if>
  2287. </where>
  2288. order by user_id desc
  2289. limit 10
  2290. </select>
  2291. <select id="findUsersByParam" resultType="com.fs.his.dto.FindUsersByDTO">
  2292. SELECT user_id as id, 0 as type,
  2293. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2294. FROM fs_user
  2295. WHERE user_id = #{keywords}
  2296. UNION
  2297. <!-- fs_user 按nick_name前缀搜索 -->
  2298. SELECT user_id as id, 0 as type,
  2299. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2300. FROM fs_user
  2301. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2302. UNION
  2303. <!-- fs_user 按phone精确搜索(仅当keywords是数字时) -->
  2304. <if test="keywords.matches('\\d+')">
  2305. SELECT user_id as id, 0 as type,
  2306. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2307. FROM fs_user
  2308. WHERE phone = #{keywords}
  2309. UNION
  2310. </if>
  2311. <!-- company_user相关查询 -->
  2312. SELECT user_id as id, 1 as type,
  2313. IFNULL(nick_name, '') as name
  2314. FROM company_user
  2315. WHERE user_id = #{keywords}
  2316. UNION
  2317. SELECT user_id as id, 1 as type,
  2318. IFNULL(nick_name, '') as name
  2319. FROM company_user
  2320. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2321. <if test="keywords.matches('\\d+')">
  2322. UNION
  2323. SELECT user_id as id, 1 as type,
  2324. IFNULL(nick_name, '') as name
  2325. FROM company_user
  2326. WHERE phonenumber = #{keywords}
  2327. </if>
  2328. </select>
  2329. <select id="countExternalRedPacketStats" resultType="com.fs.store.vo.h5.ExternalRedPacketStatsVO">
  2330. SELECT
  2331. COUNT(red.log_id) AS redPacketNum,
  2332. COALESCE(SUM(red.amount), 0) AS redPacketAmount
  2333. FROM fs_course_red_packet_log log
  2334. WHERE log.status = 1
  2335. AND log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2336. <if test="startTime != null and startTime != ''">
  2337. AND log.create_time &gt;= #{startTime}
  2338. </if>
  2339. <if test="endTime != null and endTime != ''">
  2340. AND log.create_time &lt;= #{endTime}
  2341. </if>
  2342. </select>
  2343. <select id="countExternalAnswerStats" resultType="com.fs.store.vo.h5.ExternalAnswerStatsVO">
  2344. SELECT
  2345. COUNT(*) AS answerNum,
  2346. SUM(CASE WHEN is_right = 1 THEN 1 ELSE 0 END) AS answerRightNum
  2347. FROM fs_course_answer_logs log
  2348. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2349. <if test="startTime != null and startTime != ''">
  2350. AND log.create_time &gt;= #{startTime}
  2351. </if>
  2352. <if test="endTime != null and endTime != ''">
  2353. AND log.create_time &lt;= #{endTime}
  2354. </if>
  2355. </select>
  2356. <select id="countExternalWatchStats" resultType="com.fs.store.vo.h5.ExternalWatchStatsVO">
  2357. SELECT
  2358. COUNT(CASE WHEN log_type != 3 THEN 1 END) AS courseWatchNum,
  2359. COUNT(CASE WHEN log_type = 2 THEN 1 END) AS courseCompleteNum
  2360. FROM fs_course_watch_log log
  2361. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2362. <if test="startTime != null and startTime != ''">
  2363. AND log.create_time &gt;= #{startTime}
  2364. </if>
  2365. <if test="endTime != null and endTime != ''">
  2366. AND log.create_time &lt;= #{endTime}
  2367. </if>
  2368. </select>
  2369. <select id="selectFsUserListByPhone" resultType="com.fs.his.domain.FsUser">
  2370. select * from fs_user where phone=#{phone}
  2371. </select>
  2372. <!-- 查询用户列表(用于积分管理) -->
  2373. <select id="selectFsUserListForIntegral" parameterType="FsUser" resultMap="FsUserResult">
  2374. select user_id, nick_name, phone, integral from fs_user
  2375. <where>
  2376. and is_del = 0
  2377. <if test="phone != null and phone != ''">
  2378. and phone like concat('%', #{phone}, '%')
  2379. </if>
  2380. <if test="nickName != null and nickName != ''">
  2381. and (nick_name like concat('%', #{nickName}, '%') or nickname like concat('%', #{nickName}, '%'))
  2382. </if>
  2383. </where>
  2384. order by user_id desc
  2385. </select>
  2386. </mapper>