昨天 684e4306a08feeae188070f264148e6765da8dcf
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
package com.ruoyi.account.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.account.enums.PartyTypeEnum;
import com.ruoyi.account.pojo.PaymentRecord;
import com.ruoyi.account.service.PaymentRecordService;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * 客户/供应商往来付款回款流水
 *
 * @author :yys
 */
@RestController
@Tag(name = "往来付款回款")
@RequestMapping("/paymentRecord")
@AllArgsConstructor
public class PaymentRecordController extends BaseController {
 
    private PaymentRecordService paymentRecordService;
 
    @GetMapping("/listPage")
    @Log(title = "往来付款回款-分页查询", businessType = BusinessType.OTHER)
    public AjaxResult listPage(Page page, PaymentRecord paymentRecord) {
        IPage<PaymentRecord> listPage = paymentRecordService.listPage(page, paymentRecord);
        return AjaxResult.success(listPage);
    }
 
    @PostMapping("/add")
    @Log(title = "往来付款回款-新增", businessType = BusinessType.INSERT)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult add(@RequestBody PaymentRecord paymentRecord) {
        validate(paymentRecord);
        boolean save = paymentRecordService.save(paymentRecord);
        return save ? AjaxResult.success() : AjaxResult.error();
    }
 
    @PostMapping("/update")
    @Log(title = "往来付款回款-修改", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult update(@RequestBody PaymentRecord paymentRecord) {
        if (paymentRecord.getId() == null) {
            return AjaxResult.error("缺少主键id");
        }
        validate(paymentRecord);
        boolean update = paymentRecordService.updateById(paymentRecord);
        return update ? AjaxResult.success() : AjaxResult.error();
    }
 
    @DeleteMapping("/delete")
    @Log(title = "往来付款回款-删除", businessType = BusinessType.DELETE)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult delete(@RequestBody List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return AjaxResult.error("请选择至少一条数据");
        }
        boolean delete = paymentRecordService.removeBatchByIds(ids);
        return delete ? AjaxResult.success() : AjaxResult.error();
    }
 
    private void validate(PaymentRecord paymentRecord) {
        if (paymentRecord.getPartyType() == null || paymentRecord.getPartyId() == null) {
            throw new RuntimeException("请选择往来方");
        }
        if (PartyTypeEnum.getByCode(paymentRecord.getPartyType()) == null) {
            throw new RuntimeException("往来方类型不合法");
        }
        if (paymentRecord.getDirection() == null) {
            throw new RuntimeException("请选择方向(付款/回款)");
        }
        if (paymentRecord.getAmount() == null) {
            throw new RuntimeException("请填写金额");
        }
    }
}