FsUserMapper.xml 81 KB

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