@ -66,15 +66,16 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long>
@@ -66,15 +66,16 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long>
// ========== 核心:查询按钮配置VO(合并当前用户所有角色) ==========
@Override
public Map < String , Set < String > > getButtonConfigVo ( Long formId ) {
try {
// 1. 获取当前登录用户的所有角色
Set < Long > roleIds = getCurrentUserRoleIds ( ) ;
// Set<Long> roleIds = CollectionUtil.newHashSet(2080534691714174976L, 1694263314487447643L);
if ( CollectionUtil . isEmpty ( roleIds ) ) {
return Collections . emptyMap ( ) ;
return buildEmptyResultForAllForms ( ) ;
}
List < RoleFormButton > roleFormButtonList = mapper . selectList ( new LambdaQueryWrapper < RoleFormButton > ( ) . in ( RoleFormButton : : getRoleId , roleIds ) ) ;
if ( CollectionUtil . isEmpty ( roleFormButtonList ) ) {
return Collections . emptyMap ( ) ;
return buildEmptyResultForAllForms ( ) ;
}
// 2. 遍历所有角色,合并各角色在该表单的勾选按钮(取并集)
Map < String , Set < String > > roleCheckedNamesMap = new HashMap < > ( ) ;
@ -87,6 +88,10 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long>
@@ -87,6 +88,10 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long>
roleCheckedNamesMap . computeIfAbsent ( Long . toString ( roleFormButton . getFormId ( ) ) , k - > new HashSet < > ( ) ) . addAll ( checkedNames ) ;
}
return roleCheckedNamesMap ;
} catch ( Exception e ) {
log . error ( "获取按钮配置失败" , e ) ;
}
return buildEmptyResultForAllForms ( ) ;
}
/ * *
@ -100,6 +105,26 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long>
@@ -100,6 +105,26 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long>
return StrUtil . split ( tokenData . getRoleIds ( ) , ',' ) . stream ( ) . map ( Long : : valueOf ) . collect ( Collectors . toSet ( ) ) ;
}
/ * *
* 构建空结果 Map : 查询所有已发布在线表单中有按钮的 formId , value 均为空 Set 。
* 确保前端在没有角色按钮权限配置时仍能拿到完整的 formId key 列表 。
* /
private Map < String , Set < String > > buildEmptyResultForAllForms ( ) {
Map < String , Set < String > > result = new HashMap < > ( ) ;
List < OnlinePage > pageList = onlinePageService . queryByEnableList ( ) ;
if ( CollectionUtil . isEmpty ( pageList ) ) {
return result ;
}
Set < Long > pageIdSet = pageList . stream ( ) . map ( OnlinePage : : getPageId ) . collect ( Collectors . toSet ( ) ) ;
OnlineForm filter = new OnlineForm ( ) ;
filter . setPageIdSet ( pageIdSet ) ;
List < OnlineForm > formList = onlineFormService . getOnlineFormList ( filter , null ) ;
for ( OnlineForm form : formList ) {
result . put ( form . getFormId ( ) . toString ( ) , Collections . emptySet ( ) ) ;
}
return result ;
}
// ========== 核心:批量保存按钮配置(事务) ==========
@Override
@Transactional ( rollbackFor = Exception . class )