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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.crmanalysis.vo.*;
import cn.iocoder.yudao.module.crm.service.crmanalysis.AchievementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 业绩分析")
@RestController
@RequestMapping("/crm/analysis-achievement")
@Validated
public class AchievementController {

    @Resource
    private AchievementService achievementService;



    @GetMapping("/depts")
    @Operation(summary = "获得部门业绩分析")
    public CommonResult<List<DeptAchieveVO>> getDeptsAchievement(@Valid AchievementPageReqVO pageReqVO) {
        List<DeptAchieveVO> deptAchieveRespVOS = achievementService.getDeptAchieve(pageReqVO);
        return success(deptAchieveRespVOS);
    }

    @GetMapping("/user")
    @Operation(summary = "获得员工业绩分析")
    public CommonResult<PageResult<UserAchieveVO>> getAchievementPage(@Valid AchievementPageReqVO pageReqVO) {
        return success(achievementService.getAchievementPage(pageReqVO));
    }

    @GetMapping("/completion")
    @Operation(summary = "获得业绩完成度")
    public CommonResult<List<CompletionVO>> getAchievementCompletion(@RequestParam(name = "relation",defaultValue = "my",required=false) String relation) {
        return success(achievementService.getCompletion(relation));
    }


    @GetMapping("/sales")
    @Operation(summary = "销售简报")
    public CommonResult<List<SalesVO>> getSales(@RequestParam(name = "relation",defaultValue = "my",required=false) String relation) {
        return success(achievementService.getSales(relation));
    }
}
