魏超 il y a 5 ans
Parent
révision
0a61b8e0be
1 fichiers modifiés avec 72 ajouts et 40 suppressions
  1. 72
    40
      src/main/resources/mapper/statistic/TaActivityStaticMapper.xml

+ 72
- 40
src/main/resources/mapper/statistic/TaActivityStaticMapper.xml Voir le fichier

@@ -1649,8 +1649,10 @@
1649 1649
         </if>
1650 1650
         ) as person
1651 1651
         LEFT JOIN (
1652
-        SELECT count(*) as visitPersonNum,t.share_person as person_id
1652
+        SELECT count(*) as visitPersonNum, ifnull(a.person_id,b.person_id) as person_id
1653 1653
         FROM ta_share_person_from t
1654
+        left join ta_person a on t.share_person = a.person_id
1655
+        left join ta_person b on t.share_person = b.user_id
1654 1656
         where t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id =
1655 1657
         #{orgId}
1656 1658
         <if test="personId != null and personId != ''">
@@ -1741,8 +1743,10 @@
1741 1743
         </if>
1742 1744
         ) as person
1743 1745
         LEFT JOIN (
1744
-        SELECT count(*) as visitPersonNum,t.share_person as person_id
1746
+        SELECT count(*) as visitPersonNum, ifnull(a.person_id,b.person_id) as person_id
1745 1747
         FROM ta_share_person_from t
1748
+        left join ta_person a on t.share_person = a.person_id
1749
+        left join ta_person b on t.share_person = b.user_id
1746 1750
         where t.target_type in ('dynamic_share','h5_share','help_share','live_share', 'group_share') and t.org_id =
1747 1751
         #{orgId}
1748 1752
         <if test="personId != null and personId != ''">
@@ -1788,7 +1792,7 @@
1788 1792
             and t.target_type = concat(#{activityType}, '_share')
1789 1793
         </if>
1790 1794
         <if test="personFrom != null and personFrom != ''">
1791
-            and b.scene_id = #{personFrom}
1795
+            and b.scene_type = #{personFrom}
1792 1796
         </if>
1793 1797
         <if test="buildingId != null and buildingId != ''">
1794 1798
             and c.building_id = #{buildingId}
@@ -1827,7 +1831,7 @@
1827 1831
             and t.target_type = concat(#{activityType}, '_share')
1828 1832
         </if>
1829 1833
         <if test="personFrom != null and personFrom != ''">
1830
-            and b.scene_id = #{personFrom}
1834
+            and b.scene_type = #{personFrom}
1831 1835
         </if>
1832 1836
         <if test="buildingId != null and buildingId != ''">
1833 1837
             and c.building_id = #{buildingId}
@@ -1840,13 +1844,15 @@
1840 1844
         a.nickname, a.phone,
1841 1845
         if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
1842 1846
         a.province,
1843
-        b1.scene_name as personFrom,
1844
-        d.user_name as realtyConsultant,
1845
-        d.phone as realtyConsultantPhone,
1847
+        b1.scene_alias as personFrom,
1848
+        GROUP_CONCAT(d.user_name) as realtyConsultant,
1849
+        GROUP_CONCAT(d.phone) as realtyConsultantPhone,
1850
+        e.nickname as sharePersonName,
1851
+        e.phone as sharePersonPhone,
1846 1852
         t.visit_time as visitDate
1847 1853
         From (
1848 1854
         SELECT
1849
-        t.person_id, t.visit_time
1855
+        t.person_id, t.visit_time, t.share_person_id
1850 1856
         FROM
1851 1857
         ta_person_visit_record t
1852 1858
         WHERE
@@ -1861,7 +1867,8 @@
1861 1867
             and t.target_id = #{activityId}
1862 1868
         </if>
1863 1869
         <if test="activityType != null and activityType != ''">
1864
-            and t.target_type = #{activityType}
1870
+            and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{activityType}
1871
+            end)
1865 1872
         </if>
1866 1873
         <if test="buildingId != null and buildingId != ''">
1867 1874
             and t.building_id = #{buildingId}
@@ -1875,20 +1882,22 @@
1875 1882
         left join td_wx_dict b1 on b.scene_id = b1.scene_id
1876 1883
         LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
1877 1884
         left join ta_user d on c.realty_consultant = d.user_id
1885
+        left join ta_person e on t.share_person_id = e.person_id
1878 1886
         <where>
1879 1887
             <if test="personFrom != null and personFrom != ''">
1880
-                and b.scene_id = #{personFrom}
1888
+                and b.scene_type = #{personFrom}
1881 1889
             </if>
1882 1890
             <if test="province != null and province != ''">
1883
-                and a.province = #{province}
1891
+                and a.province like concat('%', #{province}, '%')
1884 1892
             </if>
1885 1893
             <if test="realtyConsultant != null and realtyConsultant != ''">
1886
-                and d.name = #{realtyConsultant}
1894
+                and d.user_name like concat('%', #{realtyConsultant}, '%')
1887 1895
             </if>
1888 1896
             <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
1889
-                and d.phone = #{realtyConsultantPhone}
1897
+                and d.phone like concat('%', #{realtyConsultantPhone}, '%')
1890 1898
             </if>
1891 1899
         </where>
1900
+        group by t.visit_time
1892 1901
         order by t.visit_time desc
1893 1902
     </select>
1894 1903
 
@@ -1897,13 +1906,15 @@
1897 1906
         a.nickname, a.phone,
1898 1907
         if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
1899 1908
         a.province,
1900
-        b1.scene_name as personFrom,
1901
-        d.user_name as realtyConsultant,
1902
-        d.phone as realtyConsultantPhone,
1909
+        b1.scene_alias as personFrom,
1910
+        GROUP_CONCAT(d.user_name) as realtyConsultant,
1911
+        GROUP_CONCAT(d.phone) as realtyConsultantPhone,
1912
+        e.nickname as sharePersonName,
1913
+        e.phone as sharePersonPhone,
1903 1914
         t.visit_time as visitDate
1904 1915
         From (
1905 1916
         SELECT
1906
-        t.person_id, t.visit_time
1917
+        t.person_id, t.visit_time, t.share_person_id
1907 1918
         FROM
1908 1919
         ta_person_visit_record t
1909 1920
         WHERE
@@ -1918,7 +1929,8 @@
1918 1929
             and t.target_id = #{activityId}
1919 1930
         </if>
1920 1931
         <if test="activityType != null and activityType != ''">
1921
-            and t.target_type = #{activityType}
1932
+            and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{activityType}
1933
+            end)
1922 1934
         </if>
1923 1935
         <if test="buildingId != null and buildingId != ''">
1924 1936
             and t.building_id = #{buildingId}
@@ -1932,20 +1944,22 @@
1932 1944
         left join td_wx_dict b1 on b.scene_id = b1.scene_id
1933 1945
         LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
1934 1946
         left join ta_user d on c.realty_consultant = d.user_id
1947
+        left join ta_person e on t.share_person_id = e.person_id
1935 1948
         <where>
1936 1949
             <if test="personFrom != null and personFrom != ''">
1937
-                and b.scene_id = #{personFrom}
1950
+                and b.scene_type = #{personFrom}
1938 1951
             </if>
1939 1952
             <if test="province != null and province != ''">
1940
-                and a.province = #{province}
1953
+                and a.province like concat('%', #{province}, '%')
1941 1954
             </if>
1942 1955
             <if test="realtyConsultant != null and realtyConsultant != ''">
1943
-                and d.name = #{realtyConsultant}
1956
+                and d.user_name like concat('%', #{realtyConsultant}, '%')
1944 1957
             </if>
1945 1958
             <if test="realtyConsultantPhone != null and realtyConsultantPhone != ''">
1946
-                and d.phone = #{realtyConsultantPhone}
1959
+                and d.phone like concat('%', #{realtyConsultantPhone}, '%')
1947 1960
             </if>
1948 1961
         </where>
1962
+        group by t.visit_time
1949 1963
         order by t.visit_time desc
1950 1964
     </select>
1951 1965
 
@@ -1957,7 +1971,7 @@
1957 1971
         a.province,
1958 1972
         b1.scene_alias as personFrom,
1959 1973
         GROUP_CONCAT(d.user_name) as realtyConsultant,
1960
-        d.phone as realtyConsultantPhone,
1974
+        GROUP_CONCAT(d.phone) as realtyConsultantPhone,
1961 1975
         t.create_date as visitDate,
1962 1976
         ifnull(e.nickName, f.user_name) as sharePersonName,
1963 1977
         t.visitNum
@@ -1983,7 +1997,8 @@
1983 1997
             and t.target_id = #{activityId}
1984 1998
         </if>
1985 1999
         <if test="activityType != null and activityType != ''">
1986
-            and t.target_type = #{activityType}
2000
+            and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{activityType}
2001
+            end)
1987 2002
         </if>
1988 2003
         <if test="buildingId != null and buildingId != ''">
1989 2004
             and t.building_id = #{buildingId}
@@ -1999,10 +2014,10 @@
1999 2014
         left join ta_user f on f.user_id = c.recommend_person
2000 2015
         <where>
2001 2016
             <if test="personFrom != null and personFrom != ''">
2002
-                and b.scene_id = #{personFrom}
2017
+                and b.scene_type = #{personFrom}
2003 2018
             </if>
2004 2019
             <if test="province != null and province != ''">
2005
-                and a.province = #{province}
2020
+                and a.province like concat('%', #{province},'%')
2006 2021
             </if>
2007 2022
             <if test="realtyConsultant != null and realtyConsultant != ''">
2008 2023
                 and d.user_name like concat('%', #{realtyConsultant},'%')
@@ -2023,7 +2038,7 @@
2023 2038
         a.province,
2024 2039
         b1.scene_alias as personFrom,
2025 2040
         GROUP_CONCAT(d.user_name) as realtyConsultant,
2026
-        d.phone as realtyConsultantPhone,
2041
+        GROUP_CONCAT(d.phone) as realtyConsultantPhone,
2027 2042
         t.create_date as visitDate,
2028 2043
         ifnull(e.nickName, f.user_name) as sharePersonName,
2029 2044
         t.visitNum
@@ -2049,7 +2064,8 @@
2049 2064
             and t.target_id = #{activityId}
2050 2065
         </if>
2051 2066
         <if test="activityType != null and activityType != ''">
2052
-            and t.target_type = #{activityType}
2067
+            and (case when #{activityType} = 'activity' then t.target_type = 'dynamic' else t.target_type = #{activityType}
2068
+            end)
2053 2069
         </if>
2054 2070
         <if test="buildingId != null and buildingId != ''">
2055 2071
             and t.building_id = #{buildingId}
@@ -2065,10 +2081,10 @@
2065 2081
         left join ta_user f on f.user_id = c.recommend_person
2066 2082
         <where>
2067 2083
             <if test="personFrom != null and personFrom != ''">
2068
-                and b.scene_id = #{personFrom}
2084
+                and b.scene_type = #{personFrom}
2069 2085
             </if>
2070 2086
             <if test="province != null and province != ''">
2071
-                and a.province = #{province}
2087
+                and a.province like concat('%', #{province},'%')
2072 2088
             </if>
2073 2089
             <if test="realtyConsultant != null and realtyConsultant != ''">
2074 2090
                 and d.user_name like concat('%', #{realtyConsultant},'%')
@@ -2088,8 +2104,8 @@
2088 2104
         if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
2089 2105
         a.province,
2090 2106
         b1.scene_alias as personFrom,
2091
-        d.user_name as realtyConsultant,
2092
-        d.phone as realtyConsultantPhone,
2107
+        GROUP_CONCAT(d.user_name) as realtyConsultant,
2108
+        GROUP_CONCAT(d.phone) as realtyConsultantPhone,
2093 2109
         t.create_date as visitDate,
2094 2110
         ifnull(e.nickName, f.user_name) as sharePersonName,
2095 2111
         t.visitNum
@@ -2112,6 +2128,7 @@
2112 2128
         left join ta_user d on c.realty_consultant = d.user_id
2113 2129
         left join ta_person e on e.person_id = c.recommend_person
2114 2130
         left join ta_user f on f.user_id = c.recommend_person
2131
+        group by t.person_id
2115 2132
     </select>
2116 2133
 
2117 2134
     <select id="selectActivityVisitNumByPersonId" resultType="com.huiju.estateagents.excel.ActivityStatistics.VisitNum">
@@ -2122,9 +2139,11 @@
2122 2139
         b1.scene_alias as personFrom,
2123 2140
         d.user_name as realtyConsultant,
2124 2141
         d.phone as realtyConsultantPhone,
2125
-        t.create_date as visitDate
2142
+        t.create_date as visitDate,
2143
+        ifnull(e.nickname, f.user_name) as sharePersonName,
2144
+        ifnull(e.phone, f.phone) as sharePersonPhone
2126 2145
         From (
2127
-        SELECT t.person_id, t.create_date
2146
+        SELECT t.person_id, t.create_date, t.share_person
2128 2147
         FROM ta_share_person_from t
2129 2148
         LEFT JOIN (
2130 2149
         SELECT a.person_id, b.user_id
@@ -2135,7 +2154,9 @@
2135 2154
         WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
2136 2155
         DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in
2137 2156
         ('dynamic_share','h5_share','help_share','live_share', 'group_share')
2138
-        and t.share_person = #{personId}
2157
+        and
2158
+        (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})
2159
+        or t.share_person = #{personId})
2139 2160
         ) as t
2140 2161
 
2141 2162
         left join ta_person a on t.person_id = a.person_id
@@ -2143,6 +2164,9 @@
2143 2164
         left join td_wx_dict b1 on b.scene_id = b1.scene_id
2144 2165
         LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
2145 2166
         left join ta_user d on c.realty_consultant = d.user_id
2167
+        left join ta_person e on t.share_person = e.person_id
2168
+        left join ta_user f on t.share_person = f.user_id
2169
+        group by t.create_date
2146 2170
     </select>
2147 2171
 
2148 2172
     <select id="selectActivityVisitPersonNumExportByPersonId"
@@ -2152,8 +2176,8 @@
2152 2176
         if(a.gender = '1', '男', if(a.gender = '2', '女','未知') ) as gender,
2153 2177
         a.province,
2154 2178
         b1.scene_alias as personFrom,
2155
-        d.user_name as realtyConsultant,
2156
-        d.phone as realtyConsultantPhone,
2179
+        GROUP_CONCAT(d.user_name) as realtyConsultant,
2180
+        GROUP_CONCAT(d.phone) as realtyConsultantPhone,
2157 2181
         t.create_date as visitDate,
2158 2182
         ifnull(e.nickName, f.user_name) as sharePersonName,
2159 2183
         t.visitNum
@@ -2176,6 +2200,7 @@
2176 2200
         left join ta_user d on c.realty_consultant = d.user_id
2177 2201
         left join ta_person e on e.person_id = c.recommend_person
2178 2202
         left join ta_user f on f.user_id = c.recommend_person
2203
+        group by t.person_id
2179 2204
     </select>
2180 2205
 
2181 2206
     <select id="selectActivityVisitNumExportByPersonId"
@@ -2187,12 +2212,14 @@
2187 2212
         b1.scene_alias as personFrom,
2188 2213
         d.user_name as realtyConsultant,
2189 2214
         d.phone as realtyConsultantPhone,
2190
-        t.create_date as visitDate
2215
+        t.create_date as visitDate,
2216
+        ifnull(e.nickname, f.user_name) as sharePersonName,
2217
+        ifnull(e.phone, f.phone) as sharePersonPhone
2191 2218
         From (
2192 2219
         SELECT t.person_id, t.create_date
2193 2220
         FROM ta_share_person_from t
2194 2221
         LEFT JOIN (
2195
-        SELECT a.person_id, b.user_id
2222
+        SELECT a.person_id, b.user_id, t.share_person
2196 2223
         FROM ta_person a
2197 2224
         LEFT JOIN ta_user b
2198 2225
         ON a.user_id = b.user_id
@@ -2200,7 +2227,9 @@
2200 2227
         WHERE t.create_date >= DATE_FORMAT(#{startDate}, '%Y-%m-%d %H:%I:%S' ) and t.create_date &lt;=
2201 2228
         DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%I:%S' ) and t.target_type in
2202 2229
         ('dynamic_share','h5_share','help_share','live_share', 'group_share')
2203
-        and t.share_person = #{personId}
2230
+        and
2231
+        (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})
2232
+        or t.share_person = #{personId})
2204 2233
         ) as t
2205 2234
 
2206 2235
         left join ta_person a on t.person_id = a.person_id
@@ -2208,5 +2237,8 @@
2208 2237
         left join td_wx_dict b1 on b.scene_id = b1.scene_id
2209 2238
         LEFT JOIN ta_recommend_customer c on c.person_id = t.person_id
2210 2239
         left join ta_user d on c.realty_consultant = d.user_id
2240
+        left join ta_person e on t.share_person = e.person_id
2241
+        left join ta_user f on t.share_person = f.user_id
2242
+        group by t.create_date
2211 2243
     </select>
2212 2244
 </mapper>