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.supplier.BpmOASupplierProductPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.supplier.BpmOASupplierProductRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.supplier.BpmOASupplierProductSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASupplierProductDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOaSupplierProductService;
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 = "管理后台 - OA供应商商品")
@RestController
@RequestMapping("/bpm/oa-supplier-product")
@Validated
public class BpmOaSupplierProductController {

    @Resource
    private BpmOaSupplierProductService oaSupplierProductService;

    @PostMapping("/create")
    @Operation(summary = "创建OA供应商商品")
    public CommonResult<Long> createOaSupplierProduct(@Valid @RequestBody BpmOASupplierProductSaveReqVO createReqVO) {
        return success(oaSupplierProductService.createOaSupplierProduct(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新OA供应商商品")
    public CommonResult<Boolean> updateOaSupplierProduct(@Valid @RequestBody BpmOASupplierProductSaveReqVO updateReqVO) {
        oaSupplierProductService.updateOaSupplierProduct(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除OA供应商商品")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteOaSupplierProduct(@RequestParam("id") Long id) {
        oaSupplierProductService.deleteOaSupplierProduct(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得OA供应商商品")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BpmOASupplierProductRespVO> getOaSupplierProduct(@RequestParam("id") Long id) {
        BpmOASupplierProductDO oaSupplierProduct = oaSupplierProductService.getOaSupplierProduct(id);
        return success(BeanUtils.toBean(oaSupplierProduct, BpmOASupplierProductRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得OA供应商商品分页")
    public CommonResult<PageResult<BpmOASupplierProductRespVO>> getOaSupplierProductPage(@Valid BpmOASupplierProductPageReqVO pageReqVO) {
        PageResult<BpmOASupplierProductDO> pageResult = oaSupplierProductService.getOaSupplierProductPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, BpmOASupplierProductRespVO.class));
    }

}
