package cn.iocoder.yudao.module.bpm.controller.admin.oa;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.supplierpurchasepayment.BpmOASupplierPurchasePaymentPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.supplierpurchasepayment.BpmOASupplierPurchasePaymentRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.supplierpurchasepayment.BpmOASupplierPurchasePaymentSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASupplierPurchasePaymentDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOASupplierPurchasePaymentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 供应商采购付款")
@RestController
@RequestMapping("/bpm/OA-supplier-purchase-payment")
@Validated
public class BpmOASupplierPurchasePaymentController {

    @Resource
    private BpmOASupplierPurchasePaymentService oASupplierPurchasePaymentServiceBpm;

    @PostMapping("/create")
    @Operation(summary = "创建供应商采购付款")
    public CommonResult<Long> createOASupplierPurchasePayment(@Valid @RequestBody BpmOASupplierPurchasePaymentSaveReqVO createReqVO) {
        return success(oASupplierPurchasePaymentServiceBpm.createOASupplierPurchasePayment(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新供应商采购付款")
    public CommonResult<Boolean> updateOASupplierPurchasePayment(@Valid @RequestBody BpmOASupplierPurchasePaymentSaveReqVO updateReqVO) {
        oASupplierPurchasePaymentServiceBpm.updateOASupplierPurchasePayment(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除供应商采购付款")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteOASupplierPurchasePayment(@RequestParam("id") Long id) {
        oASupplierPurchasePaymentServiceBpm.deleteOASupplierPurchasePayment(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得供应商采购付款")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BpmOASupplierPurchasePaymentRespVO> getOASupplierPurchasePayment(@RequestParam("id") Long id) {
        BpmOASupplierPurchasePaymentDO oASupplierPurchasePayment = oASupplierPurchasePaymentServiceBpm.getOASupplierPurchasePayment(id);
        return success(BeanUtils.toBean(oASupplierPurchasePayment, BpmOASupplierPurchasePaymentRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得供应商采购付款分页")
    public CommonResult<PageResult<BpmOASupplierPurchasePaymentRespVO>> getOASupplierPurchasePaymentPage(@Valid BpmOASupplierPurchasePaymentPageReqVO pageReqVO) {
        PageResult<BpmOASupplierPurchasePaymentDO> pageResult = oASupplierPurchasePaymentServiceBpm.getOASupplierPurchasePaymentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, BpmOASupplierPurchasePaymentRespVO.class));
    }

}
