|
|
|
@ -2,8 +2,7 @@ package apelet.tenantadmin.tenant.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import apelet.common.core.base.dao.BaseDaoMapper; |
|
|
|
import apelet.common.core.base.dao.BaseDaoMapper; |
|
|
|
import apelet.common.core.base.service.BaseService; |
|
|
|
import apelet.common.core.base.service.BaseService; |
|
|
|
import apelet.common.core.object.CallResult; |
|
|
|
import apelet.common.core.object.*; |
|
|
|
import apelet.common.core.object.MyOrderParam; |
|
|
|
|
|
|
|
import apelet.common.online.model.OnlineForm; |
|
|
|
import apelet.common.online.model.OnlineForm; |
|
|
|
import apelet.common.online.model.OnlinePage; |
|
|
|
import apelet.common.online.model.OnlinePage; |
|
|
|
import apelet.common.online.service.OnlineFormService; |
|
|
|
import apelet.common.online.service.OnlineFormService; |
|
|
|
@ -15,8 +14,11 @@ import apelet.tenantadmin.tenant.model.RoleFormButton; |
|
|
|
import apelet.tenantadmin.tenant.service.IRoleFormButtonService; |
|
|
|
import apelet.tenantadmin.tenant.service.IRoleFormButtonService; |
|
|
|
import apelet.tenantadmin.tenant.util.WidgetJsonButtonParser; |
|
|
|
import apelet.tenantadmin.tenant.util.WidgetJsonButtonParser; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
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 lombok.extern.slf4j.Slf4j; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -60,11 +62,10 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long> |
|
|
|
return mapper.getListByFilter(filter, orderBy); |
|
|
|
return mapper.getListByFilter(filter, orderBy); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ========== 核心:查询按钮配置VO ==========
|
|
|
|
// ========== 核心:查询按钮配置VO(合并当前用户所有角色) ==========
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<String, Object> getButtonConfigVo(Long roleId, Long formId) { |
|
|
|
public Map<String, Object> getButtonConfigVo(Long formId) { |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
result.put("roleId", roleId); |
|
|
|
|
|
|
|
result.put("formId", formId); |
|
|
|
result.put("formId", formId); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 获取 widgetJson,提取所有开启的按钮
|
|
|
|
// 1. 获取 widgetJson,提取所有开启的按钮
|
|
|
|
@ -73,15 +74,16 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long> |
|
|
|
result.put("buttonList", Collections.emptyList()); |
|
|
|
result.put("buttonList", Collections.emptyList()); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<WidgetJsonButtonParser.ButtonInfo> enabledButtons = WidgetJsonButtonParser.extractEnabledButtons(onlineForm.getWidgetJson()); |
|
|
|
|
|
|
|
|
|
|
|
List<WidgetJsonButtonParser.ButtonInfo> enabledButtons = |
|
|
|
// 2. 获取当前登录用户的所有角色
|
|
|
|
WidgetJsonButtonParser.extractEnabledButtons(onlineForm.getWidgetJson()); |
|
|
|
Set<Long> roleIds = getCurrentUserRoleIds(); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 查询已存储的配置
|
|
|
|
// 3. 遍历所有角色,合并各角色在该表单的勾选按钮(取并集)
|
|
|
|
RoleFormButton config = getByRoleIdAndFormId(roleId, formId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 解析已勾选的按钮名称集合
|
|
|
|
|
|
|
|
Set<String> checkedNames = new HashSet<>(); |
|
|
|
Set<String> checkedNames = new HashSet<>(); |
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(roleIds)) { |
|
|
|
|
|
|
|
for (Long roleId : roleIds) { |
|
|
|
|
|
|
|
RoleFormButton config = getByRoleIdAndFormId(roleId, formId); |
|
|
|
if (config != null && config.getButtonConfig() != null) { |
|
|
|
if (config != null && config.getButtonConfig() != null) { |
|
|
|
List<WidgetJsonButtonParser.ButtonInfo> savedButtons = |
|
|
|
List<WidgetJsonButtonParser.ButtonInfo> savedButtons = |
|
|
|
JSON.parseArray(config.getButtonConfig(), |
|
|
|
JSON.parseArray(config.getButtonConfig(), |
|
|
|
@ -92,6 +94,8 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long> |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 4. 合并:表单所有开启的按钮 + 是否勾选
|
|
|
|
// 4. 合并:表单所有开启的按钮 + 是否勾选
|
|
|
|
List<Map<String, Object>> buttonList = new ArrayList<>(); |
|
|
|
List<Map<String, Object>> buttonList = new ArrayList<>(); |
|
|
|
@ -102,11 +106,21 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long> |
|
|
|
buttonList.add(item); |
|
|
|
buttonList.add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
result.put("id", config != null ? config.getId() : null); |
|
|
|
|
|
|
|
result.put("buttonList", buttonList); |
|
|
|
result.put("buttonList", buttonList); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取当前登录用户的所有角色ID集合(从 TokenData 中解析)。 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Set<Long> getCurrentUserRoleIds() { |
|
|
|
|
|
|
|
TokenData tokenData = TokenData.takeFromRequest(); |
|
|
|
|
|
|
|
if (tokenData == null || StrUtil.isBlank(tokenData.getRoleIds())) { |
|
|
|
|
|
|
|
return Collections.emptySet(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return StrUtil.split(tokenData.getRoleIds(), ',').stream().map(Long::valueOf).collect(Collectors.toSet()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ========== 核心:批量保存按钮配置(事务) ==========
|
|
|
|
// ========== 核心:批量保存按钮配置(事务) ==========
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@ -190,7 +204,7 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long> |
|
|
|
|
|
|
|
|
|
|
|
private static @NotNull Map<String, Object> getButtonResult(OnlineForm form, List<WidgetJsonButtonParser.ButtonInfo> buttons) { |
|
|
|
private static @NotNull Map<String, Object> getButtonResult(OnlineForm form, List<WidgetJsonButtonParser.ButtonInfo> buttons) { |
|
|
|
Map<String, Object> item = new HashMap<>(); |
|
|
|
Map<String, Object> item = new HashMap<>(); |
|
|
|
item.put("formId", form.getFormId()); |
|
|
|
item.put("formId", form.getFormId().toString()); |
|
|
|
item.put("formName", form.getFormName()); |
|
|
|
item.put("formName", form.getFormName()); |
|
|
|
List<Map<String, Object>> buttonList = new ArrayList<>(); |
|
|
|
List<Map<String, Object>> buttonList = new ArrayList<>(); |
|
|
|
if (!CollectionUtils.isEmpty(buttons)) { |
|
|
|
if (!CollectionUtils.isEmpty(buttons)) { |
|
|
|
@ -206,24 +220,82 @@ public class RoleFormButtonServiceImpl extends BaseService<RoleFormButton, Long> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public List<Map<String, Object>> listAllFormButtons(MyOrderParam orderParam) { |
|
|
|
public MyPageData<Map<String, Object>> listAllFormButtons(Long roleId, MyOrderParam orderParam, MyPageParam pageParam) { |
|
|
|
// 查询已发布的 page
|
|
|
|
// 1. 查询已发布的 page(不分页,获取全量)
|
|
|
|
List<OnlinePage> pageList = onlinePageService.queryByEnableList(); |
|
|
|
List<OnlinePage> pageList = onlinePageService.queryByEnableList(); |
|
|
|
if (CollectionUtil.isEmpty(pageList)) { |
|
|
|
if (CollectionUtil.isEmpty(pageList)) { |
|
|
|
return Collections.emptyList(); |
|
|
|
return new MyPageData<>(Collections.emptyList(), 0L); |
|
|
|
} |
|
|
|
} |
|
|
|
Set<Long> pageIdSet = pageList.stream().map(OnlinePage::getPageId).collect(Collectors.toSet()); |
|
|
|
Set<Long> pageIdSet = pageList.stream().map(OnlinePage::getPageId).collect(Collectors.toSet()); |
|
|
|
// 分页查询在线表单
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 分页查询 OnlineForm
|
|
|
|
|
|
|
|
if (pageParam != null) { |
|
|
|
|
|
|
|
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize()); |
|
|
|
|
|
|
|
} |
|
|
|
String orderBy = MyOrderParam.buildOrderBy(orderParam, OnlineForm.class); |
|
|
|
String orderBy = MyOrderParam.buildOrderBy(orderParam, OnlineForm.class); |
|
|
|
OnlineForm onlineForm = new OnlineForm(); |
|
|
|
OnlineForm onlineForm = new OnlineForm(); |
|
|
|
onlineForm.setPageIdSet(pageIdSet); |
|
|
|
onlineForm.setPageIdSet(pageIdSet); |
|
|
|
List<OnlineForm> formList = onlineFormService.getOnlineFormList(null, orderBy); |
|
|
|
List<OnlineForm> formList = onlineFormService.getOnlineFormList(onlineForm, orderBy); |
|
|
|
|
|
|
|
long total = formList instanceof Page ? ((Page) formList).getTotal() : formList.size(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 如果传了 roleId,查询 RoleFormButton 获取勾选状态
|
|
|
|
|
|
|
|
Map<Long, Set<String>> formCheckedMap = Collections.emptyMap(); |
|
|
|
|
|
|
|
if (roleId != null) { |
|
|
|
|
|
|
|
List<RoleFormButton> configList = this.listByRoleId(roleId); |
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(configList)) { |
|
|
|
|
|
|
|
formCheckedMap = new HashMap<>(configList.size()); |
|
|
|
|
|
|
|
for (RoleFormButton config : configList) { |
|
|
|
|
|
|
|
formCheckedMap.put(config.getFormId(), extractCheckedNames(config)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 构建结果
|
|
|
|
List<Map<String, Object>> result = new ArrayList<>(); |
|
|
|
List<Map<String, Object>> result = new ArrayList<>(); |
|
|
|
for (OnlineForm form : formList) { |
|
|
|
for (OnlineForm form : formList) { |
|
|
|
List<WidgetJsonButtonParser.ButtonInfo> buttons = |
|
|
|
List<WidgetJsonButtonParser.ButtonInfo> buttons = |
|
|
|
WidgetJsonButtonParser.extractEnabledButtons(form.getWidgetJson()); |
|
|
|
WidgetJsonButtonParser.extractEnabledButtons(form.getWidgetJson()); |
|
|
|
result.add(getButtonResult(form, buttons)); |
|
|
|
Map<String, Object> item = getButtonResult(form, buttons); |
|
|
|
|
|
|
|
if (roleId != null) { |
|
|
|
|
|
|
|
Set<String> checkedNames = formCheckedMap.get(form.getFormId()); |
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(checkedNames)) { |
|
|
|
|
|
|
|
applyCheckedStatus(item, checkedNames); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result.add(item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new MyPageData<>(result, total); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 从 RoleFormButton.buttonConfig 中提取已勾选的按钮名称集合。 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Set<String> extractCheckedNames(RoleFormButton config) { |
|
|
|
|
|
|
|
if (config.getButtonConfig() == null) { |
|
|
|
|
|
|
|
return Collections.emptySet(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<WidgetJsonButtonParser.ButtonInfo> savedButtons = |
|
|
|
|
|
|
|
JSON.parseArray(config.getButtonConfig(), WidgetJsonButtonParser.ButtonInfo.class); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(savedButtons)) { |
|
|
|
|
|
|
|
return Collections.emptySet(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return savedButtons.stream() |
|
|
|
|
|
|
|
.filter(b -> Boolean.TRUE.equals(b.getEnabled())) |
|
|
|
|
|
|
|
.map(WidgetJsonButtonParser.ButtonInfo::getName) |
|
|
|
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 将已勾选的按钮名称集合应用到返回结果中。 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void applyCheckedStatus(Map<String, Object> item, Set<String> checkedNames) { |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
|
|
|
List<Map<String, Object>> buttonList = |
|
|
|
|
|
|
|
(List<Map<String, Object>>) item.get("buttonList"); |
|
|
|
|
|
|
|
if (buttonList != null) { |
|
|
|
|
|
|
|
for (Map<String, Object> btn : buttonList) { |
|
|
|
|
|
|
|
btn.put("checked", checkedNames.contains(btn.get("name"))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|