chengf
2025-08-21 bde271fdbab51e654a293dba02a31eab8ff3ea8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?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="reportFeeServiceDaoImpl">
    <select id="repostInFee" resultType="java.util.Map">
        SELECT
            fee_type_cd AS 'fee_type_cd',
            detail_year,
            -- 当年应收款项合计(保留2位小数)
            ROUND(SUM(CASE WHEN detail_year BETWEEN 2020 AND 2025 THEN receivable_amount ELSE 0 END), 2) AS '该年应缴总额',
 
            -- 当年收缴率(保留2位小数,百分比格式)
            ROUND(
                    CASE
                        WHEN SUM(CASE WHEN detail_year BETWEEN 2020 AND 2025 THEN receivable_amount ELSE 0 END) = 0 THEN 0
                        ELSE SUM(CASE WHEN detail_year BETWEEN 2020 AND 2025 THEN received_amount ELSE 0 END)
                                 / SUM(CASE WHEN detail_year BETWEEN 2020 AND 2025 THEN receivable_amount ELSE 0 END) * 100
                        END, 2
            ) AS '当年收缴率',
 
            -- 总折扣金额(保留2位小数)
            ROUND(SUM(CASE WHEN detail_year BETWEEN 2020 AND 2025 THEN discount_amount ELSE 0 END), 2) AS '折扣金额',
 
            -- 2020-2024年实收金额(保留2位小数)
            ROUND(SUM(CASE WHEN detail_year = 2020 THEN received_amount ELSE 0 END), 2) AS '2020年实缴',
            ROUND(SUM(CASE WHEN detail_year = 2021 THEN received_amount ELSE 0 END), 2) AS '2021年实缴',
            ROUND(SUM(CASE WHEN detail_year = 2022 THEN received_amount ELSE 0 END), 2) AS '2022年实缴',
            ROUND(SUM(CASE WHEN detail_year = 2023 THEN received_amount ELSE 0 END), 2) AS '2023年实缴',
            ROUND(SUM(CASE WHEN detail_year = 2024 THEN received_amount ELSE 0 END), 2) AS '2024年实缴',
 
            -- 2025年合计数据(保留2位小数)
            ROUND(SUM(CASE WHEN detail_year = 2025 THEN receivable_amount ELSE 0 END), 2) AS '当年预算',
            ROUND(SUM(CASE WHEN detail_year = 2025 THEN received_amount ELSE 0 END), 2) AS '2025年实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 THEN discount_amount ELSE 0 END), 2) AS '当年折扣总额',
            ROUND(SUM(CASE WHEN detail_year = 2025 THEN receivable_amount - received_amount ELSE 0 END), 2) AS '当年欠款',
 
            -- 2025年各月份实收(保留2位小数)
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 1 THEN received_amount ELSE 0 END), 2) AS '当年1月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 2 THEN received_amount ELSE 0 END), 2) AS '当年2月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 3 THEN received_amount ELSE 0 END), 2) AS '当年3月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 4 THEN received_amount ELSE 0 END), 2) AS '当年4月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 5 THEN received_amount ELSE 0 END), 2) AS '当年5月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 6 THEN received_amount ELSE 0 END), 2) AS '当年6月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 7 THEN received_amount ELSE 0 END), 2) AS '当年7月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 8 THEN received_amount ELSE 0 END), 2) AS '当年8月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 9 THEN received_amount ELSE 0 END), 2) AS '当年9月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 10 THEN received_amount ELSE 0 END), 2) AS '当年10月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 11 THEN received_amount ELSE 0 END), 2) AS '当年11月实缴',
            ROUND(SUM(CASE WHEN detail_year = 2025 AND detail_month = 12 THEN received_amount ELSE 0 END), 2) AS '当年12月实缴',
 
            -- 每月费用(保留2位小数)和应收月份数(整数,无需处理)
            ROUND(AVG(CASE WHEN detail_year BETWEEN 2020 AND 2025 THEN receivable_amount ELSE NULL END), 2) AS '每月费用',
            COUNT(DISTINCT CASE WHEN detail_year BETWEEN 2020 AND 2025 THEN CONCAT(detail_year, '-', detail_month) END) AS '应收月份数',
 
            -- 费用所属年份(区分普通行和汇总行)
            CASE
                WHEN detail_year IS NULL THEN '类型总计'
                ELSE CAST(detail_year AS CHAR)
                END AS '费用所属年份'
 
        FROM
            pay_fee_detail_month
        WHERE
            community_id = #{communityId}
            detail_year BETWEEN 2020 AND 2025
        GROUP BY
            fee_type_cd, detail_year
        WITH ROLLUP;
    </select>
    <insert id="saveReport" parameterType="Map">
        INSERT INTO report_query_record (
            id,
            refresh_time,
            end_year,
            community_id,
            community_name,
            report_content,
            operator,
            operator_id,
            query_status,
            create_time,
            update_time
        ) VALUES (
                     #{id},
                     now(),
                     #{endYear},
                     #{communityId},
                     null,
                     #{reportContent},
                     #{operator},
                     null,
                     #{queryStatus},
                     now(),
                     now()
                 )
    </insert>
    <select id="queryReport" resultType="java.util.Map">
        SELECT
        id,
        refresh_time AS refreshTime,
        end_year AS endYear,
        community_id AS communityId,
        community_name AS communityName,
        report_content AS reportContent,
        operator,
        operator_id AS operatorId,
        query_status AS queryStatus,
        create_time AS createTime,
        update_time AS updateTime
        FROM report_query_record
        WHERE 1 = 1
        <if test="communityId != null and communityId != ''">
            AND community_id = #{communityId}
        </if>
        <if test="endYear != null and endYear != ''">
            AND end_year = #{endYear}
        </if>
        <if test="queryStatus != null and queryStatus != ''">
            AND query_status = #{queryStatus}
        </if>
        <if test="operatorId != null and operatorId != ''">
            AND operator_id = #{operatorId}
        </if>
        <if test="startTime != null and startTime != ''">
            AND create_time >= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND create_time &lt;= #{endTime}
        </if>
        ORDER BY create_time DESC
        <if test="pageNum != null and pageSize != null">
            LIMIT #{pageNum}, #{pageSize}
        </if>
    </select>
</mapper>