@RequestMapping("form-viewTaskForm")
public String viewTaskForm(@RequestParam("taskId") String taskId,
Model model, RedirectAttributes redirectAttributes)
throws Exception {
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task == null) {
messageHelper.addFlashMessage(redirectAttributes, "任务不存在");
return "redirect:/bpm/workspace-listPersonalTasks.do";
}
FormService formService = processEngine.getFormService();
String taskFormKey = formService.getTaskFormKey(
task.getProcessDefinitionId(), task.getTaskDefinitionKey());
FormTemplate formTemplate = formTemplateManager.findUniqueBy("code",
taskFormKey);
model.addAttribute("formTemplate", formTemplate);
FormInfo formInfo = new FormInfo();
formInfo.setTaskId(taskId);
model.addAttribute("formInfo", formInfo);
List<BpmConfOperation> bpmConfOperations = bpmConfOperationManager
.find("from BpmConfOperation where bpmConfNode.bpmConfBase.processDefinitionId=? and bpmConfNode.code=?",
task.getProcessDefinitionId(),
task.getTaskDefinitionKey());
for (BpmConfOperation bpmConfOperation : bpmConfOperations) {
formInfo.getButtons().add(bpmConfOperation.getValue());
}
String processDefinitionId = task.getProcessDefinitionId();
String activityId = task.getTaskDefinitionKey();
formInfo.setProcessDefinitionId(processDefinitionId);
formInfo.setActivityId(activityId);
List<BpmConfForm> bpmConfForms = bpmConfFormManager
.find("from BpmConfForm where bpmConfNode.bpmConfBase.processDefinitionId=? and bpmConfNode.code=?",
processDefinitionId, activityId);
if (!bpmConfForms.isEmpty()) {
if (Integer.valueOf(1).equals(bpmConfForms.get(0).getType())) {
String redirectUrl = bpmConfForms.get(0).getValue()
+ "?taskId=" + taskId;
return "redirect:" + redirectUrl;
}
}
if ((formTemplate != null)
&& Integer.valueOf(1).equals(formTemplate.getType())) {
String redirectUrl = formTemplate.getContent() + "?taskId="
+ taskId;
return "redirect:" + redirectUrl;
}
if ((taskId != null) && (!"".equals(taskId))) {
// 如果是任务草稿,直接通过processInstanceId获得record,更新数据
// TODO: 分支肯定有问题
String processInstanceId = task.getProcessInstanceId();
Record record = keyValue.findByRef(processInstanceId);
if (record != null) {
Map map = new HashMap();