FsUserMapper.xml 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  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="nickName != null and nickName != ''"> and nick_name like concat( #{nickName}, '%')</if>
  58. <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
  59. <if test="phone != null and phone != ''"> and phone = #{phone}</if>
  60. <if test="integral != null "> and integral = #{integral}</if>
  61. <if test="signNum != null "> and sign_num = #{signNum}</if>
  62. <if test="status != null "> and status = #{status}</if>
  63. <if test="tuiUserId != null and tuiUserId != ''"> and tui_user_id = #{tuiUserId}</if>
  64. <if test="tuiTime != null "> and tui_time = #{tuiTime}</if>
  65. <if test="tuiUserCount != null "> and tui_user_count = #{tuiUserCount}</if>
  66. <if test="maOpenId != null and maOpenId != ''"> and ma_open_id = #{maOpenId}</if>
  67. <if test="mpOpenId != null and mpOpenId != ''"> and mp_open_id = #{mpOpenId}</if>
  68. <if test="unionId != null and unionId != ''"> and union_id = #{unionId}</if>
  69. <if test="isDel != null "> and is_del = #{isDel}</if>
  70. <if test="userCode != null and userCode != ''"> and user_code = #{userCode}</if>
  71. <if test="lastIp != null and lastIp != ''"> and last_ip = #{lastIp}</if>
  72. <if test="balance != null "> and balance = #{balance}</if>
  73. </where>
  74. </select>
  75. <select id="selectFsUserByUserId" parameterType="Long" resultMap="FsUserResult">
  76. <include refid="selectFsUserVo"/>
  77. where user_id = #{userId}
  78. </select>
  79. <select id="courseAnalysisWatchLog" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  80. SELECT
  81. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS courseWatchNum,
  82. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTimes,
  83. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS courseCompleteNum,
  84. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTimes,
  85. ifnull(
  86. ROUND(
  87. (
  88. 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,
  89. 2
  90. ),
  91. 0
  92. ) AS completeRate,
  93. fwl.video_id
  94. FROM
  95. fs_course_watch_log fwl
  96. <where>
  97. <if test="periodId != null and periodId != ''">
  98. AND fwl.period_id = #{periodId}
  99. </if>
  100. <if test="videoId != null and videoId != ''">
  101. AND fwl.video_id = #{videoId}
  102. </if>
  103. <if test="videoIdList != null and videoIdList.size > 0 ">
  104. AND fwl.video_id in
  105. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  106. #{videoId}
  107. </foreach>
  108. </if>
  109. </where>
  110. GROUP BY
  111. fwl.video_id
  112. </select>
  113. <select id="courseAnalysisRedPacketCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  114. SELECT
  115. count( flog.log_id ) as redPacketNum,
  116. ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
  117. flog.video_id
  118. FROM
  119. fs_course_red_packet_log flog
  120. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  121. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  122. <where>
  123. <if test="companyUserId != null and companyUserId != 0 ">
  124. AND fs_user.company_user_id = #{companyUserId}
  125. </if>
  126. <if test="companyUserId != null and companyUserId == 0 ">
  127. and fs_user.company_id = #{companyId}
  128. </if>
  129. <if test="periodId != null and periodId != ''">
  130. AND flog.period_id = #{periodId}
  131. </if>
  132. <if test="videoId != null and videoId != ''">
  133. AND flog.video_id = #{videoId}
  134. </if>
  135. <if test="videoIdList != null and videoIdList.size > 0 ">
  136. AND flog.video_id in
  137. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  138. #{videoId}
  139. </foreach>
  140. </if>
  141. </where>
  142. GROUP BY
  143. flog.video_id
  144. </select>
  145. <select id="courseAnalysisAnswerCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  146. SELECT
  147. count( DISTINCT fs_user.user_id ) as answerNum,
  148. count(fs_course_answer_logs.log_id) answerTimes,
  149. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
  150. COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) as answerRightTimes,
  151. ifnull(
  152. ROUND(
  153. (
  154. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  155. 2
  156. ),
  157. 0
  158. ) as answerRightRate,
  159. fs_course_answer_logs.video_id
  160. FROM
  161. fs_course_answer_logs
  162. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  163. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  164. <where>
  165. <if test="companyUserId != null and companyUserId != 0 ">
  166. AND fs_user.company_user_id = #{companyUserId}
  167. </if>
  168. <if test="companyUserId != null and companyUserId == 0 ">
  169. and fs_user.company_id = #{companyId}
  170. </if>
  171. <if test="periodId != null and periodId != ''">
  172. AND fs_course_answer_logs.period_id = #{periodId}
  173. </if>
  174. <if test="videoId != null and videoId != ''">
  175. AND fs_course_answer_logs.video_id = #{videoId}
  176. </if>
  177. <if test="videoIdList != null and videoIdList.size > 0 ">
  178. AND fs_course_answer_logs.video_id in
  179. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  180. #{videoId}
  181. </foreach>
  182. </if>
  183. </where>
  184. GROUP BY
  185. fs_course_answer_logs.video_id
  186. </select>
  187. <select id="selectFsUserById" parameterType="Long" resultMap="FsUserResult">
  188. <include refid="selectFsUserVo"/>
  189. where user_id = #{userId}
  190. </select>
  191. <select id="selectFsUserPageList" resultType="com.fs.store.vo.h5.FsUserPageListVO">
  192. SELECT
  193. fs_user.*,
  194. fs_user_course_count.id,
  195. fs_user_course_count.watch_course_count,
  196. fs_user_course_count.miss_course_count,
  197. fs_user_course_count.miss_course_status,
  198. fs_user_course_count.course_ids,
  199. fs_user_course_count.part_course_count,
  200. fs_user_course_count.last_watch_date,
  201. fs_user_course_count.STATUS AS courseCountStatus,
  202. fs_user_course_count.stop_watch_days,
  203. fs_user_course_count.complete_watch_date,
  204. GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
  205. GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
  206. company_user.nick_name as companyUserNickName,
  207. fs_user_company_user.is_repeat_fans
  208. FROM
  209. fs_user
  210. LEFT JOIN fs_user_course_count ON fs_user.user_id = fs_user_course_count.user_id
  211. LEFT JOIN company_tag_user ON fs_user.user_id = company_tag_user.user_id
  212. LEFT JOIN company_tag ON FIND_IN_SET(company_tag.tag_id, company_tag_user.tag_ids) > 0
  213. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  214. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  215. where fs_user.is_del = 0
  216. <if test="userId != null and userId!= 0 ">
  217. and fs_user.company_user_id = #{userId}
  218. </if>
  219. <if test="companyId != null ">
  220. and fs_user.company_id = #{companyId}
  221. </if>
  222. <if test="companyUserId != null and companyUserId!= '' ">
  223. and fs_user.company_user_id = #{companyUserId}
  224. </if>
  225. <choose>
  226. <when test = "isBlack">
  227. AND (fs_user.status = 0 or fs_user_company_user.is_repeat_fans = 1)
  228. </when>
  229. <otherwise>
  230. AND (fs_user.status = 1 and fs_user_company_user.is_repeat_fans = 0)
  231. </otherwise>
  232. </choose>
  233. <if test="keyword != null and keyword !='' ">
  234. AND (fs_user.nick_name LIKE concat('%',#{keyword},'%')
  235. or fs_user.phone LIKE concat('%',#{keyword},'%')
  236. )
  237. </if>
  238. <if test="registerStartTime != null and registerStartTime !='' ">
  239. AND fs_user.create_time &gt;= #{registerStartTime}
  240. </if>
  241. <if test="registerEndTime != null and registerEndTime !='' ">
  242. AND fs_user.create_time &lt;= #{registerEndTime}
  243. </if>
  244. <if test="tagIds != null and tagIds.length > 0">
  245. AND
  246. <foreach collection="tagIds" item="item" index="index" open="(" separator="or" close=")">
  247. CONCAT(',', company_tag_user.tag_ids, ',') LIKE CONCAT('%,', #{item}, ',%')
  248. </foreach>
  249. </if>
  250. <if test="tabValue != null and tabValue !='' ">
  251. <choose>
  252. <when test = "tabValue == 1">
  253. AND DAY(fs_user.create_time) = DAY(NOW())
  254. </when>
  255. <when test = "tabValue == 2">
  256. AND DAY(fs_user_course_count.complete_watch_date) = DAY(NOW())
  257. </when>
  258. <when test = "tabValue == 3">
  259. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  260. </when>
  261. </choose>
  262. </if>
  263. <if test="watchCourseType != null and watchCourseType !='' ">
  264. <choose>
  265. <when test = "watchCourseType == 1">
  266. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  267. </when>
  268. <when test = "watchCourseType == 2">
  269. AND fs_user_course_count.status = 1
  270. </when>
  271. <when test = "watchCourseType == 3">
  272. AND fs_user_course_count.status = 2
  273. </when>
  274. </choose>
  275. </if>
  276. <if test="missCourseStatus != null and missCourseStatus !='' ">
  277. <choose>
  278. <when test = "missCourseStatus == 1">
  279. AND fs_user_course_count.miss_course_status = 1
  280. </when>
  281. <when test = "missCourseStatus == 2">
  282. AND (fs_user_course_count.miss_course_status = 2 or fs_user_course_count.miss_course_status is null )
  283. </when>
  284. </choose>
  285. </if>
  286. group by fs_user.user_id
  287. <if test="continueMissCourseSort != null and continueMissCourseSort !='' ">
  288. order by
  289. <choose>
  290. <when test = "continueMissCourseSort == 0">
  291. fs_user.create_time desc
  292. </when>
  293. <when test = "continueMissCourseSort == 1">
  294. fs_user.nick_name asc
  295. </when>
  296. </choose>
  297. </if>
  298. </select>
  299. <select id="selectFsUserPageListNew" resultType="com.fs.store.vo.h5.FsUserPageListVO">
  300. SELECT
  301. fs_user.user_id,
  302. fs_user.nick_name,
  303. fs_user.avatar,
  304. fs_user.phone,
  305. fs_user.status,
  306. fs_user.create_time,
  307. fs_user.remark,
  308. fs_user.company_user_id,
  309. fs_user.company_id
  310. FROM
  311. fs_user
  312. <where>
  313. fs_user.is_del = 0
  314. <if test="registerStartTime != null and registerStartTime !='' ">
  315. AND fs_user.create_time &gt;= #{registerStartTime}
  316. </if>
  317. <if test="registerEndTime != null and registerEndTime !='' ">
  318. AND fs_user.create_time &lt;= #{registerEndTime}
  319. </if>
  320. <if test="companyUserIds != null and companyUserIds.size > 0">
  321. AND fs_user.company_user_id in
  322. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  323. ${item}
  324. </foreach>
  325. </if>
  326. <if test="nickname != null and nickname != ''">
  327. AND fs_user.nick_name like concat(#{nickname},'%')
  328. </if>
  329. <if test="phone != null and phone != ''">
  330. AND fs_user.phone = #{phone}
  331. </if>
  332. <if test="companyId != null">
  333. AND fs_user.company_id = #{companyId}
  334. </if>
  335. </where>
  336. limit ${(pageNum-1)*pageSize},${pageSize}
  337. </select>
  338. <select id="selectFsUserPageListCount" resultType="java.lang.Long">
  339. SELECT
  340. count(1)
  341. FROM
  342. fs_user
  343. <where>
  344. fs_user.is_del = 0
  345. <if test="registerStartTime != null and registerStartTime !='' ">
  346. AND fs_user.create_time &gt;= #{registerStartTime}
  347. </if>
  348. <if test="registerEndTime != null and registerEndTime !='' ">
  349. AND fs_user.create_time &lt;= #{registerEndTime}
  350. </if>
  351. <if test="companyUserIds != null and companyUserIds.size > 0">
  352. AND fs_user.company_user_id in
  353. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  354. ${item}
  355. </foreach>
  356. </if>
  357. <if test="nickname != null and nickname!=''">
  358. AND fs_user.nick_name like concat(#{nickname},'%')
  359. </if>
  360. <if test="phone != null and phone!=''">
  361. AND fs_user.phone = #{phone}
  362. </if>
  363. <if test="companyId != null">
  364. AND fs_user.company_id = #{companyId}
  365. </if>
  366. </where>
  367. </select>
  368. <update id="transferCompanyUser">
  369. update fs_user
  370. set company_user_id=#{targetCompanyUserId}
  371. where
  372. user_id in
  373. <foreach collection="userIds" open="(" close=")" separator="," item="item">
  374. ${item}
  375. </foreach>
  376. </update>
  377. <update id="batchUpdateFsUserByIds" parameterType="Long">
  378. update fs_user
  379. set status = #{status} where user_id in
  380. <foreach item="id" collection="ids" open="(" separator="," close=")">
  381. #{id}
  382. </foreach>
  383. </update>
  384. <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
  385. insert into fs_user
  386. <trim prefix="(" suffix=")" suffixOverrides=",">
  387. <if test="nickName != null">nick_name,</if>
  388. <if test="avatar != null">avatar,</if>
  389. <if test="phone != null">phone,</if>
  390. <if test="integral != null">integral,</if>
  391. <if test="signNum != null">sign_num,</if>
  392. <if test="status != null">status,</if>
  393. <if test="tuiUserId != null">tui_user_id,</if>
  394. <if test="tuiTime != null">tui_time,</if>
  395. <if test="tuiUserCount != null">tui_user_count,</if>
  396. <if test="maOpenId != null">ma_open_id,</if>
  397. <if test="mpOpenId != null">mp_open_id,</if>
  398. <if test="unionId != null">union_id,</if>
  399. <if test="isDel != null">is_del,</if>
  400. <if test="userCode != null">user_code,</if>
  401. <if test="remark != null">remark,</if>
  402. <if test="createTime != null">create_time,</if>
  403. <if test="updateTime != null">update_time,</if>
  404. <if test="lastIp != null">last_ip,</if>
  405. <if test="balance != null">balance,</if>
  406. <if test="integralStatus != null">integral_status,</if>
  407. <if test="isBuy != null">is_buy,</if>
  408. <if test="password != null">password,</if>
  409. <if test="jpushId != null">jpush_id,</if>
  410. <if test="isVip != null">is_vip,</if>
  411. <if test="vipStartDate != null">vip_start_date,</if>
  412. <if test="vipEndDate != null">vip_end_date,</if>
  413. <if test="vipLevel != null">vip_level,</if>
  414. <if test="vipStatus != null">vip_status,</if>
  415. <if test="sex != null">sex,</if>
  416. <if test="storeOpenId != null">store_open_id,</if>
  417. <if test="isPush != null">is_push,</if>
  418. <if test="isIndividuationPush != null">is_individuation_push,</if>
  419. <if test="isWeixinAuth != null">is_weixin_auth,</if>
  420. <if test="loginDevice != null">login_device,</if>
  421. <if test="source != null">source,</if>
  422. <if test="isAddQw != null">is_add_qw,</if>
  423. <if test="courseMaOpenId != null">course_ma_open_id,</if>
  424. <if test="qwExtId != null">qw_ext_id,</if>
  425. <if test="companyId != null">company_id,</if>
  426. <if test="companyUserId != null">company_user_id,</if>
  427. </trim>
  428. <trim prefix="values (" suffix=")" suffixOverrides=",">
  429. <if test="nickName != null">#{nickName},</if>
  430. <if test="avatar != null">#{avatar},</if>
  431. <if test="phone != null">#{phone},</if>
  432. <if test="integral != null">#{integral},</if>
  433. <if test="signNum != null">#{signNum},</if>
  434. <if test="status != null">#{status},</if>
  435. <if test="tuiUserId != null">#{tuiUserId},</if>
  436. <if test="tuiTime != null">#{tuiTime},</if>
  437. <if test="tuiUserCount != null">#{tuiUserCount},</if>
  438. <if test="maOpenId != null">#{maOpenId},</if>
  439. <if test="mpOpenId != null">#{mpOpenId},</if>
  440. <if test="unionId != null">#{unionId},</if>
  441. <if test="isDel != null">#{isDel},</if>
  442. <if test="userCode != null">#{userCode},</if>
  443. <if test="remark != null">#{remark},</if>
  444. <if test="createTime != null">#{createTime},</if>
  445. <if test="updateTime != null">#{updateTime},</if>
  446. <if test="lastIp != null">#{lastIp},</if>
  447. <if test="balance != null">#{balance},</if>
  448. <if test="integralStatus != null">#{integralStatus},</if>
  449. <if test="isBuy != null">#{isBuy},</if>
  450. <if test="password != null">#{password},</if>
  451. <if test="jpushId != null">#{jpushId},</if>
  452. <if test="isVip != null">#{isVip},</if>
  453. <if test="vipStartDate != null">#{vipStartDate},</if>
  454. <if test="vipEndDate != null">#{vipEndDate},</if>
  455. <if test="vipLevel != null">#{vipLevel},</if>
  456. <if test="vipStatus != null">#{vipStatus},</if>
  457. <if test="sex != null">#{sex},</if>
  458. <if test="storeOpenId != null">#{storeOpenId},</if>
  459. <if test="isPush != null">#{isPush},</if>
  460. <if test="isIndividuationPush != null">#{isIndividuationPush},</if>
  461. <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
  462. <if test="loginDevice != null">#{loginDevice},</if>
  463. <if test="source != null">#{source},</if>
  464. <if test="isAddQw != null">#{isAddQw},</if>
  465. <if test="courseMaOpenId != null">#{courseMaOpenId},</if>
  466. <if test="qwExtId != null">#{qwExtId},</if>
  467. <if test="companyId != null">#{companyId},</if>
  468. <if test="companyUserId != null">#{companyUserId},</if>
  469. </trim>
  470. </insert>
  471. <update id="updateFsUser" parameterType="FsUser">
  472. update fs_user
  473. <trim prefix="SET" suffixOverrides=",">
  474. <if test="nickName != null">nick_name = #{nickName},</if>
  475. <if test="avatar != null">avatar = #{avatar},</if>
  476. <if test="phone != null">phone = #{phone},</if>
  477. <if test="integral != null">integral = #{integral},</if>
  478. <if test="signNum != null">sign_num = #{signNum},</if>
  479. <if test="status != null">status = #{status},</if>
  480. <if test="tuiUserId != null">tui_user_id = #{tuiUserId},</if>
  481. <if test="tuiTime != null">tui_time = #{tuiTime},</if>
  482. <if test="tuiUserCount != null">tui_user_count = #{tuiUserCount},</if>
  483. <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
  484. <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
  485. <if test="unionId != null">union_id = #{unionId},</if>
  486. <if test="isDel != null">is_del = #{isDel},</if>
  487. <if test="userCode != null">user_code = #{userCode},</if>
  488. <if test="remark != null">remark = #{remark},</if>
  489. <if test="createTime != null">create_time = #{createTime},</if>
  490. <if test="updateTime != null">update_time = #{updateTime},</if>
  491. <if test="lastIp != null">last_ip = #{lastIp},</if>
  492. <if test="balance != null">balance = #{balance},</if>
  493. <if test="integralStatus != null">integral_status = #{integralStatus},</if>
  494. <if test="isBuy != null">is_buy = #{isBuy},</if>
  495. <if test="password != null">password = #{password},</if>
  496. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  497. <if test="isVip != null">is_vip = #{isVip},</if>
  498. <if test="vipStartDate != null">vip_start_date = #{vipStartDate},</if>
  499. <if test="vipEndDate != null">vip_end_date = #{vipEndDate},</if>
  500. <if test="vipLevel != null">vip_level = #{vipLevel},</if>
  501. <if test="vipStatus != null">vip_status = #{vipStatus},</if>
  502. <if test="sex != null">sex = #{sex},</if>
  503. <if test="storeOpenId != null">store_open_id = #{storeOpenId},</if>
  504. <if test="isPush != null">is_push = #{isPush},</if>
  505. <if test="isIndividuationPush != null">is_individuation_push = #{isIndividuationPush},</if>
  506. <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
  507. <if test="loginDevice != null">login_device = #{loginDevice},</if>
  508. <if test="source != null">source = #{source},</if>
  509. <if test="isAddQw != null">is_add_qw = #{isAddQw},</if>
  510. <if test="courseMaOpenId != null">course_ma_open_id = #{courseMaOpenId},</if>
  511. <if test="parentId != null">parent_id = #{parentId},</if>
  512. <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
  513. <if test="companyId != null">company_id = #{companyId},</if>
  514. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  515. </trim>
  516. where user_id = #{userId}
  517. </update>
  518. <delete id="deleteFsUserByUserId" parameterType="Long">
  519. delete from fs_user where user_id = #{userId}
  520. </delete>
  521. <delete id="deleteFsUserByUserIds" parameterType="Long">
  522. delete from fs_user where user_id in
  523. <foreach item="userId" collection="array" open="(" separator="," close=")">
  524. #{userId}
  525. </foreach>
  526. </delete>
  527. <update id="batchUpdateUserCompanyUser">
  528. update fs_user
  529. set company_id = #{companyId},
  530. company_user_id = #{companyUserId}
  531. where
  532. <foreach collection="userIds" separator="or" item="userId" index="index">
  533. user_id = #{userId}
  534. </foreach>
  535. </update>
  536. <select id="selectUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  537. select
  538. u.user_id dictValue,
  539. u.nick_name dictLabel
  540. from fs_user u
  541. <where>
  542. <if test="params.nickName != null and params.nickName != ''">
  543. u.nick_name like concat('%', #{params.nickName}, '%')
  544. </if>
  545. </where>
  546. </select>
  547. <select id ="selectFsUserByUserIds" resultType="Integer">
  548. select count(1) from fs_user_company_user
  549. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  550. where is_repeat_fans = 1
  551. and (fs_user_company_user.company_user_id = #{companyUserId} OR company_user.parent_id = #{companyUserId})
  552. <if test="userIds != null and userIds.length > 0 ">
  553. and fs_user_company_user.user_id in
  554. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  555. #{userId}
  556. </foreach>
  557. </if>
  558. </select>
  559. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  560. select
  561. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  562. count(u.user_id) vipCount
  563. from fs_user u
  564. where u.company_user_id = #{companyUserId}
  565. </select>
  566. <select id="getUserNumber" resultType="com.fs.store.vo.h5.UserListCountVO">
  567. SELECT
  568. fs_user.`status` as status,
  569. count( DISTINCT fs_user.user_id ) AS num
  570. FROM
  571. fs_user
  572. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  573. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  574. WHERE fs_user.is_del = 0
  575. <if test="userId != null and userId != 0 ">
  576. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  577. </if>
  578. <if test="companyId != null ">
  579. and fs_user.company_id = #{companyId}
  580. </if>
  581. GROUP BY
  582. fs_user.`status`
  583. </select>
  584. <select id="getRepeatUserNumber" resultType="int">
  585. SELECT
  586. count( DISTINCT fs_user.user_id ) AS num
  587. FROM
  588. fs_user
  589. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  590. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  591. WHERE
  592. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  593. AND fs_user.is_del = 0
  594. AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
  595. </select>
  596. <select id="getCountWatchCourse" resultType="com.fs.store.vo.h5.UserDetailsVO">
  597. SELECT
  598. <if test="dateTag == null or dateTag =='' or dateTag == '近七天' ">
  599. ifnull( sum(complete_watch_count), 0 ) AS completeWatchCount ,
  600. ifnull( sum(watch_times), 0 ) AS watchTimes,
  601. </if>
  602. <if test="dateTag != null and dateTag !='' and dateTag != '近七天' ">
  603. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  604. ifnull( watch_times, 0 ) AS watchTimes,
  605. </if>
  606. fs_user.user_id
  607. FROM
  608. fs_user_course_count
  609. LEFT JOIN fs_user ON fs_user.user_id = fs_user_course_count.user_id
  610. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  611. <where>
  612. <if test="dateTag != null and dateTag !='' ">
  613. <choose>
  614. <when test = "dateTag == '今天'">
  615. and to_days(fs_user_course_count.create_time) = to_days(now())
  616. </when>
  617. <when test = "dateTag == '昨天'">
  618. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_user_course_count.create_time &lt; CURDATE()
  619. </when>
  620. <when test = "dateTag == '前天'">
  621. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_user_course_count.create_time &lt; CURDATE() - INTERVAL 1 DAY
  622. </when>
  623. <when test = "dateTag == '近七天'">
  624. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  625. </when>
  626. </choose>
  627. </if>
  628. and fs_user.user_id = #{fsUserId}
  629. </where>
  630. GROUP BY
  631. fs_user.user_id
  632. </select>
  633. <select id="getCountAnswer" resultType="com.fs.store.vo.h5.UserDetailsVO">
  634. SELECT
  635. (
  636. SELECT
  637. ifnull(count( DISTINCT log_id ), 0) AS answerTime
  638. FROM
  639. fs_course_answer_logs
  640. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  641. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  642. <where>
  643. <if test="dateTag != null and dateTag !='' ">
  644. <choose>
  645. <when test = "dateTag == '今天'">
  646. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  647. </when>
  648. <when test = "dateTag == '昨天'">
  649. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  650. </when>
  651. <when test = "dateTag == '前天'">
  652. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  653. </when>
  654. <when test = "dateTag == '近七天'">
  655. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  656. </when>
  657. </choose>
  658. </if>
  659. and fs_user.user_id = #{fsUserId}
  660. </where>
  661. GROUP BY
  662. fs_user.user_id
  663. ) AS answerTime,
  664. (
  665. SELECT
  666. ifnull(count( DISTINCT log_id ), 0) AS answerRightTime
  667. FROM
  668. fs_course_answer_logs
  669. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  670. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  671. <where>
  672. fs_course_answer_logs.is_right = 1
  673. <if test="dateTag != null and dateTag !='' ">
  674. <choose>
  675. <when test = "dateTag == '今天'">
  676. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  677. </when>
  678. <when test = "dateTag == '昨天'">
  679. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  680. </when>
  681. <when test = "dateTag == '前天'">
  682. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  683. </when>
  684. <when test = "dateTag == '近七天'">
  685. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  686. </when>
  687. </choose>
  688. </if>
  689. and fs_user.user_id = #{fsUserId}
  690. </where>
  691. GROUP BY
  692. fs_user.user_id
  693. ) AS answerRightTime;
  694. </select>
  695. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  696. SELECT
  697. ifnull( count( DISTINCT log_id ), 0 ) AS answerRedPacketTime,
  698. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  699. fs_user.user_id
  700. FROM
  701. fs_course_red_packet_log
  702. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  703. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  704. <where>
  705. fs_course_red_packet_log.status = 1
  706. <if test="dateTag != null and dateTag !='' ">
  707. <choose>
  708. <when test = "dateTag == '今天'">
  709. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  710. </when>
  711. <when test = "dateTag == '昨天'">
  712. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE()
  713. </when>
  714. <when test = "dateTag == '前天'">
  715. 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
  716. </when>
  717. <when test = "dateTag == '近七天'">
  718. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  719. </when>
  720. </choose>
  721. </if>
  722. and fs_user.user_id = #{fsUserId}
  723. </where>
  724. GROUP BY
  725. fs_user.user_id
  726. </select>
  727. <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
  728. SELECT (SELECT count(fs_user.user_id)
  729. FROM fs_user
  730. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  731. WHERE fs_user.is_del = 0
  732. <if test="userId != null and userId != 0 ">
  733. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  734. </if>
  735. <if test="companyId != null ">
  736. and fs_user.company_id = #{companyId}
  737. </if>
  738. ) as userTotal,
  739. (SELECT count(fs_user.user_id)
  740. FROM fs_user
  741. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  742. WHERE fs_user.is_del = 0
  743. <if test="userId != null and userId != 0 ">
  744. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  745. </if>
  746. <if test="companyId != null ">
  747. and fs_user.company_id = #{companyId}
  748. </if>
  749. AND to_days(fs_user.create_time) = to_days(now())) as todayNewUser
  750. </select>
  751. <select id="countTag" resultType="com.fs.store.vo.h5.FsUserSummaryCountTagVO">
  752. SELECT
  753. company_tag.tag AS tagName,
  754. count( fs_user.user_id ) AS number
  755. FROM
  756. company_tag_user
  757. LEFT JOIN fs_user ON fs_user.user_id = company_tag_user.user_id
  758. LEFT JOIN company_tag ON FIND_IN_SET( company_tag.tag_id, company_tag_user.tag_ids ) > 0
  759. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  760. <where>
  761. <if test="userId != null and userId != 0 ">
  762. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  763. </if>
  764. <if test="companyId != null ">
  765. and fs_user.company_id = #{companyId}
  766. </if>
  767. and company_tag.tag_id is not null
  768. </where>
  769. GROUP BY
  770. company_tag.tag_id
  771. </select>
  772. <select id="countUserCourse" resultType="Map">
  773. SELECT
  774. (
  775. SELECT
  776. count(distinct fcc.user_id )
  777. FROM
  778. fs_user_course_count fcc
  779. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  780. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  781. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  782. <where>
  783. <if test="userId != null and userId != 0 ">
  784. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  785. </if>
  786. <if test="userId != null and userId == 0 ">
  787. and fs_user.company_id = #{companyId}
  788. </if>
  789. <if test="startTime != null and startTime !='' ">
  790. and fcc.create_time &gt;= #{startTime}
  791. </if>
  792. <if test="endTime != null and endTime != ''">
  793. and fcc.create_time &lt;= #{endTime}
  794. </if>
  795. <if test="periodId != null and periodId != ''">
  796. AND fcpd.period_id = #{periodId}
  797. </if>
  798. <if test="videoId != null and videoId != ''">
  799. AND fcpd.video_id = #{videoId}
  800. </if>
  801. -- 单独通过销售id查询
  802. <if test="companyUserId != null and companyUserId != ''">
  803. AND company_user.user_id = #{companyUserId}
  804. </if>
  805. </where>
  806. ) as courseWatchNum,
  807. (
  808. SELECT
  809. count(distinct fcc.user_id )
  810. FROM
  811. fs_user_course_count fcc
  812. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  813. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  814. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  815. <where>
  816. <if test="userId != null and userId != 0 ">
  817. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  818. </if>
  819. <if test="userId != null and userId == 0 ">
  820. and fs_user.company_id = #{companyId}
  821. </if>
  822. AND fcc.complete_watch_count > 0
  823. <if test="startTime != null and startTime !='' ">
  824. and fcc.create_time &gt;= #{startTime}
  825. </if>
  826. <if test="endTime != null and endTime != ''">
  827. and fcc.create_time &lt;= #{endTime}
  828. </if>
  829. <if test="periodId != null and periodId != ''">
  830. AND fcpd.period_id = #{periodId}
  831. </if>
  832. <if test="videoId != null and videoId != ''">
  833. AND fcpd.video_id = #{videoId}
  834. </if>
  835. -- 单独通过销售id查询
  836. <if test="companyUserId != null and companyUserId != ''">
  837. AND company_user.user_id = #{companyUserId}
  838. </if>
  839. </where>
  840. ) as courseCompleteNum
  841. </select>
  842. <select id="countUserAnswer" resultType="Map">
  843. SELECT
  844. (
  845. SELECT
  846. count(distinct fs_user.user_id )
  847. FROM
  848. fs_course_answer_logs
  849. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  850. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  851. <where>
  852. <if test="userId != null and userId != 0 ">
  853. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  854. </if>
  855. <if test="userId != null and userId == 0 ">
  856. and fs_user.company_id = #{companyId}
  857. </if>
  858. <if test="startTime != null and startTime !='' ">
  859. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  860. </if>
  861. <if test="endTime != null and endTime != ''">
  862. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  863. </if>
  864. <if test="periodId != null and periodId != ''">
  865. AND fs_course_answer_logs.period_id = #{periodId}
  866. </if>
  867. <if test="videoId != null and videoId != ''">
  868. AND fs_course_answer_logs.video_id = #{videoId}
  869. </if>
  870. -- 单独通过销售id查询
  871. <if test="companyUserId != null and companyUserId != ''">
  872. AND company_user.user_id = #{companyUserId}
  873. </if>
  874. </where>
  875. ) AS answerNum,
  876. (
  877. SELECT
  878. count(distinct fs_user.user_id )
  879. FROM
  880. fs_course_answer_logs
  881. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  882. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  883. <where>
  884. <if test="userId != null and userId != 0 ">
  885. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  886. </if>
  887. <if test="userId != null and userId == 0 ">
  888. and fs_user.company_id = #{companyId}
  889. </if>
  890. AND fs_course_answer_logs.is_right = 1
  891. <if test="startTime != null and startTime !='' ">
  892. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  893. </if>
  894. <if test="endTime != null and endTime != ''">
  895. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  896. </if>
  897. <if test="periodId != null and periodId != ''">
  898. AND fs_course_answer_logs.period_id = #{periodId}
  899. </if>
  900. <if test="videoId != null and videoId != ''">
  901. AND fs_course_answer_logs.video_id = #{videoId}
  902. </if>
  903. -- 单独通过销售id查询
  904. <if test="companyUserId != null and companyUserId != ''">
  905. AND company_user.user_id = #{companyUserId}
  906. </if>
  907. </where>
  908. ) AS answerRightNum
  909. </select>
  910. <select id="countCourseDetails" resultType="Map">
  911. select (SELECT
  912. count( DISTINCT fcpd.period_id )
  913. FROM
  914. fs_user_course_period_days fcpd
  915. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  916. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  917. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  918. WHERE 1=1
  919. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  920. <if test="userId != null and userId != 0 ">
  921. AND fs_user.company_user_id = #{userId}
  922. </if>
  923. <if test="userId != null and userId == 0 ">
  924. and fs_user.company_id = #{companyId}
  925. </if>
  926. <if test="periodId != null and periodId != ''">
  927. AND fcpd.period_id = #{periodId}
  928. </if>
  929. -- 单独通过销售id查询
  930. <if test="companyUserId != null and companyUserId != ''">
  931. AND fs_user.company_user_id = #{companyUserId}
  932. </if>
  933. ) as courseNum,
  934. (SELECT count(DISTINCT fcpd.video_id)
  935. FROM fs_user_course_period_days fcpd
  936. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  937. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  938. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  939. WHERE 1=1
  940. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  941. <if test="userId != null and userId != 0 ">
  942. AND fs_user.company_user_id = #{userId}
  943. </if>
  944. <if test="userId != null and userId == 0 ">
  945. and fs_user.company_id = #{companyId}
  946. </if>
  947. <if test="periodId != null and periodId != ''">
  948. AND fcpd.period_id = #{periodId}
  949. </if>
  950. <if test="videoId != null and videoId != ''">
  951. AND fcpd.video_id = #{videoId}
  952. </if>
  953. -- 单独通过销售id查询
  954. <if test="companyUserId != null and companyUserId != ''">
  955. AND fs_user.company_user_id = #{companyUserId}
  956. </if>
  957. ) as videoNum,
  958. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  959. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  960. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  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 fs_user.company_user_id = #{companyUserId}
  970. </if>
  971. <where>
  972. <if test="userId != null and userId != 0 ">
  973. AND fs_user.company_user_id = #{userId}
  974. </if>
  975. <if test="userId != null and userId == 0 ">
  976. and fs_user.company_id = #{companyId}
  977. </if>
  978. </where>
  979. ) as courseUserNum
  980. </select>
  981. <select id="countUserRankingByComplete" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  982. SELECT
  983. company_user.nick_name as userName,
  984. ifnull(
  985. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  986. ) as completeRate
  987. FROM
  988. fs_user_course_count fcc
  989. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  990. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  991. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  992. <where>
  993. <if test="userId != null and userId != 0 ">
  994. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  995. </if>
  996. <if test="userId != null and userId == 0 ">
  997. and fs_user.company_id = #{companyId}
  998. </if>
  999. <if test="startTime != null and startTime !='' ">
  1000. AND fcc.create_time &gt;= #{startTime}
  1001. </if>
  1002. <if test="endTime != null and endTime != ''">
  1003. AND fcc.create_time &lt;= #{endTime}
  1004. </if>
  1005. <if test="periodId != null and periodId != ''">
  1006. AND fcpd.period_id = #{periodId}
  1007. </if>
  1008. <if test="videoId != null and videoId != ''">
  1009. AND fcpd.video_id = #{videoId}
  1010. </if>
  1011. </where>
  1012. group by fcc.user_id
  1013. <choose>
  1014. <when test="order != null and order == 'asc'">
  1015. order by completeRate asc
  1016. </when>
  1017. <when test="order != null and order == 'desc'">
  1018. order by completeRate desc
  1019. </when>
  1020. <otherwise>
  1021. order by completeRate desc
  1022. </otherwise>
  1023. </choose>
  1024. limit 20
  1025. </select>
  1026. <select id="countUserRankingByRight" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1027. SELECT
  1028. company_user.nick_name as userName,
  1029. ifnull(ROUND(
  1030. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1031. *100,2),0
  1032. ) as answerRightRate
  1033. FROM
  1034. fs_course_answer_logs
  1035. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1036. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1037. <where>
  1038. <if test="userId != null and userId != 0 ">
  1039. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1040. </if>
  1041. <if test="userId != null and userId == 0 ">
  1042. and fs_user.company_id = #{companyId}
  1043. </if>
  1044. <if test="startTime != null and startTime !='' ">
  1045. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1046. </if>
  1047. <if test="endTime != null and endTime != ''">
  1048. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1049. </if>
  1050. <if test="periodId != null and periodId != ''">
  1051. AND fs_course_answer_logs.period_id = #{periodId}
  1052. </if>
  1053. <if test="videoId != null and videoId != ''">
  1054. AND fs_course_answer_logs.video_id = #{videoId}
  1055. </if>
  1056. </where>
  1057. group by fs_user.user_id
  1058. <choose>
  1059. <when test="order != null and order == 'asc'">
  1060. order by answerRightRate asc
  1061. </when>
  1062. <when test="order != null and order == 'desc'">
  1063. order by answerRightRate desc
  1064. </when>
  1065. <otherwise>
  1066. order by answerRightRate desc
  1067. </otherwise>
  1068. </choose>
  1069. limit 20
  1070. </select>
  1071. <select id="countCourseRankingByComplete" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1072. SELECT
  1073. fcv.title AS videoName,
  1074. ifnull(
  1075. ROUND((
  1076. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))* 100,
  1077. 2
  1078. ),
  1079. 0
  1080. ) AS completeRate
  1081. FROM
  1082. fs_user_course_count fcc
  1083. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1084. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1085. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1086. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fcpd.video_id
  1087. <where>
  1088. <if test="userId != null and userId != 0 ">
  1089. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1090. </if>
  1091. <if test="userId != null and userId == 0 ">
  1092. and fs_user.company_id = #{companyId}
  1093. </if>
  1094. <if test="startTime != null and startTime !='' ">
  1095. AND fcc.create_time &gt;= #{startTime}
  1096. </if>
  1097. <if test="endTime != null and endTime != ''">
  1098. AND fcc.create_time &lt;= #{endTime}
  1099. </if>
  1100. <if test="periodId != null and periodId != ''">
  1101. AND fcpd.period_id = #{periodId}
  1102. </if>
  1103. <if test="videoId != null and videoId != ''">
  1104. AND fcpd.video_id = #{videoId}
  1105. </if>
  1106. </where>
  1107. GROUP BY
  1108. fcpd.video_id
  1109. <choose>
  1110. <when test="order != null and order == 'asc'">
  1111. ORDER BY completeRate asc
  1112. </when>
  1113. <when test="order != null and order == 'desc'">
  1114. ORDER BY completeRate desc
  1115. </when>
  1116. <otherwise>
  1117. ORDER BY completeRate desc
  1118. </otherwise>
  1119. </choose>
  1120. LIMIT 20
  1121. </select>
  1122. <select id="countCourseRankingByRight" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1123. SELECT
  1124. fcv.title AS videoName,
  1125. ifnull(
  1126. ROUND(
  1127. (
  1128. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1)) * 100,
  1129. 2
  1130. ),
  1131. 0
  1132. ) AS answerRightRate
  1133. FROM
  1134. fs_course_answer_logs
  1135. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1136. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1137. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1138. <where>
  1139. <if test="userId != null and userId != 0 ">
  1140. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1141. </if>
  1142. <if test="userId != null and userId == 0 ">
  1143. and fs_user.company_id = #{companyId}
  1144. </if>
  1145. <if test="startTime != null and startTime !='' ">
  1146. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1147. </if>
  1148. <if test="endTime != null and endTime != ''">
  1149. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1150. </if>
  1151. <if test="periodId != null and periodId != ''">
  1152. AND fs_course_answer_logs.period_id = #{periodId}
  1153. </if>
  1154. <if test="videoId != null and videoId != ''">
  1155. AND fs_course_answer_logs.video_id = #{videoId}
  1156. </if>
  1157. </where>
  1158. GROUP BY
  1159. fs_course_answer_logs.video_id
  1160. <choose>
  1161. <when test="order != null and order == 'asc'">
  1162. ORDER BY answerRightRate asc
  1163. </when>
  1164. <when test="order != null and order == 'desc'">
  1165. ORDER BY answerRightRate desc
  1166. </when>
  1167. <otherwise>
  1168. ORDER BY answerRightRate desc
  1169. </otherwise>
  1170. </choose>
  1171. LIMIT 20
  1172. </select>
  1173. <select id="countUserRedPacket" resultType="Map">
  1174. SELECT
  1175. (
  1176. SELECT
  1177. count( flog.log_id )
  1178. FROM
  1179. fs_course_red_packet_log flog
  1180. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1181. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1182. where flog.status = 1
  1183. <if test="userId != null and userId != 0 ">
  1184. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1185. </if>
  1186. <if test="userId != null and userId == 0 ">
  1187. and fs_user.company_id = #{companyId}
  1188. </if>
  1189. <if test="startTime != null and startTime !='' ">
  1190. AND flog.create_time &gt;= #{startTime}
  1191. </if>
  1192. <if test="endTime != null and endTime != ''">
  1193. AND flog.create_time &lt;= #{endTime}
  1194. </if>
  1195. <if test="periodId != null and periodId != ''">
  1196. AND flog.period_id = #{periodId}
  1197. </if>
  1198. <if test="videoId != null and videoId != ''">
  1199. AND flog.video_id = #{videoId}
  1200. </if>
  1201. -- 单独通过销售id查询
  1202. <if test="companyUserId != null and companyUserId != ''">
  1203. AND company_user.user_id = #{companyUserId}
  1204. </if>
  1205. ) AS redPacketNum,
  1206. (
  1207. SELECT
  1208. ifnull (sum( flog.amount ), 0)
  1209. FROM
  1210. fs_course_red_packet_log flog
  1211. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1212. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1213. where flog.status = 1
  1214. <if test="userId != null and userId != 0 ">
  1215. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1216. </if>
  1217. <if test="userId != null and userId == 0 ">
  1218. and fs_user.company_id = #{companyId}
  1219. </if>
  1220. <if test="startTime != null and startTime !='' ">
  1221. AND flog.create_time &gt;= #{startTime}
  1222. </if>
  1223. <if test="endTime != null and endTime != ''">
  1224. AND flog.create_time &lt;= #{endTime}
  1225. </if>
  1226. <if test="periodId != null and periodId != ''">
  1227. AND flog.period_id = #{periodId}
  1228. </if>
  1229. <if test="videoId != null and videoId != ''">
  1230. AND flog.video_id = #{videoId}
  1231. </if>
  1232. -- 单独通过销售id查询
  1233. <if test="companyUserId != null and companyUserId != ''">
  1234. AND company_user.user_id = #{companyUserId}
  1235. </if>
  1236. ) AS redPacketAmount
  1237. </select>
  1238. <select id="courseAnalysisCourseCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  1239. SELECT
  1240. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1241. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1242. ifnull(
  1243. ROUND(
  1244. (
  1245. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1246. 2
  1247. ),
  1248. 0
  1249. ) as completeRate,
  1250. fcpd.video_id
  1251. FROM
  1252. fs_user_course_count fcc
  1253. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1254. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1255. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1256. <where>
  1257. <if test="companyUserId != null and companyUserId != 0 ">
  1258. AND fs_user.company_user_id = #{companyUserId}
  1259. </if>
  1260. <if test="companyUserId != null and companyUserId == 0 ">
  1261. and fs_user.company_id = #{companyId}
  1262. </if>
  1263. <if test="periodId != null and periodId != ''">
  1264. AND fcpd.period_id = #{periodId}
  1265. </if>
  1266. <if test="videoId != null and videoId != ''">
  1267. AND fcpd.video_id = #{videoId}
  1268. </if>
  1269. </where>
  1270. GROUP BY
  1271. fcpd.video_id
  1272. </select>
  1273. <select id="companyUserCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1274. SELECT
  1275. (
  1276. SELECT count( fs_user.user_id ) FROM fs_user LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1277. <where>
  1278. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1279. AND fs_user.company_user_id = #{companyUserId}
  1280. </if>
  1281. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1282. and fs_user.company_id = #{companyId}
  1283. </if>
  1284. </where>
  1285. ) AS userTotal,
  1286. (
  1287. SELECT
  1288. count( fs_user.user_id )
  1289. FROM
  1290. fs_user
  1291. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1292. <where>
  1293. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1294. AND fs_user.company_user_id = #{companyUserId}
  1295. </if>
  1296. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1297. and fs_user.company_id = #{companyId}
  1298. </if>
  1299. and fs_user.is_del = 0
  1300. AND to_days( fs_user.create_time ) = to_days(
  1301. now())
  1302. </where>
  1303. ) AS todayNewUser
  1304. </select>
  1305. <select id="newUserRedPacketCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1306. SELECT
  1307. count(flog.log_id) as userRedPacketNum,
  1308. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1309. FROM
  1310. fs_course_red_packet_log flog
  1311. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1312. <where>
  1313. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1314. AND fs_user.company_user_id = #{companyUserId}
  1315. </if>
  1316. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1317. and fs_user.company_id = #{companyId}
  1318. </if>
  1319. </where>
  1320. </select>
  1321. </mapper>