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
478
479
480
481
482
package com.by4cloud.platformx.business.controller;
 
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.by4cloud.platformx.business.dto.*;
import com.by4cloud.platformx.business.entity.Contract;
import com.by4cloud.platformx.business.entity.PaymentConfirm;
import com.by4cloud.platformx.common.core.util.R;
import com.by4cloud.platformx.common.data.mybatis.BaseModel;
import com.by4cloud.platformx.common.log.annotation.SysLog;
import com.by4cloud.platformx.business.service.ContractService;
import com.by4cloud.platformx.common.security.annotation.Inner;
import com.by4cloud.platformx.common.security.util.SecurityUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import com.by4cloud.platformx.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
 
/**
 * 合同管理
 *
 * @author platformx
 * @date 2026-04-29 16:46:26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/contract" )
@Tag(description = "contract" , name = "合同管理管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ContractController {
 
    private final  ContractService contractService;
 
    /**
     * 分页查询
     * @param page 分页对象
     * @param queryDTO 合同管理
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('business_contract_view')" )
    public R getContractPage(@ParameterObject Page page, @ParameterObject ContracQueryDTO queryDTO) {
        LambdaQueryWrapper<Contract> wrapper = Wrappers.lambdaQuery();
//        wrapper.like(StringUtils.isNotBlank(contract.getContractName()),Contract::getContractName,contract.getContractName());
//        wrapper.like(StringUtils.isNotBlank(contract.getPartyA()),Contract::getPartyA,contract.getPartyA());
//        wrapper.eq(ObjUtil.isNotNull(contract.getContractStatus()),Contract::getContractStatus,contract.getContractStatus());
//        wrapper.orderByDesc(Contract::getCreateTime);
        return R.ok(contractService.pageScope(page, queryDTO));
    }
 
 
    /**
     * 通过id查询合同管理
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('business_contract_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(contractService.detail(id));
    }
 
    /**
     * 手动推送合同中心
     * @param dto
     * @return R
     */
    @Operation(summary = "手动推送合同中心" , description = "手动推送合同中心" )
    @PostMapping("/pushCenter" )
    public R pushCenter(@RequestBody PushCenterDTO dto) {
        return contractService.pushCenter(dto);
    }
 
 
    /**
     * 新增合同管理
     * @param addDTO 合同管理
     * @return R
     */
    @Operation(summary = "新增合同管理" , description = "新增合同管理" )
    @SysLog("新增合同管理" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('business_contract_add')" )
    public R save(@RequestBody ContractAddDTO addDTO) {
        return contractService.add(addDTO);
    }
 
    /**
     * 新增简易合同
     * @param addDTO 合同管理
     * @return R
     */
    @Operation(summary = "新增简易合同" , description = "新增简易合同" )
    @SysLog("新增简易合同" )
    @PostMapping("/addSimple")
    public R addSimple(@RequestBody ContractAddDTO addDTO) {
        return contractService.addSimple(addDTO);
    }
 
    /**
     * 修改合同管理
     * @param updateDTO 合同管理
     * @return R
     */
    @Operation(summary = "修改合同管理" , description = "修改合同管理" )
    @SysLog("修改合同管理" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('business_contract_edit')" )
    public R updateById(@RequestBody ContractUpdateDTO updateDTO) {
        return contractService.edit(updateDTO);
    }
 
    /**
     * 通过id删除合同管理
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除合同管理" , description = "通过id删除合同管理" )
    @SysLog("通过id删除合同管理" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('business_contract_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(contractService.removeBatchByIds(CollUtil.toList(ids)));
    }
 
 
    /**
     * 导出excel 表格
     * @param contract 查询条件
        * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('business_contract_export')" )
    public List<Contract> export(Contract contract,Long[] ids) {
        return contractService.list(Wrappers.lambdaQuery(contract).in(ArrayUtil.isNotEmpty(ids), Contract::getId, ids));
    }
 
    /**
     * list 下拉
     */
    @GetMapping("/list")
    public R list(@ParameterObject Contract contract) {
        return R.ok(contractService.listByScope(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractStatus,2)
                .eq(ObjUtil.isNotNull(contract.getPartyAId()),Contract::getPartyAId,contract.getPartyAId())
                .orderByDesc(Contract::getCreateTime)));
    }
 
    @GetMapping("/listAssoci")
    public R listAssoci(@ParameterObject Contract contract) {
        return R.ok(contractService.listByScope(Wrappers.<Contract>lambdaQuery().eq(Contract::getContractStatus,2)
                .and(wrapper -> wrapper
                        .eq(ObjUtil.isNotNull(contract.getPartyAId()),Contract::getPartyAId,contract.getPartyAId())
                        .or()
                        .eq(ObjUtil.isNotNull(contract.getPartyAId()),Contract::getPartyCId,contract.getPartyAId())
                )
                .orderByDesc(Contract::getCreateTime)));
    }
 
    /**
     * 启动审核流程
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id启动审核流程" , description = "通过id合同生效" )
    @GetMapping("/startApproval/{id}" )
    public R startApproval(@PathVariable("id" ) Long id) {
        return contractService.startApproval(id);
    }
 
 
    /**
     * 定时生成应收逾期
     * @return R
     */
    @GetMapping("/genCurrentOverdue" )
    @Inner(value = false)
    public R genCurrentOverdue() {
        return contractService.genCurrentOverdue();
    }
 
    /**
     * 定时生成周期性应收
     * @return R
     */
    @GetMapping("/genCycleReceiced" )
    @Inner(value = false)
    public R genCycleReceiced() {
        return contractService.genCycleReceiced();
    }
 
    /**
     * 生成新合同
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id生成新合同" , description = "通过id生成新合同" )
    @GetMapping("/copyNewContract/{id}" )
    public R copyNewContract(@PathVariable("id" ) Long id) {
        return contractService.copyNewContract(id);
    }
 
    /**
     * 根据客商查询合同
     * @param busId id
     * @return R
     */
    @Operation(summary = "根据客商查询合同" , description = "根据客商查询合同" )
    @GetMapping("/listByBusId/{busId}" )
    public R listByBusId(@PathVariable("busId" ) Long busId) {
        return R.ok(contractService.listByScope(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId,busId)
                .eq(Contract::getPartyBId,SecurityUtils.getUser().getCompId())
                .gt(Contract::getBillingAmout,new BigDecimal("0"))
                .apply("paid_amount < billing_amout")));
    }
 
    /**
     * 根据模版生成word一煤机加工承揽合同
     * @param id id
     * @return R
     */
    @Operation(summary = "根据模版生成word合同" , description = "根据模版生成word合同" )
    @GetMapping("/exportContractYMJJGCLWord/{id}" )
    public void exportContractYMJJGCLWord(@PathVariable("id" ) Long id, HttpServletResponse response) {
        contractService.exportContractYMJJGCLWord(id,response);
    }
 
    /**
     * 根据模版生成word一煤机工业品买卖合同
     * @param id id
     * @return R
     */
    @Operation(summary = "根据模版生成word合同" , description = "根据模版生成word合同" )
    @GetMapping("/exportContractYMJGYPMMWord/{id}" )
    public void exportContractYMJGYPMMWord(@PathVariable("id" ) Long id, HttpServletResponse response) {
        contractService.exportContractYMJGYPMMWord(id,response);
    }
 
    /**
     * 根据模版生成word一煤机工矿产品买卖合同
     * @param id id
     * @return R
     */
    @Operation(summary = "根据模版生成word合同" , description = "根据模版生成word合同" )
    @GetMapping("/exportContractYMJGKCPMMWord/{id}" )
    public void exportContractYMJGKCPMMWord(@PathVariable("id" ) Long id, HttpServletResponse response) {
        contractService.exportContractYMJGKCPMMWord(id,response);
    }
 
    /**
     * 根据模版生成word一煤机采购合同
     * @param id id
     * @return R
     */
    @Operation(summary = "根据模版生成word合同" , description = "根据模版生成word合同" )
    @GetMapping("/exportContractYMJCGWord/{id}" )
    public void exportContractYMJCGWord(@PathVariable("id" ) Long id, HttpServletResponse response) {
        contractService.exportContractYMJCGWord(id,response);
    }
 
    /**
     * 根据模版生成word通方公司工业品买卖合同
     * @param id id
     * @return R
     */
    @Operation(summary = "根据模版生成word合同" , description = "根据模版生成word合同" )
    @GetMapping("/exportContractTFGSGYPMMWord/{id}" )
    public void exportContractTFGSGYPMMWord(@PathVariable("id" ) Long id, HttpServletResponse response) {
        contractService.exportContractTFGSGYPMMWord(id,response);
    }
 
    /**
     * 根据模版生成word石煤机工业品买卖合同
     * @param id id
     * @return R
     */
    @Operation(summary = "根据模版生成word合同" , description = "根据模版生成word合同" )
    @GetMapping("/exportContractSMJGYPMMWord/{id}" )
    public void exportContractSMJGYPMMWord(@PathVariable("id" ) Long id, HttpServletResponse response) {
        contractService.exportContractSMJGYPMMWord(id,response);
    }
 
    /**
     * 根据模版生成word机械厂销售合同
     * @param id id
     * @return R
     */
    @Operation(summary = "根据模版生成word机械厂销售合同" , description = "根据模版生成word机械厂销售合同" )
    @GetMapping("/exportContractJXCXSWord/{id}" )
    public void exportContractJXCXSWord(@PathVariable("id" ) Long id, HttpServletResponse response) {
        contractService.exportContractJXCXSWord(id,response);
    }
 
 
 
    /**
     * 延期出货审批
     */
 
    @PostMapping("/delayOutApproval")
    public R delayOutApproval(@RequestBody DelayOutApprovalDTO dto) {
        return contractService.delayOutApproval(dto);
    }
 
    /**
     * 新增合同-石工泵
     * @return R
     */
    @Operation(summary = "新增历史合同-石工泵" , description = "新增历史合同-石工泵" )
    @PostMapping("/addContractSgbHis")
    @SysLog("新增历史合同-石工泵" )
    public R addContractSgbHis(@RequestBody ContractAddDTO addDTO) {
        return contractService.addContractSgbHis(addDTO);
    }
 
    /**
     * 新增合同-石工泵
     * @return R
     */
    @Operation(summary = "新增合同-石工泵" , description = "新增合同-石工泵" )
    @PostMapping("/addContractSgb")
    @SysLog("新增合同-石工泵" )
    public R addContractSgb(@RequestBody ContractAddDTO addDTO) {
        return contractService.addContractSgb(addDTO);
    }
 
    /**
     * 修改合同-石工泵
     * @return R
     */
    @Operation(summary = "修改合同-石工泵" , description = "修改合同-石工泵" )
    @PostMapping("/updateContractSgb")
    @SysLog("修改合同-石工泵" )
    public R updateContractSgb(@RequestBody ContractUpdateDTO updateDTO) {
        return contractService.updateContractSgb(updateDTO);
    }
 
    /**
     * 终止合同-石工泵
     * @return R
     */
    @Operation(summary = "终止合同-石工泵" , description = "终止合同-石工泵" )
    @GetMapping("/abortContractSgb/{dataId}")
    @SysLog("终止合同-石工泵" )
    public R abortContractSgb(@PathVariable String dataId) {
        return contractService.abortContractSgb(dataId);
    }
 
    /**
     * 删除合同-石工泵
     * @return R
     */
    @Operation(summary = "删除合同-石工泵" , description = "删除合同-石工泵" )
    @GetMapping("/delContractSgb/{dataId}")
    @SysLog("删除合同-石工泵" )
    public R delContractSgb(@PathVariable String dataId) {
        return contractService.delContractSgb(dataId);
    }
 
    /**
     * 四关联查询
     * @return R
     */
    @Operation(summary = "四关联查询" , description = "四关联查询" )
    @GetMapping("/fourAssociation")
    public R fourAssociation(@ParameterObject Page page,@ParameterObject ContractQueryDTO queryDTO) {
        return R.ok(contractService.fourAssociation(page,queryDTO));
    }
 
    @PostMapping("/importContractMultiSheet")
    public R importContractMultiSheet(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return R.failed("文件不能为空");
        }
        return contractService.importContractMultiSheet(file);
    }
 
    /**
     * 合同标的物变更
     * @param changeDTO 合同管理
     * @return R
     */
    @Operation(summary = "合同标的物变更" , description = "合同标的物变更" )
    @SysLog("合同标的物变更" )
    @PostMapping("/subjectChange")
    @PreAuthorize("@pms.hasPermission('business_contract_subchange')" )
    public R subjectChange(@RequestBody ContractSubjectChangeDTO changeDTO) {
        return contractService.subjectChange(changeDTO);
    }
 
    /**
     * 合同标的物变更分页
     * @param queryDTO 合同管理
     * @return R
     */
    @Operation(summary = "合同标的物变更分页" , description = "合同标的物变更分页" )
    @SysLog("合同标的物变更分页" )
    @GetMapping("/subjectChangePage")
    public R subjectChangePage(@ParameterObject Page page, @ParameterObject ContracQueryDTO queryDTO) {
        return R.ok(contractService.subjectChangePage(page,queryDTO));
    }
 
    /**
     * 合同标的物变更附件
     * @param attDTO 合同管理
     * @return R
     */
    @Operation(summary = "合同标的物变更附件" , description = "合同标的物变更附件" )
    @SysLog("合同标的物变更附件" )
    @PostMapping("/subjectChangeAtt")
    public R subjectChangeAtt(@RequestBody ContractSubjectChangeAttDTO attDTO) {
        return contractService.subjectChangeAtt(attDTO);
    }
 
    /**
     * 合同标的物变更附件
     * @param dto 合同管理
     * @return R
     */
    @Inner(value = false)
    @SysLog("合同审批结果同步" )
    @PostMapping("/syncContractStatus")
    public R syncContractStatus(@RequestBody SyncContractStatusDTO dto) {
        return contractService.syncContractStatus(dto);
    }
 
    @PostMapping("/finallyPdf")
    public R finallyPdf(@RequestBody ContractFinallyDTO attDTO) {
        return contractService.finallyPdf(attDTO);
    }
 
    @PostMapping("/associationPartyC")
    public R associationPartyC(@RequestBody ContractAssociationPartyCyDTO associationPartyCyDTO) {
        return contractService.associationPartyC(associationPartyCyDTO);
    }
 
    @GetMapping("/getFinallyInfo/{id}")
    public R getFinallyInfo(@PathVariable("id") Long id) {
        return contractService.getFinallyInfo(id);
    }
 
    @Inner(value = false)
    @GetMapping("/erpPush/{id}")
    public R erpPush(@PathVariable("id") Long id) {
        return contractService.erpPush(id);
    }
 
    @GetMapping("/getInvoiceObj/{id}")
    public R getInvoiceObj(@PathVariable("id") Long id) {
        return contractService.getInvoiceObj(id);
    }
 
    /**
     * 新增合同-石工泵
     * @return R
     */
    @Operation(summary = "新增历史合同" , description = "新增历史合同" )
    @PostMapping("/addContractHis")
    @SysLog("新增历史合同" )
    public R addContractHis(@RequestBody ContractAddDTO addDTO) {
        return contractService.addContractHis(addDTO);
    }
}