FsUserMapper.xml 95 KB

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