package cn.com.oa.controller;

import cn.com.oa.model.vo.FlowInstanceVo;
import cn.com.oa.service.IFlowInstanceService;
import cn.com.v2.common.base.BaseController;
import cn.com.v2.common.domain.AjaxResult;
import cn.com.v2.common.domain.ResultTable;
import cn.com.v2.common.domain.Tablepar;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/flowInstance")
public class FlowInstanceController extends BaseController {
    @Autowired
    private IFlowInstanceService flowInstanceService;

    @ApiOperation(value = "获取近七天流程详情统计数据", notes = "获取近七天流程详情统计数据")
    @GetMapping("/getSevenDayFlowInfoIns")
    @ResponseBody
    public AjaxResult getSevenDayFlowInfoIns()
    {
        List<FlowInstanceVo> flowInfoInsMap = flowInstanceService.getSevenDayFlowInfoIns();
        return AjaxResult.successData(200,flowInfoInsMap).put("msg","获取成功");
    }

    @ApiOperation(value = "获取近七天流程统计数据", notes = "获取近七天流程统计数据")
    @GetMapping("/getSevenDayFlowIns")
    @ResponseBody
    public AjaxResult getSevenDayFlowIns()
    {
        Map<String, Object> flowInsMap = flowInstanceService.getSevenDayFlowIns();
        //return flowInsMap;
        return AjaxResult.successData(200,flowInsMap).put("msg","获取成功");
    }

    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/pageAllDealing")
    @ResponseBody
    public ResultTable pageAllDealing(Tablepar tablepar){
        Page<FlowInstanceVo> page= new Page<FlowInstanceVo>(tablepar.getPage(), tablepar.getLimit());
        IPage<FlowInstanceVo> iPages=flowInstanceService.pageAllDealing(page);

        ResultTable resultTable=new ResultTable();
        resultTable.setData(iPages.getRecords());
        resultTable.setCode(200);
        resultTable.setCount(iPages.getTotal());
        resultTable.setMsg("获取成功");
        return resultTable;
    }

    @ApiOperation(value = "统计排名前五的流程数据", notes = "统计排名前五的流程数据")
    @GetMapping("/getMaxUseFlowIns")
    @ResponseBody
    public AjaxResult getMaxUseFlowIns()
    {
        List<Map<String, Object>> flowList = flowInstanceService.getMaxUseFlows();
        //return flowList;
        return AjaxResult.successData(200,flowList).put("msg","获取成功");
    }

    @ApiOperation(value = "获取总流程数", notes = "获取总流程数")
    @GetMapping("/getTotalFlowInsCount")
    @ResponseBody
    public AjaxResult getTotalFlowInsCount()
    {
        Integer totalFlowInsCount = flowInstanceService.getTotalFlowInsCount();
        //return totalFlowInsCount;
        return AjaxResult.successData(200,totalFlowInsCount).put("msg","获取成功");
    }

    @ApiOperation(value = "所有在办流程", notes = "所有在办流程")
    @GetMapping("/listAllDealing")
    @ResponseBody
    public AjaxResult listAllDealing(Tablepar tablepar){
        List<FlowInstanceVo> flowList = flowInstanceService.listAllDealing();
        return AjaxResult.successData(200,flowList).put("msg","获取成功");
    }
}
