package cn.iocoder.yudao.module.crm.controller.admin.salesperformanceassessment;

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.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
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.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.crm.controller.admin.salesperformanceassessment.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.salesperformanceassessment.SalesPerformanceAssessmentDO;
import cn.iocoder.yudao.module.crm.service.salesperformanceassessment.SalesPerformanceAssessmentService;

@Tag(name = "管理后台 - 绩效考核设置")
@RestController
@RequestMapping("/crm/sales-performance-assessment")
@Validated
public class SalesPerformanceAssessmentController {

    @Resource
    private SalesPerformanceAssessmentService salesPerformanceAssessmentService;

    @PostMapping("/create")
    @Operation(summary = "创建绩效考核设置")
    public CommonResult<Long> createSalesPerformanceAssessment(@Valid @RequestBody SalesPerformanceAssessmentSaveReqVO createReqVO) {
        return success(salesPerformanceAssessmentService.createSalesPerformanceAssessment(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新绩效考核设置")
    public CommonResult<Boolean> updateSalesPerformanceAssessment(@Valid @RequestBody SalesPerformanceAssessmentSaveReqVO updateReqVO) {
        salesPerformanceAssessmentService.updateSalesPerformanceAssessment(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除绩效考核设置")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteSalesPerformanceAssessment(@RequestParam("id") Long id) {
        salesPerformanceAssessmentService.deleteSalesPerformanceAssessment(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得绩效考核设置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<SalesPerformanceAssessmentRespVO> getSalesPerformanceAssessment(@RequestParam("id") Long id) {
        SalesPerformanceAssessmentDO salesPerformanceAssessment = salesPerformanceAssessmentService.getSalesPerformanceAssessment(id);
        return success(BeanUtils.toBean(salesPerformanceAssessment, SalesPerformanceAssessmentRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得绩效考核设置分页")
    public CommonResult<PageResult<SalesPerformanceAssessmentRespVO>> getSalesPerformanceAssessmentPage(@Valid SalesPerformanceAssessmentPageReqVO pageReqVO) {
        PageResult<SalesPerformanceAssessmentDO> pageResult = salesPerformanceAssessmentService.getSalesPerformanceAssessmentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, SalesPerformanceAssessmentRespVO.class));
    }
}
