FsUserMapper.xml 105 KB

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