TaHousingResourcesMapper.xml 13KB

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