FsUserMapper.xml 75 KB

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