BillInvoiceMapper.xml 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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.property.dao.BillInvoiceMapper">
  4. <sql id="Base_Column_List" >
  5. id, org_id, bill_id, building_owner_info_id, ta_user_id, bill_invoice_explain,
  6. pay_price, bill_statement_id, bill_status, pay_name, pay_date, create_user, create_date,
  7. update_user, update_date, pay_type
  8. </sql>
  9. <select id="selectBillInvoice" resultType="com.huiju.estateagents.property.model.BillInvoice">
  10. SELECT
  11. tpi.*,
  12. tboi.owner_name as ownerName,
  13. tpro.phase_name as phase,
  14. tpro.building_name as building,
  15. tpro.unit_name as unit,
  16. tpro.name as roomNo,
  17. tpbo.order_bumber as billStatement,
  18. (SELECT user_name from ta_user tu WHERE tu.user_id = tpi.create_user) as createUserName,
  19. (SELECT user_name from ta_user tu WHERE tu.user_id = tpi.update_user) as updateUserName
  20. FROM
  21. tp_bill_invoice tpi
  22. LEFT JOIN tp_room_no tpro ON tpi.room_no_id = tpro.id
  23. LEFT JOIN tp_bill_order tpbo ON tpi.id = tpbo.tp_bill_invoice_id
  24. LEFT JOIN tp_building_owner_info tboi ON tpi.building_owner_info_id = tboi.id
  25. <where>
  26. <trim prefixOverrides="and | or">
  27. <if test="map.phase != null and map.phase != ''">
  28. AND tpro.phase_id = #{map.phase}
  29. </if>
  30. <if test="map.building != null and map.building != ''">
  31. AND tpro.building_id = #{map.building}
  32. </if>
  33. <if test="map.unit != null and map.unit != ''">
  34. AND tpro.unit_id = #{map.unit}
  35. </if>
  36. <if test="map.roomNo != null and map.roomNo != ''">
  37. AND tpro.room_no_id = #{map.roomNo}
  38. </if>
  39. <if test="map.ownerName != null and map.ownerName != ''">
  40. AND tboi.owner_name like CONCAT('%',#{map.ownerName},'%')
  41. </if>
  42. <if test="map.billStatus != null">
  43. AND tpi.bill_status = #{map.billStatus}
  44. </if>
  45. <if test="map.payName != null and map.payName != ''">
  46. AND tpi.pay_name like CONCAT('%',#{map.payName}, '%')
  47. </if>
  48. <if test="map.billId != null">
  49. AND tpi.bill_id = #{map.billId}
  50. </if>
  51. <if test="map.orgId != null">
  52. AND tpi.org_id = #{map.orgId}
  53. </if>
  54. AND tpi.status = 1
  55. </trim>
  56. </where>
  57. order by tpi.id DESC
  58. </select>
  59. <select id="selectBillInvoiceTemp" resultType="com.huiju.estateagents.property.model.BillInvoice">
  60. SELECT
  61. tpi.*,
  62. tboi.owner_name as ownerName,
  63. tprn.phase_name as phase,
  64. tprn.building_name as building,
  65. tprn.unit_name as unit,
  66. tprn.name as roomNo
  67. FROM
  68. tp_bill_invoice tpi
  69. LEFT JOIN tp_room_no tprn ON tpi.room_no_id = tprn.id
  70. LEFT JOIN tp_building_owner_info tboi ON tpi.bill_statement_id = tboi.id
  71. <where>
  72. <trim prefixOverrides="and | or">
  73. <if test="map.billId != null">
  74. AND tpi.bill_id = #{map.billId}
  75. </if>
  76. <if test="map.orgId != null">
  77. AND tpi.org_id = #{map.orgId}
  78. </if>
  79. AND tpi.status = 0
  80. </trim>
  81. </where>
  82. order by tpi.create_date DESC
  83. </select>
  84. <select id="selectBillInvoiceEffective" resultType="com.huiju.estateagents.property.model.BillInvoice">
  85. SELECT
  86. tpi.*,
  87. tboi.owner_name as ownerName,
  88. tpro.phase_name as phase,
  89. tpro.building_name as building,
  90. tpro.unit_name as unit,
  91. tpro.name as roomNo,
  92. tpbo.order_bumber as billStatement,
  93. (SELECT user_name from ta_user tu WHERE tu.user_id = tpi.create_user) as createUserName,
  94. (SELECT user_name from ta_user tu WHERE tu.user_id = tpi.update_user) as updateUserName
  95. FROM
  96. tp_bill_invoice tpi
  97. LEFT JOIN tp_room_no tpro ON tpi.room_no_id = tpro.id
  98. LEFT JOIN tp_bill_order tpbo ON tpi.id = tpbo.tp_bill_invoice_id
  99. LEFT JOIN tp_building_owner_info tboi ON tpi.building_owner_info_id = tboi.id
  100. <where>
  101. <trim prefixOverrides="and | or">
  102. <if test="map.billId != null">
  103. AND tpi.bill_id = #{map.billId}
  104. </if>
  105. <if test="map.orgId != null">
  106. AND tpi.org_id = #{map.orgId}
  107. </if>
  108. AND tpi.status = 1
  109. </trim>
  110. </where>
  111. order by tpi.create_date DESC
  112. </select>
  113. <select id="getPriceCount" resultType="map">
  114. SELECT
  115. sum( pay_price ) AS totalPrice,
  116. org_id AS orgId
  117. FROM
  118. tp_bill_invoice
  119. WHERE
  120. `status` = 1
  121. AND bill_status = 1
  122. GROUP BY
  123. org_id
  124. </select>
  125. <select id="getBillsList" resultType="map">
  126. SELECT
  127. i.id,
  128. i.bill_invoice_explain as billInvoiceExplain,
  129. b.is_ticket as isTicket,
  130. i.pay_price AS payPrice,
  131. i.ta_user_id AS taUserId,
  132. i.bill_status AS billStatus,
  133. b.bill_name AS billName,
  134. b.bill_explain AS billExplain,
  135. b.end_date AS endDate,
  136. b.create_date AS createDate,
  137. i.out_trade_no AS outTradeNo
  138. FROM
  139. tp_bill_invoice i
  140. LEFT JOIN tp_bill b ON b.id = i.bill_id
  141. AND b.org_id = #{orgId,jdbcType=INTEGER}
  142. WHERE
  143. i.org_id = #{orgId,jdbcType=INTEGER}
  144. <if test="payType == 0">
  145. AND i.bill_status = 0
  146. </if>
  147. <if test="payType == 1">
  148. AND (i.bill_status = 1 or i.bill_status = 2)
  149. </if>
  150. and i.status=1
  151. AND i.room_no_id in (SELECT room_no_id
  152. from ta_user_verify WHERE person_id = #{personId}
  153. <!-- and role_id = 1-->
  154. <if test="taUserVerifyId != null">
  155. AND id = #{taUserVerifyId}
  156. </if>
  157. )
  158. </select>
  159. <select id="getBillInvoiceDetail" resultType="map">
  160. SELECT
  161. i.id,
  162. i.bill_invoice_explain AS billInvoiceExplain,
  163. b.is_ticket as isTicket,
  164. i.pay_price AS payPrice,
  165. i.pay_date as payDate,
  166. i.ta_user_id AS taUserId,
  167. i.bill_status AS billStatus,
  168. b.bill_name AS billName,
  169. b.bill_explain AS billExplain,
  170. b.end_date AS endDate,
  171. s.id AS billStatementId,
  172. s.pay_name AS payName,
  173. s.pay_remark AS payRemark,
  174. s.pay_type AS payType,
  175. s.create_time AS createTime,
  176. i.out_trade_no AS outTradeNo
  177. FROM
  178. tp_bill_invoice i
  179. LEFT JOIN tp_bill b ON b.id = i.bill_id
  180. AND b.org_id = #{orgId,jdbcType=INTEGER}
  181. LEFT JOIN tp_bill_statement s ON i.bill_statement_id = s.id
  182. AND s.org_id = #{orgId,jdbcType=INTEGER}
  183. WHERE
  184. i.id = #{billInvoiceId,jdbcType=INTEGER}
  185. AND i.org_id = #{orgId,jdbcType=INTEGER}
  186. </select>
  187. <select id="selectByIdAndroomNoId" resultType="com.huiju.estateagents.property.model.BillInvoice" >
  188. SELECT
  189. t.id,
  190. t.org_id AS orgId,
  191. t.bill_id AS billId,
  192. t.building_owner_info_id AS buildingOwnerInfoId,
  193. t.ta_user_id AS taUserId,
  194. t.bill_invoice_explain AS billInvoiceExplain,
  195. t.pay_price AS payPrice,
  196. t.bill_statement_id AS billStatementId,
  197. t.bill_status AS billStatus,
  198. t.pay_name AS payName,
  199. t.out_trade_no AS outTradeNo,
  200. b.bill_name as billName
  201. FROM
  202. tp_bill_invoice t
  203. LEFT JOIN tp_bill b ON t.bill_id = b.id and b.org_id = #{orgId,jdbcType=INTEGER}
  204. where t.id = #{id,jdbcType=INTEGER}
  205. and t.org_id = #{orgId,jdbcType=INTEGER}
  206. and t.status = 1
  207. and t.room_no_id = #{roomNoId,jdbcType=INTEGER}
  208. </select>
  209. <select id="selectByOutTradeNo" resultType="com.huiju.estateagents.property.model.BillInvoice" >
  210. SELECT
  211. t.id,
  212. t.org_id AS orgId,
  213. t.bill_id AS billId,
  214. t.building_owner_info_id AS buildingOwnerInfoId,
  215. t.ta_user_id AS taUserId,
  216. t.bill_invoice_explain AS billInvoiceExplain,
  217. t.pay_price AS payPrice,
  218. t.bill_statement_id AS billStatementId,
  219. t.bill_status AS billStatus,
  220. t.pay_name AS payName,
  221. t.out_trade_no AS outTradeNo,
  222. b.bill_name as billName
  223. FROM
  224. tp_bill_invoice t
  225. LEFT JOIN tp_bill b ON t.bill_id = b.id
  226. where t.out_trade_no = #{outTradeNo,jdbcType=VARCHAR}
  227. and t.status = 1
  228. </select>
  229. <select id="selectByBuildingOwnerInfoId" parameterType="integer" resultType="com.huiju.estateagents.property.model.BillInvoice" >
  230. select
  231. <include refid="Base_Column_List"/>
  232. from tp_bill_invoice
  233. where bill_statement_id = #{buildingOwnerInfoId,jdbcType=INTEGER}
  234. </select>
  235. <update id="updateBeach" parameterType="map" >
  236. update tp_bill_invoice
  237. set ta_user_id = #{map.taUserId}
  238. where id in
  239. <foreach collection="map.list" item="item" index="index" separator="," open="(" close=")">
  240. #{item.id}
  241. </foreach>
  242. </update>
  243. </mapper>