FsUserMapper.xml 61 KB

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