...
|
...
|
@@ -15,6 +15,7 @@ import com.yohoufo.dal.product.ProductMapper; |
|
|
import com.yohoufo.dal.product.StoragePriceMapper;
|
|
|
import com.yohoufo.dal.product.model.Product;
|
|
|
import com.yohoufo.dal.product.model.StoragePrice;
|
|
|
import com.yohoufo.order.utils.MailSender;
|
|
|
import lombok.Builder;
|
|
|
import lombok.Getter;
|
|
|
import lombok.Setter;
|
...
|
...
|
@@ -92,7 +93,7 @@ public class HkAccountSettlement { |
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
log.info("{} settle, sum income is {}", uid, sumIncome);
|
|
|
// 满足打款条件,通知财务打款
|
|
|
double limitAmount = configReader.getDouble("ufo.order.seller.hkAccountSettlementAmountLimit",5000);
|
|
|
double limitAmount = configReader.getDouble("ufo.order.seller.hkAccountSettlementAmountLimit", 5000);
|
|
|
if (sumIncome.doubleValue() >= limitAmount) {
|
|
|
try {
|
|
|
log.info("{} settle, send email", uid, sumIncome);
|
...
|
...
|
@@ -217,80 +218,15 @@ public class HkAccountSettlement { |
|
|
|
|
|
|
|
|
public void sendMail(List<TradeBillResult> tradeBillResults) throws MessagingException {
|
|
|
|
|
|
//环境
|
|
|
Properties props = new Properties(); // 参数配置
|
|
|
props.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求)
|
|
|
props.setProperty("mail.smtp.host", "smtp.126.com"); // 发件人的邮箱的 SMTP 服务器地址
|
|
|
props.setProperty("mail.smtp.auth", "true");
|
|
|
|
|
|
// 2. 根据配置创建会话对象, 用于和邮件服务器交互
|
|
|
Session session = Session.getDefaultInstance(props);
|
|
|
|
|
|
//邮件
|
|
|
MimeMessage msg = new MimeMessage(session);
|
|
|
//设置主题
|
|
|
msg.setSubject("UFO香港卖家结算");
|
|
|
//发件人,注意中文的处理
|
|
|
msg.setFrom(new InternetAddress("UFO System<lxc1317@126.com>"));
|
|
|
//设置邮件回复人
|
|
|
|
|
|
String toMail = configReader.getString("ufo.order.seller.hkAccountSettlementEmailTo","xiuchun.luo@yoho.cn");
|
|
|
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toMail));
|
|
|
|
|
|
//整封邮件的MINE消息体
|
|
|
MimeMultipart msgMultipart = new MimeMultipart("mixed");//混合的组合关系
|
|
|
//设置邮件的MINE消息体
|
|
|
msg.setContent(msgMultipart);
|
|
|
|
|
|
//附件1
|
|
|
MimeBodyPart attch1 = new MimeBodyPart();
|
|
|
//正文内容
|
|
|
MimeBodyPart content = new MimeBodyPart();
|
|
|
|
|
|
//把内容,附件1,附件2加入到 MINE消息体中
|
|
|
msgMultipart.addBodyPart(attch1);
|
|
|
msgMultipart.addBodyPart(content);
|
|
|
|
|
|
//把文件,添加到附件1中
|
|
|
//数据源
|
|
|
DataSource dataSource = buildDataSource(tradeBillResults);
|
|
|
//数据处理器
|
|
|
DataHandler dataHandler = new DataHandler(dataSource);
|
|
|
//设置第一个附件的数据
|
|
|
attch1.setDataHandler(dataHandler);
|
|
|
//设置第一个附件的文件名
|
|
|
|
|
|
try {
|
|
|
attch1.setFileName(MimeUtility.encodeText("卖家结算清单.csv"));
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
attch1.setFileName("list.csv");
|
|
|
MailSender.newMailSender()
|
|
|
.subject("UFO香港卖家结算")
|
|
|
.to(configReader.getString("ufo.order.seller.hkAccountSettlementEmailTo", "xiuchun.luo@yoho.cn"))
|
|
|
.body("ok", "text/html;charset=utf-8")
|
|
|
.attachment("卖家结算清单.csv", buildDate(tradeBillResults), "application/x-csv;charset=utf-8")
|
|
|
.send();
|
|
|
}
|
|
|
|
|
|
//正文(图片和文字部分)
|
|
|
MimeMultipart bodyMultipart = new MimeMultipart("related");
|
|
|
//设置内容为正文
|
|
|
content.setContent(bodyMultipart);
|
|
|
|
|
|
//html代码部分
|
|
|
MimeBodyPart htmlPart = new MimeBodyPart();
|
|
|
|
|
|
//正文添加图片和html代码
|
|
|
bodyMultipart.addBodyPart(htmlPart);
|
|
|
|
|
|
//html代码
|
|
|
htmlPart.setContent("ok", "text/html;charset=utf-8");
|
|
|
|
|
|
//生成文件邮件
|
|
|
msg.saveChanges();
|
|
|
|
|
|
|
|
|
Transport transport = session.getTransport();
|
|
|
transport.connect("lxc1317@126.com", "luoxiuchun");
|
|
|
transport.sendMessage(msg, msg.getAllRecipients());
|
|
|
}
|
|
|
|
|
|
private ByteArrayDataSource buildDataSource(List<TradeBillResult> tradeBillResults) {
|
|
|
private String buildDate(List<TradeBillResult> tradeBillResults) {
|
|
|
StringBuffer text = new StringBuffer();
|
|
|
text.append("用户UID,订单编号,商品货号,商品名称,商品金额,税费,平台服务费,打款金额,金额类型");
|
|
|
tradeBillResults.forEach(tradeBillResult -> text.append("\n")
|
...
|
...
|
@@ -304,11 +240,7 @@ public class HkAccountSettlement { |
|
|
.append(tradeBillResult.getPayAmount()).append(",")
|
|
|
.append(tradeBillResult.getPayType())
|
|
|
);
|
|
|
try {
|
|
|
return new ByteArrayDataSource(text.toString(), "application/x-csv;charset=utf-8");
|
|
|
} catch (IOException e) {
|
|
|
throw new IllegalStateException(e);
|
|
|
}
|
|
|
return text.toString();
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|