activiti的外置表单_【应用篇】Activiti外置表单实例demo(四)

/*

* 启动流程 启动流程,只考虑首次登录。 首次登录:启动工作流,并且更新/{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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值