FsUserMapper.xml 115 KB

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