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

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.hz.pm.api.common.util.ExcelDownUtil;
import com.hz.pm.api.performance.manage.OrgSelfAppraisalManage;
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.hz.pm.api.performance.model.vo.ProjectAppraisalIndexDetailVO;
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;

/**
 * @Classname OrgSelfAppraisalController
 * @Description
 * @Date 2023/6/25 14:16
 * @Author PoffyZhang
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "绩效评价-单位自评")
@RequestMapping("/api/v1/self-appraisal")
public class OrgSelfAppraisalController {

    private final OrgSelfAppraisalManage selfAppraisalManage;

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

    @GetMapping("/pending-list/{planId}")
    @ApiOperation("当前绩效评价待自评列表")
    public PageVo<PerformanceAppraisalProjectVO> pendingList(@PathVariable Long planId, PerformanceAppraisalListReq req) {
        return selfAppraisalManage.pendingList(planId,req);
    }

    @GetMapping("/appraisaled-list/{planId}")
    @ApiOperation("当前绩效评价已自评列表")
    public PageVo<PerformanceAppraisalProjectVO> appraisaledList(@PathVariable Long planId,PerformanceAppraisalListReq req) {
        return selfAppraisalManage.appraisaledList(planId,req);
    }

    @GetMapping("/get-appraisal-template-detail/{projectCode}")
    @ApiOperation("获取自评模版详情")
    public ProjectAppraisalIndexDetailVO getAppraisalTemplateDetail(@PathVariable String projectCode){
        return selfAppraisalManage.getAppraisalTemplateDetail(projectCode);
    }

    @PostMapping("/submit-self-appraisal")
    @ApiOperation("提交自评")
    @WebLog(value = "提交自评",modular = "绩效评价-单位自评")
    public String submitSelfAppraisal(@Valid @RequestBody ProjectAppraisalDTO param){
        return selfAppraisalManage.submitSelfAppraisal(param);
    }

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