TaActivityStaticMapper.xml 85KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862
  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
  10. ON t.be_share = a.help_activity_id
  11. LEFT JOIN ta_share_activity b
  12. ON t.be_share = b.share_id
  13. LEFT JOIN ta_live_activity c
  14. ON t.be_share = c.live_activity_id
  15. LEFT JOIN ta_drainage d
  16. ON t.be_share = d.drainage_id
  17. LEFT JOIN ta_building_dynamic e
  18. ON t.be_share = e.dynamic_id
  19. LEFT JOIN ta_person f
  20. ON t.person_id = f.person_id
  21. WHERE
  22. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  23. <if test="buildingId != null and buildingId != ''">
  24. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or d.building_id = #{buildingId} or e.building_id = #{buildingId})
  25. </if>
  26. <if test="targetType != null and targetType != ''">
  27. and t.tagert_type = #{targetType}
  28. </if>
  29. <if test="startDate != null ">
  30. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  31. </if>
  32. <if test="endDate != null ">
  33. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  34. </if>
  35. <if test="startDate == null or endDate == null ">
  36. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  37. </if>
  38. GROUP BY DATE_FORMAT( t.create_date, '%Y-%m-%d' ) ,t.person_id
  39. ) as temp1
  40. </select>
  41. <select id="selectShareNum" resultType="java.lang.Integer">
  42. SELECT
  43. COUNT( 1 ) AS shareNum
  44. FROM
  45. ta_share_count t
  46. left join ta_help_activity a on t.be_share = a.help_activity_id
  47. left join ta_share_activity b on t.be_share = b.share_id
  48. left join ta_live_activity c on t.be_share = c.live_activity_id
  49. left join ta_drainage d on t.be_share = d.drainage_id
  50. left join ta_building_dynamic e on t.be_share = e.dynamic_id
  51. left join ta_person f on t.person_id = f.person_id
  52. WHERE
  53. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  54. <if test="buildingId != null and buildingId != ''">
  55. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or d.building_id = #{buildingId} or e.building_id = #{buildingId})
  56. </if>
  57. <if test="targetType != null and targetType != ''">
  58. and t.tagert_type = #{targetType}
  59. </if>
  60. <if test="startDate != null ">
  61. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  62. </if>
  63. <if test="endDate != null ">
  64. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  65. </if>
  66. <if test="startDate == null or endDate == null ">
  67. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  68. </if>
  69. </select>
  70. <select id="selectVisitPersonNum" resultType="java.lang.Integer">
  71. select count(*)AS visitPersonNum from (
  72. SELECT
  73. t.visit_time AS create_date,
  74. t.person_id
  75. FROM
  76. ta_person_visit_record t
  77. WHERE
  78. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  79. <if test="buildingId != null and buildingId != ''">
  80. and t.building_id = #{buildingId}
  81. </if>
  82. <if test="targetType != null and targetType != ''">
  83. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType} end)
  84. </if>
  85. <if test="startDate != null">
  86. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  87. </if>
  88. <if test="endDate != null">
  89. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  90. </if>
  91. <if test="startDate == null or endDate == null">
  92. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  93. </if>
  94. GROUP BY
  95. DATE_FORMAT(t.visit_time, '%Y-%m-%d'),
  96. person_id) as visitPersonCount
  97. </select>
  98. <select id="selectVisitNum" resultType="java.lang.Integer">
  99. select count(*) from ta_person_visit_record t where t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  100. <if test="buildingId != null and buildingId != ''">
  101. and t.building_id = #{buildingId}
  102. </if>
  103. <if test="targetType != null and targetType != ''">
  104. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType} end)
  105. </if>
  106. <if test="startDate != null">
  107. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  108. </if>
  109. <if test="endDate != null">
  110. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  111. </if>
  112. </select>
  113. <select id="selectShareCount" resultType="java.util.Map">
  114. SELECT
  115. share_count_table.date AS date,
  116. ifnull( share_count_table.user_count, 0 ) AS share_count
  117. FROM
  118. (
  119. SELECT
  120. *
  121. FROM
  122. (
  123. SELECT
  124. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  125. FROM
  126. sequence a
  127. <trim prefix="where">
  128. <if test="startDate != null or endDate != null">
  129. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  130. </if>
  131. </trim>
  132. ) AS temp_date
  133. LEFT JOIN (
  134. SELECT
  135. COUNT( 1 ) AS user_count,
  136. t.create_date AS create_date
  137. FROM
  138. ta_share_count t
  139. left join ta_help_activity a on t.be_share = a.help_activity_id
  140. left join ta_share_activity b on t.be_share = b.share_id
  141. left join ta_live_activity c on t.be_share = c.live_activity_id
  142. left join ta_drainage d on t.be_share = d.drainage_id
  143. left join ta_building_dynamic e on t.be_share = e.dynamic_id
  144. left join ta_person f on t.person_id = f.person_id
  145. WHERE
  146. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  147. <if test="buildingId != null and buildingId != ''">
  148. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or d.building_id = #{buildingId} or e.building_id = #{buildingId})
  149. </if>
  150. <if test="targetType != null and targetType != ''">
  151. and t.tagert_type = #{targetType}
  152. </if>
  153. <if test="startDate != null ">
  154. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  155. </if>
  156. <if test="endDate != null ">
  157. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  158. </if>
  159. <if test="startDate == null or endDate == null ">
  160. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  161. </if>
  162. GROUP BY
  163. DATE_FORMAT( t.create_date, '%Y-%m-%d' )
  164. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  165. ) AS share_count_table
  166. group by date order by date
  167. </select>
  168. <select id="selectSharePersonCount" resultType="java.util.Map">
  169. SELECT
  170. share_person_count_table.date AS date,
  171. ifnull( share_person_count_table.user_count, 0 ) AS share_person_count
  172. FROM
  173. (
  174. SELECT
  175. *
  176. FROM
  177. (
  178. SELECT
  179. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  180. FROM
  181. sequence a
  182. <trim prefix="where">
  183. <if test="startDate != null or endDate != null">
  184. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  185. </if>
  186. </trim>
  187. ) AS temp_date
  188. LEFT JOIN (
  189. SELECT count(1) as user_count , temp1.*
  190. FROM (
  191. SELECT DISTINCT(t.person_id),t.create_date
  192. FROM ta_share_count t
  193. LEFT JOIN ta_help_activity a
  194. ON t.be_share = a.help_activity_id
  195. LEFT JOIN ta_share_activity b
  196. ON t.be_share = b.share_id
  197. LEFT JOIN ta_live_activity c
  198. ON t.be_share = c.live_activity_id
  199. LEFT JOIN ta_drainage d
  200. ON t.be_share = d.drainage_id
  201. LEFT JOIN ta_building_dynamic e
  202. ON t.be_share = e.dynamic_id
  203. LEFT JOIN ta_person f
  204. ON t.person_id = f.person_id
  205. WHERE
  206. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  207. <if test="buildingId != null and buildingId != ''">
  208. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or d.building_id = #{buildingId} or e.building_id = #{buildingId})
  209. </if>
  210. <if test="targetType != null and targetType != ''">
  211. and t.tagert_type = #{targetType}
  212. </if>
  213. <if test="startDate != null ">
  214. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  215. </if>
  216. <if test="endDate != null ">
  217. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  218. </if>
  219. <if test="startDate == null or endDate == null ">
  220. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  221. </if>
  222. GROUP BY DATE_FORMAT( t.create_date, '%Y-%m-%d' ) ,t.person_id
  223. ) as temp1 GROUP BY DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  224. ) AS temp1 ON temp_date.date = DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  225. ) AS share_person_count_table
  226. group by date order by date
  227. </select>
  228. <select id="selectVisitCount" resultType="java.util.Map">
  229. SELECT
  230. visit_count_table.date AS date,
  231. ifnull( visit_count_table.user_count, 0 ) AS visit_count
  232. FROM (
  233. SELECT
  234. *
  235. FROM
  236. (
  237. SELECT
  238. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  239. FROM
  240. sequence a
  241. <trim prefix="where">
  242. <if test="startDate != null or endDate != null">
  243. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  244. </if>
  245. </trim>
  246. ) AS temp_date
  247. LEFT JOIN (
  248. SELECT
  249. COUNT( 1 ) AS user_count,
  250. t.visit_time AS create_date
  251. FROM
  252. ta_person_visit_record t
  253. WHERE
  254. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  255. <if test="buildingId != null and buildingId != ''">
  256. and t.building_id = #{buildingId}
  257. </if>
  258. <if test="targetType != null and targetType != ''">
  259. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType} end)
  260. </if>
  261. <if test="startDate != null">
  262. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  263. </if>
  264. <if test="endDate != null">
  265. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  266. </if>
  267. <if test="startDate == null or endDate == null ">
  268. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  269. </if>
  270. GROUP BY
  271. DATE_FORMAT( t.visit_time, '%Y-%m-%d' )
  272. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  273. ) AS visit_count_table
  274. group by date order by date
  275. </select>
  276. <select id="selectVisitPersonCount" resultType="java.util.Map">
  277. SELECT
  278. visit_person_count_table.date AS date,
  279. ifnull( visit_person_count_table.user_count, 0 ) AS visit_person_count
  280. FROM (
  281. SELECT
  282. *
  283. FROM
  284. (
  285. SELECT
  286. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  287. FROM
  288. sequence a
  289. <trim prefix="where">
  290. <if test="startDate != null or endDate != null">
  291. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  292. </if>
  293. </trim>
  294. ) AS temp_date
  295. LEFT JOIN (
  296. select count(*) AS user_count , visitPersonCount.* from (
  297. SELECT
  298. t.visit_time AS create_date,
  299. t.person_id
  300. FROM
  301. ta_person_visit_record t
  302. WHERE
  303. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  304. <if test="buildingId != null and buildingId != ''">
  305. and t.building_id = #{buildingId}
  306. </if>
  307. <if test="targetType != null and targetType != ''">
  308. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType} end)
  309. </if>
  310. <if test="startDate != null">
  311. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  312. </if>
  313. <if test="endDate != null">
  314. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  315. </if>
  316. <if test="startDate == null or endDate == null">
  317. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  318. </if>
  319. GROUP BY
  320. DATE_FORMAT(t.visit_time, '%Y-%m-%d'),
  321. person_id) as visitPersonCount GROUP BY DATE_FORMAT(visitPersonCount.create_date, '%Y-%m-%d')
  322. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  323. ) AS visit_person_count_table
  324. group by date order by date
  325. </select>
  326. <select id="selectAddRegistCount" resultType="java.util.Map">
  327. SELECT
  328. date,
  329. ifnull( addRegistNum, 0 ) AS addRegist_count
  330. FROM
  331. (
  332. SELECT
  333. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  334. FROM
  335. sequence a
  336. <trim prefix="where">
  337. <if test="startDate != null or endDate != null">
  338. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  339. </if>
  340. </trim>
  341. ) AS temp_date
  342. LEFT JOIN (
  343. SELECT
  344. count( * ) AS addRegistNum,
  345. temp4.*
  346. FROM
  347. (
  348. SELECT
  349. t.create_date AS create_date,
  350. t.person_id
  351. FROM
  352. ta_share_person_from t
  353. WHERE
  354. t.target_type IN ( 'dynamic_share', 'h5_share', 'help_share', 'live_share', 'group_share' )
  355. AND t.org_id = #{orgId}
  356. AND t.STATUS = 1
  357. and t.is_first_time = 1
  358. <if test="buildingId != null and buildingId != ''">
  359. and t.building_id = #{buildingId}
  360. </if>
  361. and t.status = 1 and t.is_first_time = 1
  362. <if test="targetType != null and targetType != ''">
  363. and t.target_type = #{targetType}
  364. </if>
  365. <if test="startDate != null ">
  366. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  367. </if>
  368. <if test="endDate != null ">
  369. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  370. </if>
  371. <if test="startDate == null or endDate == null">
  372. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  373. </if>
  374. GROUP BY
  375. t.person_id,
  376. t.target_type
  377. ) AS temp4
  378. GROUP BY
  379. DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  380. ) AS temp4 ON temp_date.date = DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  381. GROUP BY
  382. date
  383. ORDER BY
  384. date DESC
  385. </select>
  386. <select id="selectTableData" resultType="com.huiju.estateagents.excel.ActivityStatistics.StatisicAttractUser">
  387. SELECT date, ifnull(shareNum ,0) as shareNum, ifnull(sharePersonNum, 0) as sharePersonNum, ifnull(visitNum, 0) as visitNum, ifnull(visitPersonNum, 0) as visitPersonNum, ifnull(addRegistNum,0) as addRegistNum
  388. FROM
  389. (
  390. SELECT
  391. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  392. FROM
  393. sequence a
  394. <trim prefix="where">
  395. <if test="startDate != null or endDate != null">
  396. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  397. </if>
  398. </trim>
  399. ) AS temp_date
  400. LEFT JOIN (
  401. SELECT
  402. COUNT( 1 ) AS shareNum,
  403. t.create_date AS create_date
  404. FROM
  405. ta_share_count t
  406. left join ta_help_activity a on t.be_share = a.help_activity_id
  407. left join ta_share_activity b on t.be_share = b.share_id
  408. left join ta_live_activity c on t.be_share = c.live_activity_id
  409. left join ta_drainage d on t.be_share = d.drainage_id
  410. left join ta_building_dynamic e on t.be_share = e.dynamic_id
  411. left join ta_person f on t.person_id = f.person_id
  412. WHERE
  413. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  414. <if test="buildingId != null and buildingId != ''">
  415. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or d.building_id = #{buildingId} or e.building_id = #{buildingId})
  416. </if>
  417. <if test="targetType != null and targetType != ''">
  418. and t.tagert_type = #{targetType}
  419. </if>
  420. <if test="startDate != null ">
  421. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  422. </if>
  423. <if test="endDate != null ">
  424. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  425. </if>
  426. <if test="startDate == null or endDate == null ">
  427. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  428. </if>
  429. GROUP BY
  430. DATE_FORMAT( t.create_date, '%Y-%m-%d' )
  431. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  432. LEFT JOIN (
  433. SELECT count(1) as sharePersonNum , temp1.*
  434. FROM (
  435. SELECT DISTINCT(t.person_id),t.create_date
  436. FROM ta_share_count t
  437. LEFT JOIN ta_help_activity a
  438. ON t.be_share = a.help_activity_id
  439. LEFT JOIN ta_share_activity b
  440. ON t.be_share = b.share_id
  441. LEFT JOIN ta_live_activity c
  442. ON t.be_share = c.live_activity_id
  443. LEFT JOIN ta_drainage d
  444. ON t.be_share = d.drainage_id
  445. LEFT JOIN ta_building_dynamic e
  446. ON t.be_share = e.dynamic_id
  447. LEFT JOIN ta_person f
  448. ON t.person_id = f.person_id
  449. WHERE
  450. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  451. <if test="buildingId != null and buildingId != ''">
  452. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or d.building_id = #{buildingId} or e.building_id = #{buildingId})
  453. </if>
  454. <if test="targetType != null and targetType != ''">
  455. and t.tagert_type = #{targetType}
  456. </if>
  457. <if test="startDate != null ">
  458. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  459. </if>
  460. <if test="endDate != null ">
  461. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  462. </if>
  463. <if test="startDate == null or endDate == null ">
  464. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  465. </if>
  466. GROUP BY DATE_FORMAT( t.create_date, '%Y-%m-%d' ) ,t.person_id
  467. ) as temp1 GROUP BY DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  468. ) AS temp1 ON temp_date.date = DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  469. LEFT JOIN (
  470. SELECT
  471. COUNT( 1 ) AS visitNum,
  472. t.visit_time AS create_date
  473. FROM
  474. ta_person_visit_record t
  475. WHERE
  476. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  477. <if test="buildingId != null and buildingId != ''">
  478. and t.building_id = #{buildingId}
  479. </if>
  480. <if test="targetType != null and targetType != ''">
  481. and t.event_type = 'activity'
  482. </if>
  483. <if test="startDate != null">
  484. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  485. </if>
  486. <if test="endDate != null">
  487. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  488. </if>
  489. <if test="startDate == null or endDate == null ">
  490. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  491. </if>
  492. GROUP BY
  493. DATE_FORMAT( t.visit_time, '%Y-%m-%d' )
  494. ) AS temp2 ON temp_date.date = DATE_FORMAT( temp2.create_date, '%Y-%m-%d' )
  495. LEFT JOIN (
  496. select count(*)AS visitPersonNum , visitPersonCount.* from (
  497. SELECT
  498. t.visit_time AS create_date,
  499. t.person_id
  500. FROM
  501. ta_person_visit_record t
  502. WHERE
  503. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  504. <if test="buildingId != null and buildingId != ''">
  505. and t.building_id = #{buildingId}
  506. </if>
  507. <if test="targetType != null and targetType != ''">
  508. and (case when #{targetType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{targetType} end)
  509. </if>
  510. <if test="startDate != null">
  511. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  512. </if>
  513. <if test="endDate != null">
  514. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  515. </if>
  516. <if test="startDate == null or endDate == null">
  517. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  518. </if>
  519. GROUP BY
  520. DATE_FORMAT(t.visit_time, '%Y-%m-%d'),
  521. person_id) as visitPersonCount GROUP BY DATE_FORMAT(visitPersonCount.create_date, '%Y-%m-%d')
  522. ) AS temp3 ON temp_date.date = DATE_FORMAT( temp3.create_date, '%Y-%m-%d' )
  523. LEFT JOIN (
  524. select count(*) as addRegistNum,temp4.* from (
  525. SELECT
  526. t.create_date AS create_date,
  527. t.person_id
  528. FROM
  529. ta_share_person_from t
  530. WHERE
  531. t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  532. <if test="buildingId != null and buildingId != ''">
  533. and t.building_id = #{buildingId}
  534. </if>
  535. and t.status = 1
  536. and t.is_first_time = 1
  537. <if test="targetType != null and targetType != ''">
  538. and t.target_type = #{targetType}
  539. </if>
  540. <if test="startDate != null ">
  541. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  542. </if>
  543. <if test="endDate != null ">
  544. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  545. </if>
  546. <if test="startDate == null or endDate == null">
  547. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  548. </if>
  549. GROUP BY t.person_id, t.target_type
  550. ) as temp4 GROUP BY DATE_FORMAT(temp4.create_date,'%Y-%m-%d')
  551. ) AS temp4 ON temp_date.date = DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  552. GROUP BY date
  553. <if test="colKey == null or colKey == ''">
  554. ORDER BY date desc
  555. </if>
  556. <if test="colKey != null and colKey != ''">
  557. ORDER BY ${colKey} ${sortType}
  558. </if>
  559. </select>
  560. <select id="selectExportTableData" resultType="com.huiju.estateagents.excel.ActivityStatistics.StatisicAttractUser">
  561. SELECT date, ifnull(shareNum ,0) as shareNum, ifnull(sharePersonNum, 0) as sharePersonNum, ifnull(visitNum, 0) as visitNum, ifnull(visitPersonNum, 0) as visitPersonNum, ifnull(addRegistNum,0) as addRegistNum
  562. FROM
  563. (
  564. SELECT
  565. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  566. FROM
  567. sequence a
  568. <trim prefix="where">
  569. <if test="startDate != null or endDate != null">
  570. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  571. </if>
  572. </trim>
  573. ) AS temp_date
  574. LEFT JOIN (
  575. SELECT
  576. COUNT( 1 ) AS shareNum,
  577. t.create_date AS create_date
  578. FROM
  579. ta_share_count t
  580. left join ta_help_activity a on t.be_share = a.help_activity_id
  581. left join ta_share_activity b on t.be_share = b.share_id
  582. left join ta_live_activity c on t.be_share = c.live_activity_id
  583. left join ta_drainage d on t.be_share = d.drainage_id
  584. left join ta_building_dynamic e on t.be_share = e.dynamic_id
  585. left join ta_person f on t.person_id = f.person_id
  586. WHERE
  587. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  588. <if test="buildingId != null and buildingId != ''">
  589. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or d.building_id = #{buildingId} or e.building_id = #{buildingId})
  590. </if>
  591. <if test="targetType != null and targetType != ''">
  592. and t.tagert_type = #{targetType}
  593. </if>
  594. <if test="startDate != null ">
  595. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  596. </if>
  597. <if test="endDate != null ">
  598. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  599. </if>
  600. <if test="startDate == null or endDate == null ">
  601. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  602. </if>
  603. GROUP BY
  604. DATE_FORMAT( t.create_date, '%Y-%m-%d' )
  605. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date, '%Y-%m-%d' )
  606. LEFT JOIN (
  607. SELECT count(1) as sharePersonNum , temp1.*
  608. FROM (
  609. SELECT DISTINCT(t.person_id),t.create_date
  610. FROM ta_share_count t
  611. LEFT JOIN ta_help_activity a
  612. ON t.be_share = a.help_activity_id
  613. LEFT JOIN ta_share_activity b
  614. ON t.be_share = b.share_id
  615. LEFT JOIN ta_live_activity c
  616. ON t.be_share = c.live_activity_id
  617. LEFT JOIN ta_drainage d
  618. ON t.be_share = d.drainage_id
  619. LEFT JOIN ta_building_dynamic e
  620. ON t.be_share = e.dynamic_id
  621. LEFT JOIN ta_person f
  622. ON t.person_id = f.person_id
  623. WHERE
  624. t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  625. <if test="buildingId != null and buildingId != ''">
  626. and (a.building_id = #{buildingId} or b.building_id = #{buildingId} or c.building_id = #{buildingId} or d.building_id = #{buildingId} or e.building_id = #{buildingId})
  627. </if>
  628. <if test="targetType != null and targetType != ''">
  629. and t.tagert_type = #{targetType}
  630. </if>
  631. <if test="startDate != null ">
  632. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  633. </if>
  634. <if test="endDate != null ">
  635. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  636. </if>
  637. <if test="startDate == null or endDate == null ">
  638. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  639. </if>
  640. GROUP BY DATE_FORMAT( t.create_date, '%Y-%m-%d' ) ,t.person_id
  641. ) as temp1 GROUP BY DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  642. ) AS temp1 ON temp_date.date = DATE_FORMAT( temp1.create_date, '%Y-%m-%d' )
  643. LEFT JOIN (
  644. SELECT
  645. COUNT( 1 ) AS visitNum,
  646. t.visit_time AS create_date
  647. FROM
  648. ta_person_visit_record t
  649. WHERE
  650. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  651. <if test="buildingId != null and buildingId != ''">
  652. and t.building_id = #{buildingId}
  653. </if>
  654. <if test="targetType != null and targetType != ''">
  655. and t.target_type = #{targetType}
  656. </if>
  657. <if test="startDate != null">
  658. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  659. </if>
  660. <if test="endDate != null">
  661. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  662. </if>
  663. <if test="startDate == null or endDate == null ">
  664. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  665. </if>
  666. GROUP BY
  667. DATE_FORMAT( t.visit_time, '%Y-%m-%d' )
  668. ) AS temp2 ON temp_date.date = DATE_FORMAT( temp2.create_date, '%Y-%m-%d' )
  669. LEFT JOIN (
  670. select count(*)AS visitPersonNum , visitPersonCount.* from (
  671. SELECT
  672. t.visit_time AS create_date,
  673. t.person_id
  674. FROM
  675. ta_person_visit_record t
  676. WHERE
  677. t.`event` = 'detail' and t.event_type in ('activity','help','group','h5') and t.org_id = #{orgId}
  678. <if test="buildingId != null and buildingId != ''">
  679. and t.building_id = #{buildingId}
  680. </if>
  681. <if test="targetType != null and targetType != ''">
  682. and t.target_type = #{targetType}
  683. </if>
  684. <if test="startDate != null">
  685. and t.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  686. </if>
  687. <if test="endDate != null">
  688. and t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  689. </if>
  690. <if test="startDate == null or endDate == null">
  691. AND t.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  692. </if>
  693. GROUP BY
  694. DATE_FORMAT(t.visit_time, '%Y-%m-%d'),
  695. person_id) as visitPersonCount GROUP BY DATE_FORMAT(visitPersonCount.create_date, '%Y-%m-%d')
  696. ) AS temp3 ON temp_date.date = DATE_FORMAT( temp3.create_date, '%Y-%m-%d' )
  697. LEFT JOIN (
  698. select count(*) as addRegistNum,temp4.* from (
  699. SELECT
  700. t.create_date AS create_date,
  701. t.person_id
  702. FROM
  703. ta_share_person_from t
  704. WHERE
  705. t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  706. <if test="buildingId != null and buildingId != ''">
  707. and t.building_id = #{buildingId}
  708. </if>
  709. and t.status = 1
  710. and t.is_first_time = 1
  711. <if test="targetType != null and targetType != ''">
  712. and t.target_type = #{targetType}
  713. </if>
  714. <if test="startDate != null ">
  715. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  716. </if>
  717. <if test="endDate != null ">
  718. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  719. </if>
  720. <if test="startDate == null or endDate == null">
  721. AND t.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  722. </if>
  723. GROUP BY t.person_id, t.target_type
  724. ) as temp4 GROUP BY DATE_FORMAT(temp4.create_date,'%Y-%m-%d')
  725. ) AS temp4 ON temp_date.date = DATE_FORMAT( temp4.create_date, '%Y-%m-%d' )
  726. GROUP BY date
  727. <if test="colKey == null or colKey == ''">
  728. ORDER BY date desc
  729. </if>
  730. <if test="colKey != null and colKey != ''">
  731. ORDER BY ${colKey} ${sortType}
  732. </if>
  733. </select>
  734. <select id="selectActivityStatisDetail" resultType="com.huiju.estateagents.excel.ActivityStatistics.ActivityDetailShareRecord">
  735. select
  736. activity.*,
  737. ifnull(shareNum.shareNum, 0) as shareNum,
  738. ifnull(sharePersonNum.sharePersonNum, 0) as sharePersonNum,
  739. ifnull(visitNum.visitNum, 0) as visitNum,
  740. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  741. ifnull(addRegistNum.addRegistNum, 0) as addRegistNum
  742. from (
  743. select a.dynamic_id as activityId, a.title as activityName, "activity" as activityType from ta_building_dynamic a
  744. where org_id = #{orgId}
  745. <if test="buildingId != null and buildingId != '' ">
  746. and a.building_id = #{buildingId}
  747. </if>
  748. <if test="activityName != null and activityName != '' ">
  749. and a.title = #{activityName}
  750. </if>
  751. union all
  752. select b.help_activity_id activityId, b.title as activityName, "help" as activityType from ta_help_activity b
  753. where b.org_id = #{orgId}
  754. <if test="buildingId != null and buildingId != '' ">
  755. and b.building_id = #{buildingId}
  756. </if>
  757. <if test="activityName != null and activityName != '' ">
  758. and b.title = #{activityName}
  759. </if>
  760. union all
  761. select c.group_activity_id as activityId, c.activity_name as activityName, "group" as activityType From ta_share_activity c
  762. where c.org_id = #{orgId}
  763. <if test="buildingId != null and buildingId != '' ">
  764. and c.building_id = #{buildingId}
  765. </if>
  766. <if test="activityName != null and activityName != '' ">
  767. and c.activity_name = #{activityName}
  768. </if>
  769. union all
  770. select d.drainage_id as activityId, d.name as activityName, "h5" as activityType from ta_drainage d
  771. where d.org_id = #{orgId}
  772. <if test="buildingId != null and buildingId != '' ">
  773. and d.building_id = #{buildingId}
  774. </if>
  775. <if test="activityName != null and activityName != '' ">
  776. and d.name = #{activityName}
  777. </if>
  778. union all
  779. select e.live_activity_id as activityId, e.live_activity_title as activityName, "live" as activityType From ta_live_activity e
  780. where e.org_id = #{orgId}
  781. <if test="buildingId != null and buildingId != '' ">
  782. and e.building_id = #{buildingId}
  783. </if>
  784. <if test="activityName != null and activityName != '' ">
  785. and e.live_activity_title = #{activityName}
  786. </if>
  787. ) as activity
  788. left join (
  789. select * from (
  790. select count(*) as shareNum, a.be_share, a.tagert_type From ta_share_count a where a.tagert_type in ( 'activity', 'group','h5','help','liveApp','livePost')
  791. and a.org_id = #{orgId}
  792. <if test="targetType != null and targetType != ''">
  793. and a.tagert_type = #{targetType}
  794. </if>
  795. <if test="startDate != null ">
  796. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  797. </if>
  798. <if test="endDate != null ">
  799. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  800. </if>
  801. <if test="startDate == null or endDate == null ">
  802. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  803. </if>
  804. group by a.be_share, tagert_type
  805. ) as a
  806. ) as shareNum on shareNum.be_share = activity.activityId and shareNum.tagert_type = activity.activityType
  807. left join (
  808. select count(*) as sharePersonNum ,sharePersonNum.be_share, sharePersonNum.tagert_type, sharePersonNum.create_date from (
  809. select a.* From ta_share_count a where a.tagert_type in ( 'activity', 'group','h5','help','liveApp','livePost') and a.org_id = #{orgId}
  810. <if test="targetType != null and targetType != ''">
  811. and a.tagert_type = #{targetType}
  812. </if>
  813. <if test="startDate != null ">
  814. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  815. </if>
  816. <if test="endDate != null ">
  817. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  818. </if>
  819. <if test="startDate == null or endDate == null ">
  820. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  821. </if>
  822. group by a.person_id, be_share, tagert_type
  823. ) as sharePersonNum group by sharePersonNum.be_share, sharePersonNum.tagert_type
  824. ) as sharePersonNum on sharePersonNum.be_share = activity.activityId and sharePersonNum.tagert_type = activity.activityType
  825. left join (
  826. select * from (
  827. select count(*) as visitNum, a.target_id, a.event_type From ta_person_visit_record a where a.event_type in ('activity','group','h5','help') and a.`event` = 'detail' and a.org_id = #{orgId}
  828. <if test="targetType != null and targetType != ''">
  829. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType} end)
  830. </if>
  831. <if test="startDate != null">
  832. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  833. </if>
  834. <if test="endDate != null">
  835. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  836. </if>
  837. <if test="startDate == null or endDate == null ">
  838. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  839. </if>
  840. group by a.target_id, a.event_type
  841. ) as a
  842. ) as visitNum on visitNum.target_id = activity.activityId and visitNum.event_type = activity.activityType
  843. left join (
  844. select count(*) as visitPersonNum ,visitPersonNum.target_id, visitPersonNum.event_type from (
  845. select a.* From ta_person_visit_record a where a.event_type in ('activity','group','h5','help') and a.`event` = 'detail' and a.org_id = #{orgId}
  846. <if test="targetType != null and targetType != ''">
  847. and (case when #{targetType} = 'activity' then a.target_type = 'dynamic' else a.target_type = #{targetType} end)
  848. </if>
  849. <if test="startDate != null">
  850. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  851. </if>
  852. <if test="endDate != null">
  853. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  854. </if>
  855. <if test="startDate == null or endDate == null ">
  856. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  857. </if>
  858. group by a.person_id, a.target_id, a.event_type
  859. ) as visitPersonNum group by visitPersonNum.target_id, visitPersonNum.event_type
  860. ) as visitPersonNum on visitPersonNum.target_id = activity.activityId and visitPersonNum.event_type = activity.activityType
  861. left join (
  862. select count(*) as addRegistNum ,addRegistNum.target_id, addRegistNum.target_type From (
  863. select count(*), a.* From ta_share_person_from a where a.target_type IN ( 'dynamic_share', 'h5_share', 'help_share', 'live_share', 'group_share' ) and a.org_id = #{orgId}
  864. and a.status = 1
  865. and a.is_first_time = 1
  866. <if test="targetType != null and targetType != ''">
  867. and a.target_type = #{targetType}
  868. </if>
  869. <if test="startDate != null ">
  870. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%i:%S' )
  871. </if>
  872. <if test="endDate != null ">
  873. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%S' )
  874. </if>
  875. <if test="startDate == null or endDate == null">
  876. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  877. </if>
  878. group by a.person_id, a.target_type ,a.target_id
  879. ) as addRegistNum group by addRegistNum.target_type, addRegistNum.target_id
  880. ) as addRegistNum on addRegistNum.target_id = activity.activityId and substring_index(addRegistNum.target_type, '_share', 1) = activity.activityType
  881. <if test="targetType != null and targetType != ''">
  882. where activity.activityType = #{targetType}
  883. </if>
  884. group by activity.activityId, activity.activityType
  885. <if test="colKey == null or colKey == ''">
  886. order by sharePersonNum.create_date desc
  887. </if>
  888. <if test="colKey != null and colKey != ''">
  889. ORDER BY ${colKey} ${sortType}
  890. </if>
  891. </select>
  892. <select id="selectActivityStatisDetailExport" resultType="com.huiju.estateagents.excel.ActivityStatistics.ActivityDetailShareRecord">
  893. select
  894. activity.activityId, activity.activityName,
  895. case when activity.activityType = 'activity' then '报名活动'
  896. when activity.activityType = 'help' then '助力活动'
  897. when activity.activityType = 'group' then '拼团活动'
  898. when activity.activityType = 'h5' then 'H5活动'
  899. when activity.activityType = 'live' then '直播活动'
  900. end as activityType,
  901. ifnull(shareNum.shareNum, 0) as shareNum,
  902. ifnull(sharePersonNum.sharePersonNum, 0) as sharePersonNum,
  903. ifnull(visitNum.visitNum, 0) as visitNum,
  904. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  905. ifnull(addRegistNum.addRegistNum, 0) as addRegistNum
  906. from (
  907. select a.dynamic_id as activityId, a.title as activityName, "activity" as activityType from ta_building_dynamic a
  908. where org_id = #{orgId}
  909. <if test="buildingId != null and buildingId != '' ">
  910. and a.building_id = #{buildingId}
  911. </if>
  912. <if test="activityName != null and activityName != '' ">
  913. and a.title = #{activityName}
  914. </if>
  915. union all
  916. select b.help_activity_id activityId, b.title as activityName, "help" as activityType from ta_help_activity b
  917. where b.org_id = #{orgId}
  918. <if test="buildingId != null and buildingId != '' ">
  919. and b.building_id = #{buildingId}
  920. </if>
  921. <if test="activityName != null and activityName != '' ">
  922. and b.title = #{activityName}
  923. </if>
  924. union all
  925. select c.group_activity_id as activityId, c.activity_name as activityName, "group" as activityType From ta_share_activity c
  926. where c.org_id = #{orgId}
  927. <if test="buildingId != null and buildingId != '' ">
  928. and c.building_id = #{buildingId}
  929. </if>
  930. <if test="activityName != null and activityName != '' ">
  931. and c.activity_name = #{activityName}
  932. </if>
  933. union all
  934. select d.drainage_id as activityId, d.name as activityName, "h5" as activityType from ta_drainage d
  935. where d.org_id = #{orgId}
  936. <if test="buildingId != null and buildingId != '' ">
  937. and d.building_id = #{buildingId}
  938. </if>
  939. <if test="activityName != null and activityName != '' ">
  940. and d.name = #{activityName}
  941. </if>
  942. union all
  943. select e.live_activity_id as activityId, e.live_activity_title as activityName, "live" as activityType From ta_live_activity e
  944. where e.org_id = #{orgId}
  945. <if test="buildingId != null and buildingId != '' ">
  946. and e.building_id = #{buildingId}
  947. </if>
  948. <if test="activityName != null and activityName != '' ">
  949. and e.live_activity_title = #{activityName}
  950. </if>
  951. ) as activity
  952. left join (
  953. select * from (
  954. select count(*) as shareNum, a.be_share, a.tagert_type From ta_share_count a where a.tagert_type in ( 'activity', 'group','h5','help','liveApp','livePost')
  955. and a.org_id = #{orgId}
  956. <if test="startDate != null ">
  957. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  958. </if>
  959. <if test="endDate != null ">
  960. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  961. </if>
  962. <if test="startDate == null or endDate == null ">
  963. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  964. </if>
  965. group by a.be_share, tagert_type
  966. ) as a
  967. ) as shareNum on shareNum.be_share = activity.activityId and shareNum.tagert_type = activity.activityType
  968. left join (
  969. select count(*) as sharePersonNum ,sharePersonNum.be_share, sharePersonNum.tagert_type, sharePersonNum.create_date from (
  970. select a.* From ta_share_count a where a.tagert_type in ( 'activity', 'group','h5','help','liveApp','livePost') and a.org_id = #{orgId}
  971. <if test="startDate != null ">
  972. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  973. </if>
  974. <if test="endDate != null ">
  975. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  976. </if>
  977. <if test="startDate == null or endDate == null ">
  978. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  979. </if>
  980. group by a.person_id, be_share, tagert_type
  981. ) as sharePersonNum group by sharePersonNum.be_share, sharePersonNum.tagert_type
  982. ) as sharePersonNum on sharePersonNum.be_share = activity.activityId and sharePersonNum.tagert_type = activity.activityType
  983. left join (
  984. select * from (
  985. select count(*) as visitNum, a.target_id, a.event_type From ta_person_visit_record a where a.event_type in ('activity','group','h5','help') and a.`event` = 'detail' and a.org_id = #{orgId}
  986. <if test="startDate != null">
  987. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  988. </if>
  989. <if test="endDate != null">
  990. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  991. </if>
  992. <if test="startDate == null or endDate == null ">
  993. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  994. </if>
  995. group by a.target_id, a.event_type
  996. ) as a
  997. ) as visitNum on visitNum.target_id = activity.activityId and visitNum.event_type = activity.activityType
  998. left join (
  999. select count(*) as visitPersonNum ,visitPersonNum.target_id, visitPersonNum.event_type from (
  1000. select a.* From ta_person_visit_record a where a.event_type in ('activity','group','h5','help') and a.`event` = 'detail' and a.org_id = #{orgId}
  1001. <if test="startDate != null">
  1002. and a.visit_time &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  1003. </if>
  1004. <if test="endDate != null">
  1005. and a.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1006. </if>
  1007. <if test="startDate == null or endDate == null ">
  1008. AND a.visit_time BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1009. </if>
  1010. group by a.person_id, a.target_id, a.event_type
  1011. ) as visitPersonNum group by visitPersonNum.target_id, visitPersonNum.event_type
  1012. ) as visitPersonNum on visitPersonNum.target_id = activity.activityId and visitPersonNum.event_type = activity.activityType
  1013. left join (
  1014. select count(*) as addRegistNum ,addRegistNum.target_id, addRegistNum.target_type From (
  1015. select count(*), a.* From ta_share_person_from a where a.target_type IN ( 'dynamic_share', 'h5_share', 'help_share', 'live_share', 'group_share' ) and a.org_id = #{orgId}
  1016. and a.status = 1
  1017. and a.is_first_time = 1
  1018. <if test="startDate != null ">
  1019. and a.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  1020. </if>
  1021. <if test="endDate != null ">
  1022. and a.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1023. </if>
  1024. <if test="startDate == null or endDate == null">
  1025. AND a.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  1026. </if>
  1027. group by a.person_id, a.target_type ,a.target_id
  1028. ) as addRegistNum group by addRegistNum.target_type, addRegistNum.target_id
  1029. ) as addRegistNum on addRegistNum.target_id = activity.activityId and substring_index(addRegistNum.target_type, '_share', 1) = activity.activityType
  1030. <if test="targetType != null and targetType != ''">
  1031. where activity.activityType = #{targetType}
  1032. </if>
  1033. group by activity.activityId, activity.activityType
  1034. <if test="colKey == null or colKey == ''">
  1035. order by sharePersonNum.create_date desc
  1036. </if>
  1037. <if test="colKey != null and colKey != ''">
  1038. ORDER BY ${colKey} ${sort}
  1039. </if>
  1040. </select>
  1041. <select id="selectActivitySharePersonNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.SharePersonNum">
  1042. select person.nickname as sharePersonName,
  1043. ifnull(person.phone, '空') as sharePersonPhone ,
  1044. ifnull(shareNum, 0) as shareNum,
  1045. ifnull(visitNum, 0) as visitNum,
  1046. ifnull(visitPersonNum, 0) as visitPersonNum,
  1047. person.person_type as sharePersonType,
  1048. person.person_id
  1049. from (
  1050. SELECT t.*, f.nickname, f.phone, f.person_type
  1051. FROM ta_share_count t
  1052. LEFT JOIN ta_help_activity a
  1053. ON t.be_share = a.help_activity_id
  1054. LEFT JOIN ta_share_activity b
  1055. ON t.be_share = b.share_id
  1056. LEFT JOIN ta_live_activity c
  1057. ON t.be_share = c.live_activity_id
  1058. LEFT JOIN ta_drainage d
  1059. ON t.be_share = d.drainage_id
  1060. LEFT JOIN ta_building_dynamic e
  1061. ON t.be_share = e.dynamic_id
  1062. LEFT JOIN ta_person f
  1063. ON t.person_id = f.person_id
  1064. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1065. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1066. <if test="buildingId != null and buildingId != ''">
  1067. and (
  1068. a.building_id = #{buildingId}
  1069. or b.building_id = #{buildingId}
  1070. or c.building_id = #{buildingId}
  1071. or d.building_id = #{buildingId}
  1072. or e.building_id = #{buildingId}
  1073. )
  1074. </if>
  1075. <if test="activityId != null and activityId != ''">
  1076. and t.be_share = #{activityId}
  1077. </if>
  1078. <if test="activityType != null and activityType != ''">
  1079. and t.tagert_type = #{activityType}
  1080. </if>
  1081. <if test="sharePersonType != null and sharePersonType != ''">
  1082. and f.person_type = #{sharePersonType}
  1083. </if>
  1084. <if test="sharePersonName != null and sharePersonName != ''">
  1085. and f.nickname = #{sharePersonName}
  1086. </if>
  1087. <if test="sharePhone != null and sharePhone != ''">
  1088. and f.phone = #{sharePhone}
  1089. </if>
  1090. GROUP BY t.person_id
  1091. ) as person
  1092. left join (
  1093. select * from (
  1094. SELECT count(*) as shareNum, t.person_id
  1095. FROM ta_share_count t
  1096. LEFT JOIN ta_help_activity a
  1097. ON t.be_share = a.help_activity_id
  1098. LEFT JOIN ta_share_activity b
  1099. ON t.be_share = b.share_id
  1100. LEFT JOIN ta_live_activity c
  1101. ON t.be_share = c.live_activity_id
  1102. LEFT JOIN ta_drainage d
  1103. ON t.be_share = d.drainage_id
  1104. LEFT JOIN ta_building_dynamic e
  1105. ON t.be_share = e.dynamic_id
  1106. LEFT JOIN ta_person f
  1107. ON t.person_id = f.person_id
  1108. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1109. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1110. group by person_id
  1111. ) as temp
  1112. ) as shareNum on person.person_id = shareNum.person_id
  1113. left join (
  1114. SELECT t.visitNum, ifnull(a.person_id,b.person_id) AS person_id
  1115. FROM (
  1116. SELECT t.share_person, count(1) as visitNum
  1117. FROM ta_share_person_from t
  1118. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S') AND t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S') AND t.target_type IN ('dynamic_share', 'h5_share', 'help_share', 'live_share', 'group_share')
  1119. and t.org_id = #{orgId} group by t.share_person ) t
  1120. left join ta_person a on t.share_person = a.person_id
  1121. left join ta_person b on t.share_person = b.person_id
  1122. ) as visitNum on visitNum.person_id = person.person_id
  1123. left join (
  1124. SELECT t.visitPersonNum, ifnull(a.person_id,b.person_id) AS person_id
  1125. FROM (
  1126. SELECT count(DISTINCT t.person_id ) as visitPersonNum, t.share_person
  1127. FROM ta_share_person_from t
  1128. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1129. and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1130. and t.org_id = #{orgId} ) t
  1131. left join ta_person a on t.share_person = a.person_id
  1132. left join ta_person b on t.share_person = b.person_id
  1133. ) as visitPersonNum on visitPersonNum.person_id = person.person_id
  1134. <if test="colKey == null or colKey == ''">
  1135. order by person.create_date desc
  1136. </if>
  1137. <if test="colKey != null and colKey != ''">
  1138. ORDER BY ${colKey} ${sort}
  1139. </if>
  1140. </select>
  1141. <select id="selectActivitySharePersonNumExport" resultType="com.huiju.estateagents.excel.ActivityStatistics.SharePersonNum">
  1142. select person.nickname as sharePersonName,
  1143. ifnull(person.phone, '空') as sharePersonPhone ,
  1144. ifnull(shareNum, 0) as shareNum,
  1145. ifnull(visitNum, 0) as visitNum,
  1146. ifnull(visitPersonNum, 0) as visitPersonNum,
  1147. person.person_type as sharePersonType,
  1148. person.person_id
  1149. from (
  1150. SELECT t.*, f.nickname, f.phone, f.person_type
  1151. FROM ta_share_count t
  1152. LEFT JOIN ta_help_activity a
  1153. ON t.be_share = a.help_activity_id
  1154. LEFT JOIN ta_share_activity b
  1155. ON t.be_share = b.share_id
  1156. LEFT JOIN ta_live_activity c
  1157. ON t.be_share = c.live_activity_id
  1158. LEFT JOIN ta_drainage d
  1159. ON t.be_share = d.drainage_id
  1160. LEFT JOIN ta_building_dynamic e
  1161. ON t.be_share = e.dynamic_id
  1162. LEFT JOIN ta_person f
  1163. ON t.person_id = f.person_id
  1164. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1165. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1166. <if test="buildingId != null and buildingId != ''">
  1167. and (
  1168. a.building_id = #{buildingId}
  1169. or b.building_id = #{buildingId}
  1170. or c.building_id = #{buildingId}
  1171. or d.building_id = #{buildingId}
  1172. or e.building_id = #{buildingId}
  1173. )
  1174. </if>
  1175. <if test="activityId != null and activityId != ''">
  1176. and t.be_share = #{activityId}
  1177. </if>
  1178. <if test="activityType != null and activityType != ''">
  1179. and t.tagert_type = #{activityType}
  1180. </if>
  1181. <if test="sharePersonType != null and sharePersonType != ''">
  1182. and f.person_type = #{sharePersonType}
  1183. </if>
  1184. <if test="sharePersonName != null and sharePersonName != ''">
  1185. and f.nickname = #{sharePersonName}
  1186. </if>
  1187. <if test="sharePhone != null and sharePhone != ''">
  1188. and f.phone = #{sharePhone}
  1189. </if>
  1190. GROUP BY t.person_id
  1191. ) as person
  1192. left join (
  1193. select * from (
  1194. SELECT count(*) as shareNum, t.person_id
  1195. FROM ta_share_count t
  1196. LEFT JOIN ta_help_activity a
  1197. ON t.be_share = a.help_activity_id
  1198. LEFT JOIN ta_share_activity b
  1199. ON t.be_share = b.share_id
  1200. LEFT JOIN ta_live_activity c
  1201. ON t.be_share = c.live_activity_id
  1202. LEFT JOIN ta_drainage d
  1203. ON t.be_share = d.drainage_id
  1204. LEFT JOIN ta_building_dynamic e
  1205. ON t.be_share = e.dynamic_id
  1206. LEFT JOIN ta_person f
  1207. ON t.person_id = f.person_id
  1208. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost') and t.org_id = #{orgId}
  1209. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1210. group by person_id
  1211. ) as temp
  1212. ) as shareNum on person.person_id = shareNum.person_id
  1213. left join (
  1214. select t.visitNum, a.person_id AS person_id From (
  1215. select t.share_person, count(1) as visitNum from ta_share_person_from t WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S') AND t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S') AND t.target_type IN ('dynamic_share', 'h5_share', 'help_share', 'live_share', 'group_share')
  1216. and t.org_id = #{orgId} group by t.share_person
  1217. ) t
  1218. LEFT JOIN (SELECT a.person_id, b.user_id
  1219. FROM ta_person a
  1220. LEFT JOIN ta_user b
  1221. ON a.user_id = b.user_id
  1222. WHERE a.org_id = #{orgId}) AS a
  1223. ON t.share_person = a.person_id OR t.share_person = a.user_id
  1224. ) as visitNum on visitNum.person_id = person.person_id
  1225. left join (
  1226. SELECT count(1) as visitPersonNum, visitPersonNum.share_person as person_id
  1227. FROM (
  1228. select t.*, a.person_id From (
  1229. SELECT count(1) as visitPersonNum , t.share_person
  1230. FROM ta_share_person_from t
  1231. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1232. and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1233. and t.org_id = #{orgId} group by t.person_id
  1234. ) as t
  1235. LEFT JOIN (
  1236. SELECT a.person_id, b.user_id
  1237. FROM ta_person a
  1238. LEFT JOIN ta_user b
  1239. ON a.user_id = b.user_id
  1240. WHERE a.org_id = 84 ) as a
  1241. ON t.share_person = a.person_id or t.share_person = a.user_id
  1242. ) as visitPersonNum group by visitPersonNum.person_id
  1243. ) as visitPersonNum on visitPersonNum.person_id = person.person_id
  1244. <if test="colKey == null or colKey == ''">
  1245. order by person.create_date desc
  1246. </if>
  1247. <if test="colKey != null and colKey != ''">
  1248. ORDER BY ${colKey} ${sort}
  1249. </if>
  1250. </select>
  1251. <select id="selectActivityShareNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.ShareNum">
  1252. select person.nickname as sharePersonName,
  1253. ifnull(person.phone, '空') as sharePersonPhone ,
  1254. person.create_date as shareTime,
  1255. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1256. person.person_type as sharePersonType
  1257. FROM (
  1258. SELECT t.*, f.nickname, f.phone, f.person_type
  1259. FROM ta_share_count t
  1260. LEFT JOIN ta_help_activity a
  1261. ON t.be_share = a.help_activity_id
  1262. LEFT JOIN ta_share_activity b
  1263. ON t.be_share = b.share_id
  1264. LEFT JOIN ta_live_activity c
  1265. ON t.be_share = c.live_activity_id
  1266. LEFT JOIN ta_drainage d
  1267. ON t.be_share = d.drainage_id
  1268. LEFT JOIN ta_building_dynamic e
  1269. ON t.be_share = e.dynamic_id
  1270. LEFT JOIN ta_person f
  1271. ON t.person_id = f.person_id
  1272. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost')
  1273. <if test="activityId != null and activityId != ''">
  1274. and t.be_share = #{activityId}
  1275. </if>
  1276. <if test="activityType != null and activityType != ''">
  1277. and t.tagert_type = #{activityType}
  1278. </if>
  1279. <if test="buildingId != null and buildingId != ''">
  1280. and (
  1281. a.building_id = #{buildingId}
  1282. or b.building_id = #{buildingId}
  1283. or c.building_id = #{buildingId}
  1284. or d.building_id = #{buildingId}
  1285. or e.building_id = #{buildingId}
  1286. )
  1287. </if>
  1288. and t.org_id = #{orgId}
  1289. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' )
  1290. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1291. <if test="personId != null and personId != ''">
  1292. and t.person_id = #{personId}
  1293. </if>
  1294. ) as person
  1295. LEFT JOIN (
  1296. SELECT count(*) as visitPersonNum,t.share_person as person_id
  1297. FROM ta_share_person_from t
  1298. where t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  1299. <if test="personId != null and personId != ''">
  1300. and t.share_person = #{personId}
  1301. </if>
  1302. <if test="startDate != null ">
  1303. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  1304. </if>
  1305. <if test="endDate != null ">
  1306. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1307. </if>
  1308. ) as visitPersonNum
  1309. ON visitPersonNum.person_id = person.person_id order by person.create_date desc
  1310. </select>
  1311. <select id="selectActivityShareNumExport" resultType="com.huiju.estateagents.excel.ActivityStatistics.ShareNum">
  1312. select person.nickname as sharePersonName,
  1313. ifnull(person.phone, '空') as sharePersonPhone ,
  1314. person.create_date as shareTime,
  1315. ifnull(visitPersonNum.visitPersonNum, 0) as visitPersonNum,
  1316. CASE
  1317. WHEN person.person_type = 'drift' THEN
  1318. "游客"
  1319. WHEN person.person_type = 'customer' THEN
  1320. "客户"
  1321. WHEN person.person_type = 'Realty Consultant' THEN
  1322. "置业顾问"
  1323. END `sharePersonType`
  1324. FROM (
  1325. SELECT t.*, f.nickname, f.phone, f.person_type
  1326. FROM ta_share_count t
  1327. LEFT JOIN ta_help_activity a
  1328. ON t.be_share = a.help_activity_id
  1329. LEFT JOIN ta_share_activity b
  1330. ON t.be_share = b.share_id
  1331. LEFT JOIN ta_live_activity c
  1332. ON t.be_share = c.live_activity_id
  1333. LEFT JOIN ta_drainage d
  1334. ON t.be_share = d.drainage_id
  1335. LEFT JOIN ta_building_dynamic e
  1336. ON t.be_share = e.dynamic_id
  1337. LEFT JOIN ta_person f
  1338. ON t.person_id = f.person_id
  1339. WHERE t.tagert_type in ('activity','group','h5','help','liveApp','livePost')
  1340. <if test="activityId != null and activityId != ''">
  1341. and t.be_share = #{activityId}
  1342. </if>
  1343. <if test="activityType != null and activityType != ''">
  1344. and t.tagert_type = #{activityType}
  1345. </if>
  1346. <if test="buildingId != null and buildingId != ''">
  1347. and (
  1348. a.building_id = #{buildingId}
  1349. or b.building_id = #{buildingId}
  1350. or c.building_id = #{buildingId}
  1351. or d.building_id = #{buildingId}
  1352. or e.building_id = #{buildingId}
  1353. )
  1354. </if>
  1355. and t.org_id = #{orgId}
  1356. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' )
  1357. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' )
  1358. <if test="personId != null and personId != ''">
  1359. and t.person_id = #{personId}
  1360. </if>
  1361. ) as person
  1362. LEFT JOIN (
  1363. SELECT count(*) as visitPersonNum,t.share_person as person_id
  1364. FROM ta_share_person_from t
  1365. where t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  1366. <if test="personId != null and personId != ''">
  1367. and t.share_person = #{personId}
  1368. </if>
  1369. <if test="startDate != null ">
  1370. and t.create_date &gt;= DATE_FORMAT(#{startDate}, '%Y-%m-%d' )
  1371. </if>
  1372. <if test="endDate != null ">
  1373. and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1374. </if>
  1375. ) as visitPersonNum
  1376. ON visitPersonNum.person_id = person.person_id order by person.create_date desc
  1377. </select>
  1378. <select id="selectActivityAddRegistNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.AddRegistNum">
  1379. SELECT
  1380. a.nickname, a.phone,
  1381. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1382. a.province,
  1383. b1.scene_name as personFrom,
  1384. GROUP_CONCAT(c.name) as realtyConsultant,
  1385. ifnull(d.phone, d.tel) as realtyConsultantPhone,
  1386. ifnull(e.nickname, f.user_name) as sharePersonName,
  1387. ifnull(e.phone, e.tel) as sharePersonPhone
  1388. FROM ta_share_person_from t
  1389. left join ta_person a on t.person_id = a.person_id
  1390. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = 84 and b.is_first_time =1
  1391. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1392. left join ta_recommend_customer c on c.person_id = t.person_id
  1393. left join ta_person d on c.recommend_person = d.person_id
  1394. left join ta_person e on t.share_person = e.person_id
  1395. left join ta_user f on t.share_person = f.user_id
  1396. WHERE t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId} and t.status = 1
  1397. and t.is_first_time = 1
  1398. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1399. <if test="activityId != null and activityId != ''">
  1400. and t.target_id = #{activityId}
  1401. </if>
  1402. <if test="activityType != null and activityType != ''">
  1403. and t.target_type = concat(#{activityType}, '_share')
  1404. </if>
  1405. <if test="personFrom != null and personFrom != ''">
  1406. and b.scene_id = #{personFrom}
  1407. </if>
  1408. <if test="buildingId != null and buildingId != ''">
  1409. and c.building_id = #{buildingId}
  1410. </if>
  1411. group by t.person_id
  1412. </select>
  1413. <select id="selectActivityAddRegistNumExport" resultType="com.huiju.estateagents.excel.ActivityStatistics.AddRegistNum">
  1414. SELECT
  1415. a.nickname, a.phone,
  1416. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1417. a.province,
  1418. b1.scene_name as personFrom,
  1419. d.name as realtyConsultant,
  1420. d.phone as realtyConsultantPhone,
  1421. ifnull(e.nickname, f.user_name) as sharePersonName,
  1422. e.phone as sharePersonPhone
  1423. FROM ta_share_person_from t
  1424. left join ta_person a on t.person_id = a.person_id
  1425. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = 84 and b.is_first_time =1
  1426. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1427. left join ta_recommend_customer c on c.person_id = t.person_id
  1428. left join ta_person d on c.recommend_person = d.person_id
  1429. left join ta_person e on t.share_person = e.person_id
  1430. left join ta_user f on t.share_person = f.user_id
  1431. WHERE t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id = #{orgId}
  1432. and t.status = 1
  1433. and t.is_first_time = 1
  1434. and t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d' )
  1435. <if test="activityId != null and activityId != ''">
  1436. and t.target_id = #{activityId}
  1437. </if>
  1438. <if test="activityType != null and activityType != ''">
  1439. and t.target_type = concat(#{activityType}, '_share')
  1440. </if>
  1441. <if test="personFrom != null and personFrom != ''">
  1442. and b.scene_id = #{personFrom}
  1443. </if>
  1444. <if test="buildingId != null and buildingId != ''">
  1445. and c.building_id = #{buildingId}
  1446. </if>
  1447. </select>
  1448. <select id="selectActivityVisitNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  1449. select
  1450. a.nickname, a.phone,
  1451. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1452. a.province,
  1453. b1.scene_name as personFrom,
  1454. d.name as realtyConsultant,
  1455. d.phone as realtyConsultantPhone,
  1456. t.visit_time as visitDate
  1457. From (
  1458. SELECT
  1459. t.person_id, t.visit_time
  1460. FROM
  1461. ta_person_visit_record t
  1462. WHERE
  1463. t.`event` = 'detail'
  1464. AND t.event_type IN (
  1465. 'activity',
  1466. 'help',
  1467. 'group',
  1468. 'h5'
  1469. )
  1470. <if test="activityId != null and activityId != ''">
  1471. and t.target_id = #{activityId}
  1472. </if>
  1473. <if test="activityType != null and activityType != ''">
  1474. and t.event_type = #{activityType}
  1475. </if>
  1476. <if test="buildingId != null and buildingId != ''">
  1477. and t.building_id = #{buildingId}
  1478. </if>
  1479. AND t.org_id = #{orgId}
  1480. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  1481. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  1482. ) t
  1483. left join ta_person a on t.person_id = a.person_id
  1484. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  1485. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1486. left join (
  1487. select d.person_id, d.`name`, d.phone From ta_recommend_customer c
  1488. left join ta_person d on c.recommend_person = d.person_id where c.org_id = #{orgId} group by d.person_id
  1489. ) as d on t.person_id = d.person_id
  1490. <where>
  1491. <if test="personFrom != null and personFrom != ''">
  1492. and b.scene_id = #{personFrom}
  1493. </if>
  1494. <if test="province != null and province != ''">
  1495. and a.province = #{province}
  1496. </if>
  1497. <if test="realtyConsultant != null and realtyConsultant != ''">
  1498. and d.name = #{realtyConsultant}
  1499. </if>
  1500. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  1501. and d.phone = #{realtyConsultantPhone}
  1502. </if>
  1503. </where>
  1504. order by t.visit_time desc
  1505. </select>
  1506. <select id="selectActivityVisitNumExport" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  1507. select
  1508. a.nickname, a.phone,
  1509. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1510. a.province,
  1511. b1.scene_name as personFrom,
  1512. d.name as realtyConsultant,
  1513. d.phone as realtyConsultantPhone,
  1514. t.visit_time as visitDate
  1515. From (
  1516. SELECT
  1517. t.person_id, t.visit_time
  1518. FROM
  1519. ta_person_visit_record t
  1520. WHERE
  1521. t.`event` = 'detail'
  1522. AND t.event_type IN (
  1523. 'activity',
  1524. 'help',
  1525. 'group',
  1526. 'h5'
  1527. )
  1528. <if test="activityId != null and activityId != ''">
  1529. and t.target_id = #{activityId}
  1530. </if>
  1531. <if test="activityType != null and activityType != ''">
  1532. and t.event_type = #{activityType}
  1533. </if>
  1534. <if test="buildingId != null and buildingId != ''">
  1535. and t.building_id = #{buildingId}
  1536. </if>
  1537. AND t.org_id = #{orgId}
  1538. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  1539. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  1540. ) t
  1541. left join ta_person a on t.person_id = a.person_id
  1542. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  1543. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1544. left join (
  1545. select d.person_id, d.`name`, d.phone From ta_recommend_customer c
  1546. left join ta_person d on c.recommend_person = d.person_id where c.org_id = #{orgId} group by d.person_id
  1547. ) as d on t.person_id = d.person_id
  1548. <where>
  1549. <if test="personFrom != null and personFrom != ''">
  1550. and b.scene_id = #{personFrom}
  1551. </if>
  1552. <if test="province != null and province != ''">
  1553. and a.province = #{province}
  1554. </if>
  1555. <if test="realtyConsultant != null and realtyConsultant != ''">
  1556. and d.name = #{realtyConsultant}
  1557. </if>
  1558. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  1559. and d.phone = #{realtyConsultantPhone}
  1560. </if>
  1561. </where>
  1562. order by t.visit_time desc
  1563. </select>
  1564. <select id="selectActivityVisitPersonNum" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  1565. select
  1566. a.nickname, a.phone,
  1567. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1568. a.province,
  1569. b1.scene_name as personFrom,
  1570. d.name as realtyConsultant,
  1571. d.phone as realtyConsultantPhone,
  1572. t.create_date as visitDate,
  1573. t.visitNum
  1574. from (
  1575. SELECT
  1576. t.visit_time AS create_date,
  1577. t.person_id,
  1578. count(*) as visitNum
  1579. FROM
  1580. ta_person_visit_record t
  1581. WHERE
  1582. t.`event` = 'detail'
  1583. AND t.event_type IN (
  1584. 'activity',
  1585. 'help',
  1586. 'group',
  1587. 'h5'
  1588. )
  1589. AND t.org_id = #{orgId}
  1590. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  1591. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  1592. <if test="activityId != null and activityId != ''">
  1593. and t.target_id = #{activityId}
  1594. </if>
  1595. <if test="activityType != null and activityType != ''">
  1596. and t.event_type = #{activityType}
  1597. </if>
  1598. <if test="buildingId != null and buildingId != ''">
  1599. and t.building_id = #{buildingId}
  1600. </if>
  1601. GROUP BY
  1602. t.person_id ) as t
  1603. left join ta_person a on t.person_id = a.person_id
  1604. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  1605. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1606. left join (
  1607. select d.person_id, d.`name`, d.phone From ta_recommend_customer c
  1608. left join ta_person d on c.recommend_person = d.person_id where c.org_id = #{orgId} group by d.person_id
  1609. ) as d on t.person_id = d.person_id
  1610. <where>
  1611. <if test="personFrom != null and personFrom != ''">
  1612. and b.scene_id = #{personFrom}
  1613. </if>
  1614. <if test="province != null and province != ''">
  1615. and a.province = #{province}
  1616. </if>
  1617. <if test="realtyConsultant != null and realtyConsultant != ''">
  1618. and d.name = #{realtyConsultant}
  1619. </if>
  1620. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  1621. and d.phone = #{realtyConsultantPhone}
  1622. </if>
  1623. </where>
  1624. order by t.create_date desc
  1625. </select>
  1626. <select id="selectActivityVisitPersonNumExport"
  1627. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  1628. select
  1629. a.nickname, a.phone,
  1630. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1631. a.province,
  1632. b1.scene_name as personFrom,
  1633. d.name as realtyConsultant,
  1634. d.phone as realtyConsultantPhone,
  1635. t.create_date as visitDate,
  1636. t.visitNum
  1637. from (
  1638. SELECT
  1639. t.visit_time AS create_date,
  1640. t.person_id,
  1641. count(*) as visitNum
  1642. FROM
  1643. ta_person_visit_record t
  1644. WHERE
  1645. t.`event` = 'detail'
  1646. AND t.event_type IN (
  1647. 'activity',
  1648. 'help',
  1649. 'group',
  1650. 'h5'
  1651. )
  1652. AND t.org_id = #{orgId}
  1653. AND t.visit_time >= DATE_FORMAT(#{startDate}, '%Y-%m-%d')
  1654. AND t.visit_time &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d')
  1655. <if test="activityId != null and activityId != ''">
  1656. and t.target_id = #{activityId}
  1657. </if>
  1658. <if test="activityType != null and activityType != ''">
  1659. and t.event_type = #{activityType}
  1660. </if>
  1661. <if test="buildingId != null and buildingId != ''">
  1662. and t.building_id = #{buildingId}
  1663. </if>
  1664. GROUP BY
  1665. t.person_id ) as t
  1666. left join ta_person a on t.person_id = a.person_id
  1667. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  1668. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1669. left join (
  1670. select d.person_id, d.`name`, d.phone From ta_recommend_customer c
  1671. left join ta_person d on c.recommend_person = d.person_id where c.org_id = #{orgId} group by d.person_id
  1672. ) as d on t.person_id = d.person_id
  1673. <where>
  1674. <if test="personFrom != null and personFrom != ''">
  1675. and b.scene_id = #{personFrom}
  1676. </if>
  1677. <if test="province != null and province != ''">
  1678. and a.province = #{province}
  1679. </if>
  1680. <if test="realtyConsultant != null and realtyConsultant != ''">
  1681. and d.name = #{realtyConsultant}
  1682. </if>
  1683. <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
  1684. and d.phone = #{realtyConsultantPhone}
  1685. </if>
  1686. </where>
  1687. order by t.create_date desc
  1688. </select>
  1689. <select id="selectActivityVisitPersonNumByPersonId" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  1690. select
  1691. a.nickname, a.phone,
  1692. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1693. a.province,
  1694. b1.scene_name as personFrom,
  1695. d.name as realtyConsultant,
  1696. d.phone as realtyConsultantPhone,
  1697. t.create_date as visitDate,
  1698. t.visitNum
  1699. From (
  1700. SELECT count(1) as visitNum, t.person_id, t.create_date
  1701. FROM ta_share_person_from t
  1702. LEFT JOIN (
  1703. SELECT a.person_id, b.user_id
  1704. FROM ta_person a
  1705. LEFT JOIN ta_user b
  1706. ON a.user_id = b.user_id
  1707. WHERE a.org_id = #{orgId} ) as a ON t.share_person = a.person_id or t.share_person = a.user_id
  1708. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1709. and t.share_person = #{personId} group by t.person_id
  1710. ) as t
  1711. left join ta_person a on t.person_id = a.person_id
  1712. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  1713. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1714. left join (
  1715. select d.person_id, d.`name`, d.phone From ta_recommend_customer c
  1716. left join ta_person d on c.recommend_person = d.person_id where c.org_id = #{orgId} group by d.person_id
  1717. ) as d on t.person_id = d.person_id
  1718. </select>
  1719. <select id="selectActivityVisitNumByPersonId" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  1720. select
  1721. a.nickname, a.phone,
  1722. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1723. a.province,
  1724. b1.scene_name as personFrom,
  1725. d.name as realtyConsultant,
  1726. d.phone as realtyConsultantPhone,
  1727. t.create_date as visitDate
  1728. From (
  1729. SELECT t.person_id, t.create_date
  1730. FROM ta_share_person_from t
  1731. LEFT JOIN (
  1732. SELECT a.person_id, b.user_id
  1733. FROM ta_person a
  1734. LEFT JOIN ta_user b
  1735. ON a.user_id = b.user_id
  1736. WHERE a.org_id = #{orgId} ) as a ON t.share_person = a.person_id or t.share_person = a.user_id
  1737. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1738. and t.share_person = #{personId}
  1739. ) as t
  1740. left join ta_person a on t.person_id = a.person_id
  1741. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  1742. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1743. left join (
  1744. select d.person_id, d.`name`, d.phone From ta_recommend_customer c
  1745. left join ta_person d on c.recommend_person = d.person_id where c.org_id = #{orgId} group by d.person_id
  1746. ) as d on t.person_id = d.person_id
  1747. </select>
  1748. <select id="selectActivityVisitPersonNumExportByPersonId"
  1749. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitPersonNum">
  1750. select
  1751. a.nickname, a.phone,
  1752. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1753. a.province,
  1754. b1.scene_name as personFrom,
  1755. d.name as realtyConsultant,
  1756. d.phone as realtyConsultantPhone,
  1757. t.create_date as visitDate,
  1758. t.visitNum
  1759. From (
  1760. SELECT count(1) as visitNum, t.person_id, t.create_date
  1761. FROM ta_share_person_from t
  1762. LEFT JOIN (
  1763. SELECT a.person_id, b.user_id
  1764. FROM ta_person a
  1765. LEFT JOIN ta_user b
  1766. ON a.user_id = b.user_id
  1767. WHERE a.org_id = #{orgId} ) as a ON t.share_person = a.person_id or t.share_person = a.user_id
  1768. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1769. and t.share_person = #{personId} group by t.person_id
  1770. ) as t
  1771. left join ta_person a on t.person_id = a.person_id
  1772. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  1773. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1774. left join (
  1775. select d.person_id, d.`name`, d.phone From ta_recommend_customer c
  1776. left join ta_person d on c.recommend_person = d.person_id where c.org_id = #{orgId} group by d.person_id
  1777. ) as d on t.person_id = d.person_id
  1778. </select>
  1779. <select id="selectActivityVisitNumExportByPersonId"
  1780. resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
  1781. select
  1782. a.nickname, a.phone,
  1783. if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
  1784. a.province,
  1785. b1.scene_name as personFrom,
  1786. d.name as realtyConsultant,
  1787. d.phone as realtyConsultantPhone,
  1788. t.create_date as visitDate
  1789. From (
  1790. SELECT t.person_id, t.create_date
  1791. FROM ta_share_person_from t
  1792. LEFT JOIN (
  1793. SELECT a.person_id, b.user_id
  1794. FROM ta_person a
  1795. LEFT JOIN ta_user b
  1796. ON a.user_id = b.user_id
  1797. WHERE a.org_id = #{orgId} ) as a ON t.share_person = a.person_id or t.share_person = a.user_id
  1798. WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;= DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share')
  1799. and t.share_person = #{personId}
  1800. ) as t
  1801. left join ta_person a on t.person_id = a.person_id
  1802. left join ta_person_from_record b on a.person_id = b.person_id and b.org_id = #{orgId}
  1803. left join td_wx_dict b1 on b.scene_id = b1.scene_id
  1804. left join (
  1805. select d.person_id, d.`name`, d.phone From ta_recommend_customer c
  1806. left join ta_person d on c.recommend_person = d.person_id where c.org_id = #{orgId} group by d.person_id
  1807. ) as d on t.person_id = d.person_id
  1808. </select>
  1809. </mapper>