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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.salesperformanceweight.vo.SalesPerformanceWeightRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.salesperformanceweight.vo.SalesPerformanceWeightSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.salesperformanceweight.SalesPerformanceWeightDO;
import cn.iocoder.yudao.module.crm.service.salesperformanceweight.SalesPerformanceWeightService;
import io.swagger.v3.oas.annotations.Operation;
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("/crm/sales-performance-weight")
@Validated
public class SalesPerformanceWeightController {

    @Resource
    private SalesPerformanceWeightService salesPerformanceWeightService;

    @PutMapping("/saveOrEdit")
    @Operation(summary = "新增/修改销售业绩权重设置")
    public CommonResult<Boolean> saveOrEdit(@Valid @RequestBody SalesPerformanceWeightSaveReqVO updateReqVO) {
        salesPerformanceWeightService.saveOrEdit(updateReqVO);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得销售业绩权重设置")
    public CommonResult<SalesPerformanceWeightRespVO> getSalesPerformanceWeight() {
        SalesPerformanceWeightDO salesPerformanceWeight = salesPerformanceWeightService.getSalesPerformanceWeight();
        return success(BeanUtils.toBean(salesPerformanceWeight, SalesPerformanceWeightRespVO.class));
    }
}
