FsUserMapper.xml 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  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="selectFsUserPageList" resultType="FsUserPageListVO">
  372. SELECT
  373. fs_user.*,
  374. fs_user_course_count.id,
  375. fs_user_course_count.watch_course_count,
  376. fs_user_course_count.miss_course_count,
  377. fs_user_course_count.miss_course_status,
  378. fs_user_course_count.course_id,
  379. fs_user_course_count.part_course_count,
  380. fs_user_course_count.last_watch_date,
  381. fs_user_course_count.STATUS AS courseCountStatus,
  382. fs_user_course_count.stop_watch_days,
  383. fs_user_course_count.complete_watch_date,
  384. GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
  385. GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
  386. company_user.nick_name as companyUserNickName
  387. FROM
  388. fs_user
  389. left join company_user on fs_user.company_user_id = company_user.user_id
  390. LEFT JOIN fs_user_course_count ON fs_user.user_id = fs_user_course_count.user_id
  391. LEFT JOIN company_tag_user ON fs_user.user_id = company_tag_user.user_id
  392. LEFT JOIN company_tag ON FIND_IN_SET(company_tag.tag_id, company_tag_user.tag_ids) > 0
  393. where 1 = 1
  394. <if test="userId != null and userId !='' ">
  395. and (company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  396. </if>
  397. <if test="companyUserId != null and companyUserId !='' ">
  398. and company_user.user_id = #{companyUserId}
  399. </if>
  400. <choose>
  401. <when test = "isBlack">
  402. AND fs_user.status = 0
  403. </when>
  404. <otherwise>
  405. AND fs_user.status = 1
  406. </otherwise>
  407. </choose>
  408. <if test="keyword != null and keyword !='' ">
  409. AND (fs_user.nickname LIKE concat('%',#{keyword},'%')
  410. or fs_user.phone LIKE concat('%',#{keyword},'%')
  411. )
  412. </if>
  413. <if test="registerStartTime != null and registerStartTime !='' ">
  414. AND fs_user.create_time &gt;= #{registerStartTime}
  415. </if>
  416. <if test="registerEndTime != null and registerEndTime !='' ">
  417. AND fs_user.create_time &lt;= #{registerEndTime}
  418. </if>
  419. <if test="tagIds != null and tagIds.length > 0">
  420. AND
  421. <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
  422. company_tag_user.tag_ids LIKE concat('%"',#{item},'"%')
  423. </foreach>
  424. </if>
  425. <if test="tabValue != null and tabValue !='' ">
  426. <choose>
  427. <when test = "tabValue == 1">
  428. AND DAY(fs_user.create_time) = DAY(NOW())
  429. </when>
  430. <when test = "tabValue == 2">
  431. AND DAY(fs_user_course_count.complete_watch_date) = DAY(NOW())
  432. </when>
  433. <when test = "tabValue == 3">
  434. AND fs_user_course_count.status = 3
  435. </when>
  436. </choose>
  437. </if>
  438. <if test="watchCourseType != null and watchCourseType !='' ">
  439. <choose>
  440. <when test = "watchCourseType == 1">
  441. AND fs_user_course_count.status = 3
  442. </when>
  443. <when test = "watchCourseType == 2">
  444. AND fs_user_course_count.status = 1
  445. </when>
  446. <when test = "watchCourseType == 3">
  447. AND fs_user_course_count.status = 2
  448. </when>
  449. </choose>
  450. </if>
  451. <if test="missCourseStatus != null and missCourseStatus !='' ">
  452. <choose>
  453. <when test = "missCourseStatus == 1">
  454. AND fs_user_course_count.miss_course_status = 1
  455. </when>
  456. <when test = "missCourseStatus == 2">
  457. AND fs_user_course_count.miss_course_status = 2
  458. </when>
  459. </choose>
  460. </if>
  461. <if test="nickname != null and nickname !='' ">
  462. AND nickname LIKE concat('%"',#{nickname},'"%')
  463. </if>
  464. <if test="phone != null and phone !='' ">
  465. AND phone LIKE concat('%"',#{phone},'"%')
  466. </if>
  467. group by fs_user.user_id
  468. <if test="continueMissCourseSort != null and continueMissCourseSort !='' ">
  469. order by
  470. <choose>
  471. <when test = "continueMissCourseSort == 0">
  472. fs_user_course_count.miss_course_days desc
  473. </when>
  474. <when test = "continueMissCourseSort == 1">
  475. fs_user_course_count.miss_course_days asc
  476. </when>
  477. <when test = "continueMissCourseSort == 2">
  478. fs_user.create_time desc
  479. </when>
  480. <when test = "continueMissCourseSort == 3">
  481. fs_user.nickname asc
  482. </when>
  483. </choose>
  484. </if>
  485. </select>
  486. <select id="getUserNumber" resultType="UserListCountVO">
  487. SELECT
  488. fs_user.`status` as status,
  489. count( fs_user.user_id ) as num
  490. FROM
  491. fs_user
  492. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  493. WHERE
  494. company_user.parent_id = #{userId}
  495. GROUP BY
  496. fs_user.`status`
  497. </select>
  498. <select id="getCountAnswer" resultType="UserDetailsVO">
  499. SELECT
  500. (
  501. SELECT
  502. ifnull(count( DISTINCT log_id ), 0) AS answerTime
  503. FROM
  504. fs_course_answer_logs
  505. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  506. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  507. WHERE
  508. company_user.parent_id = #{userId}
  509. <if test="dateTag != null and dateTag !='' ">
  510. <choose>
  511. <when test = "dateTag == '今天'">
  512. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  513. </when>
  514. <when test = "dateTag == ' 昨天'">
  515. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 1
  516. </when>
  517. <when test = "dateTag == '前天'">
  518. and to_days(now()) - to_days(fs_course_answer_logs.create_time) &lt;= 2
  519. </when>
  520. <when test = "dateTag == '近七天'">
  521. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_answer_logs.create_time)
  522. </when>
  523. </choose>
  524. </if>
  525. GROUP BY
  526. fs_user.user_id
  527. HAVING
  528. fs_user.user_id = #{fsUserId}
  529. ) AS answerTime,
  530. (
  531. SELECT
  532. ifnull(count( DISTINCT log_id ), 0) AS answerRightTime
  533. FROM
  534. fs_course_answer_logs
  535. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  536. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  537. WHERE
  538. company_user.parent_id = #{userId}
  539. AND fs_course_answer_logs.is_right = 1
  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 answerRightTime;
  561. </select>
  562. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  563. SELECT
  564. ifnull( count( DISTINCT log_id ), 0 ) AS answerRedPacketTime,
  565. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  566. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  567. ifnull( watch_times, 0 ) AS watchTimes,
  568. fs_user.user_id
  569. FROM
  570. fs_course_red_packet_log
  571. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  572. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  573. LEFT JOIN fs_user_course_count ON fs_user_course_count.user_id = fs_user.user_id
  574. WHERE
  575. company_user.parent_id = #{userId}
  576. <if test="dateTag != null and dateTag !='' ">
  577. <choose>
  578. <when test = "dateTag == '今天'">
  579. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  580. </when>
  581. <when test = "dateTag == ' 昨天'">
  582. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 1
  583. </when>
  584. <when test = "dateTag == '前天'">
  585. and to_days(now()) - to_days(fs_course_red_packet_log.create_time) &lt;= 2
  586. </when>
  587. <when test = "dateTag == '近七天'">
  588. and DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;= date(fs_course_red_packet_log.create_time)
  589. </when>
  590. </choose>
  591. </if>
  592. GROUP BY
  593. fs_user.user_id
  594. HAVING
  595. fs_user.user_id = #{fsUserId}
  596. </select>
  597. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  598. select
  599. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  600. count(u.user_id) vipCount
  601. from fs_user u
  602. where u.company_user_id = #{companyUserId}
  603. </select>
  604. <update id="batchUpdateFsUserByIds" parameterType="Long">
  605. update fs_user
  606. set status = #{status} where user_id in
  607. <foreach item="id" collection="ids" open="(" separator="," close=")">
  608. #{id}
  609. </foreach>
  610. </update>
  611. <select id="countUserSummary" resultType="FsUserSummaryCountVO">
  612. SELECT (SELECT count(fs_user.user_id)
  613. FROM fs_user
  614. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  615. WHERE (
  616. company_user.user_id = #{userId}
  617. OR company_user.parent_id = #{userId}
  618. )) as userTotal,
  619. (SELECT count(fs_user.user_id)
  620. FROM fs_user
  621. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  622. WHERE (company_user.user_id = #{userId} OR company_user.parent_id = #{userId})
  623. AND to_days(fs_user.create_time) = to_days(now())) as todayNewUser
  624. </select>
  625. <select id="countTag" resultType="FsUserSummaryCountTagVO">
  626. SELECT
  627. company_tag.tag AS tagName,
  628. count( fs_user.user_id ) AS userCount
  629. FROM
  630. company_tag_user
  631. LEFT JOIN fs_user ON fs_user.user_id = company_tag_user.user_id
  632. LEFT JOIN company_tag ON FIND_IN_SET( company_tag.tag_id, company_tag_user.tag_ids ) > 0
  633. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  634. where (company_user.user_id = #{userId} or company_user.parent_id = #{userId} ) and company_tag.tag_id is not null
  635. GROUP BY
  636. company_tag.tag_id
  637. </select>
  638. <select id="countUserCourse" resultType="Map">
  639. SELECT
  640. (
  641. SELECT
  642. count(distinct fcc.user_id )
  643. FROM
  644. fs_user_course_count fcc
  645. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  646. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  647. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  648. WHERE
  649. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  650. <if test="startTime != null and startTime !='' ">
  651. and fcc.create_time &gt;= #{startTime}
  652. </if>
  653. <if test="endTime != null and endTime != ''">
  654. and fcc.create_time &lt;= #{endTime}
  655. </if>
  656. <if test="courseId != null and courseId != ''">
  657. AND fcc.course_id = #{courseId}
  658. </if>
  659. <if test="videoId != null and videoId != ''">
  660. AND fcv.video_id = #{videoId}
  661. </if>
  662. <if test="videoId != null and videoId != ''">
  663. AND fcv.video_id = #{videoId}
  664. </if>
  665. -- 单独通过销售id查询
  666. <if test="companyUserId != null and companyUserId != ''">
  667. AND company_user.user_id = #{companyUserId}
  668. </if>
  669. ) as courseWatchNum,
  670. (
  671. SELECT
  672. count(distinct fcc.user_id )
  673. FROM
  674. fs_user_course_count fcc
  675. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  676. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  677. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  678. WHERE
  679. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  680. AND fcc.complete_watch_count > 0
  681. <if test="startTime != null and startTime !='' ">
  682. and fcc.create_time &gt;= #{startTime}
  683. </if>
  684. <if test="endTime != null and endTime != ''">
  685. and fcc.create_time &lt;= #{endTime}
  686. </if>
  687. <if test="courseId != null and courseId != ''">
  688. AND fcc.course_id = #{courseId}
  689. </if>
  690. <if test="videoId != null and videoId != ''">
  691. AND fcv.video_id = #{videoId}
  692. </if>
  693. -- 单独通过销售id查询
  694. <if test="companyUserId != null and companyUserId != ''">
  695. AND company_user.user_id = #{companyUserId}
  696. </if>
  697. ) as courseCompleteNum
  698. </select>
  699. <select id="countUserAnswer" resultType="Map">
  700. SELECT
  701. (
  702. SELECT
  703. count(distinct fs_user.user_id )
  704. FROM
  705. fs_course_answer_logs
  706. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  707. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  708. WHERE
  709. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  710. <if test="startTime != null and startTime !='' ">
  711. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  712. </if>
  713. <if test="endTime != null and endTime != ''">
  714. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  715. </if>
  716. <if test="courseId != null and courseId != ''">
  717. AND fs_course_answer_logs.course_id = #{courseId}
  718. </if>
  719. <if test="videoId != null and videoId != ''">
  720. AND fs_course_answer_logs.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 answerNum,
  727. (
  728. SELECT
  729. count(distinct fs_user.user_id )
  730. FROM
  731. fs_course_answer_logs
  732. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  733. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  734. WHERE
  735. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  736. AND fs_course_answer_logs.is_right = 1
  737. <if test="startTime != null and startTime !='' ">
  738. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  739. </if>
  740. <if test="endTime != null and endTime != ''">
  741. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  742. </if>
  743. <if test="courseId != null and courseId != ''">
  744. AND fs_course_answer_logs.course_id = #{courseId}
  745. </if>
  746. <if test="videoId != null and videoId != ''">
  747. AND fs_course_answer_logs.video_id = #{videoId}
  748. </if>
  749. -- 单独通过销售id查询
  750. <if test="companyUserId != null and companyUserId != ''">
  751. AND company_user.user_id = #{companyUserId}
  752. </if>
  753. ) AS answerRightNum
  754. </select>
  755. <select id="countUserRedPacket" resultType="Map">
  756. SELECT
  757. (
  758. SELECT
  759. count( flog.log_id )
  760. FROM
  761. fs_course_red_packet_log flog
  762. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  763. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  764. WHERE
  765. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  766. <if test="startTime != null and startTime !='' ">
  767. AND flog.create_time &gt;= #{startTime}
  768. </if>
  769. <if test="endTime != null and endTime != ''">
  770. AND flog.create_time &lt;= #{endTime}
  771. </if>
  772. <if test="courseId != null and courseId != ''">
  773. AND flog.course_id = #{courseId}
  774. </if>
  775. <if test="videoId != null and videoId != ''">
  776. AND flog.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 redPacketNum,
  783. (
  784. SELECT
  785. ifnull (sum( flog.amount ), 0)
  786. FROM
  787. fs_course_red_packet_log flog
  788. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  789. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  790. WHERE
  791. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  792. <if test="startTime != null and startTime !='' ">
  793. AND flog.create_time &gt;= #{startTime}
  794. </if>
  795. <if test="endTime != null and endTime != ''">
  796. AND flog.create_time &lt;= #{endTime}
  797. </if>
  798. <if test="courseId != null and courseId != ''">
  799. AND flog.course_id = #{courseId}
  800. </if>
  801. <if test="videoId != null and videoId != ''">
  802. AND flog.video_id = #{videoId}
  803. </if>
  804. -- 单独通过销售id查询
  805. <if test="companyUserId != null and companyUserId != ''">
  806. AND company_user.user_id = #{companyUserId}
  807. </if>
  808. ) AS redPacketAmount
  809. </select>
  810. <select id="countCourseDetails" resultType="Map">
  811. select (SELECT count(DISTINCT fc.course_id)
  812. FROM fs_user_course fc
  813. LEFT JOIN fs_user_course_count fcc ON fcc.course_id = fc.course_id
  814. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  815. WHERE fc.is_del = 0
  816. AND FIND_IN_SET(#{companyId}, fc.company_ids)
  817. <if test="courseId != null and courseId != ''">
  818. AND fc.course_id = #{courseId}
  819. </if>
  820. -- 单独通过销售id查询
  821. <if test="companyUserId != null and companyUserId != ''">
  822. AND fs_user.company_user_id = #{companyUserId}
  823. </if>
  824. ) as courseNum,
  825. (SELECT count(DISTINCT fcv.video_id)
  826. FROM fs_user_course_video fcv
  827. LEFT JOIN fs_user_course fc ON fc.course_id = fcv.course_id
  828. LEFT JOIN fs_user_course_count fcc ON fcc.course_id = fc.course_id
  829. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  830. WHERE fc.is_del = 0
  831. AND FIND_IN_SET(#{companyId}, fc.company_ids)
  832. <if test="courseId != null and courseId != ''">
  833. AND fcv.course_id = #{courseId}
  834. </if>
  835. <if test="videoId != null and videoId != ''">
  836. AND fcv.video_id = #{videoId}
  837. </if>
  838. -- 单独通过销售id查询
  839. <if test="companyUserId != null and companyUserId != ''">
  840. AND fs_user.company_user_id = #{companyUserId}
  841. </if>
  842. ) as videoNum,
  843. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  844. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  845. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  846. <if test="courseId != null and courseId != ''">
  847. AND fcc.course_id = #{courseId}
  848. </if>
  849. <if test="videoId != null and videoId != ''">
  850. AND fcv.video_id = #{videoId}
  851. </if>
  852. -- 单独通过销售id查询
  853. <if test="companyUserId != null and companyUserId != ''">
  854. AND fs_user.company_user_id = #{companyUserId}
  855. </if>
  856. ) as courseUserNum
  857. </select>
  858. <select id="countUserRankingByComplete" resultType="FsUserRankingVO">
  859. SELECT
  860. company_user.nick_name as userName,
  861. ifnull(
  862. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  863. ) as completeRate
  864. FROM
  865. fs_user_course_count fcc
  866. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  867. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  868. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  869. WHERE
  870. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  871. <if test="startTime != null and startTime !='' ">
  872. AND fcc.create_time &gt;= #{startTime}
  873. </if>
  874. <if test="endTime != null and endTime != ''">
  875. AND fcc.create_time &lt;= #{endTime}
  876. </if>
  877. <if test="courseId != null and courseId != ''">
  878. AND fcc.course_id = #{courseId}
  879. </if>
  880. <if test="videoId != null and videoId != ''">
  881. AND fcv.video_id = #{videoId}
  882. </if>
  883. group by fcc.user_id
  884. <choose>
  885. <when test="order != null and order == 'asc'">
  886. order by completeRate asc
  887. </when>
  888. <when test="order != null and order == 'desc'">
  889. order by completeRate desc
  890. </when>
  891. <otherwise>
  892. order by completeRate desc
  893. </otherwise>
  894. </choose>
  895. limit 20
  896. </select>
  897. <select id="countUserRankingByRight" resultType="FsUserRankingVO">
  898. SELECT
  899. company_user.nick_name as userName,
  900. ifnull(ROUND(
  901. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  902. *100,2),0
  903. ) as answerRightRate
  904. FROM
  905. fs_course_answer_logs
  906. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  907. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  908. WHERE
  909. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  910. <if test="startTime != null and startTime !='' ">
  911. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  912. </if>
  913. <if test="endTime != null and endTime != ''">
  914. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  915. </if>
  916. <if test="courseId != null and courseId != ''">
  917. AND fs_course_answer_logs.course_id = #{courseId}
  918. </if>
  919. <if test="videoId != null and videoId != ''">
  920. AND fs_course_answer_logs.video_id = #{videoId}
  921. </if>
  922. group by fs_user.user_id
  923. <choose>
  924. <when test="order != null and order == 'asc'">
  925. order by answerRightRate asc
  926. </when>
  927. <when test="order != null and order == 'desc'">
  928. order by answerRightRate desc
  929. </when>
  930. <otherwise>
  931. order by answerRightRate desc
  932. </otherwise>
  933. </choose>
  934. limit 20
  935. </select>
  936. <select id="countCourseRankingByComplete" resultType="FsCourseRankingVO">
  937. SELECT
  938. fcv.title AS videoName,
  939. ifnull(
  940. ROUND((
  941. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))* 100,
  942. 2
  943. ),
  944. 0
  945. ) AS completeRate
  946. FROM
  947. fs_user_course_count fcc
  948. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  949. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  950. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  951. WHERE
  952. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  953. <if test="startTime != null and startTime !='' ">
  954. AND fcc.create_time &gt;= #{startTime}
  955. </if>
  956. <if test="endTime != null and endTime != ''">
  957. AND fcc.create_time &lt;= #{endTime}
  958. </if>
  959. <if test="courseId != null and courseId != ''">
  960. AND fcc.course_id = #{courseId}
  961. </if>
  962. <if test="videoId != null and videoId != ''">
  963. AND fcv.video_id = #{videoId}
  964. </if>
  965. GROUP BY
  966. fcv.video_id
  967. <choose>
  968. <when test="order != null and order == 'asc'">
  969. ORDER BY completeRate asc
  970. </when>
  971. <when test="order != null and order == 'desc'">
  972. ORDER BY completeRate desc
  973. </when>
  974. <otherwise>
  975. ORDER BY completeRate desc
  976. </otherwise>
  977. </choose>
  978. LIMIT 20
  979. </select>
  980. <select id="countCourseRankingByRight" resultType="FsCourseRankingVO">
  981. SELECT
  982. fcv.title AS videoName,
  983. ifnull(
  984. ROUND(
  985. (
  986. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1)) * 100,
  987. 2
  988. ),
  989. 0
  990. ) AS answerRightRate
  991. FROM
  992. fs_course_answer_logs
  993. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  994. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  995. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  996. WHERE
  997. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  998. <if test="startTime != null and startTime !='' ">
  999. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1000. </if>
  1001. <if test="endTime != null and endTime != ''">
  1002. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1003. </if>
  1004. <if test="courseId != null and courseId != ''">
  1005. AND fs_course_answer_logs.course_id = #{courseId}
  1006. </if>
  1007. <if test="videoId != null and videoId != ''">
  1008. AND fs_course_answer_logs.video_id = #{videoId}
  1009. </if>
  1010. GROUP BY
  1011. fs_course_answer_logs.video_id
  1012. <choose>
  1013. <when test="order != null and order == 'asc'">
  1014. ORDER BY answerRightRate asc
  1015. </when>
  1016. <when test="order != null and order == 'desc'">
  1017. ORDER BY answerRightRate desc
  1018. </when>
  1019. <otherwise>
  1020. ORDER BY answerRightRate desc
  1021. </otherwise>
  1022. </choose>
  1023. LIMIT 20
  1024. </select>
  1025. <!-- 查询某用户的课程视频,看课统计 -->
  1026. <select id="courseAnalysisCourseCount" resultType="FsCourseAnalysisCountVO">
  1027. SELECT
  1028. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1029. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1030. ifnull(
  1031. ROUND(
  1032. (
  1033. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1034. 2
  1035. ),
  1036. 0
  1037. ) as completeRate,
  1038. fcv.video_id
  1039. FROM
  1040. fs_user_course_count fcc
  1041. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1042. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1043. LEFT JOIN fs_user_course_video fcv ON fcv.course_id = fcc.course_id
  1044. WHERE
  1045. company_user.user_id = #{companyUserId}
  1046. and fcv.is_del = 0
  1047. <if test="courseId != null and courseId != ''">
  1048. AND fcc.course_id = #{courseId}
  1049. </if>
  1050. <if test="videoId != null and videoId != ''">
  1051. AND fcv.video_id = #{videoId}
  1052. </if>
  1053. GROUP BY
  1054. fcv.video_id
  1055. </select>
  1056. <!-- 查询某用户的课程视频,红包统计 -->
  1057. <select id="courseAnalysisRedPacketCount" resultType="FsCourseAnalysisCountVO">
  1058. SELECT
  1059. count( flog.log_id ) as redPacketNum,
  1060. ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
  1061. flog.video_id
  1062. FROM
  1063. fs_course_red_packet_log flog
  1064. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1065. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1066. WHERE
  1067. company_user.user_id = #{companyUserId}
  1068. <if test="courseId != null and courseId != ''">
  1069. AND flog.course_id = #{courseId}
  1070. </if>
  1071. <if test="videoId != null and videoId != ''">
  1072. AND flog.video_id = #{videoId}
  1073. </if>
  1074. GROUP BY
  1075. flog.video_id
  1076. </select>
  1077. <!-- 查询某用户的课程视频,答题统计 -->
  1078. <select id="courseAnalysisAnswerCount" resultType="FsCourseAnalysisCountVO">
  1079. SELECT
  1080. count( DISTINCT fs_user.user_id ) as answerNum,
  1081. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
  1082. ifnull(
  1083. ROUND(
  1084. (
  1085. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  1086. 2
  1087. ),
  1088. 0
  1089. ) as answerRightRate,
  1090. fs_course_answer_logs.video_id
  1091. FROM
  1092. fs_course_answer_logs
  1093. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1094. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1095. WHERE
  1096. company_user.user_id = #{companyUserId}
  1097. <if test="courseId != null and courseId != ''">
  1098. AND fs_course_answer_logs.course_id = #{courseId}
  1099. </if>
  1100. <if test="videoId != null and videoId != ''">
  1101. AND fs_course_answer_logs.video_id = #{videoId}
  1102. </if>
  1103. GROUP BY
  1104. fs_course_answer_logs.video_id
  1105. </select>
  1106. <select id="companyUserCount" resultType="CompanyUserSummaryCountVO">
  1107. SELECT
  1108. (
  1109. SELECT count( fs_user.user_id ) FROM fs_user LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1110. WHERE company_user.user_id = #{companyUserId}
  1111. ) AS userTotal,
  1112. (
  1113. SELECT
  1114. count( fs_user.user_id )
  1115. FROM
  1116. fs_user
  1117. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1118. WHERE
  1119. company_user.user_id = #{companyUserId}
  1120. AND to_days( fs_user.create_time ) = to_days(
  1121. now())
  1122. ) AS todayNewUser
  1123. </select>
  1124. <select id="newUserRedPacketCount" resultType="CompanyUserSummaryCountVO">
  1125. SELECT
  1126. count(flog.log_id) as userRedPacketNum,
  1127. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1128. FROM
  1129. fs_course_red_packet_log flog
  1130. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1131. WHERE
  1132. fs_user.company_user_id = #{companyUserId}
  1133. </select>
  1134. </mapper>