FsUserMapper.xml 114 KB

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