chengf
2026-02-25 64b14b0549344f13b191e2c26ed199f62655c43f
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<?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="contractServiceDaoImpl">
 
    <!-- 保存合同管理信息 add by wuxw 2018-07-03 -->
    <insert id="saveContractInfo" parameterType="Map">
        insert into contract(a_link, a_contacts, amount, contract_type, store_id, operator, signing_time, b_contacts,
        party_a, b_link, party_b,
        contract_id, obj_id, contract_name, start_time, end_time, state, contract_code, obj_type,
        operator_link, contract_parent_id,
        obj_name, obj_person_name, obj_person_id, start_user_id,party_c,c_link,c_contacts
        ,a_partya_id,b_partya_id,c_partya_id,community_id,
        property_company,contract_term,is_archived,contract_reminder_date,
        signatory_address,contact_email,contact_wechat,remarks)
        values (#{aLink}, #{aContacts}, #{amount}, #{contractType}, #{storeId}, #{operator}, #{signingTime},
        #{bContacts}, #{partyA}, #{bLink}, #{partyB},
        #{contractId}, #{objId}, #{contractName}, #{startTime}, #{endTime}, #{state}, #{contractCode},
        #{objType}, #{operatorLink}, #{contractParentId},
        #{objName}, #{objPersonName}, #{objPersonId}, #{startUserId},#{partyC},#{cLink},#{cContacts}
        ,#{aPartyaId},#{bPartyaId},#{cPartyaId},#{communityId},
        #{propertyCompany},#{contractTerm},#{isArchived},#{contractReminderDate},
        #{signatoryAddress},#{contactEmail},#{contactWechat},#{remarks})
    </insert>
 
    <!-- 查询合同管理信息 add by wuxw 2018-07-03 -->
    <select id="getContractInfo" parameterType="Map" resultType="Map">
        select t.a_link,t.a_link aLink,t.a_contacts,t.a_contacts aContacts,t.amount,t.contract_type,t.contract_type
        contractType,t.status_cd,t.status_cd statusCd,t.store_id,t.store_id
        storeId,t.operator,t.signing_time,t.signing_time signingTime,t.b_contacts,t.b_contacts
        bContacts,t.party_a,t.party_a partyA,t.b_link,t.b_link bLink,t.party_b,t.party_b
        partyB,t.contract_id,t.contract_id contractId,t.obj_id,t.obj_id objId,t.contract_name,t.contract_name
        contractName,t.start_time,t.start_time startTime,t.end_time,t.end_time
        endTime,t.state,t.contract_code,t.contract_code contractCode,t.obj_type,t.obj_type
        objType,t.operator_link,t.operator_link operatorLink,ct.type_name contractTypeName,ct.audit,td.`name`
        stateName,t.state_desc stateDesc,t.contract_parent_id contractParentId,tt.contract_code parentContractCode,
        tt.contract_name parentContractName,t.obj_name objName, t.obj_person_name objPersonName, t.obj_person_id
        objPersonId,t.start_user_id startUserId,t.create_time createTime,t.party_c partyC,t.c_link cLink,t.c_contacts cContacts
        ,t.a_partya_id aPartyaId,t.b_partya_id bPartyaId,t.c_partya_id cPartyaId,s_community.`name` communityName,
        t.property_company propertyCompany,t.contract_term contractTerm,t.is_archived isArchived,
        t.contract_reminder_date contractReminderDate,t.signatory_address signatoryAddress,
        t.contact_email contactEmail,t.contact_wechat contactWechat,t.remarks remarks
        from contract t
        LEFT JOIN contract_type ct on t.contract_type = ct.contract_type_id and ct.status_cd = '0' and ct.store_id =
        t.store_id
        LEFT JOIN t_dict td on td.status_cd = t.state and td.table_name = 'contract' and td.table_columns = 'state'
        left join contract tt on t.contract_parent_id = tt.contract_id and tt.status_cd = '0' and tt.store_id =
        t.store_id
        left join s_community on t.community_id = s_community.community_id
        where 1 =1
        <if test="communityName != null and communityName != ''">
            and s_community.`name` like concat('%',#{communityName},'%')
        </if>
        <if test="communityId != null and communityId != ''">
            and t.community_id = #{communityId}
        </if>
        <if test="aLink !=null and aLink != ''">
            and t.a_link= #{aLink}
        </if>
        <if test="aPartyaId !=null and aPartyaId != ''">
            and t.a_partya_id= #{aPartyaId}
        </if>
        <if test="bPartyaId !=null and bPartyaId != ''">
            and t.b_partya_id= #{bPartyaId}
        </if>
        <if test="cPartyaId !=null and cPartyaId != ''">
            and t.c_partya_id= #{cPartyaId}
        </if>
        <if test="aContacts !=null and aContacts != ''">
            and t.a_contacts= #{aContacts}
        </if>
        <if test="amount !=null and amount != ''">
            and t.amount= #{amount}
        </if>
        <if test="contractType !=null and contractType != ''">
            and t.contract_type= #{contractType}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
        <if test="storeId !=null and storeId != ''">
            and t.store_id= #{storeId}
        </if>
        <if test="operator !=null and operator != ''">
            and t.operator= #{operator}
        </if>
        <if test="signingTime !=null and signingTime != ''">
            and t.signing_time= #{signingTime}
        </if>
        <if test="bContacts !=null and bContacts != ''">
            and t.b_contacts= #{bContacts}
        </if>
        <if test="partyA !=null and partyA != ''">
            and t.party_a= #{partyA}
        </if>
        <if test="bLink !=null and bLink != ''">
            and t.b_link= #{bLink}
        </if>
        <if test="partyB !=null and partyB != ''">
            and t.party_b= #{partyB}
        </if>
        <if test="partyBLike !=null and partyBLike != ''">
            and t.party_b like concat('%',#{partyBLike},'%')
        </if>
        <if test="contractId !=null and contractId != ''">
            and t.contract_id= #{contractId}
        </if>
        <if test="contractIds !=null">
            and t.contract_id in
            <foreach collection="contractIds" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="objId !=null and objId != ''">
            and t.obj_id= #{objId}
        </if>
        <if test="objPersonId !=null and objPersonId != ''">
            and t.obj_person_id= #{objPersonId}
        </if>
        <if test="contractName !=null and contractName != ''">
            and t.contract_name= #{contractName}
        </if>
        <if test="contractNameLike !=null and contractNameLike != ''">
            and t.contract_name like concat('%',#{contractNameLike},'%')
        </if>
        <if test="startTime !=null">
            and t.start_time= #{startTime}
        </if>
        <if test="endTime !=null ">
            and t.end_time &lt;= #{endTime}
        </if>
        <if test="queryStartTime !=null and queryStartTime != ''">
            and t.create_time &gt; #{queryStartTime}
        </if>
        <if test="queryEndTime !=null and queryEndTime != ''">
            and t.create_time &lt; #{queryEndTime}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="partyC !=null and partyC != ''">
            and t.party_c= #{partyC}
        </if>
        <if test="cLink !=null and cLink != ''">
            and t.c_link= #{cLink}
        </if>
        <if test="cContacts !=null and cContacts != ''">
            and t.c_contacts= #{cContacts}
        </if>
        <if test="noStates !=null ">
            and t.state not in
            <foreach collection="noStates" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="contractCode !=null and contractCode != ''">
            and t.contract_code= #{contractCode}
        </if>
        <if test="contractCodeLike !=null and contractCodeLike != ''">
            and t.contract_code like concat('%',#{contractCodeLike},'%')
        </if>
        <if test="objType !=null and objType != ''">
            and t.obj_type= #{objType}
        </if>
        <if test="operatorLink !=null and operatorLink != ''">
            and t.operator_link= #{operatorLink}
        </if>
        <if test="contractParentId !=null and contractParentId != ''">
            and t.contract_parent_id= #{contractParentId}
        </if>
        <if test="parentContractCodeLike !=null and parentContractCodeLike != ''">
            and tt.contract_code like concat('%',#{parentContractCodeLike},'%')
        </if>
        <!-- 新增字段的查询条件 -->
        <if test="propertyCompany !=null and propertyCompany != ''">
            and t.property_company like concat('%',#{propertyCompany},'%')
        </if>
        <if test="contractTerm !=null and contractTerm != ''">
            and t.contract_term= #{contractTerm}
        </if>
        <if test="isArchived !=null and isArchived != ''">
            and t.is_archived= #{isArchived}
        </if>
        <if test="contractReminderDate !=null and contractReminderDate != ''">
            and t.contract_reminder_date= #{contractReminderDate}
        </if>
        order by t.create_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <!-- 修改合同管理信息 add by wuxw 2018-07-03 -->
    <update id="updateContractInfo" parameterType="Map">
        update contract t set t.status_cd = #{statusCd}
        <if test="newBId != null and newBId != ''">
            ,t.b_id = #{newBId}
        </if>
        <if test="aLink !=null">
            , t.a_link= #{aLink}
        </if>
        <if test="aContacts !=null">
            , t.a_contacts= #{aContacts}
        </if>
        <if test="amount !=null and amount != ''">
            , t.amount= #{amount}
        </if>
        <if test="contractType !=null and contractType != ''">
            , t.contract_type= #{contractType}
        </if>
        <if test="storeId !=null and storeId != ''">
            , t.store_id= #{storeId}
        </if>
        <if test="operator !=null and operator != ''">
            , t.operator= #{operator}
        </if>
        <if test="signingTime !=null and signingTime != ''">
            , t.signing_time= #{signingTime}
        </if>
        <if test="bContacts !=null">
            , t.b_contacts= #{bContacts}
        </if>
        <if test="partyA !=null and partyA != ''">
            , t.party_a= #{partyA}
        </if>
        <if test="bLink !=null">
            , t.b_link= #{bLink}
        </if>
        <if test="partyB !=null and partyB != ''">
            , t.party_b= #{partyB}
        </if>
        <if test="objId !=null and objId != ''">
            , t.obj_id= #{objId}
        </if>
        <if test="objName !=null and objName != ''">
            , t.obj_name= #{objName}
        </if>
        <if test="objPersonId !=null and objPersonId != ''">
            , t.obj_person_id= #{objPersonId}
        </if>
        <if test="objPersonName !=null and objPersonName != ''">
            , t.obj_person_name= #{objPersonName}
        </if>
        <if test="contractName !=null and contractName != ''">
            , t.contract_name= #{contractName}
        </if>
        <if test="startTime !=null ">
            , t.start_time= #{startTime}
        </if>
        <if test="endTime !=null">
            , t.end_time= #{endTime}
        </if>
        <if test="state !=null and state != ''">
            , t.state= #{state}
        </if>
        <if test="stateDesc !=null and stateDesc != ''">
            , t.state_desc= #{stateDesc}
        </if>
        <if test="contractCode !=null and contractCode != ''">
            , t.contract_code= #{contractCode}
        </if>
        <if test="objType !=null and objType != ''">
            , t.obj_type= #{objType}
        </if>
        <if test="operatorLink !=null and operatorLink != ''">
            , t.operator_link= #{operatorLink}
        </if>
        <if test="partyC !=null and partyC != ''">
            , t.party_c= #{partyC}
        </if>
        <if test="cLink !=null">
            , t.c_link= #{cLink}
        </if>
        <if test="cContacts !=null">
            , t.c_contacts= #{cContacts}
        </if>
        <if test="aPartyaId !=null">
            , t.a_partya_id= #{aPartyaId}
        </if>
        <if test="bPartyaId !=null">
            , t.b_partya_id= #{bPartyaId}
        </if>
        <if test="cPartyaId !=null">
            , t.c_partya_id= #{cPartyaId}
        </if>
        <if test="communityId != null and communityId != ''">
            , t.community_id = #{communityId}
        </if>
        <!-- 新增字段的更新逻辑 -->
        <if test="propertyCompany !=null and propertyCompany != ''">
            , t.property_company= #{propertyCompany}
        </if>
        <if test="contractTerm !=null and contractTerm != ''">
            , t.contract_term= #{contractTerm}
        </if>
        <if test="isArchived !=null and isArchived != ''">
            , t.is_archived= #{isArchived}
        </if>
        <if test="contractReminderDate !=null and contractReminderDate != ''">
            , t.contract_reminder_date= #{contractReminderDate}
        </if>
        <if test="signatoryAddress !=null and signatoryAddress != ''">
            , t.signatory_address= #{signatoryAddress}
        </if>
        <if test="contactEmail !=null and contactEmail != ''">
            , t.contact_email= #{contactEmail}
        </if>
        <if test="contactWechat !=null and contactWechat != ''">
            , t.contact_wechat= #{contactWechat}
        </if>
        <if test="remarks !=null and remarks != ''">
            , t.remarks= #{remarks}
        </if>
        where 1=1
        <if test="contractId !=null and contractId != ''">
            and t.contract_id= #{contractId}
        </if>
    </update>
 
    <!-- 查询合同管理数量 add by wuxw 2018-07-03 -->
    <select id="queryContractsCount" parameterType="Map" resultType="Map">
        select count(1) count
        from contract t
        left join contract tt on t.contract_parent_id = tt.contract_id and tt.status_cd = '0' and tt.store_id =
        t.store_id
        where 1 =1
 
        <if test="communityId != null and communityId != ''">
            and t.community_id = #{communityId}
        </if>
        <if test="partyC !=null and partyC != ''">
            and t.party_c= #{partyC}
        </if>
        <if test="cLink !=null and cLink != ''">
            and t.c_link= #{cLink}
        </if>
        <if test="cContacts !=null and cContacts != ''">
            and t.c_contacts= #{cContacts}
        </if>
        <if test="aLink !=null and aLink != ''">
            and t.a_link= #{aLink}
        </if>
        <if test="aPartyaId !=null and aPartyaId != ''">
            and t.a_partya_id= #{aPartyaId}
        </if>
        <if test="bPartyaId !=null and bPartyaId != ''">
            and t.b_partya_id= #{bPartyaId}
        </if>
        <if test="cPartyaId !=null and cPartyaId != ''">
            and t.c_partya_id= #{cPartyaId}
        </if>
        <if test="aContacts !=null and aContacts != ''">
            and t.a_contacts= #{aContacts}
        </if>
        <if test="amount !=null and amount != ''">
            and t.amount= #{amount}
        </if>
        <if test="contractType !=null and contractType != ''">
            and t.contract_type= #{contractType}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
        <if test="storeId !=null and storeId != ''">
            and t.store_id= #{storeId}
        </if>
        <if test="operator !=null and operator != ''">
            and t.operator= #{operator}
        </if>
        <if test="signingTime !=null and signingTime != ''">
            and t.signing_time= #{signingTime}
        </if>
        <if test="bContacts !=null and bContacts != ''">
            and t.b_contacts= #{bContacts}
        </if>
        <if test="partyA !=null and partyA != ''">
            and t.party_a= #{partyA}
        </if>
        <if test="bLink !=null and bLink != ''">
            and t.b_link= #{bLink}
        </if>
        <if test="partyB !=null and partyB != ''">
            and t.party_b= #{partyB}
        </if>
        <if test="partyBLike !=null and partyBLike != ''">
            and t.party_b like concat('%',#{partyBLike},'%')
        </if>
        <if test="contractId !=null and contractId != ''">
            and t.contract_id= #{contractId}
        </if>
        <if test="contractIds !=null">
            and t.contract_id in
            <foreach collection="contractIds" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="objId !=null and objId != ''">
            and t.obj_id= #{objId}
        </if>
        <if test="objPersonId !=null and objPersonId != ''">
            and t.obj_person_id= #{objPersonId}
        </if>
        <if test="contractName !=null and contractName != ''">
            and t.contract_name= #{contractName}
        </if>
        <if test="contractNameLike !=null and contractNameLike != ''">
            and t.contract_name like concat('%',#{contractNameLike},'%')
        </if>
        <if test="startTime !=null and startTime != ''">
            and t.start_time= #{startTime}
        </if>
        <if test="endTime !=null and endTime != ''">
            and t.end_time &lt;= #{endTime}
        </if>
        <if test="queryStartTime !=null and queryStartTime != ''">
            and t.create_time &gt; #{queryStartTime}
        </if>
        <if test="queryEndTime !=null and queryEndTime != ''">
            and t.create_time &lt; #{queryEndTime}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="noStates !=null ">
            and t.state not in
            <foreach collection="noStates" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="contractCode !=null and contractCode != ''">
            and t.contract_code= #{contractCode}
        </if>
        <if test="contractCodeLike !=null and contractCodeLike != ''">
            and t.contract_code like concat('%',#{contractCodeLike},'%')
        </if>
        <if test="objType !=null and objType != ''">
            and t.obj_type= #{objType}
        </if>
        <if test="operatorLink !=null and operatorLink != ''">
            and t.operator_link= #{operatorLink}
        </if>
        <if test="contractParentId !=null and contractParentId != ''">
            and t.contract_parent_id= #{contractParentId}
        </if>
        <if test="parentContractCodeLike !=null and parentContractCodeLike != ''">
            and tt.contract_code like concat('%',#{parentContractCodeLike},'%')
        </if>
        <!-- 新增字段的数量查询条件 -->
        <if test="propertyCompany !=null and propertyCompany != ''">
            and t.property_company like concat('%',#{propertyCompany},'%')
        </if>
        <if test="contractTerm !=null and contractTerm != ''">
            and t.contract_term= #{contractTerm}
        </if>
        <if test="isArchived !=null and isArchived != ''">
            and t.is_archived= #{isArchived}
        </if>
        <if test="contractReminderDate !=null and contractReminderDate != ''">
            and t.contract_reminder_date= #{contractReminderDate}
        </if>
    </select>
 
    <select id="queryContractsByOwnerIds" parameterType="Map" resultType="Map">
        select t.obj_id ownerId,count(t.contract_id) contractCount
        from contract t
        where t.status_cd = '0'
 
        <if test="communityId != null and communityId != ''">
            and t.community_id = #{communityId}
        </if>
        and t.obj_id in
        <foreach collection="ownerIds" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
        group by t.obj_id
    </select>
</mapper>