FsUserMapper.xml 64 KB

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