package com.hz.pm.api.performance.controller;

import com.hz.pm.api.common.util.ExcelDownUtil;
import com.hz.pm.api.performance.manage.ReAppraisalManage;
import com.hz.pm.api.performance.model.dto.ProjectAppraisalDTO;
import com.hz.pm.api.performance.model.req.PerformanceAppraisalExportReq;
import com.hz.pm.api.performance.model.req.PerformanceAppraisalListReq;
import com.hz.pm.api.performance.model.vo.PerformanceAppraisalProjectVO;
import com.hz.pm.api.performance.model.vo.PerformanceAppraisalVO;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * ReAppraisalController
 *
 * @author CMM
 * @return
 * @since 2023/08/10 8:54
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "绩效评价-人工复评")
@RequestMapping("/api/v1/re-appraisal")
public class ReAppraisalController {

    private final ReAppraisalManage reAppraisalManage;

    @GetMapping("/list")
    @ApiOperation("当前复评用户的绩效评价计划列表")
    public PageVo<PerformanceAppraisalVO> list(PerformanceAppraisalListReq req) {
        return reAppraisalManage.list(req);
    }

    @GetMapping("/group-project-list/{groupId}")
    @ApiOperation("当前复评用户所在分组复评项目列表")
    public PageVo<PerformanceAppraisalProjectVO> groupProjectList(@PathVariable Long groupId, PerformanceAppraisalListReq req) {
        return reAppraisalManage.groupProjectList(groupId, req);
    }

    @PostMapping("/submit-reAppraisal")
    @ApiOperation("提交复评")
    @WebLog(value = "提交复评", modular = "绩效评价-人工复评")
    public String submitReAppraisal(@Valid @RequestBody ProjectAppraisalDTO param) {
        return reAppraisalManage.submitReAppraisal(param);
    }

    @GetMapping("/score/export")
    @ApiOperation("复评打分导出")
    @WebLog(value = "复评打分导出", modular = "绩效评价-人工复评")
    public void exportScore(@Valid @ModelAttribute PerformanceAppraisalExportReq param, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, param, reAppraisalManage::exportScore);
    }

}
