Commit 00fb1021 by zhangxingmin

push

parent 58ee9833
......@@ -23,6 +23,7 @@ import com.yd.email.service.dto.EmailContactDto;
import com.yd.email.service.model.EmailContact;
import com.yd.email.service.service.IEmailContactService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -30,6 +31,7 @@ import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
......@@ -188,14 +190,26 @@ public class ApiEmailContactServiceImpl implements ApiEmailContactService {
*/
@Override
public String replacePlaceholders(String content, String contactBizId) {
if (StringUtils.isBlank(content)) return "";
String result = content;
//查询收件人信息
EmailContact emailContact = iEmailContactService.queryOne(contactBizId);
if (!Objects.isNull(emailContact)) {
result = result.replace("{{name}}", emailContact.getName());
result = result.replace("{{appellation}}", emailContact.getAppellation());
result = result.replace("{{compantName}}", emailContact.getCompanyName());
// 使用 Optional 或三目运算符处理 null
String name = Optional.ofNullable(emailContact.getName())
.filter(s -> !s.trim().isEmpty())
.orElse("");
String appellation = Optional.ofNullable(emailContact.getAppellation())
.orElse("");
String companyName = Optional.ofNullable(emailContact.getCompanyName())
.orElse("");
result = result.replace("{{name}}", name)
.replace("{{appellation}}", appellation)
.replace("{{compantName}}", companyName);
}
return result;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment