FsUserMapper.xml 80 KB

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