FsUserMapper.xml 109 KB

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