/*
* 启动流程 启动流程,只考虑首次登录。 首次登录:启动工作流,并且更新/{processDefinitionId} @RequestMapping(value = "get-form/start/{processDefinitionId}")
*/
@RequestMapping(value = "/start/{processDefinitionId}")
public String start(@PathVariable("processDefinitionId") String processDefinitionId,HttpServletRequest request) throws Exception {
try {
// 定义map用于往工作流数据库中传值。
Map formProperties = new HashMap();
//启动流程-何静媛-2015年5月24日--processDefinitionId,
ProcessInstance processInstance = formService
.submitStartFormData(processDefinitionId,
formProperties);
// 返回到显示用户信息的controller
logger.debug("start a processinstance: {}", processInstance);
return "redirect:/workflow/auto/get-form/task/"+ processInstance.getId();
} catch (Exception e) {
throw e;
} finally {
identityService.setAuthenticatedUserId(null);
}
}
/**
* 读取Task的表单
* @RequestMapping(value = "get-form/task/{processDefinitionkey}")
* @PathVariable("processDefinitionkey") String processDefinitionkey
*/
@RequestMapping(value = "/get-form/task/{processInstanceId}")
@ResponseBody
public ModelAndView findTaskForm(
@PathVariable("processInstanceId") String processInstanceId,
HttpServletRequest request) throws Exception {
ModelAndView mav = new ModelAndView("leave/apply");
// 获取当前登陆人信息。
/* User user = UserUtil.getUserFromSession(request.getSession()); */
TaskQuery taskQuery = taskService.createTaskQuery()
.processInstanceId(processInstanceId).orderByProcessInstanceId().desc();
List tasks = taskQuery.list();
if (tasks.size()==0) {
ModelAndView mav2 = new ModelAndView("leave/finish");
return mav2;
}
Task task = tasks.get(0);
Object renderedTaskForm = formService.getRenderedTaskForm(task.getId());
System.out.println(renderedTaskForm.toString());
mav.addObject("renderedTaskForm", renderedTaskForm.toString());//整个页面,参数已经赋值(整个页面是什么时候赋上值的?)
mav.addObject("taskId", task.getId());
mav.addObject("processInstanceId", processInstanceId);
return mav;
}
/**
* 办理任务,提交task的并保存form
*/
@RequestMapping(value = "task/complete/{taskId}/{processInstanceId}")
@SuppressWarnings("unchecked")
public String completeTask(@PathVariable("taskId") String taskId,@PathVariable("processInstanceId") String processInstanceId, RedirectAttributes redirectAttributes, HttpServletRequest request) {
Map formProperties = new HashMap();
// 从request中读取参数然后转换
Map parameterMap = request.getParameterMap();
Set> entrySet = parameterMap.entrySet();
for (Entry entry : entrySet) {
String key = entry.getKey();
/*
* 参数结构:fq_reason,用_分割 fp的意思是form paremeter 最后一个是属性名称
*/
if (StringUtils.defaultString(key).startsWith("fp_")) {
String[] paramSplit = key.split("_");
formProperties.put(paramSplit[1], entry.getValue()[0]);
}
}
logger.debug("start form parameters: {}", formProperties);
try {
formService.submitTaskFormData(taskId, formProperties);
} finally {
identityService.setAuthenticatedUserId(null);
}
redirectAttributes.addFlashAttribute("message", "任务完成:taskId=" + taskId);
return "redirect:/workflow/auto/get-form/task/"+processInstanceId;
}