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.procurepay.BpmOAProcurePayItemPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procurepay.BpmOAProcurePayItemRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procurepay.BpmOAProcurePayItemSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAProcurePayItemDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAProcurePayItemService;
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-procure-pay-item")
@Validated
public class BpmOAProcurePayItemController {

    @Resource
    private BpmOAProcurePayItemService oAProcurePayItemService;

    @PostMapping("/create")
    @Operation(summary = "创建采购收款明细")
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay-item:create')")
    public CommonResult<Long> createOAProcurePayItem(@Valid @RequestBody BpmOAProcurePayItemSaveReqVO createReqVO) {
        return success(oAProcurePayItemService.createOAProcurePayItem(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新采购收款明细")
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay-item:update')")
    public CommonResult<Boolean> updateOAProcurePayItem(@Valid @RequestBody BpmOAProcurePayItemSaveReqVO updateReqVO) {
        oAProcurePayItemService.updateOAProcurePayItem(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除采购收款明细")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay-item:delete')")
    public CommonResult<Boolean> deleteOAProcurePayItem(@RequestParam("id") Long id) {
        oAProcurePayItemService.deleteOAProcurePayItem(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得采购收款明细")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay-item:query')")
    public CommonResult<BpmOAProcurePayItemRespVO> getOAProcurePayItem(@RequestParam("id") Long id) {
        BpmOAProcurePayItemDO oAProcurePayItem = oAProcurePayItemService.getOAProcurePayItem(id);
        return success(BeanUtils.toBean(oAProcurePayItem, BpmOAProcurePayItemRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得采购收款明细分页")
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay-item:query')")
    public CommonResult<PageResult<BpmOAProcurePayItemRespVO>> getOAProcurePayItemPage(@Valid BpmOAProcurePayItemPageReqVO pageReqVO) {
        PageResult<BpmOAProcurePayItemDO> pageResult = oAProcurePayItemService.getOAProcurePayItemPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, BpmOAProcurePayItemRespVO.class));
    }

}