package org.springblade.flow.visual.portal.controller;

import java.util.List;

import org.springblade.flow.base.ActionResult;
import org.springblade.flow.base.vo.ListVO;
import org.springblade.flow.engine.service.FlowDelegateService;
import org.springblade.flow.engine.service.FlowTaskService;
import org.springblade.flow.extend.service.EmailReceiveService;
import org.springblade.flow.message.service.MessageService;
import org.springblade.flow.util.JsonUtil;
import org.springblade.flow.visual.portal.model.home.EmailVO;
import org.springblade.flow.visual.portal.model.home.FlowTodoCountVO;
import org.springblade.flow.visual.portal.model.home.FlowTodoVO;
import org.springblade.flow.visual.portal.model.home.MyFlowTodoVO;
import org.springblade.flow.visual.portal.model.home.NoticeVO;
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.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 主页控制器
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2019年9月27日 上午9:18
 */
@Api(tags = "主页控制器", value = "Home")
@RestController
@RequestMapping("api/visualdev/Dashboard")
public class DashboardController {
	@Autowired
	private FlowTaskService flowTaskService;

	@Autowired
	private FlowDelegateService flowDelegateService;

	@Autowired
	private MessageService messageService;

	@Autowired
	private EmailReceiveService emailReceiveService;

	/**
	 * 获取我的待办
	 *
	 * @return
	 */
	@ApiOperation("获取我的待办")
	@GetMapping("/FlowTodoCount")
	public ActionResult<FlowTodoCountVO> getFlowTodoCount() {
		FlowTodoCountVO vo = new FlowTodoCountVO();
		vo.setToBeReviewed(flowTaskService.getWaitList().size());
		vo.setEntrust(flowDelegateService.getList().size());
		vo.setFlowDone(flowTaskService.getTrialList().size());
		return ActionResult.success(vo);
	}

	/**
	 * 获取通知公告
	 *
	 * @return
	 */
	@ApiOperation("获取通知公告")
	@GetMapping("/Notice")
	public ActionResult<ListVO<NoticeVO>> getNotice() {
		List<NoticeVO> list = JsonUtil.getJsonToList(messageService.getNoticeList(), NoticeVO.class);

		ListVO<NoticeVO> voList = new ListVO<>();
		voList.setList(list);
		return ActionResult.success(voList);
	}

	/**
	 * 获取未读邮件
	 *
	 * @return
	 */
	@ApiOperation("获取未读邮件")
	@GetMapping("/Email")
	public ActionResult<ListVO<EmailVO>> getEmail() {
		List<EmailVO> list = JsonUtil.getJsonToList(emailReceiveService.getReceiveList(), EmailVO.class);
		ListVO<EmailVO> voList = new ListVO<>();
		voList.setList(list);
		return ActionResult.success(voList);
	}

	/**
	 * 获取待办事项
	 *
	 * @return
	 */
	@ApiOperation("获取待办事项")
	@GetMapping("/FlowTodo")
	public ActionResult<ListVO<FlowTodoVO>> getFlowTodo() {
		List<FlowTodoVO> list = JsonUtil.getJsonToList(flowTaskService.getAllWaitList(), FlowTodoVO.class);
		ListVO<FlowTodoVO> voList = new ListVO<>();
		voList.setList(list);
		return ActionResult.success(voList);
	}

	/**
	 * 获取我的待办事项
	 *
	 * @return
	 */
	@ApiOperation("获取我的待办事项")
	@GetMapping("/MyFlowTodo")
	public ActionResult<ListVO<MyFlowTodoVO>> getMyFlowTodo() {
		List<MyFlowTodoVO> list = JsonUtil.getJsonToList(flowTaskService.getWaitList(), MyFlowTodoVO.class);
		ListVO<MyFlowTodoVO> voList = new ListVO<>();
		voList.setList(list);
		return ActionResult.success(voList);
	}
}
