FsUserMapper.xml 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286
  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. COALESCE(ucu.update_time, ucu.create_time) createTime,
  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. count(distinct if(fcwl.log_type = 2, fcwl.log_id, null)) completeWatchCount,
  737. count(distinct fcwl.log_id) watchTimes,
  738. count(distinct fcal.log_id) answerTime,
  739. count(distinct if(fcal.is_right = 1, fcal.log_id, null)) answerRightTime,
  740. count(distinct fcrpl.log_id) answerRedPacketTime,
  741. sum(ifnull((
  742. select sum(frp.amount)
  743. from fs_course_red_packet_log frp
  744. where frp.watch_log_id = fcwl.log_id and frp.status = 1
  745. ), 0)) answerRedPacketAmount
  746. FROM fs_course_watch_log fcwl
  747. inner join fs_user_company_user fucu on fcwl.user_id = fucu.user_id and fcwl.project = fucu.project_id and fcwl.company_user_id = fucu.company_user_id
  748. left join fs_course_answer_logs fcal on fcal.watch_log_id = fcwl.log_id
  749. left join fs_course_red_packet_log fcrpl on fcrpl.watch_log_id = fcwl.log_id
  750. <where>
  751. <if test="dateTag != null and dateTag !='' ">
  752. <choose>
  753. <when test = "dateTag == '今天'">
  754. and to_days(fcwl.create_time) = to_days(now())
  755. </when>
  756. <when test = "dateTag == '昨天'">
  757. and fcwl.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fcwl.create_time &lt; CURDATE()
  758. </when>
  759. <when test = "dateTag == '前天'">
  760. and fcwl.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fcwl.create_time &lt; CURDATE() - INTERVAL 1 DAY
  761. </when>
  762. <when test = "dateTag == '近七天'">
  763. and fcwl.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  764. </when>
  765. </choose>
  766. </if>
  767. and fcwl.user_id = #{fsUserId} and fucu.company_user_id = #{userId}
  768. <if test="userCompanyId!=null">
  769. and fucu.id = #{userCompanyId}
  770. </if>
  771. </where>
  772. group by fcwl.user_id
  773. </select>
  774. <select id="getUserTotal" resultType="java.lang.Integer">
  775. SELECT count(fs_user.user_id) as userTotal
  776. FROM fs_user
  777. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  778. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  779. WHERE fs_user.is_del = 0
  780. <if test="userId != null and userId != 0 ">
  781. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  782. </if>
  783. <if test="companyId != null ">
  784. and ucu.company_id = #{companyId}
  785. </if>
  786. </select>
  787. <select id="getTodayNewUser" resultType="java.lang.Integer">
  788. SELECT count(fs_user.user_id) as todayNewUser
  789. FROM fs_user
  790. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  791. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  792. WHERE fs_user.is_del = 0
  793. <if test="userId != null and userId != 0 ">
  794. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  795. </if>
  796. <if test="companyId != null ">
  797. and ucu.company_id = #{companyId}
  798. </if>
  799. AND to_days(ucu.create_time) = to_days(now())
  800. </select>
  801. <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
  802. SELECT (SELECT count(fs_user.user_id)
  803. FROM fs_user
  804. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  805. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  806. WHERE fs_user.is_del = 0
  807. <if test="userId != null and userId != 0 ">
  808. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  809. </if>
  810. <if test="companyId != null ">
  811. and ucu.company_id = #{companyId}
  812. </if>
  813. ) as userTotal,
  814. (SELECT count(fs_user.user_id)
  815. FROM fs_user
  816. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  817. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  818. WHERE fs_user.is_del = 0
  819. <if test="userId != null and userId != 0 ">
  820. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  821. </if>
  822. <if test="companyId != null ">
  823. and ucu.company_id = #{companyId}
  824. </if>
  825. AND to_days(ucu.create_time) = to_days(now())) as todayNewUser
  826. </select>
  827. <select id="countTag" resultType="com.fs.store.vo.h5.FsUserSummaryCountTagVO">
  828. SELECT
  829. company_tag.tag AS tagName,
  830. count( ucu.user_id ) AS number
  831. FROM
  832. fs_user_project_tag upt
  833. inner join fs_user_company_user ucu on ucu.id = upt.user_company_user_id
  834. inner join company_tag ON upt.tag_id = company_tag.tag_id
  835. left join company_user on company_user.user_id = ucu.company_user_id
  836. <where>
  837. <if test="userId != null and userId != 0 ">
  838. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  839. </if>
  840. <if test="companyId != null ">
  841. and ucu.company_id = #{companyId}
  842. </if>
  843. </where>
  844. GROUP BY
  845. company_tag.tag_id
  846. </select>
  847. <select id="countUserCourse" resultType="Map">
  848. SELECT
  849. (SELECT COUNT(*) FROM (
  850. SELECT 1
  851. FROM fs_user_course_count fcc
  852. JOIN fs_user ON fs_user.user_id = fcc.user_id
  853. JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
  854. JOIN company_user ON ucu.company_user_id = company_user.user_id
  855. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  856. <where>
  857. fcc.project_id = ucu.project_id
  858. <if test="userId != null and userId != 0 ">
  859. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  860. </if>
  861. <if test="userId != null and userId == 0 ">
  862. and ucu.company_id = #{companyId}
  863. </if>
  864. <if test="startTime != null and startTime !='' ">
  865. and fcc.create_time &gt;= #{startTime}
  866. </if>
  867. <if test="endTime != null and endTime != ''">
  868. and fcc.create_time &lt;= #{endTime}
  869. </if>
  870. <if test="periodId != null and periodId != ''">
  871. AND fcpd.period_id = #{periodId}
  872. </if>
  873. <if test="videoId != null and videoId != ''">
  874. AND fcpd.video_id = #{videoId}
  875. </if>
  876. -- 单独通过销售id查询
  877. <if test="companyUserId != null and companyUserId != ''">
  878. AND company_user.user_id = #{companyUserId}
  879. </if>
  880. </where>
  881. ) as courseWatchNum,
  882. (SELECT COUNT(*) FROM (
  883. SELECT 1
  884. FROM fs_user_course_count fcc
  885. JOIN fs_user ON fs_user.user_id = fcc.user_id
  886. JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
  887. JOIN company_user ON ucu.company_user_id = company_user.user_id
  888. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  889. <where>
  890. fcc.project_id = ucu.project_id
  891. <if test="userId != null and userId != 0 ">
  892. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  893. </if>
  894. <if test="userId != null and userId == 0 ">
  895. and ucu.company_id = #{companyId}
  896. </if>
  897. AND fcc.complete_watch_count > 0
  898. <if test="startTime != null and startTime !='' ">
  899. and fcc.create_time &gt;= #{startTime}
  900. </if>
  901. <if test="endTime != null and endTime != ''">
  902. and fcc.create_time &lt;= #{endTime}
  903. </if>
  904. <if test="periodId != null and periodId != ''">
  905. AND fcpd.period_id = #{periodId}
  906. </if>
  907. <if test="videoId != null and videoId != ''">
  908. AND fcpd.video_id = #{videoId}
  909. </if>
  910. -- 单独通过销售id查询
  911. <if test="companyUserId != null and companyUserId != ''">
  912. AND company_user.user_id = #{companyUserId}
  913. </if>
  914. </where>
  915. GROUP BY fcc.user_id, ucu.project_id
  916. ) AS complete_counts ) as courseCompleteNum
  917. </select>
  918. <select id="countUserStats" resultType="Map">
  919. SELECT
  920. -- 观看人数
  921. (
  922. SELECT COUNT(DISTINCT l.user_id)
  923. FROM fs_course_watch_log l
  924. LEFT JOIN fs_user u ON u.user_id = l.user_id
  925. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  926. <where>
  927. l.log_type != 3 AND l.send_type = 1
  928. <if test="userId != null and userId != 0 ">
  929. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  930. </if>
  931. <if test="userId != null and userId == 0 ">
  932. AND l.company_id = #{companyId}
  933. </if>
  934. <if test="periodId != null and periodId != '' ">
  935. AND l.period_id = #{periodId}
  936. </if>
  937. <if test="videoId != null and videoId != '' ">
  938. AND l.video_id = #{videoId}
  939. </if>
  940. <if test="startTime != null and startTime != '' ">
  941. AND l.create_time &gt;= #{startTime}
  942. </if>
  943. <if test="endTime != null and endTime != '' ">
  944. AND l.create_time &lt;= #{endTime}
  945. </if>
  946. <if test="companyUserId != null and companyUserId != '' ">
  947. AND l.company_user_id = #{companyUserId}
  948. </if>
  949. </where>
  950. ) AS courseWatchNum,
  951. -- 完成人数
  952. (
  953. SELECT COUNT(DISTINCT l.user_id)
  954. FROM fs_course_watch_log l
  955. LEFT JOIN fs_user u ON u.user_id = l.user_id
  956. LEFT JOIN company_user cu ON l.company_user_id = cu.user_id
  957. <where>
  958. l.log_type = 2 AND l.send_type = 1
  959. <if test="userId != null and userId != 0 ">
  960. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  961. </if>
  962. <if test="userId != null and userId == 0 ">
  963. AND l.company_id = #{companyId}
  964. </if>
  965. <if test="periodId != null and periodId != '' ">
  966. AND l.period_id = #{periodId}
  967. </if>
  968. <if test="videoId != null and videoId != '' ">
  969. AND l.video_id = #{videoId}
  970. </if>
  971. <if test="startTime != null and startTime != '' ">
  972. AND l.create_time &gt;= #{startTime}
  973. </if>
  974. <if test="endTime != null and endTime != '' ">
  975. AND l.create_time &lt;= #{endTime}
  976. </if>
  977. <if test="companyUserId != null and companyUserId != '' ">
  978. AND l.company_user_id = #{companyUserId}
  979. </if>
  980. </where>
  981. ) AS courseCompleteNum,
  982. -- 答题人数
  983. (
  984. SELECT COUNT(distinct a.user_id)
  985. FROM fs_course_answer_logs a
  986. LEFT JOIN fs_user u ON u.user_id = a.user_id
  987. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  988. <where>
  989. 1=1
  990. <if test="userId != null and userId != 0 ">
  991. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  992. </if>
  993. <if test="userId != null and userId == 0 ">
  994. AND a.company_id = #{companyId}
  995. </if>
  996. <if test="periodId != null and periodId != '' ">
  997. AND a.period_id = #{periodId}
  998. </if>
  999. <if test="videoId != null and videoId != '' ">
  1000. AND a.video_id = #{videoId}
  1001. </if>
  1002. <if test="startTime != null and startTime != '' ">
  1003. AND a.create_time &gt;= #{startTime}
  1004. </if>
  1005. <if test="endTime != null and endTime != '' ">
  1006. AND a.create_time &lt;= #{endTime}
  1007. </if>
  1008. <if test="companyUserId != null and companyUserId != '' ">
  1009. AND a.company_user_id = #{companyUserId}
  1010. </if>
  1011. </where>
  1012. ) AS answerNum,
  1013. -- 答对人数
  1014. (
  1015. SELECT COUNT(distinct a.user_id)
  1016. FROM fs_course_answer_logs a
  1017. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1018. LEFT JOIN company_user cu ON cu.user_id = a.company_user_id
  1019. <where>
  1020. a.is_right = 1
  1021. <if test="userId != null and userId != 0 ">
  1022. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1023. </if>
  1024. <if test="userId != null and userId == 0 ">
  1025. AND a.company_id = #{companyId}
  1026. </if>
  1027. <if test="periodId != null and periodId != '' ">
  1028. AND a.period_id = #{periodId}
  1029. </if>
  1030. <if test="videoId != null and videoId != '' ">
  1031. AND a.video_id = #{videoId}
  1032. </if>
  1033. <if test="startTime != null and startTime != '' ">
  1034. AND a.create_time &gt;= #{startTime}
  1035. </if>
  1036. <if test="endTime != null and endTime != '' ">
  1037. AND a.create_time &lt;= #{endTime}
  1038. </if>
  1039. <if test="companyUserId != null and companyUserId != '' ">
  1040. AND a.company_user_id = #{companyUserId}
  1041. </if>
  1042. </where>
  1043. ) AS answerRightNum,
  1044. -- 红包数
  1045. (
  1046. SELECT COUNT(flog.log_id)
  1047. FROM fs_course_red_packet_log flog
  1048. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1049. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1050. <where>
  1051. flog.status = 1
  1052. <if test="userId != null and userId != 0 ">
  1053. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1054. </if>
  1055. <if test="userId != null and userId == 0 ">
  1056. AND flog.company_id = #{companyId}
  1057. </if>
  1058. <if test="periodId != null and periodId != '' ">
  1059. AND flog.period_id = #{periodId}
  1060. </if>
  1061. <if test="videoId != null and videoId != '' ">
  1062. AND flog.video_id = #{videoId}
  1063. </if>
  1064. <if test="startTime != null and startTime != '' ">
  1065. AND flog.create_time &gt;= #{startTime}
  1066. </if>
  1067. <if test="endTime != null and endTime != '' ">
  1068. AND flog.create_time &lt;= #{endTime}
  1069. </if>
  1070. <if test="companyUserId != null and companyUserId != '' ">
  1071. AND flog.company_user_id = #{companyUserId}
  1072. </if>
  1073. </where>
  1074. ) AS redPacketNum,
  1075. -- 红包金额
  1076. (
  1077. SELECT IFNULL(SUM(flog.amount), 0)
  1078. FROM fs_course_red_packet_log flog
  1079. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1080. LEFT JOIN company_user cu ON cu.user_id = flog.company_user_id
  1081. <where>
  1082. flog.status = 1
  1083. <if test="userId != null and userId != 0 ">
  1084. AND (cu.user_id = #{userId} OR cu.parent_id = #{userId})
  1085. </if>
  1086. <if test="userId != null and userId == 0 ">
  1087. AND flog.company_id = #{companyId}
  1088. </if>
  1089. <if test="periodId != null and periodId != '' ">
  1090. AND flog.period_id = #{periodId}
  1091. </if>
  1092. <if test="videoId != null and videoId != '' ">
  1093. AND flog.video_id = #{videoId}
  1094. </if>
  1095. <if test="startTime != null and startTime != '' ">
  1096. AND flog.create_time &gt;= #{startTime}
  1097. </if>
  1098. <if test="endTime != null and endTime != '' ">
  1099. AND flog.create_time &lt;= #{endTime}
  1100. </if>
  1101. <if test="companyUserId != null and companyUserId != '' ">
  1102. AND flog.company_user_id = #{companyUserId}
  1103. </if>
  1104. </where>
  1105. ) AS redPacketAmount
  1106. </select>
  1107. <!-- 查询观看和完成人数 -->
  1108. <select id="countUserWatchStats" resultType="Map">
  1109. SELECT
  1110. COUNT(DISTINCT CASE WHEN l.log_type != 3 AND l.send_type = 1 THEN l.user_id END) AS courseWatchNum,
  1111. COUNT(DISTINCT CASE WHEN l.log_type = 2 AND l.send_type = 1 THEN l.user_id END) AS courseCompleteNum
  1112. FROM fs_course_watch_log l
  1113. LEFT JOIN fs_user u ON u.user_id = l.user_id
  1114. LEFT JOIN company_user cu_l ON l.company_user_id = cu_l.user_id
  1115. <where>
  1116. <if test="userId != null and userId != 0">
  1117. AND (cu_l.user_id = #{userId} OR cu_l.parent_id = #{userId})
  1118. </if>
  1119. <if test="userId != null and userId == 0">
  1120. AND l.company_id = #{companyId}
  1121. </if>
  1122. <if test="periodId != null and periodId != ''">
  1123. AND l.period_id = #{periodId}
  1124. </if>
  1125. <if test="videoId != null and videoId != ''">
  1126. AND l.video_id = #{videoId}
  1127. </if>
  1128. <if test="startTime != null and startTime != ''">
  1129. AND l.create_time &gt;= #{startTime}
  1130. </if>
  1131. <if test="endTime != null and endTime != ''">
  1132. AND l.create_time &lt;= #{endTime}
  1133. </if>
  1134. <if test="companyUserId != null and companyUserId != ''">
  1135. AND l.company_user_id = #{companyUserId}
  1136. </if>
  1137. </where>
  1138. </select>
  1139. <!-- 查询答题人数和答对人数 -->
  1140. <select id="countUserAnswerStats" resultType="Map">
  1141. SELECT
  1142. COUNT(DISTINCT CASE WHEN a.user_id THEN a.user_id END) AS answerNum,
  1143. COUNT(DISTINCT CASE WHEN a.is_right = 1 THEN a.user_id END) AS answerRightNum
  1144. FROM fs_course_answer_logs a
  1145. LEFT JOIN fs_user u ON u.user_id = a.user_id
  1146. LEFT JOIN company_user cu_a ON a.company_user_id = cu_a.user_id
  1147. <where>
  1148. <if test="userId != null and userId != 0">
  1149. AND (cu_a.user_id = #{userId} OR cu_a.parent_id = #{userId})
  1150. </if>
  1151. <if test="userId != null and userId == 0">
  1152. AND a.company_id = #{companyId}
  1153. </if>
  1154. <if test="periodId != null and periodId != ''">
  1155. AND a.period_id = #{periodId}
  1156. </if>
  1157. <if test="videoId != null and videoId != ''">
  1158. AND a.video_id = #{videoId}
  1159. </if>
  1160. <if test="startTime != null and startTime != ''">
  1161. AND a.create_time &gt;= #{startTime}
  1162. </if>
  1163. <if test="endTime != null and endTime != ''">
  1164. AND a.create_time &lt;= #{endTime}
  1165. </if>
  1166. <if test="companyUserId != null and companyUserId != ''">
  1167. AND a.company_user_id = #{companyUserId}
  1168. </if>
  1169. </where>
  1170. </select>
  1171. <!-- 查询红包数量和红包金额 -->
  1172. <select id="countUserRedPacketStats" resultType="Map">
  1173. SELECT
  1174. COUNT(CASE WHEN flog.status = 1 THEN flog.log_id END) AS redPacketNum,
  1175. IFNULL(SUM(CASE WHEN flog.status = 1 THEN flog.amount END), 0) AS redPacketAmount
  1176. FROM fs_course_red_packet_log flog
  1177. LEFT JOIN fs_user u ON u.user_id = flog.user_id
  1178. LEFT JOIN company_user cu_flog ON flog.company_user_id = cu_flog.user_id
  1179. <where>
  1180. <if test="userId != null and userId != 0">
  1181. AND (cu_flog.user_id = #{userId} OR cu_flog.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. </select>
  1203. <select id="countUserAnswer" resultType="Map">
  1204. SELECT
  1205. (
  1206. SELECT
  1207. count(distinct fs_user.user_id )
  1208. FROM
  1209. fs_course_answer_logs
  1210. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1211. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1212. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1213. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1214. <where>
  1215. <if test="userId != null and userId != 0 ">
  1216. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1217. </if>
  1218. <if test="userId != null and userId == 0 ">
  1219. and fs_course_answer_logs.company_id = #{companyId}
  1220. </if>
  1221. <if test="startTime != null and startTime !='' ">
  1222. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1223. </if>
  1224. <if test="endTime != null and endTime != ''">
  1225. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1226. </if>
  1227. <if test="periodId != null and periodId != ''">
  1228. AND fs_course_answer_logs.period_id = #{periodId}
  1229. </if>
  1230. <if test="videoId != null and videoId != ''">
  1231. AND fs_course_answer_logs.video_id = #{videoId}
  1232. </if>
  1233. -- 单独通过销售id查询
  1234. <if test="companyUserId != null and companyUserId != ''">
  1235. AND company_user.user_id = #{companyUserId}
  1236. </if>
  1237. </where>
  1238. ) AS answerNum,
  1239. (
  1240. SELECT
  1241. count(distinct fs_user.user_id )
  1242. FROM
  1243. fs_course_answer_logs
  1244. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1245. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1246. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1247. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1248. <where>
  1249. <if test="userId != null and userId != 0 ">
  1250. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1251. </if>
  1252. <if test="userId != null and userId == 0 ">
  1253. and fs_course_answer_logs.company_id = #{companyId}
  1254. </if>
  1255. AND fs_course_answer_logs.is_right = 1
  1256. <if test="startTime != null and startTime !='' ">
  1257. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1258. </if>
  1259. <if test="endTime != null and endTime != ''">
  1260. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1261. </if>
  1262. <if test="periodId != null and periodId != ''">
  1263. AND fs_course_answer_logs.period_id = #{periodId}
  1264. </if>
  1265. <if test="videoId != null and videoId != ''">
  1266. AND fs_course_answer_logs.video_id = #{videoId}
  1267. </if>
  1268. -- 单独通过销售id查询
  1269. <if test="companyUserId != null and companyUserId != ''">
  1270. AND company_user.user_id = #{companyUserId}
  1271. </if>
  1272. </where>
  1273. ) AS answerRightNum
  1274. </select>
  1275. <select id="countCourseDetails" resultType="Map">
  1276. select (SELECT
  1277. count( DISTINCT fcpd.period_id )
  1278. FROM
  1279. fs_user_course_period_days fcpd
  1280. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1281. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1282. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1283. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1284. WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
  1285. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1286. <if test="userId != null and userId != 0 ">
  1287. AND ucu.company_user_id = #{userId}
  1288. </if>
  1289. <if test="userId != null and userId == 0 ">
  1290. and ucu.company_id = #{companyId}
  1291. </if>
  1292. <if test="periodId != null and periodId != ''">
  1293. AND fcpd.period_id = #{periodId}
  1294. </if>
  1295. -- 单独通过销售id查询
  1296. <if test="companyUserId != null and companyUserId != ''">
  1297. AND ucu.company_user_id = #{companyUserId}
  1298. </if>
  1299. ) as courseNum,
  1300. (SELECT count(DISTINCT fcpd.video_id)
  1301. FROM fs_user_course_period_days fcpd
  1302. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1303. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1304. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1305. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1306. WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
  1307. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1308. <if test="userId != null and userId != 0 ">
  1309. AND ucu.company_user_id = #{userId}
  1310. </if>
  1311. <if test="userId != null and userId == 0 ">
  1312. and ucu.company_id = #{companyId}
  1313. </if>
  1314. <if test="periodId != null and periodId != ''">
  1315. AND fcpd.period_id = #{periodId}
  1316. </if>
  1317. <if test="videoId != null and videoId != ''">
  1318. AND fcpd.video_id = #{videoId}
  1319. </if>
  1320. -- 单独通过销售id查询
  1321. <if test="companyUserId != null and companyUserId != ''">
  1322. AND ucu.company_user_id = #{companyUserId}
  1323. </if>
  1324. ) as videoNum,
  1325. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  1326. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1327. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1328. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1329. <if test="periodId != null and periodId != ''">
  1330. AND fcpd.period_id = #{periodId}
  1331. </if>
  1332. <if test="videoId != null and videoId != ''">
  1333. AND fcpd.video_id = #{videoId}
  1334. </if>
  1335. -- 单独通过销售id查询
  1336. <if test="companyUserId != null and companyUserId != ''">
  1337. AND ucu.company_user_id = #{companyUserId}
  1338. </if>
  1339. <where>
  1340. <if test="userId != null and userId != 0 ">
  1341. AND ucu.company_user_id = #{userId}
  1342. </if>
  1343. <if test="userId != null and userId == 0 ">
  1344. and ucu.company_id = #{companyId}
  1345. </if>
  1346. </where>
  1347. ) as courseUserNum
  1348. </select>
  1349. <select id="countUserRankingByComplete" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1350. SELECT
  1351. company_user.nick_name as userName,
  1352. ifnull(
  1353. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  1354. ) as completeRate
  1355. FROM
  1356. fs_user_course_count fcc
  1357. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1358. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1359. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1360. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1361. <where>
  1362. <if test="userId != null and userId != 0 ">
  1363. AND ( ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1364. </if>
  1365. <if test="userId != null and userId == 0 ">
  1366. and ucu.company_id = #{companyId}
  1367. </if>
  1368. <if test="startTime != null and startTime !='' ">
  1369. AND fcc.create_time &gt;= #{startTime}
  1370. </if>
  1371. <if test="endTime != null and endTime != ''">
  1372. AND fcc.create_time &lt;= #{endTime}
  1373. </if>
  1374. <if test="periodId != null and periodId != ''">
  1375. AND fcpd.period_id = #{periodId}
  1376. </if>
  1377. <if test="videoId != null and videoId != ''">
  1378. AND fcpd.video_id = #{videoId}
  1379. </if>
  1380. </where>
  1381. group by fcc.user_id
  1382. <choose>
  1383. <when test="order != null and order == 'asc'">
  1384. order by completeRate asc
  1385. </when>
  1386. <when test="order != null and order == 'desc'">
  1387. order by completeRate desc
  1388. </when>
  1389. <otherwise>
  1390. order by completeRate desc
  1391. </otherwise>
  1392. </choose>
  1393. limit 20
  1394. </select>
  1395. <select id="countUserRankingByRight" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1396. SELECT
  1397. company_user.nick_name as userName,
  1398. ifnull(ROUND(
  1399. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1400. *100,2),0
  1401. ) as answerRightRate
  1402. FROM
  1403. fs_course_answer_logs
  1404. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1405. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1406. <where>
  1407. <if test="userId != null and userId != 0 ">
  1408. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1409. </if>
  1410. <if test="userId != null and userId == 0 ">
  1411. and fs_course_answer_logs.company_id = #{companyId}
  1412. </if>
  1413. <if test="startTime != null and startTime !='' ">
  1414. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1415. </if>
  1416. <if test="endTime != null and endTime != ''">
  1417. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1418. </if>
  1419. <if test="periodId != null and periodId != ''">
  1420. AND fs_course_answer_logs.period_id = #{periodId}
  1421. </if>
  1422. <if test="videoId != null and videoId != ''">
  1423. AND fs_course_answer_logs.video_id = #{videoId}
  1424. </if>
  1425. </where>
  1426. group by fs_user.user_id
  1427. <choose>
  1428. <when test="order != null and order == 'asc'">
  1429. order by answerRightRate asc
  1430. </when>
  1431. <when test="order != null and order == 'desc'">
  1432. order by answerRightRate desc
  1433. </when>
  1434. <otherwise>
  1435. order by answerRightRate desc
  1436. </otherwise>
  1437. </choose>
  1438. limit 20
  1439. </select>
  1440. <select id="countCourseRankingByComplete" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1441. SELECT
  1442. fcv.title AS videoName,
  1443. fcv.video_id,
  1444. ifnull(
  1445. ROUND(
  1446. (
  1447. 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,
  1448. 2
  1449. ),
  1450. 0
  1451. ) AS completeRate
  1452. FROM
  1453. fs_course_watch_log fwl
  1454. LEFT JOIN fs_user ON fs_user.user_id = fwl.user_id
  1455. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1456. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1457. -- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1458. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fwl.video_id
  1459. <where>
  1460. <if test="userId != null and userId != 0 ">
  1461. AND ( fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1462. </if>
  1463. <if test="userId != null and userId == 0 ">
  1464. and fs_user_company_user.company_id = #{companyId}
  1465. </if>
  1466. <if test="startTime != null and startTime !='' ">
  1467. AND fwl.create_time &gt;= #{startTime}
  1468. </if>
  1469. <if test="endTime != null and endTime != ''">
  1470. AND fwl.create_time &lt;= #{endTime}
  1471. </if>
  1472. <if test="periodId != null and periodId != ''">
  1473. AND fwl.period_id = #{periodId}
  1474. </if>
  1475. <if test="videoId != null and videoId != ''">
  1476. AND fwl.video_id = #{videoId}
  1477. </if>
  1478. </where>
  1479. GROUP BY
  1480. fwl.video_id
  1481. <choose>
  1482. <when test="order != null and order == 'asc'">
  1483. ORDER BY completeRate asc
  1484. </when>
  1485. <when test="order != null and order == 'desc'">
  1486. ORDER BY completeRate desc
  1487. </when>
  1488. <otherwise>
  1489. ORDER BY completeRate desc
  1490. </otherwise>
  1491. </choose>
  1492. LIMIT 20
  1493. </select>
  1494. <select id="countCourseRankingByRight" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1495. SELECT
  1496. fcv.title AS videoName,
  1497. ifnull(
  1498. ROUND(
  1499. (
  1500. 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,
  1501. 2
  1502. ),
  1503. 0
  1504. ) AS answerRightRate
  1505. FROM
  1506. fs_course_answer_logs
  1507. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1508. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1509. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1510. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1511. <where>
  1512. <if test="userId != null and userId != 0 ">
  1513. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1514. </if>
  1515. <if test="userId != null and userId == 0 ">
  1516. and fs_course_answer_logs.company_id = #{companyId}
  1517. </if>
  1518. <if test="startTime != null and startTime !='' ">
  1519. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1520. </if>
  1521. <if test="endTime != null and endTime != ''">
  1522. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1523. </if>
  1524. <if test="periodId != null and periodId != ''">
  1525. AND fs_course_answer_logs.period_id = #{periodId}
  1526. </if>
  1527. <if test="videoId != null and videoId != ''">
  1528. AND fs_course_answer_logs.video_id = #{videoId}
  1529. </if>
  1530. </where>
  1531. GROUP BY
  1532. fs_course_answer_logs.video_id
  1533. <choose>
  1534. <when test="order != null and order == 'asc'">
  1535. ORDER BY answerRightRate asc
  1536. </when>
  1537. <when test="order != null and order == 'desc'">
  1538. ORDER BY answerRightRate desc
  1539. </when>
  1540. <otherwise>
  1541. ORDER BY answerRightRate desc
  1542. </otherwise>
  1543. </choose>
  1544. LIMIT 20
  1545. </select>
  1546. <select id="countUserRedPacket" resultType="Map">
  1547. SELECT
  1548. (
  1549. SELECT
  1550. count( flog.log_id )
  1551. FROM
  1552. fs_course_red_packet_log flog
  1553. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1554. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1555. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1556. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1557. where flog.status = 1
  1558. <if test="userId != null and userId != 0 ">
  1559. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1560. </if>
  1561. <if test="userId != null and userId == 0 ">
  1562. and flog.company_id = #{companyId}
  1563. </if>
  1564. <if test="startTime != null and startTime !='' ">
  1565. AND flog.create_time &gt;= #{startTime}
  1566. </if>
  1567. <if test="endTime != null and endTime != ''">
  1568. AND flog.create_time &lt;= #{endTime}
  1569. </if>
  1570. <if test="periodId != null and periodId != ''">
  1571. AND flog.period_id = #{periodId}
  1572. </if>
  1573. <if test="videoId != null and videoId != ''">
  1574. AND flog.video_id = #{videoId}
  1575. </if>
  1576. -- 单独通过销售id查询
  1577. <if test="companyUserId != null and companyUserId != ''">
  1578. AND company_user.user_id = #{companyUserId}
  1579. </if>
  1580. ) AS redPacketNum,
  1581. (
  1582. SELECT
  1583. ifnull (sum( flog.amount ), 0)
  1584. FROM
  1585. fs_course_red_packet_log flog
  1586. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1587. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1588. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1589. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1590. where flog.status = 1
  1591. <if test="userId != null and userId != 0 ">
  1592. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1593. </if>
  1594. <if test="userId != null and userId == 0 ">
  1595. and flog.company_id = #{companyId}
  1596. </if>
  1597. <if test="startTime != null and startTime !='' ">
  1598. AND flog.create_time &gt;= #{startTime}
  1599. </if>
  1600. <if test="endTime != null and endTime != ''">
  1601. AND flog.create_time &lt;= #{endTime}
  1602. </if>
  1603. <if test="periodId != null and periodId != ''">
  1604. AND flog.period_id = #{periodId}
  1605. </if>
  1606. <if test="videoId != null and videoId != ''">
  1607. AND flog.video_id = #{videoId}
  1608. </if>
  1609. -- 单独通过销售id查询
  1610. <if test="companyUserId != null and companyUserId != ''">
  1611. AND company_user.user_id = #{companyUserId}
  1612. </if>
  1613. ) AS redPacketAmount
  1614. </select>
  1615. <select id="courseAnalysisCourseCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  1616. SELECT
  1617. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1618. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1619. ifnull(
  1620. ROUND(
  1621. (
  1622. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1623. 2
  1624. ),
  1625. 0
  1626. ) as completeRate,
  1627. fcpd.video_id
  1628. FROM
  1629. fs_user_course_count fcc
  1630. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1631. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1632. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1633. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1634. <where>
  1635. <if test="companyUserId != null and companyUserId != 0 ">
  1636. AND ucu.company_user_id = #{companyUserId}
  1637. </if>
  1638. <if test="companyUserId != null and companyUserId == 0 ">
  1639. and ucu.company_id = #{companyId}
  1640. </if>
  1641. <if test="periodId != null and periodId != ''">
  1642. AND fcpd.period_id = #{periodId}
  1643. </if>
  1644. <if test="videoId != null and videoId != ''">
  1645. AND fcpd.video_id = #{videoId}
  1646. </if>
  1647. </where>
  1648. GROUP BY
  1649. fcpd.video_id
  1650. </select>
  1651. <select id="companyUserCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1652. SELECT
  1653. (
  1654. 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
  1655. <where>
  1656. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1657. AND ucu.company_user_id = #{companyUserId}
  1658. </if>
  1659. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1660. and ucu.company_id = #{companyId}
  1661. </if>
  1662. </where>
  1663. ) AS userTotal,
  1664. (
  1665. SELECT
  1666. count( fs_user.user_id )
  1667. FROM
  1668. fs_user
  1669. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1670. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1671. <where>
  1672. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1673. AND ucu.company_user_id = #{companyUserId}
  1674. </if>
  1675. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1676. and ucu.company_id = #{companyId}
  1677. </if>
  1678. and fs_user.is_del = 0
  1679. AND to_days( fs_user.create_time ) = to_days(
  1680. now())
  1681. </where>
  1682. ) AS todayNewUser
  1683. </select>
  1684. <select id="newUserRedPacketCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1685. SELECT
  1686. count(flog.log_id) as userRedPacketNum,
  1687. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1688. FROM
  1689. fs_course_red_packet_log flog
  1690. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1691. <where>
  1692. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1693. AND flog.company_user_id = #{companyUserId}
  1694. </if>
  1695. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1696. and flog.company_id = #{companyId}
  1697. </if>
  1698. </where>
  1699. </select>
  1700. <select id="countUserCourse2" resultType="java.util.Map">
  1701. SELECT
  1702. (
  1703. SELECT
  1704. count(DISTINCT l.user_id)
  1705. FROM
  1706. fs_course_watch_log l
  1707. LEFT JOIN fs_user on fs_user.user_id = l.user_id
  1708. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1709. 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
  1710. where
  1711. l.log_type != 3 and send_type = 1
  1712. <if test="userId != null and userId != 0 ">
  1713. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1714. </if>
  1715. <if test="userId != null and userId == 0 ">
  1716. and l.company_id = #{companyId}
  1717. </if>
  1718. <if test="periodId != null and periodId != ''">
  1719. AND l.period_id = #{periodId}
  1720. </if>
  1721. <if test="videoId != null and videoId != ''">
  1722. AND l.video_id = #{videoId}
  1723. </if>
  1724. <if test="startTime != null and startTime !='' ">
  1725. and l.create_time &gt;= #{startTime}
  1726. </if>
  1727. <if test="endTime != null and endTime != ''">
  1728. and l.create_time &lt;= #{endTime}
  1729. </if> <if test="companyUserId != null and companyUserId != ''">
  1730. AND l.user_id = #{companyUserId}
  1731. </if>
  1732. -- 单独通过销售id查询
  1733. <if test="companyUserId != null and companyUserId != ''">
  1734. AND l.company_user_id = #{companyUserId}
  1735. </if>
  1736. ) as courseWatchNum,
  1737. (
  1738. SELECT
  1739. count(DISTINCT l.user_id)
  1740. FROM
  1741. fs_course_watch_log l
  1742. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1743. LEFT JOIN fs_user ON fs_user.user_id = l.user_id
  1744. 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
  1745. where
  1746. l.log_type = 2 and send_type = 1
  1747. <if test="userId != null and userId != 0 ">
  1748. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1749. </if>
  1750. <if test="userId != null and userId == 0 ">
  1751. and l.company_id = #{companyId}
  1752. </if>
  1753. <if test="periodId != null and periodId != ''">
  1754. AND l.period_id = #{periodId}
  1755. </if>
  1756. <if test="videoId != null and videoId != ''">
  1757. AND l.video_id = #{videoId}
  1758. </if>
  1759. <if test="startTime != null and startTime !='' ">
  1760. and l.create_time &gt;= #{startTime}
  1761. </if>
  1762. <if test="endTime != null and endTime != ''">
  1763. and l.create_time &lt;= #{endTime}
  1764. </if>
  1765. -- 单独通过销售id查询
  1766. <if test="companyUserId != null and companyUserId != ''">
  1767. AND l.company_user_id = #{companyUserId}
  1768. </if>
  1769. ) as courseCompleteNum
  1770. </select>
  1771. <select id="countCourseDetailsNew" resultType="Map">
  1772. SELECT
  1773. count( DISTINCT l.period_id ) as courseNum,
  1774. count( DISTINCT l.video_id ) as videoNum,
  1775. count( DISTINCT l.user_id ) as courseUserNum
  1776. FROM
  1777. fs_course_watch_log l
  1778. left join fs_user on fs_user.user_id = l.user_id
  1779. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1780. WHERE
  1781. l.log_type != 3
  1782. AND send_type = 1
  1783. <if test="userId != null and userId != 0 ">
  1784. AND l.company_user_id = #{userId}
  1785. </if>
  1786. <if test="userId != null and userId == 0 ">
  1787. and l.company_id = #{companyId}
  1788. </if>
  1789. <if test="periodId != null and periodId != ''">
  1790. AND l.period_id = #{periodId}
  1791. </if>
  1792. <if test="videoId != null and videoId != ''">
  1793. AND l.video_id = #{videoId}
  1794. </if>
  1795. -- 单独通过销售id查询
  1796. <if test="companyUserId != null and companyUserId != ''">
  1797. AND l.company_user_id = #{companyUserId}
  1798. </if>
  1799. </select>
  1800. <select id="selectFsUserVOListByProjectNew" resultType="com.fs.his.vo.FsUserVO">
  1801. SELECT
  1802. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  1803. ucu.project_id,ucu.company_user_id as companyUserId,ucu.create_time as bindTime,ucu.status,
  1804. company.company_name,
  1805. cu.nick_name companyUserNickName
  1806. FROM
  1807. fs_user_company_user ucu
  1808. left join
  1809. fs_user u on ucu.user_id = u.user_id
  1810. left join
  1811. company on company.company_id = ucu.company_id
  1812. left join
  1813. company_user cu on cu.user_id = ucu.company_user_id
  1814. <where>
  1815. 1 = 1 and u.nick_name is not null
  1816. and u.is_del = 0
  1817. <if test = "maps.nickname != null and maps.nickname !='' " >
  1818. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  1819. </if >
  1820. <if test = "maps.userId != null and maps.userId !='' " >
  1821. AND u.user_id = #{maps.userId}
  1822. </if >
  1823. <if test = "maps.phone != null and maps.phone !='' " >
  1824. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  1825. </if >
  1826. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  1827. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  1828. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  1829. )
  1830. </if >
  1831. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  1832. AND u.register_code = #{maps.registerCode}
  1833. </if >
  1834. <if test = "maps.status != null" >
  1835. AND ucu.status = #{maps.status}
  1836. </if >
  1837. <if test = "maps.companyId != null and maps.companyId != '' " >
  1838. AND ucu.company_id = #{maps.companyId}
  1839. </if >
  1840. <if test = "maps.companyUserId != null" >
  1841. AND ucu.company_user_id = #{maps.companyUserId}
  1842. </if >
  1843. <if test = "maps.projectId != null" >
  1844. AND ucu.project_id = #{maps.projectId}
  1845. </if >
  1846. </where>
  1847. ORDER BY
  1848. user_id DESC
  1849. </select>
  1850. <select id="selectFsUserVOListByProject" resultType="com.fs.his.vo.FsUserVO">
  1851. SELECT distinct
  1852. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  1853. u.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  1854. fcc.watch_course_count, fcc.part_course_count, company_user.nick_name AS companyUserNickName, fcc.last_watch_date
  1855. ,company.company_name,
  1856. ucu.project_id,
  1857. ucu.id as companyUserId,
  1858. ucu.create_time as bindTime,
  1859. ucu.status
  1860. FROM
  1861. fs_user u
  1862. LEFT JOIN (
  1863. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  1864. user_id
  1865. FROM
  1866. fs_store_payment
  1867. WHERE
  1868. STATUS = 1
  1869. AND user_id IS NOT NULL
  1870. GROUP BY
  1871. user_id
  1872. ) b ON u.user_id = b.user_id
  1873. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  1874. AND b.last_buy_time = p.pay_time
  1875. AND b.payment_id = p.payment_id
  1876. LEFT JOIN (
  1877. SELECT
  1878. 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,
  1879. fs_user_course_count.part_course_count
  1880. FROM
  1881. fs_user_course_count
  1882. GROUP BY fs_user_course_count.user_id
  1883. ) fcc ON fcc.user_id = u.user_id
  1884. inner join fs_user_company_user ucu on ucu.user_id = u.user_id
  1885. LEFT JOIN company_user ON company_user.user_id = ucu.company_user_id
  1886. LEFT JOIN company on company.company_id = company_user.company_id
  1887. <where>
  1888. 1 = 1 and u.nick_name is not null
  1889. and u.is_del = 0
  1890. <if test = "maps.nickname != null and maps.nickname !='' " >
  1891. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  1892. </if >
  1893. <if test = "maps.userId != null and maps.userId !='' " >
  1894. AND u.user_id = #{maps.userId}
  1895. </if >
  1896. <if test = "maps.phone != null and maps.phone !='' " >
  1897. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  1898. </if >
  1899. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  1900. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  1901. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  1902. )
  1903. </if >
  1904. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  1905. AND u.register_code = #{maps.registerCode}
  1906. </if >
  1907. <if test = "maps.status != null" >
  1908. AND ucu.status = #{maps.status}
  1909. </if >
  1910. <if test = "maps.companyId != null and maps.companyId != '' " >
  1911. AND company.company_id = #{maps.companyId}
  1912. </if >
  1913. <if test = "maps.companyUserId != null" >
  1914. AND company_user.user_id = #{maps.companyUserId}
  1915. </if >
  1916. <if test = "maps.projectId != null" >
  1917. AND ucu.project_id = #{maps.projectId}
  1918. </if >
  1919. </where>
  1920. ORDER BY
  1921. user_id DESC
  1922. </select>
  1923. <select id="selectCompanyAndDoctor" resultType="com.fs.watch.domain.vo.FsUserAndCompanyAndDoctorVo">
  1924. SELECT
  1925. f.*,
  1926. GROUP_CONCAT(c.company_id SEPARATOR ',') AS company_id,
  1927. GROUP_CONCAT(c.company_user_id SEPARATOR ',') AS company_user_id,
  1928. GROUP_CONCAT(o.doctor_id SEPARATOR ',') AS doctor_id
  1929. FROM
  1930. fs_user f
  1931. LEFT JOIN
  1932. company_user_user c ON c.user_id = f.user_id
  1933. LEFT JOIN
  1934. fs_inquiry_order o ON o.user_id = f.user_id AND o.`status` = 4
  1935. WHERE
  1936. f.is_del = 0 AND f.user_id = #{userId}
  1937. GROUP BY
  1938. f.user_id;
  1939. </select>
  1940. <select id="selectUserNameByIds" resultMap="FsUserResult">
  1941. select user_id,nick_name from fs_user where user_id in
  1942. <foreach collection="userIds.split(',')" item="userId" open="(" close=")" separator=",">
  1943. #{userId}
  1944. </foreach>
  1945. </select>
  1946. <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
  1947. SELECT
  1948. count( DISTINCT fs_user.user_id ) as userNum,
  1949. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  1950. fs_user_company_user.company_id
  1951. FROM
  1952. fs_user
  1953. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1954. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1955. WHERE
  1956. fs_user.is_del = 0
  1957. AND fs_user.`status` = 1
  1958. AND fs_user_company_user.`status` = 1
  1959. AND company_user.user_id IS NOT NULL
  1960. GROUP BY
  1961. fs_user_company_user.company_id
  1962. </select>
  1963. <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
  1964. SELECT
  1965. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  1966. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  1967. ifnull(
  1968. ROUND(
  1969. (
  1970. 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,
  1971. 2
  1972. ),
  1973. 0
  1974. ) AS completeWatchRate,
  1975. fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
  1976. FROM
  1977. fs_course_watch_log fwl
  1978. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fwl.user_id
  1979. WHERE
  1980. fwl.send_type = 1
  1981. AND fs_user_company_user.`status` = 1
  1982. GROUP BY
  1983. fwl.period_id, fwl.video_id, fwl.company_user_id
  1984. </select>
  1985. <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
  1986. SELECT
  1987. count(DISTINCT flog.log_id ) AS redPacketNum,
  1988. ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
  1989. flog.period_id,
  1990. flog.video_id,
  1991. flog.company_user_id,
  1992. flog.company_id
  1993. FROM
  1994. fs_course_red_packet_log flog
  1995. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = flog.user_id
  1996. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1997. where flog.`status` = 1
  1998. AND fs_user_company_user.`status` = 1
  1999. GROUP BY
  2000. flog.period_id,
  2001. flog.video_id,
  2002. flog.company_user_id
  2003. </select>
  2004. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  2005. SELECT
  2006. count( DISTINCT fs_user_company_user.user_id ) AS answerNum,
  2007. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user_company_user.user_id END ) AS answerRightNum,
  2008. ifnull(
  2009. ROUND(
  2010. (
  2011. 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,
  2012. 2
  2013. ),
  2014. 0
  2015. ) AS answerRightRate,
  2016. fs_course_answer_logs.period_id,
  2017. fs_course_answer_logs.video_id,
  2018. fs_course_answer_logs.company_user_id,
  2019. fs_course_answer_logs.company_id
  2020. FROM
  2021. fs_course_answer_logs
  2022. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_course_answer_logs.user_id
  2023. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2024. where fs_user_company_user.`status` = 1
  2025. GROUP BY
  2026. fs_course_answer_logs.period_id,
  2027. fs_course_answer_logs.video_id,
  2028. fs_course_answer_logs.company_user_id
  2029. </select>
  2030. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  2031. SELECT
  2032. count(DISTINCT fs_user.user_id ) as userNum,
  2033. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  2034. date(fs_user.create_time) as userCreateDate
  2035. ,company.company_id,
  2036. company.company_name,
  2037. company_user.user_id AS companyUserId,
  2038. company_user.nick_name AS companyUserName
  2039. FROM
  2040. fs_user
  2041. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  2042. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  2043. LEFT JOIN company ON company.company_id = fs_user_company_user.company_id
  2044. WHERE
  2045. fs_user.is_del = 0
  2046. AND fs_user_company_user.`status` = 1
  2047. AND fs_user.`status` = 1
  2048. AND company_user.user_id is not null
  2049. GROUP BY
  2050. fs_user_company_user.company_user_id, date(fs_user.create_time)
  2051. </select>
  2052. <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
  2053. <include refid="selectFsUserVo"/>
  2054. <where>
  2055. <if test="userName != null and userName != ''">
  2056. AND (
  2057. nickname like concat('%', #{userName}, '%')
  2058. or user_id LIKE concat('%',#{userName},'%')
  2059. )
  2060. </if>
  2061. </where>
  2062. order by user_id desc
  2063. </select>
  2064. <select id="selectFsUserCount" resultType="java.lang.Long">
  2065. select count(1) from fs_user
  2066. where 1=1
  2067. <if test = "type != null and type ==1">
  2068. and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
  2069. </if>
  2070. <if test = "companyId != null">
  2071. and company_id=#{companyId}
  2072. </if>
  2073. <if test="companyUserId != null">
  2074. and company_user_id = #{companyUserId}
  2075. </if>
  2076. </select>
  2077. <select id="selectFsUserListLimit" resultMap="FsUserResult">
  2078. <include refid="selectFsUserVo"/>
  2079. <where>
  2080. <if test="password != null and password != ''">and password = #{password}</if>
  2081. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  2082. <if test="birthday != null ">and birthday = #{birthday}</if>
  2083. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  2084. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  2085. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  2086. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  2087. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  2088. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  2089. <if test="integral != null ">and integral = #{integral}</if>
  2090. <if test="signNum != null ">and sign_num = #{signNum}</if>
  2091. <if test="status != null ">and status = #{status}</if>
  2092. <if test="level != null ">and level = #{level}</if>
  2093. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  2094. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  2095. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  2096. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  2097. <if test="payCount != null ">and pay_count = #{payCount}</if>
  2098. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  2099. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  2100. <if test="isDel != null ">and is_del = #{isDel}</if>
  2101. <if test="companyId != null ">and company_id = #{companyId}</if>
  2102. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  2103. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  2104. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  2105. </if>
  2106. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  2107. <if test="source != null and source != '' ">and source = #{source}</if>
  2108. <if test="isShow != null ">and is_show = #{isShow}</if>
  2109. <if test="(username != null and username != '') or (userId != null and userId != '') or (nickname != null and nickname != '') or (phone != null and phone != '')">
  2110. and (
  2111. <if test="username != null and username != ''">username like concat('%', #{username}, '%')</if>
  2112. <if test="userId != null and userId != ''">or user_id = #{userId}</if>
  2113. <if test="nickname != null and nickname != ''">or nickname like concat('%', #{nickname}, '%')</if>
  2114. <if test="phone != null and phone != ''">or phone like concat('%',#{phone},'%')</if>
  2115. )
  2116. </if>
  2117. <if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  2118. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>
  2119. <if test="payOrder != null ">and pay_order = #{payOrder}</if>
  2120. </where>
  2121. order by user_id desc
  2122. limit 10
  2123. </select>
  2124. <select id="findUsersByParam" resultType="com.fs.his.dto.FindUsersByDTO">
  2125. SELECT user_id as id, 0 as type,
  2126. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2127. FROM fs_user
  2128. WHERE user_id = #{keywords}
  2129. UNION
  2130. <!-- fs_user 按nick_name前缀搜索 -->
  2131. SELECT user_id as id, 0 as type,
  2132. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2133. FROM fs_user
  2134. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2135. UNION
  2136. <!-- fs_user 按phone精确搜索(仅当keywords是数字时) -->
  2137. <if test="keywords.matches('\\d+')">
  2138. SELECT user_id as id, 0 as type,
  2139. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  2140. FROM fs_user
  2141. WHERE phone = #{keywords}
  2142. UNION
  2143. </if>
  2144. <!-- company_user相关查询 -->
  2145. SELECT user_id as id, 1 as type,
  2146. IFNULL(nick_name, '') as name
  2147. FROM company_user
  2148. WHERE user_id = #{keywords}
  2149. UNION
  2150. SELECT user_id as id, 1 as type,
  2151. IFNULL(nick_name, '') as name
  2152. FROM company_user
  2153. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  2154. <if test="keywords.matches('\\d+')">
  2155. UNION
  2156. SELECT user_id as id, 1 as type,
  2157. IFNULL(nick_name, '') as name
  2158. FROM company_user
  2159. WHERE phonenumber = #{keywords}
  2160. </if>
  2161. </select>
  2162. <select id="countExternalRedPacketStats" resultType="com.fs.store.vo.h5.ExternalRedPacketStatsVO">
  2163. SELECT
  2164. COUNT(red.log_id) AS redPacketNum,
  2165. COALESCE(SUM(red.amount), 0) AS redPacketAmount
  2166. FROM fs_course_red_packet_log log
  2167. WHERE log.status = 1
  2168. AND log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2169. <if test="startTime != null and startTime != ''">
  2170. AND log.create_time &gt;= #{startTime}
  2171. </if>
  2172. <if test="endTime != null and endTime != ''">
  2173. AND log.create_time &lt;= #{endTime}
  2174. </if>
  2175. </select>
  2176. <select id="countExternalAnswerStats" resultType="com.fs.store.vo.h5.ExternalAnswerStatsVO">
  2177. SELECT
  2178. COUNT(*) AS answerNum,
  2179. SUM(CASE WHEN is_right = 1 THEN 1 ELSE 0 END) AS answerRightNum
  2180. FROM fs_course_answer_logs log
  2181. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2182. <if test="startTime != null and startTime != ''">
  2183. AND log.create_time &gt;= #{startTime}
  2184. </if>
  2185. <if test="endTime != null and endTime != ''">
  2186. AND log.create_time &lt;= #{endTime}
  2187. </if>
  2188. </select>
  2189. <select id="countExternalWatchStats" resultType="com.fs.store.vo.h5.ExternalWatchStatsVO">
  2190. SELECT
  2191. COUNT(CASE WHEN log_type != 3 THEN 1 END) AS courseWatchNum,
  2192. COUNT(CASE WHEN log_type = 2 THEN 1 END) AS courseCompleteNum
  2193. FROM fs_course_watch_log log
  2194. WHERE log.user_id = #{userId} AND log.company_user_id = #{companyUserId}
  2195. <if test="startTime != null and startTime != ''">
  2196. AND log.create_time &gt;= #{startTime}
  2197. </if>
  2198. <if test="endTime != null and endTime != ''">
  2199. AND log.create_time &lt;= #{endTime}
  2200. </if>
  2201. </select>
  2202. <select id="selectLastWatchTimeByUserAndProject" resultType="java.util.Map">
  2203. SELECT
  2204. CONCAT(user_id, '_', project) AS userProjectKey,
  2205. MAX(COALESCE(update_time, create_time)) AS lastWatchTime
  2206. FROM fs_course_watch_log
  2207. WHERE (user_id, project) IN
  2208. <foreach collection="userProjectPairs" item="pair" open="(" close=")" separator=",">
  2209. (#{pair.userId}, #{pair.projectId})
  2210. </foreach>
  2211. GROUP BY user_id, project_id
  2212. </select>
  2213. </mapper>