예제 #1
0
  /**
   * 启动流程
   *
   * @param entity
   */
  @Transactional(readOnly = false)
  public void save(Leave leave, Map<String, Object> variables) {

    // 保存业务数据
    if (StringUtils.isBlank(leave.getId())) {
      leave.preInsert();
      leaveDao.insert(leave);
    } else {
      leave.preUpdate();
      leaveDao.update(leave);
    }
    logger.debug("save entity: {}", leave);

    // 用来设置启动流程的人员ID,引擎会自动把用户ID保存到activiti:initiator中
    identityService.setAuthenticatedUserId(leave.getCurrentUser().getLoginName());

    // 启动流程
    String businessKey = leave.getId().toString();
    variables.put("type", "leave");
    variables.put("busId", businessKey);
    ProcessInstance processInstance =
        runtimeService.startProcessInstanceByKey(ActUtils.PD_LEAVE[0], businessKey, variables);
    leave.setProcessInstance(processInstance);

    // 更新流程实例ID
    leave.setProcessInstanceId(processInstance.getId());
    leaveDao.updateProcessInstanceId(leave);

    logger.debug(
        "start process of {key={}, bkey={}, pid={}, variables={}}",
        new Object[] {ActUtils.PD_LEAVE[0], businessKey, processInstance.getId(), variables});
  }
예제 #2
0
 @Override
 public void run() {
   // 获取日志标题
   if (StringUtils.isBlank(log.getTitle())) {
     String permission = "";
     if (handler instanceof HandlerMethod) {
       Method m = ((HandlerMethod) handler).getMethod();
       RequiresPermissions rp = m.getAnnotation(RequiresPermissions.class);
       permission = (rp != null ? StringUtils.join(rp.value(), ",") : "");
     }
     log.setTitle(getMenuNamePath(log.getRequestUri(), permission));
   }
   // 如果有异常,设置异常信息
   log.setException(Exceptions.getStackTraceAsString(ex));
   // 如果无标题并无异常日志,则不保存信息
   if (StringUtils.isBlank(log.getTitle()) && StringUtils.isBlank(log.getException())) {
     return;
   }
   // 保存日志信息
   log.preInsert();
   logDao.insert(log);
 }