baseClosingAccountInfoMapper.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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.bz.smart_city.dao.pay.BaseClosingAccountInfoMapper">
  4. <sql id="baseClosingaccountinfoColumns">
  5. a.id AS "id",
  6. a.name AS "name",
  7. a.closingtype AS "closingtype",
  8. a.endtime AS "endtime",
  9. a.month AS "month",
  10. a.starttime AS "starttime",
  11. a.state AS "state",
  12. a.year AS "year",
  13. a.create_by AS "createBy",
  14. a.create_date AS "createDate",
  15. a.update_by AS "updateBy",
  16. a.update_date AS "updateDate",
  17. a.remarks AS "remarks",
  18. a.del_flag AS "delFlag",
  19. a.site_id AS "siteId",
  20. a.customer_id AS "customerId",
  21. case when a.closingtype = 1 then "月结" else "年结" end closingTypeName,
  22. case when a.state = 0 then "未结账" else "已结账" end stateName
  23. </sql>
  24. <sql id="baseClosingaccountinfoJoins">
  25. </sql>
  26. <select id="get" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
  27. SELECT
  28. <include refid="baseClosingaccountinfoColumns"/>
  29. FROM pay_base_closingaccountinfo a
  30. <include refid="baseClosingaccountinfoJoins"/>
  31. WHERE a.id = #{id}
  32. </select>
  33. <select id="getList" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
  34. SELECT
  35. <include refid="baseClosingaccountinfoColumns"/>
  36. FROM pay_base_closingaccountinfo a
  37. <include refid="baseClosingaccountinfoJoins"/>
  38. <where>
  39. <if test="state != null">
  40. and a.state=#{state}
  41. </if>
  42. <if test="siteId != null">
  43. and a.site_id=#{siteId}
  44. </if>
  45. <if test="customerId != null">
  46. and a.customer_id=#{customerId}
  47. </if>
  48. <if test="year != null">
  49. and a.year=#{year}
  50. </if>
  51. <if test="month != null">
  52. and a.month=#{month}
  53. </if>
  54. </where>
  55. ORDER BY a.create_date desc
  56. </select>
  57. <select id="getListNumber" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
  58. SELECT
  59. <include refid="baseClosingaccountinfoColumns"/>
  60. FROM pay_base_closingaccountinfo a
  61. <include refid="baseClosingaccountinfoJoins"/>
  62. <where>
  63. <if test="state != null">
  64. and a.state=#{state}
  65. </if>
  66. <if test="siteId != null">
  67. and a.site_id=#{siteId}
  68. </if>
  69. <if test="customerId != null">
  70. and a.customer_id=#{customerId}
  71. </if>
  72. <if test="year != null">
  73. and a.year=#{year}
  74. </if>
  75. <if test="month != null">
  76. and a.month=#{month}
  77. </if>
  78. </where>
  79. ORDER BY a.create_date asc
  80. </select>
  81. <insert id="insert">
  82. INSERT INTO pay_base_closingaccountinfo(
  83. name,
  84. closingtype,
  85. endtime,
  86. month,
  87. starttime,
  88. state,
  89. year,
  90. create_by,
  91. create_date,
  92. update_by,
  93. update_date,
  94. remarks,
  95. del_flag,
  96. site_id,
  97. customer_id
  98. ) VALUES (
  99. #{baseClosingAccountInfoDto.name},
  100. #{baseClosingAccountInfoDto.closingType},
  101. #{baseClosingAccountInfoDto.endTime},
  102. #{baseClosingAccountInfoDto.month},
  103. #{baseClosingAccountInfoDto.startTime},
  104. #{baseClosingAccountInfoDto.state},
  105. #{baseClosingAccountInfoDto.year},
  106. #{baseClosingAccountInfoDto.createBy},
  107. #{baseClosingAccountInfoDto.createDate},
  108. #{baseClosingAccountInfoDto.updateBy},
  109. #{baseClosingAccountInfoDto.updateDate},
  110. #{baseClosingAccountInfoDto.remarks},
  111. #{baseClosingAccountInfoDto.delFlag},
  112. #{baseClosingAccountInfoDto.siteId},
  113. #{baseClosingAccountInfoDto.customerId}
  114. )
  115. </insert>
  116. <update id="update">
  117. UPDATE pay_base_closingaccountinfo SET
  118. name = #{baseClosingAccountInfoDto.name},
  119. closingtype = #{baseClosingAccountInfoDto.closingType},
  120. endtime = #{baseClosingAccountInfoDto.endTime},
  121. month = #{baseClosingAccountInfoDto.month},
  122. starttime = #{baseClosingAccountInfoDto.startTime},
  123. state = #{baseClosingAccountInfoDto.state},
  124. year = #{baseClosingAccountInfoDto.year},
  125. update_by = #{baseClosingAccountInfoDto.updateBy},
  126. update_date = #{baseClosingAccountInfoDto.updateDate},
  127. remarks = #{baseClosingAccountInfoDto.remarks}
  128. WHERE id = #{baseClosingAccountInfoDto.id}
  129. </update>
  130. <select id ="checkClosing" resultType="Integer">
  131. <if test="type == '0'.toString()">
  132. select count(1)
  133. from pay_amount_waterusedamount amount
  134. where amount.year= #{year} and amount.month = #{month}
  135. and amount.site_id=#{siteId} and amount.customer_id =#{customerId}
  136. </if>
  137. <if test="type == '1'.toString()">
  138. select count(1) from pay_pay_received received
  139. where (received.iscanceled=0 or received.iscanceled is null) and received.receivedamount>0 and received.invoice_id is null
  140. and received.year = #{year} and received.month = #{month}
  141. and received.site_id=#{siteId} and received.customer_id =#{customerId}
  142. </if>
  143. <if test = "type == '2'.toString()">
  144. select count(1) from pay_amount_waterusedamount amount
  145. where amount.state = 1 and amount.year = #{year} and amount.month = #{month}
  146. and amount.site_id=#{siteId} and amount.customer_id =#{customerId}
  147. </if>
  148. <if test = "type == '3'.toString()">
  149. select count(1) From pay_pay_receivable rece
  150. left join (select ifnull(sum(received.receivedamount),0) as receivedamount,received.receivable_id
  151. from pay_pay_received received where (received.iscanceled=0 or received.iscanceled is null) and received.receivedamount>0 group by received.receivable_id) as tabre
  152. on tabre.receivable_id=rece.id
  153. where rece.receivablefee != (rece.debt+tabre.receivedamount)
  154. and rece.year=#{year}
  155. and rece.month=#{month}
  156. and rece.site_id=#{siteId} and rece.customer_id =#{customerId}
  157. </if>
  158. <if test = "type == '4'.toString()">
  159. select count(1) from pay_amount_waterusedamount amount
  160. left join pay_pay_receivable rece on rece.usedamount_id =amount.id
  161. inner join pay_base_customerandmeterrela rela
  162. on rela.id=amount.customerandmeterrela_id
  163. where state=0 and rece.id is null and rela.CalculateWay!=2 and amount.payamount>0
  164. and amount.year=#{year}
  165. and amount.month=#{month}
  166. and amount.site_id=#{siteId} and amount.customer_id =#{customerId}
  167. </if>
  168. </select>
  169. <select id="getLastClosingAccount" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
  170. select
  171. year AS "year"
  172. ,month AS "month"
  173. ,starttime as "startTime"
  174. ,endtime as "endTime"
  175. from pay_base_closingaccountinfo
  176. where state = 0
  177. <if test="siteId != null">
  178. and site_id=#{siteId}
  179. </if>
  180. <if test="customerId != null">
  181. and customer_id=#{customerId}
  182. </if>
  183. order by year desc,month desc LIMIT 1
  184. </select>
  185. <select id="getCurrentCloseInfo" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
  186. SELECT
  187. <include refid="baseClosingaccountinfoColumns"/>
  188. FROM pay_base_closingaccountinfo a
  189. <include refid="baseClosingaccountinfoJoins"/>
  190. <where>
  191. a.state=0
  192. <if test="siteId != null">
  193. and a.site_id=#{siteId}
  194. </if>
  195. <if test="customerId != null">
  196. and a.customer_id=#{customerId}
  197. </if>
  198. </where>
  199. limit 1
  200. </select>
  201. <select id="getClosingSC" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
  202. select
  203. site_id as "siteId",
  204. customer_id as "customerId"
  205. from pay_base_closingaccountinfo
  206. where site_id = 51 and customer_id = 120
  207. GROUP BY site_id,customer_id
  208. </select>
  209. </mapper>