package com.uas.platform.b2b.mobile.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.uas.platform.b2b.mobile.service.MobileFlowService;

/**
 * 审流刘节点
 * 
 * @author hejq
 * @time 创建时间：2017年3月17日
 */
@Controller("mobile.ApprovalFlowController")
@RequestMapping("/mobile/approvalflow")
public class MobileFlowController {

	@Autowired
	private MobileFlowService mobileFlowService;

	/**
	 * 获取待审批的接口
	 * 
	 * @param count
	 * @param page
	 * @param enuu
	 * @param emuu
	 * @return
	 */
	@RequestMapping(value = "/getAuditTodo", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getAuditTodo(Integer count, Integer page, Long enuu, Long emuu) {
		return mobileFlowService.getAuditTodo(count, page, enuu, emuu);
	}

	/**
	 * 获取已审批的接口
	 * 
	 * @param count
	 * @param page
	 * @param enuu
	 * @param emuu
	 * @return
	 */
	@RequestMapping(value = "/getAuditDone", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getAuditDone(Integer count, Integer page, Long enuu, Long emuu) {
		return mobileFlowService.getAuditDone(count, page, enuu, emuu);
	}
	
	/**
	 * 通过id获取审批节点和审批日志
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getNodesAndLog", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getNodesAndLog(Long id, String caller) {
		return mobileFlowService.getNodesAndLog(id, caller);
	}
	
	/**
	 * 审核单据
	 * 
	 * @param id
	 * @param description
	 * @param dealtype
	 * @return
	 */
	@RequestMapping(value = "/auditDocuments", method = RequestMethod.POST)
	@ResponseBody
	private ModelMap auditDocuments(Long id, String description, Integer dealtype) {
		ModelMap map = new ModelMap();
		if (id != 0) {
			return mobileFlowService.auditDocuments(id, description, dealtype);
		} else {
			map.put("error", "单据不存在或已被审核");
			return map;
		}
	}

	/**
	 * 获取人员信息
	 * 
	 * @param enuu
	 * @return
	 */
	@RequestMapping(value = "/getUsersInfo", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getUsersInfo(Long enuu) {
		return mobileFlowService.getUsersInfo(enuu);
	}
}
