FsUserMapper.xml 107 KB

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