FsUserMapper.xml 64 KB

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