REQ-3201: 用枚举替换字符串

This commit is contained in:
yanglin 2024-12-16 19:41:32 +08:00
parent 1e1ab4348a
commit 056ad95a68
9 changed files with 26 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package cn.axzo.msg.center.message.service.card;
import cn.axzo.msg.center.service.domain.card.StateImageConfig;
import cn.axzo.msg.center.service.enums.CardBizState;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
@ -18,11 +19,11 @@ public class CardStateImageConfigs {
return new CardStateImageConfigs(images);
}
public String determineStateImage(String bizStateCode) {
public String determineStateImage(CardBizState bizState) {
if (configs == null) return "";
return configs.stream()
.filter(StateImageConfig::isEnabled)
.filter(cfg -> cfg.getStateCode().equals(bizStateCode))
.filter(cfg -> cfg.determineBizState().equals(bizState))
.findFirst()
.map(StateImageConfig::determineImageUrl)
.orElse(null);

View File

@ -197,7 +197,7 @@ public class CardSupport {
info.setReceiverOuId(card.getReceiverOuId());
info.setReceiverWorkspaceId(card.getReceiverWorkspaceId());
info.setReceiverAppType(card.getReceiverAppType());
info.setState(card.getBizState());
info.setBizState(card.getBizState());
info.setImTaskId(card.getImTaskId());
info.setTemplateCode(card.getTemplateCode());
return info;

View File

@ -30,7 +30,6 @@ import cn.axzo.msg.center.service.dto.MessageCardContentItemDTO;
import cn.axzo.msg.center.service.dto.MessageTemplateButtonV3DTO;
import cn.axzo.msg.center.service.dto.MessageTemplateCardJumpV3DTO;
import cn.axzo.msg.center.service.dto.StateImageConfigDTO;
import cn.axzo.msg.center.service.enums.CardBizState;
import cn.axzo.msg.center.service.enums.MessageCategoryEnum;
import cn.axzo.msg.center.service.enums.PushTerminalEnum;
import cn.axzo.msg.center.service.enums.StatusEnum;
@ -588,8 +587,8 @@ public class MessageTemplateV3ServiceImpl implements MessageTemplateV3Service {
}
return record.getStateImageConfigs().stream().map(item -> StateImageConfigDTO.builder()
.stateCode(item.getStateCode())
.description(Objects.nonNull(CardBizState.getByCode(item.getStateCode())) ? CardBizState.getByCode(item.getStateCode()).getDescription() : "")
.stateCode(item.determineBizState().getCode())
.description(item.determineBizState().getDescription())
.enabled(item.isEnabled())
.imageUrl(item.getImageUrl())
.build()).collect(Collectors.toList());

View File

@ -97,7 +97,7 @@ public class TodoWithCardWrapper {
* 卡片更新状态-完成
*/
public void cardCompleteStateByTodoList(List<Todo> todoList) {
this.cardUpdateStateByTodoList(todoList,CardBizState.END.getCode(), CardState.COMPLETED);
this.cardUpdateStateByTodoList(todoList,CardBizState.END, CardState.COMPLETED);
}
/**
@ -105,27 +105,27 @@ public class TodoWithCardWrapper {
* 暂时不需要
*/
public void cardRollbackStateByTodoList(List<Todo> todoList) {
this.cardUpdateStateByTodoList(todoList, CardBizState.ABORTED.getCode(), CardState.CREATED);
this.cardUpdateStateByTodoList(todoList, CardBizState.ABORTED, CardState.CREATED);
}
/**
* 卡片更新状态-撤销
*/
public void cardRevokeStateByTodoList(List<Todo> todoList) {
this.cardUpdateStateByTodoList(todoList, CardBizState.REVOKED.getCode(), CardState.CREATED);
this.cardUpdateStateByTodoList(todoList, CardBizState.REVOKED, CardState.CREATED);
}
/**
* 卡片更新状态-执行中
*/
public void cardProcessingStateByTodoList(List<Todo> todoList) {
this.cardUpdateStateByTodoList(todoList, CardBizState.PENDING.getCode(), CardState.CREATED);
this.cardUpdateStateByTodoList(todoList, CardBizState.PENDING, CardState.CREATED);
}
/**
* 卡片更新完成状态
*/
private void cardUpdateStateByTodoList(List<Todo> todoList, String bizState, CardState cardState) {
private void cardUpdateStateByTodoList(List<Todo> todoList, CardBizState bizState, CardState cardState) {
log.info("TodoWithCardWrapper#cardUpdateStateByTodoList start,todoList:{},bizState:{},cardState:{}", JSON.toJSONString(todoList), bizState, cardState);
try {
//1 构建对象
@ -142,7 +142,7 @@ public class TodoWithCardWrapper {
/**
* 构建卡片完成状态
*/
private List<CardUpdateStateRequest> buildCardStateByTodoList(List<Todo> todoList, String bizState, CardState cardState) {
private List<CardUpdateStateRequest> buildCardStateByTodoList(List<Todo> todoList, CardBizState bizState, CardState cardState) {
if (CollectionUtils.isNotEmpty(todoList)) {
return Lists.newArrayList();
}
@ -184,7 +184,7 @@ public class TodoWithCardWrapper {
if (StringUtils.isNotBlank(param.getRouterParams())) {
sendRequest.setRouterParam(JSON.parseObject(param.getRouterParams()));
}
sendRequest.setStateInfo(CardStateInfo.buildCardStateInfo(CardBizState.PENDING.getCode(), CardState.CREATED));
sendRequest.setStateInfo(CardStateInfo.buildCardStateInfo(CardBizState.PENDING, CardState.CREATED));
sendRequest.setIdempotentCode(new IdBuilder(false)
.append(param.getBizCode())

View File

@ -30,8 +30,11 @@ public class StateImageConfig {
public String determineImageUrl() {
if (StringUtils.isNotBlank(imageUrl)) return imageUrl;
CardBizState state = CodeDefinition.findByCode(CardBizState.class, stateCode).orElse(null);
CardBizState state = determineBizState();
return state == null ? null : state.getDefaultImageUrl();
}
public CardBizState determineBizState() {
return CodeDefinition.findByCode(CardBizState.class, stateCode).orElse(null);
}
}

View File

@ -13,9 +13,9 @@ import lombok.Setter;
public class CardStateInfo {
/**
* 业务状态编辑. 可参考 {@link CardBizState#getCode()}
* 业务状态编辑
*/
private String bizState;
private CardBizState bizState;
/**
* 卡片状态
@ -25,7 +25,7 @@ public class CardStateInfo {
/**
* 构建对象
*/
public static CardStateInfo buildCardStateInfo(String bizStateCode, CardState cardState) {
public static CardStateInfo buildCardStateInfo(CardBizState bizStateCode, CardState cardState) {
CardStateInfo cardStateInfo = new CardStateInfo();
cardStateInfo.setBizState(bizStateCode);
cardStateInfo.setCardState(cardState);

View File

@ -1,6 +1,7 @@
package cn.axzo.msg.center.service.pending.response;
import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.msg.center.service.enums.CardBizState;
import lombok.Getter;
import lombok.Setter;
@ -17,7 +18,7 @@ public class CardInfo {
private Long receiverOuId;
private Long receiverWorkspaceId;
private AppTypeEnum receiverAppType;
private String state;
private CardBizState bizState;
private Long imTaskId;
private String templateCode;
}

View File

@ -5,6 +5,7 @@ import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.im.center.common.enums.YesOrNo;
import cn.axzo.msg.center.domain.persistence.BaseEntityExt;
import cn.axzo.msg.center.domain.utils.IgnorePropsJsonTypeHandler;
import cn.axzo.msg.center.service.enums.CardBizState;
import cn.axzo.msg.center.service.enums.CardState;
import cn.axzo.msg.center.service.pending.card.domain.CardButtonState;
import cn.axzo.msg.center.service.pending.card.domain.CardButtonStates;
@ -72,7 +73,7 @@ public class Card extends BaseEntityExt<Card> implements CardContent {
/**
* 业务状态
*/
private String bizState;
private CardBizState bizState;
/**
* 卡片状态

View File

@ -3,6 +3,7 @@ package cn.axzo.msg.center.domain.entity;
import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.msg.center.domain.persistence.BaseEntityExt;
import cn.axzo.msg.center.domain.utils.IgnorePropsJsonTypeHandler;
import cn.axzo.msg.center.service.enums.CardBizState;
import cn.axzo.msg.center.service.enums.CardState;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
@ -93,7 +94,7 @@ public class CardLog extends BaseEntityExt<CardLog> {
/**
* 业务状态
*/
private String bizState;
private CardBizState bizState;
/**
* 上下文