HouseResourceMapMapper.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. package com.nokia.financeapi.dao.house;
  2. import com.nokia.financeapi.pojo.dto.GetBuildingAreaStatDto;
  3. import com.nokia.financeapi.pojo.dto.GetBuildingMapDto;
  4. import com.nokia.financeapi.pojo.dto.GetBuildingOptionsDto;
  5. import com.nokia.financeapi.pojo.dto.GetBuildingRepairStatDto;
  6. import com.nokia.financeapi.pojo.dto.GetHouseNoticeDto;
  7. import com.nokia.financeapi.pojo.dto.GetLandBuildingStatDto;
  8. import com.nokia.financeapi.pojo.vo.GetBuildingAreaStatVo;
  9. import com.nokia.financeapi.pojo.vo.GetBuildingMapVo;
  10. import com.nokia.financeapi.pojo.vo.GetBuildingOptionsVo;
  11. import com.nokia.financeapi.pojo.vo.GetBuildingRepairStatVo;
  12. import com.nokia.financeapi.pojo.vo.GetHouseNoticeVo;
  13. import com.nokia.financeapi.pojo.vo.GetLandBuildingStatVo;
  14. import org.apache.ibatis.annotations.Mapper;
  15. import org.apache.ibatis.annotations.Param;
  16. import org.apache.ibatis.annotations.Select;
  17. import java.util.List;
  18. @Mapper
  19. public interface HouseResourceMapMapper {
  20. /**
  21. * 获取最新月份全省或地市的建筑面积统计
  22. */
  23. @Select("""
  24. <script>
  25. with
  26. t1 as (
  27. select
  28. sum(case when building_use = '综合用房' then building_area else 0 end) as area_synthesis,
  29. sum(case when building_use = '设备用房' then building_area else 0 end) as area_equipment,
  30. sum(case when building_use = '营销用房' then building_area else 0 end) as area_marketing,
  31. sum(case when building_use = '附属用房' then building_area else 0 end) as area_affiliate,
  32. sum(case when building_use = '行政用房' then building_area else 0 end) as area_administration,
  33. sum(case when building_use not in ('综合用房', '设备用房', '营销用房', '附属用房', '行政用房') then building_area else 0 end) as area_other,
  34. sum(building_area_self_use) as area_self_use,
  35. sum(building_area_rent) as area_rent,
  36. sum(building_area) - sum(building_area_self_use) - sum(building_area_rent) as area_unused,
  37. sum(building_area) as area_total
  38. from
  39. house.building_month
  40. where
  41. year_month = (
  42. select
  43. max(year_month)
  44. from
  45. house.building_month)
  46. <if test="dto.city != null and dto.city != ''">
  47. and city = #{dto.city}
  48. </if>
  49. )
  50. select
  51. round(area_self_use / 10000, 2) as area_self_use,
  52. round(area_rent / 10000, 2) as area_rent,
  53. round(area_unused / 10000, 2) as area_unused,
  54. round(area_synthesis / area_total * 100, 2) as percent_synthesis,
  55. round(area_equipment / area_total * 100, 2) as percent_equipment,
  56. round(area_marketing / area_total * 100, 2) as percent_marketing,
  57. round(area_affiliate / area_total * 100, 2) as percent_affiliate,
  58. round(area_administration / area_total * 100, 2) as percent_administration,
  59. round(area_other / area_total * 100, 2) as percent_other,
  60. round(area_self_use / area_total * 100, 2) as percent_self_use,
  61. round(area_rent / area_total * 100, 2) as percent_rent,
  62. round(area_unused / area_total * 100, 2) as percent_unused
  63. from t1
  64. </script>
  65. """)
  66. GetBuildingAreaStatVo getBuildingAreaStat(@Param("dto") GetBuildingAreaStatDto dto);
  67. /**
  68. * 统计最新月份各个地市的建筑和土地数量
  69. */
  70. @Select("""
  71. with
  72. t1 as (
  73. select
  74. city as area_name,
  75. count(1) as building_count
  76. from
  77. house.building_month
  78. where
  79. year_month = (
  80. select
  81. max(year_month)
  82. from
  83. house.building_month)
  84. group by
  85. city
  86. ),
  87. t2 as (
  88. select
  89. city as area_name,
  90. count(1) as land_count
  91. from
  92. house.land_month
  93. where
  94. year_month = (
  95. select
  96. max(year_month)
  97. from
  98. house.land_month)
  99. group by
  100. city
  101. )
  102. select
  103. t1.area_name,
  104. t1.building_count,
  105. t2.land_count
  106. from
  107. t1
  108. join t2 on
  109. t1.area_name = t2.area_name
  110. order by
  111. t1.area_name
  112. """)
  113. List<GetLandBuildingStatVo> getCityLandBuildingStat();
  114. /**
  115. * 统计最新月份某地市各个区县的建筑和土地数量
  116. */
  117. @Select("""
  118. <script>
  119. with
  120. t1 as (
  121. select
  122. district as area_name,
  123. count(1) as building_count
  124. from
  125. house.building_month
  126. where
  127. city = #{dto.city}
  128. and district is not null
  129. and district != ''
  130. and year_month = (
  131. select
  132. max(year_month)
  133. from
  134. house.building_month)
  135. group by
  136. district
  137. ),
  138. t2 as (
  139. select
  140. district as area_name,
  141. count(1) as land_count
  142. from
  143. house.land_month
  144. where
  145. city = #{dto.city}
  146. and district is not null
  147. and district != ''
  148. and year_month = (
  149. select
  150. max(year_month)
  151. from
  152. house.land_month)
  153. group by
  154. district
  155. )
  156. select
  157. t1.area_name,
  158. t1.building_count,
  159. t2.land_count
  160. from
  161. t1
  162. join t2 on
  163. t1.area_name = t2.area_name
  164. order by t1.area_name
  165. </script>
  166. """)
  167. List<GetLandBuildingStatVo> getDistrictLandBuildingStat(@Param("dto") GetLandBuildingStatDto dto);
  168. /**
  169. * 获取建筑数据最新的日期
  170. */
  171. @Select("""
  172. select max(year_month) from house.building_month
  173. """)
  174. Integer getBuildingMonthMaxDate();
  175. /**
  176. * 获取区县最大面积建筑
  177. */
  178. @Select("""
  179. with
  180. t101 as (
  181. select
  182. *
  183. from
  184. house.building_month
  185. where
  186. lng_bd09 is not null
  187. and lat_bd09 is not null
  188. and year_month = #{dto.endDate}
  189. and city = #{dto.city}
  190. and district = #{dto.district}
  191. order by
  192. building_area desc
  193. limit 10
  194. ),
  195. t102 as (
  196. select
  197. building_id,
  198. sum(amount) as maintenance_cost
  199. from
  200. house.building_repair_main_month
  201. where
  202. repair_type != '财务预提冲销'
  203. and exists (select 1 from t101 where t101.building_id = house.building_repair_main_month.building_id)
  204. and year_month >= #{dto.startDate}
  205. and year_month <= #{dto.endDate}
  206. group by
  207. building_id
  208. ),
  209. t103 as (
  210. select
  211. t101.*,
  212. t102.maintenance_cost
  213. from t101 left join t102 on t101.building_id = t102.building_id
  214. )
  215. select
  216. building_id,
  217. site_num,
  218. address,
  219. area_sector,
  220. building_name,
  221. acquisition_date,
  222. building_use,
  223. building_area,
  224. building_area_idle,
  225. building_area_rent,
  226. round(maintenance_cost, 2) as maintenance_cost,
  227. building_img,
  228. lng_bd09 as lng,
  229. lat_bd09 as lat
  230. from
  231. t103
  232. order by
  233. building_area desc
  234. """)
  235. List<GetBuildingMapVo> getBuildingByDistrict(@Param("dto") GetBuildingMapDto dto);
  236. /**
  237. * 获取坐标范围内的建筑,相同坐标保留建筑面积最大的
  238. */
  239. @Select("""
  240. with
  241. t101 as (
  242. select
  243. *
  244. from
  245. house.building_month
  246. where
  247. year_month = #{dto.endDate}
  248. and lng_bd09 >= #{dto.leftLng}
  249. and lng_bd09 <= #{dto.rightLng}
  250. and lat_bd09 >= #{dto.leftLat}
  251. and lat_bd09 <= #{dto.rightLat}
  252. ),
  253. t102 as (
  254. select
  255. distinct on
  256. (lng_bd09, lat_bd09) *
  257. from
  258. t101
  259. order by
  260. lng_bd09,
  261. lat_bd09,
  262. building_area desc
  263. ),
  264. t103 as (
  265. select
  266. building_id,
  267. sum(amount) as maintenance_cost
  268. from
  269. house.building_repair_main_month
  270. where
  271. repair_type != '财务预提冲销'
  272. and exists (select 1 from t102 where t102.building_id = house.building_repair_main_month.building_id)
  273. and year_month >= #{dto.startDate}
  274. and year_month <= #{dto.endDate}
  275. group by
  276. building_id
  277. ),
  278. t104 as (
  279. select
  280. t102.*,
  281. t103.maintenance_cost
  282. from t102 left join t103 on t102.building_id = t103.building_id
  283. )
  284. select
  285. building_id,
  286. site_num,
  287. address,
  288. area_sector,
  289. building_name,
  290. acquisition_date,
  291. building_use,
  292. building_area,
  293. building_area_idle,
  294. building_area_rent,
  295. round(maintenance_cost, 2) as maintenance_cost,
  296. building_img,
  297. lng_bd09 as lng,
  298. lat_bd09 as lat
  299. from
  300. t104
  301. order by
  302. building_area desc
  303. limit 150
  304. """)
  305. List<GetBuildingMapVo> getBuildingByCoordinate(@Param("dto") GetBuildingMapDto dto);
  306. /**
  307. * 统计最新年份各个地市的维修费
  308. */
  309. @Select("""
  310. with
  311. t1 as (
  312. select
  313. city,
  314. sum(case when repair_type = '零星维修' then final_cost else 0 end) as odd_sum,
  315. sum(final_cost) as total_sum
  316. from
  317. house.building_repair_month
  318. where
  319. city is not null
  320. and city != ''
  321. and repair_type != '财务预提冲销'
  322. and year_no = (
  323. select
  324. max(year_no)
  325. from
  326. house.building_repair_month)
  327. group by
  328. city
  329. ),
  330. t2 as (
  331. select
  332. *,
  333. case
  334. when total_sum = 0 then 0
  335. else odd_sum / total_sum * 100
  336. end as odd_percent
  337. from
  338. t1
  339. ),
  340. t3 as (
  341. select
  342. *
  343. from t2 left join house.second_unit_sort on t2.city = house.second_unit_sort.second_unit
  344. order by house.second_unit_sort.sort desc
  345. )
  346. select
  347. city as area_name,
  348. round(odd_sum / 10000,
  349. 2) as odd_sum,
  350. round(total_sum / 10000,
  351. 2) as total_sum,
  352. round(odd_percent,
  353. 2) as odd_percent
  354. from
  355. t3
  356. """)
  357. List<GetBuildingRepairStatVo> getCityRepairStat();
  358. /**
  359. * 统计最新年份某个地市的各个区县的维修费
  360. */
  361. @Select("""
  362. with
  363. t1 as (
  364. select
  365. city,
  366. district,
  367. sum(case when repair_type = '零星维修' then final_cost else 0 end) as odd_sum,
  368. sum(final_cost) as total_sum
  369. from
  370. house.building_repair_month
  371. where
  372. repair_type != '财务预提冲销'
  373. and year_no = (
  374. select
  375. max(year_no)
  376. from
  377. house.building_repair_month)
  378. and city is not null
  379. and city != ''
  380. and district is not null
  381. and district != ''
  382. and city = #{dto.city}
  383. group by
  384. city,
  385. district
  386. ),
  387. t2 as (
  388. select
  389. *,
  390. case
  391. when total_sum = 0 then 0
  392. else odd_sum / total_sum * 100
  393. end as odd_percent
  394. from
  395. t1
  396. )
  397. select
  398. district as area_name,
  399. round(odd_sum / 10000,
  400. 2) as odd_sum,
  401. round(total_sum / 10000,
  402. 2) as total_sum,
  403. round(odd_percent,
  404. 2) as odd_percent
  405. from
  406. t2
  407. order by
  408. total_sum
  409. """)
  410. List<GetBuildingRepairStatVo> getDistrictRepairStat(@Param("dto") GetBuildingRepairStatDto dto);
  411. /**
  412. * 获取不动产公告
  413. */
  414. @Select("""
  415. select * from house.notices
  416. where city = #{dto.city}
  417. order by create_time desc
  418. """)
  419. List<GetHouseNoticeVo> getNotice(@Param("dto") GetHouseNoticeDto dto);
  420. /**
  421. * 获取区县内的建筑,相同坐标保留建筑面积最大的
  422. */
  423. @Select("""
  424. with
  425. t101 as (
  426. select
  427. distinct on
  428. (lng_bd09, lat_bd09) *
  429. from
  430. house.building_month
  431. where
  432. lng_bd09 is not null
  433. and lat_bd09 is not null
  434. and year_month = #{dto.endDate}
  435. and city = #{dto.city}
  436. and district = #{dto.district}
  437. order by
  438. lng_bd09,
  439. lat_bd09,
  440. building_area desc
  441. ),
  442. t102 as (
  443. select
  444. building_id,
  445. sum(amount) as maintenance_cost
  446. from
  447. house.building_repair_main_month
  448. where
  449. repair_type != '财务预提冲销'
  450. and exists (select 1 from t101 where t101.building_id = house.building_repair_main_month.building_id)
  451. and year_month >= #{dto.startDate}
  452. and year_month <= #{dto.endDate}
  453. group by
  454. building_id
  455. ),
  456. t103 as (
  457. select
  458. t101.*,
  459. t102.maintenance_cost
  460. from t101 left join t102 on t101.building_id = t102.building_id
  461. )
  462. select
  463. building_id,
  464. site_num,
  465. address,
  466. area_sector,
  467. building_name,
  468. acquisition_date,
  469. building_use,
  470. building_area,
  471. building_area_idle,
  472. building_area_rent,
  473. round(maintenance_cost, 2) as maintenance_cost,
  474. building_img,
  475. lng_bd09 as lng,
  476. lat_bd09 as lat
  477. from
  478. t103
  479. order by
  480. building_area desc
  481. """)
  482. List<GetBuildingOptionsVo> getBuildingOptions(@Param("dto") GetBuildingOptionsDto dto);
  483. /**
  484. * 获取省本部建筑选项,相同坐标保留建筑面积最大的
  485. */
  486. @Select("""
  487. with
  488. t101 as (
  489. select
  490. distinct on
  491. (lng_bd09, lat_bd09) *
  492. from
  493. house.building_month
  494. where
  495. lng_bd09 is not null
  496. and lat_bd09 is not null
  497. and year_month = #{dto.endDate}
  498. and area_name = #{dto.city}
  499. order by
  500. lng_bd09,
  501. lat_bd09,
  502. building_area desc
  503. ),
  504. t102 as (
  505. select
  506. building_id,
  507. sum(amount) as maintenance_cost
  508. from
  509. house.building_repair_main_month
  510. where
  511. repair_type != '财务预提冲销'
  512. and exists (select 1 from t101 where t101.building_id = house.building_repair_main_month.building_id)
  513. and year_month >= #{dto.startDate}
  514. and year_month <= #{dto.endDate}
  515. group by
  516. building_id
  517. ),
  518. t103 as (
  519. select
  520. t101.*,
  521. t102.maintenance_cost
  522. from t101 left join t102 on t101.building_id = t102.building_id
  523. )
  524. select
  525. building_id,
  526. site_num,
  527. address,
  528. area_sector,
  529. building_name,
  530. acquisition_date,
  531. building_use,
  532. building_area,
  533. building_area_idle,
  534. building_area_rent,
  535. round(maintenance_cost, 2) as maintenance_cost,
  536. building_img,
  537. lng_bd09 as lng,
  538. lat_bd09 as lat
  539. from
  540. t103
  541. order by
  542. building_area desc
  543. """)
  544. List<GetBuildingOptionsVo> getSbbBuildingOptions(@Param("dto") GetBuildingOptionsDto dto);
  545. /**
  546. * 获取省本部建筑,相同坐标保留建筑面积最大的
  547. */
  548. @Select("""
  549. with
  550. t101 as (
  551. select
  552. distinct on
  553. (lng_bd09, lat_bd09) *
  554. from
  555. house.building_month
  556. where
  557. lng_bd09 is not null
  558. and lat_bd09 is not null
  559. and year_month = #{dto.endDate}
  560. and area_name = #{dto.city}
  561. order by
  562. lng_bd09,
  563. lat_bd09,
  564. building_area desc
  565. ),
  566. t102 as (
  567. select
  568. building_id,
  569. sum(amount) as maintenance_cost
  570. from
  571. house.building_repair_main_month
  572. where
  573. repair_type != '财务预提冲销'
  574. and exists (select 1 from t101 where t101.building_id = house.building_repair_main_month.building_id)
  575. and year_month >= #{dto.startDate}
  576. and year_month <= #{dto.endDate}
  577. group by
  578. building_id
  579. ),
  580. t103 as (
  581. select
  582. t101.*,
  583. t102.maintenance_cost
  584. from t101 left join t102 on t101.building_id = t102.building_id
  585. )
  586. select
  587. building_id,
  588. site_num,
  589. address,
  590. area_sector,
  591. building_name,
  592. acquisition_date,
  593. building_use,
  594. building_area,
  595. building_area_idle,
  596. building_area_rent,
  597. round(maintenance_cost, 2) as maintenance_cost,
  598. building_img,
  599. lng_bd09 as lng,
  600. lat_bd09 as lat
  601. from
  602. t103
  603. order by
  604. building_area desc
  605. """)
  606. List<GetBuildingMapVo> getSbbBuildings(@Param("dto") GetBuildingMapDto dto);
  607. }