FsUserMapper.xml 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  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. </resultMap>
  47. <sql id="selectFsUserVo">
  48. select user_id,
  49. qw_ext_id,
  50. is_show,
  51. username,
  52. password,
  53. real_name,
  54. birthday,
  55. id_card,
  56. remark,
  57. nickname,
  58. avatar,
  59. phone,
  60. create_time,
  61. update_time,
  62. last_ip,
  63. now_money,
  64. brokerage_price,
  65. integral,
  66. sign_num,
  67. status,
  68. level,
  69. spread_user_id,
  70. spread_time,
  71. user_type,
  72. is_promoter,
  73. pay_count,
  74. spread_count,
  75. addres,
  76. ma_open_id,
  77. mp_open_id,
  78. union_id,
  79. is_del,
  80. is_weixin_auth,
  81. company_id,
  82. company_user_id,
  83. register_date,
  84. register_code,
  85. source,
  86. user_code
  87. from fs_user
  88. </sql>
  89. <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
  90. <include refid="selectFsUserVo"/>
  91. <where>
  92. <if test="username != null and username != ''">and username like concat('%', #{username}, '%')</if>
  93. <if test="password != null and password != ''">and password = #{password}</if>
  94. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  95. <if test="birthday != null ">and birthday = #{birthday}</if>
  96. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  97. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  98. <if test="nickname != null and nickname != ''">and nickname like concat('%', #{nickname}, '%')</if>
  99. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  100. <if test="phone != null and phone != ''">and phone = #{phone}</if>
  101. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  102. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  103. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  104. <if test="integral != null ">and integral = #{integral}</if>
  105. <if test="signNum != null ">and sign_num = #{signNum}</if>
  106. <if test="status != null ">and status = #{status}</if>
  107. <if test="level != null ">and level = #{level}</if>
  108. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  109. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  110. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  111. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  112. <if test="payCount != null ">and pay_count = #{payCount}</if>
  113. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  114. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  115. <if test="isDel != null ">and is_del = #{isDel}</if>
  116. <if test="companyId != null ">and company_id = #{companyId}</if>
  117. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  118. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  119. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  120. </if>
  121. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  122. <if test="source != null and source != '' ">and source = #{source}</if>
  123. <if test="isShow != null ">and is_show = #{isShow}</if>
  124. </where>
  125. order by user_id desc
  126. </select>
  127. <select id="selectFsUserById" parameterType="Long" resultMap="FsUserResult">
  128. <include refid="selectFsUserVo"/>
  129. where user_id = #{userId}
  130. </select>
  131. <select id="selectFsUserListLimit" resultType="com.fs.store.domain.FsUser">
  132. <include refid="selectFsUserVo"/>
  133. <where>
  134. <if test="password != null and password != ''">and password = #{password}</if>
  135. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  136. <if test="birthday != null ">and birthday = #{birthday}</if>
  137. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  138. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  139. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  140. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  141. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  142. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  143. <if test="integral != null ">and integral = #{integral}</if>
  144. <if test="signNum != null ">and sign_num = #{signNum}</if>
  145. <if test="status != null ">and status = #{status}</if>
  146. <if test="level != null ">and level = #{level}</if>
  147. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  148. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  149. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  150. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  151. <if test="payCount != null ">and pay_count = #{payCount}</if>
  152. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  153. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  154. <if test="isDel != null ">and is_del = #{isDel}</if>
  155. <if test="companyId != null ">and company_id = #{companyId}</if>
  156. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  157. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  158. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  159. </if>
  160. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  161. <if test="source != null and source != '' ">and source = #{source}</if>
  162. <if test="isShow != null ">and is_show = #{isShow}</if>
  163. <if test="(username != null and username != '') or (nickname != null and nickname != '') or (phone != null and phone != '')">
  164. and (
  165. <if test="username != null and username != ''">username like concat('%', #{username}, '%')</if>
  166. <if test="nickname != null and nickname != ''">or nickname like concat('%', #{nickname}, '%')</if>
  167. <if test="phone != null and phone != ''">or phone like concat('%',#{phone},'%')</if>
  168. )
  169. </if>
  170. </where>
  171. order by user_id desc
  172. limit 10
  173. </select>
  174. <select id="selectCusListPage" resultType="com.fs.store.domain.FsUser">
  175. select user.user_id,
  176. user.username,
  177. user.real_name,
  178. user.id_card,
  179. user.phone,
  180. user.addres,
  181. user.nickname,
  182. user.status,
  183. user.company_id,
  184. user.company_user_id,
  185. user.create_time
  186. from
  187. fs_user `user` join (
  188. select user_id from fs_user
  189. <where>
  190. <if test="companyId != null and companyId != ''">
  191. AND company_id = #{companyId}
  192. </if>
  193. <if test="companyUserId != null and companyUserId != ''">
  194. AND company_user_id = #{companyUserId}
  195. </if>
  196. <if test="phone != null and phone != ''">
  197. AND phone = #{phone}
  198. </if>
  199. </where>
  200. order by user_id desc
  201. limit ${(pageNum-1)*pageSize},${pageSize}
  202. ) t on t.user_id = `user`.user_id
  203. </select>
  204. <select id="selectCusListPageCount" resultType="java.lang.Long">
  205. SELECT COUNT(user_id)
  206. FROM fs_user
  207. <where>
  208. <if test="companyId != null and companyId != ''">
  209. AND company_id = #{companyId}
  210. </if>
  211. <if test="companyUserId != null and companyUserId != ''">
  212. AND company_user_id = #{companyUserId}
  213. </if>
  214. <if test="phone != null and phone != ''">
  215. AND phone = #{phone}
  216. </if>
  217. </where>
  218. </select>
  219. <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
  220. insert into fs_user
  221. <trim prefix="(" suffix=")" suffixOverrides=",">
  222. <if test="username != null">username,</if>
  223. <if test="password != null">password,</if>
  224. <if test="realName != null">real_name,</if>
  225. <if test="birthday != null">birthday,</if>
  226. <if test="idCard != null">id_card,</if>
  227. <if test="remark != null">remark,</if>
  228. <if test="nickname != null">nickname,</if>
  229. <if test="avatar != null">avatar,</if>
  230. <if test="phone != null">phone,</if>
  231. <if test="createTime != null">create_time,</if>
  232. <if test="updateTime != null">update_time,</if>
  233. <if test="lastIp != null">last_ip,</if>
  234. <if test="nowMoney != null">now_money,</if>
  235. <if test="brokeragePrice != null">brokerage_price,</if>
  236. <if test="integral != null">integral,</if>
  237. <if test="signNum != null">sign_num,</if>
  238. <if test="status != null">status,</if>
  239. <if test="level != null">level,</if>
  240. <if test="spreadUserId != null">spread_user_id,</if>
  241. <if test="spreadTime != null">spread_time,</if>
  242. <if test="userType != null and userType != ''">user_type,</if>
  243. <if test="isPromoter != null">is_promoter,</if>
  244. <if test="payCount != null">pay_count,</if>
  245. <if test="spreadCount != null">spread_count,</if>
  246. <if test="addres != null and addres != ''">addres,</if>
  247. <if test="maOpenId != null">ma_open_id,</if>
  248. <if test="mpOpenId != null">mp_open_id,</if>
  249. <if test="unionId != null">union_id,</if>
  250. <if test="isDel != null">is_del,</if>
  251. <if test="isWeixinAuth != null">is_weixin_auth,</if>
  252. <if test="companyId != null">company_id,</if>
  253. <if test="companyUserId != null">company_user_id,</if>
  254. <if test="registerDate != null">register_date,</if>
  255. <if test="registerCode != null">register_code,</if>
  256. <if test="source != null">source,</if>
  257. <if test="userCode != null">user_code,</if>
  258. <if test="isShow != null">is_show,</if>
  259. <if test="qwExtId != null">qw_ext_id,</if>
  260. </trim>
  261. <trim prefix="values (" suffix=")" suffixOverrides=",">
  262. <if test="username != null">#{username},</if>
  263. <if test="password != null">#{password},</if>
  264. <if test="realName != null">#{realName},</if>
  265. <if test="birthday != null">#{birthday},</if>
  266. <if test="idCard != null">#{idCard},</if>
  267. <if test="remark != null">#{remark},</if>
  268. <if test="nickname != null">#{nickname},</if>
  269. <if test="avatar != null">#{avatar},</if>
  270. <if test="phone != null">#{phone},</if>
  271. <if test="createTime != null">#{createTime},</if>
  272. <if test="updateTime != null">#{updateTime},</if>
  273. <if test="lastIp != null">#{lastIp},</if>
  274. <if test="nowMoney != null">#{nowMoney},</if>
  275. <if test="brokeragePrice != null">#{brokeragePrice},</if>
  276. <if test="integral != null">#{integral},</if>
  277. <if test="signNum != null">#{signNum},</if>
  278. <if test="status != null">#{status},</if>
  279. <if test="level != null">#{level},</if>
  280. <if test="spreadUserId != null">#{spreadUserId},</if>
  281. <if test="spreadTime != null">#{spreadTime},</if>
  282. <if test="userType != null and userType != ''">#{userType},</if>
  283. <if test="isPromoter != null">#{isPromoter},</if>
  284. <if test="payCount != null">#{payCount},</if>
  285. <if test="spreadCount != null">#{spreadCount},</if>
  286. <if test="addres != null and addres != ''">#{addres},</if>
  287. <if test="maOpenId != null">#{maOpenId},</if>
  288. <if test="mpOpenId != null">#{mpOpenId},</if>
  289. <if test="unionId != null">#{unionId},</if>
  290. <if test="isDel != null">#{isDel},</if>
  291. <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
  292. <if test="companyId != null">#{companyId},</if>
  293. <if test="companyUserId != null">#{companyUserId},</if>
  294. <if test="registerDate != null">#{registerDate},</if>
  295. <if test="registerCode != null">#{registerCode},</if>
  296. <if test="source != null">#{source},</if>
  297. <if test="userCode != null">#{userCode},</if>
  298. <if test="isShow != null">#{isShow},</if>
  299. <if test="qwExtId != null">#{qwExtId},</if>
  300. </trim>
  301. </insert>
  302. <update id="updateFsUser" parameterType="FsUser">
  303. update fs_user
  304. <trim prefix="SET" suffixOverrides=",">
  305. <if test="username != null">username = #{username},</if>
  306. <if test="password != null">password = #{password},</if>
  307. <if test="realName != null">real_name = #{realName},</if>
  308. <if test="birthday != null">birthday = #{birthday},</if>
  309. <if test="idCard != null">id_card = #{idCard},</if>
  310. <if test="remark != null">remark = #{remark},</if>
  311. <if test="nickname != null">nickname = #{nickname},</if>
  312. <if test="avatar != null">avatar = #{avatar},</if>
  313. <if test="phone != null">phone = #{phone},</if>
  314. <if test="createTime != null">create_time = #{createTime},</if>
  315. <if test="updateTime != null">update_time = #{updateTime},</if>
  316. <if test="lastIp != null">last_ip = #{lastIp},</if>
  317. <if test="nowMoney != null">now_money = #{nowMoney},</if>
  318. <if test="brokeragePrice != null">brokerage_price = #{brokeragePrice},</if>
  319. <if test="integral != null">integral = #{integral},</if>
  320. <if test="signNum != null">sign_num = #{signNum},</if>
  321. <if test="status != null">status = #{status},</if>
  322. <if test="level != null">level = #{level},</if>
  323. <if test="spreadUserId != null">spread_user_id = #{spreadUserId},</if>
  324. <if test="spreadTime != null">spread_time = #{spreadTime},</if>
  325. <if test="userType != null and userType != ''">user_type = #{userType},</if>
  326. <if test="isPromoter != null">is_promoter = #{isPromoter},</if>
  327. <if test="payCount != null">pay_count = #{payCount},</if>
  328. <if test="spreadCount != null">spread_count = #{spreadCount},</if>
  329. <if test="addres != null and addres != ''">addres = #{addres},</if>
  330. <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
  331. <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
  332. <if test="unionId != null">union_id = #{unionId},</if>
  333. <if test="isDel != null">is_del = #{isDel},</if>
  334. <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
  335. <if test="companyId != null">company_id = #{companyId},</if>
  336. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  337. <if test="registerDate != null">register_date = #{registerDate},</if>
  338. <if test="registerCode != null">register_code = #{registerCode},</if>
  339. <if test="source != null">source = #{source},</if>
  340. <if test="userCode != null">user_code = #{userCode},</if>
  341. <if test="isShow != null">is_show = #{isShow},</if>
  342. <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
  343. </trim>
  344. where user_id = #{userId}
  345. </update>
  346. <update id="transferCompanyUser">
  347. update fs_user
  348. set company_user_id=#{targetCompanyUserId}
  349. where
  350. user_id in
  351. <foreach collection="userIds" open="(" close=")" separator="," item="item">
  352. ${item}
  353. </foreach>
  354. </update>
  355. <delete id="deleteFsUserById" parameterType="Long">
  356. delete
  357. from fs_user
  358. where user_id = #{userId}
  359. </delete>
  360. <delete id="deleteFsUserByIds" parameterType="String">
  361. delete from fs_user where user_id in
  362. <foreach item="userId" collection="array" open="(" separator="," close=")">
  363. #{userId}
  364. </foreach>
  365. </delete>
  366. <select id="selectFsUserPageList" resultType="FsUserPageListVO">
  367. SELECT
  368. fs_user.*,
  369. fs_user_course_count.id,
  370. fs_user_course_count.user_id,
  371. fs_user_course_count.watch_course_count,
  372. fs_user_course_count.miss_course_count,
  373. fs_user_course_count.miss_course_status,
  374. fs_user_course_count.course_id,
  375. fs_user_course_count.part_course_count,
  376. fs_user_course_count.last_watch_date,
  377. fs_user_course_count.STATUS AS courseCountStatus,
  378. fs_user_course_count.stop_watch_days,
  379. fs_user_course_count.create_time,
  380. fs_user_course_count.complete_watch_date,
  381. company_tag.tag,
  382. company_tag_user.tag_ids,
  383. company_user.nick_name as companyUserNickName
  384. FROM
  385. fs_user
  386. left join company_user on fs_user.company_user_id = company_user.user_id
  387. LEFT JOIN fs_user_course_count ON fs_user.user_id = fs_user_course_count.user_id
  388. LEFT JOIN company_tag_user ON fs_user.user_id = company_tag_user.user_id
  389. LEFT JOIN company_tag ON FIND_IN_SET(company_tag.tag_id, company_tag_user.tag_ids) > 0
  390. where company_user.parent_id = #{userId}
  391. <if test="companyUserId != null and companyUserId !='' ">
  392. and company_user.user_id = #{companyUserId}
  393. </if>
  394. <choose>
  395. <when test = "isBlack">
  396. AND fs_user.status = 0
  397. </when>
  398. <otherwise>
  399. AND fs_user.status = 1
  400. </otherwise>
  401. </choose>
  402. <if test="keyword != null and keyword !='' ">
  403. AND (fs_user.nickname LIKE concat('%',#{keyword},'%')
  404. or fs_user.phone LIKE concat('%',#{keyword},'%')
  405. )
  406. </if>
  407. <if test="registerStartTime != null and registerStartTime !='' ">
  408. AND fs_user.create_time &gt;= #{registerStartTime}
  409. </if>
  410. <if test="registerEndTime != null and registerEndTime !='' ">
  411. AND fs_user.create_time &lt;= #{registerEndTime}
  412. </if>
  413. <if test="tagIds != null and tagIds.length > 0">
  414. AND
  415. <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
  416. company_tag_user.tag_ids LIKE concat('%"',#{item},'"%')
  417. </foreach>
  418. </if>
  419. <if test="tabValue != null and tabValue !='' ">
  420. <choose>
  421. <when test = "tabValue == 1">
  422. AND DAY(fs_user.create_time) = DAY(NOW())
  423. </when>
  424. <when test = "tabValue == 2">
  425. AND DAY(fs_user_course_count.complete_watch_date) = DAY(NOW())
  426. </when>
  427. <when test = "tabValue == 3">
  428. AND fs_user_course_count.status = 3
  429. </when>
  430. </choose>
  431. </if>
  432. <if test="watchCourseType != null and watchCourseType !='' ">
  433. <choose>
  434. <when test = "watchCourseType == 1">
  435. AND fs_user_course_count.status = 3
  436. </when>
  437. <when test = "watchCourseType == 2">
  438. AND fs_user_course_count.status = 1
  439. </when>
  440. <when test = "watchCourseType == 3">
  441. AND fs_user_course_count.status = 2
  442. </when>
  443. </choose>
  444. </if>
  445. <if test="missCourseStatus != null and missCourseStatus !='' ">
  446. <choose>
  447. <when test = "missCourseStatus == 1">
  448. AND fs_user_course_count.miss_course_status = 1
  449. </when>
  450. <when test = "missCourseStatus == 2">
  451. AND fs_user_course_count.miss_course_status = 2
  452. </when>
  453. </choose>
  454. </if>
  455. <if test="continueMissCourseSort != null and continueMissCourseSort !='' ">
  456. order by
  457. <choose>
  458. <when test = "continueMissCourseSort == 0">
  459. fs_user_course_count.miss_course_days desc
  460. </when>
  461. <when test = "continueMissCourseSort == 1">
  462. fs_user_course_count.miss_course_days asc
  463. </when>
  464. <when test = "continueMissCourseSort == 2">
  465. fs_user.create_time desc
  466. </when>
  467. <when test = "continueMissCourseSort == 3">
  468. fs_user.nickname asc
  469. </when>
  470. </choose>
  471. </if>
  472. </select>
  473. <select id="getUserNumber" resultType="UserListCountVO">
  474. SELECT
  475. fs_user.`status` as status,
  476. count( fs_user.user_id ) as num
  477. FROM
  478. fs_user
  479. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  480. WHERE
  481. company_user.parent_id = #{userId}
  482. GROUP BY
  483. fs_user.`status`
  484. </select>
  485. <select id="getCountAnswer" resultType="UserDetailsVO">
  486. SELECT
  487. (
  488. SELECT
  489. ifnull(count( DISTINCT log_id ), 0) AS answerTime
  490. FROM
  491. fs_course_answer_logs
  492. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  493. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  494. WHERE
  495. company_user.parent_id = #{userId}
  496. <if test="dateTag != null and dateTag !='' ">
  497. <choose>
  498. <when test = "dateTag == '今天'">
  499. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  500. </when>
  501. <when test = "dateTag == ' 昨天'">
  502. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 1
  503. </when>
  504. <when test = "dateTag == '前天'">
  505. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 2
  506. </when>
  507. <when test = "dateTag == '近七天'">
  508. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_answer_logs.create_time)
  509. </when>
  510. </choose>
  511. </if>
  512. GROUP BY
  513. fs_user.user_id
  514. HAVING
  515. fs_user.user_id = #{fsUserId}
  516. ) AS answerTime,
  517. (
  518. SELECT
  519. ifnull(count( DISTINCT log_id ), 0) AS answerRightTime
  520. FROM
  521. fs_course_answer_logs
  522. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  523. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  524. WHERE
  525. company_user.parent_id = #{userId}
  526. AND fs_course_answer_logs.is_right = 1
  527. <if test="dateTag != null and dateTag !='' ">
  528. <choose>
  529. <when test = "dateTag == '今天'">
  530. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  531. </when>
  532. <when test = "dateTag == ' 昨天'">
  533. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 1
  534. </when>
  535. <when test = "dateTag == '前天'">
  536. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 2
  537. </when>
  538. <when test = "dateTag == '近七天'">
  539. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_answer_logs.create_time)
  540. </when>
  541. </choose>
  542. </if>
  543. GROUP BY
  544. fs_user.user_id
  545. HAVING
  546. fs_user.user_id = #{fsUserId}
  547. ) AS answerRightTime;
  548. </select>
  549. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  550. SELECT
  551. ifnull( count( DISTINCT log_id ), 0 ) AS answerRedPacketTime,
  552. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  553. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  554. ifnull( watch_times, 0 ) AS watchTimes,
  555. fs_user.user_id
  556. FROM
  557. fs_course_red_packet_log
  558. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  559. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  560. LEFT JOIN fs_user_course_count ON fs_user_course_count.user_id = fs_user.user_id
  561. WHERE
  562. company_user.parent_id = #{userId}
  563. <if test="dateTag != null and dateTag !='' ">
  564. <choose>
  565. <when test = "dateTag == '今天'">
  566. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  567. </when>
  568. <when test = "dateTag == ' 昨天'">
  569. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 1
  570. </when>
  571. <when test = "dateTag == '前天'">
  572. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 2
  573. </when>
  574. <when test = "dateTag == '近七天'">
  575. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_red_packet_log.create_time)
  576. </when>
  577. </choose>
  578. </if>
  579. GROUP BY
  580. fs_user.user_id
  581. HAVING
  582. fs_user.user_id = #{fsUserId}
  583. </select>
  584. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  585. select
  586. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  587. count(u.user_id) vipCount
  588. from fs_user u
  589. where u.company_user_id = #{companyUserId}
  590. </select>
  591. <update id="batchUpdateFsUserByIds" parameterType="Long">
  592. update fs_user
  593. set status = #{status} where user_id in
  594. <foreach item="id" collection="ids" open="(" separator="," close=")">
  595. #{id}
  596. </foreach>
  597. </update>
  598. <select id="countUserSummary" resultType="FsUserSummaryCountVO">
  599. SELECT (SELECT count(fs_user.user_id)
  600. FROM fs_user
  601. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  602. WHERE (
  603. company_user.user_id = #{userId}
  604. OR company_user.parent_id = #{userId}
  605. )) as userTotal,
  606. (SELECT count(fs_user.user_id)
  607. FROM fs_user
  608. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  609. WHERE (company_user.user_id = #{userId} OR company_user.parent_id = #{userId})
  610. AND to_days(fs_user.create_time) = to_days(now())) as todayNewUser
  611. </select>
  612. <select id="countTag" resultType="FsUserSummaryCountTagVO">
  613. SELECT
  614. company_tag.tag AS tagName,
  615. count( fs_user.user_id ) AS userCount
  616. FROM
  617. company_tag_user
  618. LEFT JOIN fs_user ON fs_user.user_id = company_tag_user.user_id
  619. LEFT JOIN company_tag ON FIND_IN_SET( company_tag.tag_id, company_tag_user.tag_ids ) > 0
  620. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  621. where (company_user.user_id = #{userId} or company_user.parent_id = #{userId} ) and company_tag.tag_id is not null
  622. GROUP BY
  623. company_tag.tag_id
  624. </select>
  625. <select id="countUserCourse" resultType="Map">
  626. SELECT
  627. (
  628. SELECT
  629. count(distinct fcc.user_id )
  630. FROM
  631. fs_user_course_count fcc
  632. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  633. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  634. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  635. WHERE
  636. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  637. <if test="startTime != null and startTime !='' ">
  638. and fcc.create_time &gt;= #{startTime}
  639. </if>
  640. <if test="endTime != null and endTime != ''">
  641. and fcc.create_time &lt;= #{endTime}
  642. </if>
  643. <if test="courseId != null and courseId != ''">
  644. AND fcc.course_id = #{courseId}
  645. </if>
  646. <if test="videoId != null and videoId != ''">
  647. AND fcv.video_id = #{videoId}
  648. </if>
  649. ) as courseWatchNum,
  650. (
  651. SELECT
  652. count(distinct fcc.user_id )
  653. FROM
  654. fs_user_course_count fcc
  655. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  656. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  657. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  658. WHERE
  659. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  660. AND fcc.complete_watch_count > 0
  661. <if test="startTime != null and startTime !='' ">
  662. and fcc.create_time &gt;= #{startTime}
  663. </if>
  664. <if test="endTime != null and endTime != ''">
  665. and fcc.create_time &lt;= #{endTime}
  666. </if>
  667. <if test="courseId != null and courseId != ''">
  668. AND fcc.course_id = #{courseId}
  669. </if>
  670. <if test="videoId != null and videoId != ''">
  671. AND fcv.video_id = #{videoId}
  672. </if>
  673. ) as courseCompleteNum
  674. </select>
  675. <select id="countUserAnswer" resultType="Map">
  676. SELECT
  677. (
  678. SELECT
  679. count(distinct fs_user.user_id )
  680. FROM
  681. fs_course_answer_logs
  682. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  683. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  684. WHERE
  685. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  686. <if test="startTime != null and startTime !='' ">
  687. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  688. </if>
  689. <if test="endTime != null and endTime != ''">
  690. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  691. </if>
  692. <if test="courseId != null and courseId != ''">
  693. AND fs_course_answer_logs.course_id = #{courseId}
  694. </if>
  695. <if test="videoId != null and videoId != ''">
  696. AND fs_course_answer_logs.video_id = #{videoId}
  697. </if>
  698. ) AS answerNum,
  699. (
  700. SELECT
  701. count(distinct fs_user.user_id )
  702. FROM
  703. fs_course_answer_logs
  704. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  705. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  706. WHERE
  707. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  708. AND fs_course_answer_logs.is_right = 1
  709. <if test="startTime != null and startTime !='' ">
  710. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  711. </if>
  712. <if test="endTime != null and endTime != ''">
  713. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  714. </if>
  715. <if test="courseId != null and courseId != ''">
  716. AND fs_course_answer_logs.course_id = #{courseId}
  717. </if>
  718. <if test="videoId != null and videoId != ''">
  719. AND fs_course_answer_logs.video_id = #{videoId}
  720. </if>
  721. ) AS answerRightNum
  722. </select>
  723. <select id="countUserRedPacket" resultType="Map">
  724. SELECT
  725. (
  726. SELECT
  727. count( flog.log_id )
  728. FROM
  729. fs_course_red_packet_log flog
  730. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  731. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  732. WHERE
  733. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  734. <if test="startTime != null and startTime !='' ">
  735. AND flog.create_time &gt;= #{startTime}
  736. </if>
  737. <if test="endTime != null and endTime != ''">
  738. AND flog.create_time &lt;= #{endTime}
  739. </if>
  740. <if test="courseId != null and courseId != ''">
  741. AND flog.course_id = #{courseId}
  742. </if>
  743. <if test="videoId != null and videoId != ''">
  744. AND flog.video_id = #{videoId}
  745. </if>
  746. ) AS redPacketNum,
  747. (
  748. SELECT
  749. ifnull (sum( flog.amount ), 0)
  750. FROM
  751. fs_course_red_packet_log flog
  752. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  753. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  754. WHERE
  755. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  756. <if test="startTime != null and startTime !='' ">
  757. AND flog.create_time &gt;= #{startTime}
  758. </if>
  759. <if test="endTime != null and endTime != ''">
  760. AND flog.create_time &lt;= #{endTime}
  761. </if>
  762. <if test="courseId != null and courseId != ''">
  763. AND flog.course_id = #{courseId}
  764. </if>
  765. <if test="videoId != null and videoId != ''">
  766. AND flog.video_id = #{videoId}
  767. </if>
  768. ) AS redPacketAmount
  769. </select>
  770. <select id="countCourseDetails" resultType="Map">
  771. select (SELECT count(DISTINCT fc.course_id)
  772. FROM fs_user_course fc
  773. WHERE fc.is_del = 0
  774. AND FIND_IN_SET(#{companyId}, fc.company_ids)
  775. <if test="courseId != null and courseId != ''">
  776. AND fc.course_id = #{courseId}
  777. </if>
  778. ) as courseNum,
  779. (SELECT count(DISTINCT fcv.video_id)
  780. FROM fs_user_course_video fcv
  781. LEFT JOIN fs_user_course fc ON fc.course_id = fcv.course_id
  782. WHERE fc.is_del = 0
  783. AND FIND_IN_SET(#{companyId}, fc.company_ids)
  784. <if test="courseId != null and courseId != ''">
  785. AND fcv.course_id = #{courseId}
  786. </if>
  787. <if test="videoId != null and videoId != ''">
  788. AND fcv.video_id = #{videoId}
  789. </if>
  790. ) as videoNum,
  791. ( SELECT count(DISTINCT user_id ) FROM fs_user_course_count fcc
  792. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  793. <if test="courseId != null and courseId != ''">
  794. AND fcc.course_id = #{courseId}
  795. </if>
  796. <if test="videoId != null and videoId != ''">
  797. AND fcv.video_id = #{videoId}
  798. </if>
  799. ) as courseUserNum
  800. </select>
  801. <select id="countUserRankingByComplete" resultType="FsUserRankingVO">
  802. SELECT
  803. company_user.nick_name as userName,
  804. ifnull(
  805. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  806. ) as completeRate
  807. FROM
  808. fs_user_course_count fcc
  809. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  810. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  811. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  812. WHERE
  813. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  814. <if test="startTime != null and startTime !='' ">
  815. AND fcc.create_time &gt;= #{startTime}
  816. </if>
  817. <if test="endTime != null and endTime != ''">
  818. AND fcc.create_time &lt;= #{endTime}
  819. </if>
  820. <if test="courseId != null and courseId != ''">
  821. AND fcc.course_id = #{courseId}
  822. </if>
  823. <if test="videoId != null and videoId != ''">
  824. AND fcv.video_id = #{videoId}
  825. </if>
  826. group by fcc.user_id
  827. <choose>
  828. <when test="order != null and order == 'asc'">
  829. order by completeRate asc
  830. </when>
  831. <when test="order != null and order == 'desc'">
  832. order by completeRate desc
  833. </when>
  834. <otherwise>
  835. order by completeRate desc
  836. </otherwise>
  837. </choose>
  838. limit 20
  839. </select>
  840. <select id="countUserRankingByRight" resultType="FsUserRankingVO">
  841. SELECT
  842. company_user.nick_name as userName,
  843. ifnull(ROUND(
  844. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  845. *100,2),0
  846. ) as answerRightRate
  847. FROM
  848. fs_course_answer_logs
  849. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  850. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  851. WHERE
  852. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  853. <if test="startTime != null and startTime !='' ">
  854. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  855. </if>
  856. <if test="endTime != null and endTime != ''">
  857. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  858. </if>
  859. <if test="courseId != null and courseId != ''">
  860. AND fs_course_answer_logs.course_id = #{courseId}
  861. </if>
  862. <if test="videoId != null and videoId != ''">
  863. AND fs_course_answer_logs.video_id = #{videoId}
  864. </if>
  865. group by fs_user.user_id
  866. <choose>
  867. <when test="order != null and order == 'asc'">
  868. order by answerRightRate asc
  869. </when>
  870. <when test="order != null and order == 'desc'">
  871. order by answerRightRate desc
  872. </when>
  873. <otherwise>
  874. order by answerRightRate desc
  875. </otherwise>
  876. </choose>
  877. limit 20
  878. </select>
  879. <select id="countCourseRankingByComplete" resultType="FsCourseRankingVO">
  880. SELECT
  881. fcv.title AS videoName,
  882. ifnull(
  883. ROUND((
  884. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))* 100,
  885. 2
  886. ),
  887. 0
  888. ) AS completeRate
  889. FROM
  890. fs_user_course_count fcc
  891. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  892. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  893. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  894. WHERE
  895. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  896. <if test="startTime != null and startTime !='' ">
  897. AND fcc.create_time &gt;= #{startTime}
  898. </if>
  899. <if test="endTime != null and endTime != ''">
  900. AND fcc.create_time &lt;= #{endTime}
  901. </if>
  902. <if test="courseId != null and courseId != ''">
  903. AND fcc.course_id = #{courseId}
  904. </if>
  905. <if test="videoId != null and videoId != ''">
  906. AND fcv.video_id = #{videoId}
  907. </if>
  908. GROUP BY
  909. fcv.video_id
  910. <choose>
  911. <when test="order != null and order == 'asc'">
  912. ORDER BY completeRate asc
  913. </when>
  914. <when test="order != null and order == 'desc'">
  915. ORDER BY completeRate desc
  916. </when>
  917. <otherwise>
  918. ORDER BY completeRate desc
  919. </otherwise>
  920. </choose>
  921. LIMIT 20
  922. </select>
  923. <select id="countCourseRankingByRight" resultType="FsCourseRankingVO">
  924. SELECT
  925. fcv.title AS videoName,
  926. ifnull(
  927. ROUND(
  928. (
  929. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1)) * 100,
  930. 2
  931. ),
  932. 0
  933. ) AS answerRightRate
  934. FROM
  935. fs_course_answer_logs
  936. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  937. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  938. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  939. WHERE
  940. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  941. <if test="startTime != null and startTime !='' ">
  942. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  943. </if>
  944. <if test="endTime != null and endTime != ''">
  945. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  946. </if>
  947. <if test="courseId != null and courseId != ''">
  948. AND fs_course_answer_logs.course_id = #{courseId}
  949. </if>
  950. <if test="videoId != null and videoId != ''">
  951. AND fs_course_answer_logs.video_id = #{videoId}
  952. </if>
  953. GROUP BY
  954. fs_course_answer_logs.video_id
  955. <choose>
  956. <when test="order != null and order == 'asc'">
  957. ORDER BY answerRightRate asc
  958. </when>
  959. <when test="order != null and order == 'desc'">
  960. ORDER BY answerRightRate desc
  961. </when>
  962. <otherwise>
  963. ORDER BY answerRightRate desc
  964. </otherwise>
  965. </choose>
  966. LIMIT 20
  967. </select>
  968. </mapper>