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

import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.salesperformance.SalesPerformancePageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.salesperformance.SalesPerformanceRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.salesperformance.SalesPerformanceSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOASalesPerformanceDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOASalesPerformanceService;

@Tag(name = "管理后台 - 销售业绩目标申请OA")
@RestController
@RequestMapping("/bpm/sales-performance")
@Validated
public class SalesPerformanceController {

    @Resource
    private BpmOASalesPerformanceService bpmOASalesPerformanceService;

    @PostMapping("/create")
    @Operation(summary = "创建销售业绩目标申请OA")
    @PreAuthorize("@ss.hasPermission('bpm:sales-performance:create')")
    public CommonResult<Long> createSalesPerformance(@Valid @RequestBody SalesPerformanceSaveReqVO createReqVO) {
        return success(bpmOASalesPerformanceService.createSalesPerformance(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新销售业绩目标申请OA")
    @PreAuthorize("@ss.hasPermission('bpm:sales-performance:update')")
    public CommonResult<Boolean> updateSalesPerformance(@Valid @RequestBody SalesPerformanceSaveReqVO updateReqVO) {
        bpmOASalesPerformanceService.updateSalesPerformance(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除销售业绩目标申请OA")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('bpm:sales-performance:delete')")
    public CommonResult<Boolean> deleteSalesPerformance(@RequestParam("id") Long id) {
        bpmOASalesPerformanceService.deleteSalesPerformance(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得销售业绩目标申请OA")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('bpm:sales-performance:query')")
    public CommonResult<SalesPerformanceRespVO> getSalesPerformance(@RequestParam("id") Long id) {
        BpmOASalesPerformanceDO salesPerformance = bpmOASalesPerformanceService.getSalesPerformance(id);
        return success(BeanUtils.toBean(salesPerformance, SalesPerformanceRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得销售业绩目标申请OA分页")
    @PreAuthorize("@ss.hasPermission('bpm:sales-performance:query')")
    public CommonResult<PageResult<SalesPerformanceRespVO>> getSalesPerformancePage(@Valid SalesPerformancePageReqVO pageReqVO) {
        PageResult<BpmOASalesPerformanceDO> pageResult = bpmOASalesPerformanceService.getSalesPerformancePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, SalesPerformanceRespVO.class));
    }
}
