package com.leanwo.activiti.rest.base;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.leanwo.activiti.dto.BaseResponse;
import com.leanwo.activiti.dto.manage.ProcessInstanceDocRequest;
import com.leanwo.activiti.dto.manage.ProcessInstanceDocResponse;
import com.leanwo.activiti.dto.manage.TaskDocInfo;
import com.leanwo.activiti.service.base.DocManagmentService;

/**
 * 单据管理资源类
 * @author YangZhiJie
 *
 */

@RestController
@RequestMapping("/workflow-prodog/DocManagmentResource")
public class DocManagmentResource {

	@Autowired
	private DocManagmentService docManagmentService;
	
	/**
	 * 查询所有的工作流实例信息
	 * @param processInstanceDocRequest
	 * @return
	 */
	@RequestMapping(value = "/query", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
	public ProcessInstanceDocResponse query(@RequestBody ProcessInstanceDocRequest processInstanceDocRequest) {
		return docManagmentService.query(processInstanceDocRequest);
	}
	

	/**
	 * 修改流程实例Id的状态
	 * @param changeType suspend:暂停, activate: 激活, delete: 删除
	 * @param processInstanceId  流程实例Id
	 * @param reason 原因
	 * @return
	 */
	@RequestMapping(value = "/changeProcessInstance", method = RequestMethod.GET, produces = "application/json")
	public BaseResponse changeProcessInstance(@RequestParam("changeType") String changeType,
			@RequestParam("processInstanceId") String processInstanceId, 
			@RequestParam("reason") String reason){
		return docManagmentService.changeProcessInstance(changeType, processInstanceId, reason);
	}
	
	
	/**
	 * 根据流程实例Id查询任务信息
	 * @param processInstanceId
	 * @return
	 */
	@RequestMapping(value = "/listTasks", method = RequestMethod.GET, produces = "application/json")
	public List<TaskDocInfo> listTasks(@RequestParam("processInstanceId") String processInstanceId){
		return docManagmentService.listTasks(processInstanceId);
	}
	
	
	/**
	 * 根据流程实例Id查询历史任务信息
	 * @param processInstanceId
	 * @return
	 */
	@RequestMapping(value = "/listHistoricTasks", method = RequestMethod.GET, produces = "application/json")
	public List<TaskDocInfo> listHistoricTasks(@RequestParam("processInstanceId") String processInstanceId){
		return docManagmentService.listHistoricTasks(processInstanceId);
	}
}
