FsUserMapper.xml 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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.user_id,
  374. fs_user.nickname,
  375. fs_user.avatar,
  376. fs_user.phone,
  377. fs_user.status,
  378. fs_user.create_time,
  379. fs_user.remark,
  380. fs_user.company_user_id,
  381. fs_user.company_id
  382. FROM
  383. fs_user
  384. <where>
  385. fs_user.is_del = 0
  386. <if test="registerStartTime != null and registerStartTime !='' ">
  387. AND fs_user.create_time &gt;= #{registerStartTime}
  388. </if>
  389. <if test="registerEndTime != null and registerEndTime !='' ">
  390. AND fs_user.create_time &lt;= #{registerEndTime}
  391. </if>
  392. <if test="companyUserIds != null and companyUserIds.size > 0">
  393. AND fs_user.company_user_id in
  394. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  395. ${item}
  396. </foreach>
  397. </if>
  398. <if test="nickname != null and nickname != ''">
  399. AND fs_user.nickname like concat(#{nickname},'%')
  400. </if>
  401. <if test="phone != null and phone != ''">
  402. AND fs_user.phone = #{phone}
  403. </if>
  404. </where>
  405. limit ${(pageNum-1)*pageSize},${pageSize}
  406. </select>
  407. <select id="selectFsUserPageList" resultType="FsUserPageListVO">
  408. SELECT
  409. fs_user.*,
  410. fs_user_course_count.id,
  411. fs_user_course_count.watch_course_count,
  412. fs_user_course_count.miss_course_count,
  413. fs_user_course_count.miss_course_status,
  414. fs_user_course_count.course_ids,
  415. fs_user_course_count.part_course_count,
  416. fs_user_course_count.last_watch_date,
  417. fs_user_course_count.STATUS AS courseCountStatus,
  418. fs_user_course_count.stop_watch_days,
  419. fs_user_course_count.complete_watch_date,
  420. GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
  421. GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
  422. company_user.nick_name as companyUserNickName,
  423. fs_user_company_user.is_repeat_fans
  424. FROM
  425. fs_user
  426. LEFT JOIN fs_user_course_count ON fs_user.user_id = fs_user_course_count.user_id
  427. LEFT JOIN company_tag_user ON fs_user.user_id = company_tag_user.user_id
  428. LEFT JOIN company_tag ON FIND_IN_SET(company_tag.tag_id, company_tag_user.tag_ids) > 0
  429. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  430. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  431. where fs_user.is_del = 0
  432. <if test="userId != null and userId !='' ">
  433. and (company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  434. </if>
  435. <if test="companyUserId != null and companyUserId !='' ">
  436. and company_user.user_id = #{companyUserId}
  437. </if>
  438. <choose>
  439. <when test = "isBlack">
  440. AND (fs_user.status = 0 or fs_user_company_user.is_repeat_fans = 1)
  441. </when>
  442. <otherwise>
  443. AND (fs_user.status = 1 and fs_user_company_user.is_repeat_fans = 0)
  444. </otherwise>
  445. </choose>
  446. <if test="keyword != null and keyword !='' ">
  447. AND (fs_user.nickname LIKE concat('%',#{keyword},'%')
  448. or fs_user.phone LIKE concat('%',#{keyword},'%')
  449. )
  450. </if>
  451. <if test="registerStartTime != null and registerStartTime !='' ">
  452. AND fs_user.create_time &gt;= #{registerStartTime}
  453. </if>
  454. <if test="registerEndTime != null and registerEndTime !='' ">
  455. AND fs_user.create_time &lt;= #{registerEndTime}
  456. </if>
  457. <if test="tagIds != null and tagIds.length > 0">
  458. AND
  459. <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
  460. company_tag_user.tag_ids LIKE concat('%"',#{item},'"%')
  461. </foreach>
  462. </if>
  463. <if test="tabValue != null and tabValue !='' ">
  464. <choose>
  465. <when test = "tabValue == 1">
  466. AND DAY(fs_user.create_time) = DAY(NOW())
  467. </when>
  468. <when test = "tabValue == 2">
  469. AND DAY(fs_user_course_count.complete_watch_date) = DAY(NOW())
  470. </when>
  471. <when test = "tabValue == 3">
  472. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  473. </when>
  474. </choose>
  475. </if>
  476. <if test="watchCourseType != null and watchCourseType !='' ">
  477. <choose>
  478. <when test = "watchCourseType == 1">
  479. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  480. </when>
  481. <when test = "watchCourseType == 2">
  482. AND fs_user_course_count.status = 1
  483. </when>
  484. <when test = "watchCourseType == 3">
  485. AND fs_user_course_count.status = 2
  486. </when>
  487. </choose>
  488. </if>
  489. <if test="missCourseStatus != null and missCourseStatus !='' ">
  490. <choose>
  491. <when test = "missCourseStatus == 1">
  492. AND fs_user_course_count.miss_course_status = 1
  493. </when>
  494. <when test = "missCourseStatus == 2">
  495. AND (fs_user_course_count.miss_course_status = 2 or fs_user_course_count.miss_course_status is null )
  496. </when>
  497. </choose>
  498. </if>
  499. group by fs_user.user_id
  500. <if test="continueMissCourseSort != null and continueMissCourseSort !='' ">
  501. order by
  502. <choose>
  503. <when test = "continueMissCourseSort == 0">
  504. fs_user_course_count.miss_course_days desc
  505. </when>
  506. <when test = "continueMissCourseSort == 1">
  507. fs_user_course_count.miss_course_days asc
  508. </when>
  509. <when test = "continueMissCourseSort == 2">
  510. fs_user.create_time desc
  511. </when>
  512. <when test = "continueMissCourseSort == 3">
  513. fs_user.nickname asc
  514. </when>
  515. </choose>
  516. </if>
  517. </select>
  518. <select id="getUserNumber" resultType="UserListCountVO">
  519. SELECT
  520. fs_user.`status` as status,
  521. count( DISTINCT fs_user.user_id ) AS num
  522. FROM
  523. fs_user
  524. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  525. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  526. WHERE
  527. (company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  528. and fs_user.is_del = 0
  529. GROUP BY
  530. fs_user.`status`
  531. </select>
  532. <select id="getRepeatUserNumber" resultType="int">
  533. SELECT
  534. count( DISTINCT fs_user.user_id ) AS num
  535. FROM
  536. fs_user
  537. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  538. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  539. WHERE
  540. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  541. AND fs_user.is_del = 0
  542. AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
  543. </select>
  544. <select id="getCountAnswer" resultType="UserDetailsVO">
  545. SELECT
  546. (
  547. SELECT
  548. ifnull(count( DISTINCT log_id ), 0) AS answerTime
  549. FROM
  550. fs_course_answer_logs
  551. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  552. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  553. WHERE
  554. company_user.parent_id = #{userId}
  555. <if test="dateTag != null and dateTag !='' ">
  556. <choose>
  557. <when test = "dateTag == '今天'">
  558. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  559. </when>
  560. <when test = "dateTag == ' 昨天'">
  561. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 1
  562. </when>
  563. <when test = "dateTag == '前天'">
  564. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 2
  565. </when>
  566. <when test = "dateTag == '近七天'">
  567. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_answer_logs.create_time)
  568. </when>
  569. </choose>
  570. </if>
  571. GROUP BY
  572. fs_user.user_id
  573. HAVING
  574. fs_user.user_id = #{fsUserId}
  575. ) AS answerTime,
  576. (
  577. SELECT
  578. ifnull(count( DISTINCT log_id ), 0) AS answerRightTime
  579. FROM
  580. fs_course_answer_logs
  581. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  582. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  583. WHERE
  584. company_user.parent_id = #{userId}
  585. AND fs_course_answer_logs.is_right = 1
  586. <if test="dateTag != null and dateTag !='' ">
  587. <choose>
  588. <when test = "dateTag == '今天'">
  589. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  590. </when>
  591. <when test = "dateTag == ' 昨天'">
  592. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 1
  593. </when>
  594. <when test = "dateTag == '前天'">
  595. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 2
  596. </when>
  597. <when test = "dateTag == '近七天'">
  598. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_answer_logs.create_time)
  599. </when>
  600. </choose>
  601. </if>
  602. GROUP BY
  603. fs_user.user_id
  604. HAVING
  605. fs_user.user_id = #{fsUserId}
  606. ) AS answerRightTime;
  607. </select>
  608. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  609. SELECT
  610. ifnull( count( DISTINCT log_id ), 0 ) AS answerRedPacketTime,
  611. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  612. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  613. ifnull( watch_times, 0 ) AS watchTimes,
  614. fs_user.user_id
  615. FROM
  616. fs_course_red_packet_log
  617. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  618. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  619. LEFT JOIN fs_user_course_count ON fs_user_course_count.user_id = fs_user.user_id
  620. WHERE
  621. company_user.parent_id = #{userId}
  622. <if test="dateTag != null and dateTag !='' ">
  623. <choose>
  624. <when test = "dateTag == '今天'">
  625. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  626. </when>
  627. <when test = "dateTag == ' 昨天'">
  628. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 1
  629. </when>
  630. <when test = "dateTag == '前天'">
  631. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 2
  632. </when>
  633. <when test = "dateTag == '近七天'">
  634. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_red_packet_log.create_time)
  635. </when>
  636. </choose>
  637. </if>
  638. GROUP BY
  639. fs_user.user_id
  640. HAVING
  641. fs_user.user_id = #{fsUserId}
  642. </select>
  643. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  644. select
  645. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  646. count(u.user_id) vipCount
  647. from fs_user u
  648. where u.company_user_id = #{companyUserId}
  649. </select>
  650. <update id="batchUpdateFsUserByIds" parameterType="Long">
  651. update fs_user
  652. set status = #{status} where user_id in
  653. <foreach item="id" collection="ids" open="(" separator="," close=")">
  654. #{id}
  655. </foreach>
  656. </update>
  657. <select id="countUserSummary" resultType="FsUserSummaryCountVO">
  658. SELECT (SELECT count(fs_user.user_id)
  659. FROM fs_user
  660. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  661. WHERE (
  662. company_user.user_id = #{userId}
  663. OR company_user.parent_id = #{userId}
  664. ) and fs_user.is_del = 0) as userTotal,
  665. (SELECT count(fs_user.user_id)
  666. FROM fs_user
  667. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  668. WHERE (company_user.user_id = #{userId} OR company_user.parent_id = #{userId})
  669. and fs_user.is_del = 0
  670. AND to_days(fs_user.create_time) = to_days(now())) as todayNewUser
  671. </select>
  672. <select id="countTag" resultType="FsUserSummaryCountTagVO">
  673. SELECT
  674. company_tag.tag AS tagName,
  675. count( fs_user.user_id ) AS number
  676. FROM
  677. company_tag_user
  678. LEFT JOIN fs_user ON fs_user.user_id = company_tag_user.user_id
  679. LEFT JOIN company_tag ON FIND_IN_SET( company_tag.tag_id, company_tag_user.tag_ids ) > 0
  680. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  681. where (company_user.user_id = #{userId} or company_user.parent_id = #{userId} ) and company_tag.tag_id is not null
  682. GROUP BY
  683. company_tag.tag_id
  684. </select>
  685. <select id="countUserCourse" resultType="Map">
  686. SELECT
  687. (
  688. SELECT
  689. count(distinct fcc.user_id )
  690. FROM
  691. fs_user_course_count fcc
  692. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  693. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  694. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  695. WHERE
  696. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  697. <if test="startTime != null and startTime !='' ">
  698. and fcc.create_time &gt;= #{startTime}
  699. </if>
  700. <if test="endTime != null and endTime != ''">
  701. and fcc.create_time &lt;= #{endTime}
  702. </if>
  703. <if test="periodId != null and periodId != ''">
  704. AND fcpd.period_id = #{periodId}
  705. </if>
  706. <if test="videoId != null and videoId != ''">
  707. AND fcpd.video_id = #{videoId}
  708. </if>
  709. -- 单独通过销售id查询
  710. <if test="companyUserId != null and companyUserId != ''">
  711. AND company_user.user_id = #{companyUserId}
  712. </if>
  713. ) as courseWatchNum,
  714. (
  715. SELECT
  716. count(distinct fcc.user_id )
  717. FROM
  718. fs_user_course_count fcc
  719. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  720. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  721. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  722. WHERE
  723. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  724. AND fcc.complete_watch_count > 0
  725. <if test="startTime != null and startTime !='' ">
  726. and fcc.create_time &gt;= #{startTime}
  727. </if>
  728. <if test="endTime != null and endTime != ''">
  729. and fcc.create_time &lt;= #{endTime}
  730. </if>
  731. <if test="periodId != null and periodId != ''">
  732. AND fcpd.period_id = #{periodId}
  733. </if>
  734. <if test="videoId != null and videoId != ''">
  735. AND fcpd.video_id = #{videoId}
  736. </if>
  737. -- 单独通过销售id查询
  738. <if test="companyUserId != null and companyUserId != ''">
  739. AND company_user.user_id = #{companyUserId}
  740. </if>
  741. ) as courseCompleteNum
  742. </select>
  743. <select id="countUserAnswer" resultType="Map">
  744. SELECT
  745. (
  746. SELECT
  747. count(distinct fs_user.user_id )
  748. FROM
  749. fs_course_answer_logs
  750. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  751. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  752. WHERE
  753. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  754. <if test="startTime != null and startTime !='' ">
  755. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  756. </if>
  757. <if test="endTime != null and endTime != ''">
  758. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  759. </if>
  760. <if test="periodId != null and periodId != ''">
  761. AND fs_course_answer_logs.period_id = #{periodId}
  762. </if>
  763. <if test="videoId != null and videoId != ''">
  764. AND fs_course_answer_logs.video_id = #{videoId}
  765. </if>
  766. -- 单独通过销售id查询
  767. <if test="companyUserId != null and companyUserId != ''">
  768. AND company_user.user_id = #{companyUserId}
  769. </if>
  770. ) AS answerNum,
  771. (
  772. SELECT
  773. count(distinct fs_user.user_id )
  774. FROM
  775. fs_course_answer_logs
  776. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  777. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  778. WHERE
  779. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  780. AND fs_course_answer_logs.is_right = 1
  781. <if test="startTime != null and startTime !='' ">
  782. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  783. </if>
  784. <if test="endTime != null and endTime != ''">
  785. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  786. </if>
  787. <if test="periodId != null and periodId != ''">
  788. AND fs_course_answer_logs.period_id = #{periodId}
  789. </if>
  790. <if test="videoId != null and videoId != ''">
  791. AND fs_course_answer_logs.video_id = #{videoId}
  792. </if>
  793. -- 单独通过销售id查询
  794. <if test="companyUserId != null and companyUserId != ''">
  795. AND company_user.user_id = #{companyUserId}
  796. </if>
  797. ) AS answerRightNum
  798. </select>
  799. <select id="countUserRedPacket" resultType="Map">
  800. SELECT
  801. (
  802. SELECT
  803. count( flog.log_id )
  804. FROM
  805. fs_course_red_packet_log flog
  806. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  807. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  808. WHERE
  809. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  810. <if test="startTime != null and startTime !='' ">
  811. AND flog.create_time &gt;= #{startTime}
  812. </if>
  813. <if test="endTime != null and endTime != ''">
  814. AND flog.create_time &lt;= #{endTime}
  815. </if>
  816. <if test="periodId != null and periodId != ''">
  817. AND flog.period_id = #{periodId}
  818. </if>
  819. <if test="videoId != null and videoId != ''">
  820. AND flog.video_id = #{videoId}
  821. </if>
  822. -- 单独通过销售id查询
  823. <if test="companyUserId != null and companyUserId != ''">
  824. AND company_user.user_id = #{companyUserId}
  825. </if>
  826. ) AS redPacketNum,
  827. (
  828. SELECT
  829. ifnull (sum( flog.amount ), 0)
  830. FROM
  831. fs_course_red_packet_log flog
  832. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  833. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  834. WHERE
  835. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  836. <if test="startTime != null and startTime !='' ">
  837. AND flog.create_time &gt;= #{startTime}
  838. </if>
  839. <if test="endTime != null and endTime != ''">
  840. AND flog.create_time &lt;= #{endTime}
  841. </if>
  842. <if test="periodId != null and periodId != ''">
  843. AND flog.period_id = #{periodId}
  844. </if>
  845. <if test="videoId != null and videoId != ''">
  846. AND flog.video_id = #{videoId}
  847. </if>
  848. -- 单独通过销售id查询
  849. <if test="companyUserId != null and companyUserId != ''">
  850. AND company_user.user_id = #{companyUserId}
  851. </if>
  852. ) AS redPacketAmount
  853. </select>
  854. <select id="countCourseDetails" resultType="Map">
  855. select (SELECT
  856. count( DISTINCT fcpd.period_id )
  857. FROM
  858. fs_user_course_period_days fcpd
  859. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  860. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  861. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  862. WHERE 1=1
  863. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  864. <if test="periodId != null and periodId != ''">
  865. AND fcpd.period_id = #{periodId}
  866. </if>
  867. -- 单独通过销售id查询
  868. <if test="companyUserId != null and companyUserId != ''">
  869. AND fs_user.company_user_id = #{companyUserId}
  870. </if>
  871. ) as courseNum,
  872. (SELECT count(DISTINCT fcpd.video_id)
  873. FROM fs_user_course_period_days fcpd
  874. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  875. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  876. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  877. WHERE 1=1
  878. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  879. <if test="periodId != null and periodId != ''">
  880. AND fcpd.period_id = #{periodId}
  881. </if>
  882. <if test="videoId != null and videoId != ''">
  883. AND fcpd.video_id = #{videoId}
  884. </if>
  885. -- 单独通过销售id查询
  886. <if test="companyUserId != null and companyUserId != ''">
  887. AND fs_user.company_user_id = #{companyUserId}
  888. </if>
  889. ) as videoNum,
  890. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  891. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  892. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  893. <if test="periodId != null and periodId != ''">
  894. AND fcpd.period_id = #{periodId}
  895. </if>
  896. <if test="videoId != null and videoId != ''">
  897. AND fcpd.video_id = #{videoId}
  898. </if>
  899. -- 单独通过销售id查询
  900. <if test="companyUserId != null and companyUserId != ''">
  901. AND fs_user.company_user_id = #{companyUserId}
  902. </if>
  903. ) as courseUserNum
  904. </select>
  905. <select id="countUserRankingByComplete" resultType="FsUserRankingVO">
  906. SELECT
  907. company_user.nick_name as userName,
  908. ifnull(
  909. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  910. ) as completeRate
  911. FROM
  912. fs_user_course_count fcc
  913. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  914. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  915. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  916. WHERE
  917. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  918. <if test="startTime != null and startTime !='' ">
  919. AND fcc.create_time &gt;= #{startTime}
  920. </if>
  921. <if test="endTime != null and endTime != ''">
  922. AND fcc.create_time &lt;= #{endTime}
  923. </if>
  924. <if test="periodId != null and periodId != ''">
  925. AND fcpd.period_id = #{periodId}
  926. </if>
  927. <if test="videoId != null and videoId != ''">
  928. AND fcpd.video_id = #{videoId}
  929. </if>
  930. group by fcc.user_id
  931. <choose>
  932. <when test="order != null and order == 'asc'">
  933. order by completeRate asc
  934. </when>
  935. <when test="order != null and order == 'desc'">
  936. order by completeRate desc
  937. </when>
  938. <otherwise>
  939. order by completeRate desc
  940. </otherwise>
  941. </choose>
  942. limit 20
  943. </select>
  944. <select id="countUserRankingByRight" resultType="FsUserRankingVO">
  945. SELECT
  946. company_user.nick_name as userName,
  947. ifnull(ROUND(
  948. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  949. *100,2),0
  950. ) as answerRightRate
  951. FROM
  952. fs_course_answer_logs
  953. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  954. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  955. WHERE
  956. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  957. <if test="startTime != null and startTime !='' ">
  958. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  959. </if>
  960. <if test="endTime != null and endTime != ''">
  961. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  962. </if>
  963. <if test="periodId != null and periodId != ''">
  964. AND fs_course_answer_logs.period_id = #{periodId}
  965. </if>
  966. <if test="videoId != null and videoId != ''">
  967. AND fs_course_answer_logs.video_id = #{videoId}
  968. </if>
  969. group by fs_user.user_id
  970. <choose>
  971. <when test="order != null and order == 'asc'">
  972. order by answerRightRate asc
  973. </when>
  974. <when test="order != null and order == 'desc'">
  975. order by answerRightRate desc
  976. </when>
  977. <otherwise>
  978. order by answerRightRate desc
  979. </otherwise>
  980. </choose>
  981. limit 20
  982. </select>
  983. <select id="countCourseRankingByComplete" resultType="FsCourseRankingVO">
  984. SELECT
  985. fcv.title AS videoName,
  986. ifnull(
  987. ROUND((
  988. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))* 100,
  989. 2
  990. ),
  991. 0
  992. ) AS completeRate
  993. FROM
  994. fs_user_course_count fcc
  995. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  996. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  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_course_video fcv ON fcv.video_id = fcpd.video_id
  999. WHERE
  1000. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  1001. <if test="startTime != null and startTime !='' ">
  1002. AND fcc.create_time &gt;= #{startTime}
  1003. </if>
  1004. <if test="endTime != null and endTime != ''">
  1005. AND fcc.create_time &lt;= #{endTime}
  1006. </if>
  1007. <if test="periodId != null and periodId != ''">
  1008. AND fcpd.period_id = #{periodId}
  1009. </if>
  1010. <if test="videoId != null and videoId != ''">
  1011. AND fcpd.video_id = #{videoId}
  1012. </if>
  1013. GROUP BY
  1014. fcpd.video_id
  1015. <choose>
  1016. <when test="order != null and order == 'asc'">
  1017. ORDER BY completeRate asc
  1018. </when>
  1019. <when test="order != null and order == 'desc'">
  1020. ORDER BY completeRate desc
  1021. </when>
  1022. <otherwise>
  1023. ORDER BY completeRate desc
  1024. </otherwise>
  1025. </choose>
  1026. LIMIT 20
  1027. </select>
  1028. <select id="countCourseRankingByRight" resultType="FsCourseRankingVO">
  1029. SELECT
  1030. fcv.title AS videoName,
  1031. ifnull(
  1032. ROUND(
  1033. (
  1034. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1)) * 100,
  1035. 2
  1036. ),
  1037. 0
  1038. ) AS answerRightRate
  1039. FROM
  1040. fs_course_answer_logs
  1041. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1042. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1043. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1044. WHERE
  1045. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  1046. <if test="startTime != null and startTime !='' ">
  1047. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1048. </if>
  1049. <if test="endTime != null and endTime != ''">
  1050. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1051. </if>
  1052. <if test="periodId != null and periodId != ''">
  1053. AND fs_course_answer_logs.period_id = #{periodId}
  1054. </if>
  1055. <if test="videoId != null and videoId != ''">
  1056. AND fs_course_answer_logs.video_id = #{videoId}
  1057. </if>
  1058. GROUP BY
  1059. fs_course_answer_logs.video_id
  1060. <choose>
  1061. <when test="order != null and order == 'asc'">
  1062. ORDER BY answerRightRate asc
  1063. </when>
  1064. <when test="order != null and order == 'desc'">
  1065. ORDER BY answerRightRate desc
  1066. </when>
  1067. <otherwise>
  1068. ORDER BY answerRightRate desc
  1069. </otherwise>
  1070. </choose>
  1071. LIMIT 20
  1072. </select>
  1073. <!-- 查询某用户的课程视频,看课统计 -->
  1074. <select id="courseAnalysisCourseCount" resultType="FsCourseAnalysisCountVO">
  1075. SELECT
  1076. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1077. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1078. ifnull(
  1079. ROUND(
  1080. (
  1081. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1082. 2
  1083. ),
  1084. 0
  1085. ) as completeRate,
  1086. fcpd.video_id
  1087. FROM
  1088. fs_user_course_count fcc
  1089. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1090. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1091. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1092. WHERE
  1093. company_user.user_id = #{companyUserId}
  1094. <if test="periodId != null and periodId != ''">
  1095. AND fcpd.period_id = #{periodId}
  1096. </if>
  1097. <if test="videoId != null and videoId != ''">
  1098. AND fcpd.video_id = #{videoId}
  1099. </if>
  1100. GROUP BY
  1101. fcpd.video_id
  1102. </select>
  1103. <!-- 查询某用户的课程视频,红包统计 -->
  1104. <select id="courseAnalysisRedPacketCount" resultType="FsCourseAnalysisCountVO">
  1105. SELECT
  1106. count( flog.log_id ) as redPacketNum,
  1107. ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
  1108. flog.video_id
  1109. FROM
  1110. fs_course_red_packet_log flog
  1111. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1112. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1113. <where>
  1114. <if test="companyUserId != null and companyUserId !='' ">
  1115. AND company_user.user_id = #{companyUserId}
  1116. </if>
  1117. <if test="periodId != null and periodId != ''">
  1118. AND flog.period_id = #{periodId}
  1119. </if>
  1120. <if test="videoId != null and videoId != ''">
  1121. AND flog.video_id = #{videoId}
  1122. </if>
  1123. <if test="videoIdList != null and videoIdList.size > 0 ">
  1124. AND flog.video_id in
  1125. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  1126. #{videoId}
  1127. </foreach>
  1128. </if>
  1129. </where>
  1130. GROUP BY
  1131. flog.video_id
  1132. </select>
  1133. <!-- 查询某用户的课程视频,答题统计 -->
  1134. <select id="courseAnalysisAnswerCount" resultType="FsCourseAnalysisCountVO">
  1135. SELECT
  1136. count( DISTINCT fs_user.user_id ) as answerNum,
  1137. count(fs_course_answer_logs.log_id) answerTimes,
  1138. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
  1139. COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) as answerRightTimes,
  1140. ifnull(
  1141. ROUND(
  1142. (
  1143. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  1144. 2
  1145. ),
  1146. 0
  1147. ) as answerRightRate,
  1148. fs_course_answer_logs.video_id
  1149. FROM
  1150. fs_course_answer_logs
  1151. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1152. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1153. <where>
  1154. <if test="companyUserId != null and companyUserId !='' ">
  1155. AND company_user.user_id = #{companyUserId}
  1156. </if>
  1157. <if test="periodId != null and periodId != ''">
  1158. AND fs_course_answer_logs.period_id = #{periodId}
  1159. </if>
  1160. <if test="videoId != null and videoId != ''">
  1161. AND fs_course_answer_logs.video_id = #{videoId}
  1162. </if>
  1163. <if test="videoIdList != null and videoIdList.size > 0 ">
  1164. AND fs_course_answer_logs.video_id in
  1165. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  1166. #{videoId}
  1167. </foreach>
  1168. </if>
  1169. </where>
  1170. GROUP BY
  1171. fs_course_answer_logs.video_id
  1172. </select>
  1173. <select id="companyUserCount" resultType="CompanyUserSummaryCountVO">
  1174. SELECT
  1175. (
  1176. SELECT count( fs_user.user_id ) FROM fs_user LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1177. WHERE company_user.user_id = #{companyUserId}
  1178. ) AS userTotal,
  1179. (
  1180. SELECT
  1181. count( fs_user.user_id )
  1182. FROM
  1183. fs_user
  1184. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1185. WHERE
  1186. company_user.user_id = #{companyUserId}
  1187. and fs_user.is_del = 0
  1188. AND to_days( fs_user.create_time ) = to_days(
  1189. now())
  1190. ) AS todayNewUser
  1191. </select>
  1192. <select id="newUserRedPacketCount" resultType="CompanyUserSummaryCountVO">
  1193. SELECT
  1194. count(flog.log_id) as userRedPacketNum,
  1195. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1196. FROM
  1197. fs_course_red_packet_log flog
  1198. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1199. WHERE
  1200. fs_user.company_user_id = #{companyUserId}
  1201. </select>
  1202. <select id="selectFsUserPageListCount" resultType="java.lang.Long">
  1203. SELECT
  1204. count(1)
  1205. FROM
  1206. fs_user
  1207. <where>
  1208. fs_user.is_del = 0
  1209. <if test="registerStartTime != null and registerStartTime !='' ">
  1210. AND fs_user.create_time &gt;= #{registerStartTime}
  1211. </if>
  1212. <if test="registerEndTime != null and registerEndTime !='' ">
  1213. AND fs_user.create_time &lt;= #{registerEndTime}
  1214. </if>
  1215. <if test="companyUserIds != null and companyUserIds.size > 0">
  1216. AND fs_user.company_user_id in
  1217. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  1218. ${item}
  1219. </foreach>
  1220. </if>
  1221. <if test="nickname != null and nickname!=''">
  1222. AND fs_user.nickname like concat(#{nickname},'%')
  1223. </if>
  1224. <if test="phone != null and phone!=''">
  1225. AND fs_user.phone = #{phone}
  1226. </if>
  1227. </where>
  1228. </select>
  1229. <select id="courseAnalysisWatchLog" resultType="FsCourseAnalysisCountVO">
  1230. SELECT
  1231. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS courseWatchNum,
  1232. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTimes,
  1233. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS courseCompleteNum,
  1234. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTimes,
  1235. ifnull(
  1236. ROUND(
  1237. (
  1238. 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,
  1239. 2
  1240. ),
  1241. 0
  1242. ) AS completeRate,
  1243. fwl.video_id
  1244. FROM
  1245. fs_course_watch_log fwl
  1246. <where>
  1247. <if test="periodId != null and periodId != ''">
  1248. AND fwl.period_id = #{periodId}
  1249. </if>
  1250. <if test="videoId != null and videoId != ''">
  1251. AND fwl.video_id = #{videoId}
  1252. </if>
  1253. <if test="videoIdList != null and videoIdList.size > 0 ">
  1254. AND fwl.video_id in
  1255. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  1256. #{videoId}
  1257. </foreach>
  1258. </if>
  1259. </where>
  1260. GROUP BY
  1261. fwl.video_id
  1262. </select>
  1263. <update id="batchUpdateUserCompanyUser">
  1264. update fs_user
  1265. set company_id = #{companyId},
  1266. company_user_id = #{companyUserId}
  1267. where
  1268. <foreach collection="userIds" separator="or" item="userId" index="index">
  1269. user_id = #{userId}
  1270. </foreach>
  1271. </update>
  1272. <select id="selectUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  1273. select
  1274. u.user_id dictValue,
  1275. u.nickname dictLabel
  1276. from fs_user u
  1277. <where>
  1278. <if test="params.nickName != null and params.nickName != ''">
  1279. u.nickname like concat('%', #{params.nickName}, '%')
  1280. </if>
  1281. </where>
  1282. </select>
  1283. <select id ="selectFsUserByUserIds" resultType="Integer">
  1284. select count(1) from fs_user_company_user
  1285. where is_repeat_fans = 1
  1286. and fs_user_company_user.company_user_id = #{companyUserId}
  1287. <if test="userIds != null and userIds.length > 0 ">
  1288. and fs_user_company_user.user_id in
  1289. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  1290. #{userId}
  1291. </foreach>
  1292. </if>
  1293. </select>
  1294. </mapper>