FsUserMapper.xml 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.his.mapper.FsUserMapper">
  6. <resultMap type="FsUser" id="FsUserResult">
  7. <result property="userId" column="user_id" />
  8. <result property="nickName" column="nick_name" />
  9. <result property="avatar" column="avatar" />
  10. <result property="phone" column="phone" />
  11. <result property="integral" column="integral" />
  12. <result property="status" column="status" />
  13. <result property="tuiUserId" column="tui_user_id" />
  14. <result property="tuiTime" column="tui_time" />
  15. <result property="tuiUserCount" column="tui_user_count" />
  16. <result property="maOpenId" column="ma_open_id" />
  17. <result property="mpOpenId" column="mp_open_id" />
  18. <result property="unionId" column="union_id" />
  19. <result property="isDel" column="is_del" />
  20. <result property="userCode" column="user_code" />
  21. <result property="remark" column="remark" />
  22. <result property="createTime" column="create_time" />
  23. <result property="updateTime" column="update_time" />
  24. <result property="lastIp" column="last_ip" />
  25. <result property="balance" column="balance" />
  26. <result property="signNum" column="sign_num" />
  27. <result property="integralStatus" column="integral_status" />
  28. <result property="isBuy" column="is_buy" />
  29. <result property="password" column="password" />
  30. <result property="isVip" column="is_vip" />
  31. <result property="jpushId" column="jpush_id" />
  32. <result property="vipStartDate" column="vip_start_date" />
  33. <result property="vipEndDate" column="vip_end_date" />
  34. <result property="vipLevel" column="vip_level" />
  35. <result property="vipStatus" column="vip_status" />
  36. <result property="sex" column="sex" />
  37. <result property="storeOpenId" column="store_open_id" />
  38. <result property="isPush" column="is_push" />
  39. <result property="isIndividuationPush" column="is_individuation_push" />
  40. <result property="isWeixinAuth" column="is_weixin_auth" />
  41. <result property="companyId" column="company_id"/>
  42. <result property="companyUserId" column="company_user_id"/>
  43. <result property="loginDevice" column="login_device" />
  44. <result property="source" column="source" />
  45. <result property="isAddQw" column="is_add_qw" />
  46. <result property="parentId" column="parent_id" />
  47. <result property="courseMaOpenId" column="course_ma_open_id" />
  48. <result property="qwExtId" column="qw_ext_id" />
  49. <result property="qwUserId" column="qw_user_id" />
  50. </resultMap>
  51. <sql id="selectFsUserVo">
  52. select user_id,qw_ext_id,sex,is_buy,course_ma_open_id,is_push,is_add_qw,source,login_device,is_individuation_push,store_open_id,password,jpush_id, is_vip,vip_start_date,vip_end_date,vip_level,vip_status,nick_name,integral_status, avatar, phone, integral,sign_num, status, tui_user_id, tui_time, tui_user_count, ma_open_id, mp_open_id, union_id, is_del, user_code, remark, create_time, update_time, last_ip, balance,is_weixin_auth,parent_id,qw_user_id,company_id,company_user_id from fs_user
  53. </sql>
  54. <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
  55. <include refid="selectFsUserVo"/>
  56. <where>
  57. <if test="userId != null">and user_id = #{userId}</if>
  58. <if test="nickName != null and nickName != ''"> and nick_name like concat( #{nickName}, '%')</if>
  59. <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
  60. <if test="phone != null and phone != ''"> and phone = #{phone}</if>
  61. <if test="integral != null "> and integral = #{integral}</if>
  62. <if test="signNum != null "> and sign_num = #{signNum}</if>
  63. <if test="status != null "> and status = #{status}</if>
  64. <if test="tuiUserId != null and tuiUserId != ''"> and tui_user_id = #{tuiUserId}</if>
  65. <if test="tuiTime != null "> and tui_time = #{tuiTime}</if>
  66. <if test="tuiUserCount != null "> and tui_user_count = #{tuiUserCount}</if>
  67. <if test="maOpenId != null and maOpenId != ''"> and ma_open_id = #{maOpenId}</if>
  68. <if test="mpOpenId != null and mpOpenId != ''"> and mp_open_id = #{mpOpenId}</if>
  69. <if test="unionId != null and unionId != ''"> and union_id = #{unionId}</if>
  70. <if test="isDel != null "> and is_del = #{isDel}</if>
  71. <if test="userCode != null and userCode != ''"> and user_code = #{userCode}</if>
  72. <if test="lastIp != null and lastIp != ''"> and last_ip = #{lastIp}</if>
  73. <if test="balance != null "> and balance = #{balance}</if>
  74. </where>
  75. </select>
  76. <select id="selectFsUserByUserId" parameterType="Long" resultMap="FsUserResult">
  77. <include refid="selectFsUserVo"/>
  78. where user_id = #{userId}
  79. </select>
  80. <select id="courseAnalysisWatchLog" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  81. SELECT
  82. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS courseWatchNum,
  83. count( CASE WHEN fwl.log_type != 3 THEN fwl.log_id END ) AS courseWatchTimes,
  84. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS courseCompleteNum,
  85. count( CASE WHEN fwl.log_type = 2 THEN fwl.log_id END ) AS courseCompleteTimes,
  86. ifnull(
  87. ROUND(
  88. (
  89. COUNT( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) / count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END )) * 100,
  90. 2
  91. ),
  92. 0
  93. ) AS completeRate,
  94. fwl.video_id
  95. FROM
  96. fs_course_watch_log fwl
  97. <where>
  98. <if test="periodId != null and periodId != ''">
  99. AND fwl.period_id = #{periodId}
  100. </if>
  101. <if test="videoId != null and videoId != ''">
  102. AND fwl.video_id = #{videoId}
  103. </if>
  104. <if test="videoIdList != null and videoIdList.size > 0 ">
  105. AND fwl.video_id in
  106. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  107. #{videoId}
  108. </foreach>
  109. </if>
  110. <if test="companyId != null">
  111. AND fwl.company_id = #{companyId}
  112. </if>
  113. </where>
  114. GROUP BY
  115. fwl.video_id
  116. </select>
  117. <select id="courseAnalysisRedPacketCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  118. SELECT
  119. count( flog.log_id ) as redPacketNum,
  120. ifnull ( sum( flog.amount ), 0 ) as redPacketAmount,
  121. flog.video_id
  122. FROM
  123. fs_course_red_packet_log flog
  124. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  125. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  126. <where>
  127. <if test="companyUserId != null and companyUserId != 0 ">
  128. AND flog.company_user_id = #{companyUserId}
  129. </if>
  130. <if test="companyUserId != null and companyUserId == 0 ">
  131. and flog.company_id = #{companyId}
  132. </if>
  133. <if test="periodId != null and periodId != ''">
  134. AND flog.period_id = #{periodId}
  135. </if>
  136. <if test="videoId != null and videoId != ''">
  137. AND flog.video_id = #{videoId}
  138. </if>
  139. <if test="videoIdList != null and videoIdList.size > 0 ">
  140. AND flog.video_id in
  141. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  142. #{videoId}
  143. </foreach>
  144. </if>
  145. <if test="companyId != null">
  146. AND flog.company_id = #{companyId}
  147. </if>
  148. </where>
  149. GROUP BY
  150. flog.video_id
  151. </select>
  152. <select id="courseAnalysisAnswerCount" resultType="com.fs.course.vo.newfs.FsCourseAnalysisCountVO">
  153. SELECT
  154. count( DISTINCT fs_user.user_id ) as answerNum,
  155. count(fs_course_answer_logs.log_id) answerTimes,
  156. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) as answerRightNum,
  157. COUNT( CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_course_answer_logs.log_id END ) as answerRightTimes,
  158. ifnull(
  159. ROUND(
  160. (
  161. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  162. 2
  163. ),
  164. 0
  165. ) as answerRightRate,
  166. fs_course_answer_logs.video_id
  167. FROM
  168. fs_course_answer_logs
  169. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  170. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  171. <where>
  172. <if test="companyUserId != null and companyUserId != 0 ">
  173. AND fs_course_answer_logs.company_user_id = #{companyUserId}
  174. </if>
  175. <if test="companyUserId != null and companyUserId == 0 ">
  176. and fs_course_answer_logs.company_id = #{companyId}
  177. </if>
  178. <if test="periodId != null and periodId != ''">
  179. AND fs_course_answer_logs.period_id = #{periodId}
  180. </if>
  181. <if test="videoId != null and videoId != ''">
  182. AND fs_course_answer_logs.video_id = #{videoId}
  183. </if>
  184. <if test="videoIdList != null and videoIdList.size > 0 ">
  185. AND fs_course_answer_logs.video_id in
  186. <foreach collection="videoIdList" open="(" close=")" separator="," item="videoId">
  187. #{videoId}
  188. </foreach>
  189. </if>
  190. <if test="companyId != null">
  191. AND fs_course_answer_logs.company_id = #{companyId}
  192. </if>
  193. </where>
  194. GROUP BY
  195. fs_course_answer_logs.video_id
  196. </select>
  197. <select id="selectFsUserById" parameterType="Long" resultMap="FsUserResult">
  198. <include refid="selectFsUserVo"/>
  199. where user_id = #{userId}
  200. </select>
  201. <select id="selectFsUserPageList" resultType="com.fs.store.vo.h5.FsUserPageListVO">
  202. SELECT
  203. fs_user.user_id,
  204. fs_user.avatar,
  205. fs_user.nick_name as nickname,
  206. fs_user.phone,
  207. fs_user_course_count.id,
  208. fs_user_course_count.watch_course_count,
  209. -- fs_course_watch_log.watch_course_count,
  210. fs_user_course_count.miss_course_count,
  211. fs_user_course_count.miss_course_status,
  212. fs_user_course_count.course_ids,
  213. fs_user_course_count.part_course_count,
  214. -- fs_course_watch_log.part_course_count,
  215. fs_user_course_count.last_watch_date,
  216. fs_user_course_count.STATUS AS courseCountStatus,
  217. fs_user_course_count.stop_watch_days,
  218. fs_user_course_count.complete_watch_date,
  219. GROUP_CONCAT(DISTINCT company_tag.tag) AS tag,
  220. GROUP_CONCAT(DISTINCT company_tag.tag_id) AS tagIds,
  221. company_user.nick_name as companyUserNickName,
  222. fs_user_company_user.is_repeat_fans,
  223. fs_user_company_user.project_id,
  224. fs_user_company_user.`status`,
  225. fs_user_company_user.remark,
  226. fs_user_company_user.id as userCompanyUserId,
  227. fs_user_company_user.create_time
  228. FROM
  229. fs_user
  230. INNER JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
  231. LEFT JOIN fs_user_course_count ON fs_user_company_user.user_id = fs_user_course_count.user_id and fs_user_company_user.project_id = fs_user_course_count.project_id
  232. left join fs_user_project_tag upt ON upt.user_company_user_id = fs_user_company_user.id
  233. LEFT JOIN company_tag ON company_tag.tag_id = upt.tag_id
  234. LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
  235. where fs_user.is_del = 0
  236. <if test="userId != null and userId!= 0 ">
  237. and fs_user_company_user.company_user_id = #{userId}
  238. </if>
  239. <if test="companyId != null ">
  240. and fs_user_company_user.company_id = #{companyId}
  241. </if>
  242. <if test="status != null">
  243. AND fs_user_company_user.status = #{status}
  244. </if>
  245. <if test="projectId != null">
  246. AND fs_user_company_user.project_id = #{projectId}
  247. </if>
  248. <if test="keyword != null and keyword !='' ">
  249. AND (fs_user.nick_name LIKE concat('%',#{keyword},'%')
  250. or fs_user.phone LIKE concat('%',#{keyword},'%')
  251. )
  252. </if>
  253. <if test="registerStartTime != null and registerStartTime !='' ">
  254. AND fs_user_company_user.create_time &gt;= #{registerStartTime}
  255. </if>
  256. <if test="registerEndTime != null and registerEndTime !='' ">
  257. AND fs_user_company_user.create_time &lt;= #{registerEndTime}
  258. </if>
  259. <if test="isNullTag">
  260. and (upt.tag_id is null
  261. <if test="tagIds != null and tagIds.length > 0">
  262. or upt.tag_id in
  263. <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
  264. #{item}
  265. </foreach>
  266. </if>
  267. )
  268. </if>
  269. <if test="!isNullTag and tagIds != null and tagIds.length > 0">
  270. AND upt.tag_id in
  271. <foreach collection="tagIds" item="item" index="index" open="(" separator="," close=")">
  272. #{item}
  273. </foreach>
  274. </if>
  275. <if test="tabValue != null and tabValue !='' ">
  276. <choose>
  277. <when test = "tabValue == 1">
  278. AND fs_user_company_user.create_time >= CURDATE() AND fs_user_company_user.create_time &lt; CURDATE() + INTERVAL 1 DAY
  279. </when>
  280. <when test = "tabValue == 2">
  281. AND fs_user_course_count.complete_watch_date >= CURDATE() AND fs_user_course_count.complete_watch_date &lt; CURDATE() + INTERVAL 1 DAY
  282. </when>
  283. <when test = "tabValue == 3">
  284. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  285. </when>
  286. </choose>
  287. </if>
  288. <if test="watchCourseType != null and watchCourseType !='' ">
  289. <choose>
  290. <when test = "watchCourseType == 1">
  291. AND (fs_user_course_count.status = 3 or fs_user_course_count.status is null)
  292. </when>
  293. <when test = "watchCourseType == 2">
  294. AND fs_user_course_count.status = 1
  295. </when>
  296. <when test = "watchCourseType == 3">
  297. AND fs_user_course_count.status = 2
  298. </when>
  299. </choose>
  300. </if>
  301. <if test="missCourseStatus != null and missCourseStatus !='' ">
  302. <choose>
  303. <when test = "missCourseStatus == 1">
  304. AND fs_user_course_count.miss_course_status = 1
  305. </when>
  306. <when test = "missCourseStatus == 2">
  307. AND (fs_user_course_count.miss_course_status = 2 or fs_user_course_count.miss_course_status is null )
  308. </when>
  309. </choose>
  310. </if>
  311. group by fs_user.user_id, fs_user_company_user.project_id, fs_user_company_user.create_time
  312. order by
  313. <choose>
  314. <when test = "continueMissCourseSort != null and continueMissCourseSort == 0">
  315. fs_user_company_user.create_time desc,fs_user.user_id desc
  316. </when>
  317. <when test = "continueMissCourseSort != null and continueMissCourseSort == 1">
  318. fs_user.nick_name asc,fs_user.user_id desc
  319. </when>
  320. <otherwise>
  321. fs_user.user_id desc, fs_user_company_user.project_id
  322. </otherwise>
  323. </choose>
  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.nick_name 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 ="selectFsUserByUserIds" 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(distinct 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(distinct 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.user_id, u.nick_name, u.avatar, u.phone, u.integral, u.now_money,
  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. ucu.create_time as bindTime,
  1584. ucu.status
  1585. FROM
  1586. fs_user u
  1587. LEFT JOIN (
  1588. SELECT max( payment_id ) AS payment_id, max( pay_time ) AS last_buy_time, SUM( pay_money ) AS total_amount,
  1589. user_id
  1590. FROM
  1591. fs_store_payment
  1592. WHERE
  1593. STATUS = 1
  1594. AND user_id IS NOT NULL
  1595. GROUP BY
  1596. user_id
  1597. ) b ON u.user_id = b.user_id
  1598. LEFT JOIN fs_store_payment p ON u.user_id = p.user_id
  1599. AND b.last_buy_time = p.pay_time
  1600. AND b.payment_id = p.payment_id
  1601. LEFT JOIN (
  1602. SELECT
  1603. 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,
  1604. fs_user_course_count.part_course_count
  1605. FROM
  1606. fs_user_course_count
  1607. GROUP BY fs_user_course_count.user_id
  1608. ) fcc ON fcc.user_id = u.user_id
  1609. inner join fs_user_company_user ucu on ucu.user_id = u.user_id
  1610. LEFT JOIN company_user ON company_user.user_id = ucu.company_user_id
  1611. LEFT JOIN company on company.company_id = company_user.company_id
  1612. <where>
  1613. 1 = 1 and u.nick_name is not null
  1614. and u.is_del = 0
  1615. <if test = "maps.nickname != null and maps.nickname !='' " >
  1616. AND u.nick_name LIKE CONCAT("%",#{maps.nickname},"%")
  1617. </if >
  1618. <if test = "maps.userId != null and maps.userId !='' " >
  1619. AND u.user_id = #{maps.userId}
  1620. </if >
  1621. <if test = "maps.phone != null and maps.phone !='' " >
  1622. AND u.phone LIKE CONCAT("%",#{maps.phone},"%")
  1623. </if >
  1624. <if test = "maps.startCreateTime != null and maps.endCreateTime != null" >
  1625. AND (DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &gt;= DATE_FORMAT(#{maps.startCreateTime}, "%Y-%m-%d")
  1626. and DATE_FORMAT( ucu.create_time, "%Y-%m-%d" ) &lt;= DATE_FORMAT(#{maps.endCreateTime}, "%Y-%m-%d")
  1627. )
  1628. </if >
  1629. <if test = "maps.registerCode != null and maps.registerCode !='' " >
  1630. AND u.register_code = #{maps.registerCode}
  1631. </if >
  1632. <if test = "maps.status != null" >
  1633. AND ucu.status = #{maps.status}
  1634. </if >
  1635. <if test = "maps.companyId != null and maps.companyId != '' " >
  1636. AND company.company_id = #{maps.companyId}
  1637. </if >
  1638. <if test = "maps.projectId != null" >
  1639. AND ucu.project_id = #{maps.projectId}
  1640. </if >
  1641. </where>
  1642. ORDER BY
  1643. user_id DESC
  1644. </select>
  1645. <select id="selectCompanyAndDoctor" resultType="com.fs.watch.domain.vo.FsUserAndCompanyAndDoctorVo">
  1646. SELECT
  1647. f.*,
  1648. GROUP_CONCAT(c.company_id SEPARATOR ',') AS company_id,
  1649. GROUP_CONCAT(c.company_user_id SEPARATOR ',') AS company_user_id,
  1650. GROUP_CONCAT(o.doctor_id SEPARATOR ',') AS doctor_id
  1651. FROM
  1652. fs_user f
  1653. LEFT JOIN
  1654. company_user_user c ON c.user_id = f.user_id
  1655. LEFT JOIN
  1656. fs_inquiry_order o ON o.user_id = f.user_id AND o.`status` = 4
  1657. WHERE
  1658. f.is_del = 0 AND f.user_id = #{userId}
  1659. GROUP BY
  1660. f.user_id;
  1661. </select>
  1662. <select id="selectUserNameByIds" resultMap="FsUserResult">
  1663. select user_id,nick_name from fs_user where user_id in
  1664. <foreach collection="userIds.split(',')" item="userId" open="(" close=")" separator=",">
  1665. #{userId}
  1666. </foreach>
  1667. </select>
  1668. <select id="selectFsUserTotal" resultType="FsUserWatchStatistics">
  1669. SELECT
  1670. count( fs_user.user_id ) as userNum,
  1671. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  1672. fs_user.company_id
  1673. FROM
  1674. fs_user
  1675. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1676. WHERE
  1677. fs_user.is_del = 0
  1678. AND fs_user.`status` = 1
  1679. AND company_user.user_id is not null
  1680. GROUP BY
  1681. fs_user.company_id
  1682. </select>
  1683. <select id="selectWatchLogCount" resultType="FsUserWatchCourseStatistics">
  1684. SELECT
  1685. count( DISTINCT CASE WHEN fwl.log_type != 3 THEN fwl.user_id END ) AS watchNum,
  1686. count( DISTINCT CASE WHEN fwl.log_type = 2 THEN fwl.user_id END ) AS completeWatchNum,
  1687. ifnull(
  1688. ROUND(
  1689. (
  1690. 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,
  1691. 2
  1692. ),
  1693. 0
  1694. ) AS completeWatchRate,
  1695. fwl.period_id, fwl.video_id, fwl.company_user_id, fwl.company_id
  1696. FROM
  1697. fs_course_watch_log fwl
  1698. WHERE
  1699. fwl.send_type = 1
  1700. GROUP BY
  1701. fwl.period_id, fwl.video_id, fwl.company_user_id
  1702. </select>
  1703. <select id="selectRedPacketLogCount" resultType="FsUserWatchCourseStatistics">
  1704. SELECT
  1705. count( flog.log_id ) AS redPacketNum,
  1706. ifnull ( sum( flog.amount ), 0 ) AS redPacketAmount,
  1707. flog.period_id,
  1708. flog.video_id,
  1709. flog.company_user_id,
  1710. flog.company_id
  1711. FROM
  1712. fs_course_red_packet_log flog
  1713. LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
  1714. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1715. where flog.`status` = 1
  1716. GROUP BY
  1717. flog.period_id,
  1718. flog.video_id,
  1719. flog.company_user_id
  1720. </select>
  1721. <select id="selectAnswerLogCount" resultType="FsUserWatchCourseStatistics">
  1722. SELECT
  1723. count( DISTINCT fs_user.user_id ) AS answerNum,
  1724. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) AS answerRightNum,
  1725. ifnull(
  1726. ROUND(
  1727. (
  1728. COUNT( DISTINCT CASE WHEN fs_course_answer_logs.is_right = 1 THEN fs_user.user_id END ) / count( DISTINCT fs_user.user_id )) * 100,
  1729. 2
  1730. ),
  1731. 0
  1732. ) AS answerRightRate,
  1733. fs_course_answer_logs.period_id,
  1734. fs_course_answer_logs.video_id,
  1735. fs_course_answer_logs.company_user_id,
  1736. fs_course_answer_logs.company_id
  1737. FROM
  1738. fs_course_answer_logs
  1739. LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
  1740. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1741. GROUP BY
  1742. fs_course_answer_logs.period_id,
  1743. fs_course_answer_logs.video_id,
  1744. fs_course_answer_logs.company_user_id
  1745. </select>
  1746. <select id="selectFsUserDetail" resultType="FsUserWatchCourseStatistics">
  1747. SELECT
  1748. count( fs_user.user_id ) as userNum,
  1749. count( DISTINCT CASE WHEN to_days( fs_user.create_time ) = to_days( now()) THEN fs_user.user_id END ) as newUserNum,
  1750. date(fs_user.create_time) as userCreateDate
  1751. ,company.company_id,
  1752. company.company_name,
  1753. company_user.user_id AS companyUserId,
  1754. company_user.nick_name AS companyUserName
  1755. FROM
  1756. fs_user
  1757. LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
  1758. LEFT JOIN company ON company.company_id = fs_user.company_id
  1759. WHERE
  1760. fs_user.is_del = 0
  1761. AND fs_user.`status` = 1
  1762. AND company_user.user_id is not null
  1763. GROUP BY
  1764. fs_user.company_user_id, date(fs_user.create_time)
  1765. </select>
  1766. <select id="selectFsUserListByJointUserNameKey" parameterType="FsUser" resultMap="FsUserResult">
  1767. <include refid="selectFsUserVo"/>
  1768. <where>
  1769. <if test="userName != null and userName != ''">
  1770. AND (
  1771. nickname like concat('%', #{userName}, '%')
  1772. or user_id LIKE concat('%',#{userName},'%')
  1773. )
  1774. </if>
  1775. </where>
  1776. order by user_id desc
  1777. </select>
  1778. <select id="selectFsUserCount" resultType="java.lang.Long">
  1779. select count(1) from fs_user
  1780. where 1=1
  1781. <if test = "type != null and type ==1">
  1782. and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d')
  1783. </if>
  1784. <if test = "companyId != null">
  1785. and company_id=#{companyId}
  1786. </if>
  1787. <if test="companyUserId != null">
  1788. and company_user_id = #{companyUserId}
  1789. </if>
  1790. </select>
  1791. <select id="selectFsUserListLimit" resultMap="FsUserResult">
  1792. <include refid="selectFsUserVo"/>
  1793. <where>
  1794. <if test="password != null and password != ''">and password = #{password}</if>
  1795. <if test="realName != null and realName != ''">and real_name like concat('%', #{realName}, '%')</if>
  1796. <if test="birthday != null ">and birthday = #{birthday}</if>
  1797. <if test="idCard != null and idCard != ''">and id_card = #{idCard}</if>
  1798. <if test="remark != null and remark != ''">and remark = #{remark}</if>
  1799. <if test="avatar != null and avatar != ''">and avatar = #{avatar}</if>
  1800. <if test="lastIp != null and lastIp != ''">and last_ip = #{lastIp}</if>
  1801. <if test="nowMoney != null ">and now_money = #{nowMoney}</if>
  1802. <if test="brokeragePrice != null ">and brokerage_price = #{brokeragePrice}</if>
  1803. <if test="integral != null ">and integral = #{integral}</if>
  1804. <if test="signNum != null ">and sign_num = #{signNum}</if>
  1805. <if test="status != null ">and status = #{status}</if>
  1806. <if test="level != null ">and level = #{level}</if>
  1807. <if test="spreadUserId != null ">and spread_user_id = #{spreadUserId}</if>
  1808. <if test="spreadTime != null ">and spread_time = #{spreadTime}</if>
  1809. <if test="userType != null and userType != ''">and user_type = #{userType}</if>
  1810. <if test="isPromoter != null ">and is_promoter = #{isPromoter}</if>
  1811. <if test="payCount != null ">and pay_count = #{payCount}</if>
  1812. <if test="spreadCount != null ">and spread_count = #{spreadCount}</if>
  1813. <if test="addres != null and addres != ''">and addres = #{addres}</if>
  1814. <if test="isDel != null ">and is_del = #{isDel}</if>
  1815. <if test="companyId != null ">and company_id = #{companyId}</if>
  1816. <if test="companyUserId != null ">and company_user_id = #{companyUserId}</if>
  1817. <if test="registerDate != null ">and DATE_FORMAT(register_date,'%Y-%m-%d') =
  1818. DATE_FORMAT(#{registerDate},'%Y-%m-%d')
  1819. </if>
  1820. <if test="registerCode != null and registerCode != '' ">and register_code = #{registerCode}</if>
  1821. <if test="source != null and source != '' ">and source = #{source}</if>
  1822. <if test="isShow != null ">and is_show = #{isShow}</if>
  1823. <if test="(username != null and username != '') or (userId != null and userId != '') or (nickname != null and nickname != '') or (phone != null and phone != '')">
  1824. and (
  1825. <if test="username != null and username != ''">username like concat('%', #{username}, '%')</if>
  1826. <if test="userId != null and userId != ''">or user_id = #{userId}</if>
  1827. <if test="nickname != null and nickname != ''">or nickname like concat('%', #{nickname}, '%')</if>
  1828. <if test="phone != null and phone != ''">or phone like concat('%',#{phone},'%')</if>
  1829. )
  1830. </if>
  1831. <if test="qwRepeat != null ">and qw_repeat = #{qwRepeat}</if>
  1832. <if test="userRepeat != null ">and user_repeat = #{userRepeat}</if>
  1833. <if test="payOrder != null ">and pay_order = #{payOrder}</if>
  1834. </where>
  1835. order by user_id desc
  1836. limit 10
  1837. </select>
  1838. <select id="findUsersByParam" resultType="com.fs.his.dto.FindUsersByDTO">
  1839. SELECT user_id as id, 0 as type,
  1840. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  1841. FROM fs_user
  1842. WHERE user_id = #{keywords}
  1843. UNION
  1844. <!-- fs_user 按nick_name前缀搜索 -->
  1845. SELECT user_id as id, 0 as type,
  1846. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  1847. FROM fs_user
  1848. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  1849. UNION
  1850. <!-- fs_user 按phone精确搜索(仅当keywords是数字时) -->
  1851. <if test="keywords.matches('\\d+')">
  1852. SELECT user_id as id, 0 as type,
  1853. CONCAT(user_id, '_', IFNULL(nick_name, '')) as name
  1854. FROM fs_user
  1855. WHERE phone = #{keywords}
  1856. UNION
  1857. </if>
  1858. <!-- company_user相关查询 -->
  1859. SELECT user_id as id, 1 as type,
  1860. IFNULL(nick_name, '') as name
  1861. FROM company_user
  1862. WHERE user_id = #{keywords}
  1863. UNION
  1864. SELECT user_id as id, 1 as type,
  1865. IFNULL(nick_name, '') as name
  1866. FROM company_user
  1867. WHERE nick_name LIKE CONCAT(#{keywords}, '%')
  1868. <if test="keywords.matches('\\d+')">
  1869. UNION
  1870. SELECT user_id as id, 1 as type,
  1871. IFNULL(nick_name, '') as name
  1872. FROM company_user
  1873. WHERE phonenumber = #{keywords}
  1874. </if>
  1875. </select>
  1876. </mapper>