FsUserMapper.xml 102 KB

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