FsUserMapper.xml 79 KB

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