zhangmei
2025-03-27 1fad0578c97abbb7fc30f59eb1de0f23f08ddde1
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
<?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.TContractMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.model.TContract">
        <id column="id" property="id" />
        <result column="contract_number" property="contractNumber" />
        <result column="contract_name" property="contractName" />
        <result column="start_time" property="startTime" />
        <result column="end_time" property="endTime" />
        <result column="deposit" property="deposit" />
        <result column="pay_type" property="payType" />
        <result column="first_pay_time" property="firstPayTime" />
        <result column="isIncreasing" property="isIncreasing" />
        <result column="isIncreasing_deposit" property="isIncreasingDeposit" />
        <result column="proportion" property="proportion" />
        <result column="house_id" property="houseId" />
        <result column="party_one_name" property="partyOneName" />
        <result column="party_one_person" property="partyOnePerson" />
        <result column="party_one_phone" property="partyOnePhone" />
        <result column="tenant_id" property="tenantId" />
        <result column="party_two_name" property="partyTwoName" />
        <result column="party_two_person" property="partyTwoPerson" />
        <result column="party_two_phone" property="partyTwoPhone" />
        <result column="contract_file" property="contractFile" />
        <result column="remark" property="remark" />
        <result column="status" property="status" />
        <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" />
        <result column="memory" property="memory" />
        <result column="contract_file_name" property="contractFileName" />
        <result column="signature" property="signature" />
        <result column="terminate_remark" property="terminateRemark" />
        <result column="total_year" property="totalYear" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, contract_number, contract_name, start_time, end_time, deposit, pay_type, first_pay_time, isIncreasing, isIncreasing_deposit,
            proportion, house_id, party_one_name, party_one_person, party_one_phone, tenant_id, party_two_name, party_two_person, party_two_phone,
            memory, contract_file_name, signature, terminate_remark, total_year,status
    </sql>
    <select id="contractList" resultType="com.ruoyi.system.model.TContract">
        select t1.* from t_contract t1
        <where>
            <if test="query.partyTwoName != null and query.partyTwoName != ''">
                and t1.party_two_name like concat('%',#{query.partyTwoName},'%')
            </if>
            <if test="query.contractNumber != null and query.contractNumber != ''">
                and t1.contract_number like concat('%',#{query.contractNumber},'%')
            </if>
             <if test="query.contractName != null and query.contractName != ''">
                and t1.contract_name like concat('%',#{query.contractName},'%')
            </if>
            <if test="query.status != null">
                and t1.status = #{query.status}
            </if>
            <if test="query.tenantId != null">
                and t1.tenant_id = #{query.tenantId}
            </if>
            <if test="query.statuses != null and query.statuses.size()>0">
                and t1.status in
                <foreach collection="query.statuses" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="businessDeptId!=null and businessDeptId !='' and businessDeptId != '0'">
                and t1.business_dept_id = #{businessDeptId}
            </if>
            AND t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by t1.create_time desc
    </select>
    <select id="contractAppletList" resultType="com.ruoyi.system.model.TContract">
        select t1.* from t_contract t1
        <where>
            <if test="query.status != null">
                and t1.status = #{query.status}
            </if>
            <if test="query.tenantId != null">
                and t1.tenant_id = #{query.tenantId}
            </if>
            and (t1.status=3 or t1.status=4)
            AND t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
    </select>
    <select id="contractBillList" resultType="com.ruoyi.system.vo.BillVO">
        select t1.*,t2.contract_number as contractNumber,t3.resident_name as residentName,t3.phone as phone
        from t_bill t1
        left join t_contract t2 on t1.contract_id = t2.id
        left join t_tenant t3 on t2.tenant_id = t3.id
        where t2.id = #{query.id}
        and (t1.pay_fees_status = 1 or t1.pay_fees_status = 4)
        AND t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        AND t2.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        AND t3.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
    </select>
    <select id="contractExportList" resultType="com.ruoyi.system.model.TContract">
        select t1.* from t_contract t1
        <where>
            <if test="query.ids != null and query.ids.size()>0">
                AND t1.id IN
                <foreach collection="query.ids" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="query.ids == null or query.ids.size()==0">
                <if test="query.partyTwoName != null and query.partyTwoName != ''">
                    and t1.party_two_name like concat('%',#{query.partyTwoName},'%')
                </if>
                <if test="query.contractNumber != null and query.contractNumber != ''">
                    and t1.contract_number like concat('%',#{query.contractNumber},'%')
                </if>
                <if test="query.contractName != null and query.contractName != ''">
                    and t1.contract_name like concat('%',#{query.contractName},'%')
                </if>
                <if test="query.status != null">
                    and t1.status = #{query.status}
                </if>
            </if>
 
            AND t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
 
        </where>
    </select>
    <select id="getCurrentMonthRentCount" resultType="java.lang.Integer">
        SELECT COUNT(DISTINCT tc.tenant_id) AS new_tenant_count
        FROM t_contract tc
        WHERE
        -- 筛选本月签订的合同
        DATE_FORMAT(tc.sign_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m') AND tc.status IN ("4", "5", "6", "7", "8", "9")
        -- 且租户在本月前从未签订过任何合同
        AND NOT EXISTS (
        SELECT 1
        FROM t_contract tc_hist
        WHERE tc_hist.tenant_id = tc.tenant_id
        AND tc_hist.sign_time <![CDATA[ < ]]> DATE_FORMAT(CURDATE(), '%Y-%m-01') AND tc_hist.status IN ("4", "5", "6", "7", "8", "9")
        )
    </select>
 
</mapper>