/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.workengineeringproject.web;

import com.jeeplus.common.config.Global;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.utils.MyBeanUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.act.entity.Act;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.act.utils.ActUtils;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.entity.Workattachment;
import com.jeeplus.modules.sys.service.OfficeService;
import com.jeeplus.modules.sys.service.WorkattachmentService;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workactivity.entity.Activity;
import com.jeeplus.modules.workactivity.service.ActivityService;
import com.jeeplus.modules.workengineeringprice.entity.WorkEngineeringPrice;
import com.jeeplus.modules.workengineeringproject.entity.WorkEngineeringProject;
import com.jeeplus.modules.workengineeringproject.service.WorkEngineeringProjectService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工程项目信息Controller
 * @author 杨帆
 * @version 2017-10-23
 */
@Controller
@RequestMapping(value = "${adminPath}/projectManagement/projectManagement")
public class WorkProjectManagementController extends BaseController {

	@Autowired
	private WorkEngineeringProjectService workEngineeringProjectService;
	@Autowired
	protected RuntimeService runtimeService;
	@Autowired
	protected TaskService taskService;
	@Autowired
	private ActTaskService actTaskService;
	@Autowired
	protected HistoryService historyService;
	@Autowired
	protected RepositoryService repositoryService;
	@Autowired
	private WorkattachmentService workattachmentService;
	@Autowired
	private OfficeService officeService;
	@Autowired
	private ActivityService activityService;

