package com.chushang.inspection.project.controller;

import com.chushang.common.core.validator.Create;
import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.log.annotation.SysLog;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.common.mybatis.page.CommonParam;
import com.chushang.inspection.project.dto.PaymentDTO;
import com.chushang.inspection.project.service.WrkProjectPaymentService;
import com.chushang.security.annotation.RequiresPermissions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 回款
 * @auther: zhao
 * @date: 2024/6/15 11:22
 */
@Slf4j
@RestController
@RequestMapping(value = "/project/payment")
public class WrkProjectPaymentController {

    @Resource
    WrkProjectPaymentService paymentService;

    @SysLog(value = "回款", businessType = BusinessType.INSERT)
    @PostMapping(value = "/save")
    @RequiresPermissions("project:payment:save")
    public AjaxResult save(@RequestBody @Validated(Create.class)PaymentDTO payment){
        return AjaxResult.success(paymentService.save(payment));
    }

    @GetMapping(value = "/list")
    @RequiresPermissions("project:payment:list")
    public AjaxResult list(PaymentDTO payment)
    {
        CommonParam commonParam = CommonParam.buildPageRequest();
        return AjaxResult.success(paymentService.pageList(payment.getProjectId(), payment.getContractId(),commonParam));
    }
    @SysLog(value = "合同回款", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/{paymentId}")
    @RequiresPermissions("project:payment:del")
    public AjaxResult del(@PathVariable Long paymentId){
        paymentService.removeById(paymentId);
        return AjaxResult.success();
    }


}
