REQ-3444: 调用方控制是否截断参数

This commit is contained in:
yanglin 2024-12-17 16:32:24 +08:00
parent b5107667d8
commit ad153db418
2 changed files with 9 additions and 5 deletions

View File

@ -10,8 +10,10 @@ import lombok.Setter;
@Getter
public class VariableAbbreviation {
public static final int DEFAULT_MAX_LENGTH = 32;
public static VariableAbbreviation defaultAbbreviate() {
return abbreviate(32);
return abbreviate(DEFAULT_MAX_LENGTH);
}
public static VariableAbbreviation abbreviate(int maxLength) {

View File

@ -8,10 +8,10 @@ import cn.axzo.msg.center.notices.common.enums.ChannelHandlerEnum;
import cn.axzo.msg.center.notices.common.enums.ReturnCodeEnum;
import cn.axzo.msg.center.notices.common.exception.BizException;
import cn.axzo.msg.center.notices.manager.api.SmsSendManager;
import cn.axzo.msg.center.notices.manager.api.dto.response.BatchMessageSendResponseDto;
import cn.axzo.msg.center.notices.manager.api.dto.response.SendSmsCommonResponseDto;
import cn.axzo.msg.center.notices.manager.api.dto.request.BatchMessageSendRequestDto;
import cn.axzo.msg.center.notices.manager.api.dto.request.MessageSendRequestDto;
import cn.axzo.msg.center.notices.manager.api.dto.response.BatchMessageSendResponseDto;
import cn.axzo.msg.center.notices.manager.api.dto.response.SendSmsCommonResponseDto;
import cn.azxo.framework.common.utils.LogUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
@ -173,10 +173,12 @@ public class SmsSendManagerComposite implements SmsSendManager, ApplicationConte
}
if (str != null) {
int size = str.length();
if ( size <= abbreviation.getMaxLength() + 3 ) {
int maxLength = abbreviation.getMaxLength();
if (maxLength <= 0) maxLength = VariableAbbreviation.DEFAULT_MAX_LENGTH;
if (size <= maxLength + 3) {
return str;
}
return str.substring(0, abbreviation.getMaxLength()) + "...";
return str.substring(0, maxLength) + "...";
}
return "";
}