FsUserMapper.xml 81 KB

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