TaActivityStaticMapper.xml 115KB

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_share_person_from t
  495. WHERE
  496. t.target_type IN ( 'dynamic_share', 'h5_share', 'help_share', 'live_share', 'group_share' )
  497. AND t.org_id = #{orgId}
  498. AND t.STATUS = 1
  499. and t.is_first_time = 1
  500. <if test="buildingId != null and buildingId != ''">
  501. and t.building_id = #{buildingId}
  502. </if>
  503. <if test="targetType != null and targetType != ''">
  504. and t.target_type = #{targetType}
  505. </if>
  506. <if test="startDate != null ">
  507. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  508. </if>
  509. <if test="endDate != null ">
  510. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  511. </if>
  512. <if test="startDate == null or endDate == null">
  513. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  514. </if>
  515. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  516. AND t.building_id in
  517. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  518. #{taPersonBuilding.buildingId}
  519. </foreach>
  520. </if>
  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' 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' 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_share_person_from t
  735. WHERE
  736. t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  737. <if test="buildingId != null and buildingId != ''">
  738. and t.building_id = #{buildingId}
  739. </if>
  740. and t.status = 1
  741. and t.is_first_time = 1
  742. <if test="targetType != null and targetType != ''">
  743. and t.target_type = #{targetType}
  744. </if>
  745. <if test="startDate != null ">
  746. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  747. </if>
  748. <if test="endDate != null ">
  749. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  750. </if>
  751. <if test="startDate == null or endDate == null">
  752. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  753. </if>
  754. GROUP BY t.person_id, t.target_type
  755. ) as temp4 GROUP BY DATE_FORMAT(temp4.create_date,'%Y-%m-%d')
  756. ) AS temp4 ON temp_date.date = DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  757. GROUP BY date
  758. <if test="colKey == null or colKey == ''">
  759. ORDER BY date desc
  760. </if>
  761. <if test="colKey != null and colKey != ''">
  762. ORDER BY ${colKey} ${sortType}
  763. </if>
  764. </select>
  765. <select id="selectExportTableData" resultType="com.huiju.estateagents.excel.ActivityStatistics.StatisicAttractUser">
  766. SELECT date, ifnull(shareNum ,0) as shareNum, ifnull(sharePersonNum, 0) as sharePersonNum, ifnull(visitNum, 0)
  767. as visitNum, ifnull(visitPersonNum, 0) as visitPersonNum, ifnull(addRegistNum,0) as addRegistNum
  768. FROM
  769. (
  770. SELECT
  771. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  772. FROM
  773. sequence a
  774. <trim prefix="where">
  775. <if test="startDate != null or endDate != null">
  776. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  777. </if>
  778. </trim>
  779. ) AS temp_date
  780. LEFT JOIN (
  781. SELECT
  782. COUNT( 1 ) AS shareNum,
  783. t.create_date AS create_date
  784. FROM
  785. ta_share_count t
  786. left join ta_help_activity a on t.be_share = a.help_activity_id
  787. left join ta_share_activity b on t.be_share = b.share_id
  788. left join ta_live_activity c on t.be_share = c.live_activity_id
  789. left join ta_drainage d on t.be_share = d.drainage_id
  790. left join ta_building_dynamic e on t.be_share = e.dynamic_id
  791. left join ta_person f on t.person_id = f.person_id
  792. WHERE
  793. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  794. <if test="buildingId != null and buildingId != ''">
  795. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  796. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  797. </if>
  798. <if test="targetType != null and targetType != ''">
  799. and t.tagert_type = #{targetType}
  800. </if>
  801. <if test="startDate != null ">
  802. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  803. </if>
  804. <if test="endDate != null ">
  805. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  806. </if>
  807. <if test="startDate == null or endDate == null ">
  808. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  809. </if>
  810. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  811. AND
  812. (a.building_id in
  813. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  814. #{taPersonBuilding.buildingId}
  815. </foreach>
  816. or
  817. b.building_id in
  818. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  819. #{taPersonBuilding.buildingId}
  820. </foreach>
  821. or
  822. e.building_id in
  823. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  824. #{taPersonBuilding.buildingId}
  825. </foreach>
  826. or
  827. c.building_id in
  828. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  829. #{taPersonBuilding.buildingId}
  830. </foreach>
  831. or
  832. d.building_id in
  833. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  834. #{taPersonBuilding.buildingId}
  835. </foreach>
  836. or d.create_user = #{userId}
  837. or c.create_user = #{userId}
  838. )
  839. </if>
  840. GROUP BY
  841. DATE_FORMAT( t.create_date, '%Y-%m-%d' )
  842. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  843. LEFT JOIN (
  844. SELECT count(1) as sharePersonNum , temp1.*
  845. FROM (
  846. SELECT DISTINCT(t.person_id),t.create_date
  847. FROM ta_share_count t
  848. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  849. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  850. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  851. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  852. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  853. LEFT JOIN ta_person f ON t.person_id = f.person_id
  854. WHERE
  855. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  856. <if test="buildingId != null and buildingId != ''">
  857. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or
  858. d.building_id = #{buildingId} or e.building_id = #{buildingId})
  859. </if>
  860. <if test="targetType != null and targetType != ''">
  861. and t.tagert_type = #{targetType}
  862. </if>
  863. <if test="startDate != null ">
  864. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  865. </if>
  866. <if test="endDate != null ">
  867. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  868. </if>
  869. <if test="startDate == null or endDate == null ">
  870. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  871. </if>
  872. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  873. AND
  874. (a.building_id in
  875. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  876. #{taPersonBuilding.buildingId}
  877. </foreach>
  878. or
  879. b.building_id in
  880. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  881. #{taPersonBuilding.buildingId}
  882. </foreach>
  883. or
  884. e.building_id in
  885. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  886. #{taPersonBuilding.buildingId}
  887. </foreach>
  888. or d.create_user = #{userId}
  889. or c.create_user = #{userId}
  890. )
  891. </if>
  892. GROUP BY DATE_FORMAT( t.create_date, '%Y-%m-%d' ) ,t.person_id
  893. ) as temp1 GROUP BY DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  894. ) AS temp1 ON temp_date.date = DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  895. LEFT JOIN (
  896. SELECT
  897. COUNT( 1 ) AS visitNum,
  898. t.visit_time AS create_date
  899. FROM
  900. ta_person_visit_record t
  901. WHERE
  902. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  903. <if test="buildingId != null and buildingId != ''">
  904. and t.building_id = #{buildingId}
  905. </if>
  906. <if test="targetType != null and targetType != ''">
  907. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType}
  908. end)
  909. </if>
  910. <if test="startDate != null">
  911. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  912. </if>
  913. <if test="endDate != null">
  914. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  915. </if>
  916. <if test="startDate == null or endDate == null ">
  917. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  918. </if>
  919. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  920. AND t.building_id in
  921. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  922. #{taPersonBuilding.buildingId}
  923. </foreach>
  924. </if>
  925. GROUP BY
  926. DATE_FORMAT( t.visit_time, '%Y-%m-%d' )
  927. ) AS temp2 ON temp_date.date = DATE_FORMAT( temp2.create_date, '%Y-%m-%d' )
  928. LEFT JOIN (
  929. select count(*)AS visitPersonNum , visitPersonCount.* from (
  930. SELECT
  931. t.visit_time AS create_date,
  932. t.person_id
  933. FROM
  934. ta_person_visit_record t
  935. WHERE
  936. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  937. <if test="buildingId != null and buildingId != ''">
  938. and t.building_id = #{buildingId}
  939. </if>
  940. <if test="targetType != null and targetType != ''">
  941. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType}
  942. end)
  943. </if>
  944. <if test="startDate != null">
  945. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  946. </if>
  947. <if test="endDate != null">
  948. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  949. </if>
  950. <if test="startDate == null or endDate == null">
  951. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  952. </if>
  953. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  954. AND t.building_id in
  955. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  956. #{taPersonBuilding.buildingId}
  957. </foreach>
  958. </if>
  959. GROUP BY
  960. DATE_FORMAT(t.visit_time, '%Y-%m-%d'),
  961. person_id) as visitPersonCount GROUP BY DATE_FORMAT(visitPersonCount.create_date, '%Y-%m-%d')
  962. ) AS temp3 ON temp_date.date = DATE_FORMAT( temp3.create_date, '%Y-%m-%d' )
  963. LEFT JOIN (
  964. select count(*) as addRegistNum,temp4.* from (
  965. SELECT
  966. t.create_date AS create_date,
  967. t.person_id
  968. FROM
  969. ta_share_person_from t
  970. WHERE
  971. t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  972. <if test="buildingId != null and buildingId != ''">
  973. and t.building_id = #{buildingId}
  974. </if>
  975. and t.status = 1
  976. and t.is_first_time = 1
  977. <if test="targetType != null and targetType != ''">
  978. and t.target_type = #{targetType}
  979. </if>
  980. <if test="startDate != null ">
  981. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  982. </if>
  983. <if test="endDate != null ">
  984. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  985. </if>
  986. <if test="startDate == null or endDate == null">
  987. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  988. </if>
  989. GROUP BY t.person_id, t.target_type
  990. ) as temp4 GROUP BY DATE_FORMAT(temp4.create_date,'%Y-%m-%d')
  991. ) AS temp4 ON temp_date.date = DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  992. GROUP BY date
  993. <if test="colKey == null or colKey == ''">
  994. ORDER BY date desc
  995. </if>
  996. <if test="colKey != null and colKey != ''">
  997. ORDER BY ${colKey} ${sortType}
  998. </if>
  999. </select>
  1000. <select id="selectActivityStatisDetail"
  1001. resultType="com.huiju.estateagents.excel.ActivityStatistics.ActivityDetailShareRecord">
  1002. select
  1003. activity.*,
  1004. ifnull(shareNum.shareNum, 0) as shareNum,
  1005. ifnull(sharePersonNum.sharePersonNum, 0) as sharePersonNum,
  1006. ifnull(visitNum.visitNum, 0) as visitNum,
  1007. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1008. ifnull(addRegistNum.addRegistNum, 0) as addRegistNum
  1009. from (
  1010. select a.dynamic_id as activityId, a.title as activityName, "activity" as activityType from ta_building_dynamic
  1011. a
  1012. where org_id = #{orgId}
  1013. <if test="buildingId != null and buildingId != '' ">
  1014. and a.building_id = #{buildingId}
  1015. </if>
  1016. <if test="activityName != null and activityName != '' ">
  1017. and a.title like concat('%', #{activityName}, '%')
  1018. </if>
  1019. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1020. and a.building_id in
  1021. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1022. #{taPersonBuilding.buildingId}
  1023. </foreach>
  1024. </if>
  1025. union all
  1026. select b.help_activity_id activityId, b.title as activityName, "help" as activityType from ta_help_activity b
  1027. where b.org_id = #{orgId}
  1028. <if test="buildingId != null and buildingId != '' ">
  1029. and b.building_id = #{buildingId}
  1030. </if>
  1031. <if test="activityName != null and activityName != '' ">
  1032. and b.title like concat('%', #{activityName}, '%')
  1033. </if>
  1034. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1035. and b.building_id in
  1036. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1037. #{taPersonBuilding.buildingId}
  1038. </foreach>
  1039. </if>
  1040. union all
  1041. select c.group_activity_id as activityId, c.activity_name as activityName, "group" as activityType From
  1042. ta_share_activity c
  1043. where c.org_id = #{orgId}
  1044. <if test="buildingId != null and buildingId != '' ">
  1045. and c.building_id = #{buildingId}
  1046. </if>
  1047. <if test="activityName != null and activityName != '' ">
  1048. and c.activity_name like concat('%', #{activityName}, '%')
  1049. </if>
  1050. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1051. and c.building_id in
  1052. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1053. #{taPersonBuilding.buildingId}
  1054. </foreach>
  1055. </if>
  1056. union all
  1057. select d.drainage_id as activityId, d.name as activityName, "h5" as activityType from ta_drainage d
  1058. where d.org_id = #{orgId}
  1059. <if test="buildingId != null and buildingId != '' ">
  1060. and d.building_id = #{buildingId}
  1061. </if>
  1062. <if test="activityName != null and activityName != '' ">
  1063. and d.name like concat('%', #{activityName}, '%')
  1064. </if>
  1065. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1066. and (d.building_id in
  1067. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1068. #{taPersonBuilding.buildingId}
  1069. </foreach>
  1070. or d.create_user = #{userId}
  1071. )
  1072. </if>
  1073. union all
  1074. select e.live_activity_id as activityId, e.live_activity_title as activityName, "live" as activityType From
  1075. ta_live_activity e
  1076. where e.org_id = #{orgId}
  1077. <if test="buildingId != null and buildingId != '' ">
  1078. and e.building_id = #{buildingId}
  1079. </if>
  1080. <if test="activityName != null and activityName != '' ">
  1081. and e.live_activity_title like concat('%', #{activityName}, '%')
  1082. </if>
  1083. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1084. and (e.building_id in
  1085. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1086. #{taPersonBuilding.buildingId}
  1087. </foreach>
  1088. or e.create_user = #{userId}
  1089. )
  1090. </if>
  1091. ) as activity
  1092. left join (
  1093. SELECT count(1) as shareNum, 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
  1094. FROM ta_share_count a where a.tagert_type in (
  1095. 'activity', 'group','h5','help','liveApp','livePost')
  1096. and a.org_id = #{orgId}
  1097. <if test="targetType != null and targetType != ''">
  1098. and (case when #{targetType} = 'live' then a.tagert_type in ('liveApp', 'livePost') else a.tagert_type = #{targetType}
  1099. end)
  1100. </if>
  1101. <if test="startDate != null ">
  1102. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1103. </if>
  1104. <if test="endDate != null ">
  1105. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1106. </if>
  1107. <if test="startDate == null or endDate == null ">
  1108. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1109. </if>
  1110. group by a.be_share,a.tagert_type order by a.create_date desc limit 9999999
  1111. ) as shareNum on shareNum.be_share = activity.activityId and shareNum.tagert_type = activity.activityType
  1112. left join (
  1113. SELECT count(*) as sharePersonNum ,sharePersonNum.be_share, sharePersonNum.tagert_type, sharePersonNum.create_date from (
  1114. 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
  1115. From ta_share_count a where a.tagert_type in ( 'activity', 'group','h5','help','liveApp','livePost')
  1116. and a.org_id = #{orgId}
  1117. <if test="targetType != null and targetType != ''">
  1118. and (case when #{targetType} = 'live' then a.tagert_type in ('liveApp', 'livePost') else a.tagert_type = #{targetType}
  1119. end)
  1120. </if>
  1121. <if test="startDate != null ">
  1122. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1123. </if>
  1124. <if test="endDate != null ">
  1125. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1126. </if>
  1127. <if test="startDate == null or endDate == null ">
  1128. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1129. </if>
  1130. group by a.person_id, be_share
  1131. <!-- , be_share, tagert_type-->
  1132. ) as sharePersonNum group by sharePersonNum.be_share, sharePersonNum.tagert_type
  1133. ) as sharePersonNum on sharePersonNum.be_share = activity.activityId and sharePersonNum.tagert_type =
  1134. activity.activityType
  1135. left join (
  1136. 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
  1137. From ta_person_visit_record a where a.event_type in
  1138. ('activity','group','h5','help') and a.`event` = 'detail' and a.org_id = #{orgId}
  1139. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1140. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType}
  1141. end)
  1142. </if>
  1143. <if test="startDate != null">
  1144. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1145. </if>
  1146. <if test="endDate != null">
  1147. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1148. </if>
  1149. <if test="startDate == null or endDate == null ">
  1150. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1151. </if>
  1152. group by a.target_id, a.target_type
  1153. ) as visitNum on visitNum.target_id = activity.activityId and visitNum.target_type = activity.activityType
  1154. left join (
  1155. 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
  1156. From ta_person_visit_record a where a.event_type in ('activity','group','h5','help') and a.`event` =
  1157. 'detail' and a.org_id = #{orgId}
  1158. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1159. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType}
  1160. end)
  1161. </if>
  1162. <if test="startDate != null">
  1163. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1164. </if>
  1165. <if test="endDate != null">
  1166. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1167. </if>
  1168. <if test="startDate == null or endDate == null ">
  1169. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1170. </if>
  1171. group by a.target_id, a.target_type
  1172. ) as visitPersonNum on visitPersonNum.target_id = activity.activityId and visitPersonNum.event_type =
  1173. activity.activityType
  1174. left join (
  1175. select count(*) as addRegistNum ,addRegistNum.target_id, addRegistNum.target_type From (
  1176. select count(*), a.* From ta_share_person_from a where a.target_type IN ( 'dynamic_share', 'h5_share',
  1177. 'help_share', 'live_share', 'group_share' ) and a.org_id = #{orgId}
  1178. and a.status = 1
  1179. and a.is_first_time = 1
  1180. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1181. and a.target_type = concat(REPLACE(#{targetType}, 'activity', 'dynamic'), '_share')
  1182. </if>
  1183. <if test="startDate != null ">
  1184. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1185. </if>
  1186. <if test="endDate != null ">
  1187. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1188. </if>
  1189. <if test="startDate == null or endDate == null">
  1190. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1191. </if>
  1192. group by a.person_id, a.target_type ,a.target_id
  1193. ) as addRegistNum group by addRegistNum.target_type, addRegistNum.target_id
  1194. ) as addRegistNum on addRegistNum.target_id = activity.activityId and activity.activityType = substring_index(REPLACE(addRegistNum.target_type, 'dynamic_share', 'activity_share') , '_share', 1)
  1195. <if test="targetType != null and targetType != ''">
  1196. where activity.activityType = #{targetType}
  1197. </if>
  1198. group by activity.activityId, activity.activityType
  1199. <if test="colKey == null or colKey == ''">
  1200. order by sharePersonNum.create_date desc
  1201. </if>
  1202. <if test="colKey != null and colKey != ''">
  1203. ORDER BY ${colKey} ${sortType}
  1204. </if>
  1205. </select>
  1206. <select id="selectActivityStatisDetailExport"
  1207. resultType="com.huiju.estateagents.excel.ActivityStatistics.ActivityDetailShareRecord">
  1208. select
  1209. activity.*,
  1210. ifnull(shareNum.shareNum, 0) as shareNum,
  1211. ifnull(sharePersonNum.sharePersonNum, 0) as sharePersonNum,
  1212. ifnull(visitNum.visitNum, 0) as visitNum,
  1213. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1214. ifnull(addRegistNum.addRegistNum, 0) as addRegistNum
  1215. from (
  1216. select a.dynamic_id as activityId, a.title as activityName, "activity" as activityType from ta_building_dynamic
  1217. a
  1218. where org_id = #{orgId}
  1219. <if test="buildingId != null and buildingId != '' ">
  1220. and a.building_id = #{buildingId}
  1221. </if>
  1222. <if test="activityName != null and activityName != '' ">
  1223. and a.title like concat('%', #{activityName}, '%')
  1224. </if>
  1225. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1226. and a.building_id in
  1227. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1228. #{taPersonBuilding.buildingId}
  1229. </foreach>
  1230. </if>
  1231. union all
  1232. select b.help_activity_id activityId, b.title as activityName, "help" as activityType from ta_help_activity b
  1233. where b.org_id = #{orgId}
  1234. <if test="buildingId != null and buildingId != '' ">
  1235. and b.building_id = #{buildingId}
  1236. </if>
  1237. <if test="activityName != null and activityName != '' ">
  1238. and b.title like concat('%', #{activityName}, '%')
  1239. </if>
  1240. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1241. and b.building_id in
  1242. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1243. #{taPersonBuilding.buildingId}
  1244. </foreach>
  1245. </if>
  1246. union all
  1247. select c.group_activity_id as activityId, c.activity_name as activityName, "group" as activityType From
  1248. ta_share_activity c
  1249. where c.org_id = #{orgId}
  1250. <if test="buildingId != null and buildingId != '' ">
  1251. and c.building_id = #{buildingId}
  1252. </if>
  1253. <if test="activityName != null and activityName != '' ">
  1254. and c.activity_name like concat('%', #{activityName}, '%')
  1255. </if>
  1256. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1257. and c.building_id in
  1258. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1259. #{taPersonBuilding.buildingId}
  1260. </foreach>
  1261. </if>
  1262. union all
  1263. select d.drainage_id as activityId, d.name as activityName, "h5" as activityType from ta_drainage d
  1264. where d.org_id = #{orgId}
  1265. <if test="buildingId != null and buildingId != '' ">
  1266. and d.building_id = #{buildingId}
  1267. </if>
  1268. <if test="activityName != null and activityName != '' ">
  1269. and d.name like concat('%', #{activityName}, '%')
  1270. </if>
  1271. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1272. and (d.building_id in
  1273. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1274. #{taPersonBuilding.buildingId}
  1275. </foreach>
  1276. or d.create_user = #{userId}
  1277. )
  1278. </if>
  1279. union all
  1280. select e.live_activity_id as activityId, e.live_activity_title as activityName, "live" as activityType From
  1281. ta_live_activity e
  1282. where e.org_id = #{orgId}
  1283. <if test="buildingId != null and buildingId != '' ">
  1284. and e.building_id = #{buildingId}
  1285. </if>
  1286. <if test="activityName != null and activityName != '' ">
  1287. and e.live_activity_title like concat('%', #{activityName}, '%')
  1288. </if>
  1289. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1290. and (e.building_id in
  1291. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1292. #{taPersonBuilding.buildingId}
  1293. </foreach>
  1294. or e.create_user = #{userId}
  1295. )
  1296. </if>
  1297. ) as activity
  1298. left join (
  1299. SELECT count(1) as shareNum, 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
  1300. FROM ta_share_count a where a.tagert_type in (
  1301. 'activity', 'group','h5','help','liveApp','livePost')
  1302. and a.org_id = #{orgId}
  1303. <if test="targetType != null and targetType != ''">
  1304. and (case when #{targetType} = 'live' then a.tagert_type in ('liveApp', 'livePost') else a.tagert_type = #{targetType}
  1305. end)
  1306. </if>
  1307. <if test="startDate != null ">
  1308. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1309. </if>
  1310. <if test="endDate != null ">
  1311. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1312. </if>
  1313. <if test="startDate == null or endDate == null ">
  1314. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1315. </if>
  1316. group by a.be_share,a.tagert_type order by a.create_date desc limit 9999999
  1317. ) as shareNum on shareNum.be_share = activity.activityId and shareNum.tagert_type = activity.activityType
  1318. left join (
  1319. SELECT count(*) as sharePersonNum ,sharePersonNum.be_share, sharePersonNum.tagert_type, sharePersonNum.create_date from (
  1320. 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
  1321. From ta_share_count a where a.tagert_type in ( 'activity', 'group','h5','help','liveApp','livePost')
  1322. and a.org_id = #{orgId}
  1323. <if test="targetType != null and targetType != ''">
  1324. and (case when #{targetType} = 'live' then a.tagert_type in ('liveApp', 'livePost') else a.tagert_type = #{targetType}
  1325. end)
  1326. </if>
  1327. <if test="startDate != null ">
  1328. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1329. </if>
  1330. <if test="endDate != null ">
  1331. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1332. </if>
  1333. <if test="startDate == null or endDate == null ">
  1334. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1335. </if>
  1336. group by a.person_id, be_share
  1337. <!-- , be_share, tagert_type-->
  1338. ) as sharePersonNum group by sharePersonNum.be_share, sharePersonNum.tagert_type
  1339. ) as sharePersonNum on sharePersonNum.be_share = activity.activityId and sharePersonNum.tagert_type =
  1340. activity.activityType
  1341. left join (
  1342. 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
  1343. From ta_person_visit_record a where a.event_type in
  1344. ('activity','group','h5','help') and a.`event` = 'detail' and a.org_id = #{orgId}
  1345. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1346. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType}
  1347. end)
  1348. </if>
  1349. <if test="startDate != null">
  1350. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1351. </if>
  1352. <if test="endDate != null">
  1353. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1354. </if>
  1355. <if test="startDate == null or endDate == null ">
  1356. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1357. </if>
  1358. group by a.target_id, a.target_type
  1359. ) as visitNum on visitNum.target_id = activity.activityId and visitNum.target_type = activity.activityType
  1360. left join (
  1361. 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
  1362. From ta_person_visit_record a where a.event_type in ('activity','group','h5','help') and a.`event` =
  1363. 'detail' and a.org_id = #{orgId}
  1364. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1365. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType}
  1366. end)
  1367. </if>
  1368. <if test="startDate != null">
  1369. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1370. </if>
  1371. <if test="endDate != null">
  1372. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1373. </if>
  1374. <if test="startDate == null or endDate == null ">
  1375. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1376. </if>
  1377. group by a.target_id, a.target_type
  1378. ) as visitPersonNum on visitPersonNum.target_id = activity.activityId and visitPersonNum.event_type =
  1379. activity.activityType
  1380. left join (
  1381. select count(*) as addRegistNum ,addRegistNum.target_id, addRegistNum.target_type From (
  1382. select count(*), a.* From ta_share_person_from a where a.target_type IN ( 'dynamic_share', 'h5_share',
  1383. 'help_share', 'live_share', 'group_share' ) and a.org_id = #{orgId}
  1384. and a.status = 1
  1385. and a.is_first_time = 1
  1386. <if test="targetType != null and targetType != '' and targetType != 'h5'">
  1387. and a.target_type = concat(REPLACE(#{targetType}, 'activity', 'dynamic'), '_share')
  1388. </if>
  1389. <if test="startDate != null ">
  1390. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  1391. </if>
  1392. <if test="endDate != null ">
  1393. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  1394. </if>
  1395. <if test="startDate == null or endDate == null">
  1396. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1397. </if>
  1398. group by a.person_id, a.target_type ,a.target_id
  1399. ) as addRegistNum group by addRegistNum.target_type, addRegistNum.target_id
  1400. ) as addRegistNum on addRegistNum.target_id = activity.activityId and activity.activityType = substring_index(REPLACE(addRegistNum.target_type, 'dynamic_share', 'activity_share') , '_share', 1)
  1401. <if test="targetType != null and targetType != ''">
  1402. where activity.activityType = #{targetType}
  1403. </if>
  1404. group by activity.activityId, activity.activityType
  1405. <if test="colKey == null or colKey == ''">
  1406. order by sharePersonNum.create_date desc
  1407. </if>
  1408. <if test="colKey != null and colKey != ''">
  1409. ORDER BY ${colKey} ${sortType}
  1410. </if>
  1411. </select>
  1412. <select id="selectActivitySharePersonNum"
  1413. resultType="com.huiju.estateagents.excel.ActivityStatistics.SharePersonNum">
  1414. select person.nickname as sharePersonName,
  1415. ifnull(person.phone, '空') as sharePersonPhone ,
  1416. ifnull(shareNum, 0) as shareNum,
  1417. ifnull(visitNum, 0) as visitNum,
  1418. ifnull(visitPersonNum, 0) as visitPersonNum,
  1419. person.person_type as sharePersonType,
  1420. person.person_id
  1421. from (
  1422. SELECT t.*, f.nickname, f.phone, f.person_type
  1423. FROM ta_share_count t
  1424. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1425. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1426. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1427. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1428. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1429. LEFT JOIN ta_person f
  1430. ON t.person_id = f.person_id
  1431. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1432. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1433. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1434. <if test="buildingId != null and buildingId != ''">
  1435. and (
  1436. a.building_id = #{buildingId}
  1437. or b.building_id = #{buildingId}
  1438. or c.building_id = #{buildingId}
  1439. or d.building_id = #{buildingId}
  1440. or e.building_id = #{buildingId}
  1441. )
  1442. </if>
  1443. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1444. AND
  1445. (a.building_id in
  1446. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1447. #{taPersonBuilding.buildingId}
  1448. </foreach>
  1449. or
  1450. b.building_id in
  1451. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1452. #{taPersonBuilding.buildingId}
  1453. </foreach>
  1454. or
  1455. e.building_id in
  1456. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1457. #{taPersonBuilding.buildingId}
  1458. </foreach>
  1459. or
  1460. c.building_id in
  1461. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1462. #{taPersonBuilding.buildingId}
  1463. </foreach>
  1464. or
  1465. d.building_id in
  1466. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1467. #{taPersonBuilding.buildingId}
  1468. </foreach>
  1469. or d.create_user = #{userId}
  1470. or c.create_user = #{userId}
  1471. )
  1472. </if>
  1473. <if test="activityId != null and activityId != ''">
  1474. and t.be_share = #{activityId}
  1475. </if>
  1476. <if test="activityType != null and activityType != ''">
  1477. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1478. end)
  1479. </if>
  1480. <if test="sharePersonType != null and sharePersonType != ''">
  1481. and f.person_type = #{sharePersonType}
  1482. </if>
  1483. <if test="sharePersonName != null and sharePersonName != ''">
  1484. and f.nickname like CONCAT('%',#{sharePersonName}, '%')
  1485. </if>
  1486. <if test="sharePhone != null and sharePhone != ''">
  1487. and f.phone like CONCAT('%',#{sharePhone}, '%')
  1488. </if>
  1489. GROUP BY t.person_id
  1490. ) as person
  1491. left join (
  1492. select count(*) as shareNum, temp.person_id from (
  1493. SELECT t.person_id, t.create_date
  1494. FROM ta_share_count t
  1495. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1496. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1497. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1498. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1499. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1500. LEFT JOIN ta_person f
  1501. ON t.person_id = f.person_id
  1502. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1503. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1504. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1505. <if test="activityId != null and activityId != ''">
  1506. and t.be_share = #{activityId}
  1507. </if>
  1508. <if test="activityType != null and activityType != ''">
  1509. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1510. end)
  1511. </if>
  1512. order by t.create_date desc limit 999999
  1513. ) as temp group by temp.person_id order by temp.create_date desc
  1514. ) as shareNum on person.person_id = shareNum.person_id
  1515. left join (
  1516. SELECT t.visitNum, ifnull(a.person_id,b.person_id) AS person_id
  1517. FROM (
  1518. SELECT t.share_person, count(1) as visitNum
  1519. FROM ta_share_person_from t
  1520. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S') AND t.create_date &lt;=
  1521. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S') AND t.target_type IN ('dynamic_share', 'h5_share', 'help_share',
  1522. 'live_share', 'group_share')
  1523. <if test="activityId != null and activityId != ''">
  1524. and t.target_id = #{activityId}
  1525. </if>
  1526. <if test="activityType != null and activityType != ''">
  1527. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1528. </if>
  1529. and t.org_id = #{orgId} ) t
  1530. left join ta_person a on t.share_person = a.person_id
  1531. left join ta_person b on t.share_person = b.user_id
  1532. ) as visitNum on visitNum.person_id = person.person_id
  1533. left join (
  1534. SELECT t.visitPersonNum, ifnull(a.person_id,b.person_id) AS person_id
  1535. FROM (
  1536. SELECT count(DISTINCT t.person_id ) as visitPersonNum, t.share_person
  1537. FROM ta_share_person_from t
  1538. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1539. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1540. <if test="activityId != null and activityId != ''">
  1541. and t.target_id = #{activityId}
  1542. </if>
  1543. <if test="activityType != null and activityType != ''">
  1544. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1545. </if>
  1546. and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1547. and t.org_id = #{orgId}
  1548. <!-- group by t.share_person -->
  1549. ) t
  1550. left join ta_person a on t.share_person = a.person_id
  1551. left join ta_person b on t.share_person = b.user_id
  1552. ) as visitPersonNum on visitPersonNum.person_id = person.person_id
  1553. group by person.person_id
  1554. <if test="colKey == null or colKey == ''">
  1555. order by person.create_date desc
  1556. </if>
  1557. <if test="colKey != null and colKey != ''">
  1558. ORDER BY ${colKey} ${sort}
  1559. </if>
  1560. </select>
  1561. <select id="selectActivitySharePersonNumExport"
  1562. resultType="com.huiju.estateagents.excel.ActivityStatistics.SharePersonNum">
  1563. select person.nickname as sharePersonName,
  1564. ifnull(person.phone, '空') as sharePersonPhone ,
  1565. ifnull(shareNum, 0) as shareNum,
  1566. ifnull(visitNum, 0) as visitNum,
  1567. ifnull(visitPersonNum, 0) as visitPersonNum,
  1568. CASE
  1569. WHEN person.person_type = 'drift' THEN
  1570. "游客"
  1571. WHEN person.person_type = 'customer' THEN
  1572. "普通客户"
  1573. WHEN person.person_type = 'Realty Consultant' THEN
  1574. "置业顾问"
  1575. END `sharePersonType`,
  1576. person.person_id
  1577. from (
  1578. SELECT t.*, f.nickname, f.phone, f.person_type
  1579. FROM ta_share_count t
  1580. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1581. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1582. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1583. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1584. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1585. LEFT JOIN ta_person f
  1586. ON t.person_id = f.person_id
  1587. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1588. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1589. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1590. <if test="buildingId != null and buildingId != ''">
  1591. and (
  1592. a.building_id = #{buildingId}
  1593. or b.building_id = #{buildingId}
  1594. or c.building_id = #{buildingId}
  1595. or d.building_id = #{buildingId}
  1596. or e.building_id = #{buildingId}
  1597. )
  1598. </if>
  1599. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1600. AND
  1601. (a.building_id in
  1602. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1603. #{taPersonBuilding.buildingId}
  1604. </foreach>
  1605. or
  1606. b.building_id in
  1607. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1608. #{taPersonBuilding.buildingId}
  1609. </foreach>
  1610. or
  1611. e.building_id in
  1612. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1613. #{taPersonBuilding.buildingId}
  1614. </foreach>
  1615. or
  1616. c.building_id in
  1617. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1618. #{taPersonBuilding.buildingId}
  1619. </foreach>
  1620. or
  1621. d.building_id in
  1622. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1623. #{taPersonBuilding.buildingId}
  1624. </foreach>
  1625. or d.create_user = #{userId}
  1626. or c.create_user = #{userId}
  1627. )
  1628. </if>
  1629. <if test="activityId != null and activityId != ''">
  1630. and t.be_share = #{activityId}
  1631. </if>
  1632. <if test="activityType != null and activityType != ''">
  1633. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1634. end)
  1635. </if>
  1636. <if test="sharePersonType != null and sharePersonType != ''">
  1637. and f.person_type = #{sharePersonType}
  1638. </if>
  1639. <if test="sharePersonName != null and sharePersonName != ''">
  1640. and f.nickname like CONCAT('%',#{sharePersonName}, '%')
  1641. </if>
  1642. <if test="sharePhone != null and sharePhone != ''">
  1643. and f.phone like CONCAT('%',#{sharePhone}, '%')
  1644. </if>
  1645. GROUP BY t.person_id
  1646. ) as person
  1647. left join (
  1648. select count(*) as shareNum, temp.person_id from (
  1649. SELECT t.person_id, t.create_date
  1650. FROM ta_share_count t
  1651. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1652. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1653. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1654. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1655. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1656. LEFT JOIN ta_person f
  1657. ON t.person_id = f.person_id
  1658. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1659. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1660. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1661. <if test="activityId != null and activityId != ''">
  1662. and t.be_share = #{activityId}
  1663. </if>
  1664. <if test="activityType != null and activityType != ''">
  1665. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1666. end)
  1667. </if>
  1668. order by t.create_date desc limit 999999
  1669. ) as temp group by temp.person_id order by temp.create_date desc
  1670. ) as shareNum on person.person_id = shareNum.person_id
  1671. left join (
  1672. SELECT t.visitNum, ifnull(a.person_id,b.person_id) AS person_id
  1673. FROM (
  1674. SELECT t.share_person, count(1) as visitNum
  1675. FROM ta_share_person_from t
  1676. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S') AND t.create_date &lt;=
  1677. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S') AND t.target_type IN ('dynamic_share', 'h5_share', 'help_share',
  1678. 'live_share', 'group_share')
  1679. <if test="activityId != null and activityId != ''">
  1680. and t.target_id = #{activityId}
  1681. </if>
  1682. <if test="activityType != null and activityType != ''">
  1683. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1684. </if>
  1685. and t.org_id = #{orgId} ) t
  1686. left join ta_person a on t.share_person = a.person_id
  1687. left join ta_person b on t.share_person = b.user_id
  1688. ) as visitNum on visitNum.person_id = person.person_id
  1689. left join (
  1690. SELECT t.visitPersonNum, ifnull(a.person_id,b.person_id) AS person_id
  1691. FROM (
  1692. SELECT count(DISTINCT t.person_id ) as visitPersonNum, t.share_person
  1693. FROM ta_share_person_from t
  1694. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  1695. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1696. <if test="activityId != null and activityId != ''">
  1697. and t.target_id = #{activityId}
  1698. </if>
  1699. <if test="activityType != null and activityType != ''">
  1700. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1701. </if>
  1702. and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1703. and t.org_id = #{orgId}
  1704. <!-- group by t.share_person -->
  1705. ) t
  1706. left join ta_person a on t.share_person = a.person_id
  1707. left join ta_person b on t.share_person = b.user_id
  1708. ) as visitPersonNum on visitPersonNum.person_id = person.person_id
  1709. group by person.person_id
  1710. <if test="colKey == null or colKey == ''">
  1711. order by person.create_date desc
  1712. </if>
  1713. <if test="colKey != null and colKey != ''">
  1714. ORDER BY ${colKey} ${sort}
  1715. </if>
  1716. </select>
  1717. <select id="selectActivityShareNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.ShareNum">
  1718. select person.nickname as sharePersonName,
  1719. ifnull(person.phone, '空') as sharePersonPhone ,
  1720. person.create_date as shareTime,
  1721. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1722. person.person_type as sharePersonType
  1723. FROM (
  1724. SELECT t.*, f.nickname, f.phone, f.person_type
  1725. FROM ta_share_count t
  1726. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1727. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1728. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1729. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1730. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1731. LEFT JOIN ta_person f ON t.person_id = f.person_id
  1732. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost')
  1733. <if test="activityId != null and activityId != ''">
  1734. and t.be_share = #{activityId}
  1735. </if>
  1736. <if test="activityType != null and activityType != ''">
  1737. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1738. end)
  1739. </if>
  1740. <if test="buildingId != null and buildingId != ''">
  1741. and (
  1742. a.building_id = #{buildingId}
  1743. or b.building_id = #{buildingId}
  1744. or c.building_id = #{buildingId}
  1745. or d.building_id = #{buildingId}
  1746. or e.building_id = #{buildingId}
  1747. )
  1748. </if>
  1749. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1750. AND
  1751. (a.building_id in
  1752. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1753. #{taPersonBuilding.buildingId}
  1754. </foreach>
  1755. or
  1756. b.building_id in
  1757. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1758. #{taPersonBuilding.buildingId}
  1759. </foreach>
  1760. or
  1761. e.building_id in
  1762. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1763. #{taPersonBuilding.buildingId}
  1764. </foreach>
  1765. or
  1766. c.building_id in
  1767. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1768. #{taPersonBuilding.buildingId}
  1769. </foreach>
  1770. or
  1771. d.building_id in
  1772. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1773. #{taPersonBuilding.buildingId}
  1774. </foreach>
  1775. or d.create_user = #{userId}
  1776. or c.create_user = #{userId}
  1777. )
  1778. </if>
  1779. and t.org_id = #{orgId}
  1780. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' )
  1781. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1782. <if test="personId != null and personId != ''">
  1783. and t.person_id = #{personId}
  1784. </if>
  1785. <if test="sharePersonName != null and sharePersonName != ''">
  1786. and f.nickname like CONCAT('%',#{sharePersonName}, '%')
  1787. </if>
  1788. <if test="sharePhone != null and sharePhone != ''">
  1789. and f.phone like CONCAT('%',#{sharePhone}, '%')
  1790. </if>
  1791. <if test="sharePersonType != null and sharePersonType != ''">
  1792. and f.person_type = #{sharePersonType}
  1793. </if>
  1794. ) as person
  1795. LEFT JOIN (
  1796. SELECT count(DISTINCT(t.person_id)) as visitPersonNum, ifnull(a.person_id,b.person_id) as person_id
  1797. FROM ta_share_person_from t
  1798. left join ta_person a on t.share_person = a.person_id
  1799. left join ta_person b on t.share_person = b.user_id
  1800. where t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  1801. <if test="activityId != null and activityId != ''">
  1802. and t.target_id = #{activityId}
  1803. </if>
  1804. <if test="activityType != null and activityType != ''">
  1805. and t.target_type = concat(#{activityType}, '_share')
  1806. </if>
  1807. <if test="personId != null and personId != ''">
  1808. and t.share_person = #{personId}
  1809. </if>
  1810. <if test="startDate != null ">
  1811. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  1812. </if>
  1813. <if test="endDate != null ">
  1814. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1815. </if>
  1816. ) as visitPersonNum
  1817. ON visitPersonNum.person_id = person.person_id order by person.create_date desc
  1818. </select>
  1819. <select id="selectActivityShareNumExport" resultType="com.huiju.estateagents.excel.ActivityStatistics.ShareNum">
  1820. select person.nickname as sharePersonName,
  1821. ifnull(person.phone, '空') as sharePersonPhone ,
  1822. person.create_date as shareTime,
  1823. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1824. CASE
  1825. WHEN person.person_type = 'drift' THEN
  1826. "游客"
  1827. WHEN person.person_type = 'customer' THEN
  1828. "普通客户"
  1829. WHEN person.person_type = 'Realty Consultant' THEN
  1830. "置业顾问"
  1831. END `sharePersonType`
  1832. FROM (
  1833. SELECT t.*, f.nickname, f.phone, f.person_type
  1834. FROM ta_share_count t
  1835. LEFT JOIN ta_help_activity a ON t.be_share = a.help_activity_id
  1836. LEFT JOIN ta_share_activity b ON t.be_share = b.share_id
  1837. LEFT JOIN ta_live_activity c ON t.be_share = c.live_activity_id
  1838. LEFT JOIN ta_drainage d ON t.be_share = d.drainage_id
  1839. LEFT JOIN ta_building_dynamic e ON t.be_share = e.dynamic_id
  1840. LEFT JOIN ta_person f ON t.person_id = f.person_id
  1841. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost')
  1842. <if test="activityId != null and activityId != ''">
  1843. and t.be_share = #{activityId}
  1844. </if>
  1845. <if test="activityType != null and activityType != ''">
  1846. and (case when #{activityType} = 'live' then t.tagert_type in ('liveApp', 'livePost') else t.tagert_type = #{activityType}
  1847. end)
  1848. </if>
  1849. <if test="buildingId != null and buildingId != ''">
  1850. and (
  1851. a.building_id = #{buildingId}
  1852. or b.building_id = #{buildingId}
  1853. or c.building_id = #{buildingId}
  1854. or d.building_id = #{buildingId}
  1855. or e.building_id = #{buildingId}
  1856. )
  1857. </if>
  1858. <if test="taPersonBuildings != null and taPersonBuildings.size > 0">
  1859. AND
  1860. (a.building_id in
  1861. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1862. #{taPersonBuilding.buildingId}
  1863. </foreach>
  1864. or
  1865. b.building_id in
  1866. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1867. #{taPersonBuilding.buildingId}
  1868. </foreach>
  1869. or
  1870. e.building_id in
  1871. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1872. #{taPersonBuilding.buildingId}
  1873. </foreach>
  1874. or
  1875. c.building_id in
  1876. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1877. #{taPersonBuilding.buildingId}
  1878. </foreach>
  1879. or
  1880. d.building_id in
  1881. <foreach collection="taPersonBuildings" item="taPersonBuilding" open="(" close=")" separator=",">
  1882. #{taPersonBuilding.buildingId}
  1883. </foreach>
  1884. or d.create_user = #{userId}
  1885. or c.create_user = #{userId}
  1886. )
  1887. </if>
  1888. and t.org_id = #{orgId}
  1889. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' )
  1890. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1891. <if test="personId != null and personId != ''">
  1892. and t.person_id = #{personId}
  1893. </if>
  1894. <if test="sharePersonName != null and sharePersonName != ''">
  1895. and f.nickname like CONCAT('%',#{sharePersonName}, '%')
  1896. </if>
  1897. <if test="sharePhone != null and sharePhone != ''">
  1898. and f.phone like CONCAT('%',#{sharePhone}, '%')
  1899. </if>
  1900. <if test="sharePersonType != null and sharePersonType != ''">
  1901. and f.person_type = #{sharePersonType}
  1902. </if>
  1903. ) as person
  1904. LEFT JOIN (
  1905. SELECT count(DISTINCT(t.person_id)) as visitPersonNum, ifnull(a.person_id,b.person_id) as person_id
  1906. FROM ta_share_person_from t
  1907. left join ta_person a on t.share_person = a.person_id
  1908. left join ta_person b on t.share_person = b.user_id
  1909. where t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  1910. <if test="activityId != null and activityId != ''">
  1911. and t.target_id = #{activityId}
  1912. </if>
  1913. <if test="activityType != null and activityType != ''">
  1914. and t.target_type = concat(#{activityType}, '_share')
  1915. </if>
  1916. <if test="personId != null and personId != ''">
  1917. and t.share_person = #{personId}
  1918. </if>
  1919. <if test="startDate != null ">
  1920. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  1921. </if>
  1922. <if test="endDate != null ">
  1923. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1924. </if>
  1925. ) as visitPersonNum
  1926. ON visitPersonNum.person_id = person.person_id order by person.create_date desc
  1927. </select>
  1928. <select id="selectActivityAddRegistNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.AddRegistNum">
  1929. SELECT
  1930. a.nickname, a.phone,
  1931. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1932. a.province,
  1933. b1.scene_alias as personFrom,
  1934. GROUP_CONCAT(d.user_name) as realtyConsultant,
  1935. d.phone as realtyConsultantPhone,
  1936. ifnull(e.nickname, f.name) as sharePersonName,
  1937. ifnull(e.phone, f.phone) as sharePersonPhone
  1938. FROM ta_share_person_from t
  1939. left join ta_person a on t.person_id = a.person_id
  1940. 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
  1941. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1942. left join ta_recommend_customer c on c.person_id = t.person_id
  1943. LEFT JOIN ta_user d ON c.realty_consultant = d.user_id
  1944. LEFT JOIN ta_person e ON t.share_person = e.person_id
  1945. LEFT JOIN ta_person f ON t.share_person = f.user_id
  1946. WHERE t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id =
  1947. #{orgId} and t.status = 1
  1948. and t.is_first_time = 1
  1949. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d' ) and t.create_date &lt;= DATE_FORMAT(#{endDate},
  1950. '%Y-%m-%d' )
  1951. <if test="activityId != null and activityId != ''">
  1952. and t.target_id = #{activityId}
  1953. </if>
  1954. <if test="activityType != null and activityType != ''">
  1955. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1956. </if>
  1957. <if test="province != null and province != ''">
  1958. and a.province like concat('%', #{province}, '%')
  1959. </if>
  1960. <if test="personFrom != null and personFrom != ''">
  1961. and b.scene_type = #{personFrom}
  1962. </if>
  1963. <if test="buildingId != null and buildingId != ''">
  1964. and c.building_id = #{buildingId}
  1965. </if>
  1966. group by t.person_id order by t.create_date desc
  1967. </select>
  1968. <select id="selectActivityAddRegistNumExport"
  1969. resultType="com.huiju.estateagents.excel.ActivityStatistics.AddRegistNum">
  1970. SELECT
  1971. a.nickname, a.phone,
  1972. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1973. a.province,
  1974. b1.scene_alias as personFrom,
  1975. GROUP_CONCAT(d.user_name) as realtyConsultant,
  1976. d.phone as realtyConsultantPhone,
  1977. ifnull(e.nickname, f.name) as sharePersonName,
  1978. ifnull(e.phone, f.phone) as sharePersonPhone
  1979. FROM ta_share_person_from t
  1980. left join ta_person a on t.person_id = a.person_id
  1981. 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
  1982. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1983. left join ta_recommend_customer c on c.person_id = t.person_id
  1984. LEFT JOIN ta_user d ON c.realty_consultant = d.user_id
  1985. LEFT JOIN ta_person e ON t.share_person = e.person_id
  1986. LEFT JOIN ta_person f ON t.share_person = f.user_id
  1987. WHERE t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id =
  1988. #{orgId} and t.status = 1
  1989. and t.is_first_time = 1
  1990. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d' ) and t.create_date &lt;= DATE_FORMAT(#{endDate},
  1991. '%Y-%m-%d' )
  1992. <if test="activityId != null and activityId != ''">
  1993. and t.target_id = #{activityId}
  1994. </if>
  1995. <if test="activityType != null and activityType != ''">
  1996. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  1997. </if>
  1998. <if test="province != null and province != ''">
  1999. and a.province like concat('%', #{province}, '%')
  2000. </if>
  2001. <if test="personFrom != null and personFrom != ''">
  2002. and b.scene_type = #{personFrom}
  2003. </if>
  2004. <if test="buildingId != null and buildingId != ''">
  2005. and c.building_id = #{buildingId}
  2006. </if>
  2007. group by t.person_id order by t.create_date desc
  2008. </select>
  2009. <select id="selectActivityVisitNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  2010. select
  2011. a.nickname, a.phone,
  2012. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2013. a.province,
  2014. b1.scene_alias as personFrom,
  2015. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2016. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2017. e.nickname as sharePersonName,
  2018. e.phone as sharePersonPhone,
  2019. t.visit_time as visitDate
  2020. From (
  2021. SELECT
  2022. t.person_id, t.visit_time, t.share_person_id
  2023. FROM
  2024. ta_person_visit_record t
  2025. WHERE
  2026. t.`event` = 'detail'
  2027. AND t.event_type IN (
  2028. 'activity',
  2029. 'help',
  2030. 'group',
  2031. 'h5'
  2032. )
  2033. <if test="activityId != null and activityId != ''">
  2034. and t.target_id = #{activityId}
  2035. </if>
  2036. <if test="activityType != null and activityType != ''">
  2037. and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' when #{activityType} = 'h5' then t.event_type = 'h5' else t.target_type = #{activityType}
  2038. end)
  2039. </if>
  2040. <if test="buildingId != null and buildingId != ''">
  2041. and t.building_id = #{buildingId}
  2042. </if>
  2043. AND t.org_id = #{orgId}
  2044. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  2045. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  2046. ) t
  2047. left join ta_person a on t.person_id = a.person_id
  2048. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2049. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2050. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2051. left join ta_user d on c.realty_consultant = d.user_id
  2052. left join ta_person e on t.share_person_id = e.person_id
  2053. <where>
  2054. <if test="personFrom != null and personFrom != ''">
  2055. and b.scene_type = #{personFrom}
  2056. </if>
  2057. <if test="province != null and province != ''">
  2058. and a.province like concat('%', #{province}, '%')
  2059. </if>
  2060. <if test="realtyConsultant != null and realtyConsultant != ''">
  2061. and d.user_name like concat('%', #{realtyConsultant}, '%')
  2062. </if>
  2063. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  2064. and d.phone like concat('%', #{realtyConsultantPhone}, '%')
  2065. </if>
  2066. </where>
  2067. group by t.visit_time
  2068. order by t.visit_time desc
  2069. </select>
  2070. <select id="selectActivityVisitNumExport" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  2071. select
  2072. a.nickname, a.phone,
  2073. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2074. a.province,
  2075. b1.scene_alias as personFrom,
  2076. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2077. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2078. e.nickname as sharePersonName,
  2079. e.phone as sharePersonPhone,
  2080. t.visit_time as visitDate
  2081. From (
  2082. SELECT
  2083. t.person_id, t.visit_time, t.share_person_id
  2084. FROM
  2085. ta_person_visit_record t
  2086. WHERE
  2087. t.`event` = 'detail'
  2088. AND t.event_type IN (
  2089. 'activity',
  2090. 'help',
  2091. 'group',
  2092. 'h5'
  2093. )
  2094. <if test="activityId != null and activityId != ''">
  2095. and t.target_id = #{activityId}
  2096. </if>
  2097. <if test="activityType != null and activityType != ''">
  2098. and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' when #{activityType} = 'h5' then t.event_type = 'h5' else t.target_type = #{activityType}
  2099. end)
  2100. </if>
  2101. <if test="buildingId != null and buildingId != ''">
  2102. and t.building_id = #{buildingId}
  2103. </if>
  2104. AND t.org_id = #{orgId}
  2105. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  2106. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  2107. ) t
  2108. left join ta_person a on t.person_id = a.person_id
  2109. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2110. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2111. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2112. left join ta_user d on c.realty_consultant = d.user_id
  2113. left join ta_person e on t.share_person_id = e.person_id
  2114. <where>
  2115. <if test="personFrom != null and personFrom != ''">
  2116. and b.scene_type = #{personFrom}
  2117. </if>
  2118. <if test="province != null and province != ''">
  2119. and a.province like concat('%', #{province}, '%')
  2120. </if>
  2121. <if test="realtyConsultant != null and realtyConsultant != ''">
  2122. and d.user_name like concat('%', #{realtyConsultant}, '%')
  2123. </if>
  2124. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  2125. and d.phone like concat('%', #{realtyConsultantPhone}, '%')
  2126. </if>
  2127. </where>
  2128. group by t.visit_time
  2129. order by t.visit_time desc
  2130. </select>
  2131. <select id="selectActivityVisitPersonNum"
  2132. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  2133. select
  2134. a.nickname, a.phone,
  2135. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2136. a.province,
  2137. b1.scene_alias as personFrom,
  2138. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2139. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2140. t.create_date as visitDate,
  2141. e.nickName as sharePersonName,
  2142. t.visitNum
  2143. from (
  2144. SELECT
  2145. t.visit_time AS create_date,
  2146. t.person_id,
  2147. count(*) as visitNum
  2148. FROM
  2149. ta_person_visit_record t
  2150. WHERE
  2151. t.`event` = 'detail'
  2152. AND t.event_type IN (
  2153. 'activity',
  2154. 'help',
  2155. 'group',
  2156. 'h5'
  2157. )
  2158. AND t.org_id = #{orgId}
  2159. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  2160. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  2161. <if test="activityId != null and activityId != ''">
  2162. and t.target_id = #{activityId}
  2163. </if>
  2164. <if test="activityType != null and activityType != ''">
  2165. and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' when #{activityType} = 'h5' then t.event_type = 'h5' else t.target_type = #{activityType}
  2166. end)
  2167. </if>
  2168. <if test="buildingId != null and buildingId != ''">
  2169. and t.building_id = #{buildingId}
  2170. </if>
  2171. GROUP BY
  2172. t.person_id ) as t
  2173. left join ta_person a on t.person_id = a.person_id
  2174. 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
  2175. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2176. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2177. left join ta_user d on c.realty_consultant = d.user_id
  2178. LEFT JOIN ta_person e ON e.person_id = b.share_person_id
  2179. <where>
  2180. <if test="personFrom != null and personFrom != ''">
  2181. and b.scene_type = #{personFrom}
  2182. </if>
  2183. <if test="province != null and province != ''">
  2184. and a.province like concat('%', #{province},'%')
  2185. </if>
  2186. <if test="realtyConsultant != null and realtyConsultant != ''">
  2187. and d.user_name like concat('%', #{realtyConsultant},'%')
  2188. </if>
  2189. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  2190. and d.phone like concat('%', #{realtyConsultantPhone},'%')
  2191. </if>
  2192. </where>
  2193. group by t.person_id
  2194. order by t.create_date desc
  2195. </select>
  2196. <select id="selectActivityVisitPersonNumExport"
  2197. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  2198. select
  2199. a.nickname, a.phone,
  2200. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2201. a.province,
  2202. b1.scene_alias as personFrom,
  2203. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2204. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2205. t.create_date as visitDate,
  2206. e.nickName as sharePersonName,
  2207. t.visitNum
  2208. from (
  2209. SELECT
  2210. t.visit_time AS create_date,
  2211. t.person_id,
  2212. count(*) as visitNum
  2213. FROM
  2214. ta_person_visit_record t
  2215. WHERE
  2216. t.`event` = 'detail'
  2217. AND t.event_type IN (
  2218. 'activity',
  2219. 'help',
  2220. 'group',
  2221. 'h5'
  2222. )
  2223. AND t.org_id = #{orgId}
  2224. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  2225. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  2226. <if test="activityId != null and activityId != ''">
  2227. and t.target_id = #{activityId}
  2228. </if>
  2229. <if test="activityType != null and activityType != ''">
  2230. and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' when #{activityType} = 'h5' then t.event_type = 'h5' else t.target_type = #{activityType}
  2231. end)
  2232. </if>
  2233. <if test="buildingId != null and buildingId != ''">
  2234. and t.building_id = #{buildingId}
  2235. </if>
  2236. GROUP BY
  2237. t.person_id ) as t
  2238. left join ta_person a on t.person_id = a.person_id
  2239. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2240. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2241. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2242. left join ta_user d on c.realty_consultant = d.user_id
  2243. LEFT JOIN ta_person e ON e.person_id = b.share_person_id
  2244. <where>
  2245. <if test="personFrom != null and personFrom != ''">
  2246. and b.scene_type = #{personFrom}
  2247. </if>
  2248. <if test="province != null and province != ''">
  2249. and a.province like concat('%', #{province},'%')
  2250. </if>
  2251. <if test="realtyConsultant != null and realtyConsultant != ''">
  2252. and d.user_name like concat('%', #{realtyConsultant},'%')
  2253. </if>
  2254. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  2255. and d.phone like concat('%', #{realtyConsultantPhone},'%')
  2256. </if>
  2257. </where>
  2258. group by t.person_id
  2259. order by t.create_date desc
  2260. </select>
  2261. <select id="selectActivityVisitPersonNumByPersonId"
  2262. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  2263. select
  2264. a.nickname, a.phone,
  2265. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2266. a.province,
  2267. b1.scene_alias as personFrom,
  2268. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2269. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2270. t.create_date as visitDate,
  2271. e.nickName as sharePersonName,
  2272. t.visitNum
  2273. From (
  2274. SELECT count(1) as visitNum, t.person_id, t.create_date
  2275. FROM ta_share_person_from t
  2276. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  2277. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  2278. <if test="activityId != null and activityId != ''">
  2279. and t.target_id = #{activityId}
  2280. </if>
  2281. <if test="activityType != null and activityType != ''">
  2282. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  2283. </if>
  2284. and t.target_type in
  2285. ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  2286. and
  2287. (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})
  2288. or t.share_person = #{personId})
  2289. group by t.person_id
  2290. ) as t
  2291. left join ta_person a on t.person_id = a.person_id
  2292. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2293. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2294. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2295. left join ta_user d on c.realty_consultant = d.user_id
  2296. LEFT JOIN ta_person e ON e.person_id = b.share_person_id
  2297. group by t.person_id
  2298. </select>
  2299. <select id="selectActivityVisitNumByPersonId" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  2300. select
  2301. a.nickname, a.phone,
  2302. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2303. a.province,
  2304. b1.scene_alias as personFrom,
  2305. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2306. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2307. t.create_date as visitDate,
  2308. ifnull(e.nickname, f.user_name) as sharePersonName,
  2309. ifnull(e.phone, f.phone) as sharePersonPhone
  2310. From (
  2311. SELECT t.person_id, t.create_date, t.share_person
  2312. FROM ta_share_person_from t
  2313. LEFT JOIN (
  2314. SELECT a.person_id, b.user_id
  2315. FROM ta_person a
  2316. LEFT JOIN ta_user b
  2317. ON a.user_id = b.user_id
  2318. WHERE a.org_id = #{orgId} ) as a ON t.share_person = a.person_id or t.share_person = a.user_id
  2319. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  2320. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in
  2321. ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  2322. <if test="activityId != null and activityId != ''">
  2323. and t.target_id = #{activityId}
  2324. </if>
  2325. <if test="activityType != null and activityType != ''">
  2326. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  2327. </if>
  2328. and
  2329. (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})
  2330. or t.share_person = #{personId})
  2331. ) as t
  2332. left join ta_person a on t.person_id = a.person_id
  2333. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2334. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2335. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2336. left join ta_user d on c.realty_consultant = d.user_id
  2337. left join ta_person e on t.share_person = e.person_id
  2338. left join ta_user f on t.share_person = f.user_id
  2339. group by t.create_date
  2340. </select>
  2341. <select id="selectActivityVisitPersonNumExportByPersonId"
  2342. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  2343. select
  2344. a.nickname, a.phone,
  2345. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2346. a.province,
  2347. b1.scene_alias as personFrom,
  2348. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2349. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2350. t.create_date as visitDate,
  2351. e.nickName as sharePersonName,
  2352. t.visitNum
  2353. From (
  2354. SELECT count(1) as visitNum, t.person_id, t.create_date
  2355. FROM ta_share_person_from t
  2356. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  2357. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  2358. <if test="activityId != null and activityId != ''">
  2359. and t.target_id = #{activityId}
  2360. </if>
  2361. <if test="activityType != null and activityType != ''">
  2362. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  2363. </if>
  2364. and t.target_type in
  2365. ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  2366. and
  2367. (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})
  2368. or t.share_person = #{personId})
  2369. group by t.person_id
  2370. ) as t
  2371. left join ta_person a on t.person_id = a.person_id
  2372. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2373. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2374. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2375. left join ta_user d on c.realty_consultant = d.user_id
  2376. LEFT JOIN ta_person e ON e.person_id = b.share_person_id
  2377. group by t.person_id
  2378. </select>
  2379. <select id="selectActivityVisitNumExportByPersonId"
  2380. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  2381. select
  2382. a.nickname, a.phone,
  2383. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  2384. a.province,
  2385. b1.scene_alias as personFrom,
  2386. GROUP_CONCAT(d.user_name) as realtyConsultant,
  2387. GROUP_CONCAT(d.phone) as realtyConsultantPhone,
  2388. t.create_date as visitDate,
  2389. ifnull(e.nickname, f.user_name) as sharePersonName,
  2390. ifnull(e.phone, f.phone) as sharePersonPhone
  2391. From (
  2392. SELECT t.person_id, t.create_date, t.share_person
  2393. FROM ta_share_person_from t
  2394. LEFT JOIN (
  2395. SELECT a.person_id, b.user_id
  2396. FROM ta_person a
  2397. LEFT JOIN ta_user b
  2398. ON a.user_id = b.user_id
  2399. WHERE a.org_id = #{orgId} ) as a ON t.share_person = a.person_id or t.share_person = a.user_id
  2400. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
  2401. DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in
  2402. ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  2403. <if test="activityId != null and activityId != ''">
  2404. and t.target_id = #{activityId}
  2405. </if>
  2406. <if test="activityType != null and activityType != ''">
  2407. and t.target_type = concat(REPLACE(#{activityType}, 'activity', 'dynamic'), '_share')
  2408. </if>
  2409. and
  2410. (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})
  2411. or t.share_person = #{personId})
  2412. ) as t
  2413. left join ta_person a on t.person_id = a.person_id
  2414. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  2415. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  2416. LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
  2417. left join ta_user d on c.realty_consultant = d.user_id
  2418. left join ta_person e on t.share_person = e.person_id
  2419. left join ta_user f on t.share_person = f.user_id
  2420. group by t.create_date
  2421. </select>
  2422. </mapper>