HouseResourceMapMapper.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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. address,
  218. area_sector,
  219. building_name,
  220. acquisition_date,
  221. building_use,
  222. building_area,
  223. building_area_idle,
  224. building_area_rent,
  225. round(maintenance_cost, 2) as maintenance_cost,
  226. building_img,
  227. lng_bd09 as lng,
  228. lat_bd09 as lat
  229. from
  230. t103
  231. order by
  232. building_area desc
  233. """)
  234. List<GetBuildingMapVo> getBuildingByDistrict(@Param("dto") GetBuildingMapDto dto);
  235. /**
  236. * 获取坐标范围内的建筑,相同坐标保留建筑面积最大的
  237. */
  238. @Select("""
  239. with
  240. t101 as (
  241. select
  242. *
  243. from
  244. house.building_month
  245. where
  246. year_month = #{dto.endDate}
  247. and lng_bd09 >= #{dto.leftLng}
  248. and lng_bd09 <= #{dto.rightLng}
  249. and lat_bd09 >= #{dto.leftLat}
  250. and lat_bd09 <= #{dto.rightLat}
  251. ),
  252. t102 as (
  253. select
  254. distinct on
  255. (lng_bd09, lat_bd09) *
  256. from
  257. t101
  258. order by
  259. lng_bd09,
  260. lat_bd09,
  261. building_area desc
  262. ),
  263. t103 as (
  264. select
  265. building_id,
  266. sum(amount) as maintenance_cost
  267. from
  268. house.building_repair_main_month
  269. where
  270. repair_type != '财务预提冲销'
  271. and exists (select 1 from t102 where t102.building_id = house.building_repair_main_month.building_id)
  272. and year_month >= #{dto.startDate}
  273. and year_month <= #{dto.endDate}
  274. group by
  275. building_id
  276. ),
  277. t104 as (
  278. select
  279. t102.*,
  280. t103.maintenance_cost
  281. from t102 left join t103 on t102.building_id = t103.building_id
  282. )
  283. select
  284. building_id,
  285. address,
  286. area_sector,
  287. building_name,
  288. acquisition_date,
  289. building_use,
  290. building_area,
  291. building_area_idle,
  292. building_area_rent,
  293. round(maintenance_cost, 2) as maintenance_cost,
  294. building_img,
  295. lng_bd09 as lng,
  296. lat_bd09 as lat
  297. from
  298. t104
  299. order by
  300. building_area desc
  301. limit 150
  302. """)
  303. List<GetBuildingMapVo> getBuildingByCoordinate(@Param("dto") GetBuildingMapDto dto);
  304. /**
  305. * 统计最新年份各个地市的维修费
  306. */
  307. @Select("""
  308. with
  309. t1 as (
  310. select
  311. city,
  312. sum(case when repair_type = '零星维修' then amount else 0 end) as odd_sum,
  313. sum(amount) as total_sum
  314. from
  315. house.building_repair_main_month
  316. where
  317. repair_type != '财务预提冲销'
  318. and year_num = (
  319. select
  320. max(year_num)
  321. from
  322. house.building_repair_main_month)
  323. group by
  324. city
  325. ),
  326. t2 as (
  327. select
  328. *,
  329. case
  330. when total_sum = 0 then 0
  331. else odd_sum / total_sum * 100
  332. end as odd_percent
  333. from
  334. t1
  335. ),
  336. t3 as (
  337. select
  338. *
  339. from t2 left join house.second_unit_sort on t2.city = house.second_unit_sort.second_unit
  340. order by house.second_unit_sort.sort desc
  341. )
  342. select
  343. city as area_name,
  344. round(odd_sum / 10000,
  345. 2) as odd_sum,
  346. round(total_sum / 10000,
  347. 2) as total_sum,
  348. round(odd_percent,
  349. 2) as odd_percent
  350. from
  351. t3
  352. """)
  353. List<GetBuildingRepairStatVo> getCityRepairStat();
  354. /**
  355. * 统计最新年份某个地市的各个区县的维修费
  356. */
  357. @Select("""
  358. with
  359. t1 as (
  360. select
  361. city,
  362. district,
  363. sum(case when repair_type = '零星维修' then amount else 0 end) as odd_sum,
  364. sum(amount) as total_sum
  365. from
  366. house.building_repair_main_month
  367. where
  368. repair_type != '财务预提冲销'
  369. and year_num = (
  370. select
  371. max(year_num)
  372. from
  373. house.building_repair_main_month)
  374. and district is not null
  375. and district != ''
  376. and city = #{dto.city}
  377. group by
  378. city,
  379. district
  380. ),
  381. t2 as (
  382. select
  383. *,
  384. case
  385. when total_sum = 0 then 0
  386. else odd_sum / total_sum * 100
  387. end as odd_percent
  388. from
  389. t1
  390. )
  391. select
  392. district as area_name,
  393. round(odd_sum / 10000,
  394. 2) as odd_sum,
  395. round(total_sum / 10000,
  396. 2) as total_sum,
  397. round(odd_percent,
  398. 2) as odd_percent
  399. from
  400. t2
  401. order by
  402. total_sum
  403. """)
  404. List<GetBuildingRepairStatVo> getDistrictRepairStat(@Param("dto") GetBuildingRepairStatDto dto);
  405. /**
  406. * 获取不动产公告
  407. */
  408. @Select("""
  409. select * from house.notices
  410. where city = #{dto.city}
  411. order by create_time desc
  412. """)
  413. List<GetHouseNoticeVo> getNotice(@Param("dto") GetHouseNoticeDto dto);
  414. /**
  415. * 获取区县内的建筑,相同坐标保留建筑面积最大的
  416. */
  417. @Select("""
  418. with
  419. t101 as (
  420. select
  421. distinct on
  422. (lng_bd09, lat_bd09) *
  423. from
  424. house.building_month
  425. where
  426. lng_bd09 is not null
  427. and lat_bd09 is not null
  428. and year_month = #{dto.endDate}
  429. and city = #{dto.city}
  430. and district = #{dto.district}
  431. order by
  432. lng_bd09,
  433. lat_bd09,
  434. building_area desc
  435. ),
  436. t102 as (
  437. select
  438. building_id,
  439. sum(amount) as maintenance_cost
  440. from
  441. house.building_repair_main_month
  442. where
  443. repair_type != '财务预提冲销'
  444. and exists (select 1 from t101 where t101.building_id = house.building_repair_main_month.building_id)
  445. and year_month >= #{dto.startDate}
  446. and year_month <= #{dto.endDate}
  447. group by
  448. building_id
  449. ),
  450. t103 as (
  451. select
  452. t101.*,
  453. t102.maintenance_cost
  454. from t101 left join t102 on t101.building_id = t102.building_id
  455. )
  456. select
  457. building_id,
  458. address,
  459. area_sector,
  460. building_name,
  461. acquisition_date,
  462. building_use,
  463. building_area,
  464. building_area_idle,
  465. building_area_rent,
  466. round(maintenance_cost, 2) as maintenance_cost,
  467. building_img,
  468. lng_bd09 as lng,
  469. lat_bd09 as lat
  470. from
  471. t103
  472. order by
  473. building_area desc
  474. """)
  475. List<GetBuildingOptionsVo> getBuildingOptions(@Param("dto") GetBuildingOptionsDto dto);
  476. /**
  477. * 获取省本部建筑选项,相同坐标保留建筑面积最大的
  478. */
  479. @Select("""
  480. with
  481. t101 as (
  482. select
  483. distinct on
  484. (lng_bd09, lat_bd09) *
  485. from
  486. house.building_month
  487. where
  488. lng_bd09 is not null
  489. and lat_bd09 is not null
  490. and year_month = #{dto.endDate}
  491. and area_name = #{dto.city}
  492. order by
  493. lng_bd09,
  494. lat_bd09,
  495. building_area desc
  496. ),
  497. t102 as (
  498. select
  499. building_id,
  500. sum(amount) as maintenance_cost
  501. from
  502. house.building_repair_main_month
  503. where
  504. repair_type != '财务预提冲销'
  505. and exists (select 1 from t101 where t101.building_id = house.building_repair_main_month.building_id)
  506. and year_month >= #{dto.startDate}
  507. and year_month <= #{dto.endDate}
  508. group by
  509. building_id
  510. ),
  511. t103 as (
  512. select
  513. t101.*,
  514. t102.maintenance_cost
  515. from t101 left join t102 on t101.building_id = t102.building_id
  516. )
  517. select
  518. building_id,
  519. address,
  520. area_sector,
  521. building_name,
  522. acquisition_date,
  523. building_use,
  524. building_area,
  525. building_area_idle,
  526. building_area_rent,
  527. round(maintenance_cost, 2) as maintenance_cost,
  528. building_img,
  529. lng_bd09 as lng,
  530. lat_bd09 as lat
  531. from
  532. t103
  533. order by
  534. building_area desc
  535. """)
  536. List<GetBuildingOptionsVo> getSbbBuildingOptions(@Param("dto") GetBuildingOptionsDto dto);
  537. /**
  538. * 获取省本部建筑,相同坐标保留建筑面积最大的
  539. */
  540. @Select("""
  541. with
  542. t101 as (
  543. select
  544. distinct on
  545. (lng_bd09, lat_bd09) *
  546. from
  547. house.building_month
  548. where
  549. lng_bd09 is not null
  550. and lat_bd09 is not null
  551. and year_month = #{dto.endDate}
  552. and area_name = #{dto.city}
  553. order by
  554. lng_bd09,
  555. lat_bd09,
  556. building_area desc
  557. ),
  558. t102 as (
  559. select
  560. building_id,
  561. sum(amount) as maintenance_cost
  562. from
  563. house.building_repair_main_month
  564. where
  565. repair_type != '财务预提冲销'
  566. and exists (select 1 from t101 where t101.building_id = house.building_repair_main_month.building_id)
  567. and year_month >= #{dto.startDate}
  568. and year_month <= #{dto.endDate}
  569. group by
  570. building_id
  571. ),
  572. t103 as (
  573. select
  574. t101.*,
  575. t102.maintenance_cost
  576. from t101 left join t102 on t101.building_id = t102.building_id
  577. )
  578. select
  579. building_id,
  580. address,
  581. area_sector,
  582. building_name,
  583. acquisition_date,
  584. building_use,
  585. building_area,
  586. building_area_idle,
  587. building_area_rent,
  588. round(maintenance_cost, 2) as maintenance_cost,
  589. building_img,
  590. lng_bd09 as lng,
  591. lat_bd09 as lat
  592. from
  593. t103
  594. order by
  595. building_area desc
  596. """)
  597. List<GetBuildingMapVo> getSbbBuildings(@Param("dto") GetBuildingMapDto dto);
  598. }