TaHousingResourcesMapper.xml 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.huiju.estateagents.mapper.TaHousingResourcesMapper">
  4. <select id="listHousingResources" resultType="com.huiju.estateagents.po.TaHousingResourcesPO">
  5. SELECT
  6. *
  7. FROM
  8. (
  9. SELECT
  10. t.*,
  11. (
  12. CASE
  13. WHEN ( SELECT num_char_extract ( t.term_name, 2 ) + 0 ) = 0 THEN
  14. ( SELECT num_char_extract ( t.term_name, 2 ) ) ELSE ( SELECT num_char_extract ( t.term_name, 2 ) + 0 )
  15. END
  16. ) termNamePre,
  17. (
  18. CASE
  19. WHEN ( SELECT num_char_extract ( t.block_name, 2 ) + 0 ) = 0 THEN
  20. ( SELECT num_char_extract ( t.block_name, 2 ) ) ELSE ( SELECT num_char_extract ( t.block_name, 2 ) + 0 )
  21. END
  22. ) blockNamePre,
  23. (
  24. CASE
  25. WHEN ( SELECT num_char_extract ( t.unit_name, 2 ) + 0 ) = 0 THEN
  26. ( SELECT num_char_extract ( t.unit_name, 2 ) ) ELSE ( SELECT num_char_extract ( t.unit_name, 2 ) + 0 )
  27. END
  28. ) unitNamePre,
  29. t2.inside_area,
  30. t2.building_area,
  31. t2.apartment_name
  32. FROM
  33. ta_housing_resources t
  34. LEFT JOIN ta_building_apartment t2 ON t.apartment_id = t2.apartment_id
  35. LEFT JOIN ta_sales_batch t4 ON t.sales_batch_id = t4.sales_batch_id
  36. <if test="source == 'raiseChoose'">
  37. LEFT JOIN ta_raise_house t5 ON t.house_id = t5.house_id
  38. LEFT JOIN ta_raise_record t6 ON t6.raise_record_id = t5.raise_record_id
  39. LEFT JOIN ta_raise t7 ON t.sales_batch_id = t7.sales_batch_id
  40. </if>
  41. WHERE
  42. t.sales_batch_id = #{salesBatchId}
  43. AND t.org_id = #{orgId}
  44. AND t.`status` > 0
  45. AND t4.`status` = 1
  46. <if test = "source == 'raiseChoose'">
  47. AND ( t6.`status` != 0 OR t6.`status` IS NULL )
  48. --AND (t.house_locking_status != 'locked' OR t.house_locking_status IS NULL)
  49. AND t7.raise_start_time &lt;= now() AND t7.raise_end_time &gt;= now()
  50. <if test="personId != null and personId != ''">
  51. AND (t6.person_id != #{personId} OR t6.person_id IS NULL)
  52. </if>
  53. </if>
  54. <choose>
  55. <when test=" endPrice != null and startPrice == null">
  56. AND t.price &lt;= #{endPrice}
  57. </when>
  58. <when test=" startPrice != null and endPrice == null">
  59. AND t.price &gt;= #{startPrice}
  60. </when>
  61. <when test="startPrice != null and endPrice != null ">
  62. AND ( t.price BETWEEN #{startPrice} AND #{endPrice} )
  63. </when>
  64. <otherwise>
  65. </otherwise>
  66. </choose>
  67. <if test="apartmentId != null and apartmentId != ''">
  68. AND t.apartment_id = #{apartmentId}
  69. </if>
  70. ) t5
  71. GROUP BY
  72. t5.house_id
  73. ORDER BY
  74. t5.termNamePre,
  75. t5.blockNamePre,
  76. t5.unitNamePre,
  77. ( SELECT num_char_extract ( t5.floor_name, 2 ) + 0 ) DESC,
  78. ( SELECT num_char_extract ( t5.room_name, 2 ) + 0)
  79. </select>
  80. <select id="listHousingResourcesForCms" resultType="com.huiju.estateagents.po.TaHousingResourcesPO">
  81. SELECT
  82. *
  83. FROM
  84. (
  85. SELECT
  86. t.house_id,
  87. (
  88. CASE
  89. WHEN ( SELECT num_char_extract ( t.term_name, 2 ) + 0 ) = 0 THEN
  90. ( SELECT num_char_extract ( t.term_name, 2 ) ) ELSE ( SELECT num_char_extract ( t.term_name, 2 ) + 0 )
  91. END
  92. ) termNamePre,
  93. (
  94. CASE
  95. WHEN ( SELECT num_char_extract ( t.block_name, 2 ) + 0 ) = 0 THEN
  96. ( SELECT num_char_extract ( t.block_name, 2 ) ) ELSE ( SELECT num_char_extract ( t.block_name, 2 ) + 0 )
  97. END
  98. ) blockNamePre,
  99. (
  100. CASE
  101. WHEN ( SELECT num_char_extract ( t.unit_name, 2 ) + 0 ) = 0 THEN
  102. ( SELECT num_char_extract ( t.unit_name, 2 ) ) ELSE ( SELECT num_char_extract ( t.unit_name, 2 ) + 0 )
  103. END
  104. ) unitNamePre,
  105. t.building_id,
  106. t.block_id,
  107. t.block_name,
  108. t.sales_batch_id,
  109. t.unit_id,
  110. t.unit_name,
  111. t.floor_id,
  112. t.floor_name,
  113. t.room_id,
  114. t.room_name,
  115. t.price,
  116. t.heat,
  117. t.real_heat,
  118. t.apartment_id,
  119. t.`status`,
  120. t.org_id,
  121. t2.inside_area,
  122. t2.building_area,
  123. t2.apartment_name,
  124. t3.term_id,
  125. t.term_name,
  126. t.raise_heat,
  127. t.raise_real_heat,
  128. t.house_locking_status
  129. FROM
  130. ta_housing_resources t
  131. LEFT JOIN ta_building_apartment t2 ON t.apartment_id = t2.apartment_id
  132. LEFT JOIN ta_building_block t3 ON t.block_id = t3.block_id
  133. WHERE
  134. t.sales_batch_id = #{salesBatchId}
  135. AND t.org_id = #{orgId}
  136. <choose>
  137. <when test=" endPrice != null and startPrice == null">
  138. AND t.price &lt;= #{endPrice}
  139. </when>
  140. <when test=" startPrice != null and endPrice == null">
  141. AND t.price &gt;= #{startPrice}
  142. </when>
  143. <when test="startPrice != null and endPrice != null ">
  144. AND ( t.price BETWEEN #{startPrice} AND #{endPrice} )
  145. </when>
  146. <otherwise>
  147. </otherwise>
  148. </choose>
  149. <if test="apartmentId != null and apartmentId != ''">
  150. AND t.apartment_id = #{apartmentId}
  151. </if>
  152. <choose>
  153. <when test="type == 1">
  154. AND t.`status` > 0
  155. </when>
  156. <otherwise>
  157. AND t.`status` > -1
  158. </otherwise>
  159. </choose>
  160. ) t5
  161. ORDER BY
  162. t5.termNamePre,
  163. t5.blockNamePre,
  164. t5.unitNamePre,
  165. ( SELECT num_char_extract ( t5.floor_name, 2 ) + 0 ) DESC,
  166. ( SELECT num_char_extract ( t5.room_name, 2 ) + 0)
  167. </select>
  168. <select id="listBuildApartmentBySalesBatchId" resultType="com.huiju.estateagents.entity.TaBuildingApartment">
  169. SELECT
  170. t3.apartment_id,
  171. t3.apartment_name,
  172. t3.apartment_type,
  173. t3.inside_area,
  174. t3.building_area,
  175. t2.apartment_id
  176. FROM
  177. (
  178. SELECT
  179. t.sales_batch_id,
  180. t.apartment_id
  181. FROM
  182. ta_housing_resources t
  183. WHERE
  184. t.sales_batch_id = #{salesBatchId}
  185. AND t.`status` > 0
  186. AND t.apartment_id IS NOT NULL
  187. GROUP BY
  188. t.apartment_id
  189. ) t2
  190. LEFT JOIN ta_building_apartment t3 ON t2.apartment_id = t3.apartment_id
  191. ORDER BY
  192. t3.apartment_name
  193. </select>
  194. <update id="updateForAddHeat" parameterType="java.lang.Integer">
  195. UPDATE ta_housing_resources t
  196. SET t.real_heat = IFNULL(t.real_heat, 0) + 1
  197. WHERE
  198. t.house_id = #{houseId}
  199. </update>
  200. <update id="updateForSubtractHeat" parameterType="java.lang.Integer">
  201. UPDATE ta_housing_resources t
  202. SET t.real_heat = IFNULL(t.real_heat, 0) - 1
  203. WHERE
  204. t.house_id = #{houseId}
  205. AND t.real_heat > 0
  206. </update>
  207. <update id="updateForSubtractRaiseHeat" parameterType="java.lang.Integer">
  208. UPDATE ta_housing_resources t
  209. SET t.raise_real_heat = IFNULL( t.raise_real_heat, 0 ) - 1
  210. WHERE
  211. t.house_id IN ( SELECT tr.house_id FROM ta_raise_house tr WHERE tr.raise_record_id = #{raiseRecordId})
  212. AND t.raise_real_heat > 0
  213. </update>
  214. <select id="getHousingDetailById" resultType="com.huiju.estateagents.po.TaHousingResourcesPO">
  215. SELECT
  216. t.house_id,
  217. t.building_id,
  218. t.block_id,
  219. t.block_name,
  220. t.sales_batch_id,
  221. t.unit_id,
  222. t.unit_name,
  223. t.floor_id,
  224. t.floor_name,
  225. t.room_id,
  226. t.room_name,
  227. t.price,
  228. t.heat,
  229. t.real_heat,
  230. t.apartment_id,
  231. t.`status`,
  232. t.org_id,
  233. t.term_id,
  234. t.term_name,
  235. t2.apartment_name,
  236. t2.inside_area,
  237. t2.building_area,
  238. t3.preselection_start_time,
  239. t3.preselection_end_time,
  240. t3.`status` saleBatchStatus,
  241. t3.display_house_price,
  242. t4.building_name buildingName
  243. FROM
  244. ta_housing_resources t
  245. LEFT JOIN ta_building_apartment t2 ON t.apartment_id = t2.apartment_id
  246. LEFT JOIN ta_sales_batch t3 ON t.sales_batch_id = t3.sales_batch_id
  247. LEFT JOIN ta_building t4 ON t.building_id = t4.building_id
  248. WHERE
  249. t.house_id = #{houseId}
  250. <if test="type != null and type == '1' ">
  251. AND t.`status` = 1
  252. AND t3.`status` = 1
  253. </if>
  254. </select>
  255. <select id="getHouseResourceList" resultType="com.huiju.estateagents.entity.TaHousingResources">
  256. SELECT
  257. t.* ,
  258. a.apartment_name,
  259. u.user_name as update_name
  260. FROM
  261. ta_housing_resources t
  262. LEFT JOIN ta_building_apartment a ON t.apartment_id = a.apartment_id
  263. LEFT JOIN ta_user u on t.update_user = u.user_id
  264. WHERE t.`status` > -1
  265. AND t.org_id = #{orgId}
  266. and t.building_id = #{buildingId}
  267. and t.sales_batch_id = #{salesBatchId}
  268. <if test="apartmentId != null and apartmentId != ''">
  269. AND t.apartment_id = #{apartmentId}
  270. </if>
  271. <if test="status != null">
  272. AND t.status = #{status}
  273. </if>
  274. <if test="houseId != null and houseId != ''">
  275. AND t.house_id like CONCAT('%',#{houseId}, '%')
  276. </if>
  277. <if test="termName != null and termName != ''">
  278. AND t.term_name like CONCAT('%',#{termName}, '%')
  279. </if>
  280. <if test="blockName != null and blockName != ''">
  281. AND t.block_name like CONCAT('%',#{blockName}, '%')
  282. </if>
  283. <if test="unitName != null and unitName != ''">
  284. AND t.unit_name like CONCAT('%',#{unitName}, '%')
  285. </if>
  286. <if test="floorName != null and floorName != ''">
  287. AND t.floor_name like CONCAT('%',#{floorName}, '%')
  288. </if>
  289. <if test="roomName != null and roomName != ''">
  290. AND t.room_name like CONCAT('%',#{roomName}, '%')
  291. </if>
  292. <if test="lockingStatus != null and lockingStatus != ''">
  293. AND t.house_locking_status = #{lockingStatus}
  294. </if>
  295. </select>
  296. <select id="selectHousingList" resultType="com.huiju.estateagents.entity.TaHousingResources">
  297. select * from ta_housing_resources where org_id = #{orgId} and sales_batch_id in
  298. <foreach collection="taSalesBatchList" item="taSalesBatch" open="(" close=")" separator=",">
  299. #{taSalesBatch.salesBatchId}
  300. </foreach>
  301. </select>
  302. <update id="batchUpdateRaiseHeat">
  303. UPDATE ta_housing_resources t
  304. SET t.raise_heat = #{raiseHeat},
  305. t.update_user = #{updateUser},
  306. t.update_date =now()
  307. WHERE
  308. t.org_id = #{orgId}
  309. AND t.sales_batch_id = #{salesBatchId}
  310. AND t.house_id IN
  311. <foreach collection="housingResourcesList" item="record" open="(" close=")" separator=",">
  312. #{record.houseId}
  313. </foreach>
  314. </update>
  315. <update id="batchUpdateHeat">
  316. UPDATE ta_housing_resources t
  317. SET t.heat = #{heat},
  318. t.update_user = #{updateUser},
  319. t.update_date =now()
  320. WHERE
  321. t.org_id = #{orgId}
  322. AND t.sales_batch_id = #{salesBatchId}
  323. AND t.house_id IN
  324. <foreach collection="housingResourcesList" item="record" open="(" close=")" separator=",">
  325. #{record.houseId}
  326. </foreach>
  327. </update>
  328. <select id="listHouseByRaiseRecordId" resultType="com.huiju.estateagents.po.TaHousingResourcesPO">
  329. SELECT
  330. t.*,
  331. t2.raise_house_id,
  332. t3.person_id lockingPersonId,
  333. t3.name lockingPersonName
  334. FROM
  335. ta_housing_resources t
  336. LEFT JOIN ta_raise_house t2 ON t.house_id = t2.house_id
  337. left join ta_person t3 on t.house_locking_person = t3.person_id
  338. WHERE
  339. t.org_id = #{orgId}
  340. AND t.`status` != - 1
  341. AND t2.raise_record_id = #{raiseRecordId}
  342. ORDER BY
  343. t.create_date DESC
  344. </select>
  345. <select id="getHouseByRaiseHouseId" resultType="com.huiju.estateagents.po.TaHousingResourcesPO">
  346. SELECT
  347. t.*,
  348. t3.person_id lockingPersonId,
  349. t3.name lockingPersonName
  350. FROM
  351. ta_housing_resources t
  352. LEFT JOIN ta_raise_house t2 ON t.house_id = t2.house_id
  353. left join ta_person t3 on t.house_locking_person = t3.person_id
  354. WHERE
  355. t2.raise_house_id = #{raiseHouseId}
  356. AND t2.org_id = #{orgId}
  357. AND t.`status` != -1
  358. </select>
  359. </mapper>