Ejemplo n.º 1
0
  public void modifyFuncGroupRelation(String funcGroupId, String targetGroupId) {
    // 查找当前功能组currentGroup
    AppFuncgroup currentGroup = AppFuncgroup.FACTORY.create();
    currentGroup.setFuncgroupid(NumberUtils.createBigDecimal(funcGroupId));
    getDASTemplate().expandEntity(currentGroup);
    String currentAppId = currentGroup.getAppApplication().getAppid().toString();

    // 查找目标功能组targetGroup
    AppFuncgroup targetGroup = AppFuncgroup.FACTORY.create();
    targetGroup.setFuncgroupid(NumberUtils.createBigDecimal(targetGroupId));
    getDASTemplate().expandEntity(targetGroup);
    String targetAppId = targetGroup.getAppApplication().getAppid().toString();

    // 查找当前功能组的所有子孙 funcGroups
    AppFuncgroup[] groups = getChildFuncGroups(currentGroup);

    // 遍历funcGroups
    List<AppFuncgroup> updateList = new ArrayList<AppFuncgroup>();
    List<String> idList = new ArrayList<String>();
    for (AppFuncgroup funcGroup : groups) {
      // 为当前功能组
      if (StringUtils.equals(funcGroup.getFuncgroupid().toString(), funcGroupId)) {
        // 修改当前功能组的父功能组
        funcGroup.setAppFuncgroup(targetGroup);
        funcGroup.setFuncgroupseq(targetGroup.getFuncgroupseq() + funcGroupId + ".");
      } else {
        funcGroup.setFuncgroupseq(
            StringUtils.replace(
                funcGroup.getFuncgroupseq(),
                currentGroup.getFuncgroupseq(),
                targetGroup.getFuncgroupseq() + funcGroupId + "."));
      }
      // 如果应用发生改变修改所有子孙的appid
      if (!StringUtils.equals(currentAppId, targetAppId)) {
        funcGroup.setAppApplication(targetGroup.getAppApplication());
      }
      updateList.add(funcGroup);
      idList.add(funcGroup.getFuncgroupid().toString());
    }
    targetGroup.setSubcount(
        targetGroup.getSubcount().add(NumberUtils.createBigDecimal(String.valueOf(groups.length))));
    updateList.add(targetGroup);
    try {
      // 批量更新子功能组,功能组,父功能组
      getDASTemplate().updateEntityBatch(updateList.toArray(new AppFuncgroup[updateList.size()]));
      // 如果应用改变了需要更新资源
      if (!StringUtils.equals(currentAppId, targetAppId)) {
        BeanFactory beanFactory = BeanFactory.newInstance();
        IAppFunctionService functionService = beanFactory.getBean("AppFunctionBean");
        String[] funcGroupIds = idList.toArray(new String[idList.size()]);
        AppFunction[] functions = functionService.getFunctionsByFuncGroupIds(funcGroupIds);
        // 更新资源
        functionService.updateResoucesBatch(functions);
      }
    } catch (Throwable t) {
      log.error(
          "Update funcgroup failure, please do the operation again or contact the sysadmin.", t);
    }
  }
Ejemplo n.º 2
0
 public void addAppFuncgroup(AppFuncgroup appFuncgroup) {
   appFuncgroup.setTenant_id(TenantManager.getCurrentTenantID());
   try {
     getDASTemplate().insertEntity(appFuncgroup);
   } catch (Throwable t) {
     log.error(
         "Insert funcgroup [funcgroupid="
             + appFuncgroup.getFuncgroupid()
             + "] failure, please do the operation again or contact the sysadmin.",
         t);
   }
 }
Ejemplo n.º 3
0
 public void updateAppFuncgroup(AppFuncgroup appFuncgroup) {
   try {
     // 更新功能组下所有功能resource
     updateResources(appFuncgroup);
     getDASTemplate().updateEntity(appFuncgroup);
   } catch (Throwable t) {
     log.error(
         "Update funcgroup [funcgroupid="
             + appFuncgroup.getFuncgroupid()
             + "] failure, please do the operation again or contact the sysadmin.",
         t);
   }
 }
Ejemplo n.º 4
0
 public void deleteFuncGroupById(String id) {
   AppFuncgroup appFuncgroup = AppFuncgroup.FACTORY.create();
   appFuncgroup.setFuncgroupid(NumberUtils.createBigDecimal(id));
   try {
     getDASTemplate().deleteEntityCascade(appFuncgroup);
   } catch (Throwable t) {
     log.error(
         "Delete funcgroup [funcgroupid="
             + appFuncgroup.getFuncgroupid()
             + "] failure, please do the operation again or contact the sysadmin.",
         t);
   }
 }
Ejemplo n.º 5
0
  private void updateResources(AppFuncgroup appFuncgroup) {
    AppFuncgroup[] appFuncgroups = getChildFuncGroups(appFuncgroup);

    // 获得funcGroupid数组
    String[] funcGroupIds = new String[appFuncgroups.length];
    for (int i = 0; i < appFuncgroups.length; i++) {
      AppFuncgroup funcgroup = appFuncgroups[i];
      funcGroupIds[i] = funcgroup.getFuncgroupid().toString();
    }
    BeanFactory beanFactory = BeanFactory.newInstance();
    IAppFunctionService functionService = beanFactory.getBean("AppFunctionBean");
    AppFunction[] functions = functionService.getFunctionsByFuncGroupIds(funcGroupIds);
    // 更新资源
    functionService.updateResoucesBatch(functions);
  }