|
|
|
@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.github.pagehelper.Page; |
|
|
|
import com.github.pagehelper.Page; |
|
|
|
import com.github.pagehelper.page.PageMethod; |
|
|
|
import com.github.pagehelper.page.PageMethod; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -64,50 +65,28 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long> |
|
|
|
|
|
|
|
|
|
|
|
// ========== 核心:查询按钮配置VO(合并当前用户所有角色) ==========
|
|
|
|
// ========== 核心:查询按钮配置VO(合并当前用户所有角色) ==========
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<String, Object> getButtonConfigVo(Long formId) { |
|
|
|
public Map<String, Set<String>> getButtonConfigVo(Long formId) { |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
// 1. 获取当前登录用户的所有角色
|
|
|
|
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. 获取当前登录用户的所有角色
|
|
|
|
|
|
|
|
Set<Long> roleIds = getCurrentUserRoleIds(); |
|
|
|
Set<Long> roleIds = getCurrentUserRoleIds(); |
|
|
|
|
|
|
|
// Set<Long> roleIds = CollectionUtil.newHashSet(2080534691714174976L, 1694263314487447643L);
|
|
|
|
// 3. 遍历所有角色,合并各角色在该表单的勾选按钮(取并集)
|
|
|
|
if (CollectionUtil.isEmpty(roleIds)) { |
|
|
|
Set<String> checkedNames = new HashSet<>(); |
|
|
|
return Collections.emptyMap(); |
|
|
|
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()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<RoleFormButton> roleFormButtonList = mapper.selectList(new LambdaQueryWrapper<RoleFormButton>().in(RoleFormButton::getRoleId, roleIds)); |
|
|
|
// 4. 合并:表单所有开启的按钮 + 是否勾选
|
|
|
|
if (CollectionUtil.isEmpty(roleFormButtonList)) { |
|
|
|
List<Map<String, Object>> buttonList = new ArrayList<>(); |
|
|
|
return Collections.emptyMap(); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 遍历所有角色,合并各角色在该表单的勾选按钮(取并集)
|
|
|
|
result.put("buttonList", buttonList); |
|
|
|
Map<String, Set<String>> roleCheckedNamesMap = new HashMap<>(); |
|
|
|
return result; |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|