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