FsUserMapper.xml 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553
  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 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. from
  201. fs_user `user` join (
  202. select user_id from fs_user
  203. <where>
  204. <if test="companyId != null and companyId != ''">
  205. AND company_id = #{companyId}
  206. </if>
  207. <if test="companyUserId != null and companyUserId != ''">
  208. AND company_user_id = #{companyUserId}
  209. </if>
  210. <if test="phone != null and phone != ''">
  211. AND phone = #{phone}
  212. </if>
  213. </where>
  214. order by user_id desc
  215. limit ${(pageNum-1)*pageSize},${pageSize}
  216. ) t on t.user_id = `user`.user_id
  217. </select>
  218. <select id="selectCusListPageCount" resultType="java.lang.Long">
  219. SELECT COUNT(user_id)
  220. FROM fs_user
  221. <where>
  222. <if test="companyId != null and companyId != ''">
  223. AND company_id = #{companyId}
  224. </if>
  225. <if test="companyUserId != null and companyUserId != ''">
  226. AND company_user_id = #{companyUserId}
  227. </if>
  228. <if test="phone != null and phone != ''">
  229. AND phone = #{phone}
  230. </if>
  231. </where>
  232. </select>
  233. <select id="selectFsUserVOList" resultType="com.fs.store.vo.FSUserVO">
  234. SELECT
  235. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  236. u.*,
  237. fcc.watch_course_count, fcc.part_course_count, company_user.nick_name AS companyUserNickName, fcc.last_watch_date
  238. ,company.company_name
  239. FROM
  240. fs_user u
  241. LEFT JOIN (
  242. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  243. user_id
  244. FROM
  245. fs_store_payment
  246. WHERE
  247. STATUS = 1
  248. AND user_id IS NOT NULL
  249. GROUP BY
  250. user_id
  251. ) b ON u.user_id = b.user_id
  252. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  253. AND b.last_buy_time = p.pay_time
  254. AND b.payment_id = p.payment_id
  255. LEFT JOIN (
  256. SELECT
  257. 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,
  258. fs_user_course_count.part_course_count
  259. FROM
  260. fs_user_course_count
  261. GROUP BY fs_user_course_count.user_id
  262. ) fcc ON fcc.user_id = u.user_id
  263. LEFT JOIN company_user ON company_user.user_id = u.company_user_id
  264. LEFT JOIN company on company.company_id = company_user.company_id
  265. <where>
  266. 1 = 1
  267. <if test = "maps.nickname != null and maps.nickname !='' " >
  268. AND u.nickname LIKE CONCAT("%",#{maps.nickname},"%")
  269. </if >
  270. <if test = "maps.phone != null and maps.phone !='' " >
  271. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  272. </if >
  273. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  274. AND (DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  275. and DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  276. )
  277. </if >
  278. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  279. AND u.register_code = #{maps.registerCode}
  280. </if >
  281. <if test = "maps.status != null" >
  282. AND u.STATUS = #{maps.status}
  283. </if >
  284. <if test = "maps.companyUserNickName != null and maps.companyUserNickName != '' " >
  285. AND company_user.nick_name like CONCAT ("%",#{maps.companyUserNickName},"%")
  286. </if >
  287. <if test = "maps.companyName != null and maps.companyName != '' " >
  288. AND company.company_name like CONCAT ("%",#{maps.companyName},"%")
  289. </if >
  290. <if test = "maps.level != null and maps.level !=''" >
  291. AND u.LEVEL = #{maps.level}
  292. </if >
  293. <if test = "maps.isPromoter != null and maps.isPromoter !=''" >
  294. AND u.is_promoter = #{maps.isPromoter}
  295. </if >
  296. </where>
  297. ORDER BY
  298. user_id DESC
  299. </select>
  300. <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
  301. insert into fs_user
  302. <trim prefix="(" suffix=")" suffixOverrides=",">
  303. <if test="username != null">username,</if>
  304. <if test="password != null">password,</if>
  305. <if test="realName != null">real_name,</if>
  306. <if test="birthday != null">birthday,</if>
  307. <if test="idCard != null">id_card,</if>
  308. <if test="remark != null">remark,</if>
  309. <if test="nickname != null">nickname,</if>
  310. <if test="avatar != null">avatar,</if>
  311. <if test="phone != null">phone,</if>
  312. <if test="createTime != null">create_time,</if>
  313. <if test="updateTime != null">update_time,</if>
  314. <if test="lastIp != null">last_ip,</if>
  315. <if test="nowMoney != null">now_money,</if>
  316. <if test="brokeragePrice != null">brokerage_price,</if>
  317. <if test="integral != null">integral,</if>
  318. <if test="signNum != null">sign_num,</if>
  319. <if test="status != null">status,</if>
  320. <if test="level != null">level,</if>
  321. <if test="spreadUserId != null">spread_user_id,</if>
  322. <if test="spreadTime != null">spread_time,</if>
  323. <if test="userType != null and userType != ''">user_type,</if>
  324. <if test="isPromoter != null">is_promoter,</if>
  325. <if test="payCount != null">pay_count,</if>
  326. <if test="spreadCount != null">spread_count,</if>
  327. <if test="addres != null and addres != ''">addres,</if>
  328. <if test="maOpenId != null">ma_open_id,</if>
  329. <if test="mpOpenId != null">mp_open_id,</if>
  330. <if test="unionId != null">union_id,</if>
  331. <if test="isDel != null">is_del,</if>
  332. <if test="isWeixinAuth != null">is_weixin_auth,</if>
  333. <if test="companyId != null">company_id,</if>
  334. <if test="companyUserId != null">company_user_id,</if>
  335. <if test="registerDate != null">register_date,</if>
  336. <if test="registerCode != null">register_code,</if>
  337. <if test="source != null">source,</if>
  338. <if test="userCode != null">user_code,</if>
  339. <if test="isShow != null">is_show,</if>
  340. <if test="qwExtId != null">qw_ext_id,</if>
  341. <if test="isAddQw != null">is_add_qw,</if>
  342. <if test="qwRepeat != null">qw_repeat,</if>
  343. <if test="userRepeat != null">user_repeat,</if>
  344. <if test="payOrder != null">pay_order,</if>
  345. </trim>
  346. <trim prefix="values (" suffix=")" suffixOverrides=",">
  347. <if test="username != null">#{username},</if>
  348. <if test="password != null">#{password},</if>
  349. <if test="realName != null">#{realName},</if>
  350. <if test="birthday != null">#{birthday},</if>
  351. <if test="idCard != null">#{idCard},</if>
  352. <if test="remark != null">#{remark},</if>
  353. <if test="nickname != null">#{nickname},</if>
  354. <if test="avatar != null">#{avatar},</if>
  355. <if test="phone != null">#{phone},</if>
  356. <if test="createTime != null">#{createTime},</if>
  357. <if test="updateTime != null">#{updateTime},</if>
  358. <if test="lastIp != null">#{lastIp},</if>
  359. <if test="nowMoney != null">#{nowMoney},</if>
  360. <if test="brokeragePrice != null">#{brokeragePrice},</if>
  361. <if test="integral != null">#{integral},</if>
  362. <if test="signNum != null">#{signNum},</if>
  363. <if test="status != null">#{status},</if>
  364. <if test="level != null">#{level},</if>
  365. <if test="spreadUserId != null">#{spreadUserId},</if>
  366. <if test="spreadTime != null">#{spreadTime},</if>
  367. <if test="userType != null and userType != ''">#{userType},</if>
  368. <if test="isPromoter != null">#{isPromoter},</if>
  369. <if test="payCount != null">#{payCount},</if>
  370. <if test="spreadCount != null">#{spreadCount},</if>
  371. <if test="addres != null and addres != ''">#{addres},</if>
  372. <if test="maOpenId != null">#{maOpenId},</if>
  373. <if test="mpOpenId != null">#{mpOpenId},</if>
  374. <if test="unionId != null">#{unionId},</if>
  375. <if test="isDel != null">#{isDel},</if>
  376. <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
  377. <if test="companyId != null">#{companyId},</if>
  378. <if test="companyUserId != null">#{companyUserId},</if>
  379. <if test="registerDate != null">#{registerDate},</if>
  380. <if test="registerCode != null">#{registerCode},</if>
  381. <if test="source != null">#{source},</if>
  382. <if test="userCode != null">#{userCode},</if>
  383. <if test="isShow != null">#{isShow},</if>
  384. <if test="qwExtId != null">#{qwExtId},</if>
  385. <if test="isAddQw != null">#{isAddQw},</if>
  386. <if test="qwRepeat != null">#{qwRepeat},</if>
  387. <if test="userRepeat != null">#{userRepeat},</if>
  388. <if test="payOrder != null">#{payOrder},</if>
  389. </trim>
  390. </insert>
  391. <update id="updateFsUser" parameterType="FsUser">
  392. update fs_user
  393. <trim prefix="SET" suffixOverrides=",">
  394. <if test="username != null">username = #{username},</if>
  395. <if test="password != null">password = #{password},</if>
  396. <if test="realName != null">real_name = #{realName},</if>
  397. <if test="birthday != null">birthday = #{birthday},</if>
  398. <if test="idCard != null">id_card = #{idCard},</if>
  399. <if test="remark != null">remark = #{remark},</if>
  400. <if test="nickname != null">nickname = #{nickname},</if>
  401. <if test="avatar != null">avatar = #{avatar},</if>
  402. <if test="phone != null">phone = #{phone},</if>
  403. <if test="createTime != null">create_time = #{createTime},</if>
  404. <if test="updateTime != null">update_time = #{updateTime},</if>
  405. <if test="lastIp != null">last_ip = #{lastIp},</if>
  406. <if test="nowMoney != null">now_money = #{nowMoney},</if>
  407. <if test="brokeragePrice != null">brokerage_price = #{brokeragePrice},</if>
  408. <if test="integral != null">integral = #{integral},</if>
  409. <if test="signNum != null">sign_num = #{signNum},</if>
  410. <if test="status != null">status = #{status},</if>
  411. <if test="level != null">level = #{level},</if>
  412. <if test="spreadUserId != null">spread_user_id = #{spreadUserId},</if>
  413. <if test="spreadTime != null">spread_time = #{spreadTime},</if>
  414. <if test="userType != null and userType != ''">user_type = #{userType},</if>
  415. <if test="isPromoter != null">is_promoter = #{isPromoter},</if>
  416. <if test="payCount != null">pay_count = #{payCount},</if>
  417. <if test="spreadCount != null">spread_count = #{spreadCount},</if>
  418. <if test="addres != null and addres != ''">addres = #{addres},</if>
  419. <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
  420. <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
  421. <if test="unionId != null">union_id = #{unionId},</if>
  422. <if test="isDel != null">is_del = #{isDel},</if>
  423. <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
  424. <if test="companyId != null">company_id = #{companyId},</if>
  425. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  426. <if test="registerDate != null">register_date = #{registerDate},</if>
  427. <if test="registerCode != null">register_code = #{registerCode},</if>
  428. <if test="source != null">source = #{source},</if>
  429. <if test="userCode != null">user_code = #{userCode},</if>
  430. <if test="isShow != null">is_show = #{isShow},</if>
  431. <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
  432. <if test="isAddQw != null">is_add_qw = #{isAddQw},</if>
  433. <if test="qwRepeat != null">qw_repeat = #{qwRepeat},</if>
  434. <if test="userRepeat != null">user_repeat = #{userRepeat},</if>
  435. <if test="payOrder != null">pay_order = #{payOrder},</if>
  436. </trim>
  437. where user_id = #{userId}
  438. </update>
  439. <update id="transferCompanyUser">
  440. update fs_user
  441. set company_user_id=#{targetCompanyUserId}
  442. where
  443. user_id in
  444. <foreach collection="userIds" open="(" close=")" separator="," item="item">
  445. ${item}
  446. </foreach>
  447. </update>
  448. <delete id="deleteFsUserById" parameterType="Long">
  449. delete
  450. from fs_user
  451. where user_id = #{userId}
  452. </delete>
  453. <delete id="deleteFsUserByIds" parameterType="String">
  454. delete from fs_user where user_id in
  455. <foreach item="userId" collection="array" open="(" separator="," close=")">
  456. #{userId}
  457. </foreach>
  458. </delete>
  459. <select id="selectFsUserPageListNew" resultType="FsUserPageListVO">
  460. SELECT
  461. fs_user.user_id,
  462. fs_user.nickname,
  463. fs_user.avatar,
  464. fs_user.phone,
  465. fs_user.status,
  466. fs_user.create_time,
  467. fs_user.remark,
  468. fs_user.company_user_id,
  469. fs_user.company_id
  470. FROM
  471. fs_user
  472. <where>
  473. fs_user.is_del = 0
  474. <if test="registerStartTime != null and registerStartTime !='' ">
  475. AND fs_user.create_time &gt;= #{registerStartTime}
  476. </if>
  477. <if test="registerEndTime != null and registerEndTime !='' ">
  478. AND fs_user.create_time &lt;= #{registerEndTime}
  479. </if>
  480. <if test="companyUserIds != null and companyUserIds.size > 0">
  481. AND fs_user.company_user_id in
  482. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  483. ${item}
  484. </foreach>
  485. </if>
  486. <if test="nickname != null and nickname != ''">
  487. AND fs_user.nickname like concat(#{nickname},'%')
  488. </if>
  489. <if test="phone != null and phone != ''">
  490. AND fs_user.phone = #{phone}
  491. </if>
  492. </where>
  493. limit ${(pageNum-1)*pageSize},${pageSize}
  494. </select>
  495. <select id="selectFsUserPageList" resultType="FsUserPageListVO">
  496. SELECT
  497. fs_user.*,
  498. fs_user_course_count.id,
  499. fs_user_course_count.watch_course_count,
  500. fs_user_course_count.miss_course_count,
  501. fs_user_course_count.miss_course_status,
  502. fs_user_course_count.course_ids,
  503. fs_user_course_count.part_course_count,
  504. fs_user_course_count.last_watch_date,
  505. fs_user_course_count.STATUS AS courseCountStatus,
  506. fs_user_course_count.stop_watch_days,
  507. fs_user_course_count.complete_watch_date,
  508. GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
  509. GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
  510. company_user.nick_name as companyUserNickName,
  511. fs_user_company_user.is_repeat_fans
  512. FROM
  513. fs_user
  514. LEFT JOIN fs_user_course_count ON fs_user.user_id = fs_user_course_count.user_id
  515. LEFT JOIN company_tag_user ON fs_user.user_id = company_tag_user.user_id
  516. LEFT JOIN company_tag ON FIND_IN_SET(company_tag.tag_id, company_tag_user.tag_ids) > 0
  517. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  518. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  519. where fs_user.is_del = 0
  520. <if test="userId != null and userId !='' ">
  521. and (company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  522. </if>
  523. <if test="companyUserId != null and companyUserId !='' ">
  524. and company_user.user_id = #{companyUserId}
  525. </if>
  526. <choose>
  527. <when test = "isBlack">
  528. AND (fs_user.status = 0 or fs_user_company_user.is_repeat_fans = 1)
  529. </when>
  530. <otherwise>
  531. AND (fs_user.status = 1 and fs_user_company_user.is_repeat_fans = 0)
  532. </otherwise>
  533. </choose>
  534. <if test="keyword != null and keyword !='' ">
  535. AND (fs_user.nickname LIKE concat('%',#{keyword},'%')
  536. or fs_user.phone LIKE concat('%',#{keyword},'%')
  537. )
  538. </if>
  539. <if test="registerStartTime != null and registerStartTime !='' ">
  540. AND fs_user.create_time &gt;= #{registerStartTime}
  541. </if>
  542. <if test="registerEndTime != null and registerEndTime !='' ">
  543. AND fs_user.create_time &lt;= #{registerEndTime}
  544. </if>
  545. <if test="tagIds != null and tagIds.length > 0">
  546. AND
  547. <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
  548. CONCAT(',', company_tag_user.tag_ids, ',') LIKE CONCAT('%,', #{item}, ',%')
  549. </foreach>
  550. </if>
  551. <if test="tabValue != null and tabValue !='' ">
  552. <choose>
  553. <when test = "tabValue == 1">
  554. AND DAY(fs_user.create_time) = DAY(NOW())
  555. </when>
  556. <when test = "tabValue == 2">
  557. AND DAY(fs_user_course_count.complete_watch_date) = DAY(NOW())
  558. </when>
  559. <when test = "tabValue == 3">
  560. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  561. </when>
  562. </choose>
  563. </if>
  564. <if test="watchCourseType != null and watchCourseType !='' ">
  565. <choose>
  566. <when test = "watchCourseType == 1">
  567. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  568. </when>
  569. <when test = "watchCourseType == 2">
  570. AND fs_user_course_count.status = 1
  571. </when>
  572. <when test = "watchCourseType == 3">
  573. AND fs_user_course_count.status = 2
  574. </when>
  575. </choose>
  576. </if>
  577. <if test="missCourseStatus != null and missCourseStatus !='' ">
  578. <choose>
  579. <when test = "missCourseStatus == 1">
  580. AND fs_user_course_count.miss_course_status = 1
  581. </when>
  582. <when test = "missCourseStatus == 2">
  583. AND (fs_user_course_count.miss_course_status = 2 or fs_user_course_count.miss_course_status is null )
  584. </when>
  585. </choose>
  586. </if>
  587. group by fs_user.user_id
  588. <if test="continueMissCourseSort != null and continueMissCourseSort !='' ">
  589. order by
  590. <choose>
  591. <when test = "continueMissCourseSort == 0">
  592. fs_user.create_time desc
  593. </when>
  594. <when test = "continueMissCourseSort == 1">
  595. fs_user.nickname asc
  596. </when>
  597. </choose>
  598. </if>
  599. </select>
  600. <select id="getUserNumber" resultType="UserListCountVO">
  601. SELECT
  602. fs_user.`status` as status,
  603. count( DISTINCT fs_user.user_id ) AS num
  604. FROM
  605. fs_user
  606. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  607. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  608. WHERE
  609. (company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  610. and fs_user.is_del = 0
  611. GROUP BY
  612. fs_user.`status`
  613. </select>
  614. <select id="getRepeatUserNumber" resultType="int">
  615. SELECT
  616. count( DISTINCT fs_user.user_id ) AS num
  617. FROM
  618. fs_user
  619. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  620. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  621. WHERE
  622. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  623. AND fs_user.is_del = 0
  624. AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
  625. </select>
  626. <select id="getCountWatchCourse" resultType="UserDetailsVO">
  627. SELECT
  628. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  629. ifnull( watch_times, 0 ) AS watchTimes,
  630. fs_user.user_id
  631. FROM
  632. fs_user_course_count
  633. LEFT JOIN fs_user ON fs_user.user_id = fs_user_course_count.user_id
  634. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  635. <where>
  636. <if test="dateTag != null and dateTag !='' ">
  637. <choose>
  638. <when test = "dateTag == '今天'">
  639. and to_days(fs_user_course_count.create_time) = to_days(now())
  640. </when>
  641. <when test = "dateTag == ' 昨天'">
  642. and to_days(now()) - to_days(fs_user_course_count.create_time) &lt;= 1
  643. </when>
  644. <when test = "dateTag == '前天'">
  645. and to_days(now()) - to_days(fs_user_course_count.create_time) &lt;= 2
  646. </when>
  647. <when test = "dateTag == '近七天'">
  648. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_user_course_count.create_time)
  649. </when>
  650. </choose>
  651. </if>
  652. </where>
  653. GROUP BY
  654. fs_user.user_id
  655. HAVING
  656. fs_user.user_id = #{fsUserId}
  657. </select>
  658. <select id="getCountAnswer" resultType="UserDetailsVO">
  659. SELECT
  660. (
  661. SELECT
  662. ifnull(count( DISTINCT log_id ), 0) AS answerTime
  663. FROM
  664. fs_course_answer_logs
  665. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  666. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  667. WHERE
  668. company_user.parent_id = #{userId}
  669. <if test="dateTag != null and dateTag !='' ">
  670. <choose>
  671. <when test = "dateTag == '今天'">
  672. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  673. </when>
  674. <when test = "dateTag == ' 昨天'">
  675. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 1
  676. </when>
  677. <when test = "dateTag == '前天'">
  678. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 2
  679. </when>
  680. <when test = "dateTag == '近七天'">
  681. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_answer_logs.create_time)
  682. </when>
  683. </choose>
  684. </if>
  685. GROUP BY
  686. fs_user.user_id
  687. HAVING
  688. fs_user.user_id = #{fsUserId}
  689. ) AS answerTime,
  690. (
  691. SELECT
  692. ifnull(count( DISTINCT log_id ), 0) AS answerRightTime
  693. FROM
  694. fs_course_answer_logs
  695. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  696. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  697. WHERE
  698. company_user.parent_id = #{userId}
  699. AND fs_course_answer_logs.is_right = 1
  700. <if test="dateTag != null and dateTag !='' ">
  701. <choose>
  702. <when test = "dateTag == '今天'">
  703. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  704. </when>
  705. <when test = "dateTag == ' 昨天'">
  706. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 1
  707. </when>
  708. <when test = "dateTag == '前天'">
  709. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 2
  710. </when>
  711. <when test = "dateTag == '近七天'">
  712. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_answer_logs.create_time)
  713. </when>
  714. </choose>
  715. </if>
  716. GROUP BY
  717. fs_user.user_id
  718. HAVING
  719. fs_user.user_id = #{fsUserId}
  720. ) AS answerRightTime;
  721. </select>
  722. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  723. SELECT
  724. ifnull( count( DISTINCT log_id ), 0 ) AS answerRedPacketTime,
  725. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  726. fs_user.user_id
  727. FROM
  728. fs_course_red_packet_log
  729. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  730. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  731. WHERE
  732. company_user.parent_id = #{userId}
  733. <if test="dateTag != null and dateTag !='' ">
  734. <choose>
  735. <when test = "dateTag == '今天'">
  736. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  737. </when>
  738. <when test = "dateTag == ' 昨天'">
  739. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 1
  740. </when>
  741. <when test = "dateTag == '前天'">
  742. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 2
  743. </when>
  744. <when test = "dateTag == '近七天'">
  745. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_red_packet_log.create_time)
  746. </when>
  747. </choose>
  748. </if>
  749. GROUP BY
  750. fs_user.user_id
  751. HAVING
  752. fs_user.user_id = #{fsUserId}
  753. </select>
  754. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  755. select
  756. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  757. count(u.user_id) vipCount
  758. from fs_user u
  759. where u.company_user_id = #{companyUserId}
  760. </select>
  761. <update id="batchUpdateFsUserByIds" parameterType="Long">
  762. update fs_user
  763. set status = #{status} where user_id in
  764. <foreach item="id" collection="ids" open="(" separator="," close=")">
  765. #{id}
  766. </foreach>
  767. </update>
  768. <select id="countUserSummary" resultType="FsUserSummaryCountVO">
  769. SELECT (SELECT count(fs_user.user_id)
  770. FROM fs_user
  771. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  772. WHERE (
  773. company_user.user_id = #{userId}
  774. OR company_user.parent_id = #{userId}
  775. ) and fs_user.is_del = 0) as userTotal,
  776. (SELECT count(fs_user.user_id)
  777. FROM fs_user
  778. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  779. WHERE (company_user.user_id = #{userId} OR company_user.parent_id = #{userId})
  780. and fs_user.is_del = 0
  781. AND to_days(fs_user.create_time) = to_days(now())) as todayNewUser
  782. </select>
  783. <select id="countTag" resultType="FsUserSummaryCountTagVO">
  784. SELECT
  785. company_tag.tag AS tagName,
  786. count( fs_user.user_id ) AS number
  787. FROM
  788. company_tag_user
  789. LEFT JOIN fs_user ON fs_user.user_id = company_tag_user.user_id
  790. LEFT JOIN company_tag ON FIND_IN_SET( company_tag.tag_id, company_tag_user.tag_ids ) > 0
  791. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  792. where (company_user.user_id = #{userId} or company_user.parent_id = #{userId} ) and company_tag.tag_id is not null
  793. GROUP BY
  794. company_tag.tag_id
  795. </select>
  796. <select id="countUserCourse" resultType="Map">
  797. SELECT
  798. (
  799. SELECT
  800. count(distinct fcc.user_id )
  801. FROM
  802. fs_user_course_count fcc
  803. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  804. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  805. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  806. WHERE
  807. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  808. <if test="startTime != null and startTime !='' ">
  809. and fcc.create_time &gt;= #{startTime}
  810. </if>
  811. <if test="endTime != null and endTime != ''">
  812. and fcc.create_time &lt;= #{endTime}
  813. </if>
  814. <if test="periodId != null and periodId != ''">
  815. AND fcpd.period_id = #{periodId}
  816. </if>
  817. <if test="videoId != null and videoId != ''">
  818. AND fcpd.video_id = #{videoId}
  819. </if>
  820. -- 单独通过销售id查询
  821. <if test="companyUserId != null and companyUserId != ''">
  822. AND company_user.user_id = #{companyUserId}
  823. </if>
  824. ) as courseWatchNum,
  825. (
  826. SELECT
  827. count(distinct fcc.user_id )
  828. FROM
  829. fs_user_course_count fcc
  830. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  831. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  832. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  833. WHERE
  834. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  835. AND fcc.complete_watch_count > 0
  836. <if test="startTime != null and startTime !='' ">
  837. and fcc.create_time &gt;= #{startTime}
  838. </if>
  839. <if test="endTime != null and endTime != ''">
  840. and fcc.create_time &lt;= #{endTime}
  841. </if>
  842. <if test="periodId != null and periodId != ''">
  843. AND fcpd.period_id = #{periodId}
  844. </if>
  845. <if test="videoId != null and videoId != ''">
  846. AND fcpd.video_id = #{videoId}
  847. </if>
  848. -- 单独通过销售id查询
  849. <if test="companyUserId != null and companyUserId != ''">
  850. AND company_user.user_id = #{companyUserId}
  851. </if>
  852. ) as courseCompleteNum
  853. </select>
  854. <select id="countUserAnswer" resultType="Map">
  855. SELECT
  856. (
  857. SELECT
  858. count(distinct fs_user.user_id )
  859. FROM
  860. fs_course_answer_logs
  861. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  862. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  863. WHERE
  864. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  865. <if test="startTime != null and startTime !='' ">
  866. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  867. </if>
  868. <if test="endTime != null and endTime != ''">
  869. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  870. </if>
  871. <if test="periodId != null and periodId != ''">
  872. AND fs_course_answer_logs.period_id = #{periodId}
  873. </if>
  874. <if test="videoId != null and videoId != ''">
  875. AND fs_course_answer_logs.video_id = #{videoId}
  876. </if>
  877. -- 单独通过销售id查询
  878. <if test="companyUserId != null and companyUserId != ''">
  879. AND company_user.user_id = #{companyUserId}
  880. </if>
  881. ) AS answerNum,
  882. (
  883. SELECT
  884. count(distinct fs_user.user_id )
  885. FROM
  886. fs_course_answer_logs
  887. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  888. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  889. WHERE
  890. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  891. AND fs_course_answer_logs.is_right = 1
  892. <if test="startTime != null and startTime !='' ">
  893. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  894. </if>
  895. <if test="endTime != null and endTime != ''">
  896. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  897. </if>
  898. <if test="periodId != null and periodId != ''">
  899. AND fs_course_answer_logs.period_id = #{periodId}
  900. </if>
  901. <if test="videoId != null and videoId != ''">
  902. AND fs_course_answer_logs.video_id = #{videoId}
  903. </if>
  904. -- 单独通过销售id查询
  905. <if test="companyUserId != null and companyUserId != ''">
  906. AND company_user.user_id = #{companyUserId}
  907. </if>
  908. ) AS answerRightNum
  909. </select>
  910. <select id="countUserRedPacket" resultType="Map">
  911. SELECT
  912. (
  913. SELECT
  914. count( flog.log_id )
  915. FROM
  916. fs_course_red_packet_log flog
  917. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  918. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  919. WHERE
  920. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  921. <if test="startTime != null and startTime !='' ">
  922. AND flog.create_time &gt;= #{startTime}
  923. </if>
  924. <if test="endTime != null and endTime != ''">
  925. AND flog.create_time &lt;= #{endTime}
  926. </if>
  927. <if test="periodId != null and periodId != ''">
  928. AND flog.period_id = #{periodId}
  929. </if>
  930. <if test="videoId != null and videoId != ''">
  931. AND flog.video_id = #{videoId}
  932. </if>
  933. -- 单独通过销售id查询
  934. <if test="companyUserId != null and companyUserId != ''">
  935. AND company_user.user_id = #{companyUserId}
  936. </if>
  937. ) AS redPacketNum,
  938. (
  939. SELECT
  940. ifnull (sum( flog.amount ), 0)
  941. FROM
  942. fs_course_red_packet_log flog
  943. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  944. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  945. WHERE
  946. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  947. <if test="startTime != null and startTime !='' ">
  948. AND flog.create_time &gt;= #{startTime}
  949. </if>
  950. <if test="endTime != null and endTime != ''">
  951. AND flog.create_time &lt;= #{endTime}
  952. </if>
  953. <if test="periodId != null and periodId != ''">
  954. AND flog.period_id = #{periodId}
  955. </if>
  956. <if test="videoId != null and videoId != ''">
  957. AND flog.video_id = #{videoId}
  958. </if>
  959. -- 单独通过销售id查询
  960. <if test="companyUserId != null and companyUserId != ''">
  961. AND company_user.user_id = #{companyUserId}
  962. </if>
  963. ) AS redPacketAmount
  964. </select>
  965. <select id="countCourseDetails" resultType="Map">
  966. select (SELECT
  967. count( DISTINCT fcpd.period_id )
  968. FROM
  969. fs_user_course_period_days fcpd
  970. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  971. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  972. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  973. WHERE 1=1
  974. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  975. <if test="periodId != null and periodId != ''">
  976. AND fcpd.period_id = #{periodId}
  977. </if>
  978. -- 单独通过销售id查询
  979. <if test="companyUserId != null and companyUserId != ''">
  980. AND fs_user.company_user_id = #{companyUserId}
  981. </if>
  982. ) as courseNum,
  983. (SELECT count(DISTINCT fcpd.video_id)
  984. FROM fs_user_course_period_days fcpd
  985. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  986. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  987. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  988. WHERE 1=1
  989. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  990. <if test="periodId != null and periodId != ''">
  991. AND fcpd.period_id = #{periodId}
  992. </if>
  993. <if test="videoId != null and videoId != ''">
  994. AND fcpd.video_id = #{videoId}
  995. </if>
  996. -- 单独通过销售id查询
  997. <if test="companyUserId != null and companyUserId != ''">
  998. AND fs_user.company_user_id = #{companyUserId}
  999. </if>
  1000. ) as videoNum,
  1001. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  1002. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1003. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1004. <if test="periodId != null and periodId != ''">
  1005. AND fcpd.period_id = #{periodId}
  1006. </if>
  1007. <if test="videoId != null and videoId != ''">
  1008. AND fcpd.video_id = #{videoId}
  1009. </if>
  1010. -- 单独通过销售id查询
  1011. <if test="companyUserId != null and companyUserId != ''">
  1012. AND fs_user.company_user_id = #{companyUserId}
  1013. </if>
  1014. ) as courseUserNum
  1015. </select>
  1016. <select id="countUserRankingByComplete" resultType="FsUserRankingVO">
  1017. SELECT
  1018. company_user.nick_name as userName,
  1019. ifnull(
  1020. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  1021. ) as completeRate
  1022. FROM
  1023. fs_user_course_count fcc
  1024. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1025. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1026. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1027. WHERE
  1028. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  1029. <if test="startTime != null and startTime !='' ">
  1030. AND fcc.create_time &gt;= #{startTime}
  1031. </if>
  1032. <if test="endTime != null and endTime != ''">
  1033. AND fcc.create_time &lt;= #{endTime}
  1034. </if>
  1035. <if test="periodId != null and periodId != ''">
  1036. AND fcpd.period_id = #{periodId}
  1037. </if>
  1038. <if test="videoId != null and videoId != ''">
  1039. AND fcpd.video_id = #{videoId}
  1040. </if>
  1041. group by fcc.user_id
  1042. <choose>
  1043. <when test="order != null and order == 'asc'">
  1044. order by completeRate asc
  1045. </when>
  1046. <when test="order != null and order == 'desc'">
  1047. order by completeRate desc
  1048. </when>
  1049. <otherwise>
  1050. order by completeRate desc
  1051. </otherwise>
  1052. </choose>
  1053. limit 20
  1054. </select>
  1055. <select id="countUserRankingByRight" resultType="FsUserRankingVO">
  1056. SELECT
  1057. company_user.nick_name as userName,
  1058. ifnull(ROUND(
  1059. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1060. *100,2),0
  1061. ) as answerRightRate
  1062. FROM
  1063. fs_course_answer_logs
  1064. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1065. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1066. WHERE
  1067. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  1068. <if test="startTime != null and startTime !='' ">
  1069. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1070. </if>
  1071. <if test="endTime != null and endTime != ''">
  1072. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1073. </if>
  1074. <if test="periodId != null and periodId != ''">
  1075. AND fs_course_answer_logs.period_id = #{periodId}
  1076. </if>
  1077. <if test="videoId != null and videoId != ''">
  1078. AND fs_course_answer_logs.video_id = #{videoId}
  1079. </if>
  1080. group by fs_user.user_id
  1081. <choose>
  1082. <when test="order != null and order == 'asc'">
  1083. order by answerRightRate asc
  1084. </when>
  1085. <when test="order != null and order == 'desc'">
  1086. order by answerRightRate desc
  1087. </when>
  1088. <otherwise>
  1089. order by answerRightRate desc
  1090. </otherwise>
  1091. </choose>
  1092. limit 20
  1093. </select>
  1094. <select id="countCourseRankingByComplete" resultType="FsCourseRankingVO">
  1095. SELECT
  1096. fcv.title AS videoName,
  1097. ifnull(
  1098. ROUND((
  1099. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))* 100,
  1100. 2
  1101. ),
  1102. 0
  1103. ) AS completeRate
  1104. FROM
  1105. fs_user_course_count fcc
  1106. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1107. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1108. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1109. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fcpd.video_id
  1110. WHERE
  1111. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  1112. <if test="startTime != null and startTime !='' ">
  1113. AND fcc.create_time &gt;= #{startTime}
  1114. </if>
  1115. <if test="endTime != null and endTime != ''">
  1116. AND fcc.create_time &lt;= #{endTime}
  1117. </if>
  1118. <if test="periodId != null and periodId != ''">
  1119. AND fcpd.period_id = #{periodId}
  1120. </if>
  1121. <if test="videoId != null and videoId != ''">
  1122. AND fcpd.video_id = #{videoId}
  1123. </if>
  1124. GROUP BY
  1125. fcpd.video_id
  1126. <choose>
  1127. <when test="order != null and order == 'asc'">
  1128. ORDER BY completeRate asc
  1129. </when>
  1130. <when test="order != null and order == 'desc'">
  1131. ORDER BY completeRate desc
  1132. </when>
  1133. <otherwise>
  1134. ORDER BY completeRate desc
  1135. </otherwise>
  1136. </choose>
  1137. LIMIT 20
  1138. </select>
  1139. <select id="countCourseRankingByRight" resultType="FsCourseRankingVO">
  1140. SELECT
  1141. fcv.title AS videoName,
  1142. ifnull(
  1143. ROUND(
  1144. (
  1145. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1)) * 100,
  1146. 2
  1147. ),
  1148. 0
  1149. ) AS answerRightRate
  1150. FROM
  1151. fs_course_answer_logs
  1152. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1153. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1154. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1155. WHERE
  1156. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  1157. <if test="startTime != null and startTime !='' ">
  1158. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1159. </if>
  1160. <if test="endTime != null and endTime != ''">
  1161. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1162. </if>
  1163. <if test="periodId != null and periodId != ''">
  1164. AND fs_course_answer_logs.period_id = #{periodId}
  1165. </if>
  1166. <if test="videoId != null and videoId != ''">
  1167. AND fs_course_answer_logs.video_id = #{videoId}
  1168. </if>
  1169. GROUP BY
  1170. fs_course_answer_logs.video_id
  1171. <choose>
  1172. <when test="order != null and order == 'asc'">
  1173. ORDER BY answerRightRate asc
  1174. </when>
  1175. <when test="order != null and order == 'desc'">
  1176. ORDER BY answerRightRate desc
  1177. </when>
  1178. <otherwise>
  1179. ORDER BY answerRightRate desc
  1180. </otherwise>
  1181. </choose>
  1182. LIMIT 20
  1183. </select>
  1184. <!-- 查询某用户的课程视频,看课统计 -->
  1185. <select id="courseAnalysisCourseCount" resultType="FsCourseAnalysisCountVO">
  1186. SELECT
  1187. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1188. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1189. ifnull(
  1190. ROUND(
  1191. (
  1192. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1193. 2
  1194. ),
  1195. 0
  1196. ) as completeRate,
  1197. fcpd.video_id
  1198. FROM
  1199. fs_user_course_count fcc
  1200. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1201. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1202. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1203. WHERE
  1204. company_user.user_id = #{companyUserId}
  1205. <if test="periodId != null and periodId != ''">
  1206. AND fcpd.period_id = #{periodId}
  1207. </if>
  1208. <if test="videoId != null and videoId != ''">
  1209. AND fcpd.video_id = #{videoId}
  1210. </if>
  1211. GROUP BY
  1212. fcpd.video_id
  1213. </select>
  1214. <!-- 查询某用户的课程视频,红包统计 -->
  1215. <select id="courseAnalysisRedPacketCount" resultType="FsCourseAnalysisCountVO">
  1216. SELECT
  1217. count( flog.log_id ) as redPacketNum,
  1218. ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
  1219. flog.video_id
  1220. FROM
  1221. fs_course_red_packet_log flog
  1222. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1223. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1224. <where>
  1225. <if test="companyUserId != null and companyUserId !='' ">
  1226. AND company_user.user_id = #{companyUserId}
  1227. </if>
  1228. <if test="periodId != null and periodId != ''">
  1229. AND flog.period_id = #{periodId}
  1230. </if>
  1231. <if test="videoId != null and videoId != ''">
  1232. AND flog.video_id = #{videoId}
  1233. </if>
  1234. <if test="videoIdList != null and videoIdList.size > 0 ">
  1235. AND flog.video_id in
  1236. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  1237. #{videoId}
  1238. </foreach>
  1239. </if>
  1240. </where>
  1241. GROUP BY
  1242. flog.video_id
  1243. </select>
  1244. <!-- 查询某用户的课程视频,答题统计 -->
  1245. <select id="courseAnalysisAnswerCount" resultType="FsCourseAnalysisCountVO">
  1246. SELECT
  1247. count( DISTINCT fs_user.user_id ) as answerNum,
  1248. count(fs_course_answer_logs.log_id) answerTimes,
  1249. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
  1250. COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) as answerRightTimes,
  1251. ifnull(
  1252. ROUND(
  1253. (
  1254. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  1255. 2
  1256. ),
  1257. 0
  1258. ) as answerRightRate,
  1259. fs_course_answer_logs.video_id
  1260. FROM
  1261. fs_course_answer_logs
  1262. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1263. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1264. <where>
  1265. <if test="companyUserId != null and companyUserId !='' ">
  1266. AND company_user.user_id = #{companyUserId}
  1267. </if>
  1268. <if test="periodId != null and periodId != ''">
  1269. AND fs_course_answer_logs.period_id = #{periodId}
  1270. </if>
  1271. <if test="videoId != null and videoId != ''">
  1272. AND fs_course_answer_logs.video_id = #{videoId}
  1273. </if>
  1274. <if test="videoIdList != null and videoIdList.size > 0 ">
  1275. AND fs_course_answer_logs.video_id in
  1276. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  1277. #{videoId}
  1278. </foreach>
  1279. </if>
  1280. </where>
  1281. GROUP BY
  1282. fs_course_answer_logs.video_id
  1283. </select>
  1284. <select id="companyUserCount" resultType="CompanyUserSummaryCountVO">
  1285. SELECT
  1286. (
  1287. SELECT count( fs_user.user_id ) FROM fs_user LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1288. WHERE company_user.user_id = #{companyUserId}
  1289. ) AS userTotal,
  1290. (
  1291. SELECT
  1292. count( fs_user.user_id )
  1293. FROM
  1294. fs_user
  1295. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1296. WHERE
  1297. company_user.user_id = #{companyUserId}
  1298. and fs_user.is_del = 0
  1299. AND to_days( fs_user.create_time ) = to_days(
  1300. now())
  1301. ) AS todayNewUser
  1302. </select>
  1303. <select id="newUserRedPacketCount" resultType="CompanyUserSummaryCountVO">
  1304. SELECT
  1305. count(flog.log_id) as userRedPacketNum,
  1306. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1307. FROM
  1308. fs_course_red_packet_log flog
  1309. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1310. WHERE
  1311. fs_user.company_user_id = #{companyUserId}
  1312. </select>
  1313. <select id="selectFsUserPageListCount" resultType="java.lang.Long">
  1314. SELECT
  1315. count(1)
  1316. FROM
  1317. fs_user
  1318. <where>
  1319. fs_user.is_del = 0
  1320. <if test="registerStartTime != null and registerStartTime !='' ">
  1321. AND fs_user.create_time &gt;= #{registerStartTime}
  1322. </if>
  1323. <if test="registerEndTime != null and registerEndTime !='' ">
  1324. AND fs_user.create_time &lt;= #{registerEndTime}
  1325. </if>
  1326. <if test="companyUserIds != null and companyUserIds.size > 0">
  1327. AND fs_user.company_user_id in
  1328. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  1329. ${item}
  1330. </foreach>
  1331. </if>
  1332. <if test="nickname != null and nickname!=''">
  1333. AND fs_user.nickname like concat(#{nickname},'%')
  1334. </if>
  1335. <if test="phone != null and phone!=''">
  1336. AND fs_user.phone = #{phone}
  1337. </if>
  1338. </where>
  1339. </select>
  1340. <select id="courseAnalysisWatchLog" resultType="FsCourseAnalysisCountVO">
  1341. SELECT
  1342. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS courseWatchNum,
  1343. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTimes,
  1344. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS courseCompleteNum,
  1345. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTimes,
  1346. ifnull(
  1347. ROUND(
  1348. (
  1349. 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,
  1350. 2
  1351. ),
  1352. 0
  1353. ) AS completeRate,
  1354. fwl.video_id
  1355. FROM
  1356. fs_course_watch_log fwl
  1357. <where>
  1358. <if test="periodId != null and periodId != ''">
  1359. AND fwl.period_id = #{periodId}
  1360. </if>
  1361. <if test="videoId != null and videoId != ''">
  1362. AND fwl.video_id = #{videoId}
  1363. </if>
  1364. <if test="videoIdList != null and videoIdList.size > 0 ">
  1365. AND fwl.video_id in
  1366. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  1367. #{videoId}
  1368. </foreach>
  1369. </if>
  1370. </where>
  1371. GROUP BY
  1372. fwl.video_id
  1373. </select>
  1374. <update id="batchUpdateUserCompanyUser">
  1375. update fs_user
  1376. set company_id = #{companyId},
  1377. company_user_id = #{companyUserId}
  1378. where
  1379. <foreach collection="userIds" separator="or" item="userId" index="index">
  1380. user_id = #{userId}
  1381. </foreach>
  1382. </update>
  1383. <select id="selectUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  1384. select
  1385. u.user_id dictValue,
  1386. u.nickname dictLabel
  1387. from fs_user u
  1388. <where>
  1389. <if test="params.nickName != null and params.nickName != ''">
  1390. u.nickname like concat('%', #{params.nickName}, '%')
  1391. </if>
  1392. </where>
  1393. </select>
  1394. <select id ="selectFsUserByUserIds" resultType="Integer">
  1395. select count(1) from fs_user_company_user
  1396. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1397. where is_repeat_fans = 1
  1398. and (fs_user_company_user.company_user_id = #{companyUserId} OR company_user.parent_id = #{companyUserId})
  1399. <if test="userIds != null and userIds.length > 0 ">
  1400. and fs_user_company_user.user_id in
  1401. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  1402. #{userId}
  1403. </foreach>
  1404. </if>
  1405. </select>
  1406. <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
  1407. SELECT
  1408. count( fs_user.user_id ) as userNum,
  1409. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum
  1410. FROM
  1411. fs_user
  1412. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1413. LEFT JOIN company ON company.company_id = fs_user.company_id
  1414. WHERE
  1415. fs_user.is_del = 0
  1416. AND fs_user.`status` = 1
  1417. AND company_user.user_id is not null
  1418. </select>
  1419. <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
  1420. SELECT
  1421. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  1422. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  1423. ifnull(
  1424. ROUND(
  1425. (
  1426. 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,
  1427. 2
  1428. ),
  1429. 0
  1430. ) AS completeWatchRate,
  1431. fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
  1432. FROM
  1433. fs_course_watch_log fwl
  1434. WHERE
  1435. fwl.send_type = 1
  1436. GROUP BY
  1437. fwl.period_id, fwl.video_id, fwl.company_user_id
  1438. </select>
  1439. <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
  1440. SELECT
  1441. count( flog.log_id ) AS redPacketNum,
  1442. ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
  1443. flog.period_id,
  1444. flog.video_id,
  1445. flog.company_user_id,
  1446. flog.company_id
  1447. FROM
  1448. fs_course_red_packet_log flog
  1449. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1450. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1451. GROUP BY
  1452. flog.period_id,
  1453. flog.video_id,
  1454. flog.company_user_id
  1455. </select>
  1456. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  1457. SELECT
  1458. count( DISTINCT fs_user.user_id ) AS answerNum,
  1459. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) AS answerRightNum,
  1460. ifnull(
  1461. ROUND(
  1462. (
  1463. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  1464. 2
  1465. ),
  1466. 0
  1467. ) AS answerRightRate,
  1468. fs_course_answer_logs.period_id,
  1469. fs_course_answer_logs.video_id,
  1470. fs_course_answer_logs.company_user_id,
  1471. fs_course_answer_logs.company_id
  1472. FROM
  1473. fs_course_answer_logs
  1474. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1475. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1476. GROUP BY
  1477. fs_course_answer_logs.period_id,
  1478. fs_course_answer_logs.video_id,
  1479. fs_course_answer_logs.company_user_id
  1480. </select>
  1481. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  1482. SELECT
  1483. count( fs_user.user_id ) as userNum,
  1484. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum
  1485. ,company.company_id,
  1486. company.company_name,
  1487. company_user.user_id AS companyUserId,
  1488. company_user.nick_name AS companyUserName
  1489. FROM
  1490. fs_user
  1491. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1492. LEFT JOIN company ON company.company_id = fs_user.company_id
  1493. WHERE
  1494. fs_user.is_del = 0
  1495. AND fs_user.`status` = 1
  1496. AND company_user.user_id is not null
  1497. GROUP BY
  1498. fs_user.company_user_id
  1499. </select>
  1500. </mapper>