@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.Page ;
import com.github.pagehelper.page.PageMethod ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.lang3.StringUtils ;
import org.jetbrains.annotations.NotNull ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
@ -64,50 +65,28 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long>
@@ -64,50 +65,28 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long>
// ========== 核心:查询按钮配置VO(合并当前用户所有角色) ==========
@Override
public Map < String , Object > getButtonConfigVo ( Long formId ) {
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( "formId" , formId ) ;
// 1. 获取 widgetJson,提取所有开启的按钮
OnlineForm onlineForm = onlineFormService . getById ( formId ) ;
if ( onlineForm = = null ) {
result . put ( "buttonList" , Collections . emptyList ( ) ) ;
return result ;
}
List < WidgetJsonButtonParser . ButtonInfo > enabledButtons = WidgetJsonButtonParser . extractEnabledButtons ( onlineForm . getWidgetJson ( ) ) ;
// 2. 获取当前登录用户的所有角色
public Map < String , Set < String > > getButtonConfigVo ( Long formId ) {
// 1. 获取当前登录用户的所有角色
Set < Long > roleIds = getCurrentUserRoleIds ( ) ;
// 3. 遍历所有角色,合并各角色在该表单的勾选按钮(取并集)
Set < String > checkedNames = new HashSet < > ( ) ;
if ( CollectionUtil . isNotEmpty ( roleIds ) ) {
for ( Long roleId : roleIds ) {
RoleFormButton config = getByRoleIdAndFormId ( roleId , formId ) ;
if ( config ! = null & & config . getButtonConfig ( ) ! = null ) {
List < WidgetJsonButtonParser . ButtonInfo > savedButtons =
JSON . parseArray ( config . getButtonConfig ( ) ,
WidgetJsonButtonParser . ButtonInfo . class ) ;
for ( WidgetJsonButtonParser . ButtonInfo btn : savedButtons ) {
if ( Boolean . TRUE . equals ( btn . getEnabled ( ) ) ) {
checkedNames . add ( btn . getName ( ) ) ;
}
}
}
}
// Set<Long> roleIds = CollectionUtil.newHashSet(2080534691714174976L, 1694263314487447643L);
if ( CollectionUtil . isEmpty ( roleIds ) ) {
return Collections . emptyMap ( ) ;
}
// 4. 合并:表单所有开启的按钮 + 是否勾选
List < Map < String , Object > > buttonList = new ArrayList < > ( ) ;
for ( WidgetJsonButtonParser . ButtonInfo btn : enabledButtons ) {
Map < String , Object > item = new HashMap < > ( ) ;
item . put ( "name" , btn . getName ( ) ) ;
item . put ( "checked" , checkedNames . contains ( btn . getName ( ) ) ) ;
buttonList . add ( item ) ;
List < RoleFormButton > roleFormButtonList = mapper . selectList ( new LambdaQueryWrapper < RoleFormButton > ( ) . in ( RoleFormButton : : getRoleId , roleIds ) ) ;
if ( CollectionUtil . isEmpty ( roleFormButtonList ) ) {
return Collections . emptyMap ( ) ;
}
result . put ( "buttonList" , buttonList ) ;
return result ;
// 2. 遍历所有角色,合并各角色在该表单的勾选按钮(取并集)
Map < String , Set < String > > roleCheckedNamesMap = new HashMap < > ( ) ;
for ( RoleFormButton roleFormButton : roleFormButtonList ) {
if ( StringUtils . isBlank ( roleFormButton . getButtonConfig ( ) ) ) {
continue ;
}
List < WidgetJsonButtonParser . ButtonInfo > buttonInfoList = JSON . parseArray ( roleFormButton . getButtonConfig ( ) , WidgetJsonButtonParser . ButtonInfo . class ) ;
Set < String > checkedNames = buttonInfoList . stream ( ) . filter ( btn - > btn . getEnabled ( ) ! = null & & btn . getEnabled ( ) ) . map ( WidgetJsonButtonParser . ButtonInfo : : getName ) . collect ( Collectors . toSet ( ) ) ;
roleCheckedNamesMap . computeIfAbsent ( Long . toString ( roleFormButton . getFormId ( ) ) , k - > new HashSet < > ( ) ) . addAll ( checkedNames ) ;
}
return roleCheckedNamesMap ;
}
/ * *