FsUserMapper.xml 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  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. <result property="qwRepeat" column="qw_repeat"/>
  48. <result property="userRepeat" column="user_repeat"/>
  49. <result property="payOrder" column="pay_order"/>
  50. <result property="isBecomeMember" column="is_become_member"/>
  51. </resultMap>
  52. <sql id="selectFsUserVo">
  53. select user_id,
  54. qw_ext_id,
  55. is_show,
  56. username,
  57. password,
  58. real_name,
  59. birthday,
  60. id_card,
  61. remark,
  62. nickname,
  63. avatar,
  64. phone,
  65. create_time,
  66. update_time,
  67. last_ip,
  68. now_money,
  69. brokerage_price,
  70. integral,
  71. sign_num,
  72. status,
  73. level,
  74. spread_user_id,
  75. spread_time,
  76. user_type,
  77. is_promoter,
  78. pay_count,
  79. spread_count,
  80. addres,
  81. ma_open_id,
  82. mp_open_id,
  83. union_id,
  84. is_del,
  85. is_weixin_auth,
  86. company_id,
  87. is_add_qw,
  88. company_user_id,
  89. register_date,
  90. register_code,
  91. source,
  92. user_code,
  93. qw_repeat,
  94. user_repeat,
  95. pay_order,
  96. is_become_member
  97. from fs_user
  98. </sql>
  99. <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
  100. <include refid="selectFsUserVo"/>
  101. <where>
  102. <if test="username != null and username != ''">and username like concat('%', #{username}, '%')</if>
  103. <if test="password != null and password != ''">and password = #{password}</if>
  104. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  105. <if test="birthday != null ">and birthday = #{birthday}</if>
  106. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  107. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  108. <if test="nickname != null and nickname != ''">and nickname like concat('%', #{nickname}, '%')</if>
  109. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  110. <if test="phone != null and phone != ''">and phone = #{phone}</if>
  111. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  112. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  113. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  114. <if test="integral != null ">and integral = #{integral}</if>
  115. <if test="signNum != null ">and sign_num = #{signNum}</if>
  116. <if test="status != null ">and status = #{status}</if>
  117. <if test="level != null ">and level = #{level}</if>
  118. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  119. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  120. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  121. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  122. <if test="payCount != null ">and pay_count = #{payCount}</if>
  123. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  124. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  125. <if test="isDel != null ">and is_del = #{isDel}</if>
  126. <if test="companyId != null ">and company_id = #{companyId}</if>
  127. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  128. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  129. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  130. </if>
  131. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  132. <if test="source != null and source != '' ">and source = #{source}</if>
  133. <if test="isShow != null ">and is_show = #{isShow}</if>
  134. <if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  135. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>
  136. <if test="payOrder != null ">and pay_order = #{payOrder}</if>
  137. </where>
  138. order by user_id desc
  139. </select>
  140. <select id="selectFsUserById" parameterType="Long" resultMap="FsUserResult">
  141. <include refid="selectFsUserVo"/>
  142. where user_id = #{userId}
  143. </select>
  144. <select id="selectFsUserListLimit" resultType="com.fs.store.domain.FsUser">
  145. <include refid="selectFsUserVo"/>
  146. <where>
  147. <if test="password != null and password != ''">and password = #{password}</if>
  148. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  149. <if test="birthday != null ">and birthday = #{birthday}</if>
  150. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  151. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  152. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  153. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  154. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  155. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  156. <if test="integral != null ">and integral = #{integral}</if>
  157. <if test="signNum != null ">and sign_num = #{signNum}</if>
  158. <if test="status != null ">and status = #{status}</if>
  159. <if test="level != null ">and level = #{level}</if>
  160. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  161. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  162. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  163. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  164. <if test="payCount != null ">and pay_count = #{payCount}</if>
  165. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  166. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  167. <if test="isDel != null ">and is_del = #{isDel}</if>
  168. <if test="companyId != null ">and company_id = #{companyId}</if>
  169. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  170. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  171. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  172. </if>
  173. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  174. <if test="source != null and source != '' ">and source = #{source}</if>
  175. <if test="isShow != null ">and is_show = #{isShow}</if>
  176. <if test="(username != null and username != '') or (nickname != null and nickname != '') or (phone != null and phone != '')">
  177. and (
  178. <if test="username != null and username != ''">username like concat('%', #{username}, '%')</if>
  179. <if test="nickname != null and nickname != ''">or nickname like concat('%', #{nickname}, '%')</if>
  180. <if test="phone != null and phone != ''">or phone like concat('%',#{phone},'%')</if>
  181. )
  182. </if>
  183. <if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  184. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>
  185. <if test="payOrder != null ">and pay_order = #{payOrder}</if>
  186. </where>
  187. order by user_id desc
  188. limit 10
  189. </select>
  190. <select id="selectCusListPage" resultType="com.fs.store.domain.FsUser">
  191. select user.user_id,
  192. user.username,
  193. user.real_name,
  194. user.id_card,
  195. user.phone,
  196. user.addres,
  197. user.nickname,
  198. user.status,
  199. user.company_id,
  200. user.company_user_id,
  201. user.create_time
  202. from
  203. fs_user `user` join (
  204. select user_id from fs_user
  205. <where>
  206. <if test="companyId != null and companyId != ''">
  207. AND company_id = #{companyId}
  208. </if>
  209. <if test="companyUserId != null and companyUserId != ''">
  210. AND company_user_id = #{companyUserId}
  211. </if>
  212. <if test="phone != null and phone != ''">
  213. AND phone = #{phone}
  214. </if>
  215. </where>
  216. order by user_id desc
  217. limit ${(pageNum-1)*pageSize},${pageSize}
  218. ) t on t.user_id = `user`.user_id
  219. </select>
  220. <select id="selectCusListPageCount" resultType="java.lang.Long">
  221. SELECT COUNT(user_id)
  222. FROM fs_user
  223. <where>
  224. <if test="companyId != null and companyId != ''">
  225. AND company_id = #{companyId}
  226. </if>
  227. <if test="companyUserId != null and companyUserId != ''">
  228. AND company_user_id = #{companyUserId}
  229. </if>
  230. <if test="phone != null and phone != ''">
  231. AND phone = #{phone}
  232. </if>
  233. </where>
  234. </select>
  235. <select id="selectFsUserVOList" resultType="com.fs.store.vo.FSUserVO">
  236. SELECT
  237. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  238. u.*,
  239. fcc.watch_course_count, fcc.part_course_count, company_user.nick_name AS companyUserNickName, fcc.last_watch_date
  240. ,company.company_name
  241. FROM
  242. fs_user u
  243. LEFT JOIN (
  244. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  245. user_id
  246. FROM
  247. fs_store_payment
  248. WHERE
  249. STATUS = 1
  250. AND user_id IS NOT NULL
  251. GROUP BY
  252. user_id
  253. ) b ON u.user_id = b.user_id
  254. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  255. AND b.last_buy_time = p.pay_time
  256. AND b.payment_id = p.payment_id
  257. LEFT JOIN (
  258. SELECT
  259. fs_user_course_count.user_id,Max( fs_user_course_count.last_watch_date ) AS last_watch_date,fs_user_course_count.watch_course_count,
  260. fs_user_course_count.part_course_count
  261. FROM
  262. fs_user_course_count
  263. GROUP BY fs_user_course_count.user_id
  264. ) fcc ON fcc.user_id = u.user_id
  265. LEFT JOIN company_user ON company_user.user_id = u.company_user_id
  266. LEFT JOIN company on company.company_id = company_user.company_id
  267. <where>
  268. <if test = "maps.userId != null" >
  269. AND u.user_id = #{maps.userId}
  270. </if >
  271. <if test = "maps.nickname != null and maps.nickname !='' " >
  272. AND u.nickname LIKE CONCAT("%",#{maps.nickname},"%")
  273. </if >
  274. <if test = "maps.phone != null and maps.phone !='' " >
  275. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  276. </if >
  277. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  278. AND (DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  279. and DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  280. )
  281. </if >
  282. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  283. AND u.register_code = #{maps.registerCode}
  284. </if >
  285. <if test = "maps.status != null" >
  286. AND u.STATUS = #{maps.status}
  287. </if >
  288. <if test = "maps.companyUserNickName != null and maps.companyUserNickName != '' " >
  289. AND company_user.nick_name like CONCAT ("%",#{maps.companyUserNickName},"%")
  290. </if >
  291. <if test = "maps.companyName != null and maps.companyName != '' " >
  292. AND company.company_name like CONCAT ("%",#{maps.companyName},"%")
  293. </if >
  294. <if test = "maps.level != null and maps.level !=''" >
  295. AND u.LEVEL = #{maps.level}
  296. </if >
  297. <if test = "maps.isPromoter != null and maps.isPromoter !=''" >
  298. AND u.is_promoter = #{maps.isPromoter}
  299. </if >
  300. </where>
  301. ORDER BY
  302. user_id DESC
  303. </select>
  304. <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
  305. insert into fs_user
  306. <trim prefix="(" suffix=")" suffixOverrides=",">
  307. <if test="username != null">username,</if>
  308. <if test="password != null">password,</if>
  309. <if test="realName != null">real_name,</if>
  310. <if test="birthday != null">birthday,</if>
  311. <if test="idCard != null">id_card,</if>
  312. <if test="remark != null">remark,</if>
  313. <if test="nickname != null">nickname,</if>
  314. <if test="avatar != null">avatar,</if>
  315. <if test="phone != null">phone,</if>
  316. <if test="createTime != null">create_time,</if>
  317. <if test="updateTime != null">update_time,</if>
  318. <if test="lastIp != null">last_ip,</if>
  319. <if test="nowMoney != null">now_money,</if>
  320. <if test="brokeragePrice != null">brokerage_price,</if>
  321. <if test="integral != null">integral,</if>
  322. <if test="signNum != null">sign_num,</if>
  323. <if test="status != null">status,</if>
  324. <if test="level != null">level,</if>
  325. <if test="spreadUserId != null">spread_user_id,</if>
  326. <if test="spreadTime != null">spread_time,</if>
  327. <if test="userType != null and userType != ''">user_type,</if>
  328. <if test="isPromoter != null">is_promoter,</if>
  329. <if test="payCount != null">pay_count,</if>
  330. <if test="spreadCount != null">spread_count,</if>
  331. <if test="addres != null and addres != ''">addres,</if>
  332. <if test="maOpenId != null">ma_open_id,</if>
  333. <if test="mpOpenId != null">mp_open_id,</if>
  334. <if test="unionId != null">union_id,</if>
  335. <if test="isDel != null">is_del,</if>
  336. <if test="isWeixinAuth != null">is_weixin_auth,</if>
  337. <if test="companyId != null">company_id,</if>
  338. <if test="companyUserId != null">company_user_id,</if>
  339. <if test="registerDate != null">register_date,</if>
  340. <if test="registerCode != null">register_code,</if>
  341. <if test="source != null">source,</if>
  342. <if test="userCode != null">user_code,</if>
  343. <if test="isShow != null">is_show,</if>
  344. <if test="qwExtId != null">qw_ext_id,</if>
  345. <if test="isAddQw != null">is_add_qw,</if>
  346. <if test="qwRepeat != null">qw_repeat,</if>
  347. <if test="userRepeat != null">user_repeat,</if>
  348. <if test="payOrder != null">pay_order,</if>
  349. <if test="isBecomeMember != null">is_become_member,</if>
  350. </trim>
  351. <trim prefix="values (" suffix=")" suffixOverrides=",">
  352. <if test="username != null">#{username},</if>
  353. <if test="password != null">#{password},</if>
  354. <if test="realName != null">#{realName},</if>
  355. <if test="birthday != null">#{birthday},</if>
  356. <if test="idCard != null">#{idCard},</if>
  357. <if test="remark != null">#{remark},</if>
  358. <if test="nickname != null">#{nickname},</if>
  359. <if test="avatar != null">#{avatar},</if>
  360. <if test="phone != null">#{phone},</if>
  361. <if test="createTime != null">#{createTime},</if>
  362. <if test="updateTime != null">#{updateTime},</if>
  363. <if test="lastIp != null">#{lastIp},</if>
  364. <if test="nowMoney != null">#{nowMoney},</if>
  365. <if test="brokeragePrice != null">#{brokeragePrice},</if>
  366. <if test="integral != null">#{integral},</if>
  367. <if test="signNum != null">#{signNum},</if>
  368. <if test="status != null">#{status},</if>
  369. <if test="level != null">#{level},</if>
  370. <if test="spreadUserId != null">#{spreadUserId},</if>
  371. <if test="spreadTime != null">#{spreadTime},</if>
  372. <if test="userType != null and userType != ''">#{userType},</if>
  373. <if test="isPromoter != null">#{isPromoter},</if>
  374. <if test="payCount != null">#{payCount},</if>
  375. <if test="spreadCount != null">#{spreadCount},</if>
  376. <if test="addres != null and addres != ''">#{addres},</if>
  377. <if test="maOpenId != null">#{maOpenId},</if>
  378. <if test="mpOpenId != null">#{mpOpenId},</if>
  379. <if test="unionId != null">#{unionId},</if>
  380. <if test="isDel != null">#{isDel},</if>
  381. <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
  382. <if test="companyId != null">#{companyId},</if>
  383. <if test="companyUserId != null">#{companyUserId},</if>
  384. <if test="registerDate != null">#{registerDate},</if>
  385. <if test="registerCode != null">#{registerCode},</if>
  386. <if test="source != null">#{source},</if>
  387. <if test="userCode != null">#{userCode},</if>
  388. <if test="isShow != null">#{isShow},</if>
  389. <if test="qwExtId != null">#{qwExtId},</if>
  390. <if test="isAddQw != null">#{isAddQw},</if>
  391. <if test="qwRepeat != null">#{qwRepeat},</if>
  392. <if test="userRepeat != null">#{userRepeat},</if>
  393. <if test="payOrder != null">#{payOrder},</if>
  394. <if test="isBecomeMember != null">#{isBecomeMember},</if>
  395. </trim>
  396. </insert>
  397. <update id="updateFsUser" parameterType="FsUser">
  398. update fs_user
  399. <trim prefix="SET" suffixOverrides=",">
  400. <if test="username != null">username = #{username},</if>
  401. <if test="password != null">password = #{password},</if>
  402. <if test="realName != null">real_name = #{realName},</if>
  403. <if test="birthday != null">birthday = #{birthday},</if>
  404. <if test="idCard != null">id_card = #{idCard},</if>
  405. <if test="remark != null">remark = #{remark},</if>
  406. <if test="nickname != null">nickname = #{nickname},</if>
  407. <if test="avatar != null">avatar = #{avatar},</if>
  408. <if test="phone != null">phone = #{phone},</if>
  409. <if test="createTime != null">create_time = #{createTime},</if>
  410. <if test="updateTime != null">update_time = #{updateTime},</if>
  411. <if test="lastIp != null">last_ip = #{lastIp},</if>
  412. <if test="nowMoney != null">now_money = #{nowMoney},</if>
  413. <if test="brokeragePrice != null">brokerage_price = #{brokeragePrice},</if>
  414. <if test="integral != null">integral = #{integral},</if>
  415. <if test="signNum != null">sign_num = #{signNum},</if>
  416. <if test="status != null">status = #{status},</if>
  417. <if test="level != null">level = #{level},</if>
  418. <if test="spreadUserId != null">spread_user_id = #{spreadUserId},</if>
  419. <if test="spreadTime != null">spread_time = #{spreadTime},</if>
  420. <if test="userType != null and userType != ''">user_type = #{userType},</if>
  421. <if test="isPromoter != null">is_promoter = #{isPromoter},</if>
  422. <if test="payCount != null">pay_count = #{payCount},</if>
  423. <if test="spreadCount != null">spread_count = #{spreadCount},</if>
  424. <if test="addres != null and addres != ''">addres = #{addres},</if>
  425. <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
  426. <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
  427. <if test="unionId != null">union_id = #{unionId},</if>
  428. <if test="isDel != null">is_del = #{isDel},</if>
  429. <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
  430. <if test="companyId != null">company_id = #{companyId},</if>
  431. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  432. <if test="registerDate != null">register_date = #{registerDate},</if>
  433. <if test="registerCode != null">register_code = #{registerCode},</if>
  434. <if test="source != null">source = #{source},</if>
  435. <if test="userCode != null">user_code = #{userCode},</if>
  436. <if test="isShow != null">is_show = #{isShow},</if>
  437. <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
  438. <if test="isAddQw != null">is_add_qw = #{isAddQw},</if>
  439. <if test="qwRepeat != null">qw_repeat = #{qwRepeat},</if>
  440. <if test="userRepeat != null">user_repeat = #{userRepeat},</if>
  441. <if test="payOrder != null">pay_order = #{payOrder},</if>
  442. <if test="isBecomeMember != null">is_become_member = #{isBecomeMember},</if>
  443. </trim>
  444. where user_id = #{userId}
  445. </update>
  446. <update id="transferCompanyUser">
  447. update fs_user
  448. set company_user_id=#{targetCompanyUserId}
  449. where
  450. user_id in
  451. <foreach collection="userIds" open="(" close=")" separator="," item="item">
  452. ${item}
  453. </foreach>
  454. </update>
  455. <delete id="deleteFsUserById" parameterType="Long">
  456. delete
  457. from fs_user
  458. where user_id = #{userId}
  459. </delete>
  460. <delete id="deleteFsUserByIds" parameterType="String">
  461. delete from fs_user where user_id in
  462. <foreach item="userId" collection="array" open="(" separator="," close=")">
  463. #{userId}
  464. </foreach>
  465. </delete>
  466. <select id="selectFsUserPageListNew" resultType="FsUserPageListVO">
  467. SELECT
  468. fs_user.user_id,
  469. fs_user.nickname,
  470. fs_user.avatar,
  471. fs_user.phone,
  472. fs_user.status,
  473. fs_user.create_time,
  474. fs_user.remark,
  475. fs_user.company_user_id,
  476. fs_user.company_id
  477. FROM
  478. fs_user
  479. where fs_user.is_del = 0
  480. <if test="userId != null">
  481. AND fs_user.user_id = #{userId}
  482. </if>
  483. <if test="companyId != null">
  484. AND fs_user.company_id = #{companyId}
  485. </if>
  486. <if test="companyUserId != null and companyUserId != '' ">
  487. AND fs_user.company_user_id = #{companyUserId}
  488. </if>
  489. <if test="registerStartTime != null and registerStartTime !='' ">
  490. AND fs_user.create_time &gt;= #{registerStartTime}
  491. </if>
  492. <if test="registerEndTime != null and registerEndTime !='' ">
  493. AND fs_user.create_time &lt;= #{registerEndTime}
  494. </if>
  495. <if test="companyUserIds != null and companyUserIds.size > 0">
  496. AND fs_user.company_user_id in
  497. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  498. ${item}
  499. </foreach>
  500. </if>
  501. <if test="nickname != null and nickname != ''">
  502. AND fs_user.nickname like concat('%', #{nickname},'%')
  503. </if>
  504. <if test="phone != null and phone != ''">
  505. AND fs_user.phone like concat('%', #{phone},'%')
  506. </if>
  507. limit ${(pageNum-1)*pageSize},${pageSize}
  508. </select>
  509. <select id="selectFsUserPageList" resultType="FsUserPageListVO">
  510. SELECT
  511. fs_user.*,
  512. fs_user_course_count.id,
  513. fs_user_course_count.watch_course_count,
  514. fs_user_course_count.miss_course_count,
  515. fs_user_course_count.miss_course_status,
  516. fs_user_course_count.course_ids,
  517. fs_user_course_count.part_course_count,
  518. fs_user_course_count.last_watch_date,
  519. fs_user_course_count.STATUS AS courseCountStatus,
  520. fs_user_course_count.stop_watch_days,
  521. fs_user_course_count.complete_watch_date,
  522. GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
  523. GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
  524. company_user.nick_name as companyUserNickName,
  525. fs_user_company_user.is_repeat_fans
  526. FROM
  527. fs_user
  528. LEFT JOIN fs_user_course_count ON fs_user.user_id = fs_user_course_count.user_id
  529. LEFT JOIN company_tag_user ON fs_user.user_id = company_tag_user.user_id
  530. LEFT JOIN company_tag ON FIND_IN_SET(company_tag.tag_id, company_tag_user.tag_ids) > 0
  531. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  532. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  533. where fs_user.is_del = 0
  534. <if test="userId != null and userId!= 0 ">
  535. and fs_user.company_user_id = #{userId}
  536. </if>
  537. <if test="companyId != null ">
  538. and fs_user.company_id = #{companyId}
  539. </if>
  540. <choose>
  541. <when test = "isBlack">
  542. AND (fs_user.status = 0 or fs_user_company_user.is_repeat_fans = 1)
  543. </when>
  544. <otherwise>
  545. AND (fs_user.status = 1 and fs_user_company_user.is_repeat_fans = 0)
  546. </otherwise>
  547. </choose>
  548. <if test="keyword != null and keyword !='' ">
  549. AND (fs_user.nickname LIKE concat('%',#{keyword},'%')
  550. or fs_user.phone LIKE concat('%',#{keyword},'%')
  551. )
  552. </if>
  553. <if test="registerStartTime != null and registerStartTime !='' ">
  554. AND fs_user.create_time &gt;= #{registerStartTime}
  555. </if>
  556. <if test="registerEndTime != null and registerEndTime !='' ">
  557. AND fs_user.create_time &lt;= #{registerEndTime}
  558. </if>
  559. <if test="isNullTag">
  560. and (company_tag_user.tag_ids is null
  561. <if test="tagIds != null and tagIds.length > 0">
  562. or
  563. <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
  564. CONCAT(',', company_tag_user.tag_ids, ',') LIKE CONCAT('%,', #{item}, ',%')
  565. </foreach>
  566. </if>
  567. )
  568. </if>
  569. <if test="!isNullTag and tagIds != null and tagIds.length > 0">
  570. AND
  571. <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
  572. CONCAT(',', company_tag_user.tag_ids, ',') LIKE CONCAT('%,', #{item}, ',%')
  573. </foreach>
  574. </if>
  575. <if test="tabValue != null and tabValue !='' ">
  576. <choose>
  577. <when test = "tabValue == 1">
  578. AND DAY(fs_user.create_time) = DAY(NOW())
  579. </when>
  580. <when test = "tabValue == 2">
  581. AND DAY(fs_user_course_count.complete_watch_date) = DAY(NOW())
  582. </when>
  583. <when test = "tabValue == 3">
  584. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  585. </when>
  586. </choose>
  587. </if>
  588. <if test="watchCourseType != null and watchCourseType !='' ">
  589. <choose>
  590. <when test = "watchCourseType == 1">
  591. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  592. </when>
  593. <when test = "watchCourseType == 2">
  594. AND fs_user_course_count.status = 1
  595. </when>
  596. <when test = "watchCourseType == 3">
  597. AND fs_user_course_count.status = 2
  598. </when>
  599. </choose>
  600. </if>
  601. <if test="missCourseStatus != null and missCourseStatus !='' ">
  602. <choose>
  603. <when test = "missCourseStatus == 1">
  604. AND fs_user_course_count.miss_course_status = 1
  605. </when>
  606. <when test = "missCourseStatus == 2">
  607. AND (fs_user_course_count.miss_course_status = 2 or fs_user_course_count.miss_course_status is null )
  608. </when>
  609. </choose>
  610. </if>
  611. group by fs_user.user_id
  612. <if test="continueMissCourseSort != null and continueMissCourseSort !='' ">
  613. order by
  614. <choose>
  615. <when test = "continueMissCourseSort == 0">
  616. fs_user.create_time desc
  617. </when>
  618. <when test = "continueMissCourseSort == 1">
  619. fs_user.nickname asc
  620. </when>
  621. </choose>
  622. </if>
  623. </select>
  624. <select id="getUserNumber" resultType="UserListCountVO">
  625. SELECT
  626. fs_user.`status` as status,
  627. count( DISTINCT fs_user.user_id ) AS num
  628. FROM
  629. fs_user
  630. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  631. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  632. WHERE fs_user.is_del = 0 and fs_user_company_user.is_repeat_fans is not null
  633. <if test="userId != null and userId != 0 ">
  634. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  635. </if>
  636. <if test="companyId != null ">
  637. and fs_user.company_id = #{companyId}
  638. </if>
  639. GROUP BY
  640. fs_user.`status`
  641. </select>
  642. <select id="getRepeatUserNumber" resultType="int">
  643. SELECT
  644. count( DISTINCT fs_user.user_id ) AS num
  645. FROM
  646. fs_user
  647. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  648. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  649. WHERE
  650. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  651. AND fs_user.is_del = 0
  652. AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
  653. </select>
  654. <select id="getCountWatchCourse" resultType="UserDetailsVO">
  655. SELECT
  656. <if test="dateTag == null or dateTag =='' or dateTag == '近七天' ">
  657. ifnull( sum(complete_watch_count), 0 ) AS completeWatchCount ,
  658. ifnull( sum(watch_times), 0 ) AS watchTimes,
  659. </if>
  660. <if test="dateTag != null and dateTag !='' and dateTag != '近七天' ">
  661. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  662. ifnull( watch_times, 0 ) AS watchTimes,
  663. </if>
  664. fs_user.user_id
  665. FROM
  666. fs_user_course_count
  667. LEFT JOIN fs_user ON fs_user.user_id = fs_user_course_count.user_id
  668. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  669. <where>
  670. <if test="dateTag != null and dateTag !='' ">
  671. <choose>
  672. <when test = "dateTag == '今天'">
  673. and to_days(fs_user_course_count.create_time) = to_days(now())
  674. </when>
  675. <when test = "dateTag == '昨天'">
  676. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_user_course_count.create_time &lt; CURDATE()
  677. </when>
  678. <when test = "dateTag == '前天'">
  679. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_user_course_count.create_time &lt; CURDATE() - INTERVAL 1 DAY
  680. </when>
  681. <when test = "dateTag == '近七天'">
  682. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  683. </when>
  684. </choose>
  685. </if>
  686. and fs_user.user_id = #{fsUserId}
  687. </where>
  688. GROUP BY
  689. fs_user.user_id
  690. </select>
  691. <select id="getCountAnswer" resultType="UserDetailsVO">
  692. SELECT
  693. (
  694. SELECT
  695. ifnull(count( DISTINCT log_id ), 0) AS answerTime
  696. FROM
  697. fs_course_answer_logs
  698. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  699. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  700. <where>
  701. <if test="dateTag != null and dateTag !='' ">
  702. <choose>
  703. <when test = "dateTag == '今天'">
  704. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  705. </when>
  706. <when test = "dateTag == '昨天'">
  707. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  708. </when>
  709. <when test = "dateTag == '前天'">
  710. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  711. </when>
  712. <when test = "dateTag == '近七天'">
  713. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  714. </when>
  715. </choose>
  716. </if>
  717. and fs_user.user_id = #{fsUserId}
  718. </where>
  719. GROUP BY
  720. fs_user.user_id
  721. ) AS answerTime,
  722. (
  723. SELECT
  724. ifnull(count( DISTINCT log_id ), 0) AS answerRightTime
  725. FROM
  726. fs_course_answer_logs
  727. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  728. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  729. <where>
  730. fs_course_answer_logs.is_right = 1
  731. <if test="dateTag != null and dateTag !='' ">
  732. <choose>
  733. <when test = "dateTag == '今天'">
  734. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  735. </when>
  736. <when test = "dateTag == '昨天'">
  737. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  738. </when>
  739. <when test = "dateTag == '前天'">
  740. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  741. </when>
  742. <when test = "dateTag == '近七天'">
  743. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  744. </when>
  745. </choose>
  746. </if>
  747. and fs_user.user_id = #{fsUserId}
  748. </where>
  749. GROUP BY
  750. fs_user.user_id
  751. ) AS answerRightTime;
  752. </select>
  753. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  754. SELECT
  755. ifnull( count( DISTINCT log_id ), 0 ) AS answerRedPacketTime,
  756. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  757. fs_user.user_id
  758. FROM
  759. fs_course_red_packet_log
  760. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  761. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  762. <where>
  763. fs_course_red_packet_log.status = 1
  764. <if test="dateTag != null and dateTag !='' ">
  765. <choose>
  766. <when test = "dateTag == '今天'">
  767. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  768. </when>
  769. <when test = "dateTag == '昨天'">
  770. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE()
  771. </when>
  772. <when test = "dateTag == '前天'">
  773. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE() - INTERVAL 1 DAY
  774. </when>
  775. <when test = "dateTag == '近七天'">
  776. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  777. </when>
  778. </choose>
  779. </if>
  780. and fs_user.user_id = #{fsUserId}
  781. </where>
  782. GROUP BY
  783. fs_user.user_id
  784. </select>
  785. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  786. select
  787. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  788. count(u.user_id) vipCount
  789. from fs_user u
  790. where u.company_user_id = #{companyUserId}
  791. </select>
  792. <update id="batchUpdateFsUserByIds" parameterType="Long">
  793. update fs_user
  794. set status = #{status} where user_id in
  795. <foreach item="id" collection="ids" open="(" separator="," close=")">
  796. #{id}
  797. </foreach>
  798. </update>
  799. <select id="countUserSummary" resultType="FsUserSummaryCountVO">
  800. SELECT (SELECT count(fs_user.user_id)
  801. FROM fs_user
  802. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  803. WHERE fs_user.is_del = 0
  804. <if test="userId != null and userId != 0 ">
  805. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  806. </if>
  807. <if test="companyId != null ">
  808. and fs_user.company_id = #{companyId}
  809. </if>
  810. ) as userTotal,
  811. (SELECT count(fs_user.user_id)
  812. FROM fs_user
  813. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  814. WHERE fs_user.is_del = 0
  815. <if test="userId != null and userId != 0 ">
  816. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  817. </if>
  818. <if test="companyId != null ">
  819. and fs_user.company_id = #{companyId}
  820. </if>
  821. AND to_days(fs_user.create_time) = to_days(now())) as todayNewUser
  822. </select>
  823. <select id="countTag" resultType="FsUserSummaryCountTagVO">
  824. SELECT
  825. company_tag.tag AS tagName,
  826. count( fs_user.user_id ) AS number
  827. FROM
  828. company_tag_user
  829. LEFT JOIN fs_user ON fs_user.user_id = company_tag_user.user_id
  830. LEFT JOIN company_tag ON FIND_IN_SET( company_tag.tag_id, company_tag_user.tag_ids ) > 0
  831. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  832. <where>
  833. <if test="userId != null and userId != 0 ">
  834. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  835. </if>
  836. <if test="companyId != null ">
  837. and fs_user.company_id = #{companyId}
  838. </if>
  839. and company_tag.tag_id is not null
  840. </where>
  841. GROUP BY
  842. company_tag.tag_id
  843. </select>
  844. <select id="countUserCourse" resultType="Map">
  845. SELECT
  846. (
  847. SELECT
  848. count(distinct fcc.user_id )
  849. FROM
  850. fs_user_course_count fcc
  851. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  852. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  853. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  854. <where>
  855. <if test="userId != null and userId != 0 ">
  856. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  857. </if>
  858. <if test="userId != null and userId == 0 ">
  859. and fs_user.company_id = #{companyId}
  860. </if>
  861. <if test="startTime != null and startTime !='' ">
  862. and fcc.create_time &gt;= #{startTime}
  863. </if>
  864. <if test="endTime != null and endTime != ''">
  865. and fcc.create_time &lt;= #{endTime}
  866. </if>
  867. <if test="periodId != null and periodId != ''">
  868. AND fcpd.period_id = #{periodId}
  869. </if>
  870. <if test="videoId != null and videoId != ''">
  871. AND fcpd.video_id = #{videoId}
  872. </if>
  873. -- 单独通过销售id查询
  874. <if test="companyUserId != null and companyUserId != ''">
  875. AND company_user.user_id = #{companyUserId}
  876. </if>
  877. </where>
  878. ) as courseWatchNum,
  879. (
  880. SELECT
  881. count(distinct fcc.user_id )
  882. FROM
  883. fs_user_course_count fcc
  884. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  885. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  886. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  887. <where>
  888. <if test="userId != null and userId != 0 ">
  889. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  890. </if>
  891. <if test="userId != null and userId == 0 ">
  892. and fs_user.company_id = #{companyId}
  893. </if>
  894. AND fcc.complete_watch_count > 0
  895. <if test="startTime != null and startTime !='' ">
  896. and fcc.create_time &gt;= #{startTime}
  897. </if>
  898. <if test="endTime != null and endTime != ''">
  899. and fcc.create_time &lt;= #{endTime}
  900. </if>
  901. <if test="periodId != null and periodId != ''">
  902. AND fcpd.period_id = #{periodId}
  903. </if>
  904. <if test="videoId != null and videoId != ''">
  905. AND fcpd.video_id = #{videoId}
  906. </if>
  907. -- 单独通过销售id查询
  908. <if test="companyUserId != null and companyUserId != ''">
  909. AND company_user.user_id = #{companyUserId}
  910. </if>
  911. </where>
  912. ) as courseCompleteNum
  913. </select>
  914. <select id="countUserAnswer" resultType="Map">
  915. SELECT
  916. (
  917. SELECT
  918. count(distinct fs_user.user_id )
  919. FROM
  920. fs_course_answer_logs
  921. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  922. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  923. <where>
  924. <if test="userId != null and userId != 0 ">
  925. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  926. </if>
  927. <if test="userId != null and userId == 0 ">
  928. and fs_user.company_id = #{companyId}
  929. </if>
  930. <if test="startTime != null and startTime !='' ">
  931. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  932. </if>
  933. <if test="endTime != null and endTime != ''">
  934. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  935. </if>
  936. <if test="periodId != null and periodId != ''">
  937. AND fs_course_answer_logs.period_id = #{periodId}
  938. </if>
  939. <if test="videoId != null and videoId != ''">
  940. AND fs_course_answer_logs.video_id = #{videoId}
  941. </if>
  942. -- 单独通过销售id查询
  943. <if test="companyUserId != null and companyUserId != ''">
  944. AND company_user.user_id = #{companyUserId}
  945. </if>
  946. </where>
  947. ) AS answerNum,
  948. (
  949. SELECT
  950. count(distinct fs_user.user_id )
  951. FROM
  952. fs_course_answer_logs
  953. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  954. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  955. <where>
  956. <if test="userId != null and userId != 0 ">
  957. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  958. </if>
  959. <if test="userId != null and userId == 0 ">
  960. and fs_user.company_id = #{companyId}
  961. </if>
  962. AND fs_course_answer_logs.is_right = 1
  963. <if test="startTime != null and startTime !='' ">
  964. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  965. </if>
  966. <if test="endTime != null and endTime != ''">
  967. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  968. </if>
  969. <if test="periodId != null and periodId != ''">
  970. AND fs_course_answer_logs.period_id = #{periodId}
  971. </if>
  972. <if test="videoId != null and videoId != ''">
  973. AND fs_course_answer_logs.video_id = #{videoId}
  974. </if>
  975. -- 单独通过销售id查询
  976. <if test="companyUserId != null and companyUserId != ''">
  977. AND company_user.user_id = #{companyUserId}
  978. </if>
  979. </where>
  980. ) AS answerRightNum
  981. </select>
  982. <select id="countUserRedPacket" resultType="Map">
  983. SELECT
  984. (
  985. SELECT
  986. count( flog.log_id )
  987. FROM
  988. fs_course_red_packet_log flog
  989. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  990. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  991. <where>
  992. <if test="userId != null and userId != 0 ">
  993. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  994. </if>
  995. <if test="userId != null and userId == 0 ">
  996. and fs_user.company_id = #{companyId}
  997. </if>
  998. <if test="startTime != null and startTime !='' ">
  999. AND flog.create_time &gt;= #{startTime}
  1000. </if>
  1001. <if test="endTime != null and endTime != ''">
  1002. AND flog.create_time &lt;= #{endTime}
  1003. </if>
  1004. <if test="periodId != null and periodId != ''">
  1005. AND flog.period_id = #{periodId}
  1006. </if>
  1007. <if test="videoId != null and videoId != ''">
  1008. AND flog.video_id = #{videoId}
  1009. </if>
  1010. -- 单独通过销售id查询
  1011. <if test="companyUserId != null and companyUserId != ''">
  1012. AND company_user.user_id = #{companyUserId}
  1013. </if>
  1014. </where>
  1015. ) AS redPacketNum,
  1016. (
  1017. SELECT
  1018. ifnull (sum( flog.amount ), 0)
  1019. FROM
  1020. fs_course_red_packet_log flog
  1021. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1022. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1023. <where>
  1024. <if test="userId != null and userId != 0 ">
  1025. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1026. </if>
  1027. <if test="userId != null and userId == 0 ">
  1028. and fs_user.company_id = #{companyId}
  1029. </if>
  1030. <if test="startTime != null and startTime !='' ">
  1031. AND flog.create_time &gt;= #{startTime}
  1032. </if>
  1033. <if test="endTime != null and endTime != ''">
  1034. AND flog.create_time &lt;= #{endTime}
  1035. </if>
  1036. <if test="periodId != null and periodId != ''">
  1037. AND flog.period_id = #{periodId}
  1038. </if>
  1039. <if test="videoId != null and videoId != ''">
  1040. AND flog.video_id = #{videoId}
  1041. </if>
  1042. -- 单独通过销售id查询
  1043. <if test="companyUserId != null and companyUserId != ''">
  1044. AND company_user.user_id = #{companyUserId}
  1045. </if>
  1046. </where>
  1047. ) AS redPacketAmount
  1048. </select>
  1049. <select id="countCourseDetails" resultType="Map">
  1050. select (SELECT
  1051. count( DISTINCT fcpd.period_id )
  1052. FROM
  1053. fs_user_course_period_days fcpd
  1054. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1055. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1056. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1057. WHERE 1=1
  1058. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1059. <if test="userId != null and userId != 0 ">
  1060. AND fs_user.company_user_id = #{userId}
  1061. </if>
  1062. <if test="userId != null and userId == 0 ">
  1063. and fs_user.company_id = #{companyId}
  1064. </if>
  1065. <if test="periodId != null and periodId != ''">
  1066. AND fcpd.period_id = #{periodId}
  1067. </if>
  1068. -- 单独通过销售id查询
  1069. <if test="companyUserId != null and companyUserId != ''">
  1070. AND fs_user.company_user_id = #{companyUserId}
  1071. </if>
  1072. ) as courseNum,
  1073. (SELECT count(DISTINCT fcpd.video_id)
  1074. FROM fs_user_course_period_days fcpd
  1075. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1076. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1077. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1078. WHERE 1=1
  1079. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1080. <if test="userId != null and userId != 0 ">
  1081. AND fs_user.company_user_id = #{userId}
  1082. </if>
  1083. <if test="userId != null and userId == 0 ">
  1084. and fs_user.company_id = #{companyId}
  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. -- 单独通过销售id查询
  1093. <if test="companyUserId != null and companyUserId != ''">
  1094. AND fs_user.company_user_id = #{companyUserId}
  1095. </if>
  1096. ) as videoNum,
  1097. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  1098. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1099. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1100. <if test="periodId != null and periodId != ''">
  1101. AND fcpd.period_id = #{periodId}
  1102. </if>
  1103. <if test="videoId != null and videoId != ''">
  1104. AND fcpd.video_id = #{videoId}
  1105. </if>
  1106. -- 单独通过销售id查询
  1107. <if test="companyUserId != null and companyUserId != ''">
  1108. AND fs_user.company_user_id = #{companyUserId}
  1109. </if>
  1110. <where>
  1111. <if test="userId != null and userId != 0 ">
  1112. AND fs_user.company_user_id = #{userId}
  1113. </if>
  1114. <if test="userId != null and userId == 0 ">
  1115. and fs_user.company_id = #{companyId}
  1116. </if>
  1117. </where>
  1118. ) as courseUserNum
  1119. </select>
  1120. <select id="countUserRankingByComplete" resultType="FsUserRankingVO">
  1121. SELECT
  1122. company_user.nick_name as userName,
  1123. ifnull(
  1124. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  1125. ) as completeRate
  1126. FROM
  1127. fs_user_course_count fcc
  1128. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1129. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1130. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1131. <where>
  1132. <if test="userId != null and userId != 0 ">
  1133. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1134. </if>
  1135. <if test="userId != null and userId == 0 ">
  1136. and fs_user.company_id = #{companyId}
  1137. </if>
  1138. <if test="startTime != null and startTime !='' ">
  1139. AND fcc.create_time &gt;= #{startTime}
  1140. </if>
  1141. <if test="endTime != null and endTime != ''">
  1142. AND fcc.create_time &lt;= #{endTime}
  1143. </if>
  1144. <if test="periodId != null and periodId != ''">
  1145. AND fcpd.period_id = #{periodId}
  1146. </if>
  1147. <if test="videoId != null and videoId != ''">
  1148. AND fcpd.video_id = #{videoId}
  1149. </if>
  1150. </where>
  1151. group by fcc.user_id
  1152. <choose>
  1153. <when test="order != null and order == 'asc'">
  1154. order by completeRate asc
  1155. </when>
  1156. <when test="order != null and order == 'desc'">
  1157. order by completeRate desc
  1158. </when>
  1159. <otherwise>
  1160. order by completeRate desc
  1161. </otherwise>
  1162. </choose>
  1163. limit 20
  1164. </select>
  1165. <select id="countUserRankingByRight" resultType="FsUserRankingVO">
  1166. SELECT
  1167. company_user.nick_name as userName,
  1168. ifnull(ROUND(
  1169. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1170. *100,2),0
  1171. ) as answerRightRate
  1172. FROM
  1173. fs_course_answer_logs
  1174. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1175. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1176. <where>
  1177. <if test="userId != null and userId != 0 ">
  1178. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1179. </if>
  1180. <if test="userId != null and userId == 0 ">
  1181. and fs_user.company_id = #{companyId}
  1182. </if>
  1183. <if test="startTime != null and startTime !='' ">
  1184. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1185. </if>
  1186. <if test="endTime != null and endTime != ''">
  1187. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1188. </if>
  1189. <if test="periodId != null and periodId != ''">
  1190. AND fs_course_answer_logs.period_id = #{periodId}
  1191. </if>
  1192. <if test="videoId != null and videoId != ''">
  1193. AND fs_course_answer_logs.video_id = #{videoId}
  1194. </if>
  1195. </where>
  1196. group by fs_user.user_id
  1197. <choose>
  1198. <when test="order != null and order == 'asc'">
  1199. order by answerRightRate asc
  1200. </when>
  1201. <when test="order != null and order == 'desc'">
  1202. order by answerRightRate desc
  1203. </when>
  1204. <otherwise>
  1205. order by answerRightRate desc
  1206. </otherwise>
  1207. </choose>
  1208. limit 20
  1209. </select>
  1210. <select id="countCourseRankingByComplete" resultType="FsCourseRankingVO">
  1211. SELECT
  1212. fcv.title AS videoName,
  1213. fcv.video_id,
  1214. ifnull(
  1215. ROUND(
  1216. (
  1217. COUNT( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) / count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.log_id END )) * 100,
  1218. 2
  1219. ),
  1220. 0
  1221. ) AS completeRate
  1222. FROM
  1223. fs_course_watch_log fwl
  1224. LEFT JOIN fs_user ON fs_user.user_id = fwl.user_id
  1225. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1226. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1227. -- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1228. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fwl.video_id
  1229. <where>
  1230. <if test="userId != null and userId != 0 ">
  1231. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1232. </if>
  1233. <if test="userId != null and userId == 0 ">
  1234. and fs_user.company_id = #{companyId}
  1235. </if>
  1236. <if test="startTime != null and startTime !='' ">
  1237. AND fwl.create_time &gt;= #{startTime}
  1238. </if>
  1239. <if test="endTime != null and endTime != ''">
  1240. AND fwl.create_time &lt;= #{endTime}
  1241. </if>
  1242. <if test="periodId != null and periodId != ''">
  1243. AND fwl.period_id = #{periodId}
  1244. </if>
  1245. <if test="videoId != null and videoId != ''">
  1246. AND fwl.video_id = #{videoId}
  1247. </if>
  1248. </where>
  1249. GROUP BY
  1250. fwl.video_id
  1251. <choose>
  1252. <when test="order != null and order == 'asc'">
  1253. ORDER BY completeRate asc
  1254. </when>
  1255. <when test="order != null and order == 'desc'">
  1256. ORDER BY completeRate desc
  1257. </when>
  1258. <otherwise>
  1259. ORDER BY completeRate desc
  1260. </otherwise>
  1261. </choose>
  1262. LIMIT 20
  1263. </select>
  1264. <select id="countCourseRankingByRight" resultType="FsCourseRankingVO">
  1265. SELECT
  1266. fcv.title AS videoName,
  1267. ifnull(
  1268. ROUND(
  1269. (
  1270. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) / count( DISTINCT fs_course_answer_logs.log_id)) * 100,
  1271. 2
  1272. ),
  1273. 0
  1274. ) AS answerRightRate
  1275. FROM
  1276. fs_course_answer_logs
  1277. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1278. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1279. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1280. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1281. <where>
  1282. <if test="userId != null and userId != 0 ">
  1283. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1284. </if>
  1285. <if test="userId != null and userId == 0 ">
  1286. and fs_user.company_id = #{companyId}
  1287. </if>
  1288. <if test="startTime != null and startTime !='' ">
  1289. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1290. </if>
  1291. <if test="endTime != null and endTime != ''">
  1292. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1293. </if>
  1294. <if test="periodId != null and periodId != ''">
  1295. AND fs_course_answer_logs.period_id = #{periodId}
  1296. </if>
  1297. <if test="videoId != null and videoId != ''">
  1298. AND fs_course_answer_logs.video_id = #{videoId}
  1299. </if>
  1300. </where>
  1301. GROUP BY
  1302. fs_course_answer_logs.video_id
  1303. <choose>
  1304. <when test="order != null and order == 'asc'">
  1305. ORDER BY answerRightRate asc
  1306. </when>
  1307. <when test="order != null and order == 'desc'">
  1308. ORDER BY answerRightRate desc
  1309. </when>
  1310. <otherwise>
  1311. ORDER BY answerRightRate desc
  1312. </otherwise>
  1313. </choose>
  1314. LIMIT 20
  1315. </select>
  1316. <!-- 查询某用户的课程视频,看课统计 -->
  1317. <select id="courseAnalysisCourseCount" resultType="FsCourseAnalysisCountVO">
  1318. SELECT
  1319. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1320. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1321. ifnull(
  1322. ROUND(
  1323. (
  1324. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1325. 2
  1326. ),
  1327. 0
  1328. ) as completeRate,
  1329. fcpd.video_id
  1330. FROM
  1331. fs_user_course_count fcc
  1332. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1333. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1334. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1335. <where>
  1336. <if test="companyUserId != null and companyUserId != 0 ">
  1337. AND fs_user.company_user_id = #{companyUserId}
  1338. </if>
  1339. <if test="companyUserId != null and companyUserId == 0 ">
  1340. and fs_user.company_id = #{companyId}
  1341. </if>
  1342. <if test="periodId != null and periodId != ''">
  1343. AND fcpd.period_id = #{periodId}
  1344. </if>
  1345. <if test="videoId != null and videoId != ''">
  1346. AND fcpd.video_id = #{videoId}
  1347. </if>
  1348. </where>
  1349. GROUP BY
  1350. fcpd.video_id
  1351. </select>
  1352. <!-- 查询某用户的课程视频,红包统计 -->
  1353. <select id="courseAnalysisRedPacketCount" resultType="FsCourseAnalysisCountVO">
  1354. SELECT
  1355. count( flog.log_id ) as redPacketNum,
  1356. ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
  1357. flog.video_id
  1358. FROM
  1359. fs_course_red_packet_log flog
  1360. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1361. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1362. <where>
  1363. <if test="companyUserId != null and companyUserId != 0 ">
  1364. AND fs_user.company_user_id = #{companyUserId}
  1365. </if>
  1366. <if test="companyUserId != null and companyUserId == 0 ">
  1367. and fs_user.company_id = #{companyId}
  1368. </if>
  1369. <if test="periodId != null and periodId != ''">
  1370. AND flog.period_id = #{periodId}
  1371. </if>
  1372. <if test="videoId != null and videoId != ''">
  1373. AND flog.video_id = #{videoId}
  1374. </if>
  1375. <if test="videoIdList != null and videoIdList.size > 0 ">
  1376. AND flog.video_id in
  1377. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  1378. #{videoId}
  1379. </foreach>
  1380. </if>
  1381. </where>
  1382. GROUP BY
  1383. flog.video_id
  1384. </select>
  1385. <!-- 查询某用户的课程视频,答题统计 -->
  1386. <select id="courseAnalysisAnswerCount" resultType="FsCourseAnalysisCountVO">
  1387. SELECT
  1388. count( DISTINCT fs_user.user_id ) as answerNum,
  1389. count(fs_course_answer_logs.log_id) answerTimes,
  1390. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
  1391. COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) as answerRightTimes,
  1392. ifnull(
  1393. ROUND(
  1394. (
  1395. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  1396. 2
  1397. ),
  1398. 0
  1399. ) as answerRightRate,
  1400. fs_course_answer_logs.video_id
  1401. FROM
  1402. fs_course_answer_logs
  1403. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1404. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1405. <where>
  1406. <if test="companyUserId != null and companyUserId != 0 ">
  1407. AND fs_user.company_user_id = #{companyUserId}
  1408. </if>
  1409. <if test="companyUserId != null and companyUserId == 0 ">
  1410. and fs_user.company_id = #{companyId}
  1411. </if>
  1412. <if test="periodId != null and periodId != ''">
  1413. AND fs_course_answer_logs.period_id = #{periodId}
  1414. </if>
  1415. <if test="videoId != null and videoId != ''">
  1416. AND fs_course_answer_logs.video_id = #{videoId}
  1417. </if>
  1418. <if test="videoIdList != null and videoIdList.size > 0 ">
  1419. AND fs_course_answer_logs.video_id in
  1420. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  1421. #{videoId}
  1422. </foreach>
  1423. </if>
  1424. </where>
  1425. GROUP BY
  1426. fs_course_answer_logs.video_id
  1427. </select>
  1428. <select id="companyUserCount" resultType="CompanyUserSummaryCountVO">
  1429. SELECT
  1430. (
  1431. SELECT count( fs_user.user_id ) FROM fs_user LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1432. <where>
  1433. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1434. AND fs_user.company_user_id = #{companyUserId}
  1435. </if>
  1436. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1437. and fs_user.company_id = #{companyId}
  1438. </if>
  1439. </where>
  1440. ) AS userTotal,
  1441. (
  1442. SELECT
  1443. count( fs_user.user_id )
  1444. FROM
  1445. fs_user
  1446. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1447. <where>
  1448. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1449. AND fs_user.company_user_id = #{companyUserId}
  1450. </if>
  1451. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1452. and fs_user.company_id = #{companyId}
  1453. </if>
  1454. and fs_user.is_del = 0
  1455. AND to_days( fs_user.create_time ) = to_days(
  1456. now())
  1457. </where>
  1458. ) AS todayNewUser
  1459. </select>
  1460. <select id="newUserRedPacketCount" resultType="CompanyUserSummaryCountVO">
  1461. SELECT
  1462. count(flog.log_id) as userRedPacketNum,
  1463. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1464. FROM
  1465. fs_course_red_packet_log flog
  1466. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1467. <where>
  1468. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1469. AND fs_user.company_user_id = #{companyUserId}
  1470. </if>
  1471. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1472. and fs_user.company_id = #{companyId}
  1473. </if>
  1474. </where>
  1475. </select>
  1476. <select id="selectFsUserPageListCount" resultType="java.lang.Long">
  1477. SELECT
  1478. count(1)
  1479. FROM
  1480. fs_user
  1481. <where>
  1482. fs_user.is_del = 0
  1483. <if test="companyId != null">
  1484. AND fs_user.company_id = #{companyId}
  1485. </if>
  1486. <if test="companyUserId != null and companyUserId != '' ">
  1487. AND fs_user.company_user_id = #{companyUserId}
  1488. </if>
  1489. <if test="registerStartTime != null and registerStartTime !='' ">
  1490. AND fs_user.create_time &gt;= #{registerStartTime}
  1491. </if>
  1492. <if test="registerEndTime != null and registerEndTime !='' ">
  1493. AND fs_user.create_time &lt;= #{registerEndTime}
  1494. </if>
  1495. <if test="companyUserIds != null and companyUserIds.size > 0">
  1496. AND fs_user.company_user_id in
  1497. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  1498. ${item}
  1499. </foreach>
  1500. </if>
  1501. <if test="nickname != null and nickname!=''">
  1502. AND fs_user.nickname like concat(#{nickname},'%')
  1503. </if>
  1504. <if test="phone != null and phone!=''">
  1505. AND fs_user.phone like concat('%', #{phone},'%')
  1506. </if>
  1507. </where>
  1508. </select>
  1509. <select id="courseAnalysisWatchLog" resultType="FsCourseAnalysisCountVO">
  1510. SELECT
  1511. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS courseWatchNum,
  1512. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTimes,
  1513. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS courseCompleteNum,
  1514. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTimes,
  1515. ifnull(
  1516. ROUND(
  1517. (
  1518. 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,
  1519. 2
  1520. ),
  1521. 0
  1522. ) AS completeRate,
  1523. fwl.video_id
  1524. FROM
  1525. fs_course_watch_log fwl
  1526. <where>
  1527. <if test="periodId != null and periodId != ''">
  1528. AND fwl.period_id = #{periodId}
  1529. </if>
  1530. <if test="videoId != null and videoId != ''">
  1531. AND fwl.video_id = #{videoId}
  1532. </if>
  1533. <if test="videoIdList != null and videoIdList.size > 0 ">
  1534. AND fwl.video_id in
  1535. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  1536. #{videoId}
  1537. </foreach>
  1538. </if>
  1539. </where>
  1540. GROUP BY
  1541. fwl.video_id
  1542. </select>
  1543. <update id="batchUpdateUserCompanyUser">
  1544. update fs_user
  1545. set company_id = #{companyId},
  1546. company_user_id = #{companyUserId}
  1547. where
  1548. <foreach collection="userIds" separator="or" item="userId" index="index">
  1549. user_id = #{userId}
  1550. </foreach>
  1551. </update>
  1552. <update id="batchUpdateCompanyUserRelation">
  1553. update fs_user_company_user
  1554. set company_id = #{companyId},
  1555. company_user_id = #{companyUserId}
  1556. where is_repeat_fans = 0 and
  1557. <foreach collection="userIds" open="(" close=")" separator="or" item="userId" index="index">
  1558. user_id = #{userId}
  1559. </foreach>
  1560. </update>
  1561. <select id="selectUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  1562. select
  1563. u.user_id dictValue,
  1564. u.nickname dictLabel
  1565. from fs_user u
  1566. <where>
  1567. <if test="params.nickName != null and params.nickName != ''">
  1568. u.nickname like concat('%', #{params.nickName}, '%')
  1569. </if>
  1570. </where>
  1571. </select>
  1572. <select id ="selectFsUserByUserIds" resultType="Integer">
  1573. select count(1) from fs_user_company_user
  1574. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1575. where is_repeat_fans = 1
  1576. and (fs_user_company_user.company_user_id = #{companyUserId} OR company_user.parent_id = #{companyUserId})
  1577. <if test="userIds != null and userIds.length > 0 ">
  1578. and fs_user_company_user.user_id in
  1579. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  1580. #{userId}
  1581. </foreach>
  1582. </if>
  1583. </select>
  1584. <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
  1585. SELECT
  1586. count( fs_user.user_id ) as userNum,
  1587. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  1588. fs_user.company_id
  1589. FROM
  1590. fs_user
  1591. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1592. WHERE
  1593. fs_user.is_del = 0
  1594. AND fs_user.`status` = 1
  1595. AND company_user.user_id is not null
  1596. GROUP BY
  1597. fs_user.company_id
  1598. </select>
  1599. <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
  1600. SELECT
  1601. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  1602. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  1603. ifnull(
  1604. ROUND(
  1605. (
  1606. 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,
  1607. 2
  1608. ),
  1609. 0
  1610. ) AS completeWatchRate,
  1611. fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
  1612. FROM
  1613. fs_course_watch_log fwl
  1614. WHERE
  1615. fwl.send_type = 1
  1616. GROUP BY
  1617. fwl.period_id, fwl.video_id, fwl.company_user_id
  1618. </select>
  1619. <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
  1620. SELECT
  1621. count( flog.log_id ) AS redPacketNum,
  1622. ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
  1623. flog.period_id,
  1624. flog.video_id,
  1625. flog.company_user_id,
  1626. flog.company_id
  1627. FROM
  1628. fs_course_red_packet_log flog
  1629. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1630. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1631. GROUP BY
  1632. flog.period_id,
  1633. flog.video_id,
  1634. flog.company_user_id
  1635. </select>
  1636. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  1637. SELECT
  1638. count( DISTINCT fs_user.user_id ) AS answerNum,
  1639. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) AS answerRightNum,
  1640. ifnull(
  1641. ROUND(
  1642. (
  1643. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  1644. 2
  1645. ),
  1646. 0
  1647. ) AS answerRightRate,
  1648. fs_course_answer_logs.period_id,
  1649. fs_course_answer_logs.video_id,
  1650. fs_course_answer_logs.company_user_id,
  1651. fs_course_answer_logs.company_id
  1652. FROM
  1653. fs_course_answer_logs
  1654. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1655. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1656. GROUP BY
  1657. fs_course_answer_logs.period_id,
  1658. fs_course_answer_logs.video_id,
  1659. fs_course_answer_logs.company_user_id
  1660. </select>
  1661. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  1662. SELECT
  1663. count( fs_user.user_id ) as userNum,
  1664. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  1665. date(fs_user.create_time) as userCreateDate
  1666. ,company.company_id,
  1667. company.company_name,
  1668. company_user.user_id AS companyUserId,
  1669. company_user.nick_name AS companyUserName
  1670. FROM
  1671. fs_user
  1672. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1673. LEFT JOIN company ON company.company_id = fs_user.company_id
  1674. WHERE
  1675. fs_user.is_del = 0
  1676. AND fs_user.`status` = 1
  1677. AND company_user.user_id is not null
  1678. GROUP BY
  1679. fs_user.company_user_id, date(fs_user.create_time)
  1680. </select>
  1681. <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
  1682. <include refid="selectFsUserVo"/>
  1683. <where>
  1684. <if test="userName != null and userName != ''">
  1685. AND (
  1686. nickname like concat('%', #{userName}, '%')
  1687. or user_id LIKE concat('%',#{userName},'%')
  1688. )
  1689. </if>
  1690. </where>
  1691. order by user_id desc
  1692. </select>
  1693. <select id="countUserCourse2" resultType="java.util.Map">
  1694. SELECT
  1695. (
  1696. SELECT
  1697. count(1)
  1698. FROM
  1699. fs_course_watch_log l
  1700. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1701. where
  1702. l.log_type != 3 and send_type = 1
  1703. <if test="userId != null and userId != 0 ">
  1704. and (l.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1705. </if>
  1706. <if test="userId != null and userId == 0 ">
  1707. and l.company_id = #{companyId}
  1708. </if>
  1709. <if test="periodId != null and periodId != ''">
  1710. AND l.period_id = #{periodId}
  1711. </if>
  1712. <if test="videoId != null and videoId != ''">
  1713. AND l.video_id = #{videoId}
  1714. </if>
  1715. <if test="companyUserId != null and companyUserId != ''">
  1716. AND l.user_id = #{companyUserId}
  1717. </if>
  1718. ) as courseWatchNum,
  1719. (
  1720. SELECT
  1721. count(1)
  1722. FROM
  1723. fs_course_watch_log l
  1724. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1725. where
  1726. l.log_type = 2 and send_type = 1
  1727. <if test="userId != null and userId != 0 ">
  1728. and (l.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1729. </if>
  1730. <if test="userId != null and userId == 0 ">
  1731. and l.company_id = #{companyId}
  1732. </if>
  1733. <if test="periodId != null and periodId != ''">
  1734. AND l.period_id = #{periodId}
  1735. </if>
  1736. <if test="videoId != null and videoId != ''">
  1737. AND l.video_id = #{videoId}
  1738. </if>
  1739. -- 单独通过销售id查询
  1740. <if test="companyUserId != null and companyUserId != ''">
  1741. AND l.user_id = #{companyUserId}
  1742. </if>
  1743. ) as courseCompleteNum
  1744. </select>
  1745. </mapper>