FsUserMapper.xml 109 KB

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