FsUserMapper.xml 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  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. </where>
  333. limit ${(pageNum-1)*pageSize},${pageSize}
  334. </select>
  335. <select id="selectFsUserPageListCount" resultType="java.lang.Long">
  336. SELECT
  337. count(1)
  338. FROM
  339. fs_user
  340. <where>
  341. fs_user.is_del = 0
  342. <if test="registerStartTime != null and registerStartTime !='' ">
  343. AND fs_user.create_time &gt;= #{registerStartTime}
  344. </if>
  345. <if test="registerEndTime != null and registerEndTime !='' ">
  346. AND fs_user.create_time &lt;= #{registerEndTime}
  347. </if>
  348. <if test="companyUserIds != null and companyUserIds.size > 0">
  349. AND fs_user.company_user_id in
  350. <foreach collection="companyUserIds" item="item" index="index" open="(" separator="," close=")">
  351. ${item}
  352. </foreach>
  353. </if>
  354. <if test="nickname != null and nickname!=''">
  355. AND fs_user.nick_name like concat(#{nickname},'%')
  356. </if>
  357. <if test="phone != null and phone!=''">
  358. AND fs_user.phone = #{phone}
  359. </if>
  360. </where>
  361. </select>
  362. <update id="transferCompanyUser">
  363. update fs_user
  364. set company_user_id=#{targetCompanyUserId}
  365. where
  366. user_id in
  367. <foreach collection="userIds" open="(" close=")" separator="," item="item">
  368. ${item}
  369. </foreach>
  370. </update>
  371. <update id="batchUpdateFsUserByIds" parameterType="Long">
  372. update fs_user
  373. set status = #{status} where user_id in
  374. <foreach item="id" collection="ids" open="(" separator="," close=")">
  375. #{id}
  376. </foreach>
  377. </update>
  378. <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
  379. insert into fs_user
  380. <trim prefix="(" suffix=")" suffixOverrides=",">
  381. <if test="nickName != null">nick_name,</if>
  382. <if test="avatar != null">avatar,</if>
  383. <if test="phone != null">phone,</if>
  384. <if test="integral != null">integral,</if>
  385. <if test="signNum != null">sign_num,</if>
  386. <if test="status != null">status,</if>
  387. <if test="tuiUserId != null">tui_user_id,</if>
  388. <if test="tuiTime != null">tui_time,</if>
  389. <if test="tuiUserCount != null">tui_user_count,</if>
  390. <if test="maOpenId != null">ma_open_id,</if>
  391. <if test="mpOpenId != null">mp_open_id,</if>
  392. <if test="unionId != null">union_id,</if>
  393. <if test="isDel != null">is_del,</if>
  394. <if test="userCode != null">user_code,</if>
  395. <if test="remark != null">remark,</if>
  396. <if test="createTime != null">create_time,</if>
  397. <if test="updateTime != null">update_time,</if>
  398. <if test="lastIp != null">last_ip,</if>
  399. <if test="balance != null">balance,</if>
  400. <if test="integralStatus != null">integral_status,</if>
  401. <if test="isBuy != null">is_buy,</if>
  402. <if test="password != null">password,</if>
  403. <if test="jpushId != null">jpush_id,</if>
  404. <if test="isVip != null">is_vip,</if>
  405. <if test="vipStartDate != null">vip_start_date,</if>
  406. <if test="vipEndDate != null">vip_end_date,</if>
  407. <if test="vipLevel != null">vip_level,</if>
  408. <if test="vipStatus != null">vip_status,</if>
  409. <if test="sex != null">sex,</if>
  410. <if test="storeOpenId != null">store_open_id,</if>
  411. <if test="isPush != null">is_push,</if>
  412. <if test="isIndividuationPush != null">is_individuation_push,</if>
  413. <if test="isWeixinAuth != null">is_weixin_auth,</if>
  414. <if test="loginDevice != null">login_device,</if>
  415. <if test="source != null">source,</if>
  416. <if test="isAddQw != null">is_add_qw,</if>
  417. <if test="courseMaOpenId != null">course_ma_open_id,</if>
  418. <if test="qwExtId != null">qw_ext_id,</if>
  419. <if test="companyId != null">company_id,</if>
  420. <if test="companyUserId != null">company_user_id,</if>
  421. </trim>
  422. <trim prefix="values (" suffix=")" suffixOverrides=",">
  423. <if test="nickName != null">#{nickName},</if>
  424. <if test="avatar != null">#{avatar},</if>
  425. <if test="phone != null">#{phone},</if>
  426. <if test="integral != null">#{integral},</if>
  427. <if test="signNum != null">#{signNum},</if>
  428. <if test="status != null">#{status},</if>
  429. <if test="tuiUserId != null">#{tuiUserId},</if>
  430. <if test="tuiTime != null">#{tuiTime},</if>
  431. <if test="tuiUserCount != null">#{tuiUserCount},</if>
  432. <if test="maOpenId != null">#{maOpenId},</if>
  433. <if test="mpOpenId != null">#{mpOpenId},</if>
  434. <if test="unionId != null">#{unionId},</if>
  435. <if test="isDel != null">#{isDel},</if>
  436. <if test="userCode != null">#{userCode},</if>
  437. <if test="remark != null">#{remark},</if>
  438. <if test="createTime != null">#{createTime},</if>
  439. <if test="updateTime != null">#{updateTime},</if>
  440. <if test="lastIp != null">#{lastIp},</if>
  441. <if test="balance != null">#{balance},</if>
  442. <if test="integralStatus != null">#{integralStatus},</if>
  443. <if test="isBuy != null">#{isBuy},</if>
  444. <if test="password != null">#{password},</if>
  445. <if test="jpushId != null">#{jpushId},</if>
  446. <if test="isVip != null">#{isVip},</if>
  447. <if test="vipStartDate != null">#{vipStartDate},</if>
  448. <if test="vipEndDate != null">#{vipEndDate},</if>
  449. <if test="vipLevel != null">#{vipLevel},</if>
  450. <if test="vipStatus != null">#{vipStatus},</if>
  451. <if test="sex != null">#{sex},</if>
  452. <if test="storeOpenId != null">#{storeOpenId},</if>
  453. <if test="isPush != null">#{isPush},</if>
  454. <if test="isIndividuationPush != null">#{isIndividuationPush},</if>
  455. <if test="isWeixinAuth != null">#{isWeixinAuth},</if>
  456. <if test="loginDevice != null">#{loginDevice},</if>
  457. <if test="source != null">#{source},</if>
  458. <if test="isAddQw != null">#{isAddQw},</if>
  459. <if test="courseMaOpenId != null">#{courseMaOpenId},</if>
  460. <if test="qwExtId != null">#{qwExtId},</if>
  461. <if test="companyId != null">#{companyId},</if>
  462. <if test="companyUserId != null">#{companyUserId},</if>
  463. </trim>
  464. </insert>
  465. <update id="updateFsUser" parameterType="FsUser">
  466. update fs_user
  467. <trim prefix="SET" suffixOverrides=",">
  468. <if test="nickName != null">nick_name = #{nickName},</if>
  469. <if test="avatar != null">avatar = #{avatar},</if>
  470. <if test="phone != null">phone = #{phone},</if>
  471. <if test="integral != null">integral = #{integral},</if>
  472. <if test="signNum != null">sign_num = #{signNum},</if>
  473. <if test="status != null">status = #{status},</if>
  474. <if test="tuiUserId != null">tui_user_id = #{tuiUserId},</if>
  475. <if test="tuiTime != null">tui_time = #{tuiTime},</if>
  476. <if test="tuiUserCount != null">tui_user_count = #{tuiUserCount},</if>
  477. <if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
  478. <if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
  479. <if test="unionId != null">union_id = #{unionId},</if>
  480. <if test="isDel != null">is_del = #{isDel},</if>
  481. <if test="userCode != null">user_code = #{userCode},</if>
  482. <if test="remark != null">remark = #{remark},</if>
  483. <if test="createTime != null">create_time = #{createTime},</if>
  484. <if test="updateTime != null">update_time = #{updateTime},</if>
  485. <if test="lastIp != null">last_ip = #{lastIp},</if>
  486. <if test="balance != null">balance = #{balance},</if>
  487. <if test="integralStatus != null">integral_status = #{integralStatus},</if>
  488. <if test="isBuy != null">is_buy = #{isBuy},</if>
  489. <if test="password != null">password = #{password},</if>
  490. <if test="jpushId != null">jpush_id = #{jpushId},</if>
  491. <if test="isVip != null">is_vip = #{isVip},</if>
  492. <if test="vipStartDate != null">vip_start_date = #{vipStartDate},</if>
  493. <if test="vipEndDate != null">vip_end_date = #{vipEndDate},</if>
  494. <if test="vipLevel != null">vip_level = #{vipLevel},</if>
  495. <if test="vipStatus != null">vip_status = #{vipStatus},</if>
  496. <if test="sex != null">sex = #{sex},</if>
  497. <if test="storeOpenId != null">store_open_id = #{storeOpenId},</if>
  498. <if test="isPush != null">is_push = #{isPush},</if>
  499. <if test="isIndividuationPush != null">is_individuation_push = #{isIndividuationPush},</if>
  500. <if test="isWeixinAuth != null">is_weixin_auth = #{isWeixinAuth},</if>
  501. <if test="loginDevice != null">login_device = #{loginDevice},</if>
  502. <if test="source != null">source = #{source},</if>
  503. <if test="isAddQw != null">is_add_qw = #{isAddQw},</if>
  504. <if test="courseMaOpenId != null">course_ma_open_id = #{courseMaOpenId},</if>
  505. <if test="parentId != null">parent_id = #{parentId},</if>
  506. <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
  507. <if test="companyId != null">company_id = #{companyId},</if>
  508. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  509. </trim>
  510. where user_id = #{userId}
  511. </update>
  512. <delete id="deleteFsUserByUserId" parameterType="Long">
  513. delete from fs_user where user_id = #{userId}
  514. </delete>
  515. <delete id="deleteFsUserByUserIds" parameterType="Long">
  516. delete from fs_user where user_id in
  517. <foreach item="userId" collection="array" open="(" separator="," close=")">
  518. #{userId}
  519. </foreach>
  520. </delete>
  521. <update id="batchUpdateUserCompanyUser">
  522. update fs_user
  523. set company_id = #{companyId},
  524. company_user_id = #{companyUserId}
  525. where
  526. <foreach collection="userIds" separator="or" item="userId" index="index">
  527. user_id = #{userId}
  528. </foreach>
  529. </update>
  530. <select id="selectUserListByMap" resultType="com.fs.his.vo.OptionsVO">
  531. select
  532. u.user_id dictValue,
  533. u.nick_name dictLabel
  534. from fs_user u
  535. <where>
  536. <if test="params.nickName != null and params.nickName != ''">
  537. u.nick_name like concat('%', #{params.nickName}, '%')
  538. </if>
  539. </where>
  540. </select>
  541. <select id ="selectFsUserByUserIds" resultType="Integer">
  542. select count(1) from fs_user_company_user
  543. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  544. where is_repeat_fans = 1
  545. and (fs_user_company_user.company_user_id = #{companyUserId} OR company_user.parent_id = #{companyUserId})
  546. <if test="userIds != null and userIds.length > 0 ">
  547. and fs_user_company_user.user_id in
  548. <foreach collection="userIds" open="(" close=")" separator="," item="userId">
  549. #{userId}
  550. </foreach>
  551. </if>
  552. </select>
  553. <select id="getUserVipCountByCompanyUserId" resultType="java.util.Map">
  554. select
  555. count(if(date(u.create_time) = curdate(),u.user_id, null)) newVipCount,
  556. count(u.user_id) vipCount
  557. from fs_user u
  558. where u.company_user_id = #{companyUserId}
  559. </select>
  560. <select id="getUserNumber" resultType="com.fs.store.vo.h5.UserListCountVO">
  561. SELECT
  562. fs_user.`status` as status,
  563. count( DISTINCT fs_user.user_id ) AS num
  564. FROM
  565. fs_user
  566. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  567. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  568. WHERE fs_user.is_del = 0
  569. <if test="userId != null and userId != 0 ">
  570. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  571. </if>
  572. <if test="companyId != null ">
  573. and fs_user.company_id = #{companyId}
  574. </if>
  575. GROUP BY
  576. fs_user.`status`
  577. </select>
  578. <select id="getRepeatUserNumber" resultType="int">
  579. SELECT
  580. count( DISTINCT fs_user.user_id ) AS num
  581. FROM
  582. fs_user
  583. LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  584. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  585. WHERE
  586. ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
  587. AND fs_user.is_del = 0
  588. AND fs_user_company_user.is_repeat_fans = 1 and fs_user.`status` = 1
  589. </select>
  590. <select id="getCountWatchCourse" resultType="com.fs.store.vo.h5.UserDetailsVO">
  591. SELECT
  592. <if test="dateTag == null or dateTag =='' or dateTag == '近七天' ">
  593. ifnull( sum(complete_watch_count), 0 ) AS completeWatchCount ,
  594. ifnull( sum(watch_times), 0 ) AS watchTimes,
  595. </if>
  596. <if test="dateTag != null and dateTag !='' and dateTag != '近七天' ">
  597. ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
  598. ifnull( watch_times, 0 ) AS watchTimes,
  599. </if>
  600. fs_user.user_id
  601. FROM
  602. fs_user_course_count
  603. LEFT JOIN fs_user ON fs_user.user_id = fs_user_course_count.user_id
  604. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  605. <where>
  606. <if test="dateTag != null and dateTag !='' ">
  607. <choose>
  608. <when test = "dateTag == '今天'">
  609. and to_days(fs_user_course_count.create_time) = to_days(now())
  610. </when>
  611. <when test = "dateTag == '昨天'">
  612. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_user_course_count.create_time &lt; CURDATE()
  613. </when>
  614. <when test = "dateTag == '前天'">
  615. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_user_course_count.create_time &lt; CURDATE() - INTERVAL 1 DAY
  616. </when>
  617. <when test = "dateTag == '近七天'">
  618. and fs_user_course_count.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  619. </when>
  620. </choose>
  621. </if>
  622. and fs_user.user_id = #{fsUserId}
  623. </where>
  624. GROUP BY
  625. fs_user.user_id
  626. </select>
  627. <select id="getCountAnswer" resultType="com.fs.store.vo.h5.UserDetailsVO">
  628. SELECT
  629. (
  630. SELECT
  631. ifnull(count( DISTINCT log_id ), 0) AS answerTime
  632. FROM
  633. fs_course_answer_logs
  634. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  635. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  636. <where>
  637. <if test="dateTag != null and dateTag !='' ">
  638. <choose>
  639. <when test = "dateTag == '今天'">
  640. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  641. </when>
  642. <when test = "dateTag == '昨天'">
  643. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  644. </when>
  645. <when test = "dateTag == '前天'">
  646. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  647. </when>
  648. <when test = "dateTag == '近七天'">
  649. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  650. </when>
  651. </choose>
  652. </if>
  653. and fs_user.user_id = #{fsUserId}
  654. </where>
  655. GROUP BY
  656. fs_user.user_id
  657. ) AS answerTime,
  658. (
  659. SELECT
  660. ifnull(count( DISTINCT log_id ), 0) AS answerRightTime
  661. FROM
  662. fs_course_answer_logs
  663. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  664. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  665. <where>
  666. fs_course_answer_logs.is_right = 1
  667. <if test="dateTag != null and dateTag !='' ">
  668. <choose>
  669. <when test = "dateTag == '今天'">
  670. and to_days(fs_course_answer_logs.create_time) = to_days(now())
  671. </when>
  672. <when test = "dateTag == '昨天'">
  673. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
  674. </when>
  675. <when test = "dateTag == '前天'">
  676. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
  677. </when>
  678. <when test = "dateTag == '近七天'">
  679. and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  680. </when>
  681. </choose>
  682. </if>
  683. and fs_user.user_id = #{fsUserId}
  684. </where>
  685. GROUP BY
  686. fs_user.user_id
  687. ) AS answerRightTime;
  688. </select>
  689. <select id="getCountRedPacket" resultType="com.fs.store.vo.h5.UserDetailsVO">
  690. SELECT
  691. ifnull( count( DISTINCT log_id ), 0 ) AS answerRedPacketTime,
  692. ifnull( sum( amount ), 0 ) AS answerRedPacketAmount,
  693. fs_user.user_id
  694. FROM
  695. fs_course_red_packet_log
  696. LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
  697. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  698. <where>
  699. fs_course_red_packet_log.status = 1
  700. <if test="dateTag != null and dateTag !='' ">
  701. <choose>
  702. <when test = "dateTag == '今天'">
  703. and to_days(fs_course_red_packet_log.create_time) = to_days(now())
  704. </when>
  705. <when test = "dateTag == '昨天'">
  706. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE()
  707. </when>
  708. <when test = "dateTag == '前天'">
  709. 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
  710. </when>
  711. <when test = "dateTag == '近七天'">
  712. and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 7 DAY
  713. </when>
  714. </choose>
  715. </if>
  716. and fs_user.user_id = #{fsUserId}
  717. </where>
  718. GROUP BY
  719. fs_user.user_id
  720. </select>
  721. <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
  722. SELECT (SELECT count(fs_user.user_id)
  723. FROM fs_user
  724. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  725. WHERE fs_user.is_del = 0
  726. <if test="userId != null and userId != 0 ">
  727. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  728. </if>
  729. <if test="companyId != null ">
  730. and fs_user.company_id = #{companyId}
  731. </if>
  732. ) as userTotal,
  733. (SELECT count(fs_user.user_id)
  734. FROM fs_user
  735. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  736. WHERE fs_user.is_del = 0
  737. <if test="userId != null and userId != 0 ">
  738. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  739. </if>
  740. <if test="companyId != null ">
  741. and fs_user.company_id = #{companyId}
  742. </if>
  743. AND to_days(fs_user.create_time) = to_days(now())) as todayNewUser
  744. </select>
  745. <select id="countTag" resultType="com.fs.store.vo.h5.FsUserSummaryCountTagVO">
  746. SELECT
  747. company_tag.tag AS tagName,
  748. count( fs_user.user_id ) AS number
  749. FROM
  750. company_tag_user
  751. LEFT JOIN fs_user ON fs_user.user_id = company_tag_user.user_id
  752. LEFT JOIN company_tag ON FIND_IN_SET( company_tag.tag_id, company_tag_user.tag_ids ) > 0
  753. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  754. <where>
  755. <if test="userId != null and userId != 0 ">
  756. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  757. </if>
  758. <if test="companyId != null ">
  759. and fs_user.company_id = #{companyId}
  760. </if>
  761. and company_tag.tag_id is not null
  762. </where>
  763. GROUP BY
  764. company_tag.tag_id
  765. </select>
  766. <select id="countUserCourse" resultType="Map">
  767. SELECT
  768. (
  769. SELECT
  770. count(distinct fcc.user_id )
  771. FROM
  772. fs_user_course_count fcc
  773. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  774. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  775. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  776. <where>
  777. <if test="userId != null and userId != 0 ">
  778. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  779. </if>
  780. <if test="userId != null and userId == 0 ">
  781. and fs_user.company_id = #{companyId}
  782. </if>
  783. <if test="startTime != null and startTime !='' ">
  784. and fcc.create_time &gt;= #{startTime}
  785. </if>
  786. <if test="endTime != null and endTime != ''">
  787. and fcc.create_time &lt;= #{endTime}
  788. </if>
  789. <if test="periodId != null and periodId != ''">
  790. AND fcpd.period_id = #{periodId}
  791. </if>
  792. <if test="videoId != null and videoId != ''">
  793. AND fcpd.video_id = #{videoId}
  794. </if>
  795. -- 单独通过销售id查询
  796. <if test="companyUserId != null and companyUserId != ''">
  797. AND company_user.user_id = #{companyUserId}
  798. </if>
  799. </where>
  800. ) as courseWatchNum,
  801. (
  802. SELECT
  803. count(distinct fcc.user_id )
  804. FROM
  805. fs_user_course_count fcc
  806. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  807. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  808. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
  809. <where>
  810. <if test="userId != null and userId != 0 ">
  811. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  812. </if>
  813. <if test="userId != null and userId == 0 ">
  814. and fs_user.company_id = #{companyId}
  815. </if>
  816. AND fcc.complete_watch_count > 0
  817. <if test="startTime != null and startTime !='' ">
  818. and fcc.create_time &gt;= #{startTime}
  819. </if>
  820. <if test="endTime != null and endTime != ''">
  821. and fcc.create_time &lt;= #{endTime}
  822. </if>
  823. <if test="periodId != null and periodId != ''">
  824. AND fcpd.period_id = #{periodId}
  825. </if>
  826. <if test="videoId != null and videoId != ''">
  827. AND fcpd.video_id = #{videoId}
  828. </if>
  829. -- 单独通过销售id查询
  830. <if test="companyUserId != null and companyUserId != ''">
  831. AND company_user.user_id = #{companyUserId}
  832. </if>
  833. </where>
  834. ) as courseCompleteNum
  835. </select>
  836. <select id="countUserAnswer" resultType="Map">
  837. SELECT
  838. (
  839. SELECT
  840. count(distinct fs_user.user_id )
  841. FROM
  842. fs_course_answer_logs
  843. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  844. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  845. <where>
  846. <if test="userId != null and userId != 0 ">
  847. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  848. </if>
  849. <if test="userId != null and userId == 0 ">
  850. and fs_user.company_id = #{companyId}
  851. </if>
  852. <if test="startTime != null and startTime !='' ">
  853. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  854. </if>
  855. <if test="endTime != null and endTime != ''">
  856. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  857. </if>
  858. <if test="periodId != null and periodId != ''">
  859. AND fs_course_answer_logs.period_id = #{periodId}
  860. </if>
  861. <if test="videoId != null and videoId != ''">
  862. AND fs_course_answer_logs.video_id = #{videoId}
  863. </if>
  864. -- 单独通过销售id查询
  865. <if test="companyUserId != null and companyUserId != ''">
  866. AND company_user.user_id = #{companyUserId}
  867. </if>
  868. </where>
  869. ) AS answerNum,
  870. (
  871. SELECT
  872. count(distinct fs_user.user_id )
  873. FROM
  874. fs_course_answer_logs
  875. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  876. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  877. <where>
  878. <if test="userId != null and userId != 0 ">
  879. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  880. </if>
  881. <if test="userId != null and userId == 0 ">
  882. and fs_user.company_id = #{companyId}
  883. </if>
  884. AND fs_course_answer_logs.is_right = 1
  885. <if test="startTime != null and startTime !='' ">
  886. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  887. </if>
  888. <if test="endTime != null and endTime != ''">
  889. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  890. </if>
  891. <if test="periodId != null and periodId != ''">
  892. AND fs_course_answer_logs.period_id = #{periodId}
  893. </if>
  894. <if test="videoId != null and videoId != ''">
  895. AND fs_course_answer_logs.video_id = #{videoId}
  896. </if>
  897. -- 单独通过销售id查询
  898. <if test="companyUserId != null and companyUserId != ''">
  899. AND company_user.user_id = #{companyUserId}
  900. </if>
  901. </where>
  902. ) AS answerRightNum
  903. </select>
  904. <select id="countCourseDetails" resultType="Map">
  905. select (SELECT
  906. count( DISTINCT fcpd.period_id )
  907. FROM
  908. fs_user_course_period_days fcpd
  909. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  910. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  911. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  912. WHERE 1=1
  913. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  914. <if test="userId != null and userId != 0 ">
  915. AND fs_user.company_user_id = #{userId}
  916. </if>
  917. <if test="userId != null and userId == 0 ">
  918. and fs_user.company_id = #{companyId}
  919. </if>
  920. <if test="periodId != null and periodId != ''">
  921. AND fcpd.period_id = #{periodId}
  922. </if>
  923. -- 单独通过销售id查询
  924. <if test="companyUserId != null and companyUserId != ''">
  925. AND fs_user.company_user_id = #{companyUserId}
  926. </if>
  927. ) as courseNum,
  928. (SELECT count(DISTINCT fcpd.video_id)
  929. FROM fs_user_course_period_days fcpd
  930. LEFT JOIN fs_user_course_period fpd on fpd.period_id = fcpd.period_id
  931. LEFT JOIN fs_user_course_count fcc ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  932. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  933. WHERE 1=1
  934. AND FIND_IN_SET(#{companyId}, fpd.company_id)
  935. <if test="userId != null and userId != 0 ">
  936. AND fs_user.company_user_id = #{userId}
  937. </if>
  938. <if test="userId != null and userId == 0 ">
  939. and fs_user.company_id = #{companyId}
  940. </if>
  941. <if test="periodId != null and periodId != ''">
  942. AND fcpd.period_id = #{periodId}
  943. </if>
  944. <if test="videoId != null and videoId != ''">
  945. AND fcpd.video_id = #{videoId}
  946. </if>
  947. -- 单独通过销售id查询
  948. <if test="companyUserId != null and companyUserId != ''">
  949. AND fs_user.company_user_id = #{companyUserId}
  950. </if>
  951. ) as videoNum,
  952. ( SELECT count(DISTINCT fs_user.user_id ) FROM fs_user_course_count fcc
  953. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  954. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  955. <if test="periodId != null and periodId != ''">
  956. AND fcpd.period_id = #{periodId}
  957. </if>
  958. <if test="videoId != null and videoId != ''">
  959. AND fcpd.video_id = #{videoId}
  960. </if>
  961. -- 单独通过销售id查询
  962. <if test="companyUserId != null and companyUserId != ''">
  963. AND fs_user.company_user_id = #{companyUserId}
  964. </if>
  965. <where>
  966. <if test="userId != null and userId != 0 ">
  967. AND fs_user.company_user_id = #{userId}
  968. </if>
  969. <if test="userId != null and userId == 0 ">
  970. and fs_user.company_id = #{companyId}
  971. </if>
  972. </where>
  973. ) as courseUserNum
  974. </select>
  975. <select id="countUserRankingByComplete" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  976. SELECT
  977. company_user.nick_name as userName,
  978. ifnull(
  979. ROUND((COUNT(DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))*100,2),0
  980. ) as completeRate
  981. FROM
  982. fs_user_course_count fcc
  983. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  984. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  985. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  986. <where>
  987. <if test="userId != null and userId != 0 ">
  988. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  989. </if>
  990. <if test="userId != null and userId == 0 ">
  991. and fs_user.company_id = #{companyId}
  992. </if>
  993. <if test="startTime != null and startTime !='' ">
  994. AND fcc.create_time &gt;= #{startTime}
  995. </if>
  996. <if test="endTime != null and endTime != ''">
  997. AND fcc.create_time &lt;= #{endTime}
  998. </if>
  999. <if test="periodId != null and periodId != ''">
  1000. AND fcpd.period_id = #{periodId}
  1001. </if>
  1002. <if test="videoId != null and videoId != ''">
  1003. AND fcpd.video_id = #{videoId}
  1004. </if>
  1005. </where>
  1006. group by fcc.user_id
  1007. <choose>
  1008. <when test="order != null and order == 'asc'">
  1009. order by completeRate asc
  1010. </when>
  1011. <when test="order != null and order == 'desc'">
  1012. order by completeRate desc
  1013. </when>
  1014. <otherwise>
  1015. order by completeRate desc
  1016. </otherwise>
  1017. </choose>
  1018. limit 20
  1019. </select>
  1020. <select id="countUserRankingByRight" resultType="com.fs.store.vo.h5.FsUserRankingVO">
  1021. SELECT
  1022. company_user.nick_name as userName,
  1023. ifnull(ROUND(
  1024. (COUNT(DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1))
  1025. *100,2),0
  1026. ) as answerRightRate
  1027. FROM
  1028. fs_course_answer_logs
  1029. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1030. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1031. <where>
  1032. <if test="userId != null and userId != 0 ">
  1033. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1034. </if>
  1035. <if test="userId != null and userId == 0 ">
  1036. and fs_user.company_id = #{companyId}
  1037. </if>
  1038. <if test="startTime != null and startTime !='' ">
  1039. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1040. </if>
  1041. <if test="endTime != null and endTime != ''">
  1042. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1043. </if>
  1044. <if test="periodId != null and periodId != ''">
  1045. AND fs_course_answer_logs.period_id = #{periodId}
  1046. </if>
  1047. <if test="videoId != null and videoId != ''">
  1048. AND fs_course_answer_logs.video_id = #{videoId}
  1049. </if>
  1050. </where>
  1051. group by fs_user.user_id
  1052. <choose>
  1053. <when test="order != null and order == 'asc'">
  1054. order by answerRightRate asc
  1055. </when>
  1056. <when test="order != null and order == 'desc'">
  1057. order by answerRightRate desc
  1058. </when>
  1059. <otherwise>
  1060. order by answerRightRate desc
  1061. </otherwise>
  1062. </choose>
  1063. limit 20
  1064. </select>
  1065. <select id="countCourseRankingByComplete" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1066. SELECT
  1067. fcv.title AS videoName,
  1068. ifnull(
  1069. ROUND((
  1070. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN 1 END ) / count(1))* 100,
  1071. 2
  1072. ),
  1073. 0
  1074. ) AS completeRate
  1075. FROM
  1076. fs_user_course_count fcc
  1077. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1078. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1079. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1080. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fcpd.video_id
  1081. <where>
  1082. <if test="userId != null and userId != 0 ">
  1083. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1084. </if>
  1085. <if test="userId != null and userId == 0 ">
  1086. and fs_user.company_id = #{companyId}
  1087. </if>
  1088. <if test="startTime != null and startTime !='' ">
  1089. AND fcc.create_time &gt;= #{startTime}
  1090. </if>
  1091. <if test="endTime != null and endTime != ''">
  1092. AND fcc.create_time &lt;= #{endTime}
  1093. </if>
  1094. <if test="periodId != null and periodId != ''">
  1095. AND fcpd.period_id = #{periodId}
  1096. </if>
  1097. <if test="videoId != null and videoId != ''">
  1098. AND fcpd.video_id = #{videoId}
  1099. </if>
  1100. </where>
  1101. GROUP BY
  1102. fcpd.video_id
  1103. <choose>
  1104. <when test="order != null and order == 'asc'">
  1105. ORDER BY completeRate asc
  1106. </when>
  1107. <when test="order != null and order == 'desc'">
  1108. ORDER BY completeRate desc
  1109. </when>
  1110. <otherwise>
  1111. ORDER BY completeRate desc
  1112. </otherwise>
  1113. </choose>
  1114. LIMIT 20
  1115. </select>
  1116. <select id="countCourseRankingByRight" resultType="com.fs.store.vo.h5.FsCourseRankingVO">
  1117. SELECT
  1118. fcv.title AS videoName,
  1119. ifnull(
  1120. ROUND(
  1121. (
  1122. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN 1 END ) / count(1)) * 100,
  1123. 2
  1124. ),
  1125. 0
  1126. ) AS answerRightRate
  1127. FROM
  1128. fs_course_answer_logs
  1129. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1130. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1131. LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
  1132. <where>
  1133. <if test="userId != null and userId != 0 ">
  1134. AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1135. </if>
  1136. <if test="userId != null and userId == 0 ">
  1137. and fs_user.company_id = #{companyId}
  1138. </if>
  1139. <if test="startTime != null and startTime !='' ">
  1140. AND fs_course_answer_logs.create_time &gt;= #{startTime}
  1141. </if>
  1142. <if test="endTime != null and endTime != ''">
  1143. AND fs_course_answer_logs.create_time &lt;= #{endTime}
  1144. </if>
  1145. <if test="periodId != null and periodId != ''">
  1146. AND fs_course_answer_logs.period_id = #{periodId}
  1147. </if>
  1148. <if test="videoId != null and videoId != ''">
  1149. AND fs_course_answer_logs.video_id = #{videoId}
  1150. </if>
  1151. </where>
  1152. GROUP BY
  1153. fs_course_answer_logs.video_id
  1154. <choose>
  1155. <when test="order != null and order == 'asc'">
  1156. ORDER BY answerRightRate asc
  1157. </when>
  1158. <when test="order != null and order == 'desc'">
  1159. ORDER BY answerRightRate desc
  1160. </when>
  1161. <otherwise>
  1162. ORDER BY answerRightRate desc
  1163. </otherwise>
  1164. </choose>
  1165. LIMIT 20
  1166. </select>
  1167. <select id="countUserRedPacket" resultType="Map">
  1168. SELECT
  1169. (
  1170. SELECT
  1171. count( flog.log_id )
  1172. FROM
  1173. fs_course_red_packet_log flog
  1174. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1175. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1176. where flog.status = 1
  1177. <if test="userId != null and userId != 0 ">
  1178. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1179. </if>
  1180. <if test="userId != null and userId == 0 ">
  1181. and fs_user.company_id = #{companyId}
  1182. </if>
  1183. <if test="startTime != null and startTime !='' ">
  1184. AND flog.create_time &gt;= #{startTime}
  1185. </if>
  1186. <if test="endTime != null and endTime != ''">
  1187. AND flog.create_time &lt;= #{endTime}
  1188. </if>
  1189. <if test="periodId != null and periodId != ''">
  1190. AND flog.period_id = #{periodId}
  1191. </if>
  1192. <if test="videoId != null and videoId != ''">
  1193. AND flog.video_id = #{videoId}
  1194. </if>
  1195. -- 单独通过销售id查询
  1196. <if test="companyUserId != null and companyUserId != ''">
  1197. AND company_user.user_id = #{companyUserId}
  1198. </if>
  1199. ) AS redPacketNum,
  1200. (
  1201. SELECT
  1202. ifnull (sum( flog.amount ), 0)
  1203. FROM
  1204. fs_course_red_packet_log flog
  1205. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1206. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1207. where flog.status = 1
  1208. <if test="userId != null and userId != 0 ">
  1209. and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
  1210. </if>
  1211. <if test="userId != null and userId == 0 ">
  1212. and fs_user.company_id = #{companyId}
  1213. </if>
  1214. <if test="startTime != null and startTime !='' ">
  1215. AND flog.create_time &gt;= #{startTime}
  1216. </if>
  1217. <if test="endTime != null and endTime != ''">
  1218. AND flog.create_time &lt;= #{endTime}
  1219. </if>
  1220. <if test="periodId != null and periodId != ''">
  1221. AND flog.period_id = #{periodId}
  1222. </if>
  1223. <if test="videoId != null and videoId != ''">
  1224. AND flog.video_id = #{videoId}
  1225. </if>
  1226. -- 单独通过销售id查询
  1227. <if test="companyUserId != null and companyUserId != ''">
  1228. AND company_user.user_id = #{companyUserId}
  1229. </if>
  1230. ) AS redPacketAmount
  1231. </select>
  1232. <select id="courseAnalysisCourseCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  1233. SELECT
  1234. count( DISTINCT fcc.user_id ) as courseWatchNum,
  1235. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) as courseCompleteNum,
  1236. ifnull(
  1237. ROUND(
  1238. (
  1239. COUNT( DISTINCT CASE WHEN fcc.complete_watch_count > 0 THEN fcc.user_id END ) / count( DISTINCT fcc.user_id )) * 100,
  1240. 2
  1241. ),
  1242. 0
  1243. ) as completeRate,
  1244. fcpd.video_id
  1245. FROM
  1246. fs_user_course_count fcc
  1247. LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
  1248. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1249. LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
  1250. <where>
  1251. <if test="companyUserId != null and companyUserId != 0 ">
  1252. AND fs_user.company_user_id = #{companyUserId}
  1253. </if>
  1254. <if test="companyUserId != null and companyUserId == 0 ">
  1255. and fs_user.company_id = #{companyId}
  1256. </if>
  1257. <if test="periodId != null and periodId != ''">
  1258. AND fcpd.period_id = #{periodId}
  1259. </if>
  1260. <if test="videoId != null and videoId != ''">
  1261. AND fcpd.video_id = #{videoId}
  1262. </if>
  1263. </where>
  1264. GROUP BY
  1265. fcpd.video_id
  1266. </select>
  1267. <select id="companyUserCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1268. SELECT
  1269. (
  1270. SELECT count( fs_user.user_id ) FROM fs_user LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1271. <where>
  1272. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1273. AND fs_user.company_user_id = #{companyUserId}
  1274. </if>
  1275. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1276. and fs_user.company_id = #{companyId}
  1277. </if>
  1278. </where>
  1279. ) AS userTotal,
  1280. (
  1281. SELECT
  1282. count( fs_user.user_id )
  1283. FROM
  1284. fs_user
  1285. LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
  1286. <where>
  1287. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1288. AND fs_user.company_user_id = #{companyUserId}
  1289. </if>
  1290. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1291. and fs_user.company_id = #{companyId}
  1292. </if>
  1293. and fs_user.is_del = 0
  1294. AND to_days( fs_user.create_time ) = to_days(
  1295. now())
  1296. </where>
  1297. ) AS todayNewUser
  1298. </select>
  1299. <select id="newUserRedPacketCount" resultType="com.fs.store.vo.h5.CompanyUserSummaryCountVO">
  1300. SELECT
  1301. count(flog.log_id) as userRedPacketNum,
  1302. ifnull ( sum(case when to_days( fs_user.create_time ) = to_days(now()) THEN IFNULL(flog.amount,0) END), 0) as todayUserRedPacketAmount
  1303. FROM
  1304. fs_course_red_packet_log flog
  1305. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1306. <where>
  1307. <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
  1308. AND fs_user.company_user_id = #{companyUserId}
  1309. </if>
  1310. <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
  1311. and fs_user.company_id = #{companyId}
  1312. </if>
  1313. </where>
  1314. </select>
  1315. </mapper>