TaActivityStaticMapper.xml 114KB

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