HouseResourceMapMapper.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package com.nokia.financeapi.dao.house;
  2. import com.nokia.financeapi.pojo.dto.GetBuildingAreaStatDto;
  3. import com.nokia.financeapi.pojo.dto.GetLandBuildingStatDto;
  4. import com.nokia.financeapi.pojo.vo.GetBuildingAreaStatVo;
  5. import com.nokia.financeapi.pojo.vo.GetLandBuildingStatVo;
  6. import org.apache.ibatis.annotations.Mapper;
  7. import org.apache.ibatis.annotations.Param;
  8. import org.apache.ibatis.annotations.Select;
  9. import java.util.List;
  10. @Mapper
  11. public interface HouseResourceMapMapper {
  12. /**
  13. * 获取全省或地市的建筑面积统计
  14. */
  15. @Select("""
  16. <script>
  17. with
  18. t1 as (
  19. select
  20. sum(case when building_use = '综合用房' then building_area else 0 end) as area_synthesis,
  21. sum(case when building_use = '设备用房' then building_area else 0 end) as area_equipment,
  22. sum(case when building_use = '营销用房' then building_area else 0 end) as area_marketing,
  23. sum(case when building_use = '附属用房' then building_area else 0 end) as area_affiliate,
  24. sum(case when building_use = '行政用房' then building_area else 0 end) as area_administration,
  25. sum(case when building_use not in ('综合用房', '设备用房', '营销用房', '附属用房', '行政用房') then building_area else 0 end) as area_other,
  26. sum(building_area_self_use) as area_self_use,
  27. sum(building_area_rent) as area_rent,
  28. sum(building_area) - sum(building_area_self_use) - sum(building_area_rent) as area_unused,
  29. sum(building_area) as area_total
  30. from
  31. house.building_month
  32. where
  33. year_month = (
  34. select
  35. max(year_month)
  36. from
  37. house.building_month)
  38. <if test="dto.city != null and dto.city != ''">
  39. and city = #{dto.city}
  40. </if>
  41. )
  42. select
  43. round(area_self_use, 2) as area_self_use,
  44. round(area_rent, 2) as area_rent,
  45. round(area_unused, 2) as area_unused,
  46. round(area_synthesis / area_total * 100, 2) as percent_synthesis,
  47. round(area_equipment / area_total * 100, 2) as percent_equipment,
  48. round(area_marketing / area_total * 100, 2) as percent_marketing,
  49. round(area_affiliate / area_total * 100, 2) as percent_affiliate,
  50. round(area_administration / area_total * 100, 2) as percent_administration,
  51. round(area_other / area_total * 100, 2) as percent_other,
  52. round(area_self_use / area_total * 100, 2) as percent_self_use,
  53. round(area_rent / area_total * 100, 2) as percent_rent,
  54. round(area_unused / area_total * 100, 2) as percent_unused
  55. from t1
  56. </script>
  57. """)
  58. GetBuildingAreaStatVo getBuildingAreaStat(@Param("dto") GetBuildingAreaStatDto dto);
  59. /**
  60. * 统计各个地市的建筑和土地数量
  61. */
  62. @Select("""
  63. with
  64. t1 as (
  65. select
  66. city as area_name,
  67. count(1) as building_count
  68. from
  69. house.building_month
  70. where
  71. year_month = (
  72. select
  73. max(year_month)
  74. from
  75. house.building_month)
  76. group by
  77. city
  78. ),
  79. t2 as (
  80. select
  81. city as area_name,
  82. count(1) as land_count
  83. from
  84. house.land_month
  85. where
  86. year_month = (
  87. select
  88. max(year_month)
  89. from
  90. house.land_month)
  91. group by
  92. city
  93. )
  94. select
  95. t1.area_name,
  96. t1.building_count,
  97. t2.land_count
  98. from
  99. t1
  100. join t2 on
  101. t1.area_name = t2.area_name
  102. order by
  103. t1.area_name
  104. """)
  105. List<GetLandBuildingStatVo> getCityLandBuildingStat();
  106. /**
  107. * 统计某地市各个区县的建筑和土地数量
  108. */
  109. @Select("""
  110. <script>
  111. with
  112. t1 as (
  113. select
  114. district as area_name,
  115. count(1) as building_count
  116. from
  117. house.building_month
  118. where
  119. city = #{dto.city}
  120. and district is not null
  121. and district != ''
  122. and year_month = (
  123. select
  124. max(year_month)
  125. from
  126. house.building_month)
  127. group by
  128. district
  129. ),
  130. t2 as (
  131. select
  132. district as area_name,
  133. count(1) as land_count
  134. from
  135. house.land_month
  136. where
  137. city = #{dto.city}
  138. and district is not null
  139. and district != ''
  140. and year_month = (
  141. select
  142. max(year_month)
  143. from
  144. house.land_month)
  145. group by
  146. district
  147. )
  148. select
  149. t1.area_name,
  150. t1.building_count,
  151. t2.land_count
  152. from
  153. t1
  154. join t2 on
  155. t1.area_name = t2.area_name
  156. order by t1.area_name
  157. </script>
  158. """)
  159. List<GetLandBuildingStatVo> getDistrictLandBuildingStat(@Param("dto") GetLandBuildingStatDto dto);
  160. }