FsUserMapper.xml 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.his.mapper.FsUserMapper">
  6. <resultMap type="FsUser" id="FsUserResult">
  7. <result property="userId" column="user_id" />
  8. <result property="nickName" column="nick_name" />
  9. <result property="avatar" column="avatar" />
  10. <result property="phone" column="phone" />
  11. <result property="integral" column="integral" />
  12. <result property="status" column="status" />
  13. <result property="tuiUserId" column="tui_user_id" />
  14. <result property="tuiTime" column="tui_time" />
  15. <result property="tuiUserCount" column="tui_user_count" />
  16. <result property="maOpenId" column="ma_open_id" />
  17. <result property="mpOpenId" column="mp_open_id" />
  18. <result property="unionId" column="union_id" />
  19. <result property="isDel" column="is_del" />
  20. <result property="userCode" column="user_code" />
  21. <result property="remark" column="remark" />
  22. <result property="createTime" column="create_time" />
  23. <result property="updateTime" column="update_time" />
  24. <result property="lastIp" column="last_ip" />
  25. <result property="balance" column="balance" />
  26. <result property="signNum" column="sign_num" />
  27. <result property="integralStatus" column="integral_status" />
  28. <result property="isBuy" column="is_buy" />
  29. <result property="password" column="password" />
  30. <result property="isVip" column="is_vip" />
  31. <result property="jpushId" column="jpush_id" />
  32. <result property="vipStartDate" column="vip_start_date" />
  33. <result property="vipEndDate" column="vip_end_date" />
  34. <result property="vipLevel" column="vip_level" />
  35. <result property="vipStatus" column="vip_status" />
  36. <result property="sex" column="sex" />
  37. <result property="storeOpenId" column="store_open_id" />
  38. <result property="isPush" column="is_push" />
  39. <result property="isIndividuationPush" column="is_individuation_push" />
  40. <result property="isWeixinAuth" column="is_weixin_auth" />
  41. <result property="companyId" column="company_id"/>
  42. <result property="companyUserId" column="company_user_id"/>
  43. <result property="loginDevice" column="login_device" />
  44. <result property="source" column="source" />
  45. <result property="isAddQw" column="is_add_qw" />
  46. <result property="parentId" column="parent_id" />
  47. <result property="courseMaOpenId" column="course_ma_open_id" />
  48. <result property="qwExtId" column="qw_ext_id" />
  49. <result property="qwUserId" column="qw_user_id" />
  50. </resultMap>
  51. <sql id="selectFsUserVo">
  52. select user_id,qw_ext_id,sex,is_buy,course_ma_open_id,is_push,is_add_qw,source,login_device,is_individuation_push,store_open_id,password,jpush_id, is_vip,vip_start_date,vip_end_date,vip_level,vip_status,nick_name,integral_status, avatar, phone, integral,sign_num, status, tui_user_id, tui_time, tui_user_count, ma_open_id, mp_open_id, union_id, is_del, user_code, remark, create_time, update_time, last_ip, balance,is_weixin_auth,parent_id,qw_user_id,company_id,company_user_id from fs_user
  53. </sql>
  54. <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
  55. <include refid="selectFsUserVo"/>
  56. <where>
  57. <if test="userId != null">and user_id = #{userId}</if>
  58. <if test="nickName != null and nickName != ''"> and nick_name like concat( #{nickName}, '%')</if>
  59. <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
  60. <if test="phone != null and phone != ''"> and phone = #{phone}</if>
  61. <if test="integral != null "> and integral = #{integral}</if>
  62. <if test="signNum != null "> and sign_num = #{signNum}</if>
  63. <if test="status != null "> and status = #{status}</if>
  64. <if test="tuiUserId != null and tuiUserId != ''"> and tui_user_id = #{tuiUserId}</if>
  65. <if test="tuiTime != null "> and tui_time = #{tuiTime}</if>
  66. <if test="tuiUserCount != null "> and tui_user_count = #{tuiUserCount}</if>
  67. <if test="maOpenId != null and maOpenId != ''"> and ma_open_id = #{maOpenId}</if>
  68. <if test="mpOpenId != null and mpOpenId != ''"> and mp_open_id = #{mpOpenId}</if>
  69. <if test="unionId != null and unionId != ''"> and union_id = #{unionId}</if>
  70. <if test="isDel != null "> and is_del = #{isDel}</if>
  71. <if test="userCode != null and userCode != ''"> and user_code = #{userCode}</if>
  72. <if test="lastIp != null and lastIp != ''"> and last_ip = #{lastIp}</if>
  73. <if test="balance != null "> and balance = #{balance}</if>
  74. </where>
  75. </select>
  76. <select id="selectFsUserByUserId" parameterType="Long" resultMap="FsUserResult">
  77. <include refid="selectFsUserVo"/>
  78. where user_id = #{userId}
  79. </select>
  80. <select id="courseAnalysisWatchLog" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  81. SELECT
  82. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS courseWatchNum,
  83. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTimes,
  84. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS courseCompleteNum,
  85. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTimes,
  86. ifnull(
  87. ROUND(
  88. (
  89. COUNT( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) / count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END )) * 100,
  90. 2
  91. ),
  92. 0
  93. ) AS completeRate,
  94. fwl.video_id
  95. FROM
  96. fs_course_watch_log fwl
  97. <where>
  98. <if test="periodId != null and periodId != ''">
  99. AND fwl.period_id = #{periodId}
  100. </if>
  101. <if test="videoId != null and videoId != ''">
  102. AND fwl.video_id = #{videoId}
  103. </if>
  104. <if test="videoIdList != null and videoIdList.size > 0 ">
  105. AND fwl.video_id in
  106. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  107. #{videoId}
  108. </foreach>
  109. </if>
  110. <if test="companyId != null">
  111. AND fwl.company_id = #{companyId}
  112. </if>
  113. </where>
  114. GROUP BY
  115. fwl.video_id
  116. </select>
  117. <select id="courseAnalysisRedPacketCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  118. SELECT
  119. count( flog.log_id ) as redPacketNum,
  120. ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
  121. flog.video_id
  122. FROM
  123. fs_course_red_packet_log flog
  124. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  125. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  126. <where>
  127. <if test="companyUserId != null and companyUserId != 0 ">
  128. AND flog.company_user_id = #{companyUserId}
  129. </if>
  130. <if test="companyUserId != null and companyUserId == 0 ">
  131. and flog.company_id = #{companyId}
  132. </if>
  133. <if test="periodId != null and periodId != ''">
  134. AND flog.period_id = #{periodId}
  135. </if>
  136. <if test="videoId != null and videoId != ''">
  137. AND flog.video_id = #{videoId}
  138. </if>
  139. <if test="videoIdList != null and videoIdList.size > 0 ">
  140. AND flog.video_id in
  141. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  142. #{videoId}
  143. </foreach>
  144. </if>
  145. <if test="companyId != null">
  146. AND flog.company_id = #{companyId}
  147. </if>
  148. </where>
  149. GROUP BY
  150. flog.video_id
  151. </select>
  152. <select id="courseAnalysisAnswerCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  153. SELECT
  154. count( DISTINCT fs_user.user_id ) as answerNum,
  155. count(fs_course_answer_logs.log_id) answerTimes,
  156. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
  157. COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) as answerRightTimes,
  158. ifnull(
  159. ROUND(
  160. (
  161. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  162. 2
  163. ),
  164. 0
  165. ) as answerRightRate,
  166. fs_course_answer_logs.video_id
  167. FROM
  168. fs_course_answer_logs
  169. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  170. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  171. <where>
  172. <if test="companyUserId != null and companyUserId != 0 ">
  173. AND fs_course_answer_logs.company_user_id = #{companyUserId}
  174. </if>
  175. <if test="companyUserId != null and companyUserId == 0 ">
  176. and fs_course_answer_logs.company_id = #{companyId}
  177. </if>
  178. <if test="periodId != null and periodId != ''">
  179. AND fs_course_answer_logs.period_id = #{periodId}
  180. </if>
  181. <if test="videoId != null and videoId != ''">
  182. AND fs_course_answer_logs.video_id = #{videoId}
  183. </if>
  184. <if test="videoIdList != null and videoIdList.size > 0 ">
  185. AND fs_course_answer_logs.video_id in
  186. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  187. #{videoId}
  188. </foreach>
  189. </if>
  190. <if test="companyId != null">
  191. AND fs_course_answer_logs.company_id = #{companyId}
  192. </if>
  193. </where>
  194. GROUP BY
  195. fs_course_answer_logs.video_id
  196. </select>
  197. <select id="selectFsUserById" parameterType="Long" resultMap="FsUserResult">
  198. <include refid="selectFsUserVo"/>
  199. where user_id = #{userId}
  200. </select>
  201. <select id="selectFsUserPageList" resultType="com.fs.store.vo.h5.FsUserPageListVO">
  202. SELECT
  203. fs_user.user_id,
  204. fs_user.avatar,
  205. fs_user.nick_name as nickname,
  206. fs_user.phone,
  207. fs_user_course_count.id,
  208. fs_user_course_count.watch_course_count,
  209. -- fs_course_watch_log.watch_course_count,
  210. fs_user_course_count.miss_course_count,
  211. fs_user_course_count.miss_course_status,
  212. fs_user_course_count.course_ids,
  213. fs_user_course_count.part_course_count,
  214. -- fs_course_watch_log.part_course_count,
  215. fs_user_course_count.last_watch_date,
  216. fs_user_course_count.STATUS AS courseCountStatus,
  217. fs_user_course_count.stop_watch_days,
  218. fs_user_course_count.complete_watch_date,
  219. GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
  220. GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
  221. company_user.nick_name as companyUserNickName,
  222. fs_user_company_user.is_repeat_fans,
  223. fs_user_company_user.project_id,
  224. fs_user_company_user.`status`,
  225. fs_user_company_user.remark,
  226. fs_user_company_user.id as userCompanyUserId,
  227. fs_user_company_user.create_time
  228. FROM
  229. fs_user
  230. INNER JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  231. LEFT JOIN fs_user_course_count ON fs_user_company_user.user_id = fs_user_course_count.user_id and fs_user_company_user.project_id = fs_user_course_count.project_id
  232. left join fs_user_project_tag upt ON upt.user_company_user_id = fs_user_company_user.id
  233. LEFT JOIN company_tag ON company_tag.tag_id = upt.tag_id
  234. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  235. where fs_user.is_del = 0
  236. <if test="userId != null and userId!= 0 ">
  237. and fs_user_company_user.company_user_id = #{userId}
  238. </if>
  239. <if test="companyId != null ">
  240. and fs_user_company_user.company_id = #{companyId}
  241. </if>
  242. <if test="status != null">
  243. AND fs_user_company_user.status = #{status}
  244. </if>
  245. <if test="projectId != null">
  246. AND fs_user_company_user.project_id = #{projectId}
  247. </if>
  248. <if test="keyword != null and keyword !='' ">
  249. AND (fs_user.nick_name LIKE concat('%',#{keyword},'%')
  250. or fs_user.phone LIKE concat('%',#{keyword},'%')
  251. )
  252. </if>
  253. <if test="registerStartTime != null and registerStartTime !='' ">
  254. AND fs_user_company_user.create_time &gt;= #{registerStartTime}
  255. </if>
  256. <if test="registerEndTime != null and registerEndTime !='' ">
  257. AND fs_user_company_user.create_time &lt;= #{registerEndTime}
  258. </if>
  259. <if test="isNullTag">
  260. and (upt.tag_id is null
  261. <if test="tagIds != null and tagIds.length > 0">
  262. or upt.tag_id in
  263. <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
  264. #{item}
  265. </foreach>
  266. </if>
  267. )
  268. </if>
  269. <if test="!isNullTag and tagIds != null and tagIds.length > 0">
  270. AND upt.tag_id in
  271. <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
  272. #{item}
  273. </foreach>
  274. </if>
  275. <if test="tabValue != null and tabValue !='' ">
  276. <choose>
  277. <when test = "tabValue == 1">
  278. AND 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_company_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.nickname 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. where u.company_user_id = #{companyUserId}
  690. </select>
  691. <select id="getUserNumber" resultType="com.fs.store.vo.h5.UserListCountVO">
  692. SELECT
  693. fs_user_company_user.`status` as status,
  694. count( DISTINCT fs_user.user_id ) AS num
  695. FROM
  696. fs_user
  697. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  698. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  699. WHERE fs_user.is_del = 0 and fs_user_company_user.is_repeat_fans is not null
  700. <if test="userId != null and userId != 0 ">
  701. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  702. </if>
  703. <if test="companyId != null ">
  704. and fs_user_company_user.company_id = #{companyId}
  705. </if>
  706. GROUP BY
  707. fs_user_company_user.`status`,fs_user_company_user.project_id
  708. </select>
  709. <select id="getRepeatUserNumber" resultType="int">
  710. SELECT
  711. count( DISTINCT fs_user.user_id ) AS num
  712. FROM
  713. fs_user
  714. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  715. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  716. WHERE
  717. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  718. AND fs_user.is_del = 0
  719. AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
  720. </select>
  721. <select id="getCountWatchCourse" resultType="com.fs.store.vo.h5.UserDetailsVO">
  722. SELECT
  723. <if test="dateTag == null or dateTag =='' or dateTag == '近七天' ">
  724. ifnull( sum(complete_watch_count), 0 ) AS completeWatchCount ,
  725. ifnull( sum(watch_times), 0 ) AS watchTimes,
  726. </if>
  727. <if test="dateTag != null and dateTag !='' and dateTag != '近七天' ">
  728. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  729. ifnull( watch_times, 0 ) AS watchTimes,
  730. </if>
  731. fs_user.user_id
  732. FROM
  733. fs_user_course_count
  734. LEFT JOIN fs_user ON fs_user.user_id = fs_user_course_count.user_id
  735. 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
  736. <where>
  737. <if test="dateTag != null and dateTag !='' ">
  738. <choose>
  739. <when test = "dateTag == '今天'">
  740. and to_days(fs_user_course_count.create_time) = to_days(now())
  741. </when>
  742. <when test = "dateTag == '昨天'">
  743. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_user_course_count.create_time &lt; CURDATE()
  744. </when>
  745. <when test = "dateTag == '前天'">
  746. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_user_course_count.create_time &lt; CURDATE() - INTERVAL 1 DAY
  747. </when>
  748. <when test = "dateTag == '近七天'">
  749. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  750. </when>
  751. </choose>
  752. </if>
  753. and fs_user.user_id = #{fsUserId}
  754. <if test="userCompanyId!=null">
  755. and cu.id = #{userCompanyId}
  756. </if>
  757. </where>
  758. GROUP BY
  759. fs_user.user_id
  760. </select>
  761. <select id="getCountAnswer" resultType="com.fs.store.vo.h5.UserDetailsVO">
  762. SELECT
  763. (
  764. SELECT
  765. ifnull(count( DISTINCT fs_course_answer_logs.log_id ), 0) AS answerTime
  766. FROM
  767. fs_course_answer_logs
  768. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  769. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id =fcwl.log_id
  770. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  771. <where>
  772. <if test="dateTag != null and dateTag !='' ">
  773. <choose>
  774. <when test = "dateTag == '今天'">
  775. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  776. </when>
  777. <when test = "dateTag == '昨天'">
  778. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  779. </when>
  780. <when test = "dateTag == '前天'">
  781. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  782. </when>
  783. <when test = "dateTag == '近七天'">
  784. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  785. </when>
  786. </choose>
  787. </if>
  788. and fs_user.user_id = #{fsUserId} and fucu.company_user_id =#{userId}
  789. </where>
  790. GROUP BY
  791. fs_user.user_id
  792. ) AS answerTime,
  793. (
  794. SELECT
  795. ifnull(count( DISTINCT fs_course_answer_logs.log_id ), 0) AS answerRightTime
  796. FROM
  797. fs_course_answer_logs
  798. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  799. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id =fcwl.log_id
  800. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  801. <where>
  802. fs_course_answer_logs.is_right = 1
  803. <if test="dateTag != null and dateTag !='' ">
  804. <choose>
  805. <when test = "dateTag == '今天'">
  806. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  807. </when>
  808. <when test = "dateTag == '昨天'">
  809. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  810. </when>
  811. <when test = "dateTag == '前天'">
  812. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  813. </when>
  814. <when test = "dateTag == '近七天'">
  815. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  816. </when>
  817. </choose>
  818. </if>
  819. and fs_user.user_id = #{fsUserId} and fucu.company_user_id =#{userId}
  820. </where>
  821. GROUP BY
  822. fs_user.user_id
  823. ) AS answerRightTime;
  824. </select>
  825. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  826. SELECT
  827. ifnull( count( DISTINCT fs_course_red_packet_log.log_id ), 0 ) AS answerRedPacketTime,
  828. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  829. fs_user.user_id
  830. FROM
  831. fs_course_red_packet_log
  832. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  833. left join fs_course_watch_log fcwl on fs_course_red_packet_log.watch_log_id =fcwl.log_id
  834. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  835. <where>
  836. fs_course_red_packet_log.status = 1
  837. <if test="dateTag != null and dateTag !='' ">
  838. <choose>
  839. <when test = "dateTag == '今天'">
  840. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  841. </when>
  842. <when test = "dateTag == '昨天'">
  843. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE()
  844. </when>
  845. <when test = "dateTag == '前天'">
  846. 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
  847. </when>
  848. <when test = "dateTag == '近七天'">
  849. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  850. </when>
  851. </choose>
  852. </if>
  853. and fs_user.user_id = #{fsUserId} and fucu.company_user_id =#{userId}
  854. </where>
  855. GROUP BY
  856. fs_user.user_id
  857. </select>
  858. <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
  859. SELECT (SELECT count(fs_user.user_id)
  860. FROM fs_user
  861. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  862. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  863. WHERE fs_user.is_del = 0
  864. <if test="userId != null and userId != 0 ">
  865. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  866. </if>
  867. <if test="companyId != null ">
  868. and ucu.company_id = #{companyId}
  869. </if>
  870. ) as userTotal,
  871. (SELECT count(fs_user.user_id)
  872. FROM fs_user
  873. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  874. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  875. WHERE fs_user.is_del = 0
  876. <if test="userId != null and userId != 0 ">
  877. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  878. </if>
  879. <if test="companyId != null ">
  880. and ucu.company_id = #{companyId}
  881. </if>
  882. AND to_days(ucu.create_time) = to_days(now())) as todayNewUser
  883. </select>
  884. <select id="countTag" resultType="com.fs.store.vo.h5.FsUserSummaryCountTagVO">
  885. SELECT
  886. company_tag.tag AS tagName,
  887. count( ucu.user_id ) AS number
  888. FROM
  889. fs_user_project_tag upt
  890. inner join fs_user_company_user ucu on ucu.id = upt.user_company_user_id
  891. inner join company_tag ON upt.tag_id = company_tag.tag_id
  892. left join company_user on company_user.user_id = ucu.company_user_id
  893. <where>
  894. <if test="userId != null and userId != 0 ">
  895. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  896. </if>
  897. <if test="companyId != null ">
  898. and ucu.company_id = #{companyId}
  899. </if>
  900. </where>
  901. GROUP BY
  902. company_tag.tag_id
  903. </select>
  904. <select id="countUserCourse" resultType="Map">
  905. SELECT
  906. (SELECT COUNT(*) FROM (
  907. SELECT 1
  908. FROM fs_user_course_count fcc
  909. JOIN fs_user ON fs_user.user_id = fcc.user_id
  910. JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
  911. JOIN company_user ON ucu.company_user_id = company_user.user_id
  912. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  913. <where>
  914. fcc.project_id = ucu.project_id
  915. <if test="userId != null and userId != 0 ">
  916. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  917. </if>
  918. <if test="userId != null and userId == 0 ">
  919. and ucu.company_id = #{companyId}
  920. </if>
  921. <if test="startTime != null and startTime !='' ">
  922. and fcc.create_time &gt;= #{startTime}
  923. </if>
  924. <if test="endTime != null and endTime != ''">
  925. and fcc.create_time &lt;= #{endTime}
  926. </if>
  927. <if test="periodId != null and periodId != ''">
  928. AND fcpd.period_id = #{periodId}
  929. </if>
  930. <if test="videoId != null and videoId != ''">
  931. AND fcpd.video_id = #{videoId}
  932. </if>
  933. -- 单独通过销售id查询
  934. <if test="companyUserId != null and companyUserId != ''">
  935. AND company_user.user_id = #{companyUserId}
  936. </if>
  937. </where>
  938. ) as courseWatchNum,
  939. (SELECT COUNT(*) FROM (
  940. SELECT 1
  941. FROM fs_user_course_count fcc
  942. JOIN fs_user ON fs_user.user_id = fcc.user_id
  943. JOIN fs_user_company_user ucu ON ucu.user_id = fs_user.user_id
  944. JOIN company_user ON ucu.company_user_id = company_user.user_id
  945. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  946. <where>
  947. fcc.project_id = ucu.project_id
  948. <if test="userId != null and userId != 0 ">
  949. and (ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  950. </if>
  951. <if test="userId != null and userId == 0 ">
  952. and ucu.company_id = #{companyId}
  953. </if>
  954. AND fcc.complete_watch_count > 0
  955. <if test="startTime != null and startTime !='' ">
  956. and fcc.create_time &gt;= #{startTime}
  957. </if>
  958. <if test="endTime != null and endTime != ''">
  959. and fcc.create_time &lt;= #{endTime}
  960. </if>
  961. <if test="periodId != null and periodId != ''">
  962. AND fcpd.period_id = #{periodId}
  963. </if>
  964. <if test="videoId != null and videoId != ''">
  965. AND fcpd.video_id = #{videoId}
  966. </if>
  967. -- 单独通过销售id查询
  968. <if test="companyUserId != null and companyUserId != ''">
  969. AND company_user.user_id = #{companyUserId}
  970. </if>
  971. </where>
  972. GROUP BY fcc.user_id, ucu.project_id
  973. ) AS complete_counts ) as courseCompleteNum
  974. </select>
  975. <select id="countUserAnswer" resultType="Map">
  976. SELECT
  977. (
  978. SELECT
  979. count(fs_user.user_id )
  980. FROM
  981. fs_course_answer_logs
  982. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  983. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  984. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  985. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  986. <where>
  987. <if test="userId != null and userId != 0 ">
  988. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  989. </if>
  990. <if test="userId != null and userId == 0 ">
  991. and fs_course_answer_logs.company_id = #{companyId}
  992. </if>
  993. <if test="startTime != null and startTime !='' ">
  994. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  995. </if>
  996. <if test="endTime != null and endTime != ''">
  997. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  998. </if>
  999. <if test="periodId != null and periodId != ''">
  1000. AND fs_course_answer_logs.period_id = #{periodId}
  1001. </if>
  1002. <if test="videoId != null and videoId != ''">
  1003. AND fs_course_answer_logs.video_id = #{videoId}
  1004. </if>
  1005. -- 单独通过销售id查询
  1006. <if test="companyUserId != null and companyUserId != ''">
  1007. AND company_user.user_id = #{companyUserId}
  1008. </if>
  1009. </where>
  1010. ) AS answerNum,
  1011. (
  1012. SELECT
  1013. count(fs_user.user_id )
  1014. FROM
  1015. fs_course_answer_logs
  1016. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1017. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1018. left join fs_course_watch_log fcwl on fs_course_answer_logs.watch_log_id=fcwl.log_id
  1019. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1020. <where>
  1021. <if test="userId != null and userId != 0 ">
  1022. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1023. </if>
  1024. <if test="userId != null and userId == 0 ">
  1025. and fs_course_answer_logs.company_id = #{companyId}
  1026. </if>
  1027. AND fs_course_answer_logs.is_right = 1
  1028. <if test="startTime != null and startTime !='' ">
  1029. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1030. </if>
  1031. <if test="endTime != null and endTime != ''">
  1032. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1033. </if>
  1034. <if test="periodId != null and periodId != ''">
  1035. AND fs_course_answer_logs.period_id = #{periodId}
  1036. </if>
  1037. <if test="videoId != null and videoId != ''">
  1038. AND fs_course_answer_logs.video_id = #{videoId}
  1039. </if>
  1040. -- 单独通过销售id查询
  1041. <if test="companyUserId != null and companyUserId != ''">
  1042. AND company_user.user_id = #{companyUserId}
  1043. </if>
  1044. </where>
  1045. ) AS answerRightNum
  1046. </select>
  1047. <select id="countCourseDetails" resultType="Map">
  1048. select (SELECT
  1049. count( DISTINCT fcpd.period_id )
  1050. FROM
  1051. fs_user_course_period_days fcpd
  1052. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1053. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1054. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1055. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1056. WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
  1057. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1058. <if test="userId != null and userId != 0 ">
  1059. AND ucu.company_user_id = #{userId}
  1060. </if>
  1061. <if test="userId != null and userId == 0 ">
  1062. and ucu.company_id = #{companyId}
  1063. </if>
  1064. <if test="periodId != null and periodId != ''">
  1065. AND fcpd.period_id = #{periodId}
  1066. </if>
  1067. -- 单独通过销售id查询
  1068. <if test="companyUserId != null and companyUserId != ''">
  1069. AND ucu.company_user_id = #{companyUserId}
  1070. </if>
  1071. ) as courseNum,
  1072. (SELECT count(DISTINCT fcpd.video_id)
  1073. FROM fs_user_course_period_days fcpd
  1074. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  1075. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1076. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1077. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1078. WHERE 1=1 and fcpd.del_flag =0 and fpd.del_flag =0
  1079. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  1080. <if test="userId != null and userId != 0 ">
  1081. AND ucu.company_user_id = #{userId}
  1082. </if>
  1083. <if test="userId != null and userId == 0 ">
  1084. and ucu.company_id = #{companyId}
  1085. </if>
  1086. <if test="periodId != null and periodId != ''">
  1087. AND fcpd.period_id = #{periodId}
  1088. </if>
  1089. <if test="videoId != null and videoId != ''">
  1090. AND fcpd.video_id = #{videoId}
  1091. </if>
  1092. -- 单独通过销售id查询
  1093. <if test="companyUserId != null and companyUserId != ''">
  1094. AND ucu.company_user_id = #{companyUserId}
  1095. </if>
  1096. ) as videoNum,
  1097. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  1098. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1099. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1100. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1101. <if test="periodId != null and periodId != ''">
  1102. AND fcpd.period_id = #{periodId}
  1103. </if>
  1104. <if test="videoId != null and videoId != ''">
  1105. AND fcpd.video_id = #{videoId}
  1106. </if>
  1107. -- 单独通过销售id查询
  1108. <if test="companyUserId != null and companyUserId != ''">
  1109. AND ucu.company_user_id = #{companyUserId}
  1110. </if>
  1111. <where>
  1112. <if test="userId != null and userId != 0 ">
  1113. AND ucu.company_user_id = #{userId}
  1114. </if>
  1115. <if test="userId != null and userId == 0 ">
  1116. and ucu.company_id = #{companyId}
  1117. </if>
  1118. </where>
  1119. ) as courseUserNum
  1120. </select>
  1121. <select id="countUserRankingByComplete" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1122. SELECT
  1123. company_user.nick_name as userName,
  1124. ifnull(
  1125. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  1126. ) as completeRate
  1127. FROM
  1128. fs_user_course_count fcc
  1129. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1130. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1131. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1132. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1133. <where>
  1134. <if test="userId != null and userId != 0 ">
  1135. AND ( ucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1136. </if>
  1137. <if test="userId != null and userId == 0 ">
  1138. and ucu.company_id = #{companyId}
  1139. </if>
  1140. <if test="startTime != null and startTime !='' ">
  1141. AND fcc.create_time &gt;= #{startTime}
  1142. </if>
  1143. <if test="endTime != null and endTime != ''">
  1144. AND fcc.create_time &lt;= #{endTime}
  1145. </if>
  1146. <if test="periodId != null and periodId != ''">
  1147. AND fcpd.period_id = #{periodId}
  1148. </if>
  1149. <if test="videoId != null and videoId != ''">
  1150. AND fcpd.video_id = #{videoId}
  1151. </if>
  1152. </where>
  1153. group by fcc.user_id
  1154. <choose>
  1155. <when test="order != null and order == 'asc'">
  1156. order by completeRate asc
  1157. </when>
  1158. <when test="order != null and order == 'desc'">
  1159. order by completeRate desc
  1160. </when>
  1161. <otherwise>
  1162. order by completeRate desc
  1163. </otherwise>
  1164. </choose>
  1165. limit 20
  1166. </select>
  1167. <select id="countUserRankingByRight" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1168. SELECT
  1169. company_user.nick_name as userName,
  1170. ifnull(ROUND(
  1171. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1172. *100,2),0
  1173. ) as answerRightRate
  1174. FROM
  1175. fs_course_answer_logs
  1176. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1177. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1178. <where>
  1179. <if test="userId != null and userId != 0 ">
  1180. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1181. </if>
  1182. <if test="userId != null and userId == 0 ">
  1183. and fs_course_answer_logs.company_id = #{companyId}
  1184. </if>
  1185. <if test="startTime != null and startTime !='' ">
  1186. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1187. </if>
  1188. <if test="endTime != null and endTime != ''">
  1189. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1190. </if>
  1191. <if test="periodId != null and periodId != ''">
  1192. AND fs_course_answer_logs.period_id = #{periodId}
  1193. </if>
  1194. <if test="videoId != null and videoId != ''">
  1195. AND fs_course_answer_logs.video_id = #{videoId}
  1196. </if>
  1197. </where>
  1198. group by fs_user.user_id
  1199. <choose>
  1200. <when test="order != null and order == 'asc'">
  1201. order by answerRightRate asc
  1202. </when>
  1203. <when test="order != null and order == 'desc'">
  1204. order by answerRightRate desc
  1205. </when>
  1206. <otherwise>
  1207. order by answerRightRate desc
  1208. </otherwise>
  1209. </choose>
  1210. limit 20
  1211. </select>
  1212. <select id="countCourseRankingByComplete" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1213. SELECT
  1214. fcv.title AS videoName,
  1215. fcv.video_id,
  1216. ifnull(
  1217. ROUND(
  1218. (
  1219. 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,
  1220. 2
  1221. ),
  1222. 0
  1223. ) AS completeRate
  1224. FROM
  1225. fs_course_watch_log fwl
  1226. LEFT JOIN fs_user ON fs_user.user_id = fwl.user_id
  1227. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1228. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  1229. -- LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1230. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fwl.video_id
  1231. <where>
  1232. <if test="userId != null and userId != 0 ">
  1233. AND ( fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1234. </if>
  1235. <if test="userId != null and userId == 0 ">
  1236. and fs_user_company_user.company_id = #{companyId}
  1237. </if>
  1238. <if test="startTime != null and startTime !='' ">
  1239. AND fwl.create_time &gt;= #{startTime}
  1240. </if>
  1241. <if test="endTime != null and endTime != ''">
  1242. AND fwl.create_time &lt;= #{endTime}
  1243. </if>
  1244. <if test="periodId != null and periodId != ''">
  1245. AND fwl.period_id = #{periodId}
  1246. </if>
  1247. <if test="videoId != null and videoId != ''">
  1248. AND fwl.video_id = #{videoId}
  1249. </if>
  1250. </where>
  1251. GROUP BY
  1252. fwl.video_id
  1253. <choose>
  1254. <when test="order != null and order == 'asc'">
  1255. ORDER BY completeRate asc
  1256. </when>
  1257. <when test="order != null and order == 'desc'">
  1258. ORDER BY completeRate desc
  1259. </when>
  1260. <otherwise>
  1261. ORDER BY completeRate desc
  1262. </otherwise>
  1263. </choose>
  1264. LIMIT 20
  1265. </select>
  1266. <select id="countCourseRankingByRight" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1267. SELECT
  1268. fcv.title AS videoName,
  1269. ifnull(
  1270. ROUND(
  1271. (
  1272. 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,
  1273. 2
  1274. ),
  1275. 0
  1276. ) AS answerRightRate
  1277. FROM
  1278. fs_course_answer_logs
  1279. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1280. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  1281. LEFT JOIN company_user ON company_user.user_id = fs_course_answer_logs.company_user_id
  1282. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1283. <where>
  1284. <if test="userId != null and userId != 0 ">
  1285. AND ( fs_course_answer_logs.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1286. </if>
  1287. <if test="userId != null and userId == 0 ">
  1288. and fs_course_answer_logs.company_id = #{companyId}
  1289. </if>
  1290. <if test="startTime != null and startTime !='' ">
  1291. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1292. </if>
  1293. <if test="endTime != null and endTime != ''">
  1294. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1295. </if>
  1296. <if test="periodId != null and periodId != ''">
  1297. AND fs_course_answer_logs.period_id = #{periodId}
  1298. </if>
  1299. <if test="videoId != null and videoId != ''">
  1300. AND fs_course_answer_logs.video_id = #{videoId}
  1301. </if>
  1302. </where>
  1303. GROUP BY
  1304. fs_course_answer_logs.video_id
  1305. <choose>
  1306. <when test="order != null and order == 'asc'">
  1307. ORDER BY answerRightRate asc
  1308. </when>
  1309. <when test="order != null and order == 'desc'">
  1310. ORDER BY answerRightRate desc
  1311. </when>
  1312. <otherwise>
  1313. ORDER BY answerRightRate desc
  1314. </otherwise>
  1315. </choose>
  1316. LIMIT 20
  1317. </select>
  1318. <select id="countUserRedPacket" resultType="Map">
  1319. SELECT
  1320. (
  1321. SELECT
  1322. count( flog.log_id )
  1323. FROM
  1324. fs_course_red_packet_log flog
  1325. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1326. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1327. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1328. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1329. where flog.status = 1
  1330. <if test="userId != null and userId != 0 ">
  1331. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1332. </if>
  1333. <if test="userId != null and userId == 0 ">
  1334. and flog.company_id = #{companyId}
  1335. </if>
  1336. <if test="startTime != null and startTime !='' ">
  1337. AND flog.create_time &gt;= #{startTime}
  1338. </if>
  1339. <if test="endTime != null and endTime != ''">
  1340. AND flog.create_time &lt;= #{endTime}
  1341. </if>
  1342. <if test="periodId != null and periodId != ''">
  1343. AND flog.period_id = #{periodId}
  1344. </if>
  1345. <if test="videoId != null and videoId != ''">
  1346. AND flog.video_id = #{videoId}
  1347. </if>
  1348. -- 单独通过销售id查询
  1349. <if test="companyUserId != null and companyUserId != ''">
  1350. AND company_user.user_id = #{companyUserId}
  1351. </if>
  1352. ) AS redPacketNum,
  1353. (
  1354. SELECT
  1355. ifnull (sum( flog.amount ), 0)
  1356. FROM
  1357. fs_course_red_packet_log flog
  1358. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1359. LEFT JOIN company_user ON company_user.user_id = flog.company_user_id
  1360. left join fs_course_watch_log fcwl on flog.watch_log_id =fcwl.log_id
  1361. left join fs_user_company_user fucu on fucu.user_id =fs_user.user_id and fcwl.project = fucu.project_id
  1362. where flog.status = 1
  1363. <if test="userId != null and userId != 0 ">
  1364. and (fucu.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1365. </if>
  1366. <if test="userId != null and userId == 0 ">
  1367. and flog.company_id = #{companyId}
  1368. </if>
  1369. <if test="startTime != null and startTime !='' ">
  1370. AND flog.create_time &gt;= #{startTime}
  1371. </if>
  1372. <if test="endTime != null and endTime != ''">
  1373. AND flog.create_time &lt;= #{endTime}
  1374. </if>
  1375. <if test="periodId != null and periodId != ''">
  1376. AND flog.period_id = #{periodId}
  1377. </if>
  1378. <if test="videoId != null and videoId != ''">
  1379. AND flog.video_id = #{videoId}
  1380. </if>
  1381. -- 单独通过销售id查询
  1382. <if test="companyUserId != null and companyUserId != ''">
  1383. AND company_user.user_id = #{companyUserId}
  1384. </if>
  1385. ) AS redPacketAmount
  1386. </select>
  1387. <select id="courseAnalysisCourseCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  1388. SELECT
  1389. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1390. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1391. ifnull(
  1392. ROUND(
  1393. (
  1394. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1395. 2
  1396. ),
  1397. 0
  1398. ) as completeRate,
  1399. fcpd.video_id
  1400. FROM
  1401. fs_user_course_count fcc
  1402. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1403. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1404. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1405. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1406. <where>
  1407. <if test="companyUserId != null and companyUserId != 0 ">
  1408. AND ucu.company_user_id = #{companyUserId}
  1409. </if>
  1410. <if test="companyUserId != null and companyUserId == 0 ">
  1411. and ucu.company_id = #{companyId}
  1412. </if>
  1413. <if test="periodId != null and periodId != ''">
  1414. AND fcpd.period_id = #{periodId}
  1415. </if>
  1416. <if test="videoId != null and videoId != ''">
  1417. AND fcpd.video_id = #{videoId}
  1418. </if>
  1419. </where>
  1420. GROUP BY
  1421. fcpd.video_id
  1422. </select>
  1423. <select id="companyUserCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1424. SELECT
  1425. (
  1426. 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
  1427. <where>
  1428. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1429. AND ucu.company_user_id = #{companyUserId}
  1430. </if>
  1431. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1432. and ucu.company_id = #{companyId}
  1433. </if>
  1434. </where>
  1435. ) AS userTotal,
  1436. (
  1437. SELECT
  1438. count( fs_user.user_id )
  1439. FROM
  1440. fs_user
  1441. left join fs_user_company_user ucu on ucu.user_id = fs_user.user_id
  1442. LEFT JOIN company_user ON ucu.company_user_id = company_user.user_id
  1443. <where>
  1444. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1445. AND ucu.company_user_id = #{companyUserId}
  1446. </if>
  1447. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1448. and ucu.company_id = #{companyId}
  1449. </if>
  1450. and fs_user.is_del = 0
  1451. AND to_days( fs_user.create_time ) = to_days(
  1452. now())
  1453. </where>
  1454. ) AS todayNewUser
  1455. </select>
  1456. <select id="newUserRedPacketCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1457. SELECT
  1458. count(flog.log_id) as userRedPacketNum,
  1459. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1460. FROM
  1461. fs_course_red_packet_log flog
  1462. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1463. <where>
  1464. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1465. AND flog.company_user_id = #{companyUserId}
  1466. </if>
  1467. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1468. and flog.company_id = #{companyId}
  1469. </if>
  1470. </where>
  1471. </select>
  1472. <select id="countUserCourse2" resultType="java.util.Map">
  1473. SELECT
  1474. (
  1475. SELECT
  1476. count(DISTINCT l.user_id)
  1477. FROM
  1478. fs_course_watch_log l
  1479. LEFT JOIN fs_user on fs_user.user_id = l.user_id
  1480. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1481. 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
  1482. where
  1483. l.log_type != 3 and send_type = 1
  1484. <if test="userId != null and userId != 0 ">
  1485. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1486. </if>
  1487. <if test="userId != null and userId == 0 ">
  1488. and l.company_id = #{companyId}
  1489. </if>
  1490. <if test="periodId != null and periodId != ''">
  1491. AND l.period_id = #{periodId}
  1492. </if>
  1493. <if test="videoId != null and videoId != ''">
  1494. AND l.video_id = #{videoId}
  1495. </if>
  1496. <if test="startTime != null and startTime !='' ">
  1497. and l.create_time &gt;= #{startTime}
  1498. </if>
  1499. <if test="endTime != null and endTime != ''">
  1500. and l.create_time &lt;= #{endTime}
  1501. </if> <if test="companyUserId != null and companyUserId != ''">
  1502. AND l.user_id = #{companyUserId}
  1503. </if>
  1504. -- 单独通过销售id查询
  1505. <if test="companyUserId != null and companyUserId != ''">
  1506. AND l.company_user_id = #{companyUserId}
  1507. </if>
  1508. ) as courseWatchNum,
  1509. (
  1510. SELECT
  1511. count(DISTINCT l.user_id)
  1512. FROM
  1513. fs_course_watch_log l
  1514. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1515. LEFT JOIN fs_user ON fs_user.user_id = l.user_id
  1516. 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
  1517. where
  1518. l.log_type = 2 and send_type = 1
  1519. <if test="userId != null and userId != 0 ">
  1520. and (fs_user_company_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1521. </if>
  1522. <if test="userId != null and userId == 0 ">
  1523. and l.company_id = #{companyId}
  1524. </if>
  1525. <if test="periodId != null and periodId != ''">
  1526. AND l.period_id = #{periodId}
  1527. </if>
  1528. <if test="videoId != null and videoId != ''">
  1529. AND l.video_id = #{videoId}
  1530. </if>
  1531. <if test="startTime != null and startTime !='' ">
  1532. and l.create_time &gt;= #{startTime}
  1533. </if>
  1534. <if test="endTime != null and endTime != ''">
  1535. and l.create_time &lt;= #{endTime}
  1536. </if>
  1537. -- 单独通过销售id查询
  1538. <if test="companyUserId != null and companyUserId != ''">
  1539. AND l.company_user_id = #{companyUserId}
  1540. </if>
  1541. ) as courseCompleteNum
  1542. </select>
  1543. <select id="countCourseDetailsNew" resultType="Map">
  1544. SELECT
  1545. count( DISTINCT l.period_id ) as courseNum,
  1546. count( DISTINCT l.video_id ) as videoNum,
  1547. count( DISTINCT l.user_id ) as courseUserNum
  1548. FROM
  1549. fs_course_watch_log l
  1550. left join fs_user on fs_user.user_id = l.user_id
  1551. LEFT JOIN company_user ON l.company_user_id = company_user.user_id
  1552. WHERE
  1553. l.log_type != 3
  1554. AND send_type = 1
  1555. <if test="userId != null and userId != 0 ">
  1556. AND l.company_user_id = #{userId}
  1557. </if>
  1558. <if test="userId != null and userId == 0 ">
  1559. and l.company_id = #{companyId}
  1560. </if>
  1561. <if test="periodId != null and periodId != ''">
  1562. AND l.period_id = #{periodId}
  1563. </if>
  1564. <if test="videoId != null and videoId != ''">
  1565. AND l.video_id = #{videoId}
  1566. </if>
  1567. -- 单独通过销售id查询
  1568. <if test="companyUserId != null and companyUserId != ''">
  1569. AND l.company_user_id = #{companyUserId}
  1570. </if>
  1571. </select>
  1572. <select id="selectFsUserVOListByProject" resultType="com.fs.his.vo.FsUserVO">
  1573. SELECT distinct
  1574. b.total_amount,b.last_buy_time,p.pay_money as number,p.payment_id,p.pay_time,
  1575. u.*,
  1576. fcc.watch_course_count, fcc.part_course_count, company_user.nick_name AS companyUserNickName, fcc.last_watch_date
  1577. ,company.company_name,
  1578. ucu.project_id,
  1579. ucu.id as companyUserId
  1580. FROM
  1581. fs_user u
  1582. LEFT JOIN (
  1583. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  1584. user_id
  1585. FROM
  1586. fs_store_payment
  1587. WHERE
  1588. STATUS = 1
  1589. AND user_id IS NOT NULL
  1590. GROUP BY
  1591. user_id
  1592. ) b ON u.user_id = b.user_id
  1593. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  1594. AND b.last_buy_time = p.pay_time
  1595. AND b.payment_id = p.payment_id
  1596. LEFT JOIN (
  1597. SELECT
  1598. 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,
  1599. fs_user_course_count.part_course_count
  1600. FROM
  1601. fs_user_course_count
  1602. GROUP BY fs_user_course_count.user_id
  1603. ) fcc ON fcc.user_id = u.user_id
  1604. left join fs_user_company_user ucu on ucu.user_id = u.user_id
  1605. LEFT JOIN company_user ON company_user.user_id = ucu.company_user_id
  1606. LEFT JOIN company on company.company_id = company_user.company_id
  1607. <where>
  1608. 1 = 1 and u.nickname is not null
  1609. <if test = "maps.nickname != null and maps.nickname !='' " >
  1610. AND u.nickname LIKE CONCAT("%",#{maps.nickname},"%")
  1611. </if >
  1612. <if test = "maps.userId != null and maps.userId !='' " >
  1613. AND u.user_id = #{maps.userId}
  1614. </if >
  1615. <if test = "maps.phone != null and maps.phone !='' " >
  1616. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  1617. </if >
  1618. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  1619. AND (DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  1620. and DATE_FORMAT( u.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  1621. )
  1622. </if >
  1623. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  1624. AND u.register_code = #{maps.registerCode}
  1625. </if >
  1626. <if test = "maps.status != null" >
  1627. AND u.STATUS = #{maps.status}
  1628. </if >
  1629. <if test = "maps.companyId != null and maps.companyId != '' " >
  1630. AND company.company_id = #{maps.companyId}
  1631. </if >
  1632. <if test = "maps.projectId != null" >
  1633. AND ucu.project_id = #{maps.projectId}
  1634. </if >
  1635. </where>
  1636. ORDER BY
  1637. user_id DESC
  1638. </select>
  1639. <select id="selectCompanyAndDoctor" resultType="com.fs.watch.domain.vo.FsUserAndCompanyAndDoctorVo">
  1640. SELECT
  1641. f.*,
  1642. GROUP_CONCAT(c.company_id SEPARATOR ',') AS company_id,
  1643. GROUP_CONCAT(c.company_user_id SEPARATOR ',') AS company_user_id,
  1644. GROUP_CONCAT(o.doctor_id SEPARATOR ',') AS doctor_id
  1645. FROM
  1646. fs_user f
  1647. LEFT JOIN
  1648. company_user_user c ON c.user_id = f.user_id
  1649. LEFT JOIN
  1650. fs_inquiry_order o ON o.user_id = f.user_id AND o.`status` = 4
  1651. WHERE
  1652. f.is_del = 0 AND f.user_id = #{userId}
  1653. GROUP BY
  1654. f.user_id;
  1655. </select>
  1656. <select id="selectUserNameByIds" resultMap="FsUserResult">
  1657. select user_id,nick_name from fs_user where user_id in
  1658. <foreach collection="userIds.split(',')" item="userId" open="(" close=")" separator=",">
  1659. #{userId}
  1660. </foreach>
  1661. </select>
  1662. <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
  1663. SELECT
  1664. count( fs_user.user_id ) as userNum,
  1665. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  1666. fs_user.company_id
  1667. FROM
  1668. fs_user
  1669. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1670. WHERE
  1671. fs_user.is_del = 0
  1672. AND fs_user.`status` = 1
  1673. AND company_user.user_id is not null
  1674. GROUP BY
  1675. fs_user.company_id
  1676. </select>
  1677. <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
  1678. SELECT
  1679. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  1680. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  1681. ifnull(
  1682. ROUND(
  1683. (
  1684. 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,
  1685. 2
  1686. ),
  1687. 0
  1688. ) AS completeWatchRate,
  1689. fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
  1690. FROM
  1691. fs_course_watch_log fwl
  1692. WHERE
  1693. fwl.send_type = 1
  1694. GROUP BY
  1695. fwl.period_id, fwl.video_id, fwl.company_user_id
  1696. </select>
  1697. <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
  1698. SELECT
  1699. count( flog.log_id ) AS redPacketNum,
  1700. ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
  1701. flog.period_id,
  1702. flog.video_id,
  1703. flog.company_user_id,
  1704. flog.company_id
  1705. FROM
  1706. fs_course_red_packet_log flog
  1707. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1708. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1709. GROUP BY
  1710. flog.period_id,
  1711. flog.video_id,
  1712. flog.company_user_id
  1713. </select>
  1714. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  1715. SELECT
  1716. count( DISTINCT fs_user.user_id ) AS answerNum,
  1717. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) AS answerRightNum,
  1718. ifnull(
  1719. ROUND(
  1720. (
  1721. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  1722. 2
  1723. ),
  1724. 0
  1725. ) AS answerRightRate,
  1726. fs_course_answer_logs.period_id,
  1727. fs_course_answer_logs.video_id,
  1728. fs_course_answer_logs.company_user_id,
  1729. fs_course_answer_logs.company_id
  1730. FROM
  1731. fs_course_answer_logs
  1732. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1733. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1734. GROUP BY
  1735. fs_course_answer_logs.period_id,
  1736. fs_course_answer_logs.video_id,
  1737. fs_course_answer_logs.company_user_id
  1738. </select>
  1739. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  1740. SELECT
  1741. count( fs_user.user_id ) as userNum,
  1742. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  1743. date(fs_user.create_time) as userCreateDate
  1744. ,company.company_id,
  1745. company.company_name,
  1746. company_user.user_id AS companyUserId,
  1747. company_user.nick_name AS companyUserName
  1748. FROM
  1749. fs_user
  1750. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1751. LEFT JOIN company ON company.company_id = fs_user.company_id
  1752. WHERE
  1753. fs_user.is_del = 0
  1754. AND fs_user.`status` = 1
  1755. AND company_user.user_id is not null
  1756. GROUP BY
  1757. fs_user.company_user_id, date(fs_user.create_time)
  1758. </select>
  1759. <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
  1760. <include refid="selectFsUserVo"/>
  1761. <where>
  1762. <if test="userName != null and userName != ''">
  1763. AND (
  1764. nickname like concat('%', #{userName}, '%')
  1765. or user_id LIKE concat('%',#{userName},'%')
  1766. )
  1767. </if>
  1768. </where>
  1769. order by user_id desc
  1770. </select>
  1771. <select id="selectFsUserCount" resultType="java.lang.Long">
  1772. select count(1) from fs_user
  1773. where 1=1
  1774. <if test = "type != null and type ==1">
  1775. and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
  1776. </if>
  1777. <if test = "companyId != null">
  1778. and company_id=#{companyId}
  1779. </if>
  1780. <if test="companyUserId != null">
  1781. and company_user_id = #{companyUserId}
  1782. </if>
  1783. </select>
  1784. </mapper>