FsUserMapper.xml 58 KB

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