在下面的代码中,我将 setOriginatingNumber 重置为 null,因为对于每个非 null 值,
if (config.getOriginPhoneNumber() != null) {
PhoneNumber originphoneNumber = new PhoneNumber();
config.setOriginatingNumber(formatPhoneNumber(originphoneNumber));
}
它将重置为空白电话号码。这可能导致多个问题 这种情况仅在用户编辑现有电话号码值并更改为字母数字时存在。
如何确保对于 config.getOriginPhoneNumber() 的每个非空值,代码确实设置为空白电话号码
public SmsChannelConfig applyTo(
final SmsChannelConfigRepository repository,
final UserContext context, final ModuleRepository moduleRepository) {
final SmsChannelConfig config;
if (source == null) {
config = new SmsChannelConfig(context);
} else {
config = source;
}
super.applyTo(repository, config);
if (!Strings.isNullOrEmpty(getOriginatorType())
&& "Number".equals(getOriginatorType())) {
PhoneNumber originphoneNumber = new PhoneNumber();
originphoneNumber.setNumber(getPhoneNumber());
originphoneNumber.setCountryCode(getCountryCode());
config.setOriginPhoneNumber(originphoneNumber);
config.setOriginatingNumber(formatPhoneNumber(originphoneNumber));
config.setOriginText(null);
} else {
config.setOriginText(getOriginator());
if (config.getOriginPhoneNumber() != null) {
PhoneNumber originphoneNumber = new PhoneNumber();
config.setOriginatingNumber(formatPhoneNumber(originphoneNumber));
}
}
config.setOperator(getOperator());
if (!Strings.isNullOrEmpty(getOperator())) {
List<ExternalResource> resources = SmsChannelConfigUtil
.getSmsProviders(moduleRepository, context);
for (ExternalResource resource : resources) {
if (getOperator().equals(resource.getId().getResourceName())) {
config.setOperatorName(resource.toString());
}
}
}
config.setDescription(getDescription());
config.setName(getName());
if (repository.query().all().isEmpty()) {
repository.setDefault(context.getOrganization(), config);
}
return config;
}
仅当 getOriginatorType() 不等于“Number”时将 originphoneNumber 值重置为 null,这样它就不会产生多个问题