|
@@ -16,6 +16,7 @@
|
|
|
<result property="deposit" column="deposit" jdbcType="DECIMAL"/>
|
|
<result property="deposit" column="deposit" jdbcType="DECIMAL"/>
|
|
|
<result property="waterFee" column="water_fee" jdbcType="DECIMAL"/>
|
|
<result property="waterFee" column="water_fee" jdbcType="DECIMAL"/>
|
|
|
<result property="electricityBill" column="electricity_bill" jdbcType="DECIMAL"/>
|
|
<result property="electricityBill" column="electricity_bill" jdbcType="DECIMAL"/>
|
|
|
|
|
+ <result property="operator" column="operator" jdbcType="VARCHAR"/>
|
|
|
<result property="attachmentUrl" column="attachment_url" jdbcType="VARCHAR"/>
|
|
<result property="attachmentUrl" column="attachment_url" jdbcType="VARCHAR"/>
|
|
|
<result property="receiptReason" column="receipt_reason" jdbcType="VARCHAR"/>
|
|
<result property="receiptReason" column="receipt_reason" jdbcType="VARCHAR"/>
|
|
|
<result property="generationDate" column="generation_date" javaType="DATE"/>
|
|
<result property="generationDate" column="generation_date" javaType="DATE"/>
|
|
@@ -38,6 +39,7 @@
|
|
|
<result property="deposit" column="deposit" jdbcType="DECIMAL"/>
|
|
<result property="deposit" column="deposit" jdbcType="DECIMAL"/>
|
|
|
<result property="waterFee" column="water_fee" jdbcType="DECIMAL"/>
|
|
<result property="waterFee" column="water_fee" jdbcType="DECIMAL"/>
|
|
|
<result property="electricityBill" column="electricity_bill" jdbcType="DECIMAL"/>
|
|
<result property="electricityBill" column="electricity_bill" jdbcType="DECIMAL"/>
|
|
|
|
|
+ <result property="operator" column="operator" jdbcType="VARCHAR"/>
|
|
|
<result property="attachmentUrl" column="attachment_url" jdbcType="VARCHAR"/>
|
|
<result property="attachmentUrl" column="attachment_url" jdbcType="VARCHAR"/>
|
|
|
<result property="receiptReason" column="receipt_reason" jdbcType="VARCHAR"/>
|
|
<result property="receiptReason" column="receipt_reason" jdbcType="VARCHAR"/>
|
|
|
<result property="generationDate" column="generation_date" jdbcType="DATE" javaType="java.time.LocalDate"/>
|
|
<result property="generationDate" column="generation_date" jdbcType="DATE" javaType="java.time.LocalDate"/>
|
|
@@ -53,7 +55,7 @@
|
|
|
id,contract_id,receipt_number,payer,
|
|
id,contract_id,receipt_number,payer,
|
|
|
payment_method,total_amount,rent,
|
|
payment_method,total_amount,rent,
|
|
|
property_fee,deposit,water_fee,electricity bill,
|
|
property_fee,deposit,water_fee,electricity bill,
|
|
|
- receipt_reason,attachment_url,accounting_date,
|
|
|
|
|
|
|
+ receipt_reason,operator,attachment_url,accounting_date,
|
|
|
generation_date,start_date,end_date,create_time,update_time
|
|
generation_date,start_date,end_date,create_time,update_time
|
|
|
</sql>
|
|
</sql>
|
|
|
<select id="selectReceiptWithContractByPage" resultMap="VoResultMap">
|
|
<select id="selectReceiptWithContractByPage" resultMap="VoResultMap">
|
|
@@ -70,6 +72,7 @@
|
|
|
r.water_fee,
|
|
r.water_fee,
|
|
|
r.electricity_bill,
|
|
r.electricity_bill,
|
|
|
r.receipt_reason,
|
|
r.receipt_reason,
|
|
|
|
|
+ r.operator,
|
|
|
r.attachment_url,
|
|
r.attachment_url,
|
|
|
r.accounting_date,
|
|
r.accounting_date,
|
|
|
r.generation_date,
|
|
r.generation_date,
|
|
@@ -96,4 +99,118 @@
|
|
|
</where>
|
|
</where>
|
|
|
ORDER BY r.create_time DESC
|
|
ORDER BY r.create_time DESC
|
|
|
</select>
|
|
</select>
|
|
|
|
|
+ <!-- 按年统计:返回1-12月明细,receiptTime格式为"X月" -->
|
|
|
|
|
+ <select id="statReceiptByYear" resultType="com.zksy.property.domain.vo.AReceiptInfoReportVo">
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ CONCAT(m.month, '月') AS receiptTime,
|
|
|
|
|
+ IFNULL(SUM(r.rent), 0) AS rent,
|
|
|
|
|
+ IFNULL(SUM(r.deposit), 0) AS deposit,
|
|
|
|
|
+ IFNULL(SUM(r.property_fee), 0) AS propertyFee,
|
|
|
|
|
+ IFNULL(SUM(r.water_fee), 0) AS waterFee,
|
|
|
|
|
+ IFNULL(SUM(r.electricity_bill), 0) AS electricityBill
|
|
|
|
|
+ FROM
|
|
|
|
|
+ -- 12个月虚拟表,作为统计的时间维度基础
|
|
|
|
|
+ (
|
|
|
|
|
+ SELECT 1 AS month UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6
|
|
|
|
|
+ UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12
|
|
|
|
|
+ ) m
|
|
|
|
|
+ -- 左连接:仅筛选出「目标资产类型+指定年份」的收款数据,再按月份匹配
|
|
|
|
|
+ LEFT JOIN (
|
|
|
|
|
+ -- 子查询:先精准筛选出属于传入assetType的收款数据(核心!先筛选,再关联)
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ r.rent, r.deposit, r.property_fee, r.water_fee, r.electricity_bill,
|
|
|
|
|
+ r.accounting_date
|
|
|
|
|
+ FROM a_receipt_info r
|
|
|
|
|
+ -- 内连接:仅保留有合同的收款数据
|
|
|
|
|
+ INNER JOIN a_contract_info c ON r.contract_id = c.id
|
|
|
|
|
+ -- 内连接:仅保留有房屋信息的合同数据,且房屋类型严格匹配传入的assetType
|
|
|
|
|
+ INNER JOIN a_simplified_house_info sh ON c.simplified_house_id = sh.id AND sh.asset_type = #{assetType}
|
|
|
|
|
+ -- 筛选指定年份的收款数据
|
|
|
|
|
+ WHERE YEAR(r.accounting_date) = #{year}
|
|
|
|
|
+ ) r ON MONTH(r.accounting_date) = m.month
|
|
|
|
|
+ -- 按月份分组合计,保证12个月完整
|
|
|
|
|
+ GROUP BY m.month
|
|
|
|
|
+ ORDER BY m.month
|
|
|
|
|
+ </select>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 按月统计:返回当月每日明细,receiptTime格式为"yyyy-MM-dd" -->
|
|
|
|
|
+ <select id="statReceiptByMonth" resultType="com.zksy.property.domain.vo.AReceiptInfoReportVo">
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ DATE_FORMAT(d.day_date, '%Y-%m-%d') AS receiptTime,
|
|
|
|
|
+ IFNULL(SUM(r.rent), 0) AS rent,
|
|
|
|
|
+ IFNULL(SUM(r.deposit), 0) AS deposit,
|
|
|
|
|
+ IFNULL(SUM(r.property_fee), 0) AS propertyFee,
|
|
|
|
|
+ IFNULL(SUM(r.water_fee), 0) AS waterFee,
|
|
|
|
|
+ IFNULL(SUM(r.electricity_bill), 0) AS electricityBill
|
|
|
|
|
+ FROM
|
|
|
|
|
+ (
|
|
|
|
|
+ <!-- 生成指定年月的所有日期,原逻辑保留不变 -->
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ DATE_ADD(
|
|
|
|
|
+ CONCAT(#{year}, '-', #{month}, '-01'),
|
|
|
|
|
+ INTERVAL (t.n - 1) DAY
|
|
|
|
|
+ ) AS day_date
|
|
|
|
|
+ FROM
|
|
|
|
|
+ (
|
|
|
|
|
+ SELECT 1 AS n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6
|
|
|
|
|
+ UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12
|
|
|
|
|
+ UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18
|
|
|
|
|
+ UNION ALL SELECT 19 UNION ALL SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23 UNION ALL SELECT 24
|
|
|
|
|
+ UNION ALL SELECT 25 UNION ALL SELECT 26 UNION ALL SELECT 27 UNION ALL SELECT 28 UNION ALL SELECT 29 UNION ALL SELECT 30
|
|
|
|
|
+ UNION ALL SELECT 31
|
|
|
|
|
+ ) t
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ DATE_ADD(CONCAT(#{year}, '-', #{month}, '-01'), INTERVAL (t.n - 1) DAY)
|
|
|
|
|
+ <= LAST_DAY(CONCAT(#{year}, '-', #{month}, '-01'))
|
|
|
|
|
+ ) d
|
|
|
|
|
+ <!-- 左连接:日期表关联【筛选后的目标收款数据】,保证日期完整 -->
|
|
|
|
|
+ LEFT JOIN (
|
|
|
|
|
+ <!-- 子查询:先精准筛选【指定年月+指定资产类型】的有效收款数据(核心) -->
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ r.rent, r.deposit, r.property_fee, r.water_fee, r.electricity_bill,
|
|
|
|
|
+ r.accounting_date
|
|
|
|
|
+ FROM a_receipt_info r
|
|
|
|
|
+ <!-- 内连接:仅保留有合同的收款 -->
|
|
|
|
|
+ INNER JOIN a_contract_info c ON r.contract_id = c.id
|
|
|
|
|
+ <!-- 内连接:仅保留有房屋+资产类型匹配的合同,动态判断兼容传/不传assetType -->
|
|
|
|
|
+ INNER JOIN a_simplified_house_info sh ON c.simplified_house_id = sh.id
|
|
|
|
|
+ <if test="assetType != null and assetType != ''">
|
|
|
|
|
+ AND sh.asset_type = #{assetType}
|
|
|
|
|
+ </if>
|
|
|
|
|
+ <!-- 筛选指定年月的收款数据 -->
|
|
|
|
|
+ WHERE YEAR(r.accounting_date) = #{year}
|
|
|
|
|
+ AND MONTH(r.accounting_date) = #{month}
|
|
|
|
|
+ ) r ON DATE(r.accounting_date) = d.day_date
|
|
|
|
|
+ GROUP BY d.day_date
|
|
|
|
|
+ ORDER BY d.day_date
|
|
|
|
|
+ </select>
|
|
|
|
|
+ <select id="statReceiptByDay" resultType="com.zksy.property.domain.vo.AReceiptInfoReportDayVo">
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ r.receipt_number AS receiptCode, -- 收据号
|
|
|
|
|
+ r.payer AS payer, -- 付款人
|
|
|
|
|
+ DATE_FORMAT(r.accounting_date, '%Y-%m-%d') AS receiptTime, -- 收取时间
|
|
|
|
|
+ -- 租金收取时段:拼接开始时间和结束时间
|
|
|
|
|
+ CONCAT(DATE_FORMAT(r.start_date, '%Y-%m-%d'), ' ~ ', DATE_FORMAT(r.end_date, '%Y-%m-%d')) AS rentPeriod,
|
|
|
|
|
+ r.operator AS operator, -- 经手人/操作人
|
|
|
|
|
+ r.payment_method AS payType, -- 支付方式
|
|
|
|
|
+ -- 原有金额字段,去掉外层IFNULL(明细行保留原始值,如需置0可保留)
|
|
|
|
|
+ r.rent AS rent, -- 房租
|
|
|
|
|
+ r.deposit AS deposit, -- 押金
|
|
|
|
|
+ r.water_fee AS waterFee, -- 水费
|
|
|
|
|
+ r.electricity_bill AS electricityBill, -- 电费
|
|
|
|
|
+ r.property_fee AS propertyFee -- 物业管理费
|
|
|
|
|
+ FROM a_receipt_info r
|
|
|
|
|
+ <!-- 内连接替代左连接:仅保留有合同+有房屋的有效收款,避免无关联的无效明细 -->
|
|
|
|
|
+ INNER JOIN a_contract_info c ON r.contract_id = c.id
|
|
|
|
|
+ INNER JOIN a_simplified_house_info h ON c.simplified_house_id = h.id
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ -- 按传入的年份和月份筛选
|
|
|
|
|
+ YEAR(r.accounting_date) = #{year}
|
|
|
|
|
+ AND MONTH(r.accounting_date) = #{month}
|
|
|
|
|
+ <!-- 资产类型筛选:仅匹配指定类型,移除OR h.asset_type IS NULL(彻底排除非目标类型) -->
|
|
|
|
|
+ <if test="assetType != null and assetType != ''">
|
|
|
|
|
+ AND h.asset_type = #{assetType}
|
|
|
|
|
+ </if>
|
|
|
|
|
+ ORDER BY r.accounting_date ASC
|
|
|
|
|
+ </select>
|
|
|
</mapper>
|
|
</mapper>
|