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