public List<SysApplication> getAccessAppList(long parentId, SysUser user) {
    long parentAppId = parentId;
    SysApplication parentApp = findById(parentId);
    if (parentApp != null) {
      parentAppId = parentApp.getNode().getId();
    }

    logger.debug("parent node:" + parentAppId);

    SysApplicationQuery query = new SysApplicationQuery();
    query.parentId(parentAppId);
    query.setLocked(0);
    List<Long> nodeIds = new java.util.ArrayList<Long>();
    nodeIds.add(-1L);

    List<SysApplication> apps = sysApplicationMapper.getSysApplicationByUserId(user.getId());
    if (apps != null && !apps.isEmpty()) {
      for (SysApplication app : apps) {
        nodeIds.add(app.getNodeId());
      }
    }
    query.nodeIds(nodeIds);

    return this.list(query);
  }
  public SysApplication findById(long id) {
    String cacheKey = "sys_app_" + id;

    if (SystemConfig.getBoolean("use_query_cache") && CacheFactory.getString(cacheKey) != null) {
      String text = CacheFactory.getString(cacheKey);
      com.alibaba.fastjson.JSONObject json = JSON.parseObject(text);
      SysApplication app = SysApplicationJsonFactory.jsonToObject(json);
      if (app != null && app.getNodeId() > 0) {
        SysTree node = sysTreeService.findById(app.getNodeId());
        app.setNode(node);
      }
      return app;
    }

    SysApplication app = sysApplicationMapper.getSysApplicationById(id);
    if (app != null && app.getNodeId() > 0) {
      SysTree node = sysTreeService.findById(app.getNodeId());
      app.setNode(node);
    }

    if (app != null && SystemConfig.getBoolean("use_query_cache")) {
      com.alibaba.fastjson.JSONObject json = app.toJsonObject();
      CacheFactory.put(cacheKey, json.toJSONString());
    }

    return app;
  }
 @Transactional
 public void deleteById(Long appId) {
   if (appId != null && appId > 0) {
     sysAccessMapper.deleteSysAccessByAppId(appId);
     sysApplicationMapper.deleteSysApplicationById(appId);
     SysApplication app = this.getSysApplication(appId);
     if (app != null) {
       sysTreeMapper.deleteSysTreeById(app.getNodeId());
     }
   }
 }
 @Transactional
 public boolean create(SysApplication bean) {
   boolean ret = false;
   if (bean.getId() == 0) {
     bean.setId(idGenerator.nextId());
   }
   if (StringUtils.isEmpty(bean.getCode())) {
     bean.setCode("app_" + bean.getId());
   }
   if (bean.getNode() != null) {
     bean.getNode().setCode(bean.getCode());
     bean.getNode().setDiscriminator("A");
     bean.getNode().setCreateBy(bean.getCreateBy());
     sysTreeService.create(bean.getNode());
     bean.setNodeId(bean.getNode().getId());
   }
   bean.setSort((int) bean.getId()); // 设置排序号为刚插入的id值
   bean.setCreateDate(new Date());
   sysApplicationMapper.insertSysApplication(bean);
   ret = true;
   return ret;
 }
 public int count(SysApplicationQuery query) {
   return sysApplicationMapper.getSysApplicationCount(query);
 }
 public List<SysApplication> list(SysApplicationQuery query) {
   List<SysApplication> list = sysApplicationMapper.getSysApplications(query);
   return list;
 }
 public int getSysApplicationCountByQueryCriteria(SysApplicationQuery query) {
   return sysApplicationMapper.getSysApplicationCount(query);
 }
 public List<RealmInfo> getRealmInfos() {
   Map<String, Object> params = new java.util.HashMap<String, Object>();
   return sysApplicationMapper.getRealmInfos(params);
 }