TaActivityStaticMapper.xml 114KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.huiju.estateagents.statistic.mapper.TaActicityStaticMapper">
  4. <select id="selectSharePersonNum" resultType="java.lang.Integer">
  5. SELECT count(1) as sharePersonNum
  6. FROM (
  7. SELECT count(DISTINCT(t.person_id))
  8. FROM ta_share_count t
  9. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  10. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  11. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  12. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  13. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  14. LEFT JOIN ta_person f ON t.person_id = f.person_id
  15. WHERE
  16. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  17. <if test="buildingId != null and buildingId != ''">
  18. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  19. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  20. </if>
  21. <if test="targetType != null and targetType != ''">
  22. and t.tagert_type = #{targetType}
  23. </if>
  24. <if test="startDate != null ">
  25. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  26. </if>
  27. <if test="endDate != null ">
  28. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  29. </if>
  30. <if test="startDate == null or endDate == null ">
  31. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  32. </if>
  33. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  34. AND
  35. (a.building_id in
  36. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  37. #{taPersonBuilding.buildingId}
  38. </foreach>
  39. or
  40. b.building_id in
  41. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  42. #{taPersonBuilding.buildingId}
  43. </foreach>
  44. or
  45. e.building_id in
  46. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  47. #{taPersonBuilding.buildingId}
  48. </foreach>
  49. or
  50. c.building_id in
  51. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  52. #{taPersonBuilding.buildingId}
  53. </foreach>
  54. or
  55. d.building_id in
  56. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  57. #{taPersonBuilding.buildingId}
  58. </foreach>
  59. or d.create_user = #{userId}
  60. or c.create_user = #{userId}
  61. )
  62. </if>
  63. GROUP BY DATE_FORMAT( t.create_date, '%Y-%m-%d' ) ,t.person_id
  64. ) as temp1
  65. </select>
  66. <select id="selectShareNum" resultType="java.lang.Integer">
  67. SELECT
  68. COUNT( 1 ) AS shareNum
  69. FROM
  70. ta_share_count t
  71. left join ta_help_activity a on t.be_share = a.help_activity_id
  72. left join ta_share_activity b on t.be_share = b.share_id
  73. left join ta_live_activity c on t.be_share = c.live_activity_id
  74. left join ta_drainage d on t.be_share = d.drainage_id
  75. left join ta_building_dynamic e on t.be_share = e.dynamic_id
  76. left join ta_person f on t.person_id = f.person_id
  77. WHERE
  78. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  79. <if test="buildingId != null and buildingId != ''">
  80. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  81. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  82. </if>
  83. <if test="targetType != null and targetType != ''">
  84. and t.tagert_type = #{targetType}
  85. </if>
  86. <if test="startDate != null ">
  87. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  88. </if>
  89. <if test="endDate != null ">
  90. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  91. </if>
  92. <if test="startDate == null or endDate == null ">
  93. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  94. </if>
  95. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  96. AND
  97. (a.building_id in
  98. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  99. #{taPersonBuilding.buildingId}
  100. </foreach>
  101. or
  102. b.building_id in
  103. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  104. #{taPersonBuilding.buildingId}
  105. </foreach>
  106. or
  107. e.building_id in
  108. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  109. #{taPersonBuilding.buildingId}
  110. </foreach>
  111. or
  112. c.building_id in
  113. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  114. #{taPersonBuilding.buildingId}
  115. </foreach>
  116. or
  117. d.building_id in
  118. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  119. #{taPersonBuilding.buildingId}
  120. </foreach>
  121. or d.create_user = #{userId}
  122. or c.create_user = #{userId}
  123. )
  124. </if>
  125. </select>
  126. <select id="selectVisitPersonNum" resultType="java.lang.Integer">
  127. select count(*)AS visitPersonNum from (
  128. SELECT
  129. t.visit_time AS create_date,
  130. t.person_id
  131. FROM
  132. ta_person_visit_record t
  133. WHERE
  134. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  135. <if test="buildingId != null and buildingId != ''">
  136. and t.building_id = #{buildingId}
  137. </if>
  138. <if test="targetType != null and targetType != ''">
  139. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType}
  140. end)
  141. </if>
  142. <if test="startDate != null">
  143. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  144. </if>
  145. <if test="endDate != null">
  146. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  147. </if>
  148. <if test="startDate == null or endDate == null">
  149. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  150. </if>
  151. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  152. AND t.building_id in
  153. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  154. #{taPersonBuilding.buildingId}
  155. </foreach>
  156. </if>
  157. GROUP BY
  158. DATE_FORMAT(t.visit_time, '%Y-%m-%d'),
  159. person_id) as visitPersonCount
  160. </select>
  161. <select id="selectVisitNum" resultType="java.lang.Integer">
  162. select count(*) from ta_person_visit_record t where t.`event` = 'detail' and t.event_type in
  163. ('activity','help','group','h5') and t.org_id = #{orgId}
  164. <if test="buildingId != null and buildingId != ''">
  165. and t.building_id = #{buildingId}
  166. </if>
  167. <if test="targetType != null and targetType != ''">
  168. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType}
  169. end)
  170. </if>
  171. <if test="startDate != null">
  172. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  173. </if>
  174. <if test="endDate != null">
  175. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  176. </if>
  177. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  178. AND t.building_id in
  179. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  180. #{taPersonBuilding.buildingId}
  181. </foreach>
  182. </if>
  183. </select>
  184. <select id="selectShareCount" resultType="java.util.Map">
  185. SELECT
  186. share_count_table.date AS date,
  187. ifnull( share_count_table.user_count, 0 ) AS share_count
  188. FROM
  189. (
  190. SELECT
  191. *
  192. FROM
  193. (
  194. SELECT
  195. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  196. FROM
  197. sequence a
  198. <trim prefix="where">
  199. <if test="startDate != null or endDate != null">
  200. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  201. </if>
  202. </trim>
  203. ) AS temp_date
  204. LEFT JOIN (
  205. SELECT
  206. COUNT( 1 ) AS user_count,
  207. t.create_date AS create_date
  208. FROM
  209. ta_share_count t
  210. left join ta_help_activity a on t.be_share = a.help_activity_id
  211. left join ta_share_activity b on t.be_share = b.share_id
  212. left join ta_live_activity c on t.be_share = c.live_activity_id
  213. left join ta_drainage d on t.be_share = d.drainage_id
  214. left join ta_building_dynamic e on t.be_share = e.dynamic_id
  215. left join ta_person f on t.person_id = f.person_id
  216. WHERE
  217. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  218. <if test="buildingId != null and buildingId != ''">
  219. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  220. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  221. </if>
  222. <if test="targetType != null and targetType != ''">
  223. and t.tagert_type = #{targetType}
  224. </if>
  225. <if test="startDate != null ">
  226. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  227. </if>
  228. <if test="endDate != null ">
  229. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  230. </if>
  231. <if test="startDate == null or endDate == null ">
  232. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  233. </if>
  234. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  235. AND
  236. (a.building_id in
  237. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  238. #{taPersonBuilding.buildingId}
  239. </foreach>
  240. or
  241. b.building_id in
  242. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  243. #{taPersonBuilding.buildingId}
  244. </foreach>
  245. or
  246. e.building_id in
  247. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  248. #{taPersonBuilding.buildingId}
  249. </foreach>
  250. or
  251. c.building_id in
  252. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  253. #{taPersonBuilding.buildingId}
  254. </foreach>
  255. or
  256. d.building_id in
  257. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  258. #{taPersonBuilding.buildingId}
  259. </foreach>
  260. or d.create_user = #{userId}
  261. or c.create_user = #{userId}
  262. )
  263. </if>
  264. GROUP BY
  265. DATE_FORMAT( t.create_date, '%Y-%m-%d' )
  266. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  267. ) AS share_count_table
  268. group by date order by date
  269. </select>
  270. <select id="selectSharePersonCount" resultType="java.util.Map">
  271. SELECT
  272. share_person_count_table.date AS date,
  273. ifnull( share_person_count_table.user_count, 0 ) AS share_person_count
  274. FROM
  275. (
  276. SELECT
  277. *
  278. FROM
  279. (
  280. SELECT
  281. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  282. FROM
  283. sequence a
  284. <trim prefix="where">
  285. <if test="startDate != null or endDate != null">
  286. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  287. </if>
  288. </trim>
  289. ) AS temp_date
  290. LEFT JOIN (
  291. SELECT count(1) as user_count , temp1.*
  292. FROM (
  293. SELECT DISTINCT(t.person_id),t.create_date
  294. FROM ta_share_count t
  295. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  296. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  297. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  298. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  299. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  300. LEFT JOIN ta_person f
  301. ON t.person_id = f.person_id
  302. WHERE
  303. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  304. <if test="buildingId != null and buildingId != ''">
  305. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  306. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  307. </if>
  308. <if test="targetType != null and targetType != ''">
  309. and t.tagert_type = #{targetType}
  310. </if>
  311. <if test="startDate != null ">
  312. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  313. </if>
  314. <if test="endDate != null ">
  315. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  316. </if>
  317. <if test="startDate == null or endDate == null ">
  318. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  319. </if>
  320. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  321. AND
  322. (a.building_id in
  323. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  324. #{taPersonBuilding.buildingId}
  325. </foreach>
  326. or
  327. b.building_id in
  328. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  329. #{taPersonBuilding.buildingId}
  330. </foreach>
  331. or
  332. e.building_id in
  333. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  334. #{taPersonBuilding.buildingId}
  335. </foreach>
  336. or
  337. c.building_id in
  338. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  339. #{taPersonBuilding.buildingId}
  340. </foreach>
  341. or
  342. d.building_id in
  343. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  344. #{taPersonBuilding.buildingId}
  345. </foreach>
  346. or d.create_user = #{userId}
  347. or c.create_user = #{userId}
  348. )
  349. </if>
  350. GROUP BY DATE_FORMAT( t.create_date, '%Y-%m-%d' ) ,t.person_id
  351. ) as temp1 GROUP BY DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  352. ) AS temp1 ON temp_date.date = DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  353. ) AS share_person_count_table
  354. group by date order by date
  355. </select>
  356. <select id="selectVisitCount" resultType="java.util.Map">
  357. SELECT
  358. visit_count_table.date AS date,
  359. ifnull( visit_count_table.user_count, 0 ) AS visit_count
  360. FROM (
  361. SELECT
  362. *
  363. FROM
  364. (
  365. SELECT
  366. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  367. FROM
  368. sequence a
  369. <trim prefix="where">
  370. <if test="startDate != null or endDate != null">
  371. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  372. </if>
  373. </trim>
  374. ) AS temp_date
  375. LEFT JOIN (
  376. SELECT
  377. COUNT( 1 ) AS user_count,
  378. t.visit_time AS create_date
  379. FROM
  380. ta_person_visit_record t
  381. WHERE
  382. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  383. <if test="buildingId != null and buildingId != ''">
  384. and t.building_id = #{buildingId}
  385. </if>
  386. <if test="targetType != null and targetType != ''">
  387. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType}
  388. end)
  389. </if>
  390. <if test="startDate != null">
  391. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  392. </if>
  393. <if test="endDate != null">
  394. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  395. </if>
  396. <if test="startDate == null or endDate == null ">
  397. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  398. </if>
  399. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  400. AND t.building_id in
  401. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  402. #{taPersonBuilding.buildingId}
  403. </foreach>
  404. </if>
  405. GROUP BY
  406. DATE_FORMAT( t.visit_time, '%Y-%m-%d' )
  407. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  408. ) AS visit_count_table
  409. group by date order by date
  410. </select>
  411. <select id="selectVisitPersonCount" resultType="java.util.Map">
  412. SELECT
  413. visit_person_count_table.date AS date,
  414. ifnull( visit_person_count_table.user_count, 0 ) AS visit_person_count
  415. FROM (
  416. SELECT
  417. *
  418. FROM
  419. (
  420. SELECT
  421. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  422. FROM
  423. sequence a
  424. <trim prefix="where">
  425. <if test="startDate != null or endDate != null">
  426. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  427. </if>
  428. </trim>
  429. ) AS temp_date
  430. LEFT JOIN (
  431. select count(*) AS user_count , visitPersonCount.* from (
  432. SELECT
  433. t.visit_time AS create_date,
  434. t.person_id
  435. FROM
  436. ta_person_visit_record t
  437. WHERE
  438. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  439. <if test="buildingId != null and buildingId != ''">
  440. and t.building_id = #{buildingId}
  441. </if>
  442. <if test="targetType != null and targetType != ''">
  443. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType}
  444. end)
  445. </if>
  446. <if test="startDate != null">
  447. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  448. </if>
  449. <if test="endDate != null">
  450. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  451. </if>
  452. <if test="startDate == null or endDate == null">
  453. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  454. </if>
  455. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  456. AND t.building_id in
  457. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  458. #{taPersonBuilding.buildingId}
  459. </foreach>
  460. </if>
  461. GROUP BY
  462. DATE_FORMAT(t.visit_time, '%Y-%m-%d'),
  463. person_id) as visitPersonCount GROUP BY DATE_FORMAT(visitPersonCount.create_date, '%Y-%m-%d')
  464. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  465. ) AS visit_person_count_table
  466. group by date order by date
  467. </select>
  468. <select id="selectAddRegistCount" resultType="java.util.Map">
  469. SELECT
  470. date,
  471. ifnull( addRegistNum, 0 ) AS addRegist_count
  472. FROM
  473. (
  474. SELECT
  475. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  476. FROM
  477. sequence a
  478. <trim prefix="where">
  479. <if test="startDate != null or endDate != null">
  480. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  481. </if>
  482. </trim>
  483. ) AS temp_date
  484. LEFT JOIN (
  485. SELECT
  486. count( * ) AS addRegistNum,
  487. temp4.*
  488. FROM
  489. (
  490. SELECT
  491. t.create_date AS create_date,
  492. t.person_id
  493. FROM
  494. ta_customer_from t
  495. WHERE
  496. t.target_type IN ( 'dynamic', 'h5', 'help', 'live', 'group', 'activity' )
  497. AND t.org_id = #{orgId}
  498. and t.is_org_first = 1
  499. <if test="buildingId != null and buildingId != ''">
  500. and t.building_id = #{buildingId}
  501. </if>
  502. <if test="targetType != null and targetType != ''">
  503. and t.target_type = #{targetType}
  504. </if>
  505. <if test="startDate != null ">
  506. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  507. </if>
  508. <if test="endDate != null ">
  509. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  510. </if>
  511. <if test="startDate == null or endDate == null">
  512. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  513. </if>
  514. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  515. AND t.building_id in
  516. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  517. #{taPersonBuilding.buildingId}
  518. </foreach>
  519. </if>
  520. group by t.person_id
  521. ) AS temp4
  522. GROUP BY
  523. DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  524. ) AS temp4 ON temp_date.date = DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  525. GROUP BY
  526. date
  527. ORDER BY
  528. date DESC
  529. </select>
  530. <select id="selectTableData" resultType="com.huiju.estateagents.excel.ActivityStatistics.StatisicAttractUser">
  531. SELECT date, ifnull(shareNum ,0) as shareNum, ifnull(sharePersonNum, 0) as sharePersonNum, ifnull(visitNum, 0)
  532. as visitNum, ifnull(visitPersonNum, 0) as visitPersonNum, ifnull(addRegistNum,0) as addRegistNum
  533. FROM
  534. (
  535. SELECT
  536. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  537. FROM
  538. sequence a
  539. <trim prefix="where">
  540. <if test="startDate != null or endDate != null">
  541. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  542. </if>
  543. </trim>
  544. ) AS temp_date
  545. LEFT JOIN (
  546. SELECT
  547. COUNT( 1 ) AS shareNum,
  548. t.create_date AS create_date
  549. FROM
  550. ta_share_count t
  551. left join ta_help_activity a on t.be_share = a.help_activity_id
  552. left join ta_share_activity b on t.be_share = b.share_id
  553. left join ta_live_activity c on t.be_share = c.live_activity_id
  554. left join ta_drainage d on t.be_share = d.drainage_id
  555. left join ta_building_dynamic e on t.be_share = e.dynamic_id
  556. left join ta_person f on t.person_id = f.person_id
  557. WHERE
  558. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  559. <if test="buildingId != null and buildingId != ''">
  560. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  561. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  562. </if>
  563. <if test="targetType != null and targetType != ''">
  564. and t.tagert_type = #{targetType}
  565. </if>
  566. <if test="startDate != null ">
  567. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  568. </if>
  569. <if test="endDate != null ">
  570. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  571. </if>
  572. <if test="startDate == null or endDate == null ">
  573. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  574. </if>
  575. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  576. AND
  577. (a.building_id in
  578. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  579. #{taPersonBuilding.buildingId}
  580. </foreach>
  581. or
  582. b.building_id in
  583. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  584. #{taPersonBuilding.buildingId}
  585. </foreach>
  586. or
  587. e.building_id in
  588. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  589. #{taPersonBuilding.buildingId}
  590. </foreach>
  591. or
  592. c.building_id in
  593. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  594. #{taPersonBuilding.buildingId}
  595. </foreach>
  596. or
  597. d.building_id in
  598. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  599. #{taPersonBuilding.buildingId}
  600. </foreach>
  601. or d.create_user = #{userId}
  602. or c.create_user = #{userId}
  603. )
  604. </if>
  605. GROUP BY
  606. DATE_FORMAT( t.create_date, '%Y-%m-%d' )
  607. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  608. LEFT JOIN (
  609. SELECT count(1) as sharePersonNum , temp1.*
  610. FROM (
  611. SELECT DISTINCT(t.person_id),t.create_date
  612. FROM ta_share_count t
  613. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  614. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  615. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  616. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  617. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  618. LEFT JOIN ta_person f ON t.person_id = f.person_id
  619. WHERE
  620. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  621. <if test="buildingId != null and buildingId != ''">
  622. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  623. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  624. </if>
  625. <if test="targetType != null and targetType != ''">
  626. and t.tagert_type = #{targetType}
  627. </if>
  628. <if test="startDate != null ">
  629. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  630. </if>
  631. <if test="endDate != null ">
  632. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  633. </if>
  634. <if test="startDate == null or endDate == null ">
  635. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  636. </if>
  637. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  638. AND
  639. (a.building_id in
  640. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  641. #{taPersonBuilding.buildingId}
  642. </foreach>
  643. or
  644. b.building_id in
  645. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  646. #{taPersonBuilding.buildingId}
  647. </foreach>
  648. or
  649. e.building_id in
  650. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  651. #{taPersonBuilding.buildingId}
  652. </foreach>
  653. or d.create_user = #{userId}
  654. or c.create_user = #{userId}
  655. )
  656. </if>
  657. GROUP BY DATE_FORMAT( t.create_date, '%Y-%m-%d' ) ,t.person_id
  658. ) as temp1 GROUP BY DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  659. ) AS temp1 ON temp_date.date = DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  660. LEFT JOIN (
  661. SELECT
  662. COUNT( 1 ) AS visitNum,
  663. t.visit_time AS create_date
  664. FROM
  665. ta_person_visit_record t
  666. WHERE
  667. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  668. <if test="buildingId != null and buildingId != ''">
  669. and t.building_id = #{buildingId}
  670. </if>
  671. <if test="targetType != null and targetType != ''">
  672. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' when #{targetType} = 'h5' then t.event_type = 'h5' else t.target_type = #{targetType}
  673. end)
  674. </if>
  675. <if test="startDate != null">
  676. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  677. </if>
  678. <if test="endDate != null">
  679. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  680. </if>
  681. <if test="startDate == null or endDate == null ">
  682. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  683. </if>
  684. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  685. AND t.building_id in
  686. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  687. #{taPersonBuilding.buildingId}
  688. </foreach>
  689. </if>
  690. GROUP BY
  691. DATE_FORMAT( t.visit_time, '%Y-%m-%d' )
  692. ) AS temp2 ON temp_date.date = DATE_FORMAT( temp2.create_date, '%Y-%m-%d' )
  693. LEFT JOIN (
  694. select count(*)AS visitPersonNum , visitPersonCount.* from (
  695. SELECT
  696. t.visit_time AS create_date,
  697. t.person_id
  698. FROM
  699. ta_person_visit_record t
  700. WHERE
  701. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  702. <if test="buildingId != null and buildingId != ''">
  703. and t.building_id = #{buildingId}
  704. </if>
  705. <if test="targetType != null and targetType != ''">
  706. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' when #{targetType} = 'h5' then t.event_type = 'h5' else t.target_type = #{targetType}
  707. end)
  708. </if>
  709. <if test="startDate != null">
  710. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  711. </if>
  712. <if test="endDate != null">
  713. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  714. </if>
  715. <if test="startDate == null or endDate == null">
  716. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  717. </if>
  718. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  719. AND t.building_id in
  720. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  721. #{taPersonBuilding.buildingId}
  722. </foreach>
  723. </if>
  724. GROUP BY
  725. DATE_FORMAT(t.visit_time, '%Y-%m-%d'),
  726. person_id) as visitPersonCount GROUP BY DATE_FORMAT(visitPersonCount.create_date, '%Y-%m-%d')
  727. ) AS temp3 ON temp_date.date = DATE_FORMAT( temp3.create_date, '%Y-%m-%d' )
  728. LEFT JOIN (
  729. select count(*) as addRegistNum,temp4.* from (
  730. SELECT
  731. t.create_date AS create_date,
  732. t.person_id
  733. FROM
  734. ta_customer_from t
  735. WHERE
  736. t.target_type in ('dynamic','h5','help','live', 'group', 'activity') and t.org_id = #{orgId}
  737. <if test="buildingId != null and buildingId != ''">
  738. and t.building_id = #{buildingId}
  739. </if>
  740. and t.is_org_first = 1
  741. <if test="targetType != null and targetType != ''">
  742. and t.target_type = #{targetType}
  743. </if>
  744. <if test="startDate != null ">
  745. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  746. </if>
  747. <if test="endDate != null ">
  748. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  749. </if>
  750. <if test="startDate == null or endDate == null">
  751. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  752. </if>
  753. GROUP BY t.person_id
  754. ) as temp4 GROUP BY DATE_FORMAT(temp4.create_date,'%Y-%m-%d')
  755. ) AS temp4 ON temp_date.date = DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  756. GROUP BY date
  757. <if test="colKey == null or colKey == ''">
  758. ORDER BY date desc
  759. </if>
  760. <if test="colKey != null and colKey != ''">
  761. ORDER BY ${colKey} ${sortType}
  762. </if>
  763. </select>
  764. <select id="selectExportTableData" resultType="com.huiju.estateagents.excel.ActivityStatistics.StatisicAttractUser">
  765. SELECT date, ifnull(shareNum ,0) as shareNum, ifnull(sharePersonNum, 0) as sharePersonNum, ifnull(visitNum, 0)
  766. as visitNum, ifnull(visitPersonNum, 0) as visitPersonNum, ifnull(addRegistNum,0) as addRegistNum
  767. FROM
  768. (
  769. SELECT
  770. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  771. FROM
  772. sequence a
  773. <trim prefix="where">
  774. <if test="startDate != null or endDate != null">
  775. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  776. </if>
  777. </trim>
  778. ) AS temp_date
  779. LEFT JOIN (
  780. SELECT
  781. COUNT( 1 ) AS shareNum,
  782. t.create_date AS create_date
  783. FROM
  784. ta_share_count t
  785. left join ta_help_activity a on t.be_share = a.help_activity_id
  786. left join ta_share_activity b on t.be_share = b.share_id
  787. left join ta_live_activity c on t.be_share = c.live_activity_id
  788. left join ta_drainage d on t.be_share = d.drainage_id
  789. left join ta_building_dynamic e on t.be_share = e.dynamic_id
  790. left join ta_person f on t.person_id = f.person_id
  791. WHERE
  792. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  793. <if test="buildingId != null and buildingId != ''">
  794. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  795. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  796. </if>
  797. <if test="targetType != null and targetType != ''">
  798. and t.tagert_type = #{targetType}
  799. </if>
  800. <if test="startDate != null ">
  801. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  802. </if>
  803. <if test="endDate != null ">
  804. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  805. </if>
  806. <if test="startDate == null or endDate == null ">
  807. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  808. </if>
  809. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  810. AND
  811. (a.building_id in
  812. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  813. #{taPersonBuilding.buildingId}
  814. </foreach>
  815. or
  816. b.building_id in
  817. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  818. #{taPersonBuilding.buildingId}
  819. </foreach>
  820. or
  821. e.building_id in
  822. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  823. #{taPersonBuilding.buildingId}
  824. </foreach>
  825. or
  826. c.building_id in
  827. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  828. #{taPersonBuilding.buildingId}
  829. </foreach>
  830. or
  831. d.building_id in
  832. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  833. #{taPersonBuilding.buildingId}
  834. </foreach>
  835. or d.create_user = #{userId}
  836. or c.create_user = #{userId}
  837. )
  838. </if>
  839. GROUP BY
  840. DATE_FORMAT( t.create_date, '%Y-%m-%d' )
  841. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  842. LEFT JOIN (
  843. SELECT count(1) as sharePersonNum , temp1.*
  844. FROM (
  845. SELECT DISTINCT(t.person_id),t.create_date
  846. FROM ta_share_count t
  847. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  848. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  849. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  850. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  851. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  852. LEFT JOIN ta_person f ON t.person_id = f.person_id
  853. WHERE
  854. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  855. <if test="buildingId != null and buildingId != ''">
  856. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  857. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  858. </if>
  859. <if test="targetType != null and targetType != ''">
  860. and t.tagert_type = #{targetType}
  861. </if>
  862. <if test="startDate != null ">
  863. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  864. </if>
  865. <if test="endDate != null ">
  866. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  867. </if>
  868. <if test="startDate == null or endDate == null ">
  869. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  870. </if>
  871. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  872. AND
  873. (a.building_id in
  874. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  875. #{taPersonBuilding.buildingId}
  876. </foreach>
  877. or
  878. b.building_id in
  879. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  880. #{taPersonBuilding.buildingId}
  881. </foreach>
  882. or
  883. e.building_id in
  884. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  885. #{taPersonBuilding.buildingId}
  886. </foreach>
  887. or d.create_user = #{userId}
  888. or c.create_user = #{userId}
  889. )
  890. </if>
  891. GROUP BY DATE_FORMAT( t.create_date, '%Y-%m-%d' ) ,t.person_id
  892. ) as temp1 GROUP BY DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  893. ) AS temp1 ON temp_date.date = DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  894. LEFT JOIN (
  895. SELECT
  896. COUNT( 1 ) AS visitNum,
  897. t.visit_time AS create_date
  898. FROM
  899. ta_person_visit_record t
  900. WHERE
  901. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  902. <if test="buildingId != null and buildingId != ''">
  903. and t.building_id = #{buildingId}
  904. </if>
  905. <if test="targetType != null and targetType != ''">
  906. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType}
  907. end)
  908. </if>
  909. <if test="startDate != null">
  910. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  911. </if>
  912. <if test="endDate != null">
  913. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  914. </if>
  915. <if test="startDate == null or endDate == null ">
  916. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  917. </if>
  918. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  919. AND t.building_id in
  920. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  921. #{taPersonBuilding.buildingId}
  922. </foreach>
  923. </if>
  924. GROUP BY
  925. DATE_FORMAT( t.visit_time, '%Y-%m-%d' )
  926. ) AS temp2 ON temp_date.date = DATE_FORMAT( temp2.create_date, '%Y-%m-%d' )
  927. LEFT JOIN (
  928. select count(*)AS visitPersonNum , visitPersonCount.* from (
  929. SELECT
  930. t.visit_time AS create_date,
  931. t.person_id
  932. FROM
  933. ta_person_visit_record t
  934. WHERE
  935. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  936. <if test="buildingId != null and buildingId != ''">
  937. and t.building_id = #{buildingId}
  938. </if>
  939. <if test="targetType != null and targetType != ''">
  940. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType}
  941. end)
  942. </if>
  943. <if test="startDate != null">
  944. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  945. </if>
  946. <if test="endDate != null">
  947. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  948. </if>
  949. <if test="startDate == null or endDate == null">
  950. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  951. </if>
  952. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  953. AND t.building_id in
  954. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  955. #{taPersonBuilding.buildingId}
  956. </foreach>
  957. </if>
  958. GROUP BY
  959. DATE_FORMAT(t.visit_time, '%Y-%m-%d'),
  960. person_id) as visitPersonCount GROUP BY DATE_FORMAT(visitPersonCount.create_date, '%Y-%m-%d')
  961. ) AS temp3 ON temp_date.date = DATE_FORMAT( temp3.create_date, '%Y-%m-%d' )
  962. LEFT JOIN (
  963. select count(*) as addRegistNum,temp4.* from (
  964. SELECT
  965. t.create_date AS create_date,
  966. t.person_id
  967. FROM
  968. ta_customer_from t
  969. WHERE
  970. t.target_type in ('dynamic','h5','help','live', 'group', 'activity') and t.org_id = #{orgId}
  971. <if test="buildingId != null and buildingId != ''">
  972. and t.building_id = #{buildingId}
  973. </if>
  974. and t.is_org_first = 1
  975. <if test="targetType != null and targetType != ''">
  976. and t.target_type = #{targetType}
  977. </if>
  978. <if test="startDate != null ">
  979. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  980. </if>
  981. <if test="endDate != null ">
  982. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  983. </if>
  984. <if test="startDate == null or endDate == null">
  985. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  986. </if>
  987. GROUP BY t.person_id
  988. ) as temp4 GROUP BY DATE_FORMAT(temp4.create_date,'%Y-%m-%d')
  989. ) AS temp4 ON temp_date.date = DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  990. GROUP BY date
  991. <if test="colKey == null or colKey == ''">
  992. ORDER BY date desc
  993. </if>
  994. <if test="colKey != null and colKey != ''">
  995. ORDER BY ${colKey} ${sortType}
  996. </if>
  997. </select>
  998. <select id="selectActivityStatisDetail"
  999. resultType="com.huiju.estateagents.excel.ActivityStatistics.ActivityDetailShareRecord">
  1000. select
  1001. activity.*,
  1002. ifnull(shareNum.shareNum, 0) as shareNum,
  1003. ifnull(sharePersonNum.sharePersonNum, 0) as sharePersonNum,
  1004. ifnull(visitNum.visitNum, 0) as visitNum,
  1005. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1006. ifnull(addRegistNum.addRegistNum, 0) as addRegistNum
  1007. from (
  1008. select a.dynamic_id as activityId, a.title as activityName, "activity" as activityType from ta_building_dynamic
  1009. a
  1010. where org_id = #{orgId}
  1011. <if test="buildingId != null and buildingId != '' ">
  1012. and a.building_id = #{buildingId}
  1013. </if>
  1014. <if test="activityName != null and activityName != '' ">
  1015. and a.title like concat('%', #{activityName}, '%')
  1016. </if>
  1017. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1018. and a.building_id in
  1019. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1020. #{taPersonBuilding.buildingId}
  1021. </foreach>
  1022. </if>
  1023. union all
  1024. select b.help_activity_id activityId, b.title as activityName, "help" as activityType from ta_help_activity b
  1025. where b.org_id = #{orgId}
  1026. <if test="buildingId != null and buildingId != '' ">
  1027. and b.building_id = #{buildingId}
  1028. </if>
  1029. <if test="activityName != null and activityName != '' ">
  1030. and b.title like concat('%', #{activityName}, '%')
  1031. </if>
  1032. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1033. and b.building_id in
  1034. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1035. #{taPersonBuilding.buildingId}
  1036. </foreach>
  1037. </if>
  1038. union all
  1039. select c.group_activity_id as activityId, c.activity_name as activityName, "group" as activityType From
  1040. ta_share_activity c
  1041. where c.org_id = #{orgId}
  1042. <if test="buildingId != null and buildingId != '' ">
  1043. and c.building_id = #{buildingId}
  1044. </if>
  1045. <if test="activityName != null and activityName != '' ">
  1046. and c.activity_name like concat('%', #{activityName}, '%')
  1047. </if>
  1048. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1049. and c.building_id in
  1050. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1051. #{taPersonBuilding.buildingId}
  1052. </foreach>
  1053. </if>
  1054. union all
  1055. select d.drainage_id as activityId, d.name as activityName, "h5" as activityType from ta_drainage d
  1056. where d.org_id = #{orgId}
  1057. <if test="buildingId != null and buildingId != '' ">
  1058. and d.building_id = #{buildingId}
  1059. </if>
  1060. <if test="activityName != null and activityName != '' ">
  1061. and d.name like concat('%', #{activityName}, '%')
  1062. </if>
  1063. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1064. and (d.building_id in
  1065. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1066. #{taPersonBuilding.buildingId}
  1067. </foreach>
  1068. or d.create_user = #{userId}
  1069. )
  1070. </if>
  1071. union all
  1072. select e.live_activity_id as activityId, e.live_activity_title as activityName, "live" as activityType From
  1073. ta_live_activity e
  1074. where e.org_id = #{orgId}
  1075. <if test="buildingId != null and buildingId != '' ">
  1076. and e.building_id = #{buildingId}
  1077. </if>
  1078. <if test="activityName != null and activityName != '' ">
  1079. and e.live_activity_title like concat('%', #{activityName}, '%')
  1080. </if>
  1081. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1082. and (e.building_id in
  1083. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1084. #{taPersonBuilding.buildingId}
  1085. </foreach>
  1086. or e.create_user = #{userId}
  1087. )
  1088. </if>
  1089. ) as activity
  1090. left join (
  1091. select count(1) as shareNum, a.* from (
  1092. SELECT a.be_share, case when a.tagert_type = 'liveApp' then 'live' when a.tagert_type = 'livePost' then 'live' else a.tagert_type end as tagert_type, a.create_date
  1093. FROM ta_share_count a where a.tagert_type in (
  1094. 'activity', 'group','h5','help','liveApp','livePost')
  1095. and a.org_id = #{orgId}
  1096. <if test="targetType != null and targetType != ''">
  1097. and (case when #{targetType} = 'live' then a.tagert_type in ('liveApp', 'livePost') else a.tagert_type = #{targetType}
  1098. end)
  1099. </if>
  1100. <if test="startDate != null ">
  1101. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1102. </if>
  1103. <if test="endDate != null ">
  1104. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1105. </if>
  1106. <if test="startDate == null or endDate == null ">
  1107. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1108. </if>
  1109. order by a.create_date desc limit 9999999) as a group by a.be_share,a.tagert_type order by a.create_date desc
  1110. ) as shareNum on shareNum.be_share = activity.activityId and shareNum.tagert_type = activity.activityType
  1111. left join (
  1112. SELECT count(*) as sharePersonNum ,sharePersonNum.be_share, sharePersonNum.tagert_type, sharePersonNum.create_date from (
  1113. SELECT a.be_share, a.create_date ,case when a.tagert_type = 'liveApp' then 'live' when a.tagert_type = 'livePost' then 'live' else a.tagert_type end as tagert_type
  1114. From ta_share_count a where a.tagert_type in ( 'activity', 'group','h5','help','liveApp','livePost')
  1115. and a.org_id = #{orgId}
  1116. <if test="targetType != null and targetType != ''">
  1117. and (case when #{targetType} = 'live' then a.tagert_type in ('liveApp', 'livePost') else a.tagert_type = #{targetType}
  1118. end)
  1119. </if>
  1120. <if test="startDate != null ">
  1121. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1122. </if>
  1123. <if test="endDate != null ">
  1124. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1125. </if>
  1126. <if test="startDate == null or endDate == null ">
  1127. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1128. </if>
  1129. group by a.person_id, be_share
  1130. <!-- , be_share, tagert_type-->
  1131. ) as sharePersonNum group by sharePersonNum.be_share, sharePersonNum.tagert_type
  1132. ) as sharePersonNum on sharePersonNum.be_share = activity.activityId and sharePersonNum.tagert_type =
  1133. activity.activityType
  1134. left join (
  1135. select count(*) as visitNum, a.target_id, case when a.target_type = 'dynamic' then 'activity' when a.target_type is null then 'h5' else a.target_type end as target_type
  1136. From ta_person_visit_record a where a.event_type in
  1137. ('activity','group','h5','help') and a.`event` = 'detail' and a.org_id = #{orgId}
  1138. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1139. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType}
  1140. end)
  1141. </if>
  1142. <if test="startDate != null">
  1143. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1144. </if>
  1145. <if test="endDate != null">
  1146. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1147. </if>
  1148. <if test="startDate == null or endDate == null ">
  1149. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1150. </if>
  1151. group by a.target_id, a.target_type
  1152. ) as visitNum on visitNum.target_id = activity.activityId and visitNum.target_type = activity.activityType
  1153. left join (
  1154. SELECT count(DISTINCT(a.person_id)) as visitPersonNum , a.target_id, case when a.target_type = 'dynamic' then 'activity' when a.target_type is null then 'h5' else a.target_type end as event_type
  1155. From ta_person_visit_record a where a.event_type in ('activity','group','h5','help') and a.`event` =
  1156. 'detail' and a.org_id = #{orgId}
  1157. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1158. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType}
  1159. end)
  1160. </if>
  1161. <if test="startDate != null">
  1162. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1163. </if>
  1164. <if test="endDate != null">
  1165. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1166. </if>
  1167. <if test="startDate == null or endDate == null ">
  1168. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1169. </if>
  1170. group by a.target_id, a.target_type
  1171. ) as visitPersonNum on visitPersonNum.target_id = activity.activityId and visitPersonNum.event_type =
  1172. activity.activityType
  1173. left join (
  1174. select count(*) as addRegistNum ,addRegistNum.target_id, addRegistNum.target_type From (
  1175. select count(*), a.* From ta_customer_from a where a.target_type IN ( 'dynamic', 'h5',
  1176. 'help', 'live', 'group', 'activity' ) and a.org_id = #{orgId}
  1177. and a.is_org_first = 1
  1178. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1179. and a.target_type = #{targetType}
  1180. </if>
  1181. <if test="startDate != null ">
  1182. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1183. </if>
  1184. <if test="endDate != null ">
  1185. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1186. </if>
  1187. <if test="startDate == null or endDate == null">
  1188. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1189. </if>
  1190. group by a.person_id, a.target_type ,a.target_id
  1191. ) as addRegistNum group by addRegistNum.target_type, addRegistNum.target_id
  1192. ) as addRegistNum on addRegistNum.target_id = activity.activityId and activity.activityType = addRegistNum.target_type
  1193. <if test="targetType != null and targetType != ''">
  1194. where activity.activityType = #{targetType}
  1195. </if>
  1196. group by activity.activityId, activity.activityType
  1197. <if test="colKey == null or colKey == ''">
  1198. order by shareNum.create_date desc
  1199. </if>
  1200. <if test="colKey != null and colKey != ''">
  1201. ORDER BY ${colKey} ${sortType}
  1202. </if>
  1203. </select>
  1204. <select id="selectActivityStatisDetailExport"
  1205. resultType="com.huiju.estateagents.excel.ActivityStatistics.ActivityDetailShareRecord">
  1206. select
  1207. activity.*,
  1208. ifnull(shareNum.shareNum, 0) as shareNum,
  1209. ifnull(sharePersonNum.sharePersonNum, 0) as sharePersonNum,
  1210. ifnull(visitNum.visitNum, 0) as visitNum,
  1211. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1212. ifnull(addRegistNum.addRegistNum, 0) as addRegistNum
  1213. from (
  1214. select a.dynamic_id as activityId, a.title as activityName, "activity" as activityType from ta_building_dynamic
  1215. a
  1216. where org_id = #{orgId}
  1217. <if test="buildingId != null and buildingId != '' ">
  1218. and a.building_id = #{buildingId}
  1219. </if>
  1220. <if test="activityName != null and activityName != '' ">
  1221. and a.title like concat('%', #{activityName}, '%')
  1222. </if>
  1223. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1224. and a.building_id in
  1225. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1226. #{taPersonBuilding.buildingId}
  1227. </foreach>
  1228. </if>
  1229. union all
  1230. select b.help_activity_id activityId, b.title as activityName, "help" as activityType from ta_help_activity b
  1231. where b.org_id = #{orgId}
  1232. <if test="buildingId != null and buildingId != '' ">
  1233. and b.building_id = #{buildingId}
  1234. </if>
  1235. <if test="activityName != null and activityName != '' ">
  1236. and b.title like concat('%', #{activityName}, '%')
  1237. </if>
  1238. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1239. and b.building_id in
  1240. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1241. #{taPersonBuilding.buildingId}
  1242. </foreach>
  1243. </if>
  1244. union all
  1245. select c.group_activity_id as activityId, c.activity_name as activityName, "group" as activityType From
  1246. ta_share_activity c
  1247. where c.org_id = #{orgId}
  1248. <if test="buildingId != null and buildingId != '' ">
  1249. and c.building_id = #{buildingId}
  1250. </if>
  1251. <if test="activityName != null and activityName != '' ">
  1252. and c.activity_name like concat('%', #{activityName}, '%')
  1253. </if>
  1254. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1255. and c.building_id in
  1256. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1257. #{taPersonBuilding.buildingId}
  1258. </foreach>
  1259. </if>
  1260. union all
  1261. select d.drainage_id as activityId, d.name as activityName, "h5" as activityType from ta_drainage d
  1262. where d.org_id = #{orgId}
  1263. <if test="buildingId != null and buildingId != '' ">
  1264. and d.building_id = #{buildingId}
  1265. </if>
  1266. <if test="activityName != null and activityName != '' ">
  1267. and d.name like concat('%', #{activityName}, '%')
  1268. </if>
  1269. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1270. and (d.building_id in
  1271. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1272. #{taPersonBuilding.buildingId}
  1273. </foreach>
  1274. or d.create_user = #{userId}
  1275. )
  1276. </if>
  1277. union all
  1278. select e.live_activity_id as activityId, e.live_activity_title as activityName, "live" as activityType From
  1279. ta_live_activity e
  1280. where e.org_id = #{orgId}
  1281. <if test="buildingId != null and buildingId != '' ">
  1282. and e.building_id = #{buildingId}
  1283. </if>
  1284. <if test="activityName != null and activityName != '' ">
  1285. and e.live_activity_title like concat('%', #{activityName}, '%')
  1286. </if>
  1287. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1288. and (e.building_id in
  1289. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1290. #{taPersonBuilding.buildingId}
  1291. </foreach>
  1292. or e.create_user = #{userId}
  1293. )
  1294. </if>
  1295. ) as activity
  1296. left join (
  1297. select count(1) as shareNum, a.* from (
  1298. SELECT a.be_share, case when a.tagert_type = 'liveApp' then 'live' when a.tagert_type = 'livePost' then 'live' else a.tagert_type end as tagert_type, a.create_date
  1299. FROM ta_share_count a where a.tagert_type in (
  1300. 'activity', 'group','h5','help','liveApp','livePost')
  1301. and a.org_id = #{orgId}
  1302. <if test="targetType != null and targetType != ''">
  1303. and (case when #{targetType} = 'live' then a.tagert_type in ('liveApp', 'livePost') else a.tagert_type = #{targetType}
  1304. end)
  1305. </if>
  1306. <if test="startDate != null ">
  1307. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1308. </if>
  1309. <if test="endDate != null ">
  1310. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1311. </if>
  1312. <if test="startDate == null or endDate == null ">
  1313. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1314. </if>
  1315. order by a.create_date desc limit 9999999) as a group by a.be_share,a.tagert_type order by a.create_date desc
  1316. ) as shareNum on shareNum.be_share = activity.activityId and shareNum.tagert_type = activity.activityType
  1317. left join (
  1318. SELECT count(*) as sharePersonNum ,sharePersonNum.be_share, sharePersonNum.tagert_type, sharePersonNum.create_date from (
  1319. SELECT a.be_share, a.create_date ,case when a.tagert_type = 'liveApp' then 'live' when a.tagert_type = 'livePost' then 'live' else a.tagert_type end as tagert_type
  1320. From ta_share_count a where a.tagert_type in ( 'activity', 'group','h5','help','liveApp','livePost')
  1321. and a.org_id = #{orgId}
  1322. <if test="targetType != null and targetType != ''">
  1323. and (case when #{targetType} = 'live' then a.tagert_type in ('liveApp', 'livePost') else a.tagert_type = #{targetType}
  1324. end)
  1325. </if>
  1326. <if test="startDate != null ">
  1327. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1328. </if>
  1329. <if test="endDate != null ">
  1330. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1331. </if>
  1332. <if test="startDate == null or endDate == null ">
  1333. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1334. </if>
  1335. group by a.person_id, be_share
  1336. <!-- , be_share, tagert_type-->
  1337. ) as sharePersonNum group by sharePersonNum.be_share, sharePersonNum.tagert_type
  1338. ) as sharePersonNum on sharePersonNum.be_share = activity.activityId and sharePersonNum.tagert_type =
  1339. activity.activityType
  1340. left join (
  1341. select count(*) as visitNum, a.target_id, case when a.target_type = 'dynamic' then 'activity' when a.target_type is null then 'h5' else a.target_type end as target_type
  1342. From ta_person_visit_record a where a.event_type in
  1343. ('activity','group','h5','help') and a.`event` = 'detail' and a.org_id = #{orgId}
  1344. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1345. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType}
  1346. end)
  1347. </if>
  1348. <if test="startDate != null">
  1349. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1350. </if>
  1351. <if test="endDate != null">
  1352. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1353. </if>
  1354. <if test="startDate == null or endDate == null ">
  1355. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1356. </if>
  1357. group by a.target_id, a.target_type
  1358. ) as visitNum on visitNum.target_id = activity.activityId and visitNum.target_type = activity.activityType
  1359. left join (
  1360. SELECT count(DISTINCT(a.person_id)) as visitPersonNum , a.target_id, case when a.target_type = 'dynamic' then 'activity' when a.target_type is null then 'h5' else a.target_type end as event_type
  1361. From ta_person_visit_record a where a.event_type in ('activity','group','h5','help') and a.`event` =
  1362. 'detail' and a.org_id = #{orgId}
  1363. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1364. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType}
  1365. end)
  1366. </if>
  1367. <if test="startDate != null">
  1368. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1369. </if>
  1370. <if test="endDate != null">
  1371. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1372. </if>
  1373. <if test="startDate == null or endDate == null ">
  1374. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1375. </if>
  1376. group by a.target_id, a.target_type
  1377. ) as visitPersonNum on visitPersonNum.target_id = activity.activityId and visitPersonNum.event_type =
  1378. activity.activityType
  1379. left join (
  1380. select count(*) as addRegistNum ,addRegistNum.target_id, addRegistNum.target_type From (
  1381. select count(*), a.* From ta_customer_from a where a.target_type IN ( 'dynamic', 'h5',
  1382. 'help', 'live', 'group', 'activity') and a.org_id = #{orgId}
  1383. and a.is_org_first = 1
  1384. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1385. and a.target_type = concat(REPLACE(#{targetType}, 'activity', 'dynamic'), '_share')
  1386. </if>
  1387. <if test="startDate != null ">
  1388. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1389. </if>
  1390. <if test="endDate != null ">
  1391. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1392. </if>
  1393. <if test="startDate == null or endDate == null">
  1394. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1395. </if>
  1396. group by a.person_id, a.target_type ,a.target_id
  1397. ) as addRegistNum group by addRegistNum.target_type, addRegistNum.target_id
  1398. ) as addRegistNum on addRegistNum.target_id = activity.activityId and activity.activityType = addRegistNum.target_type
  1399. <if test="targetType != null and targetType != ''">
  1400. where activity.activityType = #{targetType}
  1401. </if>
  1402. group by activity.activityId, activity.activityType
  1403. <if test="colKey == null or colKey == ''">
  1404. order by shareNum.create_date desc
  1405. </if>
  1406. <if test="colKey != null and colKey != ''">
  1407. ORDER BY ${colKey} ${sortType}
  1408. </if>
  1409. </select>
  1410. <select id="selectActivitySharePersonNum"
  1411. resultType="com.huiju.estateagents.excel.ActivityStatistics.SharePersonNum">
  1412. select person.nickname as sharePersonName,
  1413. ifnull(person.phone, '空') as sharePersonPhone ,
  1414. ifnull(shareNum, 0) as shareNum,
  1415. ifnull(visitNum, 0) as visitNum,
  1416. ifnull(visitPersonNum, 0) as visitPersonNum,
  1417. person.person_type as sharePersonType,
  1418. person.person_id
  1419. from (
  1420. SELECT t.*, f.nickname, f.phone, f.person_type
  1421. FROM ta_share_count t
  1422. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1423. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1424. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1425. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1426. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1427. LEFT JOIN ta_person f
  1428. ON t.person_id = f.person_id
  1429. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1430. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1431. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1432. <if test="buildingId != null and buildingId != ''">
  1433. and (
  1434. a.building_id = #{buildingId}
  1435. or b.building_id = #{buildingId}
  1436. or c.building_id = #{buildingId}
  1437. or d.building_id = #{buildingId}
  1438. or e.building_id = #{buildingId}
  1439. )
  1440. </if>
  1441. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1442. AND
  1443. (a.building_id in
  1444. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1445. #{taPersonBuilding.buildingId}
  1446. </foreach>
  1447. or
  1448. b.building_id in
  1449. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1450. #{taPersonBuilding.buildingId}
  1451. </foreach>
  1452. or
  1453. e.building_id in
  1454. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1455. #{taPersonBuilding.buildingId}
  1456. </foreach>
  1457. or
  1458. c.building_id in
  1459. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1460. #{taPersonBuilding.buildingId}
  1461. </foreach>
  1462. or
  1463. d.building_id in
  1464. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1465. #{taPersonBuilding.buildingId}
  1466. </foreach>
  1467. or d.create_user = #{userId}
  1468. or c.create_user = #{userId}
  1469. )
  1470. </if>
  1471. <if test="activityId != null and activityId != ''">
  1472. and t.be_share = #{activityId}
  1473. </if>
  1474. <if test="activityType != null and activityType != ''">
  1475. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1476. end)
  1477. </if>
  1478. <if test="sharePersonType != null and sharePersonType != ''">
  1479. and f.person_type = #{sharePersonType}
  1480. </if>
  1481. <if test="sharePersonName != null and sharePersonName != ''">
  1482. and f.nickname like CONCAT('%',#{sharePersonName}, '%')
  1483. </if>
  1484. <if test="sharePhone != null and sharePhone != ''">
  1485. and f.phone like CONCAT('%',#{sharePhone}, '%')
  1486. </if>
  1487. GROUP BY t.person_id
  1488. ) as person
  1489. left join (
  1490. select count(*) as shareNum, temp.person_id, temp.create_date from (
  1491. SELECT t.person_id, t.create_date
  1492. FROM ta_share_count t
  1493. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1494. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1495. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1496. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1497. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1498. LEFT JOIN ta_person f
  1499. ON t.person_id = f.person_id
  1500. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1501. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1502. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1503. <if test="activityId != null and activityId != ''">
  1504. and t.be_share = #{activityId}
  1505. </if>
  1506. <if test="activityType != null and activityType != ''">
  1507. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1508. end)
  1509. </if>
  1510. order by t.create_date desc limit 999999
  1511. ) as temp group by temp.person_id order by temp.create_date desc
  1512. ) as shareNum on person.person_id = shareNum.person_id
  1513. left join (
  1514. SELECT t.visitNum, ifnull(a.person_id,b.person_id) AS person_id
  1515. FROM (
  1516. SELECT t.share_person, count(1) as visitNum
  1517. FROM ta_share_person_from t
  1518. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S') AND t.create_date &lt;=
  1519. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S') AND t.target_type IN ('dynamic_share', 'h5_share', 'help_share',
  1520. 'live_share', 'group_share')
  1521. <if test="activityId != null and activityId != ''">
  1522. and t.target_id = #{activityId}
  1523. </if>
  1524. <if test="activityType != null and activityType != ''">
  1525. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1526. </if>
  1527. and t.org_id = #{orgId} group by t.share_person) t
  1528. left join ta_person a on t.share_person = a.person_id
  1529. left join ta_person b on t.share_person = b.user_id
  1530. ) as visitNum on visitNum.person_id = person.person_id
  1531. left join (
  1532. SELECT t.visitPersonNum, ifnull(a.person_id,b.person_id) AS person_id
  1533. FROM (
  1534. SELECT count(DISTINCT t.person_id ) as visitPersonNum, t.share_person
  1535. FROM ta_share_person_from t
  1536. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1537. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1538. <if test="activityId != null and activityId != ''">
  1539. and t.target_id = #{activityId}
  1540. </if>
  1541. <if test="activityType != null and activityType != ''">
  1542. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1543. </if>
  1544. and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1545. and t.org_id = #{orgId}
  1546. group by t.share_person
  1547. ) t
  1548. left join ta_person a on t.share_person = a.person_id
  1549. left join ta_person b on t.share_person = b.user_id
  1550. ) as visitPersonNum on visitPersonNum.person_id = person.person_id
  1551. group by person.person_id
  1552. <if test="colKey == null or colKey == ''">
  1553. order by shareNum.create_date desc
  1554. </if>
  1555. <if test="colKey != null and colKey != ''">
  1556. ORDER BY ${colKey} ${sort}
  1557. </if>
  1558. </select>
  1559. <select id="selectActivitySharePersonNumExport"
  1560. resultType="com.huiju.estateagents.excel.ActivityStatistics.SharePersonNum">
  1561. select person.nickname as sharePersonName,
  1562. ifnull(person.phone, '空') as sharePersonPhone ,
  1563. ifnull(shareNum, 0) as shareNum,
  1564. ifnull(visitNum, 0) as visitNum,
  1565. ifnull(visitPersonNum, 0) as visitPersonNum,
  1566. CASE
  1567. WHEN person.person_type = 'drift' THEN
  1568. "游客"
  1569. WHEN person.person_type = 'customer' THEN
  1570. "普通客户"
  1571. WHEN person.person_type = 'Realty Consultant' THEN
  1572. "置业顾问"
  1573. END `sharePersonType`,
  1574. person.person_id
  1575. from (
  1576. SELECT t.*, f.nickname, f.phone, f.person_type
  1577. FROM ta_share_count t
  1578. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1579. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1580. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1581. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1582. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1583. LEFT JOIN ta_person f
  1584. ON t.person_id = f.person_id
  1585. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1586. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1587. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1588. <if test="buildingId != null and buildingId != ''">
  1589. and (
  1590. a.building_id = #{buildingId}
  1591. or b.building_id = #{buildingId}
  1592. or c.building_id = #{buildingId}
  1593. or d.building_id = #{buildingId}
  1594. or e.building_id = #{buildingId}
  1595. )
  1596. </if>
  1597. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1598. AND
  1599. (a.building_id in
  1600. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1601. #{taPersonBuilding.buildingId}
  1602. </foreach>
  1603. or
  1604. b.building_id in
  1605. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1606. #{taPersonBuilding.buildingId}
  1607. </foreach>
  1608. or
  1609. e.building_id in
  1610. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1611. #{taPersonBuilding.buildingId}
  1612. </foreach>
  1613. or
  1614. c.building_id in
  1615. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1616. #{taPersonBuilding.buildingId}
  1617. </foreach>
  1618. or
  1619. d.building_id in
  1620. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1621. #{taPersonBuilding.buildingId}
  1622. </foreach>
  1623. or d.create_user = #{userId}
  1624. or c.create_user = #{userId}
  1625. )
  1626. </if>
  1627. <if test="activityId != null and activityId != ''">
  1628. and t.be_share = #{activityId}
  1629. </if>
  1630. <if test="activityType != null and activityType != ''">
  1631. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1632. end)
  1633. </if>
  1634. <if test="sharePersonType != null and sharePersonType != ''">
  1635. and f.person_type = #{sharePersonType}
  1636. </if>
  1637. <if test="sharePersonName != null and sharePersonName != ''">
  1638. and f.nickname like CONCAT('%',#{sharePersonName}, '%')
  1639. </if>
  1640. <if test="sharePhone != null and sharePhone != ''">
  1641. and f.phone like CONCAT('%',#{sharePhone}, '%')
  1642. </if>
  1643. GROUP BY t.person_id
  1644. ) as person
  1645. left join (
  1646. select count(*) as shareNum, temp.person_id, temp.create_date from (
  1647. SELECT t.person_id, t.create_date
  1648. FROM ta_share_count t
  1649. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1650. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1651. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1652. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1653. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1654. LEFT JOIN ta_person f
  1655. ON t.person_id = f.person_id
  1656. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1657. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1658. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1659. <if test="activityId != null and activityId != ''">
  1660. and t.be_share = #{activityId}
  1661. </if>
  1662. <if test="activityType != null and activityType != ''">
  1663. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1664. end)
  1665. </if>
  1666. order by t.create_date desc limit 999999
  1667. ) as temp group by temp.person_id order by temp.create_date desc
  1668. ) as shareNum on person.person_id = shareNum.person_id
  1669. left join (
  1670. SELECT t.visitNum, ifnull(a.person_id,b.person_id) AS person_id
  1671. FROM (
  1672. SELECT t.share_person, count(1) as visitNum
  1673. FROM ta_share_person_from t
  1674. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S') AND t.create_date &lt;=
  1675. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S') AND t.target_type IN ('dynamic_share', 'h5_share', 'help_share',
  1676. 'live_share', 'group_share')
  1677. <if test="activityId != null and activityId != ''">
  1678. and t.target_id = #{activityId}
  1679. </if>
  1680. <if test="activityType != null and activityType != ''">
  1681. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1682. </if>
  1683. and t.org_id = #{orgId} ) t
  1684. left join ta_person a on t.share_person = a.person_id
  1685. left join ta_person b on t.share_person = b.user_id
  1686. ) as visitNum on visitNum.person_id = person.person_id
  1687. left join (
  1688. SELECT t.visitPersonNum, ifnull(a.person_id,b.person_id) AS person_id
  1689. FROM (
  1690. SELECT count(DISTINCT t.person_id ) as visitPersonNum, t.share_person
  1691. FROM ta_share_person_from t
  1692. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1693. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1694. <if test="activityId != null and activityId != ''">
  1695. and t.target_id = #{activityId}
  1696. </if>
  1697. <if test="activityType != null and activityType != ''">
  1698. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1699. </if>
  1700. and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1701. and t.org_id = #{orgId}
  1702. <!-- group by t.share_person -->
  1703. ) t
  1704. left join ta_person a on t.share_person = a.person_id
  1705. left join ta_person b on t.share_person = b.user_id
  1706. ) as visitPersonNum on visitPersonNum.person_id = person.person_id
  1707. group by person.person_id
  1708. <if test="colKey == null or colKey == ''">
  1709. order by shareNum.create_date desc
  1710. </if>
  1711. <if test="colKey != null and colKey != ''">
  1712. ORDER BY ${colKey} ${sort}
  1713. </if>
  1714. </select>
  1715. <select id="selectActivityShareNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.ShareNum">
  1716. select person.nickname as sharePersonName,
  1717. ifnull(person.phone, '空') as sharePersonPhone ,
  1718. person.create_date as shareTime,
  1719. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1720. person.person_type as sharePersonType
  1721. FROM (
  1722. SELECT t.*, f.nickname, f.phone, f.person_type
  1723. FROM ta_share_count t
  1724. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1725. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1726. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1727. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1728. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1729. LEFT JOIN ta_person f ON t.person_id = f.person_id
  1730. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost')
  1731. <if test="activityId != null and activityId != ''">
  1732. and t.be_share = #{activityId}
  1733. </if>
  1734. <if test="activityType != null and activityType != ''">
  1735. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1736. end)
  1737. </if>
  1738. <if test="buildingId != null and buildingId != ''">
  1739. and (
  1740. a.building_id = #{buildingId}
  1741. or b.building_id = #{buildingId}
  1742. or c.building_id = #{buildingId}
  1743. or d.building_id = #{buildingId}
  1744. or e.building_id = #{buildingId}
  1745. )
  1746. </if>
  1747. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1748. AND
  1749. (a.building_id in
  1750. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1751. #{taPersonBuilding.buildingId}
  1752. </foreach>
  1753. or
  1754. b.building_id in
  1755. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1756. #{taPersonBuilding.buildingId}
  1757. </foreach>
  1758. or
  1759. e.building_id in
  1760. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1761. #{taPersonBuilding.buildingId}
  1762. </foreach>
  1763. or
  1764. c.building_id in
  1765. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1766. #{taPersonBuilding.buildingId}
  1767. </foreach>
  1768. or
  1769. d.building_id in
  1770. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1771. #{taPersonBuilding.buildingId}
  1772. </foreach>
  1773. or d.create_user = #{userId}
  1774. or c.create_user = #{userId}
  1775. )
  1776. </if>
  1777. and t.org_id = #{orgId}
  1778. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' )
  1779. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1780. <if test="personId != null and personId != ''">
  1781. and t.person_id = #{personId}
  1782. </if>
  1783. <if test="sharePersonName != null and sharePersonName != ''">
  1784. and f.nickname like CONCAT('%',#{sharePersonName}, '%')
  1785. </if>
  1786. <if test="sharePhone != null and sharePhone != ''">
  1787. and f.phone like CONCAT('%',#{sharePhone}, '%')
  1788. </if>
  1789. <if test="sharePersonType != null and sharePersonType != ''">
  1790. and f.person_type = #{sharePersonType}
  1791. </if>
  1792. ) as person
  1793. LEFT JOIN (
  1794. SELECT count(DISTINCT(t.person_id)) as visitPersonNum, ifnull(a.person_id,b.person_id) as person_id
  1795. FROM ta_share_person_from t
  1796. left join ta_person a on t.share_person = a.person_id
  1797. left join ta_person b on t.share_person = b.user_id
  1798. where t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  1799. <if test="activityId != null and activityId != ''">
  1800. and t.target_id = #{activityId}
  1801. </if>
  1802. <if test="activityType != null and activityType != ''">
  1803. and t.target_type = concat(#{activityType}, '_share')
  1804. </if>
  1805. <if test="personId != null and personId != ''">
  1806. and t.share_person = #{personId}
  1807. </if>
  1808. <if test="startDate != null ">
  1809. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  1810. </if>
  1811. <if test="endDate != null ">
  1812. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1813. </if>
  1814. ) as visitPersonNum
  1815. ON visitPersonNum.person_id = person.person_id order by person.create_date desc
  1816. </select>
  1817. <select id="selectActivityShareNumExport" resultType="com.huiju.estateagents.excel.ActivityStatistics.ShareNum">
  1818. select person.nickname as sharePersonName,
  1819. ifnull(person.phone, '空') as sharePersonPhone ,
  1820. person.create_date as shareTime,
  1821. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1822. CASE
  1823. WHEN person.person_type = 'drift' THEN
  1824. "游客"
  1825. WHEN person.person_type = 'customer' THEN
  1826. "普通客户"
  1827. WHEN person.person_type = 'Realty Consultant' THEN
  1828. "置业顾问"
  1829. END `sharePersonType`
  1830. FROM (
  1831. SELECT t.*, f.nickname, f.phone, f.person_type
  1832. FROM ta_share_count t
  1833. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1834. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1835. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1836. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1837. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1838. LEFT JOIN ta_person f ON t.person_id = f.person_id
  1839. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost')
  1840. <if test="activityId != null and activityId != ''">
  1841. and t.be_share = #{activityId}
  1842. </if>
  1843. <if test="activityType != null and activityType != ''">
  1844. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1845. end)
  1846. </if>
  1847. <if test="buildingId != null and buildingId != ''">
  1848. and (
  1849. a.building_id = #{buildingId}
  1850. or b.building_id = #{buildingId}
  1851. or c.building_id = #{buildingId}
  1852. or d.building_id = #{buildingId}
  1853. or e.building_id = #{buildingId}
  1854. )
  1855. </if>
  1856. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1857. AND
  1858. (a.building_id in
  1859. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1860. #{taPersonBuilding.buildingId}
  1861. </foreach>
  1862. or
  1863. b.building_id in
  1864. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1865. #{taPersonBuilding.buildingId}
  1866. </foreach>
  1867. or
  1868. e.building_id in
  1869. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1870. #{taPersonBuilding.buildingId}
  1871. </foreach>
  1872. or
  1873. c.building_id in
  1874. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1875. #{taPersonBuilding.buildingId}
  1876. </foreach>
  1877. or
  1878. d.building_id in
  1879. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1880. #{taPersonBuilding.buildingId}
  1881. </foreach>
  1882. or d.create_user = #{userId}
  1883. or c.create_user = #{userId}
  1884. )
  1885. </if>
  1886. and t.org_id = #{orgId}
  1887. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' )
  1888. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1889. <if test="personId != null and personId != ''">
  1890. and t.person_id = #{personId}
  1891. </if>
  1892. <if test="sharePersonName != null and sharePersonName != ''">
  1893. and f.nickname like CONCAT('%',#{sharePersonName}, '%')
  1894. </if>
  1895. <if test="sharePhone != null and sharePhone != ''">
  1896. and f.phone like CONCAT('%',#{sharePhone}, '%')
  1897. </if>
  1898. <if test="sharePersonType != null and sharePersonType != ''">
  1899. and f.person_type = #{sharePersonType}
  1900. </if>
  1901. ) as person
  1902. LEFT JOIN (
  1903. SELECT count(DISTINCT(t.person_id)) as visitPersonNum, ifnull(a.person_id,b.person_id) as person_id
  1904. FROM ta_share_person_from t
  1905. left join ta_person a on t.share_person = a.person_id
  1906. left join ta_person b on t.share_person = b.user_id
  1907. where t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  1908. <if test="activityId != null and activityId != ''">
  1909. and t.target_id = #{activityId}
  1910. </if>
  1911. <if test="activityType != null and activityType != ''">
  1912. and t.target_type = concat(#{activityType}, '_share')
  1913. </if>
  1914. <if test="personId != null and personId != ''">
  1915. and t.share_person = #{personId}
  1916. </if>
  1917. <if test="startDate != null ">
  1918. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  1919. </if>
  1920. <if test="endDate != null ">
  1921. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1922. </if>
  1923. ) as visitPersonNum
  1924. ON visitPersonNum.person_id = person.person_id order by person.create_date desc
  1925. </select>
  1926. <select id="selectActivityAddRegistNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.AddRegistNum">
  1927. SELECT
  1928. a.nickname, a.phone,
  1929. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1930. a.province,
  1931. b1.scene_alias as personFrom,
  1932. d.user_name as realtyConsultant,
  1933. d.phone as realtyConsultantPhone,
  1934. e.nickname AS sharePersonName,
  1935. e.phone AS sharePersonPhone
  1936. FROM ta_customer_from t
  1937. left join ta_person a on t.person_id = a.person_id
  1938. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId} and b.is_first_time =1
  1939. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1940. left join ta_recommend_customer c on c.person_id = t.person_id and c.realty_consultant is not null
  1941. LEFT JOIN ta_user d ON c.realty_consultant = d.user_id
  1942. LEFT JOIN ta_person e ON t.share_person_id = e.person_id
  1943. WHERE t.target_type in ('dynamic','h5','help','live', 'group','activity') and t.org_id =
  1944. #{orgId}
  1945. and t.is_org_first = 1
  1946. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d' ) and t.create_date &lt;= DATE_FORMAT(#{endDate},
  1947. '%Y-%m-%d' )
  1948. <if test="activityId != null and activityId != ''">
  1949. and t.target_id = #{activityId}
  1950. </if>
  1951. <if test="activityType != null and activityType != ''">
  1952. and t.target_type = #{activityType}
  1953. </if>
  1954. <if test="province != null and province != ''">
  1955. and a.province like concat('%', #{province}, '%')
  1956. </if>
  1957. <if test="personFrom != null and personFrom != ''">
  1958. and b.scene_type = #{personFrom}
  1959. </if>
  1960. <if test="buildingId != null and buildingId != ''">
  1961. and c.building_id = #{buildingId}
  1962. </if>
  1963. group by t.person_id order by t.create_date desc
  1964. </select>
  1965. <select id="selectActivityAddRegistNumExport"
  1966. resultType="com.huiju.estateagents.excel.ActivityStatistics.AddRegistNum">
  1967. SELECT
  1968. a.nickname, a.phone,
  1969. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1970. a.province,
  1971. b1.scene_alias as personFrom,
  1972. GROUP_CONCAT(d.user_name) as realtyConsultant,
  1973. group_concat(d.phone) as realtyConsultantPhone,
  1974. e.nickname AS sharePersonName,
  1975. e.phone AS sharePersonPhone
  1976. FROM ta_customer_from t
  1977. left join ta_person a on t.person_id = a.person_id
  1978. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId} and b.is_first_time =1
  1979. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1980. left join ta_recommend_customer c on c.person_id = t.person_id
  1981. LEFT JOIN ta_user d ON c.realty_consultant = d.user_id
  1982. LEFT JOIN ta_person e ON t.share_person_id = e.person_id
  1983. WHERE t.target_type in ('dynamic','h5','help','live', 'group','activity') and t.org_id =
  1984. #{orgId}
  1985. and t.is_org_first = 1
  1986. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d' ) and t.create_date &lt;= DATE_FORMAT(#{endDate},
  1987. '%Y-%m-%d' )
  1988. <if test="activityId != null and activityId != ''">
  1989. and t.target_id = #{activityId}
  1990. </if>
  1991. <if test="activityType != null and activityType != ''">
  1992. and t.target_type = #{activityType}
  1993. </if>
  1994. <if test="province != null and province != ''">
  1995. and a.province like concat('%', #{province}, '%')
  1996. </if>
  1997. <if test="personFrom != null and personFrom != ''">
  1998. and b.scene_type = #{personFrom}
  1999. </if>
  2000. <if test="buildingId != null and buildingId != ''">
  2001. and c.building_id = #{buildingId}
  2002. </if>
  2003. group by t.person_id order by t.create_date desc
  2004. </select>
  2005. <select id="selectActivityVisitNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  2006. select
  2007. a.nickname, a.phone,
  2008. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2009. a.province,
  2010. b1.scene_alias as personFrom,
  2011. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2012. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2013. e.nickname as sharePersonName,
  2014. e.phone as sharePersonPhone,
  2015. t.visit_time as visitDate
  2016. From (
  2017. SELECT
  2018. t.person_id, t.visit_time, t.share_person_id
  2019. FROM
  2020. ta_person_visit_record t
  2021. WHERE
  2022. t.`event` = 'detail'
  2023. AND t.event_type IN (
  2024. 'activity',
  2025. 'help',
  2026. 'group',
  2027. 'h5'
  2028. )
  2029. <if test="activityId != null and activityId != ''">
  2030. and t.target_id = #{activityId}
  2031. </if>
  2032. <if test="activityType != null and activityType != ''">
  2033. and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' when #{activityType} = 'h5' then t.event_type = 'h5' else t.target_type = #{activityType}
  2034. end)
  2035. </if>
  2036. <if test="buildingId != null and buildingId != ''">
  2037. and t.building_id = #{buildingId}
  2038. </if>
  2039. AND t.org_id = #{orgId}
  2040. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  2041. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  2042. ) t
  2043. left join ta_person a on t.person_id = a.person_id
  2044. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2045. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2046. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2047. left join ta_user d on c.realty_consultant = d.user_id
  2048. left join ta_person e on t.share_person_id = e.person_id
  2049. <where>
  2050. <if test="personFrom != null and personFrom != ''">
  2051. and b.scene_type = #{personFrom}
  2052. </if>
  2053. <if test="province != null and province != ''">
  2054. and a.province like concat('%', #{province}, '%')
  2055. </if>
  2056. <if test="realtyConsultant != null and realtyConsultant != ''">
  2057. and d.user_name like concat('%', #{realtyConsultant}, '%')
  2058. </if>
  2059. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  2060. and d.phone like concat('%', #{realtyConsultantPhone}, '%')
  2061. </if>
  2062. </where>
  2063. group by t.visit_time
  2064. order by t.visit_time desc
  2065. </select>
  2066. <select id="selectActivityVisitNumExport" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  2067. select
  2068. a.nickname, a.phone,
  2069. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2070. a.province,
  2071. b1.scene_alias as personFrom,
  2072. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2073. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2074. e.nickname as sharePersonName,
  2075. e.phone as sharePersonPhone,
  2076. t.visit_time as visitDate
  2077. From (
  2078. SELECT
  2079. t.person_id, t.visit_time, t.share_person_id
  2080. FROM
  2081. ta_person_visit_record t
  2082. WHERE
  2083. t.`event` = 'detail'
  2084. AND t.event_type IN (
  2085. 'activity',
  2086. 'help',
  2087. 'group',
  2088. 'h5'
  2089. )
  2090. <if test="activityId != null and activityId != ''">
  2091. and t.target_id = #{activityId}
  2092. </if>
  2093. <if test="activityType != null and activityType != ''">
  2094. and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' when #{activityType} = 'h5' then t.event_type = 'h5' else t.target_type = #{activityType}
  2095. end)
  2096. </if>
  2097. <if test="buildingId != null and buildingId != ''">
  2098. and t.building_id = #{buildingId}
  2099. </if>
  2100. AND t.org_id = #{orgId}
  2101. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  2102. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  2103. ) t
  2104. left join ta_person a on t.person_id = a.person_id
  2105. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2106. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2107. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2108. left join ta_user d on c.realty_consultant = d.user_id
  2109. left join ta_person e on t.share_person_id = e.person_id
  2110. <where>
  2111. <if test="personFrom != null and personFrom != ''">
  2112. and b.scene_type = #{personFrom}
  2113. </if>
  2114. <if test="province != null and province != ''">
  2115. and a.province like concat('%', #{province}, '%')
  2116. </if>
  2117. <if test="realtyConsultant != null and realtyConsultant != ''">
  2118. and d.user_name like concat('%', #{realtyConsultant}, '%')
  2119. </if>
  2120. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  2121. and d.phone like concat('%', #{realtyConsultantPhone}, '%')
  2122. </if>
  2123. </where>
  2124. group by t.visit_time
  2125. order by t.visit_time desc
  2126. </select>
  2127. <select id="selectActivityVisitPersonNum"
  2128. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  2129. select
  2130. a.nickname, a.phone,
  2131. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2132. a.province,
  2133. b1.scene_alias as personFrom,
  2134. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2135. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2136. t.create_date as visitDate,
  2137. e.nickName as sharePersonName,
  2138. t.visitNum
  2139. from (
  2140. SELECT
  2141. t.visit_time AS create_date,
  2142. t.person_id,
  2143. count(*) as visitNum
  2144. FROM
  2145. ta_person_visit_record t
  2146. WHERE
  2147. t.`event` = 'detail'
  2148. AND t.event_type IN (
  2149. 'activity',
  2150. 'help',
  2151. 'group',
  2152. 'h5'
  2153. )
  2154. AND t.org_id = #{orgId}
  2155. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  2156. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  2157. <if test="activityId != null and activityId != ''">
  2158. and t.target_id = #{activityId}
  2159. </if>
  2160. <if test="activityType != null and activityType != ''">
  2161. and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' when #{activityType} = 'h5' then t.event_type = 'h5' else t.target_type = #{activityType}
  2162. end)
  2163. </if>
  2164. <if test="buildingId != null and buildingId != ''">
  2165. and t.building_id = #{buildingId}
  2166. </if>
  2167. GROUP BY
  2168. t.person_id ) as t
  2169. left join ta_person a on t.person_id = a.person_id
  2170. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId} and b.is_first_time = 1
  2171. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2172. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2173. left join ta_user d on c.realty_consultant = d.user_id
  2174. LEFT JOIN ta_person e ON e.person_id = b.share_person_id
  2175. <where>
  2176. <if test="personFrom != null and personFrom != ''">
  2177. and b.scene_type = #{personFrom}
  2178. </if>
  2179. <if test="province != null and province != ''">
  2180. and a.province like concat('%', #{province},'%')
  2181. </if>
  2182. <if test="realtyConsultant != null and realtyConsultant != ''">
  2183. and d.user_name like concat('%', #{realtyConsultant},'%')
  2184. </if>
  2185. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  2186. and d.phone like concat('%', #{realtyConsultantPhone},'%')
  2187. </if>
  2188. </where>
  2189. group by t.person_id
  2190. order by t.create_date desc
  2191. </select>
  2192. <select id="selectActivityVisitPersonNumExport"
  2193. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  2194. select
  2195. a.nickname, a.phone,
  2196. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2197. a.province,
  2198. b1.scene_alias as personFrom,
  2199. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2200. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2201. t.create_date as visitDate,
  2202. e.nickName as sharePersonName,
  2203. t.visitNum
  2204. from (
  2205. SELECT
  2206. t.visit_time AS create_date,
  2207. t.person_id,
  2208. count(*) as visitNum
  2209. FROM
  2210. ta_person_visit_record t
  2211. WHERE
  2212. t.`event` = 'detail'
  2213. AND t.event_type IN (
  2214. 'activity',
  2215. 'help',
  2216. 'group',
  2217. 'h5'
  2218. )
  2219. AND t.org_id = #{orgId}
  2220. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  2221. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  2222. <if test="activityId != null and activityId != ''">
  2223. and t.target_id = #{activityId}
  2224. </if>
  2225. <if test="activityType != null and activityType != ''">
  2226. and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' when #{activityType} = 'h5' then t.event_type = 'h5' else t.target_type = #{activityType}
  2227. end)
  2228. </if>
  2229. <if test="buildingId != null and buildingId != ''">
  2230. and t.building_id = #{buildingId}
  2231. </if>
  2232. GROUP BY
  2233. t.person_id ) as t
  2234. left join ta_person a on t.person_id = a.person_id
  2235. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId} and b.is_first_time = 1
  2236. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2237. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2238. left join ta_user d on c.realty_consultant = d.user_id
  2239. LEFT JOIN ta_person e ON e.person_id = b.share_person_id
  2240. <where>
  2241. <if test="personFrom != null and personFrom != ''">
  2242. and b.scene_type = #{personFrom}
  2243. </if>
  2244. <if test="province != null and province != ''">
  2245. and a.province like concat('%', #{province},'%')
  2246. </if>
  2247. <if test="realtyConsultant != null and realtyConsultant != ''">
  2248. and d.user_name like concat('%', #{realtyConsultant},'%')
  2249. </if>
  2250. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  2251. and d.phone like concat('%', #{realtyConsultantPhone},'%')
  2252. </if>
  2253. </where>
  2254. group by t.person_id
  2255. order by t.create_date desc
  2256. </select>
  2257. <select id="selectActivityVisitPersonNumByPersonId"
  2258. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  2259. select
  2260. a.nickname, a.phone,
  2261. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2262. a.province,
  2263. b1.scene_alias as personFrom,
  2264. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2265. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2266. t.create_date as visitDate,
  2267. e.nickName as sharePersonName,
  2268. t.visitNum
  2269. From (
  2270. SELECT count(1) as visitNum, t.person_id, t.create_date
  2271. FROM ta_share_person_from t
  2272. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  2273. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  2274. <if test="activityId != null and activityId != ''">
  2275. and t.target_id = #{activityId}
  2276. </if>
  2277. <if test="activityType != null and activityType != ''">
  2278. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  2279. </if>
  2280. and t.target_type in
  2281. ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  2282. and
  2283. (t.share_person = (select b.user_id from ta_person t left join ta_user b on t.user_id = b.user_id where t.person_id = #{personId})
  2284. or t.share_person = #{personId})
  2285. group by t.person_id
  2286. ) as t
  2287. left join ta_person a on t.person_id = a.person_id
  2288. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2289. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2290. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2291. left join ta_user d on c.realty_consultant = d.user_id
  2292. LEFT JOIN ta_person e ON e.person_id = b.share_person_id
  2293. group by t.person_id
  2294. </select>
  2295. <select id="selectActivityVisitNumByPersonId" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  2296. select
  2297. a.nickname, a.phone,
  2298. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2299. a.province,
  2300. b1.scene_alias as personFrom,
  2301. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2302. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2303. t.create_date as visitDate,
  2304. ifnull(e.nickname, f.user_name) as sharePersonName,
  2305. ifnull(e.phone, f.phone) as sharePersonPhone
  2306. From (
  2307. SELECT t.person_id, t.create_date, t.share_person
  2308. FROM ta_share_person_from t
  2309. LEFT JOIN (
  2310. SELECT a.person_id, b.user_id
  2311. FROM ta_person a
  2312. LEFT JOIN ta_user b
  2313. ON a.user_id = b.user_id
  2314. WHERE a.org_id = #{orgId} ) as a ON t.share_person = a.person_id or t.share_person = a.user_id
  2315. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  2316. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in
  2317. ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  2318. <if test="activityId != null and activityId != ''">
  2319. and t.target_id = #{activityId}
  2320. </if>
  2321. <if test="activityType != null and activityType != ''">
  2322. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  2323. </if>
  2324. and
  2325. (t.share_person = (select b.user_id from ta_person t left join ta_user b on t.user_id = b.user_id where t.person_id = #{personId})
  2326. or t.share_person = #{personId})
  2327. ) as t
  2328. left join ta_person a on t.person_id = a.person_id
  2329. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2330. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2331. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2332. left join ta_user d on c.realty_consultant = d.user_id
  2333. left join ta_person e on t.share_person = e.person_id
  2334. left join ta_user f on t.share_person = f.user_id
  2335. group by t.create_date
  2336. </select>
  2337. <select id="selectActivityVisitPersonNumExportByPersonId"
  2338. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  2339. select
  2340. a.nickname, a.phone,
  2341. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2342. a.province,
  2343. b1.scene_alias as personFrom,
  2344. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2345. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2346. t.create_date as visitDate,
  2347. e.nickName as sharePersonName,
  2348. t.visitNum
  2349. From (
  2350. SELECT count(1) as visitNum, t.person_id, t.create_date
  2351. FROM ta_share_person_from t
  2352. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  2353. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  2354. <if test="activityId != null and activityId != ''">
  2355. and t.target_id = #{activityId}
  2356. </if>
  2357. <if test="activityType != null and activityType != ''">
  2358. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  2359. </if>
  2360. and t.target_type in
  2361. ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  2362. and
  2363. (t.share_person = (select b.user_id from ta_person t left join ta_user b on t.user_id = b.user_id where t.person_id = #{personId})
  2364. or t.share_person = #{personId})
  2365. group by t.person_id
  2366. ) as t
  2367. left join ta_person a on t.person_id = a.person_id
  2368. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2369. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2370. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2371. left join ta_user d on c.realty_consultant = d.user_id
  2372. LEFT JOIN ta_person e ON e.person_id = b.share_person_id
  2373. group by t.person_id
  2374. </select>
  2375. <select id="selectActivityVisitNumExportByPersonId"
  2376. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  2377. select
  2378. a.nickname, a.phone,
  2379. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2380. a.province,
  2381. b1.scene_alias as personFrom,
  2382. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2383. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2384. t.create_date as visitDate,
  2385. ifnull(e.nickname, f.user_name) as sharePersonName,
  2386. ifnull(e.phone, f.phone) as sharePersonPhone
  2387. From (
  2388. SELECT t.person_id, t.create_date, t.share_person
  2389. FROM ta_share_person_from t
  2390. LEFT JOIN (
  2391. SELECT a.person_id, b.user_id
  2392. FROM ta_person a
  2393. LEFT JOIN ta_user b
  2394. ON a.user_id = b.user_id
  2395. WHERE a.org_id = #{orgId} ) as a ON t.share_person = a.person_id or t.share_person = a.user_id
  2396. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  2397. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in
  2398. ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  2399. <if test="activityId != null and activityId != ''">
  2400. and t.target_id = #{activityId}
  2401. </if>
  2402. <if test="activityType != null and activityType != ''">
  2403. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  2404. </if>
  2405. and
  2406. (t.share_person = (select b.user_id from ta_person t left join ta_user b on t.user_id = b.user_id where t.person_id = #{personId})
  2407. or t.share_person = #{personId})
  2408. ) as t
  2409. left join ta_person a on t.person_id = a.person_id
  2410. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2411. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2412. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2413. left join ta_user d on c.realty_consultant = d.user_id
  2414. left join ta_person e on t.share_person = e.person_id
  2415. left join ta_user f on t.share_person = f.user_id
  2416. group by t.create_date
  2417. </select>
  2418. </mapper>