FsUserMapper.xml 96 KB

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