123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.bz.smart_city.dao.pay.BaseClosingAccountInfoMapper">
- <sql id="baseClosingaccountinfoColumns">
- a.id AS "id",
- a.name AS "name",
- a.closingtype AS "closingtype",
- a.endtime AS "endtime",
- a.month AS "month",
- a.starttime AS "starttime",
- a.state AS "state",
- a.year AS "year",
- a.create_by AS "createBy",
- a.create_date AS "createDate",
- a.update_by AS "updateBy",
- a.update_date AS "updateDate",
- a.remarks AS "remarks",
- a.del_flag AS "delFlag",
- a.site_id AS "siteId",
- a.customer_id AS "customerId",
- case when a.closingtype = 1 then "月结" else "年结" end closingTypeName,
- case when a.state = 0 then "未结账" else "已结账" end stateName
- </sql>
- <sql id="baseClosingaccountinfoJoins">
- </sql>
- <select id="get" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
- SELECT
- <include refid="baseClosingaccountinfoColumns"/>
- FROM pay_base_closingaccountinfo a
- <include refid="baseClosingaccountinfoJoins"/>
- WHERE a.id = #{id}
- </select>
- <select id="getList" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
- SELECT
- <include refid="baseClosingaccountinfoColumns"/>
- FROM pay_base_closingaccountinfo a
- <include refid="baseClosingaccountinfoJoins"/>
- <where>
- <if test="state != null">
- and a.state=#{state}
- </if>
- <if test="siteId != null">
- and a.site_id=#{siteId}
- </if>
- <if test="customerId != null">
- and a.customer_id=#{customerId}
- </if>
- <if test="year != null">
- and a.year=#{year}
- </if>
- <if test="month != null">
- and a.month=#{month}
- </if>
- </where>
- ORDER BY a.create_date desc
- </select>
- <select id="getListNumber" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
- SELECT
- <include refid="baseClosingaccountinfoColumns"/>
- FROM pay_base_closingaccountinfo a
- <include refid="baseClosingaccountinfoJoins"/>
- <where>
- <if test="state != null">
- and a.state=#{state}
- </if>
- <if test="siteId != null">
- and a.site_id=#{siteId}
- </if>
- <if test="customerId != null">
- and a.customer_id=#{customerId}
- </if>
- <if test="year != null">
- and a.year=#{year}
- </if>
- <if test="month != null">
- and a.month=#{month}
- </if>
- </where>
- ORDER BY a.create_date asc
- </select>
- <insert id="insert">
- INSERT INTO pay_base_closingaccountinfo(
- name,
- closingtype,
- endtime,
- month,
- starttime,
- state,
- year,
- create_by,
- create_date,
- update_by,
- update_date,
- remarks,
- del_flag,
- site_id,
- customer_id
- ) VALUES (
- #{baseClosingAccountInfoDto.name},
- #{baseClosingAccountInfoDto.closingType},
- #{baseClosingAccountInfoDto.endTime},
- #{baseClosingAccountInfoDto.month},
- #{baseClosingAccountInfoDto.startTime},
- #{baseClosingAccountInfoDto.state},
- #{baseClosingAccountInfoDto.year},
- #{baseClosingAccountInfoDto.createBy},
- #{baseClosingAccountInfoDto.createDate},
- #{baseClosingAccountInfoDto.updateBy},
- #{baseClosingAccountInfoDto.updateDate},
- #{baseClosingAccountInfoDto.remarks},
- #{baseClosingAccountInfoDto.delFlag},
- #{baseClosingAccountInfoDto.siteId},
- #{baseClosingAccountInfoDto.customerId}
- )
- </insert>
- <update id="update">
- UPDATE pay_base_closingaccountinfo SET
- name = #{baseClosingAccountInfoDto.name},
- closingtype = #{baseClosingAccountInfoDto.closingType},
- endtime = #{baseClosingAccountInfoDto.endTime},
- month = #{baseClosingAccountInfoDto.month},
- starttime = #{baseClosingAccountInfoDto.startTime},
- state = #{baseClosingAccountInfoDto.state},
- year = #{baseClosingAccountInfoDto.year},
- update_by = #{baseClosingAccountInfoDto.updateBy},
- update_date = #{baseClosingAccountInfoDto.updateDate},
- remarks = #{baseClosingAccountInfoDto.remarks}
- WHERE id = #{baseClosingAccountInfoDto.id}
- </update>
- <select id ="checkClosing" resultType="Integer">
- <if test="type == '0'.toString()">
- select count(1)
- from pay_amount_waterusedamount amount
- where amount.year= #{year} and amount.month = #{month}
- and amount.site_id=#{siteId} and amount.customer_id =#{customerId}
- </if>
- <if test="type == '1'.toString()">
- select count(1) from pay_pay_received received
- where (received.iscanceled=0 or received.iscanceled is null) and received.receivedamount>0 and received.invoice_id is null
- and received.year = #{year} and received.month = #{month}
- and received.site_id=#{siteId} and received.customer_id =#{customerId}
- </if>
- <if test = "type == '2'.toString()">
- select count(1) from pay_amount_waterusedamount amount
- where amount.state = 1 and amount.year = #{year} and amount.month = #{month}
- and amount.site_id=#{siteId} and amount.customer_id =#{customerId}
- </if>
- <if test = "type == '3'.toString()">
- select count(1) From pay_pay_receivable rece
- left join (select ifnull(sum(received.receivedamount),0) as receivedamount,received.receivable_id
- 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
- on tabre.receivable_id=rece.id
- where rece.receivablefee != (rece.debt+tabre.receivedamount)
- and rece.year=#{year}
- and rece.month=#{month}
- and rece.site_id=#{siteId} and rece.customer_id =#{customerId}
- </if>
- <if test = "type == '4'.toString()">
- select count(1) from pay_amount_waterusedamount amount
- left join pay_pay_receivable rece on rece.usedamount_id =amount.id
- inner join pay_base_customerandmeterrela rela
- on rela.id=amount.customerandmeterrela_id
- where state=0 and rece.id is null and rela.CalculateWay!=2 and amount.payamount>0
- and amount.year=#{year}
- and amount.month=#{month}
- and amount.site_id=#{siteId} and amount.customer_id =#{customerId}
- </if>
- </select>
- <select id="getLastClosingAccount" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
- select
- year AS "year"
- ,month AS "month"
- ,starttime as "startTime"
- ,endtime as "endTime"
- from pay_base_closingaccountinfo
- where state = 0
- <if test="siteId != null">
- and site_id=#{siteId}
- </if>
- <if test="customerId != null">
- and customer_id=#{customerId}
- </if>
- order by year desc,month desc LIMIT 1
- </select>
- <select id="getCurrentCloseInfo" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
- SELECT
- <include refid="baseClosingaccountinfoColumns"/>
- FROM pay_base_closingaccountinfo a
- <include refid="baseClosingaccountinfoJoins"/>
- <where>
- a.state=0
- <if test="siteId != null">
- and a.site_id=#{siteId}
- </if>
- <if test="customerId != null">
- and a.customer_id=#{customerId}
- </if>
- </where>
- limit 1
- </select>
- <select id="getClosingSC" resultType="com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto">
- select
- site_id as "siteId",
- customer_id as "customerId"
- from pay_base_closingaccountinfo
- where site_id = 51 and customer_id = 120
- GROUP BY site_id,customer_id
- </select>
- </mapper>
|