FsUserMapper.xml 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844
  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. 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.nickname is not null
  1611. <if test = "maps.nickname != null and maps.nickname !='' " >
  1612. AND u.nickname 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. GROUP BY
  1712. flog.period_id,
  1713. flog.video_id,
  1714. flog.company_user_id
  1715. </select>
  1716. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  1717. SELECT
  1718. count( DISTINCT fs_user.user_id ) AS answerNum,
  1719. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) AS answerRightNum,
  1720. ifnull(
  1721. ROUND(
  1722. (
  1723. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  1724. 2
  1725. ),
  1726. 0
  1727. ) AS answerRightRate,
  1728. fs_course_answer_logs.period_id,
  1729. fs_course_answer_logs.video_id,
  1730. fs_course_answer_logs.company_user_id,
  1731. fs_course_answer_logs.company_id
  1732. FROM
  1733. fs_course_answer_logs
  1734. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1735. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1736. GROUP BY
  1737. fs_course_answer_logs.period_id,
  1738. fs_course_answer_logs.video_id,
  1739. fs_course_answer_logs.company_user_id
  1740. </select>
  1741. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  1742. SELECT
  1743. count( fs_user.user_id ) as userNum,
  1744. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  1745. date(fs_user.create_time) as userCreateDate
  1746. ,company.company_id,
  1747. company.company_name,
  1748. company_user.user_id AS companyUserId,
  1749. company_user.nick_name AS companyUserName
  1750. FROM
  1751. fs_user
  1752. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1753. LEFT JOIN company ON company.company_id = fs_user.company_id
  1754. WHERE
  1755. fs_user.is_del = 0
  1756. AND fs_user.`status` = 1
  1757. AND company_user.user_id is not null
  1758. GROUP BY
  1759. fs_user.company_user_id, date(fs_user.create_time)
  1760. </select>
  1761. <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
  1762. <include refid="selectFsUserVo"/>
  1763. <where>
  1764. <if test="userName != null and userName != ''">
  1765. AND (
  1766. nickname like concat('%', #{userName}, '%')
  1767. or user_id LIKE concat('%',#{userName},'%')
  1768. )
  1769. </if>
  1770. </where>
  1771. order by user_id desc
  1772. </select>
  1773. <select id="selectFsUserCount" resultType="java.lang.Long">
  1774. select count(1) from fs_user
  1775. where 1=1
  1776. <if test = "type != null and type ==1">
  1777. and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
  1778. </if>
  1779. <if test = "companyId != null">
  1780. and company_id=#{companyId}
  1781. </if>
  1782. <if test="companyUserId != null">
  1783. and company_user_id = #{companyUserId}
  1784. </if>
  1785. </select>
  1786. </mapper>