FsUserMapper.xml 101 KB

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