FsUserMapper.xml 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554
  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.his.mapper.FsUserMapper">
  6. <resultMap type="FsUser" id="FsUserResult">
  7. <result property="userId" column="user_id" />
  8. <result property="nickName" column="nick_name" />
  9. <result property="avatar" column="avatar" />
  10. <result property="phone" column="phone" />
  11. <result property="integral" column="integral" />
  12. <result property="status" column="status" />
  13. <result property="tuiUserId" column="tui_user_id" />
  14. <result property="tuiTime" column="tui_time" />
  15. <result property="tuiUserCount" column="tui_user_count" />
  16. <result property="maOpenId" column="ma_open_id" />
  17. <result property="mpOpenId" column="mp_open_id" />
  18. <result property="unionId" column="union_id" />
  19. <result property="isDel" column="is_del" />
  20. <result property="userCode" column="user_code" />
  21. <result property="remark" column="remark" />
  22. <result property="createTime" column="create_time" />
  23. <result property="updateTime" column="update_time" />
  24. <result property="lastIp" column="last_ip" />
  25. <result property="balance" column="balance" />
  26. <result property="signNum" column="sign_num" />
  27. <result property="integralStatus" column="integral_status" />
  28. <result property="isBuy" column="is_buy" />
  29. <result property="password" column="password" />
  30. <result property="isVip" column="is_vip" />
  31. <result property="jpushId" column="jpush_id" />
  32. <result property="vipStartDate" column="vip_start_date" />
  33. <result property="vipEndDate" column="vip_end_date" />
  34. <result property="vipLevel" column="vip_level" />
  35. <result property="vipStatus" column="vip_status" />
  36. <result property="sex" column="sex" />
  37. <result property="storeOpenId" column="store_open_id" />
  38. <result property="isPush" column="is_push" />
  39. <result property="isIndividuationPush" column="is_individuation_push" />
  40. <result property="isWeixinAuth" column="is_weixin_auth" />
  41. <result property="companyId" column="company_id"/>
  42. <result property="companyUserId" column="company_user_id"/>
  43. <result property="loginDevice" column="login_device" />
  44. <result property="source" column="source" />
  45. <result property="isAddQw" column="is_add_qw" />
  46. <result property="parentId" column="parent_id" />
  47. <result property="courseMaOpenId" column="course_ma_open_id" />
  48. <result property="qwExtId" column="qw_ext_id" />
  49. <result property="qwUserId" column="qw_user_id" />
  50. <result property="appId" column="app_id" />
  51. <result property="level" column="level"/>
  52. <result property="isShow" column="is_show"/>
  53. <result property="appOpenId" column="app_open_id" />
  54. <result property="appleKey" column="apple_key" />
  55. <result property="rechargeBalance" column="recharge_balance" />
  56. </resultMap>
  57. <sql id="selectFsUserVo">
  58. select user_id,qw_ext_id,recharge_balance,sex,is_buy,`level`,course_ma_open_id,is_push,is_add_qw,source,login_device,is_individuation_push,store_open_id,password,jpush_id, is_vip,vip_start_date,vip_end_date,vip_level,vip_status,nick_name,integral_status, avatar, phone, integral,sign_num, status, tui_user_id, tui_time, tui_user_count, ma_open_id, mp_open_id, union_id, is_del, user_code, remark, create_time, update_time, last_ip, balance,is_weixin_auth,parent_id,qw_user_id,app_id,company_id,company_user_id,is_promoter,now_money,brokerage_price,spread_user_id, spread_time,pay_count, spread_count,user_type,invited_by_sales_id,app_open_id,apple_key from fs_user
  59. </sql>
  60. <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
  61. <include refid="selectFsUserVo"/>
  62. <where>
  63. <if test="userId != null">and user_id = #{userId}</if>
  64. <if test="nickName != null and nickName != ''"> and nick_name like concat( #{nickName}, '%')</if>
  65. <if test="nickname != null and nickname != ''"> and nick_name like concat( #{nickname}, '%')</if>
  66. <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
  67. <if test="phone != null and phone != ''"> and phone = #{phone}</if>
  68. <if test="integral != null "> and integral = #{integral}</if>
  69. <if test="signNum != null "> and sign_num = #{signNum}</if>
  70. <if test="status != null "> and status = #{status}</if>
  71. <if test="tuiUserId != null and tuiUserId != ''"> and tui_user_id = #{tuiUserId}</if>
  72. <if test="tuiTime != null "> and tui_time = #{tuiTime}</if>
  73. <if test="tuiUserCount != null "> and tui_user_count = #{tuiUserCount}</if>
  74. <if test="maOpenId != null and maOpenId != ''"> and ma_open_id = #{maOpenId}</if>
  75. <if test="mpOpenId != null and mpOpenId != ''"> and mp_open_id = #{mpOpenId}</if>
  76. <if test="unionId != null and unionId != ''"> and union_id = #{unionId}</if>
  77. <if test="isDel != null "> and is_del = #{isDel}</if>
  78. <if test="userCode != null and userCode != ''"> and user_code = #{userCode}</if>
  79. <if test="lastIp != null and lastIp != ''"> and last_ip = #{lastIp}</if>
  80. <if test="balance != null "> and balance = #{balance}</if>
  81. <if test="level != null ">and level = #{level}</if>
  82. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  83. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  84. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  85. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  86. <if test="payCount != null ">and pay_count = #{payCount}</if>
  87. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  88. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  89. <if test="companyId != null ">and company_id = #{companyId}</if>
  90. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  91. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  92. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  93. </if>
  94. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  95. <if test="source != null and source != '' ">and source = #{source}</if>
  96. <if test="isShow != null ">and is_show = #{isShow}</if>
  97. <if test="rechargeBalance != null ">and recharge_balance = #{rechargeBalance}</if>
  98. <!--<if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  99. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>-->
  100. <!-- <if test="payOrder != null ">and pay_order = #{payOrder}</if>-->
  101. </where>
  102. </select>
  103. <select id="selectFsUserByUserId" parameterType="Long" resultMap="FsUserResult">
  104. <include refid="selectFsUserVo"/>
  105. where user_id = #{userId}
  106. </select>
  107. <select id="courseAnalysisWatchLog" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  108. SELECT
  109. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS courseWatchNum,
  110. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTimes,
  111. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS courseCompleteNum,
  112. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTimes,
  113. ifnull(
  114. ROUND(
  115. (
  116. 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,
  117. 2
  118. ),
  119. 0
  120. ) AS completeRate,
  121. fwl.video_id
  122. FROM
  123. fs_course_watch_log fwl
  124. <where>
  125. <if test="periodId != null and periodId != ''">
  126. AND fwl.period_id = #{periodId}
  127. </if>
  128. <if test="videoId != null and videoId != ''">
  129. AND fwl.video_id = #{videoId}
  130. </if>
  131. <if test="videoIdList != null and videoIdList.size > 0 ">
  132. AND fwl.video_id in
  133. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  134. #{videoId}
  135. </foreach>
  136. </if>
  137. <if test="companyId != null">
  138. AND fwl.company_id = #{companyId}
  139. </if>
  140. </where>
  141. GROUP BY
  142. fwl.video_id
  143. </select>
  144. <select id="courseAnalysisRedPacketCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  145. SELECT
  146. count( flog.log_id ) as redPacketNum,
  147. ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
  148. flog.video_id
  149. FROM
  150. fs_course_red_packet_log flog
  151. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  152. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  153. <where>
  154. <if test="companyUserId != null and companyUserId != 0 ">
  155. AND flog.company_user_id = #{companyUserId}
  156. </if>
  157. <if test="companyUserId != null and companyUserId == 0 ">
  158. and flog.company_id = #{companyId}
  159. </if>
  160. <if test="periodId != null and periodId != ''">
  161. AND flog.period_id = #{periodId}
  162. </if>
  163. <if test="videoId != null and videoId != ''">
  164. AND flog.video_id = #{videoId}
  165. </if>
  166. <if test="videoIdList != null and videoIdList.size > 0 ">
  167. AND flog.video_id in
  168. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  169. #{videoId}
  170. </foreach>
  171. </if>
  172. <if test="companyId != null">
  173. AND flog.company_id = #{companyId}
  174. </if>
  175. </where>
  176. GROUP BY
  177. flog.video_id
  178. </select>
  179. <select id="courseAnalysisAnswerCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  180. SELECT
  181. count( DISTINCT fs_user.user_id ) as answerNum,
  182. count(fs_course_answer_logs.log_id) answerTimes,
  183. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
  184. COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) as answerRightTimes,
  185. ifnull(
  186. ROUND(
  187. (
  188. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  189. 2
  190. ),
  191. 0
  192. ) as answerRightRate,
  193. fs_course_answer_logs.video_id
  194. FROM
  195. fs_course_answer_logs
  196. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  197. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  198. <where>
  199. <if test="companyUserId != null and companyUserId != 0 ">
  200. AND fs_course_answer_logs.company_user_id = #{companyUserId}
  201. </if>
  202. <if test="companyUserId != null and companyUserId == 0 ">
  203. and fs_course_answer_logs.company_id = #{companyId}
  204. </if>
  205. <if test="periodId != null and periodId != ''">
  206. AND fs_course_answer_logs.period_id = #{periodId}
  207. </if>
  208. <if test="videoId != null and videoId != ''">
  209. AND fs_course_answer_logs.video_id = #{videoId}
  210. </if>
  211. <if test="videoIdList != null and videoIdList.size > 0 ">
  212. AND fs_course_answer_logs.video_id in
  213. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  214. #{videoId}
  215. </foreach>
  216. </if>
  217. <if test="companyId != null">
  218. AND fs_course_answer_logs.company_id = #{companyId}
  219. </if>
  220. </where>
  221. GROUP BY
  222. fs_course_answer_logs.video_id
  223. </select>
  224. <select id="selectFsUserById" parameterType="Long" resultMap="FsUserResult">
  225. <include refid="selectFsUserVo"/>
  226. where user_id = #{userId}
  227. </select>
  228. <select id="selectFsUserPageList" resultType="com.fs.store.vo.h5.FsUserPageListVO">
  229. SELECT
  230. fs_user.user_id,
  231. fs_user.avatar,
  232. fs_user.nick_name as nickname,
  233. fs_user.phone,
  234. case when fs_user.app_open_id is null then 2 else 1 end as isAppUser,
  235. fs_user_course_count.id,
  236. fs_user_course_count.watch_course_count,
  237. -- fs_course_watch_log.watch_course_count,
  238. fs_user_course_count.miss_course_count,
  239. fs_user_course_count.miss_course_status,
  240. fs_user_course_count.course_ids,
  241. fs_user_course_count.part_course_count,
  242. -- fs_course_watch_log.part_course_count,
  243. fs_user_course_count.last_watch_date,
  244. fs_user_course_count.STATUS AS courseCountStatus,
  245. fs_user_course_count.stop_watch_days,
  246. fs_user_course_count.complete_watch_date,
  247. GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
  248. GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
  249. company_user.nick_name as companyUserNickName,
  250. fs_user_company_user.is_repeat_fans,
  251. fs_user_company_user.project_id,
  252. fs_user_company_user.`status`,
  253. ifnull(fs_user_company_user.remark, fs_user.remark) as remark,
  254. fs_user_company_user.id as userCompanyUserId,
  255. fs_user_company_user.create_time
  256. FROM
  257. fs_user
  258. INNER JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  259. 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
  260. left join fs_user_project_tag upt ON upt.user_company_user_id = fs_user_company_user.id
  261. LEFT JOIN company_tag ON company_tag.tag_id = upt.tag_id
  262. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  263. where fs_user.is_del = 0
  264. <choose>
  265. <when test="isAppUser != null and isAppUser == 1">
  266. and fs_user.app_open_id is not null
  267. </when>
  268. <when test="isAppUser != null and isAppUser == 2">
  269. and fs_user.app_open_id is null
  270. </when>
  271. </choose>
  272. <if test="userId != null and userId!= 0 ">
  273. and fs_user_company_user.company_user_id = #{userId}
  274. </if>
  275. <if test="companyId != null ">
  276. and fs_user_company_user.company_id = #{companyId}
  277. </if>
  278. <if test="status != null">
  279. AND fs_user_company_user.status = #{status}
  280. </if>
  281. <if test="projectId != null">
  282. AND fs_user_company_user.project_id = #{projectId}
  283. </if>
  284. <if test="keyword != null and keyword !='' ">
  285. AND (fs_user.nick_name LIKE concat('%',#{keyword} COLLATE utf8mb4_unicode_ci,'%')
  286. or fs_user.phone LIKE concat('%',#{keyword} COLLATE utf8mb4_unicode_ci,'%')
  287. )
  288. </if>
  289. <if test="registerStartTime != null and registerStartTime !='' ">
  290. AND fs_user_company_user.create_time &gt;= #{registerStartTime}
  291. </if>
  292. <if test="registerEndTime != null and registerEndTime !='' ">
  293. AND fs_user_company_user.create_time &lt;= #{registerEndTime}
  294. </if>
  295. <if test="isNullTag">
  296. and (upt.tag_id is null
  297. <if test="tagIds != null and tagIds.length > 0">
  298. or upt.tag_id in
  299. <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
  300. #{item}
  301. </foreach>
  302. </if>
  303. )
  304. </if>
  305. <if test="!isNullTag and tagIds != null and tagIds.length > 0">
  306. AND upt.tag_id in
  307. <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
  308. #{item}
  309. </foreach>
  310. </if>
  311. <if test="tabValue != null and tabValue !='' ">
  312. <choose>
  313. <when test = "tabValue == 1">
  314. AND fs_user_company_user.create_time >= CURDATE() AND fs_user_company_user.create_time &lt; CURDATE() + INTERVAL 1 DAY
  315. </when>
  316. <when test = "tabValue == 2">
  317. AND fs_user_course_count.complete_watch_date >= CURDATE() AND fs_user_course_count.complete_watch_date &lt; CURDATE() + INTERVAL 1 DAY
  318. </when>
  319. <when test = "tabValue == 3">
  320. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  321. </when>
  322. </choose>
  323. </if>
  324. <if test="watchCourseType != null and watchCourseType !='' ">
  325. <choose>
  326. <when test = "watchCourseType == 1">
  327. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  328. </when>
  329. <when test = "watchCourseType == 2">
  330. AND fs_user_course_count.status = 1
  331. </when>
  332. <when test = "watchCourseType == 3">
  333. AND fs_user_course_count.status = 2
  334. </when>
  335. </choose>
  336. </if>
  337. <if test="missCourseStatus != null and missCourseStatus !='' ">
  338. <choose>
  339. <when test = "missCourseStatus == 1">
  340. AND fs_user_course_count.miss_course_status = 1
  341. </when>
  342. <when test = "missCourseStatus == 2">
  343. AND (fs_user_course_count.miss_course_status = 2 or fs_user_course_count.miss_course_status is null )
  344. </when>
  345. </choose>
  346. </if>
  347. group by fs_user.user_id, fs_user_company_user.project_id, fs_user_company_user.create_time
  348. order by
  349. <choose>
  350. <when test = "continueMissCourseSort != null and continueMissCourseSort == 0">
  351. fs_user_company_user.create_time desc,fs_user.user_id desc
  352. </when>
  353. <when test = "continueMissCourseSort != null and continueMissCourseSort == 1">
  354. fs_user.nick_name asc,fs_user.user_id desc
  355. </when>
  356. <otherwise>
  357. fs_user.user_id desc, fs_user_company_user.project_id
  358. </otherwise>
  359. </choose>
  360. </select>
  361. <select id="selectFsUserPageListNew" resultType="com.fs.store.vo.h5.FsUserPageListVO">
  362. SELECT
  363. fs_user.user_id,
  364. fs_user.nick_name as nickname,
  365. fs_user.avatar,
  366. fs_user.phone,
  367. fs_user.create_time,
  368. fs_user.remark,
  369. ucu.id,
  370. ucu.`status`,
  371. ucu.company_user_id,
  372. ucu.company_id,
  373. ucu.project_id,
  374. fs_user.integral,
  375. if(fs_user.pay_count>0,1,0) as isBuy
  376. FROM
  377. fs_user
  378. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  379. <where>
  380. fs_user.is_del = 0
  381. <if test="userId != null">
  382. AND fs_user.user_id = #{userId}
  383. </if>
  384. <if test="status != null">
  385. AND ucu.status = #{status}
  386. </if>
  387. <if test="companyId != null">
  388. AND ucu.company_id = #{companyId}
  389. </if>
  390. <if test="companyUserId != null and companyUserId != '' ">
  391. AND ucu.company_user_id = #{companyUserId}
  392. </if>
  393. <if test="registerStartTime != null and registerStartTime !='' ">
  394. AND fs_user.create_time &gt;= #{registerStartTime}
  395. </if>
  396. <if test="registerEndTime != null and registerEndTime !='' ">
  397. AND fs_user.create_time &lt;= #{registerEndTime}
  398. </if>
  399. <if test="companyUserIds != null and companyUserIds.size > 0">
  400. AND ucu.company_user_id in
  401. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  402. ${item}
  403. </foreach>
  404. </if>
  405. <if test="nickname != null and nickname != ''">
  406. AND fs_user.nick_name like concat('%', #{nickname},'%')
  407. </if>
  408. <if test="phone != null and phone != ''">
  409. AND fs_user.phone like concat('%', #{phone},'%')
  410. </if>
  411. <if test="projectId != null">
  412. AND ucu.project_id = #{projectId}
  413. </if>
  414. <if test="eTime != null and sTime !=null">
  415. AND fs_user.create_time &gt;= #{sTime} AND fs_user.create_time &lt;= #{eTime}
  416. </if>
  417. </where>
  418. limit ${(pageNum-1)*pageSize},${pageSize}
  419. </select>
  420. <select id="selectFsUserPageListCount" resultType="java.lang.Long">
  421. SELECT
  422. count(1)
  423. FROM
  424. fs_user
  425. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  426. <where>
  427. fs_user.is_del = 0
  428. <if test="companyId != null">
  429. AND ucu.company_id = #{companyId}
  430. </if>
  431. <if test="companyUserId != null and companyUserId != '' ">
  432. AND ucu.company_user_id = #{companyUserId}
  433. </if>
  434. <if test="registerStartTime != null and registerStartTime !='' ">
  435. AND fs_user.create_time &gt;= #{registerStartTime}
  436. </if>
  437. <if test="registerEndTime != null and registerEndTime !='' ">
  438. AND fs_user.create_time &lt;= #{registerEndTime}
  439. </if>
  440. <if test="companyUserIds != null and companyUserIds.size > 0">
  441. AND ucu.company_user_id in
  442. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  443. ${item}
  444. </foreach>
  445. </if>
  446. <if test="nickname != null and nickname!=''">
  447. AND fs_user.nick_name like concat(#{nickname},'%')
  448. </if>
  449. <if test="phone != null and phone!=''">
  450. AND fs_user.phone = #{phone}
  451. </if>
  452. <if test="projectId != null">
  453. AND ucu.project_id = #{projectId}
  454. </if>
  455. </where>
  456. </select>
  457. <update id="transferCompanyUser">
  458. update fs_user
  459. set company_user_id=#{targetCompanyUserId}
  460. where
  461. user_id in
  462. <foreach collection="userIds" open="(" close=")" separator="," item="item">
  463. ${item}
  464. </foreach>
  465. </update>
  466. <update id="batchUpdateFsUserByIds" parameterType="Long">
  467. update fs_user
  468. set status = #{status} where user_id in
  469. <foreach item="id" collection="ids" open="(" separator="," close=")">
  470. #{id}
  471. </foreach>
  472. </update>
  473. <select id="selectFsUserVOList" resultType="com.fs.his.vo.FsUserVO">
  474. SELECT
  475. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  476. u.*,
  477. 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
  478. ,company.company_name
  479. FROM
  480. fs_user u
  481. LEFT JOIN (
  482. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  483. user_id
  484. FROM
  485. fs_store_payment
  486. WHERE
  487. STATUS = 1
  488. AND user_id IS NOT NULL
  489. GROUP BY
  490. user_id
  491. ) b ON u.user_id = b.user_id
  492. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  493. AND b.last_buy_time = p.pay_time
  494. AND b.payment_id = p.payment_id
  495. LEFT JOIN (
  496. SELECT
  497. fs_course_watch_log.user_id,
  498. Max( fs_course_watch_log.last_heartbeat_time ) AS last_watch_date,
  499. count( DISTINCT fs_course_watch_log.video_id ) watch_course_count,
  500. count( DISTINCT fs_course_watch_log.period_id ) part_course_count
  501. FROM
  502. fs_course_watch_log
  503. GROUP BY
  504. fs_course_watch_log.user_id
  505. ) fs_course_watch_log ON fs_course_watch_log.user_id = u.user_id
  506. LEFT JOIN company_user ON company_user.user_id = u.company_user_id
  507. LEFT JOIN company on company.company_id = company_user.company_id
  508. <where>
  509. 1 = 1
  510. <if test = "maps.userId != null">
  511. AND u.user_id LIKE CONCAT("%",#{maps.userId},"%")
  512. </if >
  513. <if test = "maps.nickname != null and maps.nickname !='' " >
  514. AND u.nickname LIKE CONCAT("%",#{maps.nickname},"%")
  515. </if >
  516. <if test = "maps.phone != null and maps.phone !='' " >
  517. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  518. </if >
  519. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  520. AND (DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  521. and DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  522. )
  523. </if >
  524. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  525. AND u.register_code = #{maps.registerCode}
  526. </if >
  527. <if test = "maps.status != null" >
  528. AND u.STATUS = #{maps.status}
  529. </if >
  530. <if test = "maps.companyUserNickName != null and maps.companyUserNickName != '' " >
  531. AND company_user.nick_name like CONCAT ("%",#{maps.companyUserNickName},"%")
  532. </if >
  533. <if test = "maps.companyName != null and maps.companyName != '' " >
  534. AND company.company_name like CONCAT ("%",#{maps.companyName},"%")
  535. </if >
  536. <if test = "maps.level != null and maps.level !=''" >
  537. AND u.LEVEL = #{maps.level}
  538. </if >
  539. <if test = "maps.isPromoter != null and maps.isPromoter !=''" >
  540. AND u.is_promoter = #{maps.isPromoter}
  541. </if >
  542. </where>
  543. ORDER BY
  544. user_id DESC
  545. </select>
  546. <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
  547. insert into fs_user
  548. <trim prefix="(" suffix=")" suffixOverrides=",">
  549. <if test="nickName != null">nick_name,</if>
  550. <if test="avatar != null">avatar,</if>
  551. <if test="phone != null">phone,</if>
  552. <if test="integral != null">integral,</if>
  553. <if test="signNum != null">sign_num,</if>
  554. <if test="status != null">status,</if>
  555. <if test="tuiUserId != null">tui_user_id,</if>
  556. <if test="tuiTime != null">tui_time,</if>
  557. <if test="tuiUserCount != null">tui_user_count,</if>
  558. <if test="maOpenId != null">ma_open_id,</if>
  559. <if test="mpOpenId != null">mp_open_id,</if>
  560. <if test="unionId != null">union_id,</if>
  561. <if test="isDel != null">is_del,</if>
  562. <if test="userCode != null">user_code,</if>
  563. <if test="remark != null">remark,</if>
  564. <if test="createTime != null">create_time,</if>
  565. <if test="updateTime != null">update_time,</if>
  566. <if test="lastIp != null">last_ip,</if>
  567. <if test="balance != null">balance,</if>
  568. <if test="integralStatus != null">integral_status,</if>
  569. <if test="isBuy != null">is_buy,</if>
  570. <if test="password != null">password,</if>
  571. <if test="jpushId != null">jpush_id,</if>
  572. <if test="isVip != null">is_vip,</if>
  573. <if test="vipStartDate != null">vip_start_date,</if>
  574. <if test="vipEndDate != null">vip_end_date,</if>
  575. <if test="vipLevel != null">vip_level,</if>
  576. <if test="vipStatus != null">vip_status,</if>
  577. <if test="sex != null">sex,</if>
  578. <if test="storeOpenId != null">store_open_id,</if>
  579. <if test="isPush != null">is_push,</if>
  580. <if test="isIndividuationPush != null">is_individuation_push,</if>
  581. <if test="isWeixinAuth != null">is_weixin_auth,</if>
  582. <if test="loginDevice != null">login_device,</if>
  583. <if test="source != null">source,</if>
  584. <if test="isAddQw != null">is_add_qw,</if>
  585. <if test="courseMaOpenId != null">course_ma_open_id,</if>
  586. <if test="qwExtId != null">qw_ext_id,</if>
  587. <if test="orderCount != null">order_count,</if>
  588. <if test="companyId != null">company_id,</if>
  589. <if test="companyUserId != null">company_user_id,</if>
  590. <if test="level != null">`level`,</if>
  591. <if test="spreadUserId != null">spread_user_id,</if>
  592. <if test="spreadTime != null">spread_time,</if>
  593. <if test="isPromoter != null">is_promoter,</if>
  594. <if test="payCount != null">pay_count,</if>
  595. <if test="spreadCount != null">spread_count,</if>
  596. <if test="appId != null">app_id,</if>
  597. <if test="appOpenId != null">app_open_id,</if>
  598. <if test="appleKey != null">apple_key,</if>
  599. <if test="appCreateTime != null">app_create_time,</if>
  600. </trim>
  601. <trim prefix="values (" suffix=")" suffixOverrides=",">
  602. <if test="nickName != null">#{nickName},</if>
  603. <if test="avatar != null">#{avatar},</if>
  604. <if test="phone != null">#{phone},</if>
  605. <if test="integral != null">#{integral},</if>
  606. <if test="signNum != null">#{signNum},</if>
  607. <if test="status != null">#{status},</if>
  608. <if test="tuiUserId != null">#{tuiUserId},</if>
  609. <if test="tuiTime != null">#{tuiTime},</if>
  610. <if test="tuiUserCount != null">#{tuiUserCount},</if>
  611. <if test="maOpenId != null">#{maOpenId},</if>
  612. <if test="mpOpenId != null">#{mpOpenId},</if>
  613. <if test="unionId != null">#{unionId},</if>
  614. <if test="isDel != null">#{isDel},</if>
  615. <if test="userCode != null">#{userCode},</if>
  616. <if test="remark != null">#{remark},</if>
  617. <if test="createTime != null">#{createTime},</if>
  618. <if test="updateTime != null">#{updateTime},</if>
  619. <if test="lastIp != null">#{lastIp},</if>
  620. <if test="balance != null">#{balance},</if>
  621. <if test="integralStatus != null">#{integralStatus},</if>
  622. <if test="isBuy != null">#{isBuy},</if>
  623. <if test="password != null">#{password},</if>
  624. <if test="jpushId != null">#{jpushId},</if>
  625. <if test="isVip != null">#{isVip},</if>
  626. <if test="vipStartDate != null">#{vipStartDate},</if>
  627. <if test="vipEndDate != null">#{vipEndDate},</if>
  628. <if test="vipLevel != null">#{vipLevel},</if>
  629. <if test="vipStatus != null">#{vipStatus},</if>
  630. <if test="sex != null">#{sex},</if>
  631. <if test="storeOpenId != null">#{storeOpenId},</if>
  632. <if test="isPush != null">#{isPush},</if>
  633. <if test="isIndividuationPush != null">#{isIndividuationPush},</if>
  634. <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
  635. <if test="loginDevice != null">#{loginDevice},</if>
  636. <if test="source != null">#{source},</if>
  637. <if test="isAddQw != null">#{isAddQw},</if>
  638. <if test="courseMaOpenId != null">#{courseMaOpenId},</if>
  639. <if test="qwExtId != null">#{qwExtId},</if>
  640. <if test="orderCount != null">#{orderCount},</if>
  641. <if test="companyId != null">#{companyId},</if>
  642. <if test="companyUserId != null">#{companyUserId},</if>
  643. <if test="level != null">#{level},</if>
  644. <if test="spreadUserId != null">#{spreadUserId},</if>
  645. <if test="spreadTime != null">#{spreadTime},</if>
  646. <if test="isPromoter != null">#{isPromoter},</if>
  647. <if test="payCount != null">#{payCount},</if>
  648. <if test="spreadCount != null">#{spreadCount},</if>
  649. <if test="appId != null">#{appId},</if>
  650. <if test="appOpenId != null">#{appOpenId},</if>
  651. <if test="appleKey != null">#{appleKey},</if>
  652. <if test="appCreateTime != null">#{appCreateTime},</if>
  653. </trim>
  654. </insert>
  655. <update id="updateFsUser" parameterType="FsUser">
  656. update fs_user
  657. <trim prefix="SET" suffixOverrides=",">
  658. <if test="nickName != null">nick_name = #{nickName},</if>
  659. <if test="avatar != null">avatar = #{avatar},</if>
  660. <if test="phone != null">phone = #{phone},</if>
  661. <if test="integral != null">integral = #{integral},</if>
  662. <if test="signNum != null">sign_num = #{signNum},</if>
  663. <if test="status != null">status = #{status},</if>
  664. <if test="tuiUserId != null">tui_user_id = #{tuiUserId},</if>
  665. <if test="tuiTime != null">tui_time = #{tuiTime},</if>
  666. <if test="tuiUserCount != null">tui_user_count = #{tuiUserCount},</if>
  667. <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
  668. <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
  669. <if test="unionId != null">union_id = #{unionId},</if>
  670. <if test="isDel != null">is_del = #{isDel},</if>
  671. <if test="userCode != null">user_code = #{userCode},</if>
  672. <if test="remark != null">remark = #{remark},</if>
  673. <if test="level != null">level = #{level},</if>
  674. <if test="createTime != null">create_time = #{createTime},</if>
  675. <if test="updateTime != null">update_time = #{updateTime},</if>
  676. <if test="lastIp != null">last_ip = #{lastIp},</if>
  677. <if test="balance != null">balance = #{balance},</if>
  678. <if test="integralStatus != null">integral_status = #{integralStatus},</if>
  679. <if test="isBuy != null">is_buy = #{isBuy},</if>
  680. <if test="isShow != null">is_show = #{isShow},</if>
  681. <if test="password != null">password = #{password},</if>
  682. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  683. <if test="isVip != null">is_vip = #{isVip},</if>
  684. <if test="vipStartDate != null">vip_start_date = #{vipStartDate},</if>
  685. <if test="vipEndDate != null">vip_end_date = #{vipEndDate},</if>
  686. <if test="vipLevel != null">vip_level = #{vipLevel},</if>
  687. <if test="vipStatus != null">vip_status = #{vipStatus},</if>
  688. <if test="sex != null">sex = #{sex},</if>
  689. <if test="storeOpenId != null">store_open_id = #{storeOpenId},</if>
  690. <if test="isPush != null">is_push = #{isPush},</if>
  691. <if test="isIndividuationPush != null">is_individuation_push = #{isIndividuationPush},</if>
  692. <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
  693. <if test="loginDevice != null">login_device = #{loginDevice},</if>
  694. <if test="source != null">source = #{source},</if>
  695. <if test="isAddQw != null">is_add_qw = #{isAddQw},</if>
  696. <if test="courseMaOpenId != null">course_ma_open_id = #{courseMaOpenId},</if>
  697. <if test="parentId != null">parent_id = #{parentId},</if>
  698. <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
  699. <if test="isPromoter != null">is_promoter = #{isPromoter},</if>
  700. <if test="companyId != null">company_id = #{companyId},</if>
  701. <if test="orderCount != null">order_count = #{orderCount},</if>
  702. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  703. <if test="appId != null">app_id = #{appId},</if>
  704. <if test="invitedBySalesId != null">invited_by_sales_id = #{invitedBySalesId},</if>
  705. <if test="appOpenId != null">app_open_id = #{appOpenId},</if>
  706. <if test="appleKey != null">apple_key = #{appleKey},</if>
  707. <if test="rechargeBalance != null">recharge_balance = #{rechargeBalance},</if>
  708. <if test="appCreateTime != null">app_create_time = #{appCreateTime},</if>
  709. </trim>
  710. where user_id = #{userId}
  711. </update>
  712. <delete id="deleteFsUserByUserId" parameterType="Long">
  713. delete from fs_user where user_id = #{userId}
  714. </delete>
  715. <delete id="deleteFsUserByUserIds" parameterType="Long">
  716. delete from fs_user where user_id in
  717. <foreach item="userId" collection="array" open="(" separator="," close=")">
  718. #{userId}
  719. </foreach>
  720. </delete>
  721. <update id="batchUpdateUserCompanyUser">
  722. update fs_user
  723. set company_id = #{companyId},
  724. company_user_id = #{companyUserId}
  725. where
  726. <foreach collection="userIds" separator="or" item="userId" index="index">
  727. user_id = #{userId}
  728. </foreach>
  729. </update>
  730. <update id="batchUpdateCompanyUserRelation">
  731. update fs_user_company_user
  732. set company_id = #{companyId},
  733. company_user_id = #{companyUserId}
  734. where is_repeat_fans = 0 and
  735. <foreach collection="userIds" open="(" close=")" separator="or" item="userId" index="index">
  736. user_id = #{userId}
  737. </foreach>
  738. </update>
  739. <update id="updatePasswordByPhone">
  740. update fs_user set password = #{password} where phone = #{encryptPhone}
  741. </update>
  742. <select id="selectUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  743. select
  744. u.user_id dictValue,
  745. u.nick_name dictLabel
  746. from fs_user u
  747. <where>
  748. <if test="params.nickName != null and params.nickName != ''">
  749. u.nick_name like concat('%', #{params.nickName}, '%')
  750. </if>
  751. </where>
  752. </select>
  753. <select id ="selectFsUserByUserIds" resultType="Integer">
  754. select count(1) from fs_user_company_user
  755. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  756. where is_repeat_fans = 1
  757. and (fs_user_company_user.company_user_id = #{companyUserId} OR company_user.parent_id = #{companyUserId})
  758. <if test="userIds != null and userIds.length > 0 ">
  759. and fs_user_company_user.user_id in
  760. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  761. #{userId}
  762. </foreach>
  763. </if>
  764. </select>
  765. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  766. select
  767. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  768. count(u.user_id) vipCount
  769. from fs_user u
  770. left join fs_user_company_user ucu on ucu.user_id = u.user_id
  771. left join company_user cu on cu.user_id = ucu.company_user_id
  772. where cu.user_id = #{companyUserId}
  773. </select>
  774. <select id="getUserNumber" resultType="com.fs.store.vo.h5.UserListCountVO">
  775. SELECT
  776. fs_user_company_user.`status` as status,
  777. count( DISTINCT fs_user.user_id ) AS num
  778. FROM
  779. fs_user
  780. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  781. WHERE fs_user.is_del = 0 and fs_user_company_user.is_repeat_fans is not null
  782. <if test="userId != null and userId != 0 ">
  783. and fs_user_company_user.company_user_id = #{userId}
  784. </if>
  785. <if test="companyId != null ">
  786. and fs_user_company_user.company_id = #{companyId}
  787. </if>
  788. GROUP BY
  789. fs_user_company_user.`status`,fs_user_company_user.project_id
  790. </select>
  791. <select id="getRepeatUserNumber" resultType="int">
  792. SELECT
  793. count( DISTINCT fs_user.user_id ) AS num
  794. FROM
  795. fs_user
  796. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  797. WHERE
  798. fs_user_company_user.company_user_id = #{userId}
  799. AND fs_user.is_del = 0
  800. AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
  801. </select>
  802. <select id="getCountWatchCourse" resultType="com.fs.store.vo.h5.UserDetailsVO">
  803. SELECT
  804. <if test="dateTag == null or dateTag =='' or dateTag == '近七天' ">
  805. ifnull( sum(complete_watch_count), 0 ) AS completeWatchCount ,
  806. ifnull( sum(watch_times), 0 ) AS watchTimes,
  807. </if>
  808. <if test="dateTag != null and dateTag !='' and dateTag != '近七天' ">
  809. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  810. ifnull( watch_times, 0 ) AS watchTimes,
  811. </if>
  812. fs_user.user_id
  813. FROM
  814. fs_user_course_count
  815. LEFT JOIN fs_user ON fs_user.user_id = fs_user_course_count.user_id
  816. 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
  817. <where>
  818. <if test="dateTag != null and dateTag !='' ">
  819. <choose>
  820. <when test = "dateTag == '今天'">
  821. and to_days(fs_user_course_count.create_time) = to_days(now())
  822. </when>
  823. <when test = "dateTag == '昨天'">
  824. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_user_course_count.create_time &lt; CURDATE()
  825. </when>
  826. <when test = "dateTag == '前天'">
  827. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_user_course_count.create_time &lt; CURDATE() - INTERVAL 1 DAY
  828. </when>
  829. <when test = "dateTag == '近七天'">
  830. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  831. </when>
  832. </choose>
  833. </if>
  834. and fs_user.user_id = #{fsUserId}
  835. <if test="userCompanyId!=null">
  836. and cu.id = #{userCompanyId}
  837. </if>
  838. </where>
  839. GROUP BY
  840. fs_user.user_id
  841. </select>
  842. <select id="getCountAnswer" resultType="com.fs.store.vo.h5.UserDetailsVO">
  843. SELECT
  844. (
  845. SELECT
  846. ifnull(count( DISTINCT fs_course_answer_logs.log_id ), 0) AS answerTime
  847. FROM
  848. fs_course_answer_logs
  849. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  850. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id =fcwl.log_id
  851. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  852. <where>
  853. <if test="dateTag != null and dateTag !='' ">
  854. <choose>
  855. <when test = "dateTag == '今天'">
  856. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  857. </when>
  858. <when test = "dateTag == '昨天'">
  859. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  860. </when>
  861. <when test = "dateTag == '前天'">
  862. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  863. </when>
  864. <when test = "dateTag == '近七天'">
  865. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  866. </when>
  867. </choose>
  868. </if>
  869. and fs_user.user_id = #{fsUserId}
  870. <if test="userCompanyId!=null">
  871. and fucu.id = #{userCompanyId}
  872. </if>
  873. </where>
  874. GROUP BY
  875. fs_user.user_id
  876. ) AS answerTime,
  877. (
  878. SELECT
  879. ifnull(count( DISTINCT fs_course_answer_logs.log_id ), 0) AS answerRightTime
  880. FROM
  881. fs_course_answer_logs
  882. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  883. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id =fcwl.log_id
  884. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  885. <where>
  886. fs_course_answer_logs.is_right = 1
  887. <if test="dateTag != null and dateTag !='' ">
  888. <choose>
  889. <when test = "dateTag == '今天'">
  890. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  891. </when>
  892. <when test = "dateTag == '昨天'">
  893. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  894. </when>
  895. <when test = "dateTag == '前天'">
  896. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  897. </when>
  898. <when test = "dateTag == '近七天'">
  899. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  900. </when>
  901. </choose>
  902. </if>
  903. and fs_user.user_id = #{fsUserId}
  904. <if test="userCompanyId!=null">
  905. and fucu.id = #{userCompanyId}
  906. </if>
  907. </where>
  908. GROUP BY
  909. fs_user.user_id
  910. ) AS answerRightTime;
  911. </select>
  912. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  913. SELECT
  914. ifnull( count( DISTINCT fs_course_red_packet_log.log_id ), 0 ) AS answerRedPacketTime,
  915. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  916. fs_user.user_id
  917. FROM
  918. fs_course_red_packet_log
  919. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  920. left join fs_course_watch_log fcwl on fs_course_red_packet_log.watch_log_id =fcwl.log_id
  921. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  922. <where>
  923. fs_course_red_packet_log.status = 1
  924. <if test="dateTag != null and dateTag !='' ">
  925. <choose>
  926. <when test = "dateTag == '今天'">
  927. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  928. </when>
  929. <when test = "dateTag == '昨天'">
  930. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE()
  931. </when>
  932. <when test = "dateTag == '前天'">
  933. 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
  934. </when>
  935. <when test = "dateTag == '近七天'">
  936. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  937. </when>
  938. </choose>
  939. </if>
  940. and fs_user.user_id = #{fsUserId}
  941. <if test="userCompanyId!=null">
  942. and fucu.id = #{userCompanyId}
  943. </if>
  944. </where>
  945. GROUP BY
  946. fs_user.user_id
  947. </select>
  948. <select id="getUserTotal" resultType="java.lang.Integer">
  949. SELECT count(fs_user.user_id) as userTotal
  950. FROM fs_user
  951. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  952. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  953. WHERE fs_user.is_del = 0
  954. <if test="userId != null and userId != 0 ">
  955. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  956. </if>
  957. <if test="companyId != null ">
  958. and ucu.company_id = #{companyId}
  959. </if>
  960. </select>
  961. <select id="getTodayNewUser" resultType="java.lang.Integer">
  962. SELECT count(fs_user.user_id) as todayNewUser
  963. FROM fs_user
  964. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  965. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  966. WHERE fs_user.is_del = 0
  967. <if test="userId != null and userId != 0 ">
  968. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  969. </if>
  970. <if test="companyId != null ">
  971. and ucu.company_id = #{companyId}
  972. </if>
  973. AND to_days(ucu.create_time) = to_days(now())
  974. </select>
  975. <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
  976. SELECT (SELECT count(fs_user.user_id)
  977. FROM fs_user
  978. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  979. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  980. WHERE fs_user.is_del = 0
  981. <if test="userId != null and userId != 0 ">
  982. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  983. </if>
  984. <if test="companyId != null ">
  985. and ucu.company_id = #{companyId}
  986. </if>
  987. ) as userTotal,
  988. (SELECT count(fs_user.user_id)
  989. FROM fs_user
  990. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  991. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  992. WHERE fs_user.is_del = 0
  993. <if test="userId != null and userId != 0 ">
  994. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  995. </if>
  996. <if test="companyId != null ">
  997. and ucu.company_id = #{companyId}
  998. </if>
  999. AND to_days(ucu.create_time) = to_days(now())) as todayNewUser
  1000. </select>
  1001. <select id="countTag" resultType="com.fs.store.vo.h5.FsUserSummaryCountTagVO">
  1002. SELECT
  1003. company_tag.tag AS tagName,
  1004. count( ucu.user_id ) AS number
  1005. FROM
  1006. fs_user_project_tag upt
  1007. inner join fs_user_company_user ucu on ucu.id = upt.user_company_user_id
  1008. inner join company_tag ON upt.tag_id = company_tag.tag_id
  1009. left join company_user on company_user.user_id = ucu.company_user_id
  1010. <where>
  1011. <if test="userId != null and userId != 0 ">
  1012. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1013. </if>
  1014. <if test="companyId != null ">
  1015. and ucu.company_id = #{companyId}
  1016. </if>
  1017. </where>
  1018. GROUP BY
  1019. company_tag.tag_id
  1020. </select>
  1021. <!-- <select id="countUserCourse" resultType="Map">-->
  1022. <!-- SELECT-->
  1023. <!-- (SELECT COUNT(*) FROM (-->
  1024. <!-- SELECT 1-->
  1025. <!-- FROM fs_user_course_count fcc-->
  1026. <!-- JOIN fs_user ON fs_user.user_id = fcc.user_id-->
  1027. <!-- JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id-->
  1028. <!-- JOIN company_user ON ucu.company_user_id = company_user.user_id-->
  1029. <!-- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0-->
  1030. <!-- <where>-->
  1031. <!-- fcc.project_id = ucu.project_id-->
  1032. <!-- <if test="userId != null and userId != 0 ">-->
  1033. <!-- and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )-->
  1034. <!-- </if>-->
  1035. <!-- <if test="userId != null and userId == 0 ">-->
  1036. <!-- and ucu.company_id = #{companyId}-->
  1037. <!-- </if>-->
  1038. <!-- <if test="startTime != null and startTime !='' ">-->
  1039. <!-- and fcc.create_time &gt;= #{startTime}-->
  1040. <!-- </if>-->
  1041. <!-- <if test="endTime != null and endTime != ''">-->
  1042. <!-- and fcc.create_time &lt;= #{endTime}-->
  1043. <!-- </if>-->
  1044. <!-- <if test="periodId != null and periodId != ''">-->
  1045. <!-- AND fcpd.period_id = #{periodId}-->
  1046. <!-- </if>-->
  1047. <!-- <if test="videoId != null and videoId != ''">-->
  1048. <!-- AND fcpd.video_id = #{videoId}-->
  1049. <!-- </if>-->
  1050. <!-- &#45;&#45; 单独通过销售id查询-->
  1051. <!-- <if test="companyUserId != null and companyUserId != ''">-->
  1052. <!-- AND company_user.user_id = #{companyUserId}-->
  1053. <!-- </if>-->
  1054. <!-- </where>-->
  1055. <!-- ) as courseWatchNum,-->
  1056. <!-- (SELECT COUNT(*) FROM (-->
  1057. <!-- SELECT 1-->
  1058. <!-- FROM fs_user_course_count fcc-->
  1059. <!-- JOIN fs_user ON fs_user.user_id = fcc.user_id-->
  1060. <!-- JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id-->
  1061. <!-- JOIN company_user ON ucu.company_user_id = company_user.user_id-->
  1062. <!-- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0-->
  1063. <!-- <where>-->
  1064. <!-- fcc.project_id = ucu.project_id-->
  1065. <!-- <if test="userId != null and userId != 0 ">-->
  1066. <!-- and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )-->
  1067. <!-- </if>-->
  1068. <!-- <if test="userId != null and userId == 0 ">-->
  1069. <!-- and ucu.company_id = #{companyId}-->
  1070. <!-- </if>-->
  1071. <!-- AND fcc.complete_watch_count > 0-->
  1072. <!-- <if test="startTime != null and startTime !='' ">-->
  1073. <!-- and fcc.create_time &gt;= #{startTime}-->
  1074. <!-- </if>-->
  1075. <!-- <if test="endTime != null and endTime != ''">-->
  1076. <!-- and fcc.create_time &lt;= #{endTime}-->
  1077. <!-- </if>-->
  1078. <!-- <if test="periodId != null and periodId != ''">-->
  1079. <!-- AND fcpd.period_id = #{periodId}-->
  1080. <!-- </if>-->
  1081. <!-- <if test="videoId != null and videoId != ''">-->
  1082. <!-- AND fcpd.video_id = #{videoId}-->
  1083. <!-- </if>-->
  1084. <!-- &#45;&#45; 单独通过销售id查询-->
  1085. <!-- <if test="companyUserId != null and companyUserId != ''">-->
  1086. <!-- AND company_user.user_id = #{companyUserId}-->
  1087. <!-- </if>-->
  1088. <!-- </where>-->
  1089. <!-- GROUP BY fcc.user_id, ucu.project_id-->
  1090. <!-- ) AS complete_counts ) as courseCompleteNum-->
  1091. <!-- </select>-->
  1092. <select id="countUserStats" resultType="Map">
  1093. SELECT
  1094. -- 观看人数
  1095. (
  1096. SELECT COUNT(DISTINCT l.user_id)
  1097. FROM fs_course_watch_log l
  1098. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  1099. <where>
  1100. l.log_type != 3 AND l.send_type = 1
  1101. <if test="userId != null and userId != 0 ">
  1102. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1103. </if>
  1104. <if test="userId != null and userId == 0 ">
  1105. AND l.company_id = #{companyId}
  1106. </if>
  1107. <if test="periodId != null and periodId != '' ">
  1108. AND l.period_id = #{periodId}
  1109. </if>
  1110. <if test="videoId != null and videoId != '' ">
  1111. AND l.video_id = #{videoId}
  1112. </if>
  1113. <if test="startTime != null and startTime != '' ">
  1114. AND l.create_time &gt;= #{startTime}
  1115. </if>
  1116. <if test="endTime != null and endTime != '' ">
  1117. AND l.create_time &lt;= #{endTime}
  1118. </if>
  1119. <if test="companyUserId != null and companyUserId != '' ">
  1120. AND l.company_user_id = #{companyUserId}
  1121. </if>
  1122. </where>
  1123. ) AS courseWatchNum,
  1124. -- 完成人数
  1125. (
  1126. SELECT COUNT(DISTINCT l.user_id)
  1127. FROM fs_course_watch_log l
  1128. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  1129. <where>
  1130. l.log_type = 2 AND l.send_type = 1
  1131. <if test="userId != null and userId != 0 ">
  1132. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1133. </if>
  1134. <if test="userId != null and userId == 0 ">
  1135. AND l.company_id = #{companyId}
  1136. </if>
  1137. <if test="periodId != null and periodId != '' ">
  1138. AND l.period_id = #{periodId}
  1139. </if>
  1140. <if test="videoId != null and videoId != '' ">
  1141. AND l.video_id = #{videoId}
  1142. </if>
  1143. <if test="startTime != null and startTime != '' ">
  1144. AND l.create_time &gt;= #{startTime}
  1145. </if>
  1146. <if test="endTime != null and endTime != '' ">
  1147. AND l.create_time &lt;= #{endTime}
  1148. </if>
  1149. <if test="companyUserId != null and companyUserId != '' ">
  1150. AND l.company_user_id = #{companyUserId}
  1151. </if>
  1152. </where>
  1153. ) AS courseCompleteNum,
  1154. -- 答题人数
  1155. (
  1156. SELECT COUNT(distinct a.user_id)
  1157. FROM fs_course_answer_logs a
  1158. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  1159. <where>
  1160. 1=1
  1161. <if test="userId != null and userId != 0 ">
  1162. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1163. </if>
  1164. <if test="userId != null and userId == 0 ">
  1165. AND a.company_id = #{companyId}
  1166. </if>
  1167. <if test="periodId != null and periodId != '' ">
  1168. AND a.period_id = #{periodId}
  1169. </if>
  1170. <if test="videoId != null and videoId != '' ">
  1171. AND a.video_id = #{videoId}
  1172. </if>
  1173. <if test="startTime != null and startTime != '' ">
  1174. AND a.create_time &gt;= #{startTime}
  1175. </if>
  1176. <if test="endTime != null and endTime != '' ">
  1177. AND a.create_time &lt;= #{endTime}
  1178. </if>
  1179. <if test="companyUserId != null and companyUserId != '' ">
  1180. AND a.company_user_id = #{companyUserId}
  1181. </if>
  1182. </where>
  1183. ) AS answerNum,
  1184. -- 答对人数
  1185. (
  1186. SELECT COUNT(distinct a.user_id)
  1187. FROM fs_course_answer_logs a
  1188. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  1189. <where>
  1190. a.is_right = 1
  1191. <if test="userId != null and userId != 0 ">
  1192. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1193. </if>
  1194. <if test="userId != null and userId == 0 ">
  1195. AND a.company_id = #{companyId}
  1196. </if>
  1197. <if test="periodId != null and periodId != '' ">
  1198. AND a.period_id = #{periodId}
  1199. </if>
  1200. <if test="videoId != null and videoId != '' ">
  1201. AND a.video_id = #{videoId}
  1202. </if>
  1203. <if test="startTime != null and startTime != '' ">
  1204. AND a.create_time &gt;= #{startTime}
  1205. </if>
  1206. <if test="endTime != null and endTime != '' ">
  1207. AND a.create_time &lt;= #{endTime}
  1208. </if>
  1209. <if test="companyUserId != null and companyUserId != '' ">
  1210. AND a.company_user_id = #{companyUserId}
  1211. </if>
  1212. </where>
  1213. ) AS answerRightNum,
  1214. -- 红包数
  1215. (
  1216. SELECT COUNT(flog.log_id)
  1217. FROM fs_course_red_packet_log flog
  1218. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1219. <where>
  1220. flog.status = 1
  1221. <if test="userId != null and userId != 0 ">
  1222. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1223. </if>
  1224. <if test="userId != null and userId == 0 ">
  1225. AND flog.company_id = #{companyId}
  1226. </if>
  1227. <if test="periodId != null and periodId != '' ">
  1228. AND flog.period_id = #{periodId}
  1229. </if>
  1230. <if test="videoId != null and videoId != '' ">
  1231. AND flog.video_id = #{videoId}
  1232. </if>
  1233. <if test="startTime != null and startTime != '' ">
  1234. AND flog.create_time &gt;= #{startTime}
  1235. </if>
  1236. <if test="endTime != null and endTime != '' ">
  1237. AND flog.create_time &lt;= #{endTime}
  1238. </if>
  1239. <if test="companyUserId != null and companyUserId != '' ">
  1240. AND flog.company_user_id = #{companyUserId}
  1241. </if>
  1242. </where>
  1243. ) AS redPacketNum,
  1244. -- 红包金额
  1245. (
  1246. SELECT IFNULL(SUM(flog.amount), 0)
  1247. FROM fs_course_red_packet_log flog
  1248. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1249. <where>
  1250. flog.status = 1
  1251. <if test="userId != null and userId != 0 ">
  1252. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1253. </if>
  1254. <if test="userId != null and userId == 0 ">
  1255. AND flog.company_id = #{companyId}
  1256. </if>
  1257. <if test="periodId != null and periodId != '' ">
  1258. AND flog.period_id = #{periodId}
  1259. </if>
  1260. <if test="videoId != null and videoId != '' ">
  1261. AND flog.video_id = #{videoId}
  1262. </if>
  1263. <if test="startTime != null and startTime != '' ">
  1264. AND flog.create_time &gt;= #{startTime}
  1265. </if>
  1266. <if test="endTime != null and endTime != '' ">
  1267. AND flog.create_time &lt;= #{endTime}
  1268. </if>
  1269. <if test="companyUserId != null and companyUserId != '' ">
  1270. AND flog.company_user_id = #{companyUserId}
  1271. </if>
  1272. </where>
  1273. ) AS redPacketAmount
  1274. </select>
  1275. <!-- 查询观看和完成人数 -->
  1276. <select id="countUserWatchStats" resultType="Map">
  1277. SELECT
  1278. COUNT(DISTINCT CASE WHEN l.log_type != 3 AND l.send_type = 1 THEN l.user_id END) AS courseWatchNum,
  1279. COUNT(DISTINCT CASE WHEN l.log_type = 2 AND l.send_type = 1 THEN l.user_id END) AS courseCompleteNum
  1280. FROM fs_course_watch_log l
  1281. LEFT JOIN company_user cu_l ON l.company_user_id = cu_l.user_id
  1282. <where>
  1283. <if test="userId != null and userId != 0">
  1284. AND (cu_l.user_id = #{userId} OR cu_l.parent_id = #{userId})
  1285. </if>
  1286. <if test="userId != null and userId == 0">
  1287. AND l.company_id = #{companyId}
  1288. </if>
  1289. <if test="periodId != null and periodId != ''">
  1290. AND l.period_id = #{periodId}
  1291. </if>
  1292. <if test="videoId != null and videoId != ''">
  1293. AND l.video_id = #{videoId}
  1294. </if>
  1295. <if test="startTime != null and startTime != ''">
  1296. AND l.create_time &gt;= #{startTime}
  1297. </if>
  1298. <if test="endTime != null and endTime != ''">
  1299. AND l.create_time &lt;= #{endTime}
  1300. </if>
  1301. <if test="companyUserId != null and companyUserId != ''">
  1302. AND l.company_user_id = #{companyUserId}
  1303. </if>
  1304. </where>
  1305. </select>
  1306. <!-- 查询答题人数和答对人数 -->
  1307. <select id="countUserAnswerStats" resultType="Map">
  1308. SELECT
  1309. COUNT(DISTINCT CASE WHEN a.user_id THEN a.user_id END) AS answerNum,
  1310. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS answerRightNum
  1311. FROM fs_course_answer_logs a
  1312. LEFT JOIN company_user cu_a ON a.company_user_id = cu_a.user_id
  1313. <where>
  1314. <if test="userId != null and userId != 0">
  1315. AND (cu_a.user_id = #{userId} OR cu_a.parent_id = #{userId})
  1316. </if>
  1317. <if test="userId != null and userId == 0">
  1318. AND a.company_id = #{companyId}
  1319. </if>
  1320. <if test="periodId != null and periodId != ''">
  1321. AND a.period_id = #{periodId}
  1322. </if>
  1323. <if test="videoId != null and videoId != ''">
  1324. AND a.video_id = #{videoId}
  1325. </if>
  1326. <if test="startTime != null and startTime != ''">
  1327. AND a.create_time &gt;= #{startTime}
  1328. </if>
  1329. <if test="endTime != null and endTime != ''">
  1330. AND a.create_time &lt;= #{endTime}
  1331. </if>
  1332. <if test="companyUserId != null and companyUserId != ''">
  1333. AND a.company_user_id = #{companyUserId}
  1334. </if>
  1335. </where>
  1336. </select>
  1337. <!-- 查询红包数量和红包金额 -->
  1338. <select id="countUserRedPacketStats" resultType="Map">
  1339. SELECT
  1340. COUNT(CASE WHEN flog.status = 1 THEN flog.log_id END) AS redPacketNum,
  1341. IFNULL(SUM(CASE WHEN flog.status = 1 THEN flog.amount END), 0) AS redPacketAmount
  1342. FROM fs_course_red_packet_log flog
  1343. LEFT JOIN company_user cu_flog ON flog.company_user_id = cu_flog.user_id
  1344. <where>
  1345. <if test="userId != null and userId != 0">
  1346. AND (cu_flog.user_id = #{userId} OR cu_flog.parent_id = #{userId})
  1347. </if>
  1348. <if test="userId != null and userId == 0">
  1349. AND flog.company_id = #{companyId}
  1350. </if>
  1351. <if test="periodId != null and periodId != ''">
  1352. AND flog.period_id = #{periodId}
  1353. </if>
  1354. <if test="videoId != null and videoId != ''">
  1355. AND flog.video_id = #{videoId}
  1356. </if>
  1357. <if test="startTime != null and startTime != ''">
  1358. AND flog.create_time &gt;= #{startTime}
  1359. </if>
  1360. <if test="endTime != null and endTime != ''">
  1361. AND flog.create_time &lt;= #{endTime}
  1362. </if>
  1363. <if test="companyUserId != null and companyUserId != ''">
  1364. AND flog.company_user_id = #{companyUserId}
  1365. </if>
  1366. </where>
  1367. </select>
  1368. <select id="countUserAnswer" resultType="Map">
  1369. SELECT
  1370. (
  1371. SELECT
  1372. count(distinct fs_user.user_id )
  1373. FROM
  1374. fs_course_answer_logs
  1375. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1376. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1377. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1378. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1379. <where>
  1380. <if test="userId != null and userId != 0 ">
  1381. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1382. </if>
  1383. <if test="userId != null and userId == 0 ">
  1384. and fs_course_answer_logs.company_id = #{companyId}
  1385. </if>
  1386. <if test="startTime != null and startTime !='' ">
  1387. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1388. </if>
  1389. <if test="endTime != null and endTime != ''">
  1390. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1391. </if>
  1392. <if test="periodId != null and periodId != ''">
  1393. AND fs_course_answer_logs.period_id = #{periodId}
  1394. </if>
  1395. <if test="videoId != null and videoId != ''">
  1396. AND fs_course_answer_logs.video_id = #{videoId}
  1397. </if>
  1398. -- 单独通过销售id查询
  1399. <if test="companyUserId != null and companyUserId != ''">
  1400. AND company_user.user_id = #{companyUserId}
  1401. </if>
  1402. </where>
  1403. ) AS answerNum,
  1404. (
  1405. SELECT
  1406. count(distinct fs_user.user_id )
  1407. FROM
  1408. fs_course_answer_logs
  1409. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1410. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1411. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1412. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1413. <where>
  1414. <if test="userId != null and userId != 0 ">
  1415. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1416. </if>
  1417. <if test="userId != null and userId == 0 ">
  1418. and fs_course_answer_logs.company_id = #{companyId}
  1419. </if>
  1420. AND fs_course_answer_logs.is_right = 1
  1421. <if test="startTime != null and startTime !='' ">
  1422. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1423. </if>
  1424. <if test="endTime != null and endTime != ''">
  1425. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1426. </if>
  1427. <if test="periodId != null and periodId != ''">
  1428. AND fs_course_answer_logs.period_id = #{periodId}
  1429. </if>
  1430. <if test="videoId != null and videoId != ''">
  1431. AND fs_course_answer_logs.video_id = #{videoId}
  1432. </if>
  1433. -- 单独通过销售id查询
  1434. <if test="companyUserId != null and companyUserId != ''">
  1435. AND company_user.user_id = #{companyUserId}
  1436. </if>
  1437. </where>
  1438. ) AS answerRightNum
  1439. </select>
  1440. <!-- <select id="countCourseDetails" resultType="Map">-->
  1441. <!-- select (SELECT-->
  1442. <!-- count( DISTINCT fcpd.period_id )-->
  1443. <!-- FROM-->
  1444. <!-- fs_user_course_period_days fcpd-->
  1445. <!-- LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id-->
  1446. <!-- LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0-->
  1447. <!-- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id-->
  1448. <!-- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id-->
  1449. <!-- WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0-->
  1450. <!-- AND FIND_IN_SET(#{companyId}, fpd.company_id)-->
  1451. <!-- <if test="userId != null and userId != 0 ">-->
  1452. <!-- AND ucu.company_user_id = #{userId}-->
  1453. <!-- </if>-->
  1454. <!-- <if test="userId != null and userId == 0 ">-->
  1455. <!-- and ucu.company_id = #{companyId}-->
  1456. <!-- </if>-->
  1457. <!-- <if test="periodId != null and periodId != ''">-->
  1458. <!-- AND fcpd.period_id = #{periodId}-->
  1459. <!-- </if>-->
  1460. <!-- &#45;&#45; 单独通过销售id查询-->
  1461. <!-- <if test="companyUserId != null and companyUserId != ''">-->
  1462. <!-- AND ucu.company_user_id = #{companyUserId}-->
  1463. <!-- </if>-->
  1464. <!-- ) as courseNum,-->
  1465. <!-- (SELECT count(DISTINCT fcpd.video_id)-->
  1466. <!-- FROM fs_user_course_period_days fcpd-->
  1467. <!-- LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id-->
  1468. <!-- LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0-->
  1469. <!-- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id-->
  1470. <!-- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id-->
  1471. <!-- WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0-->
  1472. <!-- AND FIND_IN_SET(#{companyId}, fpd.company_id)-->
  1473. <!-- <if test="userId != null and userId != 0 ">-->
  1474. <!-- AND ucu.company_user_id = #{userId}-->
  1475. <!-- </if>-->
  1476. <!-- <if test="userId != null and userId == 0 ">-->
  1477. <!-- and ucu.company_id = #{companyId}-->
  1478. <!-- </if>-->
  1479. <!-- <if test="periodId != null and periodId != ''">-->
  1480. <!-- AND fcpd.period_id = #{periodId}-->
  1481. <!-- </if>-->
  1482. <!-- <if test="videoId != null and videoId != ''">-->
  1483. <!-- AND fcpd.video_id = #{videoId}-->
  1484. <!-- </if>-->
  1485. <!-- &#45;&#45; 单独通过销售id查询-->
  1486. <!-- <if test="companyUserId != null and companyUserId != ''">-->
  1487. <!-- AND ucu.company_user_id = #{companyUserId}-->
  1488. <!-- </if>-->
  1489. <!-- ) as videoNum,-->
  1490. <!-- ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc-->
  1491. <!-- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0-->
  1492. <!-- LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id-->
  1493. <!-- left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id-->
  1494. <!-- <if test="periodId != null and periodId != ''">-->
  1495. <!-- AND fcpd.period_id = #{periodId}-->
  1496. <!-- </if>-->
  1497. <!-- <if test="videoId != null and videoId != ''">-->
  1498. <!-- AND fcpd.video_id = #{videoId}-->
  1499. <!-- </if>-->
  1500. <!-- &#45;&#45; 单独通过销售id查询-->
  1501. <!-- <if test="companyUserId != null and companyUserId != ''">-->
  1502. <!-- AND ucu.company_user_id = #{companyUserId}-->
  1503. <!-- </if>-->
  1504. <!-- <where>-->
  1505. <!-- <if test="userId != null and userId != 0 ">-->
  1506. <!-- AND ucu.company_user_id = #{userId}-->
  1507. <!-- </if>-->
  1508. <!-- <if test="userId != null and userId == 0 ">-->
  1509. <!-- and ucu.company_id = #{companyId}-->
  1510. <!-- </if>-->
  1511. <!-- </where>-->
  1512. <!-- ) as courseUserNum-->
  1513. <!-- </select>-->
  1514. <select id="countUserRankingByComplete" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1515. SELECT
  1516. company_user.nick_name as userName,
  1517. ifnull(
  1518. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  1519. ) as completeRate
  1520. FROM
  1521. fs_user_course_count fcc
  1522. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1523. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1524. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1525. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1526. <where>
  1527. <if test="userId != null and userId != 0 ">
  1528. AND ( ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1529. </if>
  1530. <if test="userId != null and userId == 0 ">
  1531. and ucu.company_id = #{companyId}
  1532. </if>
  1533. <if test="startTime != null and startTime !='' ">
  1534. AND fcc.create_time &gt;= #{startTime}
  1535. </if>
  1536. <if test="endTime != null and endTime != ''">
  1537. AND fcc.create_time &lt;= #{endTime}
  1538. </if>
  1539. <if test="periodId != null and periodId != ''">
  1540. AND fcpd.period_id = #{periodId}
  1541. </if>
  1542. <if test="videoId != null and videoId != ''">
  1543. AND fcpd.video_id = #{videoId}
  1544. </if>
  1545. </where>
  1546. group by fcc.user_id
  1547. <choose>
  1548. <when test="order != null and order == 'asc'">
  1549. order by completeRate asc
  1550. </when>
  1551. <when test="order != null and order == 'desc'">
  1552. order by completeRate desc
  1553. </when>
  1554. <otherwise>
  1555. order by completeRate desc
  1556. </otherwise>
  1557. </choose>
  1558. limit 20
  1559. </select>
  1560. <select id="countUserRankingByRight" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1561. SELECT
  1562. company_user.nick_name as userName,
  1563. ifnull(ROUND(
  1564. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1565. *100,2),0
  1566. ) as answerRightRate
  1567. FROM
  1568. fs_course_answer_logs
  1569. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1570. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1571. <where>
  1572. <if test="userId != null and userId != 0 ">
  1573. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1574. </if>
  1575. <if test="userId != null and userId == 0 ">
  1576. and fs_course_answer_logs.company_id = #{companyId}
  1577. </if>
  1578. <if test="startTime != null and startTime !='' ">
  1579. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1580. </if>
  1581. <if test="endTime != null and endTime != ''">
  1582. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1583. </if>
  1584. <if test="periodId != null and periodId != ''">
  1585. AND fs_course_answer_logs.period_id = #{periodId}
  1586. </if>
  1587. <if test="videoId != null and videoId != ''">
  1588. AND fs_course_answer_logs.video_id = #{videoId}
  1589. </if>
  1590. </where>
  1591. group by fs_user.user_id
  1592. <choose>
  1593. <when test="order != null and order == 'asc'">
  1594. order by answerRightRate asc
  1595. </when>
  1596. <when test="order != null and order == 'desc'">
  1597. order by answerRightRate desc
  1598. </when>
  1599. <otherwise>
  1600. order by answerRightRate desc
  1601. </otherwise>
  1602. </choose>
  1603. limit 20
  1604. </select>
  1605. <select id="countCourseRankingByComplete" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1606. SELECT
  1607. fcv.title AS videoName,
  1608. fcv.video_id,
  1609. ifnull(
  1610. ROUND(
  1611. (
  1612. 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,
  1613. 2
  1614. ),
  1615. 0
  1616. ) AS completeRate
  1617. FROM
  1618. fs_course_watch_log fwl
  1619. LEFT JOIN fs_user ON fs_user.user_id = fwl.user_id
  1620. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1621. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1622. -- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1623. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fwl.video_id
  1624. <where>
  1625. <if test="userId != null and userId != 0 ">
  1626. AND ( fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1627. </if>
  1628. <if test="userId != null and userId == 0 ">
  1629. and fs_user_company_user.company_id = #{companyId}
  1630. </if>
  1631. <if test="startTime != null and startTime !='' ">
  1632. AND fwl.create_time &gt;= #{startTime}
  1633. </if>
  1634. <if test="endTime != null and endTime != ''">
  1635. AND fwl.create_time &lt;= #{endTime}
  1636. </if>
  1637. <if test="periodId != null and periodId != ''">
  1638. AND fwl.period_id = #{periodId}
  1639. </if>
  1640. <if test="videoId != null and videoId != ''">
  1641. AND fwl.video_id = #{videoId}
  1642. </if>
  1643. </where>
  1644. GROUP BY
  1645. fwl.video_id
  1646. <choose>
  1647. <when test="order != null and order == 'asc'">
  1648. ORDER BY completeRate asc
  1649. </when>
  1650. <when test="order != null and order == 'desc'">
  1651. ORDER BY completeRate desc
  1652. </when>
  1653. <otherwise>
  1654. ORDER BY completeRate desc
  1655. </otherwise>
  1656. </choose>
  1657. LIMIT 20
  1658. </select>
  1659. <select id="countCourseRankingByRight" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1660. SELECT
  1661. fcv.title AS videoName,
  1662. ifnull(
  1663. ROUND(
  1664. (
  1665. 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,
  1666. 2
  1667. ),
  1668. 0
  1669. ) AS answerRightRate
  1670. FROM
  1671. fs_course_answer_logs
  1672. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1673. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1674. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1675. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1676. <where>
  1677. <if test="userId != null and userId != 0 ">
  1678. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1679. </if>
  1680. <if test="userId != null and userId == 0 ">
  1681. and fs_course_answer_logs.company_id = #{companyId}
  1682. </if>
  1683. <if test="startTime != null and startTime !='' ">
  1684. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1685. </if>
  1686. <if test="endTime != null and endTime != ''">
  1687. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1688. </if>
  1689. <if test="periodId != null and periodId != ''">
  1690. AND fs_course_answer_logs.period_id = #{periodId}
  1691. </if>
  1692. <if test="videoId != null and videoId != ''">
  1693. AND fs_course_answer_logs.video_id = #{videoId}
  1694. </if>
  1695. </where>
  1696. GROUP BY
  1697. fs_course_answer_logs.video_id
  1698. <choose>
  1699. <when test="order != null and order == 'asc'">
  1700. ORDER BY answerRightRate asc
  1701. </when>
  1702. <when test="order != null and order == 'desc'">
  1703. ORDER BY answerRightRate desc
  1704. </when>
  1705. <otherwise>
  1706. ORDER BY answerRightRate desc
  1707. </otherwise>
  1708. </choose>
  1709. LIMIT 20
  1710. </select>
  1711. <select id="countUserRedPacket" resultType="Map">
  1712. SELECT
  1713. (
  1714. SELECT
  1715. count( flog.log_id )
  1716. FROM
  1717. fs_course_red_packet_log flog
  1718. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1719. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1720. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1721. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1722. where flog.status = 1
  1723. <if test="userId != null and userId != 0 ">
  1724. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1725. </if>
  1726. <if test="userId != null and userId == 0 ">
  1727. and flog.company_id = #{companyId}
  1728. </if>
  1729. <if test="startTime != null and startTime !='' ">
  1730. AND flog.create_time &gt;= #{startTime}
  1731. </if>
  1732. <if test="endTime != null and endTime != ''">
  1733. AND flog.create_time &lt;= #{endTime}
  1734. </if>
  1735. <if test="periodId != null and periodId != ''">
  1736. AND flog.period_id = #{periodId}
  1737. </if>
  1738. <if test="videoId != null and videoId != ''">
  1739. AND flog.video_id = #{videoId}
  1740. </if>
  1741. -- 单独通过销售id查询
  1742. <if test="companyUserId != null and companyUserId != ''">
  1743. AND company_user.user_id = #{companyUserId}
  1744. </if>
  1745. ) AS redPacketNum,
  1746. (
  1747. SELECT
  1748. ifnull (sum( flog.amount ), 0)
  1749. FROM
  1750. fs_course_red_packet_log flog
  1751. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1752. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1753. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1754. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1755. where flog.status = 1
  1756. <if test="userId != null and userId != 0 ">
  1757. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1758. </if>
  1759. <if test="userId != null and userId == 0 ">
  1760. and flog.company_id = #{companyId}
  1761. </if>
  1762. <if test="startTime != null and startTime !='' ">
  1763. AND flog.create_time &gt;= #{startTime}
  1764. </if>
  1765. <if test="endTime != null and endTime != ''">
  1766. AND flog.create_time &lt;= #{endTime}
  1767. </if>
  1768. <if test="periodId != null and periodId != ''">
  1769. AND flog.period_id = #{periodId}
  1770. </if>
  1771. <if test="videoId != null and videoId != ''">
  1772. AND flog.video_id = #{videoId}
  1773. </if>
  1774. -- 单独通过销售id查询
  1775. <if test="companyUserId != null and companyUserId != ''">
  1776. AND company_user.user_id = #{companyUserId}
  1777. </if>
  1778. ) AS redPacketAmount
  1779. </select>
  1780. <select id="courseAnalysisCourseCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  1781. SELECT
  1782. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1783. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1784. ifnull(
  1785. ROUND(
  1786. (
  1787. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1788. 2
  1789. ),
  1790. 0
  1791. ) as completeRate,
  1792. fcpd.video_id
  1793. FROM
  1794. fs_user_course_count fcc
  1795. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1796. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1797. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1798. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1799. <where>
  1800. <if test="companyUserId != null and companyUserId != 0 ">
  1801. AND ucu.company_user_id = #{companyUserId}
  1802. </if>
  1803. <if test="companyUserId != null and companyUserId == 0 ">
  1804. and ucu.company_id = #{companyId}
  1805. </if>
  1806. <if test="periodId != null and periodId != ''">
  1807. AND fcpd.period_id = #{periodId}
  1808. </if>
  1809. <if test="videoId != null and videoId != ''">
  1810. AND fcpd.video_id = #{videoId}
  1811. </if>
  1812. </where>
  1813. GROUP BY
  1814. fcpd.video_id
  1815. </select>
  1816. <select id="companyUserCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1817. SELECT
  1818. (
  1819. 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
  1820. <where>
  1821. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1822. AND ucu.company_user_id = #{companyUserId}
  1823. </if>
  1824. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1825. and ucu.company_id = #{companyId}
  1826. </if>
  1827. </where>
  1828. ) AS userTotal,
  1829. (
  1830. SELECT
  1831. count( fs_user.user_id )
  1832. FROM
  1833. fs_user
  1834. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1835. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1836. <where>
  1837. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1838. AND ucu.company_user_id = #{companyUserId}
  1839. </if>
  1840. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1841. and ucu.company_id = #{companyId}
  1842. </if>
  1843. and fs_user.is_del = 0
  1844. AND to_days( fs_user.create_time ) = to_days(
  1845. now())
  1846. </where>
  1847. ) AS todayNewUser
  1848. </select>
  1849. <select id="newUserRedPacketCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1850. SELECT
  1851. count(flog.log_id) as userRedPacketNum,
  1852. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1853. FROM
  1854. fs_course_red_packet_log flog
  1855. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1856. <where>
  1857. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1858. AND flog.company_user_id = #{companyUserId}
  1859. </if>
  1860. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1861. and flog.company_id = #{companyId}
  1862. </if>
  1863. </where>
  1864. </select>
  1865. <select id="countUserCourse2" resultType="java.util.Map">
  1866. SELECT
  1867. (
  1868. SELECT
  1869. count(DISTINCT l.user_id)
  1870. FROM
  1871. fs_course_watch_log l
  1872. LEFT JOIN fs_user on fs_user.user_id = l.user_id
  1873. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1874. 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
  1875. where
  1876. l.log_type != 3 and send_type = 1
  1877. <if test="userId != null and userId != 0 ">
  1878. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1879. </if>
  1880. <if test="userId != null and userId == 0 ">
  1881. and l.company_id = #{companyId}
  1882. </if>
  1883. <if test="periodId != null and periodId != ''">
  1884. AND l.period_id = #{periodId}
  1885. </if>
  1886. <if test="videoId != null and videoId != ''">
  1887. AND l.video_id = #{videoId}
  1888. </if>
  1889. <if test="startTime != null and startTime !='' ">
  1890. and l.create_time &gt;= #{startTime}
  1891. </if>
  1892. <if test="endTime != null and endTime != ''">
  1893. and l.create_time &lt;= #{endTime}
  1894. </if> <if test="companyUserId != null and companyUserId != ''">
  1895. AND l.user_id = #{companyUserId}
  1896. </if>
  1897. -- 单独通过销售id查询
  1898. <if test="companyUserId != null and companyUserId != ''">
  1899. AND l.company_user_id = #{companyUserId}
  1900. </if>
  1901. ) as courseWatchNum,
  1902. (
  1903. SELECT
  1904. count(DISTINCT l.user_id)
  1905. FROM
  1906. fs_course_watch_log l
  1907. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1908. LEFT JOIN fs_user ON fs_user.user_id = l.user_id
  1909. 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
  1910. where
  1911. l.log_type = 2 and send_type = 1
  1912. <if test="userId != null and userId != 0 ">
  1913. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1914. </if>
  1915. <if test="userId != null and userId == 0 ">
  1916. and l.company_id = #{companyId}
  1917. </if>
  1918. <if test="periodId != null and periodId != ''">
  1919. AND l.period_id = #{periodId}
  1920. </if>
  1921. <if test="videoId != null and videoId != ''">
  1922. AND l.video_id = #{videoId}
  1923. </if>
  1924. <if test="startTime != null and startTime !='' ">
  1925. and l.create_time &gt;= #{startTime}
  1926. </if>
  1927. <if test="endTime != null and endTime != ''">
  1928. and l.create_time &lt;= #{endTime}
  1929. </if>
  1930. -- 单独通过销售id查询
  1931. <if test="companyUserId != null and companyUserId != ''">
  1932. AND l.company_user_id = #{companyUserId}
  1933. </if>
  1934. ) as courseCompleteNum
  1935. </select>
  1936. <select id="countCourseDetailsNew" resultType="Map">
  1937. SELECT
  1938. count( DISTINCT l.period_id ) as courseNum,
  1939. count( DISTINCT l.video_id ) as videoNum,
  1940. count( DISTINCT l.user_id ) as courseUserNum
  1941. FROM
  1942. fs_course_watch_log l
  1943. left join fs_user on fs_user.user_id = l.user_id
  1944. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1945. WHERE
  1946. l.log_type != 3
  1947. AND send_type = 1
  1948. <if test="userId != null and userId != 0 ">
  1949. AND l.company_user_id = #{userId}
  1950. </if>
  1951. <if test="userId != null and userId == 0 ">
  1952. and l.company_id = #{companyId}
  1953. </if>
  1954. <if test="periodId != null and periodId != ''">
  1955. AND l.period_id = #{periodId}
  1956. </if>
  1957. <if test="videoId != null and videoId != ''">
  1958. AND l.video_id = #{videoId}
  1959. </if>
  1960. -- 单独通过销售id查询
  1961. <if test="companyUserId != null and companyUserId != ''">
  1962. AND l.company_user_id = #{companyUserId}
  1963. </if>
  1964. </select>
  1965. <select id="selectFsUserVOListByProjectNew" resultType="com.fs.his.vo.FsUserVO">
  1966. SELECT
  1967. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  1968. ucu.project_id,ucu.id as companyUserId,ucu.create_time as bindTime,ucu.status,
  1969. company.company_name,
  1970. cu.nick_name companyUserNickName
  1971. FROM
  1972. fs_user_company_user ucu
  1973. left join
  1974. fs_user u on ucu.user_id = u.user_id
  1975. left join
  1976. company on company.company_id = ucu.company_id
  1977. left join
  1978. company_user cu on cu.user_id = ucu.company_user_id
  1979. <where>
  1980. 1 = 1 and u.nick_name is not null
  1981. and u.is_del = 0
  1982. <if test = "maps.nickname != null and maps.nickname !='' " >
  1983. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  1984. </if >
  1985. <if test = "maps.nicknameExact != null and maps.nicknameExact !='' " >
  1986. AND u.nick_name = #{maps.nicknameExact}
  1987. </if >
  1988. <if test = "maps.userId != null and maps.userId !='' " >
  1989. AND u.user_id = #{maps.userId}
  1990. </if >
  1991. <if test = "maps.phone != null and maps.phone !='' " >
  1992. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  1993. </if >
  1994. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  1995. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  1996. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  1997. )
  1998. </if >
  1999. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  2000. AND u.register_code = #{maps.registerCode}
  2001. </if >
  2002. <if test = "maps.status != null" >
  2003. AND ucu.status = #{maps.status}
  2004. </if >
  2005. <if test = "maps.companyId != null and maps.companyId != '' " >
  2006. AND ucu.company_id = #{maps.companyId}
  2007. </if >
  2008. <if test = "maps.companyUserId != null" >
  2009. AND ucu.company_user_id = #{maps.companyUserId}
  2010. </if >
  2011. <if test = "maps.projectId != null" >
  2012. AND ucu.project_id = #{maps.projectId}
  2013. </if >
  2014. <if test = "maps.companyUserIds != null and maps.companyUserIds.length > 0 " >
  2015. AND ucu.company_user_id in
  2016. <foreach collection="maps.companyUserIds" item="item" open="(" close=")" separator=",">
  2017. #{item}
  2018. </foreach>
  2019. </if >
  2020. </where>
  2021. ORDER BY
  2022. user_id DESC
  2023. </select>
  2024. <select id="selectFsUserVOListByProject" resultType="com.fs.his.vo.FsUserVO">
  2025. SELECT distinct
  2026. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  2027. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  2028. fcc.watch_course_count, fcc.part_course_count, company_user.nick_name AS companyUserNickName, fcc.last_watch_date
  2029. ,company.company_name,
  2030. ucu.project_id,
  2031. ucu.id as companyUserId,
  2032. ucu.create_time as bindTime,
  2033. ucu.status
  2034. FROM
  2035. fs_user u
  2036. LEFT JOIN (
  2037. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  2038. user_id
  2039. FROM
  2040. fs_store_payment
  2041. WHERE
  2042. STATUS = 1
  2043. AND user_id IS NOT NULL
  2044. GROUP BY
  2045. user_id
  2046. ) b ON u.user_id = b.user_id
  2047. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  2048. AND b.last_buy_time = p.pay_time
  2049. AND b.payment_id = p.payment_id
  2050. LEFT JOIN (
  2051. SELECT
  2052. 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,
  2053. fs_user_course_count.part_course_count
  2054. FROM
  2055. fs_user_course_count
  2056. GROUP BY fs_user_course_count.user_id
  2057. ) fcc ON fcc.user_id = u.user_id
  2058. inner join fs_user_company_user ucu on ucu.user_id = u.user_id
  2059. LEFT JOIN company_user ON company_user.user_id = ucu.company_user_id
  2060. LEFT JOIN company on company.company_id = company_user.company_id
  2061. <where>
  2062. 1 = 1 and u.nick_name is not null
  2063. and u.is_del = 0
  2064. <if test = "maps.nickname != null and maps.nickname !='' " >
  2065. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  2066. </if >
  2067. <if test = "maps.userId != null and maps.userId !='' " >
  2068. AND u.user_id = #{maps.userId}
  2069. </if >
  2070. <if test = "maps.phone != null and maps.phone !='' " >
  2071. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  2072. </if >
  2073. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  2074. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  2075. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  2076. )
  2077. </if >
  2078. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  2079. AND u.register_code = #{maps.registerCode}
  2080. </if >
  2081. <if test = "maps.status != null" >
  2082. AND ucu.status = #{maps.status}
  2083. </if >
  2084. <if test = "maps.companyId != null and maps.companyId != '' " >
  2085. AND company.company_id = #{maps.companyId}
  2086. </if >
  2087. <if test = "maps.companyUserId != null" >
  2088. AND company_user.user_id = #{maps.companyUserId}
  2089. </if >
  2090. <if test = "maps.projectId != null" >
  2091. AND ucu.project_id = #{maps.projectId}
  2092. </if >
  2093. </where>
  2094. ORDER BY
  2095. user_id DESC
  2096. </select>
  2097. <select id="selectCompanyAndDoctor" resultType="com.fs.watch.domain.vo.FsUserAndCompanyAndDoctorVo">
  2098. SELECT
  2099. f.*,
  2100. GROUP_CONCAT(c.company_id SEPARATOR ',') AS company_id,
  2101. GROUP_CONCAT(c.company_user_id SEPARATOR ',') AS company_user_id,
  2102. GROUP_CONCAT(o.doctor_id SEPARATOR ',') AS doctor_id
  2103. FROM
  2104. fs_user f
  2105. LEFT JOIN
  2106. company_user_user c ON c.user_id = f.user_id
  2107. LEFT JOIN
  2108. fs_inquiry_order o ON o.user_id = f.user_id AND o.`status` = 4
  2109. WHERE
  2110. f.is_del = 0 AND f.user_id = #{userId}
  2111. GROUP BY
  2112. f.user_id;
  2113. </select>
  2114. <select id="selectUserNameByIds" resultMap="FsUserResult">
  2115. select user_id,nick_name from fs_user where user_id in
  2116. <foreach collection="userIds.split(',')" item="userId" open="(" close=")" separator=",">
  2117. #{userId}
  2118. </foreach>
  2119. </select>
  2120. <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
  2121. SELECT
  2122. count( DISTINCT fs_user.user_id ) as userNum,
  2123. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  2124. fs_user_company_user.company_id
  2125. FROM
  2126. fs_user
  2127. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  2128. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2129. WHERE
  2130. fs_user.is_del = 0
  2131. AND fs_user.`status` = 1
  2132. AND fs_user_company_user.`status` = 1
  2133. AND company_user.user_id IS NOT NULL
  2134. GROUP BY
  2135. fs_user_company_user.company_id
  2136. </select>
  2137. <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
  2138. SELECT
  2139. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  2140. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  2141. ifnull(
  2142. ROUND(
  2143. (
  2144. 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,
  2145. 2
  2146. ),
  2147. 0
  2148. ) AS completeWatchRate,
  2149. fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
  2150. FROM
  2151. fs_course_watch_log fwl
  2152. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fwl.user_id
  2153. WHERE
  2154. fwl.send_type = 1
  2155. AND fs_user_company_user.`status` = 1
  2156. GROUP BY
  2157. fwl.period_id, fwl.video_id, fwl.company_user_id
  2158. </select>
  2159. <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
  2160. SELECT
  2161. count(DISTINCT flog.log_id ) AS redPacketNum,
  2162. ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
  2163. flog.period_id,
  2164. flog.video_id,
  2165. flog.company_user_id,
  2166. flog.company_id
  2167. FROM
  2168. fs_course_red_packet_log flog
  2169. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = flog.user_id
  2170. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2171. where flog.`status` = 1
  2172. AND fs_user_company_user.`status` = 1
  2173. GROUP BY
  2174. flog.period_id,
  2175. flog.video_id,
  2176. flog.company_user_id
  2177. </select>
  2178. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  2179. SELECT
  2180. count( DISTINCT fs_user_company_user.user_id ) AS answerNum,
  2181. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user_company_user.user_id END ) AS answerRightNum,
  2182. ifnull(
  2183. ROUND(
  2184. (
  2185. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user_company_user.user_id END ) / count( DISTINCT fs_user_company_user.user_id )) * 100,
  2186. 2
  2187. ),
  2188. 0
  2189. ) AS answerRightRate,
  2190. fs_course_answer_logs.period_id,
  2191. fs_course_answer_logs.video_id,
  2192. fs_course_answer_logs.company_user_id,
  2193. fs_course_answer_logs.company_id
  2194. FROM
  2195. fs_course_answer_logs
  2196. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_course_answer_logs.user_id
  2197. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2198. where fs_user_company_user.`status` = 1
  2199. GROUP BY
  2200. fs_course_answer_logs.period_id,
  2201. fs_course_answer_logs.video_id,
  2202. fs_course_answer_logs.company_user_id
  2203. </select>
  2204. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  2205. SELECT
  2206. count(DISTINCT fs_user.user_id ) as userNum,
  2207. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  2208. date(fs_user.create_time) as userCreateDate
  2209. ,company.company_id,
  2210. company.company_name,
  2211. company_user.user_id AS companyUserId,
  2212. company_user.nick_name AS companyUserName
  2213. FROM
  2214. fs_user
  2215. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  2216. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2217. LEFT JOIN company ON company.company_id = fs_user_company_user.company_id
  2218. WHERE
  2219. fs_user.is_del = 0
  2220. AND fs_user_company_user.`status` = 1
  2221. AND fs_user.`status` = 1
  2222. AND company_user.user_id is not null
  2223. GROUP BY
  2224. fs_user_company_user.company_user_id, date(fs_user.create_time)
  2225. </select>
  2226. <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
  2227. <include refid="selectFsUserVo"/>
  2228. <where>
  2229. <if test="userName != null and userName != ''">
  2230. AND (
  2231. nickname like concat('%', #{userName}, '%')
  2232. or user_id LIKE concat('%',#{userName},'%')
  2233. )
  2234. </if>
  2235. </where>
  2236. order by user_id desc
  2237. </select>
  2238. <select id="selectFsUserCount" resultType="java.lang.Long">
  2239. select count(1) from fs_user
  2240. where 1=1
  2241. <if test = "type != null and type ==1">
  2242. and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
  2243. </if>
  2244. <if test = "companyId != null">
  2245. and company_id=#{companyId}
  2246. </if>
  2247. <if test="companyUserId != null">
  2248. and company_user_id = #{companyUserId}
  2249. </if>
  2250. </select>
  2251. <select id="selectFsUserListLimit" resultMap="FsUserResult">
  2252. <include refid="selectFsUserVo"/>
  2253. <where>
  2254. <if test="password != null and password != ''">and password = #{password}</if>
  2255. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  2256. <if test="birthday != null ">and birthday = #{birthday}</if>
  2257. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  2258. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  2259. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  2260. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  2261. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  2262. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  2263. <if test="integral != null ">and integral = #{integral}</if>
  2264. <if test="signNum != null ">and sign_num = #{signNum}</if>
  2265. <if test="status != null ">and status = #{status}</if>
  2266. <if test="level != null ">and level = #{level}</if>
  2267. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  2268. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  2269. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  2270. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  2271. <if test="payCount != null ">and pay_count = #{payCount}</if>
  2272. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  2273. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  2274. <if test="isDel != null ">and is_del = #{isDel}</if>
  2275. <if test="companyId != null ">and company_id = #{companyId}</if>
  2276. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  2277. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  2278. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  2279. </if>
  2280. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  2281. <if test="source != null and source != '' ">and source = #{source}</if>
  2282. <if test="isShow != null ">and is_show = #{isShow}</if>
  2283. <if test="(username != null and username != '') or (userId != null and userId != '') or (nickname != null and nickname != '') or (phone != null and phone != '')">
  2284. and (
  2285. <if test="username != null and username != ''">username like concat('%', #{username}, '%')</if>
  2286. <if test="userId != null and userId != ''">or user_id = #{userId}</if>
  2287. <if test="nickname != null and nickname != ''">or nickname like concat('%', #{nickname}, '%')</if>
  2288. <if test="phone != null and phone != ''">or phone like concat('%',#{phone},'%')</if>
  2289. )
  2290. </if>
  2291. <if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  2292. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>
  2293. <if test="payOrder != null ">and pay_order = #{payOrder}</if>
  2294. </where>
  2295. order by user_id desc
  2296. limit 10
  2297. </select>
  2298. <select id="findUsersByParam" resultType="com.fs.his.dto.FindUsersByDTO">
  2299. SELECT user_id as id, 0 as type,
  2300. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2301. FROM fs_user
  2302. WHERE user_id = #{keywords}
  2303. UNION
  2304. <!-- fs_user 按nick_name前缀搜索 -->
  2305. SELECT user_id as id, 0 as type,
  2306. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2307. FROM fs_user
  2308. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2309. UNION
  2310. <!-- fs_user 按phone精确搜索(仅当keywords是数字时) -->
  2311. <if test="keywords.matches('\\d+')">
  2312. SELECT user_id as id, 0 as type,
  2313. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2314. FROM fs_user
  2315. WHERE phone = #{keywords}
  2316. UNION
  2317. </if>
  2318. <!-- company_user相关查询 -->
  2319. SELECT user_id as id, 1 as type,
  2320. IFNULL(nick_name, '') as name
  2321. FROM company_user
  2322. WHERE user_id = #{keywords}
  2323. UNION
  2324. SELECT user_id as id, 1 as type,
  2325. IFNULL(nick_name, '') as name
  2326. FROM company_user
  2327. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2328. <if test="keywords.matches('\\d+')">
  2329. UNION
  2330. SELECT user_id as id, 1 as type,
  2331. IFNULL(nick_name, '') as name
  2332. FROM company_user
  2333. WHERE phonenumber = #{keywords}
  2334. </if>
  2335. </select>
  2336. <select id="countExternalRedPacketStats" resultType="com.fs.store.vo.h5.ExternalRedPacketStatsVO">
  2337. SELECT
  2338. COUNT(red.log_id) AS redPacketNum,
  2339. COALESCE(SUM(red.amount), 0) AS redPacketAmount
  2340. FROM fs_course_red_packet_log log
  2341. WHERE log.status = 1
  2342. AND log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2343. <if test="startTime != null and startTime != ''">
  2344. AND log.create_time &gt;= #{startTime}
  2345. </if>
  2346. <if test="endTime != null and endTime != ''">
  2347. AND log.create_time &lt;= #{endTime}
  2348. </if>
  2349. </select>
  2350. <select id="countExternalAnswerStats" resultType="com.fs.store.vo.h5.ExternalAnswerStatsVO">
  2351. SELECT
  2352. COUNT(*) AS answerNum,
  2353. SUM(CASE WHEN is_right = 1 THEN 1 ELSE 0 END) AS answerRightNum
  2354. FROM fs_course_answer_logs log
  2355. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2356. <if test="startTime != null and startTime != ''">
  2357. AND log.create_time &gt;= #{startTime}
  2358. </if>
  2359. <if test="endTime != null and endTime != ''">
  2360. AND log.create_time &lt;= #{endTime}
  2361. </if>
  2362. </select>
  2363. <select id="countExternalWatchStats" resultType="com.fs.store.vo.h5.ExternalWatchStatsVO">
  2364. SELECT
  2365. COUNT(CASE WHEN log_type != 3 THEN 1 END) AS courseWatchNum,
  2366. COUNT(CASE WHEN log_type = 2 THEN 1 END) AS courseCompleteNum
  2367. FROM fs_course_watch_log log
  2368. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2369. <if test="startTime != null and startTime != ''">
  2370. AND log.create_time &gt;= #{startTime}
  2371. </if>
  2372. <if test="endTime != null and endTime != ''">
  2373. AND log.create_time &lt;= #{endTime}
  2374. </if>
  2375. </select>
  2376. <select id="selectFsUserListByPhone" resultType="com.fs.his.domain.FsUser">
  2377. select * from fs_user where phone=#{phone}
  2378. </select>
  2379. <!-- 查询用户列表(用于积分管理) -->
  2380. <select id="selectFsUserListForIntegral" parameterType="FsUser" resultMap="FsUserResult">
  2381. select user_id, nick_name, phone, integral from fs_user
  2382. <where>
  2383. and is_del = 0
  2384. <if test="phone != null and phone != ''">
  2385. and phone like concat('%', #{phone}, '%')
  2386. </if>
  2387. <if test="nickName != null and nickName != ''">
  2388. and (nick_name like concat('%', #{nickName}, '%') or nickname like concat('%', #{nickName}, '%'))
  2389. </if>
  2390. </where>
  2391. order by user_id desc
  2392. </select>
  2393. <select id="selectRegisterCount" resultType="java.util.Map">
  2394. SELECT
  2395. ucu.company_id AS companyId,
  2396. count(distinct ucu.user_id) AS registerCount
  2397. FROM fs_user u
  2398. left join fs_user_company_user ucu on u.user_id = ucu.user_id
  2399. WHERE u.status = 1 and is_del = 0
  2400. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  2401. AND u.app_create_time &gt;= #{startDate} AND u.app_create_time &lt;= #{endDate}
  2402. </if>
  2403. <if test="companyId != null">
  2404. AND ucu.company_id = #{companyId}
  2405. </if>
  2406. group by ucu.company_id
  2407. </select>
  2408. <select id="selectCountWatchCourse" resultType="com.fs.store.vo.h5.UserDetailsVO">
  2409. SELECT
  2410. <if test="dateTag == null or dateTag =='' or dateTag == '近七天' ">
  2411. ifnull( sum(case when log_type = 2 then 1 else 0 end), 0 ) AS completeWatchCount,
  2412. ifnull( count(*), 0 ) AS watchTimes,
  2413. </if>
  2414. <if test="dateTag != null and dateTag !='' and dateTag != '近七天' ">
  2415. ifnull( sum(case when log_type = 2 then 1 else 0 end), 0 ) AS completeWatchCount,
  2416. ifnull( count(*), 0 ) AS watchTimes,
  2417. </if>
  2418. fs_course_watch_log.user_id
  2419. FROM
  2420. fs_course_watch_log
  2421. INNER JOIN fs_user_company_user cu ON cu.user_id = fs_course_watch_log.user_id and cu.project_id = fs_course_watch_log.project
  2422. <where>
  2423. <if test="dateTag != null and dateTag !='' ">
  2424. <choose>
  2425. <when test = "dateTag == '今天'">
  2426. and to_days(fs_course_watch_log.create_time) = to_days(now())
  2427. </when>
  2428. <when test = "dateTag == '昨天'">
  2429. and fs_course_watch_log.create_time &gt;= CURDATE() - INTERVAL 1 DAY
  2430. AND fs_course_watch_log.create_time &lt; CURDATE()
  2431. </when>
  2432. <when test = "dateTag == '前天'">
  2433. and fs_course_watch_log.create_time &gt;= CURDATE() - INTERVAL 2 DAY
  2434. AND fs_course_watch_log.create_time &lt; CURDATE() - INTERVAL 1 DAY
  2435. </when>
  2436. <when test = "dateTag == '近七天'">
  2437. and fs_course_watch_log.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  2438. </when>
  2439. </choose>
  2440. </if>
  2441. and fs_course_watch_log.user_id = #{fsUserId}
  2442. <if test="userCompanyId!=null">
  2443. and cu.id = #{userCompanyId}
  2444. </if>
  2445. </where>
  2446. GROUP BY
  2447. fs_course_watch_log.user_id
  2448. </select>
  2449. <select id="selectAppSalesNewUserCountVO" resultType="com.fs.his.vo.AppSalesCourseStatisticsVO">
  2450. select count(distinct u.user_id) as newAppUserCount, u.company_user_id from fs_user u
  2451. left join fs_user_company_user ucu on u.user_id = ucu.user_id and ucu.status=1
  2452. where u.is_del = 0
  2453. <if test="companyId != null ">
  2454. and ucu.company_id = #{companyId}
  2455. </if>
  2456. <if test="companyUserId != null ">
  2457. and ucu.company_user_id = #{companyUserId}
  2458. </if>
  2459. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  2460. and u.app_create_time &gt;= #{startDate} and u.app_create_time &lt;= #{endDate}
  2461. </if>
  2462. group by ucu.company_user_id
  2463. </select>
  2464. <select id="selectAppSalesUserCountVO" resultType="com.fs.his.vo.AppSalesCourseStatisticsVO">
  2465. select count(distinct u.user_id) as appUserCount, u.company_user_id from fs_user u
  2466. left join fs_user_company_user ucu on u.user_id = ucu.user_id and ucu.status=1
  2467. where u.is_del = 0 and u.source is not null
  2468. <if test="companyId != null ">
  2469. and ucu.company_id = #{companyId}
  2470. </if>
  2471. <if test="companyUserId != null ">
  2472. and ucu.company_user_id = #{companyUserId}
  2473. </if>
  2474. group by ucu.company_user_id
  2475. </select>
  2476. </mapper>