HouseBuildingDao.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. package com.example.dao.house;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.example.entity.house.BuildingIdleStatPo;
  4. import com.example.entity.house.BuildingOfficeAreaStatPo;
  5. import com.example.entity.house.HouseAgeStatPo;
  6. import com.example.entity.house.HouseBuildingPo;
  7. import com.example.pojo.bo.BuildingIdleStatBo;
  8. import com.example.pojo.bo.BuildingOfficeAreaStatBo;
  9. import com.example.pojo.bo.HouseAgeStatBo;
  10. import com.example.pojo.bo.ListBuildingBo;
  11. import com.example.pojo.bo.ListBuildingIdleBo;
  12. import org.apache.ibatis.annotations.Mapper;
  13. import org.apache.ibatis.annotations.Param;
  14. import org.apache.ibatis.annotations.Select;
  15. import java.util.List;
  16. @Mapper
  17. public interface HouseBuildingDao {
  18. /**
  19. * 查询不动产自有房产空置
  20. */
  21. @Select("""
  22. <script>
  23. select
  24. *
  25. from house.building_idle_strategy
  26. <choose>
  27. <when test="dto.yearMonth != null">
  28. where year_month = #{dto.yearMonth}
  29. </when>
  30. <otherwise>
  31. where year_month = (select max(year_month) from house.building_idle_strategy)
  32. </otherwise>
  33. </choose>
  34. <if test="dto.areaNo != null and dto.areaNo != ''">
  35. and area_no = #{dto.areaNo}
  36. </if>
  37. <if test="dto.cityNo != null and dto.cityNo != ''">
  38. and city_no = #{dto.cityNo}
  39. </if>
  40. <if test="dto.siteName != null and dto.siteName != ''">
  41. and site_name = #{dto.siteName}
  42. </if>
  43. <if test="dto.siteNum != null and dto.siteNum != ''">
  44. and site_num = #{dto.siteNum}
  45. </if>
  46. </script>
  47. """)
  48. List<HouseBuildingPo> listBuildingIdle(Page<HouseBuildingPo> page, @Param("dto") ListBuildingIdleBo dto);
  49. /**
  50. * 查询不动产建筑
  51. */
  52. @Select("""
  53. <script>
  54. select
  55. *
  56. from house.building_month
  57. <choose>
  58. <when test="dto.yearMonth != null">
  59. where year_month = #{dto.yearMonth}
  60. </when>
  61. <otherwise>
  62. where year_month = (select max(year_month) from house.building_month)
  63. </otherwise>
  64. </choose>
  65. <if test="dto.areaNo != null and dto.areaNo != ''">
  66. and area_no = #{dto.areaNo}
  67. </if>
  68. <if test="dto.cityNo != null and dto.cityNo != ''">
  69. and city_no = #{dto.cityNo}
  70. </if>
  71. <if test="dto.siteName != null and dto.siteName != ''">
  72. and site_name = #{dto.siteName}
  73. </if>
  74. <if test="dto.siteNum != null and dto.siteNum != ''">
  75. and site_num = #{dto.siteNum}
  76. </if>
  77. </script>
  78. """)
  79. List<HouseBuildingPo> listBuilding(Page<HouseBuildingPo> page, @Param("dto") ListBuildingBo dto);
  80. /**
  81. * 不动产自有房产房龄统计
  82. */
  83. @Select("""
  84. <script>
  85. with
  86. t101 as (
  87. select
  88. area_no,
  89. city_no,
  90. count(house_age <![CDATA[ >= ]]> 0 and house_age <![CDATA[ <= ]]> 10 or null) as a1,
  91. count(house_age <![CDATA[ >= ]]> 11 and house_age <![CDATA[ <= ]]> 20 or null) as a2,
  92. count(house_age <![CDATA[ >= ]]> 21 and house_age <![CDATA[ <= ]]> 30 or null) as a3,
  93. count(house_age <![CDATA[ >= ]]> 31 and house_age <![CDATA[ <= ]]> 40 or null) as a4,
  94. count(house_age <![CDATA[ >= ]]> 41 and house_age <![CDATA[ <= ]]> 50 or null) as a5,
  95. count(house_age <![CDATA[ > ]]> 50 or null) as a6,
  96. count(house_age is null or null) as au,
  97. count(house_age) as total,
  98. sum(house_age) as house_age_sum,
  99. round(avg(house_age),
  100. 2) as house_age_avg
  101. from
  102. house.building_month
  103. <choose>
  104. <when test="dto.yearMonth != null">
  105. where year_month = #{dto.yearMonth}
  106. </when>
  107. <otherwise>
  108. where year_month = (select max(year_month) from house.building_month)
  109. </otherwise>
  110. </choose>
  111. <if test="dto.areaNo != null and dto.areaNo != ''">
  112. and area_no = #{dto.areaNo}
  113. </if>
  114. <if test="dto.cityNo != null and dto.cityNo != ''">
  115. and city_no = #{dto.cityNo}
  116. </if>
  117. group by
  118. area_no,
  119. city_no
  120. ),
  121. t102 as (
  122. select
  123. b.id as area_no,
  124. b."name" as area_name,
  125. a.id as city_no,
  126. a."name" as city_name,
  127. coalesce(c.a1, 0) as a1,
  128. coalesce(c.a2, 0) as a2,
  129. coalesce(c.a3, 0) as a3,
  130. coalesce(c.a4, 0) as a4,
  131. coalesce(c.a5, 0) as a5,
  132. coalesce(c.a6, 0) as a6,
  133. coalesce(c.au, 0) as au,
  134. coalesce(c.total, 0) as total,
  135. coalesce(c.house_age_sum, 0) as house_age_sum,
  136. c.house_age_avg as house_age_avg
  137. from
  138. common.organization a
  139. left join common.organization b on
  140. a.parent_id = b.id
  141. left join t101 c on
  142. a.id = c.city_no
  143. where
  144. a.grade = 2
  145. and a.unhide = 1
  146. <if test="dto.areaNo != null and dto.areaNo != ''">
  147. and a.parent_id = #{dto.areaNo}
  148. </if>
  149. <if test="dto.cityNo != null and dto.cityNo != ''">
  150. and a.id = #{dto.cityNo}
  151. </if>
  152. order by
  153. b.order_num,
  154. a.order_num
  155. )
  156. select
  157. *
  158. from
  159. t102
  160. </script>
  161. """)
  162. List<HouseAgeStatPo> houseAgeStat(@Param("dto") HouseAgeStatBo dto);
  163. /**
  164. * 不动产自有房产闲置统计
  165. */
  166. @Select("""
  167. <script>
  168. with
  169. t101 as (
  170. select
  171. area_no,
  172. city_no,
  173. count(building_area_idle <![CDATA[ > ]]> 0 or null) as idle_count,
  174. sum(building_area) as building_area_sum,
  175. sum(building_area_self_use) as building_area_self_use_sum,
  176. sum(building_area_rent) as building_area_rent_sum,
  177. sum(building_area_idle) as building_area_idle_sum,
  178. case
  179. when (sum(building_area_idle) + sum(building_area_rent)) = 0 then null
  180. else round(sum(building_area_idle) / (sum(building_area_idle) + sum(building_area_rent)),
  181. 4)
  182. end as idle_percent
  183. from
  184. house.building_month
  185. <choose>
  186. <when test="dto.yearMonth != null">
  187. where year_month = #{dto.yearMonth}
  188. </when>
  189. <otherwise>
  190. where year_month = (select max(year_month) from house.building_month)
  191. </otherwise>
  192. </choose>
  193. <if test="dto.areaNo != null and dto.areaNo != ''">
  194. and area_no = #{dto.areaNo}
  195. </if>
  196. <if test="dto.cityNo != null and dto.cityNo != ''">
  197. and city_no = #{dto.cityNo}
  198. </if>
  199. group by
  200. area_no,
  201. city_no
  202. ),
  203. t102 as (
  204. select
  205. b.id as area_no,
  206. b."name" as area_name,
  207. a.id as city_no,
  208. a."name" as city_name,
  209. coalesce(c.idle_count, 0) as idle_count,
  210. coalesce(c.building_area_sum, 0) as building_area_sum,
  211. coalesce(c.building_area_self_use_sum, 0) as building_area_self_use_sum,
  212. coalesce(c.building_area_rent_sum, 0) as building_area_rent_sum,
  213. coalesce(c.building_area_idle_sum, 0) as building_area_idle_sum,
  214. c.idle_percent as idle_percent
  215. from
  216. common.organization a
  217. left join common.organization b on
  218. a.parent_id = b.id
  219. left join t101 c on
  220. a.id = c.city_no
  221. where
  222. a.grade = 2
  223. and a.unhide = 1
  224. <if test="dto.areaNo != null and dto.areaNo != ''">
  225. and a.parent_id = #{dto.areaNo}
  226. </if>
  227. <if test="dto.cityNo != null and dto.cityNo != ''">
  228. and a.id = #{dto.cityNo}
  229. </if>
  230. order by
  231. b.order_num, a.order_num
  232. )
  233. select * from t102
  234. </script>
  235. """)
  236. List<BuildingIdleStatPo> buildingIdleStat(@Param("dto") BuildingIdleStatBo dto);
  237. /**
  238. * 不动产自有房产人均办公面积统计
  239. */
  240. @Select("""
  241. <script>
  242. select * from house.building_office_area_stat
  243. <choose>
  244. <when test="dto.yearMonth != null">
  245. where year_month = #{dto.yearMonth}
  246. </when>
  247. <otherwise>
  248. where year_month = (select max(year_month) from house.building_office_area_stat)
  249. </otherwise>
  250. </choose>
  251. <if test="dto.areaNo != null and dto.areaNo != ''">
  252. and area_no = #{dto.areaNo}
  253. </if>
  254. <if test="dto.cityNo != null and dto.cityNo != ''">
  255. and city_no = #{dto.cityNo}
  256. </if>
  257. order by
  258. area_order,
  259. city_order
  260. </script>
  261. """)
  262. List<BuildingOfficeAreaStatPo> buildingOfficeAreaStat(@Param("dto") BuildingOfficeAreaStatBo dto);
  263. }