FsUserMapper.xml 89 KB

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