	@ModelAttribute
	public WorkEngineeringProject get(@RequestParam(required=false) String id) {
		WorkEngineeringProject entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = workEngineeringProjectService.get(id);
		}
		if (entity == null){
			entity = new WorkEngineeringProject();
		}
		return entity;
	}

	@RequestMapping(value = "form")
	public String form(WorkEngineeringProject workEngineeringProject, Model model) {
		if (StringUtils.isBlank(workEngineeringProject.getId())) {
			workEngineeringProject.setOffice(UserUtils.getSelectOffice());
		}
		List<Workattachment> workReportList = workattachmentService.findAttachment(workEngineeringProject.getId(),"39");
		List<Workattachment> workBasisInformationList = workattachmentService.findAttachment(workEngineeringProject.getId(),"40");
		List<Workattachment> workRemoteControlList = workattachmentService.findAttachment(workEngineeringProject.getId(),"41");
		List<Workattachment> workSummaryList = workattachmentService.findAttachment(workEngineeringProject.getId(),"42");
		List<Workattachment> workOtherList = workattachmentService.findAttachment(workEngineeringProject.getId(),"43");
		model.addAttribute("workEngineeringProject", workEngineeringProject);
		model.addAttribute("workReportList", workReportList);
		model.addAttribute("workBasisInformationList", workBasisInformationList);
		model.addAttribute("workRemoteControlList", workRemoteControlList);
		model.addAttribute("workSummaryList", workSummaryList);
		model.addAttribute("workOtherList", workOtherList);
		if (!workEngineeringProject.getBusinessType().contains("2") && !workEngineeringProject.getBusinessType().contains("H")){
			if (workEngineeringProject.getAct()!=null && StringUtils.isNotBlank(workEngineeringProject.getAct().getTaskId())){
				return "modules/workprojectManagement/workThreeGradeExamination";
			}else if (StringUtils.isNotBlank(workEngineeringProject.getName()) && workEngineeringProject.getName().equals("1")){
				return "modules/workprojectManagement/workThreeGradeExamination";
			}{
				return "modules/workprojectManagement/workThreeGradeExaminationView";
			}
		}else {
			if (workEngineeringProject.getAct()!=null && StringUtils.isNotBlank(workEngineeringProject.getAct().getTaskId())){
				return "modules/workprojectManagement/workThreeExamination";
			} else if (StringUtils.isNotBlank(workEngineeringProject.getName()) && workEngineeringProject.getName().equals("1")){
				return "modules/workprojectManagement/workThreeGradeExamination";
			}else {
				return "modules/workprojectManagement/workThreeExaminationView";
			}
		}
	}


	/**
	 * 工程项目信息列表页面
	 */
	@RequiresPermissions("projectManagement:projectManagement:list")
	@RequestMapping(value = {"list", ""})
	public String list(WorkEngineeringProject workEngineeringProject, HttpServletRequest request, HttpServletResponse response, Model model) {
		//只是普通员工
		if(!UserUtils.getSelectRoleInfo()){
			String id = UserUtils.getUser().getId();
			workEngineeringProject.setQueryCon(id);
		}
		Page<WorkEngineeringProject> page = workEngineeringProjectService.findProjectManagementPage(new Page<WorkEngineeringProject>(request, response), workEngineeringProject);
		List<WorkEngineeringProject> list = page.getList();
		for (WorkEngineeringProject entity :list){
			String hostOfficeMaster = entity.getHostOfficeMaster();
			if (StringUtils.isNotBlank(hostOfficeMaster)){
				String[] ids = hostOfficeMaster.split(",");
				String name = "";
				for (String str:ids) {
					User user = UserUtils.get(str);
					name += user.getName()+",";
				}
				if (StringUtils.isNotBlank(name)){
					name = name.substring(0,name.length() - 1);
				}
				entity.setHostOfficeMasterName(name);
			}
			if(StringUtils.isNotBlank(entity.getProcessInstanceProofreadId())){
				boolean state = actTaskService.isProcessEnd(entity.getProcessInstanceProofreadId());
				if (state){
					entity.setQueryCon("true");
				}
			}
		}
		model.addAttribute("page", page);
		model.addAttribute("name", UserUtils.getSelectRole().get(0).getEnname());
		return "modules/workprojectManagement/workProjectManagementList";
	}

	@RequestMapping(value = "startThreeGradeExamination")
	public String startThreeGradeExamination(WorkEngineeringProject workEngineeringProject, Model model) {
		if (StringUtils.isBlank(workEngineeringProject.getId())) {
			workEngineeringProject.setOffice(UserUtils.getSelectOffice());
		}
		List<Workattachment> workReportList = workattachmentService.findAttachment(workEngineeringProject.getId(),"39");
		List<Workattachment> workBasisInformationList = workattachmentService.findAttachment(workEngineeringProject.getId(),"40");
		List<Workattachment> workRemoteControlList = workattachmentService.findAttachment(workEngineeringProject.getId(),"41");
		List<Workattachment> workSummaryList = workattachmentService.findAttachment(workEngineeringProject.getId(),"42");
		List<Workattachment> workOtherList = workattachmentService.findAttachment(workEngineeringProject.getId(),"43");
		model.addAttribute("workEngineeringProject", workEngineeringProject);
		model.addAttribute("workReportList", workReportList);
		model.addAttribute("workBasisInformationList", workBasisInformationList);
		model.addAttribute("workRemoteControlList", workRemoteControlList);
		model.addAttribute("workSummaryList", workSummaryList);
		model.addAttribute("workOtherList", workOtherList);
		/*if (workEngineeringProject.getName().equals("4")){
			String processInstanceId = workEngineeringProject.getProcessInstanceProofreadId();
			HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
			if(historicProcessInstance!=null) {
				workEngineeringProject.setHistoricProcessInstance(historicProcessInstance);
				workEngineeringProject.setProcessDefinition(repositoryService.createProcessDefinitionQuery().processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult());
			} else {
				ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).active().singleResult();
				if (processInstance != null){
					workEngineeringProject.setProcessInstance(processInstance);
					workEngineeringProject.setProcessDefinition(repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult());
				}
			}
			ProcessInstance processInstance = actTaskService.getProcIns(processInstanceId);
			if (processInstance!=null) {
				List<Task> taskList = actTaskService.getCurrentTaskList(processInstance);
				if(taskList!=null && taskList.size()>1){
					for (Task taskInfok:taskList) {
						if (taskInfok.getAssignee().equals(UserUtils.getUser().getId())) {
							Act act = new Act();
							act.setTaskId(taskInfok.getId());
							act.setTaskName(taskInfok.getName());
							act.setTaskDefKey(taskInfok.getTaskDefinitionKey());
							act.setProcDefId(taskInfok.getProcessDefinitionId());
							act.setProcInsId(taskInfok.getProcessInstanceId());
							act.setTask(taskInfok);
							workEngineeringProject.setAct(act);
						}
					}
				}else {
					Task task = actTaskService.getCurrentTaskInfo(processInstance);
					Act act = new Act();
					act.setTaskId(task.getId());
					act.setTaskName(task.getName());
					act.setTaskDefKey(task.getTaskDefinitionKey());
					act.setProcDefId(task.getProcessDefinitionId());
					act.setProcInsId(task.getProcessInstanceId());
					act.setTask(task);
					workEngineeringProject.setAct(act);
				}
			}
			model.addAttribute("workEngineeringProject", workEngineeringProject);
		}*/
		if (!workEngineeringProject.getBusinessType().contains("2") && !workEngineeringProject.getBusinessType().contains("H")){
			if (workEngineeringProject.getAct()!=null && StringUtils.isNotBlank(workEngineeringProject.getAct().getTaskId())){
				return "modules/workprojectManagement/workThreeGradeExamination";
			}else if (StringUtils.isNotBlank(workEngineeringProject.getName()) && workEngineeringProject.getName().equals("1")){
				return "modules/workprojectManagement/workThreeGradeExamination";
			}else if (StringUtils.isNotBlank(workEngineeringProject.getName()) && workEngineeringProject.getName().equals("5")){
				return "modules/workprojectManagement/startThreeGradeExamination";
			}{
				return "modules/workprojectManagement/workThreeGradeExaminationView";
			}
		}else {
			if (workEngineeringProject.getAct()!=null && StringUtils.isNotBlank(workEngineeringProject.getAct().getTaskId())){
				return "modules/workprojectManagement/workThreeExamination";
			} else if (StringUtils.isNotBlank(workEngineeringProject.getName()) && workEngineeringProject.getName().equals("1")){
				return "modules/workprojectManagement/workThreeGradeExamination";
			}else if (StringUtils.isNotBlank(workEngineeringProject.getName()) && workEngineeringProject.getName().equals("5")){
				return "modules/workprojectManagement/startThreeGradeExamination";
			}else {
				return "modules/workprojectManagement/workThreeExaminationView";
			}
		}

	}

	/**
	 * 保存项目实施记录
	 */
	@RequestMapping(value = "save")
	public String save(WorkEngineeringProject workEngineeringProject, Model model, RedirectAttributes redirectAttributes,HttpServletRequest request,
					   HttpServletResponse response) throws Exception{
		WorkEngineeringProject t = workEngineeringProjectService.get(workEngineeringProject.getId());//从数据库取出记录的值
		WorkEngineeringPrice workEngineeringPrice = workEngineeringProject.getWorkEngineeringPrice();
		workEngineeringPrice.setEngineeringId(workEngineeringProject.getId());
		t.setWorkEngineeringPrice(workEngineeringPrice);
		Map map = new HashMap();
		workEngineeringProjectService.saveProjectManagement(t, map);//保存
		addMessage(redirectAttributes, "三级校审已启动!");
		return "redirect:"+Global.getAdminPath()+"/projectManagement/projectManagement/?repage";

	}

	/**
	 * 审核信息
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "applyOnWorkprojectManagement")
	public String applyOnWorkprojectManagement(Act act, HttpServletResponse response, Model model) {
		// 获取流程XML上的表单KEY
		String formKey = "/workengineeringproject/workEngineeringProject/startThreeGradeExamination";
		//logger.info("------formKeys:"+formKeys);
		// 获取流程实例对象
		if (act.getProcInsId() != null){
			if(actTaskService.getProcIns(act.getProcInsId())!=null){
				act.setProcIns(actTaskService.getProcIns(act.getProcInsId()));
			}else{
				act.setFinishedProcIns(actTaskService.getFinishedProcIns(act.getProcInsId()));
			}
		}
		return "redirect:" + ActUtils.getFormUrl(formKey, act);
	}

	/**
	 * 工单执行（完成任务）
	 * @param workEngineeringProject
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "saveAudit")
	public String saveAudit(WorkEngineeringProject workEngineeringProject, Map<String, Object> vars, Model model, RedirectAttributes redirectAttributes) {
		String flag = workEngineeringProject.getAct()==null?"2":workEngineeringProject.getAct().getFlag();
		WorkEngineeringPrice workEngineeringPrice = workEngineeringProject.getWorkEngineeringPrice();
		workEngineeringPrice.setEngineeringId(workEngineeringProject.getId());
		WorkEngineeringProject t = workEngineeringProjectService.get(workEngineeringProject.getId());//从数据库取出记录的值
		t.setWorkEngineeringPrice(workEngineeringPrice);
		Map map = new HashMap();
		boolean b = workEngineeringProjectService.saveProjectManagement(t, map);//保存

		if (b){
			addMessage(redirectAttributes, "三级校审已发起!");
		}else {
			if(StringUtils.isNotBlank(workEngineeringProject.getProofreadStatus()) && workEngineeringProject.getProofreadStatus().equals("4")){
				String processInstanceProofreadId = workEngineeringProject.getProcessInstanceProofreadId();
				HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceProofreadId).singleResult();
				if(historicProcessInstance!=null) {
					workEngineeringProject.setHistoricProcessInstance(historicProcessInstance);
					workEngineeringProject.setProcessDefinition(repositoryService.createProcessDefinitionQuery().processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult());
				} else {
					ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceProofreadId).active().singleResult();
					if (processInstance != null){
						workEngineeringProject.setProcessInstance(processInstance);
						workEngineeringProject.setProcessDefinition(repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult());
					}
				}
				ProcessInstance processInstance = actTaskService.getProcIns(workEngineeringProject.getProcessInstanceProofreadId());
				if (processInstance!=null) {
					Task taskInfok = actTaskService.getCurrentTaskInfo(processInstance);
					Act act = new Act();
					act.setTaskId(taskInfok.getId());
					act.setTaskName(taskInfok.getName());
					act.setTaskDefKey(taskInfok.getTaskDefinitionKey());
					act.setProcDefId(taskInfok.getProcessDefinitionId());
					act.setProcInsId(taskInfok.getProcessInstanceId());
					act.setTask(taskInfok);
					act.setFlag(flag);
					workEngineeringProject.setAct(act);
				}
				if (StringUtils.isNotBlank(t.getRemarks()) && t.getRemarks().equals("yes")){
					addMessage(redirectAttributes, "重新申请三级校审成功");
				}else {
					addMessage(redirectAttributes, "三级校审已撤销");
				}
				t.setRemarks("");
			}

			String str = workEngineeringProjectService.auditProofreadSave(workEngineeringProject);
			addMessage(redirectAttributes, str);
		}
		return "redirect:"+Global.getAdminPath()+"/projectManagement/projectManagement/?repage";
	}

	/**
	 * 启动流程
	 * @return
	 */
	@RequestMapping(value = "startposs")
	public String startposs(WorkEngineeringProject workEngineeringProject, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes)throws Exception {
		Map<String, Object> variables = new HashMap<String, Object>();
		WorkEngineeringProject t = workEngineeringProjectService.get(workEngineeringProject.getId());//从数据库取出记录的值
		MyBeanUtils.copyBeanNotNull2Bean(workEngineeringProject, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
		t.setStatus("2");
		t.preUpdate();
		workEngineeringProjectService.update(t);
		workEngineeringProjectService.startProofreadProcess(t,variables);
		addMessage(redirectAttributes, "启动流程成功");
		return "redirect:"+Global.getAdminPath()+"/projectManagement/projectManagement/?repage";
	}

	/**
	 * 附件列表
	 * @return
	 */
	@RequestMapping(value = "getAttachmentList")
	public String getAttachmentList(WorkEngineeringProject workEngineeringProject, HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes)throws Exception {
		if (StringUtils.isBlank(workEngineeringProject.getId())) {
			workEngineeringProject.setOffice(UserUtils.getSelectOffice());
		}
		List<Workattachment> workReportList = workattachmentService.findAttachment(workEngineeringProject.getId(),"39");
		List<Workattachment> workBasisInformationList = workattachmentService.findAttachment(workEngineeringProject.getId(),"40");
		List<Workattachment> workRemoteControlList = workattachmentService.findAttachment(workEngineeringProject.getId(),"41");
		List<Workattachment> workSummaryList = workattachmentService.findAttachment(workEngineeringProject.getId(),"42");
		List<Workattachment> workOtherList = workattachmentService.findAttachment(workEngineeringProject.getId(),"43");
		model.addAttribute("workEngineeringProject", workEngineeringProject);
		model.addAttribute("workReportList", workReportList);
		model.addAttribute("workBasisInformationList", workBasisInformationList);
		model.addAttribute("workRemoteControlList", workRemoteControlList);
		model.addAttribute("workSummaryList", workSummaryList);
		model.addAttribute("workOtherList", workOtherList);
		return "modules/workprojectManagement/workAttachmentListView";
	}

	/**
	 * 待办任务列表页面
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"workProjectManagementTodoList"})
	public String workProjectManagementTodoList(Act act, HttpServletRequest request, HttpServletResponse response, Model model) {
		act.setProcDefKey("threeexamination");
		List<Act> list = new ArrayList<>();
		list.addAll(actTaskService.todoList(act));
		Office office = UserUtils.getSelectCompany();
		String companyId = office==null?"":office.getId();
		List<Activity> activities = activityService.groupByActivityMenu("7864872f45b84acd893010e66a3db2c8",companyId);
		for (Activity activity:activities){
			act.setProcDefKey(activity.getProcessKey());
			list.addAll(actTaskService.todoList(act));
		}
		List<WorkEngineeringProject> lists = new ArrayList<WorkEngineeringProject>();
		Role role = UserUtils.getSelectRole().get(0);
		String officeId = "";
		if (role.getDataScope().contains("4")){
			User user = UserUtils.getUser();
			officeId = user.getOffice().getId();
		}
		for (Act a : list) {
			WorkEngineeringProject workEngineeringProject = workEngineeringProjectService.getByProcessInstanceProofreadId(a.getTask().getProcessInstanceId());
			if (workEngineeringProject != null && workEngineeringProject.getCompanyId().equals(companyId) && workEngineeringProject.getProofreadStatus() !=null && !workEngineeringProject.getProofreadStatus().equals("4") && workEngineeringProject.getStatus() !=null && workEngineeringProject.getStatus().equals("4")) {
				User createBy = UserUtils.get(workEngineeringProject.getCreateBy().getId());
				if (StringUtils.isNotBlank(officeId)){
					if (officeId.equals(createBy.getOffice().getId())){
						if (a.getVars().getMap().get("applyUserId")!=null) {
							User user = UserUtils.get(a.getVars().getMap().get("applyUserId").toString());
							if (user != null) {
								a.getVars().getMap().put("applyUserId", UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
							}
						}
						workEngineeringProject.setAct(a);
						if (com.jeeplus.common.utils.StringUtils.isNotBlank(workEngineeringProject.getId())){
							workEngineeringProject.setName(officeService.get(companyId).getName());
						}
						lists.add(workEngineeringProject);
					}
				}else {
					if (a.getVars().getMap().get("applyUserId")!=null) {
						User user = UserUtils.get(a.getVars().getMap().get("applyUserId").toString());
						if (user != null) {
							a.getVars().getMap().put("applyUserId", UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
						}
					}
					workEngineeringProject.setAct(a);
					if (com.jeeplus.common.utils.StringUtils.isNotBlank(workEngineeringProject.getId())){
						workEngineeringProject.setName(officeService.get(companyId).getName());
					}
					lists.add(workEngineeringProject);
				}
			}
		}
		model.addAttribute("list", lists);
		return "modules/workprojectManagement/workProjectManagementTodoList";
	}

	/**
	 * 已办任务
	 * @param act
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"workProjectManagementHistoricList"})
	public String workProjectManagementHistoricList (Act act, HttpServletRequest request, HttpServletResponse response, Model model){
		act.setProcDefKey("threeexamination");
		List<Act> list = actTaskService.historicList(act);
		Office office = UserUtils.getSelectCompany();
		String companyId = office==null?"":office.getId();
		List<Activity> activities = activityService.groupByActivityMenu("7864872f45b84acd893010e66a3db2c8",companyId);
		for (Activity activity:activities){
			act.setProcDefKey(activity.getProcessKey());
			list.addAll(actTaskService.historicList(act));
		}
		List<WorkEngineeringProject> lists = new ArrayList<WorkEngineeringProject>();
		for (Act a : list) {
			try {
				WorkEngineeringProject workEngineeringProject = workEngineeringProjectService.getByProcessInstanceProofreadId(a.getHistTask().getProcessInstanceId());
				if (workEngineeringProject != null && workEngineeringProject.getCompanyId().equals(companyId)) {
					if (a.getVars().getMap().get("applyUserId")!=null){
						a.getVars().getMap().put("applyUserId",UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
					}
					workEngineeringProject.setAct(a);
					if (com.jeeplus.common.utils.StringUtils.isNotBlank(workEngineeringProject.getId())){
						workEngineeringProject.setName(officeService.get(companyId).getName());
					}
					lists.add(workEngineeringProject);
				}
			}catch (Exception e){
				logger.info("Exception e"+e);
			}

		}
		model.addAttribute("list", lists);

		return "modules/workprojectManagement/workProjectManagementHistoricList";
	}

	/**
	 * 审核信息
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "applyOnWorkProjectManagement")
	public String applyOnWorkEngineeringProject(Act act, HttpServletResponse response, Model model) {
		// 获取流程XML上的表单KEY
		String formKey = "/projectManagement/projectManagement/form";
		//logger.info("------formKeys:"+formKeys);
		// 获取流程实例对象
		if (act.getProcInsId() != null){
			if(actTaskService.getProcIns(act.getProcInsId())!=null){
				act.setProcIns(actTaskService.getProcIns(act.getProcInsId()));
			}else{
				act.setFinishedProcIns(actTaskService.getFinishedProcIns(act.getProcInsId()));
			}
		}
		return "redirect:" + ActUtils.getFormUrl(formKey, act);
	}

}