FsUserMapper.xml 102 KB

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