Ejemplo n.º 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});
  }
Ejemplo n.º 2
0
 /** 获取菜单名称路径(如:系统设置-机构用户-用户管理-编辑) */
 public static String getMenuNamePath(String requestUri, String permission) {
   String href = StringUtils.substringAfter(requestUri, Global.getAdminPath());
   @SuppressWarnings("unchecked")
   Map<String, String> menuMap = (Map<String, String>) CacheUtils.get(CACHE_MENU_NAME_PATH_MAP);
   if (menuMap == null) {
     menuMap = Maps.newHashMap();
     List<Menu> menuList = menuDao.findAllList(new Menu());
     for (Menu menu : menuList) {
       // 获取菜单名称路径(如:系统设置-机构用户-用户管理-编辑)
       String namePath = "";
       if (menu.getParentIds() != null) {
         List<String> namePathList = Lists.newArrayList();
         for (String id : StringUtils.split(menu.getParentIds(), ",")) {
           if (Menu.getRootId().equals(id)) {
             continue; // 过滤跟节点
           }
           for (Menu m : menuList) {
             if (m.getId().equals(id)) {
               namePathList.add(m.getName());
               break;
             }
           }
         }
         namePathList.add(menu.getName());
         namePath = StringUtils.join(namePathList, "-");
       }
       // 设置菜单名称路径
       if (StringUtils.isNotBlank(menu.getHref())) {
         menuMap.put(menu.getHref(), namePath);
       } else if (StringUtils.isNotBlank(menu.getPermission())) {
         for (String p : StringUtils.split(menu.getPermission())) {
           menuMap.put(p, namePath);
         }
       }
     }
     CacheUtils.put(CACHE_MENU_NAME_PATH_MAP, menuMap);
   }
   String menuNamePath = menuMap.get(href);
   if (menuNamePath == null) {
     for (String p : StringUtils.split(permission)) {
       menuNamePath = menuMap.get(p);
       if (StringUtils.isNotBlank(menuNamePath)) {
         break;
       }
     }
     if (menuNamePath == null) {
       return "";
     }
   }
   return menuNamePath;
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 /** 保存日志 */
 public static void saveLog(
     HttpServletRequest request, Object handler, Exception ex, String title) {
   User user = UserUtils.getUser();
   if (user != null && user.getId() != null) {
     Log log = new Log();
     log.setTitle(title);
     log.setType(ex == null ? Log.TYPE_ACCESS : Log.TYPE_EXCEPTION);
     log.setRemoteAddr(StringUtils.getRemoteAddr(request));
     log.setUserAgent(request.getHeader("user-agent"));
     log.setRequestUri(request.getRequestURI());
     log.setParams(request.getParameterMap());
     log.setMethod(request.getMethod());
     // 异步保存日志
     new SaveLogThread(log, handler, ex).start();
   }
 }