FsUserMapper.xml 94 KB

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