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 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 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("请填写金额"); } } }