package com.lz.modules.performance.controller;

import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.common.utils.StringUtil;
import com.lz.modules.equipment.entity.model.BasePage;
import com.lz.modules.flow.dao.FlowStartMapper;
import com.lz.modules.flow.entity.FlowStart;
import com.lz.modules.flow.service.FlowStartService;
import com.lz.modules.performance.req.ChartStartsReq;
import com.lz.modules.performance.res.ChartStartsRes;
import com.lz.modules.performance.res.ChartStatisticalRes;
import com.lz.modules.performance.res.ResultRankListRes;
import com.lz.modules.performance.service.ChartResultService;
import com.lz.modules.sys.controller.AbstractController;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @Author: djc
 * @Desc:
 * @Date: 2020/10/15 9:33
 */
@RestController
@RequestMapping("/performance")
@Api(value="报表接口", tags={"绩效报表"})
public class ChartController extends AbstractController{
    @Autowired
    private ChartResultService chartResultService;
    @Autowired
    private FlowStartMapper flowStartMapper;

    @GetMapping("chart/result")
    @ApiOperation("获取绩效报表统计")
    @ApiResponses({@ApiResponse(code = 200,message = "成功",response = ChartStatisticalRes.class)})
    public R chartResult(@RequestParam(required = false) @ApiParam(name = "startId",value = "考核周期标识id") Long startId){
        String defaultTime = StringUtil.EMPTY;
        if(startId==null){
            //取最近一条记录
            FlowStart flowStart = flowStartMapper.selectRecentlyLimt();
            if(flowStart!=null){
                startId = flowStart.getId();
                defaultTime = flowStart.getName();
            }else {
                return R.ok("暂无记录");
            }
        }
        List<ChartStatisticalRes> chartStatisticalRes = chartResultService.chartReport(startId,defaultTime);
        return R.ok().put("data",chartStatisticalRes);
    }


    @PostMapping("chart/starts")
    @ApiOperation("获取考核类型列表")
    @ApiResponses({@ApiResponse(code = 200,message = "成功",response = ChartStartsRes.class)})
    public R chartStarts(@RequestBody @ApiParam(name = "body",value = "body请求体",required = true)ChartStartsReq req){
        PageUtils pageUtils = chartResultService.chartStarts(req);
        return R.ok().put("data",pageUtils);
    }


    /*@PostMapping("chart/rank")
    @ApiOperation("获取绩排名列表")
    @ApiResponses({@ApiResponse(code = 200,message = "成功",response = ResultRankListRes.class)})
    public R rankList(@RequestBody @ApiParam(name = "body",value = "body请求体",required = true) ChartResultReq req){
        PageUtils pageUtils = chartResultService.resultRankList(req);
        return R.ok().put("data",pageUtils);
    }*/




}
