FsUserMapper.xml 65 KB

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