FsUserMapper.xml 109 KB

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