package cn.com.oa.service.impl;

import cn.com.oa.common.constant.DataService;
import cn.com.oa.mapper.FlowInstanceMapper;
import cn.com.oa.model.FlowInstance;
import cn.com.oa.model.Group;
import cn.com.oa.model.vo.FlowInstanceVo;
import cn.com.oa.service.IFlowInstanceService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 *  服务实现类
 * </p>
 */
@Service
public class FlowInstancelServiceImpl extends ServiceImpl<FlowInstanceMapper, FlowInstance> implements IFlowInstanceService {

    @Override
    public Map<String, Object> getSevenDayFlowIns() {
        Map constantData = DataService.getConstantData();
        Group group = (Group)constantData.get("defaultGroup");
        FlowInstanceVo flowInstance = new FlowInstanceVo();
        flowInstance.setDept(group.getUNIVERSALID().toString());
        List<Map<String,Object>> createList = baseMapper.getSevenDayFlowInsCreateCount(flowInstance);
        List<Map<String,Object>> finishList = baseMapper.getSevenDayFlowInsFinishCount(flowInstance);
        Map<String, Object> map = new HashMap<>();
        map.put("createList",createList);
        map.put("finishList",finishList);
        return map;
    }

    @Override
    public IPage<FlowInstanceVo> pageAllDealing(Page<FlowInstanceVo> page) {
        Map constantData = DataService.getConstantData();
        Group group = (Group)constantData.get("defaultGroup");
        FlowInstanceVo flowInstance = new FlowInstanceVo();
        flowInstance.setDept(group.getUNIVERSALID().toString());
        return baseMapper.selectPageAllDealing(page,flowInstance);
    }

    @Override
    public List<Map<String, Object>> getMaxUseFlows() {
        Map constantData = DataService.getConstantData();
        Group group = (Group)constantData.get("defaultGroup");
        FlowInstanceVo flowInstance = new FlowInstanceVo();
        flowInstance.setDept(group.getUNIVERSALID().toString());
        List<Map<String,Object>> flowList = baseMapper.getMaxUseFlows(flowInstance);
        return flowList;
    }

    @Override
    public Integer getTotalFlowInsCount() {
        Map constantData = DataService.getConstantData();
        Group group = (Group)constantData.get("defaultGroup");
        FlowInstanceVo flowInstance = new FlowInstanceVo();
        flowInstance.setDept(group.getUNIVERSALID().toString());
        Integer totalFlowInsCount = baseMapper.getTotalFlowInsCount(flowInstance);
        return totalFlowInsCount;
    }

    @Override
    public List<FlowInstanceVo> listAllDealing() {
        Map constantData = DataService.getConstantData();
        Group group = (Group)constantData.get("defaultGroup");
        FlowInstanceVo flowInstance = new FlowInstanceVo();
        flowInstance.setDept(group.getUNIVERSALID().toString());
        return baseMapper.listAllDealing(flowInstance);
    }

    @Override
    public List<FlowInstanceVo> getSevenDayFlowInfoIns() {
        return baseMapper.getSevenDayFlowInfoIns();
    }

}
