ASimplifiedHouseInfoMapper.xml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zksy.property.mapper.ASimplifiedHouseInfoMapper">
  6. <resultMap id="BaseResultMap" type="com.zksy.property.domain.ASimplifiedHouseInfo">
  7. <id property="id" column="id" jdbcType="VARCHAR"/>
  8. <result property="assetType" column="asset_type" jdbcType="VARCHAR"/>
  9. <result property="building" column="building" jdbcType="VARCHAR"/>
  10. <result property="floor" column="floor" jdbcType="VARCHAR"/>
  11. <result property="houseName" column="house_name" jdbcType="VARCHAR"/>
  12. <result property="address" column="address" jdbcType="VARCHAR"/>
  13. <result property="status" column="status" jdbcType="VARCHAR"/>
  14. <result property="rentRange" column="rent_range" jdbcType="DECIMAL"/>
  15. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  16. <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
  17. </resultMap>
  18. <sql id="Base_Column_List">
  19. id,asset_type,building,
  20. floor,house_name,address,
  21. status,rent_range,create_time,
  22. update_time
  23. </sql>
  24. <select id="getListPage" resultType="com.zksy.property.domain.vo.ASimplifiedHouseInfoVo">
  25. SELECT a.*, b.area
  26. FROM a_simplified_house_info a
  27. LEFT JOIN a_house_info_detail b ON a.id = b.simplified_house_id
  28. <where>
  29. <if test="entity.assetType != null and entity.assetType != ''">
  30. AND a.asset_type = #{entity.assetType}
  31. </if>
  32. <if test="entity.building != null and entity.building != ''">
  33. AND a.building LIKE CONCAT(#{entity.building}, '%')
  34. </if>
  35. <if test="entity.floor != null and entity.floor != ''">
  36. AND a.floor LIKE CONCAT(#{entity.floor}, '%')
  37. </if>
  38. <if test="entity.houseName != null and entity.houseName != ''">
  39. AND a.house_name LIKE CONCAT(#{entity.houseName}, '%')
  40. </if>
  41. <if test="entity.rentRangeMin != null">
  42. AND a.rent_range >= COALESCE(#{entity.rentRangeMin}, a.rent_range)
  43. </if>
  44. <if test="entity.rentRangeMax != null">
  45. AND a.rent_range &lt;= COALESCE(#{entity.rentRangeMax}, a.rent_range)
  46. </if>
  47. <if test="entity.areaMin != null">
  48. AND b.area >= COALESCE(#{entity.areaMin}, b.area)
  49. </if>
  50. <if test="entity.areaMax != null">
  51. AND b.area &lt;= COALESCE(#{entity.areaMax}, b.area)
  52. </if>
  53. </where>
  54. <if test="sortClause != null and sortClause != ''">
  55. ORDER BY ${sortClause}
  56. </if>
  57. <!-- 默认排序 -->
  58. <if test="sortClause == null or sortClause == ''">
  59. ORDER BY a.create_time DESC
  60. </if>
  61. <if test="offset != null and limit != null">
  62. LIMIT #{offset}, #{limit}
  63. </if>
  64. </select>
  65. <select id="getListPageTotal" resultType="java.lang.Long">
  66. SELECT count(*)
  67. FROM a_simplified_house_info a
  68. LEFT JOIN a_house_info_detail b ON a.id = b.simplified_house_id
  69. <where>
  70. <if test="entity.assetType != null and entity.assetType != ''">
  71. AND a.asset_type = #{entity.assetType}
  72. </if>
  73. <if test="entity.building != null and entity.building != ''">
  74. AND a.building = #{entity.building}
  75. </if>
  76. <if test="entity.floor != null and entity.floor != ''">
  77. AND a.floor LIKE CONCAT(#{entity.floor}, '%')
  78. </if>
  79. <if test="entity.rentRangeMin != null">
  80. AND a.rent_range >= COALESCE(#{entity.rentRangeMin}, a.rent_range)
  81. </if>
  82. <if test="entity.rentRangeMax != null">
  83. AND a.rent_range &lt;= COALESCE(#{entity.rentRangeMax}, a.rent_range)
  84. </if>
  85. <if test="entity.areaMin != null">
  86. AND b.area >= COALESCE(#{entity.areaMin}, b.area)
  87. </if>
  88. <if test="entity.areaMax != null">
  89. AND b.area &lt;= COALESCE(#{entity.areaMax}, b.area)
  90. </if>
  91. </where>
  92. </select>
  93. <select id="getArrears" resultType="java.util.Map">
  94. SELECT
  95. h.id AS id,
  96. h.house_name AS houseName,
  97. h.address AS address,
  98. c.contract_number AS contractNumber,
  99. c.contract_expiration_date AS contractExpirationDate,
  100. r.end_date AS endDate,
  101. NOW() AS nowAndDate
  102. FROM
  103. a_simplified_house_info h
  104. JOIN
  105. a_contract_info c ON h.id = c.simplified_house_id
  106. JOIN (
  107. -- 子查询:对每个合同,取最新一条“开始时间、结束时间非空”的收据
  108. SELECT
  109. contract_id,
  110. end_date,
  111. -- 按生成时间倒序,取第一条
  112. ROW_NUMBER() OVER (PARTITION BY contract_id ORDER BY generation_date DESC) AS rn
  113. FROM
  114. a_receipt_info
  115. WHERE
  116. start_date IS NOT NULL
  117. AND end_date IS NOT NULL
  118. ) r ON c.id = r.contract_id AND r.rn = 1
  119. WHERE
  120. h.status = '已租'
  121. AND c.contract_status = '有效'
  122. AND r.end_date &lt; c.contract_expiration_date AND r.end_date &lt; NOW()
  123. ORDER BY
  124. h.id;
  125. </select>
  126. </mapper>