}
}
public Void execute(CommandContext commandContext) {
ProcessEngine processEngine = getProcessEngine();
FormTemplateManager formTemplateManager = getFormTemplateManager();
KeyValue keyValue = getKeyValue();
String taskId = getParameter(OPERATION_TASK_ID);
TaskService taskService = processEngine.getTaskService();
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
// 处理抄送任务
if ("copy".equals(task.getCategory())) {
new DeleteTaskWithCommentCmd(taskId, "已阅").execute(commandContext);
return null;
}
// 先保存草稿
new SaveDraftOperation().execute(getParameters());
// 先设置登录用户
IdentityService identityService = processEngine.getIdentityService();
identityService.setAuthenticatedUserId(SpringSecurityUtils
.getCurrentUsername());
if (task == null) {
throw new IllegalStateException("任务不存在");
}
logger.info("{}", task.getDelegationState());
// 处理委办任务
if (DelegationState.PENDING == task.getDelegationState()) {
taskService.resolveTask(taskId);
return null;
}
// 处理子任务
if ("subtask".equals(task.getCategory())) {
new DeleteTaskWithCommentCmd(taskId, "完成").execute(commandContext);
int count = getJdbcTemplate().queryForObject(
"select count(*) from ACT_RU_TASK where PARENT_TASK_ID_=?",
Integer.class, task.getParentTaskId());
if (count > 1) {
return null;
}
taskId = task.getParentTaskId();
}
FormService formService = processEngine.getFormService();
String taskFormKey = formService.getTaskFormKey(
task.getProcessDefinitionId(), task.getTaskDefinitionKey());
FormInfo formInfo = new FormInfo();
formInfo.setTaskId(taskId);
formInfo.setFormKey(taskFormKey);
// 尝试根据表单里字段的类型,进行转换
Map<String, String> formTypeMap = new HashMap<String, String>();
if (formInfo.isFormExists()) {
FormTemplate formTemplate = formTemplateManager.findUniqueBy(
"code", formInfo.getFormKey());
String content = formTemplate.getContent();
formTypeMap = this.fetchFormTypeMap(content);
}