FsUserMapper.xml 87 KB

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