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); } }
public AppFuncgroup[] getChildFuncGroups(AppFuncgroup appFuncgroup) { CriteriaType criteria = CriteriaType.FACTORY.create(); criteria.set_entity(AppFuncgroup.QNAME); criteria.set("_expr[1]/funcgroupseq", appFuncgroup.getFuncgroupseq()); criteria.set("_expr[1]/_op", "like"); criteria.set("_expr[1]/_likeRule", "end"); IDASCriteria dasCriteria = getDASTemplate().criteriaTypeToDASCriteria(criteria); AppFuncgroup[] results = getDASTemplate().queryEntitiesByCriteriaEntity(AppFuncgroup.class, dasCriteria); return results; }