REQ-2303: 支持自定义按钮
This commit is contained in:
parent
41ac780a08
commit
383a1e1f0d
@ -43,7 +43,7 @@ public class CustomButtonConfig {
|
||||
* 创建对待办发起人总是可见的按钮, 忽略待办状态
|
||||
*/
|
||||
public static CustomButtonConfig alwaysVisibleForExecutor() {
|
||||
return visibleForExecutorAndStates(Collections.emptyList());
|
||||
return visibleForExecutorAndTodoStates(Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,11 +63,11 @@ public class CustomButtonConfig {
|
||||
*
|
||||
* @param visibleTodoStates 按钮可见的状态. 为空则忽略状态, 都可见
|
||||
*/
|
||||
public static CustomButtonConfig visibleForExecutorAndStates(PendingMessageStateEnum... visibleTodoStates) {
|
||||
public static CustomButtonConfig visibleForExecutorAndTodoStates(PendingMessageStateEnum... visibleTodoStates) {
|
||||
PendingMessageStateEnum[] states = visibleTodoStates;
|
||||
if (states == null)
|
||||
states = new PendingMessageStateEnum[0];
|
||||
return visibleForExecutorAndStates(Arrays.asList(states));
|
||||
return visibleForExecutorAndTodoStates(Arrays.asList(states));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,7 +92,7 @@ public class CustomButtonConfig {
|
||||
*
|
||||
* @param visibleTodoStates 按钮可见的状态. 为空则忽略状态, 都可见
|
||||
*/
|
||||
public static CustomButtonConfig visibleForExecutorAndStates(List<PendingMessageStateEnum> visibleTodoStates) {
|
||||
public static CustomButtonConfig visibleForExecutorAndTodoStates(List<PendingMessageStateEnum> visibleTodoStates) {
|
||||
CustomButtonConfig customButtonConfig = new CustomButtonConfig();
|
||||
customButtonConfig.setActorType(TodoActorType.TODO_EXECUTOR);
|
||||
if (visibleTodoStates != null) {
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package cn.axzo.msg.center.api.custombutton;
|
||||
|
||||
import cn.axzo.msg.center.service.dto.ButtonRouterDTO;
|
||||
import cn.axzo.msg.center.service.enums.BizCategoryEnum;
|
||||
import cn.axzo.msg.center.service.enums.PendingMessageStateEnum;
|
||||
import cn.axzo.msg.center.service.enums.RouterButtonSourceEnum;
|
||||
import cn.axzo.msg.center.service.pending.response.PendingMessageResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -20,28 +18,20 @@ import static java.util.stream.Collectors.toList;
|
||||
public class CustomButtonFilter {
|
||||
|
||||
public static void adjustCustomButtons(PendingMessageResponse response, boolean forPromoter) {
|
||||
// 非流程的待办按钮保持不变
|
||||
if (response.getBizCategory() == BizCategoryEnum.FLOW)
|
||||
response.setButtonRouters(filterFlowCustomButtons(response, forPromoter));
|
||||
response.setButtonRouters(filterCustomButtons(response, forPromoter));
|
||||
}
|
||||
|
||||
public static List<ButtonRouterDTO> filterFlowCustomButtons(PendingMessageResponse response, boolean forPromoter) {
|
||||
public static List<ButtonRouterDTO> filterCustomButtons(PendingMessageResponse response, boolean forPromoter) {
|
||||
Function<String, CustomButton> findCustomBtnFun = btnKey -> {
|
||||
if(CollectionUtils.isEmpty(response.getCustomButtons()))
|
||||
if (CollectionUtils.isEmpty(response.getCustomButtons()))
|
||||
return null;
|
||||
return response.getCustomButtons().stream()
|
||||
.filter(i -> btnKey.equals(i.getButtonKey()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
};
|
||||
Function<ButtonRouterDTO, Boolean> filterCustomBtnFun = btn -> {
|
||||
// 已完成就不显示了
|
||||
if (response.getState() != PendingMessageStateEnum.HAS_BEEN_SENT)
|
||||
return false;
|
||||
Function<ButtonRouterDTO, Boolean> syncBtnFun = btn -> {
|
||||
// 没有配置可见的自定义的按钮
|
||||
// 这个判断不能放到整个方法的里面调用, 因为涉及到自定义的按钮
|
||||
if(CollectionUtils.isEmpty(response.getCustomButtons()))
|
||||
return false;
|
||||
CustomButton customBtn = findCustomBtnFun.apply(btn.getKey());
|
||||
if (customBtn == null || CollectionUtils.isEmpty(customBtn.getConfigs()))
|
||||
return false;
|
||||
@ -51,10 +41,10 @@ public class CustomButtonFilter {
|
||||
: c.isVisible(response.getState()));
|
||||
};
|
||||
return response.getButtonRouters().stream()
|
||||
.filter(btn -> {
|
||||
CustomButton customBtn = findCustomBtnFun.apply(btn.getKey());
|
||||
boolean isNormalTodoCustomBtn = customBtn == null && btn.getSource() == RouterButtonSourceEnum.CUSTOM;
|
||||
return isNormalTodoCustomBtn || filterCustomBtnFun.apply(btn);
|
||||
.filter(routerBtn -> {
|
||||
CustomButton syncBtn = findCustomBtnFun.apply(routerBtn.getKey());
|
||||
boolean isNormalCustomBtn = syncBtn == null && routerBtn.getSource() == RouterButtonSourceEnum.CUSTOM;
|
||||
return isNormalCustomBtn || syncBtnFun.apply(routerBtn);
|
||||
})
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user