FsUserMapper.xml 114 KB

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