TaBuildingMapper.xml 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  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.yunzhi.marketing.mapper.TaBuildingMapper">
  4. <select id="buildingList" resultType="com.yunzhi.marketing.entity.TaBuilding">
  5. SELECT * FROM ta_building
  6. <where>
  7. status > -1
  8. <if test="Name != null and Name != ''">
  9. and (ta_building.name like concat('%',#{Name,jdbcType=VARCHAR},'%') or ta_building.building_name like concat('%',#{Name,jdbcType=VARCHAR},'%'))
  10. </if>
  11. <if test="Code != null and Code != ''">
  12. and ta_building.code like concat('%',#{Code,jdbcType=VARCHAR},'%')
  13. </if>
  14. <if test="startDate != null">
  15. and TO_DAYS(ta_building.opening_date ) = TO_DAYS(#{startDate})
  16. </if>
  17. <if test="buildingStatus != null and buildingStatus != ''">
  18. and ta_building.status = #{buildingStatus}
  19. </if>
  20. <if test="marketStatus != null and marketStatus != ''">
  21. and ta_building.market_status =#{marketStatus}
  22. </if>
  23. <if test="cityId != null and cityId != ''">
  24. and ta_building.city_id =#{cityId}
  25. </if>
  26. <if test="isMain != null">
  27. and ta_building.is_main = #{isMain}
  28. </if>
  29. <if test="orgId != null">
  30. and ta_building.org_id = #{orgId}
  31. </if>
  32. <if test="institutionIds != null and institutionIds.size > 0">
  33. AND ta_building.institution_id in
  34. <foreach collection="institutionIds" item="item" open="(" close=")" separator=",">
  35. #{item}
  36. </foreach>
  37. </if>
  38. <if test="personBuildingList != null and personBuildingList.size > 0">
  39. AND ta_building.building_id in
  40. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  41. #{personBuilding.buildingId}
  42. </foreach>
  43. </if>
  44. </where>
  45. ORDER BY status ASC, create_date DESC, building_id ASC
  46. </select>
  47. <select id="buildingListSelect" resultType="com.yunzhi.marketing.entity.TaBuilding">
  48. SELECT * FROM ta_building
  49. <where>
  50. 1 =1
  51. and status != -1
  52. <if test="Name != null and Name != ''">
  53. and (ta_building.name like concat('%',#{Name,jdbcType=VARCHAR},'%') or ta_building.building_name like concat('%',#{Name,jdbcType=VARCHAR},'%'))
  54. </if>
  55. <if test="Code != null and Code != ''">
  56. and ta_building.code like concat('%',#{Code,jdbcType=VARCHAR},'%')
  57. </if>
  58. <if test="startDate != null">
  59. and TO_DAYS(ta_building.opening_date ) = TO_DAYS(#{startDate})
  60. </if>
  61. <if test="marketStatus != null and marketStatus != ''">
  62. and ta_building.market_status =#{marketStatus}
  63. </if>
  64. <if test="cityId != null and cityId != ''">
  65. and ta_building.city_id =#{cityId}
  66. </if>
  67. <if test="isMain != null and isMain != ''">
  68. and ta_building.is_main = #{isMain}
  69. </if>
  70. <if test="orgId != null and orgId != ''">
  71. and ta_building.org_id = #{orgId}
  72. </if>
  73. <if test="personBuildingList != null and personBuildingList.size > 0">
  74. AND ta_building.building_id in
  75. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  76. #{personBuilding.buildingId}
  77. </foreach>
  78. </if>
  79. </where>
  80. ORDER BY create_date DESC,status asc
  81. </select>
  82. <select id="buildingAll" resultType="com.yunzhi.marketing.entity.TaBuilding">
  83. SELECT * FROM ta_building
  84. where status > -1
  85. and org_id = #{orgId}
  86. </select>
  87. <select id="selectBuilding" resultType="com.yunzhi.marketing.entity.TaBuilding">
  88. SELECT * FROM ta_building
  89. where building_id = #{buildingId}
  90. </select>
  91. <select id="selectBuildingStatistical" resultType="map">
  92. select
  93. IFNULL(sum(pv_num), 0) as pvNum,
  94. <if test="saveOrShare == 'save'">
  95. IFNULL(sum(save_num),0) as saveNum
  96. </if>
  97. <if test="saveOrShare == 'share'">
  98. IFNULL(sum(share_num),0) as shareNum
  99. </if>
  100. from ta_building
  101. where org_id = ${orgId}
  102. </select>
  103. <select id="selectBuildingPage" resultType="com.yunzhi.marketing.entity.TaBuilding">
  104. SELECT
  105. tb.*
  106. FROM
  107. (
  108. select * from ta_building
  109. WHERE
  110. `status` = 1
  111. and org_id = #{orgId}
  112. <if test="cityId != null">
  113. AND city_id = #{cityId}
  114. </if>
  115. <if test="buildingArea != null">
  116. AND building_area in
  117. <foreach collection="buildingAreaLisr" item="buildingList" open="(" close=")" separator=" , ">
  118. #{buildingList}
  119. </foreach>
  120. </if>
  121. <if test="brandId != null">
  122. AND brand_id = #{brandId}
  123. </if>
  124. <if test="isCommerce != null and isCommerce">
  125. AND is_commerce = 1
  126. </if>
  127. <if test="isRecentOpening != null and isRecentOpening">
  128. AND is_recent_opening = 1
  129. </if>
  130. <if test="marketStatus != null and marketStatus != ''">
  131. AND market_status = #{marketStatus}
  132. </if>
  133. <if test="targets != null and targets.size > 0">
  134. AND building_id IN
  135. <foreach collection="targets" item="buildingId" open="(" close=")" separator=",">
  136. #{buildingId}
  137. </foreach>
  138. </if>
  139. <if test="name != null and name !=''">
  140. AND (`name` LIKE CONCAT('%',#{name},'%')
  141. OR `building_name` LIKE CONCAT('%',#{name},'%'))
  142. </if>
  143. ) as tb
  144. left JOIN
  145. (
  146. SELECT * FROM ta_building_project_type
  147. <trim prefix="where" prefixOverrides="and | or">
  148. <if test="priceList != null and priceList.size > 0">
  149. <foreach collection="priceList" item="priceArr" open="(" close=")" separator=" OR ">
  150. (
  151. <if test='priceArr[0] != null and priceArr[0] != ""'>
  152. <![CDATA[ start_price > ${priceArr[0]} ]]>
  153. </if>
  154. <if test='priceArr.length > 1 and priceArr[0] != null and priceArr[0] != ""'>
  155. AND
  156. </if>
  157. <if test='priceArr.length > 1 and priceArr[1] != null and priceArr[1] != ""'>
  158. <![CDATA[ start_price <= ${priceArr[1]} ]]>
  159. </if>
  160. ) or
  161. (
  162. <if test='priceArr[0] != null and priceArr[0] != ""'>
  163. <![CDATA[ end_price > ${priceArr[0]} ]]>
  164. </if>
  165. <if test='priceArr.length > 1 and priceArr[0] != null and priceArr[0] != ""'>
  166. AND
  167. </if>
  168. <if test='priceArr.length > 1 and priceArr[1] != null and priceArr[1] != ""'>
  169. <![CDATA[ end_price <= ${priceArr[1]} ]]>
  170. </if>
  171. )
  172. </foreach>
  173. <if test="priceType != null and priceType != ''">
  174. and price_type = #{priceType}
  175. </if>
  176. </if>
  177. <if test="buildingTypeList != null and buildingTypeList.length > 0">
  178. AND building_type_id in
  179. <foreach collection="buildingTypeList" item="buildingType" open="(" close=")" separator=",">
  180. #{buildingType}
  181. </foreach>
  182. </if>
  183. </trim>
  184. GROUP BY building_id
  185. )
  186. AS tbpt ON tb.building_id = tbpt.building_id
  187. <if test="(areaList != null and areaList.size > 0) or (houseTypeList != null and houseTypeList.length > 0)">
  188. INNER JOIN
  189. (
  190. SELECT * FROM ta_building_apartment
  191. <trim prefix="where" prefixOverrides="and | or">
  192. <if test="areaList != null and areaList.size > 0">
  193. <foreach collection="areaList" item="areaArr" open="(" close=")" separator=" OR ">
  194. (
  195. <if test='areaArr[0] != null and areaArr[0] != ""'>
  196. <![CDATA[ building_area >= ${areaArr[0]} ]]>
  197. </if>
  198. <if test='areaArr.length > 1 and areaArr[0] != null and areaArr[0] != ""'>
  199. AND
  200. </if>
  201. <if test='areaArr.length > 1 and areaArr[1] != null and areaArr[1] != ""'>
  202. <![CDATA[ building_area <= ${areaArr[1]} ]]>
  203. </if>
  204. )
  205. </foreach>
  206. </if>
  207. <if test="houseTypeList != null and houseTypeList.length > 0">
  208. AND house_type in
  209. <foreach collection="houseTypeList" item="houseType" open="(" close=")" separator=",">
  210. #{houseType}
  211. </foreach>
  212. </if>
  213. </trim>
  214. GROUP BY building_id
  215. ) as tba ON tb.building_id = tba.building_id
  216. </if>
  217. <trim prefix="where" prefixOverrides="and | or">
  218. <if test="priceList != null and priceList.size > 0">
  219. <foreach collection="priceList" item="priceArr" open="(" close=")" separator=" OR ">
  220. (
  221. <if test='priceArr[0] != null and priceArr[0] != ""'>
  222. <![CDATA[ tbpt.start_price > ${priceArr[0]} ]]>
  223. </if>
  224. <if test='priceArr.length > 1 and priceArr[0] != null and priceArr[0] != ""'>
  225. AND
  226. </if>
  227. <if test='priceArr.length > 1 and priceArr[1] != null and priceArr[1] != ""'>
  228. <![CDATA[ tbpt.start_price <= ${priceArr[1]} ]]>
  229. </if>
  230. ) or
  231. (
  232. <if test='priceArr[0] != null and priceArr[0] != ""'>
  233. <![CDATA[ tbpt.end_price > ${priceArr[0]} ]]>
  234. </if>
  235. <if test='priceArr.length > 1 and priceArr[0] != null and priceArr[0] != ""'>
  236. AND
  237. </if>
  238. <if test='priceArr.length > 1 and priceArr[1] != null and priceArr[1] != ""'>
  239. <![CDATA[ tbpt.end_price <= ${priceArr[1]} ]]>
  240. </if>
  241. )
  242. </foreach>
  243. <if test="priceType != null and priceType != ''">
  244. and tbpt.price_type = #{priceType}
  245. </if>
  246. </if>
  247. and tb.org_id = #{orgId}
  248. <if test="buildingTypeList != null and buildingTypeList.length > 0">
  249. AND tbpt.building_type_id in
  250. <foreach collection="buildingTypeList" item="buildingType" open="(" close=")" separator=",">
  251. #{buildingType}
  252. </foreach>
  253. </if>
  254. </trim>
  255. ORDER BY ${orderBy}
  256. </select>
  257. <select id="selectBuildingByBuildingTypeId" resultType="com.yunzhi.marketing.entity.TaBuilding">
  258. SELECT
  259. tab.*
  260. FROM
  261. ta_building_project_type tbpt
  262. LEFT JOIN td_building_type tbt ON tbpt.building_type_id = tbt.building_type_id
  263. LEFT JOIN ta_building tab ON tbpt.building_id = tab.building_id
  264. WHERE
  265. tab.status <![CDATA[ > ]]> -1
  266. and
  267. tbpt.building_type_id = #{buildingTypeId}
  268. </select>
  269. <select id="getBuildingListById" resultType="com.yunzhi.marketing.entity.TaBuilding">
  270. select * from ta_building t where t.building_id in (
  271. select t.building_id from ta_goods t where t.org_id = #{orgId} and t.city_id = #{cityId} and `status`=1 group by t.building_id
  272. )
  273. </select>
  274. <select id="countNumByHeavy" resultType="java.lang.Integer">
  275. select COUNT(1) from ta_building_dynamic t where t.heavy = #{heavy}
  276. <if test="dynamicId != null and dynamicId != ''">
  277. and t.dynamic_id != #{dynamicId}
  278. </if>
  279. </select>
  280. <select id="selectMainBuildings" resultType="com.yunzhi.marketing.entity.TaBuilding">
  281. SELECT
  282. CONCAT( c.`name`, t.building_area ) AS building_area,
  283. t.*,
  284. s.url AS list_poster,
  285. GROUP_CONCAT( m.tag_name ) AS tags
  286. FROM
  287. ta_building t
  288. LEFT JOIN ta_building_img s ON t.building_id = s.building_id
  289. AND s.img_type = 'list'
  290. LEFT JOIN ta_building_tag m ON t.building_id = m.building_id
  291. LEFT JOIN td_city c ON t.city_id = c.id
  292. WHERE
  293. t.org_id = #{orgId}
  294. <if test="cityId != null and cityId != ''">
  295. AND t.city_id = #{cityId}
  296. </if>
  297. AND t.status = 1
  298. AND t.is_main = 1
  299. GROUP BY
  300. t.building_id
  301. ORDER BY t.order_no desc
  302. </select>
  303. <select id="getGkBarData" resultType="java.util.Map">
  304. SELECT
  305. count( * ) AS gk_num,
  306. bb.building_id,
  307. bb.create_date,
  308. bb.building_name
  309. FROM
  310. (
  311. SELECT
  312. b.*,
  313. d.building_name
  314. FROM
  315. ta_recommend_customer b
  316. LEFT JOIN ta_building d ON b.building_id = d.building_id
  317. WHERE
  318. b.STATUS > 0
  319. AND b.org_id = #{orgId}
  320. AND b.verify_status = 1
  321. AND ( b.realty_consultant IS NULL OR b.realty_consultant = '' )
  322. <if test="personBuildingList != null and personBuildingList.size > 0">
  323. AND b.building_id in
  324. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  325. #{personBuilding.buildingId}
  326. </foreach>
  327. </if>
  328. <if test="startDate != null">
  329. and TO_DAYS(b.create_date) >= TO_DAYS(#{startDate})
  330. </if>
  331. <if test="endDate != null">
  332. and TO_DAYS(b.create_date) &lt;= TO_DAYS(#{endDate})
  333. </if>
  334. and b.building_id is not null
  335. GROUP BY
  336. b.person_id
  337. ) bb
  338. GROUP BY
  339. bb.building_id
  340. order by gk_num desc
  341. limit 6
  342. </select>
  343. <select id="getSkBarData" resultType="java.util.Map">
  344. SELECT
  345. count( * ) AS sk_num,
  346. a.building_id,
  347. d.building_name
  348. FROM
  349. ta_recommend_customer a
  350. LEFT JOIN ta_building d ON a.building_id = d.building_id
  351. WHERE
  352. a.STATUS > 0
  353. AND a.verify_status = 1
  354. AND a.realty_consultant IS NOT NULL
  355. AND a.realty_consultant != ''
  356. AND a.org_id = #{orgId}
  357. <if test="personBuildingList != null and personBuildingList.size > 0">
  358. AND a.building_id in
  359. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  360. #{personBuilding.buildingId}
  361. </foreach>
  362. </if>
  363. <if test="startDate != null">
  364. and TO_DAYS(a.create_date) >= TO_DAYS(#{startDate})
  365. </if>
  366. <if test="endDate != null">
  367. and TO_DAYS(a.create_date) &lt;= TO_DAYS(#{endDate})
  368. </if>
  369. GROUP BY
  370. a.building_id
  371. ORDER BY
  372. sk_num DESC
  373. LIMIT 6
  374. </select>
  375. <select id="getWgBarData" resultType="java.util.Map">
  376. SELECT
  377. count( * ) AS wg_num,
  378. a.be_uv AS building_id,
  379. a.create_date,
  380. d.building_name
  381. FROM
  382. ta_uv a
  383. LEFT JOIN ta_building d ON a.be_uv = d.building_id
  384. LEFT JOIN ta_person p ON a.person_id = p.person_id
  385. WHERE
  386. a.tagert_type = 'project'
  387. and p.org_id = #{orgId}
  388. and a.be_uv != "undefined"
  389. <if test="personBuildingList != null and personBuildingList.size > 0">
  390. AND a.be_uv in
  391. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  392. #{personBuilding.buildingId}
  393. </foreach>
  394. </if>
  395. <if test="startDate != null">
  396. and TO_DAYS(a.create_date) >= TO_DAYS(#{startDate})
  397. </if>
  398. <if test="endDate != null">
  399. and TO_DAYS(a.create_date) &lt;= TO_DAYS(#{endDate})
  400. </if>
  401. GROUP BY
  402. a.be_uv
  403. ORDER BY
  404. wg_num DESC
  405. LIMIT 6
  406. </select>
  407. <select id="getFwBarData" resultType="java.util.Map">
  408. SELECT
  409. t.pv_num,
  410. t.building_id,
  411. t.building_name
  412. FROM
  413. ta_building t
  414. WHERE
  415. t.org_id = #{orgId}
  416. <if test="personBuildingList != null and personBuildingList.size > 0">
  417. AND t.building_id in
  418. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  419. #{personBuilding.buildingId}
  420. </foreach>
  421. </if>
  422. ORDER BY
  423. pv_num DESC
  424. LIMIT 6
  425. </select>
  426. <select id="getStatsTableList" resultType="com.yunzhi.marketing.excel.StatsBuilding">
  427. SELECT
  428. t.building_id,
  429. t.building_name,
  430. IFNULL( t.pv_num, 0 ) AS pv_num,
  431. IFNULL( uu.uv_num, 0 ) AS uv_num,
  432. IFNULL( aa.sk_num, 0 ) AS sk_num,
  433. IFNULL( bbb.gk_num, 0 ) AS gk_num,
  434. IFNULL( aa.sk_num, 0 ) + IFNULL( bbb.gk_num, 0 ) AS kh_num
  435. FROM
  436. ta_building t
  437. LEFT JOIN (
  438. SELECT
  439. count( * ) AS sk_num,
  440. a.building_id
  441. FROM
  442. ta_recommend_customer a
  443. WHERE
  444. a.STATUS > 0
  445. AND a.verify_status = 1
  446. AND a.realty_consultant IS NOT NULL
  447. AND a.realty_consultant != ''
  448. AND a.org_id = #{orgId}
  449. <if test="startDate != null">
  450. and TO_DAYS(a.create_date) >= TO_DAYS(#{startDate})
  451. </if>
  452. <if test="endDate != null">
  453. and TO_DAYS(a.create_date) &lt;= TO_DAYS(#{endDate})
  454. </if>
  455. GROUP BY
  456. a.building_id
  457. ) aa ON aa.building_id = t.building_id
  458. LEFT JOIN (
  459. SELECT
  460. count( * ) AS gk_num,
  461. bb.building_id
  462. FROM
  463. (
  464. SELECT
  465. b.*
  466. FROM
  467. ta_recommend_customer b
  468. WHERE
  469. b.STATUS > 0
  470. AND b.org_id = #{orgId}
  471. AND b.verify_status = 1
  472. AND ( b.realty_consultant IS NULL OR b.realty_consultant = '' )
  473. <if test="startDate != null">
  474. and TO_DAYS(b.create_date) >= TO_DAYS(#{startDate})
  475. </if>
  476. <if test="endDate != null">
  477. and TO_DAYS(b.create_date) &lt;= TO_DAYS(#{endDate})
  478. </if>
  479. GROUP BY
  480. b.person_id
  481. ) bb
  482. GROUP BY
  483. bb.building_id
  484. ) bbb ON bbb.building_id = t.building_id
  485. LEFT JOIN (
  486. SELECT
  487. count( * ) AS uv_num,
  488. u.be_uv AS building_id
  489. FROM
  490. ta_uv u
  491. LEFT JOIN ta_person p ON u.person_id = p.person_id
  492. WHERE
  493. u.tagert_type = 'project'
  494. AND p.org_id = #{orgId}
  495. <if test="startDate != null">
  496. and TO_DAYS(u.create_date) >= TO_DAYS(#{startDate})
  497. </if>
  498. <if test="endDate != null">
  499. and TO_DAYS(u.create_date) &lt;= TO_DAYS(#{endDate})
  500. </if>
  501. GROUP BY
  502. u.be_uv
  503. ) uu ON uu.building_id = t.building_id
  504. WHERE
  505. t.org_id = #{orgId}
  506. <if test="personBuildingList != null and personBuildingList.size > 0">
  507. AND t.building_id in
  508. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  509. #{personBuilding.buildingId}
  510. </foreach>
  511. </if>
  512. <if test="buildingId != null and buildingId != '' ">
  513. AND t.building_id = #{buildingId}
  514. </if>
  515. <if test="sortField != null and sortField != ''">
  516. ORDER BY ${sortField} ${orderType}
  517. </if>
  518. </select>
  519. <select id="getExportTableList" resultType="com.yunzhi.marketing.excel.StatsBuilding">
  520. SELECT
  521. t.building_id,
  522. t.building_name,
  523. IFNULL( t.pv_num, 0 ) AS pv_num,
  524. IFNULL( uu.uv_num, 0 ) AS uv_num,
  525. IFNULL( aa.sk_num, 0 ) AS sk_num,
  526. IFNULL( bbb.gk_num, 0 ) AS gk_num,
  527. IFNULL( aa.sk_num, 0 ) + IFNULL( bbb.gk_num, 0 ) AS kh_num
  528. FROM
  529. ta_building t
  530. LEFT JOIN (
  531. SELECT
  532. count( * ) AS sk_num,
  533. a.building_id
  534. FROM
  535. ta_recommend_customer a
  536. WHERE
  537. a.STATUS > 0
  538. AND a.verify_status = 1
  539. AND a.realty_consultant IS NOT NULL
  540. AND a.realty_consultant != ''
  541. AND a.org_id = #{orgId}
  542. <if test="startDate != null">
  543. and TO_DAYS(a.create_date) >= TO_DAYS(#{startDate})
  544. </if>
  545. <if test="endDate != null">
  546. and TO_DAYS(a.create_date) &lt;= TO_DAYS(#{endDate})
  547. </if>
  548. GROUP BY
  549. a.building_id
  550. ) aa ON aa.building_id = t.building_id
  551. LEFT JOIN (
  552. SELECT
  553. count( * ) AS gk_num,
  554. bb.building_id
  555. FROM
  556. (
  557. SELECT
  558. b.*
  559. FROM
  560. ta_recommend_customer b
  561. WHERE
  562. b.STATUS > 0
  563. AND b.org_id = #{orgId}
  564. AND b.verify_status = 1
  565. AND ( b.realty_consultant IS NULL OR b.realty_consultant = '' )
  566. <if test="startDate != null">
  567. and TO_DAYS(b.create_date) >= TO_DAYS(#{startDate})
  568. </if>
  569. <if test="endDate != null">
  570. and TO_DAYS(b.create_date) &lt;= TO_DAYS(#{endDate})
  571. </if>
  572. GROUP BY
  573. b.person_id
  574. ) bb
  575. GROUP BY
  576. bb.building_id
  577. ) bbb ON bbb.building_id = t.building_id
  578. LEFT JOIN (
  579. SELECT
  580. count( * ) AS uv_num,
  581. u.be_uv AS building_id
  582. FROM
  583. ta_uv u
  584. LEFT JOIN ta_person p ON u.person_id = p.person_id
  585. WHERE
  586. u.tagert_type = 'project'
  587. AND p.org_id = #{orgId}
  588. <if test="startDate != null">
  589. and TO_DAYS(u.create_date) >= TO_DAYS(#{startDate})
  590. </if>
  591. <if test="endDate != null">
  592. and TO_DAYS(u.create_date) &lt;= TO_DAYS(#{endDate})
  593. </if>
  594. GROUP BY
  595. u.be_uv
  596. ) uu ON uu.building_id = t.building_id
  597. WHERE
  598. t.org_id = #{orgId}
  599. <if test="personBuildingList != null and personBuildingList.size > 0">
  600. AND t.building_id in
  601. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  602. #{personBuilding.buildingId}
  603. </foreach>
  604. </if>
  605. <if test="buildingId != null and buildingId != '' ">
  606. AND t.building_id = #{buildingId}
  607. </if>
  608. </select>
  609. <select id="getStatsTimeBarList" resultType="com.yunzhi.marketing.excel.StatsTimeBuilding">
  610. SELECT
  611. #{buildingName} as building_name,
  612. t.date as create_date,
  613. IFNULL( s.sk_num, 0 ) AS sk_num,
  614. IFNULL( g.gk_num, 0 ) AS gk_num,
  615. IFNULL( u.uv_num, 0 ) AS uv_num,
  616. IFNULL( s.sk_num, 0 ) + IFNULL( g.gk_num, 0 ) AS kh_num
  617. FROM
  618. (
  619. SELECT
  620. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  621. FROM
  622. sequence a
  623. WHERE
  624. a.rownum &lt;= datediff( #{endDate}, #{startDate} )
  625. ) t
  626. LEFT JOIN (
  627. SELECT
  628. count( * ) AS sk_num,
  629. a.building_id,
  630. DATE_FORMAT( a.create_date, '%Y-%m-%d' ) AS create_date
  631. FROM
  632. ta_recommend_customer a
  633. WHERE
  634. a.STATUS > 0
  635. AND a.verify_status = 1
  636. AND a.realty_consultant IS NOT NULL
  637. AND a.realty_consultant != ''
  638. AND a.org_id = #{orgId}
  639. AND a.building_id = #{buildingId}
  640. <if test="startDate != null">
  641. and TO_DAYS(a.create_date) >= TO_DAYS(#{startDate})
  642. </if>
  643. <if test="endDate != null">
  644. and TO_DAYS(a.create_date) &lt;= TO_DAYS(#{endDate})
  645. </if>
  646. GROUP BY
  647. DATE_FORMAT( a.create_date, '%Y-%m-%d' )
  648. ) s ON t.date = s.create_date
  649. LEFT JOIN (
  650. SELECT
  651. count( * ) AS gk_num,
  652. b.building_id,
  653. DATE_FORMAT( b.create_date, '%Y-%m-%d' ) AS create_date
  654. FROM
  655. ta_person b
  656. WHERE
  657. b.STATUS > 0
  658. AND b.org_id = #{orgId}
  659. AND IFNULL( b.person_type, '' ) IN ( 'estate agent', 'customer' )
  660. AND b.person_id NOT IN ( SELECT c.person_id FROM ta_recommend_customer c WHERE c.org_id = 84 AND person_id IS NOT NULL AND person_id != '' )
  661. AND b.building_id = #{buildingId}
  662. <if test="startDate != null">
  663. and TO_DAYS(b.create_date) >= TO_DAYS(#{startDate})
  664. </if>
  665. <if test="endDate != null">
  666. and TO_DAYS(b.create_date) &lt;= TO_DAYS(#{endDate})
  667. </if>
  668. GROUP BY
  669. DATE_FORMAT( b.create_date, '%Y-%m-%d' )
  670. ) g ON t.date = g.create_date
  671. LEFT JOIN (
  672. SELECT
  673. count( * ) AS uv_num,
  674. u.be_uv AS building_id,
  675. DATE_FORMAT( u.create_date, '%Y-%m-%d' ) AS create_date
  676. FROM
  677. ta_uv u
  678. LEFT JOIN ta_person p ON u.person_id = p.person_id
  679. WHERE
  680. tagert_type = 'project'
  681. AND p.org_id = #{orgId}
  682. AND u.be_uv = #{buildingId}
  683. <if test="startDate != null">
  684. and TO_DAYS(u.create_date) >= TO_DAYS(#{startDate})
  685. </if>
  686. <if test="endDate != null">
  687. and TO_DAYS(u.create_date) &lt;= TO_DAYS(#{endDate})
  688. </if>
  689. GROUP BY
  690. DATE_FORMAT( u.create_date, '%Y-%m-%d' )
  691. ) u ON t.date = u.create_date
  692. ORDER BY create_date
  693. </select>
  694. <select id="getStatsTimeTableList" resultType="com.yunzhi.marketing.excel.StatsTimeBuilding">
  695. SELECT
  696. t.date as create_date,
  697. IFNULL( s.sk_num, 0 ) AS sk_num,
  698. IFNULL( g.gk_num, 0 ) AS gk_num,
  699. IFNULL( u.uv_num, 0 ) AS uv_num,
  700. IFNULL( s.sk_num, 0 ) + IFNULL( g.gk_num, 0 ) AS kh_num
  701. FROM
  702. (
  703. SELECT
  704. DATE_FORMAT( DATE_SUB( #{endDate}, INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  705. FROM
  706. sequence a
  707. WHERE
  708. a.rownum &lt;= datediff( #{endDate}, #{startDate} )
  709. ) t
  710. LEFT JOIN (
  711. SELECT
  712. count( * ) AS sk_num,
  713. a.building_id,
  714. DATE_FORMAT( a.create_date, '%Y-%m-%d' ) AS create_date
  715. FROM
  716. ta_recommend_customer a
  717. WHERE
  718. a.STATUS > 0
  719. AND a.verify_status = 1
  720. AND a.realty_consultant IS NOT NULL
  721. AND a.realty_consultant != ''
  722. AND a.org_id = #{orgId}
  723. AND a.building_id = #{buildingId}
  724. <if test="startDate != null">
  725. and TO_DAYS(a.create_date) >= TO_DAYS(#{startDate})
  726. </if>
  727. <if test="endDate != null">
  728. and TO_DAYS(a.create_date) &lt;= TO_DAYS(#{endDate})
  729. </if>
  730. GROUP BY
  731. DATE_FORMAT( a.create_date, '%Y-%m-%d' )
  732. ) s ON t.date = s.create_date
  733. LEFT JOIN (
  734. SELECT
  735. count( * ) AS gk_num,
  736. b.building_id,
  737. DATE_FORMAT( b.create_date, '%Y-%m-%d' ) AS create_date
  738. FROM
  739. ta_person b
  740. WHERE
  741. b.STATUS > 0
  742. AND b.org_id = #{orgId}
  743. AND IFNULL( b.person_type, '' ) IN ( 'estate agent', 'customer' )
  744. AND b.person_id NOT IN ( SELECT c.person_id FROM ta_recommend_customer c WHERE c.org_id = 84 AND person_id IS NOT NULL AND person_id != '' )
  745. AND b.building_id = #{buildingId}
  746. <if test="startDate != null">
  747. and TO_DAYS(b.create_date) >= TO_DAYS(#{startDate})
  748. </if>
  749. <if test="endDate != null">
  750. and TO_DAYS(b.create_date) &lt;= TO_DAYS(#{endDate})
  751. </if>
  752. GROUP BY
  753. DATE_FORMAT( b.create_date, '%Y-%m-%d' )
  754. ) g ON t.date = g.create_date
  755. LEFT JOIN (
  756. SELECT
  757. count( * ) AS uv_num,
  758. u.be_uv AS building_id,
  759. DATE_FORMAT( u.create_date, '%Y-%m-%d' ) AS create_date
  760. FROM
  761. ta_uv u
  762. LEFT JOIN ta_person p ON u.person_id = p.person_id
  763. WHERE
  764. u.tagert_type = 'project'
  765. AND p.org_id = #{orgId}
  766. AND u.be_uv = #{buildingId}
  767. <if test="startDate != null">
  768. and TO_DAYS(u.create_date) >= TO_DAYS(#{startDate})
  769. </if>
  770. <if test="endDate != null">
  771. and TO_DAYS(u.create_date) &lt;= TO_DAYS(#{endDate})
  772. </if>
  773. GROUP BY
  774. DATE_FORMAT( u.create_date, '%Y-%m-%d' )
  775. ) u ON t.date = u.create_date
  776. ORDER BY
  777. <if test="sortField != null and sortField != ''">
  778. ${sortField} ${orderType},
  779. </if>
  780. create_date desc
  781. </select>
  782. <select id="selectByUserId" resultType="com.yunzhi.marketing.entity.TaBuilding">
  783. SELECT
  784. *
  785. FROM
  786. ta_building b
  787. WHERE b.institution_id in (SELECT
  788. i.institution_id
  789. FROM
  790. xlk_institution i
  791. INNER JOIN ( SELECT x.institution_code FROM xlk_user_institution t LEFT JOIN xlk_institution x ON t.institution_id = x.institution_id WHERE t.user_id = #{userId}) g ON i.institution_code LIKE CONCAT(g.institution_code ,"%")
  792. )
  793. </select>
  794. <select id="getBuilidngsOfPerson" resultType="com.yunzhi.marketing.entity.TaBuilding">
  795. SELECT
  796. *
  797. FROM
  798. ta_building t
  799. INNER JOIN ta_person_building s ON t.building_id = s.building_id
  800. AND s.person_id = #{personId}
  801. WHERE
  802. t.org_id = #{orgId}
  803. AND t.`status` = 1
  804. ORDER BY
  805. t.create_date DESC
  806. </select>
  807. <select id="getSpecial" resultType="com.yunzhi.marketing.entity.TaBuilding">
  808. SELECT
  809. DISTINCT t.*
  810. FROM
  811. ta_building t
  812. INNER JOIN xlk_building_special_room s ON t.org_id = s.org_id
  813. AND t.building_id = s.building_id
  814. AND s.start_time &lt;= now( )
  815. AND s.end_time &gt;= now( )
  816. WHERE
  817. t.org_id = #{orgId}
  818. AND t.city_id = #{cityId}
  819. AND t.`status` = 1
  820. ORDER BY
  821. t.create_date DESC
  822. </select>
  823. </mapper>