public void onCreate(DelegateTask delegateTask) throws Exception {
    String assignee = delegateTask.getAssignee();
    String processDefinitionId = delegateTask.getProcessDefinitionId();
    DelegateInfo delegateInfo = delegateService.getDelegateInfo(assignee, processDefinitionId);

    if (delegateInfo == null) {
      return;
    }

    String attorney = delegateInfo.getAttorney();
    Set<IdentityLink> ids = delegateTask.getCandidates();

    for (IdentityLink identityLink : ids) {
      if (this.containsUser(identityLink, assignee) || this.containsGroup(identityLink, assignee)) {
        this.addCandidateUser(delegateTask, assignee, attorney);
      }
    }
  }
 private void addCandidateUser(DelegateTask delegateTask, String assignee, String attorney) {
   logger.info("自动委托任务,设置候选人: {} to {}", delegateTask, attorney);
   delegateTask.addCandidateUser(attorney);
   delegateService.saveRecord(assignee, attorney, delegateTask.getId());
 }