HouseRentInDao.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. package com.example.dao.house;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.example.pojo.bo.ListRentInCompareBo;
  4. import com.example.pojo.bo.ListRentInContractBo;
  5. import com.example.pojo.bo.ListRentInTopBo;
  6. import com.example.pojo.bo.RentInContractStatBo;
  7. import com.example.pojo.bo.RentInUseStatBo;
  8. import com.example.pojo.po.house.ListRentInComparePo;
  9. import com.example.pojo.po.house.RentInContractStatPo;
  10. import com.example.pojo.po.house.RentInMonthPo;
  11. import com.example.pojo.po.house.RentInUseStatPo;
  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 HouseRentInDao {
  18. @Select("""
  19. <script>
  20. with
  21. t101 as (
  22. select
  23. area_no,
  24. city_no,
  25. count(1) as total,
  26. sum(gross_amount_month) * 12 as gross_amount_year,
  27. round(avg(unit_price),
  28. 2) as unit_price_avg,
  29. round(sum(case when use_type = '营业' then building_area else 0 end),
  30. 2) as yy,
  31. round(sum(case when use_type = '办公' then building_area else 0 end),
  32. 2) as bg,
  33. round(sum(case when use_type = '通信设施机房' then building_area else 0 end),
  34. 2) as tx,
  35. round(sum(case when use_type = '其他租入用途' then building_area else 0 end),
  36. 2) as qt,
  37. round(sum(case when use_type in ('营业', '办公', '通信设施机房', '其他租入用途') then building_area else 0 end),
  38. 2) as zj
  39. from
  40. house.rent_in_month
  41. where
  42. contract_status = '履行中'
  43. <choose>
  44. <when test="dto.yearMonth != null">
  45. and year_month = #{dto.yearMonth}
  46. </when>
  47. <otherwise>
  48. and year_month = (select max(year_month) from house.rent_in_month)
  49. </otherwise>
  50. </choose>
  51. <if test="dto.areaNo != null and dto.areaNo != ''">
  52. and area_no = #{dto.areaNo}
  53. </if>
  54. <if test="dto.cityNo != null and dto.cityNo != ''">
  55. and city_no = #{dto.cityNo}
  56. </if>
  57. group by
  58. area_no,
  59. city_no
  60. ),
  61. t102 as (
  62. select
  63. b.id as area_no,
  64. b."name" as area_name,
  65. a.id as city_no,
  66. a."name" as city_name,
  67. coalesce(c.total,
  68. 0) as total,
  69. coalesce(c.gross_amount_year,
  70. 0) as gross_amount_year,
  71. coalesce(c.unit_price_avg,
  72. 0) as unit_price_avg,
  73. coalesce(c.yy,
  74. 0) as yy,
  75. coalesce(c.bg,
  76. 0) as bg,
  77. coalesce(c.tx,
  78. 0) as tx,
  79. coalesce(c.qt,
  80. 0) as qt,
  81. coalesce(c.zj,
  82. 0) as zj
  83. from
  84. common.organization a
  85. left join common.organization b on
  86. a.parent_id = b.id
  87. left join t101 c on
  88. a.id = c.city_no
  89. where
  90. a.grade = 2
  91. and a.unhide = 1
  92. <if test="dto.areaNo != null and dto.areaNo != ''">
  93. and a.parent_id = #{dto.areaNo}
  94. </if>
  95. <if test="dto.cityNo != null and dto.cityNo != ''">
  96. and a.id = #{dto.cityNo}
  97. </if>
  98. order by
  99. b.order_num,
  100. a.order_num
  101. )
  102. select
  103. *
  104. from
  105. t102
  106. </script>
  107. """)
  108. List<RentInContractStatPo> rentInContractStat(@Param("dto") RentInContractStatBo dto);
  109. /**
  110. * 查询租入合同
  111. */
  112. @Select("""
  113. <script>
  114. select
  115. *
  116. from house.rent_in_month
  117. where contract_status = '履行中'
  118. <choose>
  119. <when test="dto.yearMonth != null">
  120. and year_month = #{dto.yearMonth}
  121. </when>
  122. <otherwise>
  123. and year_month = (select max(year_month) from house.rent_in_month)
  124. </otherwise>
  125. </choose>
  126. <if test="dto.areaNo != null and dto.areaNo != ''">
  127. and area_no = #{dto.areaNo}
  128. </if>
  129. <if test="dto.cityNo != null and dto.cityNo != ''">
  130. and city_no = #{dto.cityNo}
  131. </if>
  132. </script>
  133. """)
  134. List<RentInMonthPo> listRentInContract(Page<RentInMonthPo> page, @Param("dto") ListRentInContractBo dto);
  135. @Select("""
  136. <script>
  137. with
  138. t101 as (
  139. select
  140. area_no,
  141. city_no,
  142. count(use_type = '营业' or null) as yy,
  143. count(use_type = '办公' or null) as bg,
  144. count(use_type = '通信设施机房' or null) as tx,
  145. count(use_type in ('营业', '办公', '通信设施机房', '其他租入用途') or null) as qt,
  146. count(1) as zj
  147. from
  148. house.rent_in_month
  149. where
  150. contract_status = '履行中'
  151. <choose>
  152. <when test="dto.yearMonth != null">
  153. and year_month = #{dto.yearMonth}
  154. </when>
  155. <otherwise>
  156. and year_month = (select max(year_month) from house.rent_in_month)
  157. </otherwise>
  158. </choose>
  159. <if test="dto.areaNo != null and dto.areaNo != ''">
  160. and area_no = #{dto.areaNo}
  161. </if>
  162. <if test="dto.cityNo != null and dto.cityNo != ''">
  163. and city_no = #{dto.cityNo}
  164. </if>
  165. group by
  166. area_no,
  167. city_no
  168. ),
  169. t102 as (
  170. select
  171. b.id as area_no,
  172. b."name" as area_name,
  173. a.id as city_no,
  174. a."name" as city_name,
  175. coalesce(c.yy,
  176. 0) as yy,
  177. coalesce(c.bg,
  178. 0) as bg,
  179. coalesce(c.tx,
  180. 0) as tx,
  181. coalesce(c.qt,
  182. 0) as qt,
  183. coalesce(c.zj,
  184. 0) as zj
  185. from
  186. common.organization a
  187. left join common.organization b on
  188. a.parent_id = b.id
  189. left join t101 c on
  190. a.id = c.city_no
  191. where
  192. a.grade = 2
  193. and a.unhide = 1
  194. <if test="dto.areaNo != null and dto.areaNo != ''">
  195. and a.parent_id = #{dto.areaNo}
  196. </if>
  197. <if test="dto.cityNo != null and dto.cityNo != ''">
  198. and a.id = #{dto.cityNo}
  199. </if>
  200. order by
  201. b.order_num,
  202. a.order_num
  203. )
  204. select
  205. *
  206. from
  207. t102
  208. </script>
  209. """)
  210. List<RentInUseStatPo> rentInUseStat(@Param("dto") RentInUseStatBo dto);
  211. /**
  212. * 查询租入合同
  213. */
  214. @Select("""
  215. <script>
  216. with
  217. t101 as (
  218. select
  219. *
  220. from
  221. house.rent_in_month
  222. where
  223. contract_status = '履行中'
  224. <choose>
  225. <when test="dto.yearMonth != null">
  226. and year_month = #{dto.yearMonth}
  227. </when>
  228. <otherwise>
  229. and year_month = (select max(year_month) from house.rent_in_month)
  230. </otherwise>
  231. </choose>
  232. order by
  233. unit_price2 desc nulls last
  234. limit 10
  235. )
  236. select * from t101
  237. <where>
  238. <if test="dto.areaNo != null and dto.areaNo != ''">
  239. and area_no = #{dto.areaNo}
  240. </if>
  241. <if test="dto.cityNo != null and dto.cityNo != ''">
  242. and city_no = #{dto.cityNo}
  243. </if>
  244. </where>
  245. </script>
  246. """)
  247. List<RentInMonthPo> listRentInTop(Page<RentInMonthPo> page, @Param("dto") ListRentInTopBo dto);
  248. /**
  249. * 查询租入单价与平均单价比较
  250. */
  251. @Select("""
  252. <script>
  253. with
  254. t101 as (
  255. select
  256. use_type,
  257. round(avg(unit_price2),
  258. 2) as unit_price_avg
  259. from
  260. house.rent_in_month
  261. where
  262. contract_status = '履行中'
  263. <choose>
  264. <when test="dto.yearMonth != null">
  265. and year_month = #{dto.yearMonth}
  266. </when>
  267. <otherwise>
  268. and year_month = (select max(year_month) from house.rent_in_month)
  269. </otherwise>
  270. </choose>
  271. group by
  272. use_type
  273. ),
  274. t102 as (
  275. select
  276. a.contract_no,
  277. a.contract_name,
  278. a.area_name,
  279. a.city_name,
  280. a.field,
  281. a.use_type,
  282. a.use_description,
  283. a.city_region,
  284. a.area_sector,
  285. a.gross_amount,
  286. a.building_area,
  287. a.rent_months,
  288. a.rent_years,
  289. a.unit_price2 as unit_price,
  290. b.unit_price_avg,
  291. case
  292. when b.unit_price_avg = 0 then null
  293. else round(a.unit_price2 / b.unit_price_avg,
  294. 2)
  295. end as unit_price_compare
  296. from
  297. house.rent_in_month a
  298. left join t101 b on
  299. a.use_type = b.use_type
  300. where
  301. a.contract_status = '履行中'
  302. <choose>
  303. <when test="dto.yearMonth != null">
  304. and a.year_month = #{dto.yearMonth}
  305. </when>
  306. <otherwise>
  307. and a.year_month = (select max(year_month) from house.rent_in_month)
  308. </otherwise>
  309. </choose>
  310. <if test="dto.areaNo != null and dto.areaNo != ''">
  311. and a.area_no = #{dto.areaNo}
  312. </if>
  313. <if test="dto.cityNo != null and dto.cityNo != ''">
  314. and a.city_no = #{dto.cityNo}
  315. </if>
  316. )
  317. select
  318. *
  319. from
  320. t102
  321. </script>
  322. """)
  323. List<ListRentInComparePo> listRentInCompare(Page<ListRentInComparePo> page, @Param("dto") ListRentInCompareBo dto);
  324. }