package com.lz.modules.performance.controller;

import com.lz.common.utils.PageUtils;
import com.lz.common.utils.R;
import com.lz.modules.flow.dao.FlowStartMapper;
import com.lz.modules.flow.entity.FlowStart;
import com.lz.modules.performance.req.AssessListReq;
import com.lz.modules.performance.req.AssessDetailReq;
import com.lz.modules.performance.res.AssessManagerDetailRes;
import com.lz.modules.performance.res.AssessManagerListRes;
import com.lz.modules.performance.res.ChartStatistical;
import com.lz.modules.performance.res.ChartStatisticalRes;
import com.lz.modules.performance.service.AssessManagerService;
import com.lz.modules.performance.service.ChartResultService;
import com.lz.modules.sys.dao.app.ResultRecordMapper;
import com.lz.modules.sys.service.app.ResultRecordService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: djc
 * @Desc:
 * @Date: 2020/10/20 17:33
 */
@RestController
@RequestMapping("/performance")
@Api(value="考核管理接口", tags={"考核管理"})
public class AssessManagerController {

    @Autowired
    private FlowStartMapper flowStartMapper;
    @Autowired
    private AssessManagerService assessManagerService;
    @Autowired
    private ResultRecordMapper resultRecordMapper;
    @Autowired
    private ChartResultService chartResultService;


    @PostMapping("assess/manager/list")
    @ApiOperation("获取考核列表")
    @ApiResponses({@ApiResponse(code = 200,message = "成功",response = AssessManagerListRes.class)})
    public R assessList(@RequestBody AssessListReq req){
        PageUtils pageUtils = assessManagerService.assessList(req);
        return R.ok().put("data",pageUtils);
    }

    @PostMapping("assess/manager/detail")
    @ApiOperation("获取考核详情列表")
    @ApiResponses({@ApiResponse(code = 200,message = "成功",response = AssessManagerDetailRes.class)})
    public R assessDetail(@RequestBody AssessDetailReq req){
        if(req.getStartId()==null){
            return R.error("考核id不能为空");
        }
        PageUtils pageUtils = assessManagerService.assessDetail(req);
        return R.ok().put("data",pageUtils);

    }



    @PostMapping("assess/manager/chart")
    @ApiOperation("获取考核详情列表人数统计")
    @ApiResponses({@ApiResponse(code = 200,message = "成功",response = ChartStatistical.class)})
    public R assessChart(@RequestBody AssessDetailReq req){
        if(req.getStartId()==null){
            return R.error("考核id不能为空");
        }
        List<ChartStatistical> process = chartResultService.countAssessNumByFlowProcess(req);
        return R.ok().put("data",process);

    }



    @GetMapping("assess/manager/delete")
    @ApiOperation("删除考核任务")
    @ApiResponses({@ApiResponse(code = 200,message = "成功",response = ChartStatisticalRes.class)})
    @ApiImplicitParam(name = "assessId",value = "发起考核id", required = true, dataType = "Long",paramType = "query")
    public R assessDelete(@RequestParam Long assessId){
        FlowStart flowStart = flowStartMapper.selectFlowStartById(assessId);
        if(flowStart == null){
            return R.error("没有此条记录");
        }
        assessManagerService.accessDelete(flowStart);
        return R.ok();
    }
}
