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

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.financialpaymentitem.vo.FinancialPaymentItemPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.financialpaymentitem.vo.FinancialPaymentItemRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.financialpaymentitem.vo.FinancialPaymentItemSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.financialpaymentitem.FinancialPaymentItemDO;
import cn.iocoder.yudao.module.bpm.service.financialpaymentitem.FinancialPaymentItemService;
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/financial-payment-item")
@Validated
public class FinancialPaymentItemController {

    @Resource
    private FinancialPaymentItemService financialPaymentItemService;

    @PostMapping("/create")
    @Operation(summary = "创建财务支付子表")
    @PreAuthorize("@ss.hasPermission('bpm:financial-payment-item:create')")
    public CommonResult<Long> createFinancialPaymentItem(@Valid @RequestBody FinancialPaymentItemSaveReqVO createReqVO) {
        return success(financialPaymentItemService.createFinancialPaymentItem(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新财务支付子表")
    @PreAuthorize("@ss.hasPermission('bpm:financial-payment-item:update')")
    public CommonResult<Boolean> updateFinancialPaymentItem(@Valid @RequestBody FinancialPaymentItemSaveReqVO updateReqVO) {
        financialPaymentItemService.updateFinancialPaymentItem(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除财务支付子表")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('bpm:financial-payment-item:delete')")
    public CommonResult<Boolean> deleteFinancialPaymentItem(@RequestParam("id") Long id) {
        financialPaymentItemService.deleteFinancialPaymentItem(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得财务支付子表")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('bpm:financial-payment-item:query')")
    public CommonResult<FinancialPaymentItemRespVO> getFinancialPaymentItem(@RequestParam("id") Long id) {
        FinancialPaymentItemDO financialPaymentItem = financialPaymentItemService.getFinancialPaymentItem(id);
        return success(BeanUtils.toBean(financialPaymentItem, FinancialPaymentItemRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得财务支付子表分页")
    @PreAuthorize("@ss.hasPermission('bpm:financial-payment-item:query')")
    public CommonResult<PageResult<FinancialPaymentItemRespVO>> getFinancialPaymentItemPage(@Valid FinancialPaymentItemPageReqVO pageReqVO) {
        PageResult<FinancialPaymentItemDO> pageResult = financialPaymentItemService.getFinancialPaymentItemPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, FinancialPaymentItemRespVO.class));
    }

}
