xuhy
2025-04-27 5fa6e6f8410ef9d057174bcff2a3c5038c54a551
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?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.ruoyi.system.mapper.TBillMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.model.TBill">
        <id column="id" property="id" />
        <result column="contract_id" property="contractId" />
        <result column="contract_number" property="contractNumber" />
        <result column="payable_fees_money" property="payableFeesMoney" />
        <result column="payable_fees_time" property="payableFeesTime" />
        <result column="pay_fees_status" property="payFeesStatus" />
        <result column="pay_fees_money" property="payFeesMoney" />
        <result column="pay_fees_time" property="payFeesTime" />
        <result column="pay_fees_type" property="payFeesType" />
        <result column="bill_type" property="billType" />
        <result column="over_days" property="overDays" />
        <result column="payable_fees_penalty" property="payableFeesPenalty" />
        <result column="start_time" property="startTime" />
        <result column="end_time" property="endTime" />
        <result column="bank_serial_number" property="bankSerialNumber" />
        <result column="outstanding_money" property="outstandingMoney" />
        <result column="voucher" property="voucher" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="create_by" property="createBy" />
        <result column="update_by" property="updateBy" />
        <result column="disabled" property="disabled" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, contract_id,contract_number, payable_fees_money, payable_fees_time, pay_fees_status, pay_fees_money, pay_fees_time, pay_fees_type, bill_type, over_days, payable_fees_penalty, start_time, end_time, bank_serial_number, outstanding_money, voucher, create_time, update_time, create_by, update_by, disabled
    </sql>
 
    <select id="page" resultType="com.ruoyi.system.dto.TBillDto">
        SELECT
            b.*,
            t.resident_name as residentName,
            t.phone,
            t.account,
            h.house_name as houseName
        FROM
            t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        LEFT JOIN t_bill_type_sort_weight sw on sw.code=b.pay_fees_status
        <where>
            b.disabled=0
            <if test="query.payFeesStatus != null">
                and b.pay_fees_status = #{query.payFeesStatus}
            </if>
            <if test="query.phone != null and query.phone !=''">
                and t.phone = #{query.phone}
            </if>
            <if test="query.residentName != null and query.residentName !=''">
                and t.resident_name like concat('%',#{query.residentName},'%')
            </if>
            <if test="query.contractNumber != null and query.contractNumber !=''">
                and b.contract_number = #{query.contractNumber}
            </if>
            <if test="query.userId != null and query.userId !=''">
                and t.id = #{query.userId}
            </if>
            <if test='query.businessDeptId != null and query.businessDeptId != "" and query.businessDeptId!=0'>
                and b.business_dept_id = #{query.businessDeptId}
            </if>
            <if test="query.billType != null">
                and b.bill_type = #{query.billType}
            </if>
        </where>
        order by sw.sort_weight desc,b.payable_fees_time asc
<!--        order by b.payable_fees_time desc,b.create_time desc-->
    </select>
 
    <select id="pageForApplet" resultType="com.ruoyi.system.dto.TBillDto">
        SELECT
        b.*,
        t.resident_name as residentName,
        t.phone,
        t.account,
        h.house_name as houseName
        FROM
        t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        LEFT JOIN t_bill_type_sort_weight sw on sw.code=b.pay_fees_status
        <where>
            b.disabled=0
            <if test="query.payFeesStatus != null">
                and b.pay_fees_status = #{query.payFeesStatus}
            </if>
            <if test="query.phone != null and query.phone !=''">
                and t.phone = #{query.phone}
            </if>
            <if test="query.residentName != null and query.residentName !=''">
                and t.resident_name like concat('%',#{query.residentName},'%')
            </if>
            <if test="query.contractNumber != null and query.contractNumber !=''">
                and b.contract_number = #{query.contractNumber}
            </if>
            <if test="query.userId != null and query.userId !=''">
                and t.id = #{query.userId}
            </if>
            <if test='query.businessDeptId != null and query.businessDeptId != "" and query.businessDeptId!="0"'>
                and b.business_dept_id = #{query.businessDeptId}
            </if>
            <if test="query.billType != null">
                and b.bill_type = #{query.billType}
            </if>
        </where>
        order by sw.sort_weight desc,b.payable_fees_time asc
    </select>
 
    <select id="getBillList" resultType="com.ruoyi.system.dto.TBillDto">
        SELECT
        b.*,
        t.resident_name as residentName,
        t.phone,
        t.account,
        h.house_name as houseName
        FROM
        t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        <where>
            <if test="query.payFeesStatus != null">
                and b.pay_fees_status = #{query.payFeesStatus}
            </if>
            <if test="query.phone != null and query.phone !=''">
                and t.phone = #{query.phone}
            </if>
            <if test="query.residentName != null and query.residentName !=''">
                and t.resident_name like concat('%',#{query.residentName},'%')
            </if>
            <if test="query.contractNumber != null and query.contractNumber !=''">
                and b.contract_number = #{query.contractNumber}
            </if>
            <if test="query.userId != null and query.userId !=''">
                and t.id = #{query.userId}
            </if>
            <if test="query.billType != null">
                and b.bill_type = #{query.billType}
            </if>
            and b.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by b.bill_type,b.payable_fees_time
    </select>
    <select id="invoiceList" resultType="com.ruoyi.system.dto.TBillDto">
        SELECT
        b.*,
        t.resident_name as residentName,
        t.phone,
        t.account,
        h.house_name as houseName
        FROM
        t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        LEFT JOIN t_invoice_to_bill tb ON b.id = tb.bill_id
        <where>
            <if test="query.phone != null and query.phone !=''">
                and t.phone = #{query.phone}
            </if>
            <if test="query.residentName != null and query.residentName !=''">
                and t.resident_name like concat('%',#{query.residentName},'%')
            </if>
            <if test="query.contractNumber != null and query.contractNumber !=''">
                and b.contract_number = #{query.contractNumber}
            </if>
            <if test="query.userId != null and query.userId !=''">
                and t.id = #{query.userId}
            </if>
            and b.pay_fees_status = 3
            and tb.invoice_id IS NULL
            and b.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by b.pay_fees_time
    </select>
 
    <select id="selectDetailByBillId" resultType="com.ruoyi.system.dto.TBillDto">
        SELECT
            b.*,
            t.resident_name as residentName,
            t.email,
            t.phone,
            t.account,
            h.house_name as houseName,
            c.contract_name,c.pay_type,c.party_two_name,c.total_year,c.deposit
        FROM
            t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        where b.id = #{billId}
    </select>
 
    <select id="statisticsAllRent" resultType="java.math.BigDecimal">
        SELECT ifnull(sum(payable_fees_money),0) as amount FROM t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        <where>
            b.disabled=0 and b.pay_fees_status!='5'
            <if test="query.payFeesStatus != null">
                and b.pay_fees_status = #{query.payFeesStatus}
            </if>
            <if test="query.phone != null and query.phone !=''">
                and t.phone = #{query.phone}
            </if>
            <if test="query.residentName != null and query.residentName !=''">
                and t.resident_name like concat('%',#{query.residentName},'%')
            </if>
            <if test="query.contractNumber != null and query.contractNumber !=''">
                and b.contract_number = #{query.contractNumber}
            </if>
            <if test="query.userId != null and query.userId !=''">
                and t.id = #{query.userId}
            </if>
            <if test='query.businessDeptId != null and query.businessDeptId != "" and query.businessDeptId!="0"'>
                and b.business_dept_id = #{query.businessDeptId}
            </if>
            <if test="query.billType != null">
                and b.bill_type = #{query.billType}
            </if>
        </where>
 
    </select>
 
    <select id="statisticsNoPay" resultType="java.math.BigDecimal">
        SELECT ifnull(sum(outstanding_money),0) as amount FROM t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        <where>
            b.disabled=0 and b.pay_fees_status!='3' and b.pay_fees_status!='5'
            <if test="query.payFeesStatus != null">
                and b.pay_fees_status = #{query.payFeesStatus}
            </if>
            <if test="query.phone != null and query.phone !=''">
                and t.phone = #{query.phone}
            </if>
            <if test="query.residentName != null and query.residentName !=''">
                and t.resident_name like concat('%',#{query.residentName},'%')
            </if>
            <if test="query.contractNumber != null and query.contractNumber !=''">
                and b.contract_number = #{query.contractNumber}
            </if>
            <if test="query.userId != null and query.userId !=''">
                and t.id = #{query.userId}
            </if>
            <if test='query.businessDeptId != null and query.businessDeptId != "" and query.businessDeptId!="0"'>
                and b.business_dept_id = #{query.businessDeptId}
            </if>
            <if test="query.billType != null">
                and b.bill_type = #{query.billType}
            </if>
        </where>
    </select>
 
    <select id="statisticsPayed" resultType="java.math.BigDecimal">
        SELECT ifnull(sum(pay_fees_money),0) as amount FROM t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        <where>
            b.disabled=0 and b.pay_fees_status!='5'
            <if test="query.payFeesStatus != null">
                and b.pay_fees_status = #{query.payFeesStatus}
            </if>
            <if test="query.phone != null and query.phone !=''">
                and t.phone = #{query.phone}
            </if>
            <if test="query.residentName != null and query.residentName !=''">
                and t.resident_name like concat('%',#{query.residentName},'%')
            </if>
            <if test="query.contractNumber != null and query.contractNumber !=''">
                and b.contract_number = #{query.contractNumber}
            </if>
            <if test="query.userId != null and query.userId !=''">
                and t.id = #{query.userId}
            </if>
            <if test='query.businessDeptId != null and query.businessDeptId != "" and query.businessDeptId!="0"'>
                and b.business_dept_id = #{query.businessDeptId}
            </if>
            <if test="query.billType != null">
                and b.bill_type = #{query.billType}
            </if>
        </where>
    </select>
 
    <select id="statisticsOverdue" resultType="java.math.BigDecimal">
        SELECT ifnull(sum(outstanding_money),0) as amount FROM t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        <where>
            b.disabled=0 and b.pay_fees_status='4'
            <if test="query.payFeesStatus != null">
                and b.pay_fees_status = #{query.payFeesStatus}
            </if>
            <if test="query.phone != null and query.phone !=''">
                and t.phone = #{query.phone}
            </if>
            <if test="query.residentName != null and query.residentName !=''">
                and t.resident_name like concat('%',#{query.residentName},'%')
            </if>
            <if test="query.contractNumber != null and query.contractNumber !=''">
                and b.contract_number = #{query.contractNumber}
            </if>
            <if test="query.userId != null and query.userId !=''">
                and t.id = #{query.userId}
            </if>
            <if test='query.businessDeptId != null and query.businessDeptId != "" and query.businessDeptId!="0"'>
                and b.business_dept_id = #{query.businessDeptId}
            </if>
            <if test="query.billType != null">
                and b.bill_type = #{query.billType}
            </if>
        </where>
    </select>
    <select id="batchBillCount" resultType="java.lang.Integer">
        SELECT
            count(b.id)
        FROM
            t_bill b
        LEFT JOIN t_contract c ON c.contract_number = b.contract_number and c.disabled=0
        LEFT JOIN t_house h ON h.id = c.house_id and h.disabled=0
        LEFT JOIN t_tenant t ON t.id = c.tenant_id and t.disabled=0
        <where>
            <if test="userId != null and userId !=''">
                AND t.id = #{userId}
            </if>
            <if test="billIds != null and billIds.size() > 0">
                AND b.id NOT IN
                <foreach collection="billIds" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            AND b.bill_type = 3
            AND b.pay_fees_status != 3
        </where>
    </select>
    <select id="getStreetRentRank" resultType="com.ruoyi.system.vo.ScreenRentRankVO">
        SELECT
            ts.street_name,ROUND(COALESCE(SUM(tb.pay_fees_money),0) /10000,2) AS rentAmount
        FROM
            t_street ts
                LEFT JOIN t_house th ON ts.id = th.street_id
                LEFT JOIN t_contract tc ON tc.house_id = th.id AND tc.pay_type = 2
                LEFT JOIN t_bill tb ON tc.id = tb.contract_id AND tb.pay_fees_status != 5
            <where>
                <if test="businessDeptId != 0">
                    AND th.business_dept_id = #{businessDeptId}
                </if>
            </where>
        GROUP BY ts.id
        ORDER BY rentAmount DESC
    </select>
    <select id="getJiFuBillList" resultType="com.ruoyi.system.model.TBill" parameterType="java.lang.String">
        SELECT tb.* FROM t_bill tb LEFT JOIN t_contract tt ON tb.contract_id = tt.id
        <where>
            tt.pay_type = 2 AND tb.bill_type = ${@com.ruoyi.common.enums.BillTypeEnum@Zujin.getCode()} AND tb.pay_fees_status != 5
            <if test="businessDeptId != null and businessDeptId != 0">
                AND tb.business_dept_id = #{businessDeptId}
            </if>
            <if test="first!=null and last !=null">
                AND tb.payable_fees_time BETWEEN #{first} AND #{last}
            </if>
        </where>
    </select>
</mapper>