|
|
|
@ -66,27 +66,32 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long> |
|
|
|
// ========== 核心:查询按钮配置VO(合并当前用户所有角色) ==========
|
|
|
|
// ========== 核心:查询按钮配置VO(合并当前用户所有角色) ==========
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<String, Set<String>> getButtonConfigVo(Long formId) { |
|
|
|
public Map<String, Set<String>> getButtonConfigVo(Long formId) { |
|
|
|
// 1. 获取当前登录用户的所有角色
|
|
|
|
try { |
|
|
|
Set<Long> roleIds = getCurrentUserRoleIds(); |
|
|
|
// 1. 获取当前登录用户的所有角色
|
|
|
|
|
|
|
|
Set<Long> roleIds = getCurrentUserRoleIds(); |
|
|
|
// Set<Long> roleIds = CollectionUtil.newHashSet(2080534691714174976L, 1694263314487447643L);
|
|
|
|
// Set<Long> roleIds = CollectionUtil.newHashSet(2080534691714174976L, 1694263314487447643L);
|
|
|
|
if (CollectionUtil.isEmpty(roleIds)) { |
|
|
|
if (CollectionUtil.isEmpty(roleIds)) { |
|
|
|
return Collections.emptyMap(); |
|
|
|
return buildEmptyResultForAllForms(); |
|
|
|
} |
|
|
|
} |
|
|
|
List<RoleFormButton> roleFormButtonList = mapper.selectList(new LambdaQueryWrapper<RoleFormButton>().in(RoleFormButton::getRoleId, roleIds)); |
|
|
|
List<RoleFormButton> roleFormButtonList = mapper.selectList(new LambdaQueryWrapper<RoleFormButton>().in(RoleFormButton::getRoleId, roleIds)); |
|
|
|
if (CollectionUtil.isEmpty(roleFormButtonList)) { |
|
|
|
if (CollectionUtil.isEmpty(roleFormButtonList)) { |
|
|
|
return Collections.emptyMap(); |
|
|
|
return buildEmptyResultForAllForms(); |
|
|
|
} |
|
|
|
} |
|
|
|
// 2. 遍历所有角色,合并各角色在该表单的勾选按钮(取并集)
|
|
|
|
// 2. 遍历所有角色,合并各角色在该表单的勾选按钮(取并集)
|
|
|
|
Map<String, Set<String>> roleCheckedNamesMap = new HashMap<>(); |
|
|
|
Map<String, Set<String>> roleCheckedNamesMap = new HashMap<>(); |
|
|
|
for (RoleFormButton roleFormButton : roleFormButtonList) { |
|
|
|
for (RoleFormButton roleFormButton : roleFormButtonList) { |
|
|
|
if (StringUtils.isBlank(roleFormButton.getButtonConfig())) { |
|
|
|
if (StringUtils.isBlank(roleFormButton.getButtonConfig())) { |
|
|
|
continue; |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
List<WidgetJsonButtonParser.ButtonInfo> buttonInfoList = JSON.parseArray(roleFormButton.getButtonConfig(), WidgetJsonButtonParser.ButtonInfo.class); |
|
|
|
return roleCheckedNamesMap; |
|
|
|
Set<String> checkedNames = buttonInfoList.stream().filter(btn -> btn.getEnabled() != null && btn.getEnabled()).map(WidgetJsonButtonParser.ButtonInfo::getName).collect(Collectors.toSet()); |
|
|
|
} catch (Exception e) { |
|
|
|
roleCheckedNamesMap.computeIfAbsent(Long.toString(roleFormButton.getFormId()), k -> new HashSet<>()).addAll(checkedNames); |
|
|
|
log.error("获取按钮配置失败", e); |
|
|
|
} |
|
|
|
} |
|
|
|
return roleCheckedNamesMap; |
|
|
|
return buildEmptyResultForAllForms(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -100,6 +105,26 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long> |
|
|
|
return StrUtil.split(tokenData.getRoleIds(), ',').stream().map(Long::valueOf).collect(Collectors.toSet()); |
|
|
|
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 |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|