FsUserMapper.xml 104 KB

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