TaActivityStaticMapper.xml 76KB

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