FsUserMapper.xml 111 KB

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