|
@@ -15,6 +15,7 @@ import com.yohoufo.dal.product.ProductMapper; |
|
@@ -15,6 +15,7 @@ import com.yohoufo.dal.product.ProductMapper; |
15
|
import com.yohoufo.dal.product.StoragePriceMapper;
|
15
|
import com.yohoufo.dal.product.StoragePriceMapper;
|
16
|
import com.yohoufo.dal.product.model.Product;
|
16
|
import com.yohoufo.dal.product.model.Product;
|
17
|
import com.yohoufo.dal.product.model.StoragePrice;
|
17
|
import com.yohoufo.dal.product.model.StoragePrice;
|
|
|
18
|
+import com.yohoufo.order.utils.MailSender;
|
18
|
import lombok.Builder;
|
19
|
import lombok.Builder;
|
19
|
import lombok.Getter;
|
20
|
import lombok.Getter;
|
20
|
import lombok.Setter;
|
21
|
import lombok.Setter;
|
|
@@ -92,7 +93,7 @@ public class HkAccountSettlement { |
|
@@ -92,7 +93,7 @@ public class HkAccountSettlement { |
92
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
93
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
93
|
log.info("{} settle, sum income is {}", uid, sumIncome);
|
94
|
log.info("{} settle, sum income is {}", uid, sumIncome);
|
94
|
// 满足打款条件,通知财务打款
|
95
|
// 满足打款条件,通知财务打款
|
95
|
- double limitAmount = configReader.getDouble("ufo.order.seller.hkAccountSettlementAmountLimit",5000);
|
96
|
+ double limitAmount = configReader.getDouble("ufo.order.seller.hkAccountSettlementAmountLimit", 5000);
|
96
|
if (sumIncome.doubleValue() >= limitAmount) {
|
97
|
if (sumIncome.doubleValue() >= limitAmount) {
|
97
|
try {
|
98
|
try {
|
98
|
log.info("{} settle, send email", uid, sumIncome);
|
99
|
log.info("{} settle, send email", uid, sumIncome);
|
|
@@ -217,80 +218,15 @@ public class HkAccountSettlement { |
|
@@ -217,80 +218,15 @@ public class HkAccountSettlement { |
217
|
|
218
|
|
218
|
|
219
|
|
219
|
public void sendMail(List<TradeBillResult> tradeBillResults) throws MessagingException {
|
220
|
public void sendMail(List<TradeBillResult> tradeBillResults) throws MessagingException {
|
220
|
-
|
|
|
221
|
- //环境
|
|
|
222
|
- Properties props = new Properties(); // 参数配置
|
|
|
223
|
- props.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求)
|
|
|
224
|
- props.setProperty("mail.smtp.host", "smtp.126.com"); // 发件人的邮箱的 SMTP 服务器地址
|
|
|
225
|
- props.setProperty("mail.smtp.auth", "true");
|
|
|
226
|
-
|
|
|
227
|
- // 2. 根据配置创建会话对象, 用于和邮件服务器交互
|
|
|
228
|
- Session session = Session.getDefaultInstance(props);
|
|
|
229
|
-
|
|
|
230
|
- //邮件
|
|
|
231
|
- MimeMessage msg = new MimeMessage(session);
|
|
|
232
|
- //设置主题
|
|
|
233
|
- msg.setSubject("UFO香港卖家结算");
|
|
|
234
|
- //发件人,注意中文的处理
|
|
|
235
|
- msg.setFrom(new InternetAddress("UFO System<lxc1317@126.com>"));
|
|
|
236
|
- //设置邮件回复人
|
|
|
237
|
-
|
|
|
238
|
- String toMail = configReader.getString("ufo.order.seller.hkAccountSettlementEmailTo","xiuchun.luo@yoho.cn");
|
|
|
239
|
- msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toMail));
|
|
|
240
|
-
|
|
|
241
|
- //整封邮件的MINE消息体
|
|
|
242
|
- MimeMultipart msgMultipart = new MimeMultipart("mixed");//混合的组合关系
|
|
|
243
|
- //设置邮件的MINE消息体
|
|
|
244
|
- msg.setContent(msgMultipart);
|
|
|
245
|
-
|
|
|
246
|
- //附件1
|
|
|
247
|
- MimeBodyPart attch1 = new MimeBodyPart();
|
|
|
248
|
- //正文内容
|
|
|
249
|
- MimeBodyPart content = new MimeBodyPart();
|
|
|
250
|
-
|
|
|
251
|
- //把内容,附件1,附件2加入到 MINE消息体中
|
|
|
252
|
- msgMultipart.addBodyPart(attch1);
|
|
|
253
|
- msgMultipart.addBodyPart(content);
|
|
|
254
|
-
|
|
|
255
|
- //把文件,添加到附件1中
|
|
|
256
|
- //数据源
|
|
|
257
|
- DataSource dataSource = buildDataSource(tradeBillResults);
|
|
|
258
|
- //数据处理器
|
|
|
259
|
- DataHandler dataHandler = new DataHandler(dataSource);
|
|
|
260
|
- //设置第一个附件的数据
|
|
|
261
|
- attch1.setDataHandler(dataHandler);
|
|
|
262
|
- //设置第一个附件的文件名
|
|
|
263
|
-
|
|
|
264
|
- try {
|
|
|
265
|
- attch1.setFileName(MimeUtility.encodeText("卖家结算清单.csv"));
|
|
|
266
|
- } catch (UnsupportedEncodingException e) {
|
|
|
267
|
- attch1.setFileName("list.csv");
|
221
|
+ MailSender.newMailSender()
|
|
|
222
|
+ .subject("UFO香港卖家结算")
|
|
|
223
|
+ .to(configReader.getString("ufo.order.seller.hkAccountSettlementEmailTo", "xiuchun.luo@yoho.cn"))
|
|
|
224
|
+ .body("ok", "text/html;charset=utf-8")
|
|
|
225
|
+ .attachment("卖家结算清单.csv", buildDate(tradeBillResults), "application/x-csv;charset=utf-8")
|
|
|
226
|
+ .send();
|
268
|
}
|
227
|
}
|
269
|
|
228
|
|
270
|
- //正文(图片和文字部分)
|
|
|
271
|
- MimeMultipart bodyMultipart = new MimeMultipart("related");
|
|
|
272
|
- //设置内容为正文
|
|
|
273
|
- content.setContent(bodyMultipart);
|
|
|
274
|
-
|
|
|
275
|
- //html代码部分
|
|
|
276
|
- MimeBodyPart htmlPart = new MimeBodyPart();
|
|
|
277
|
-
|
|
|
278
|
- //正文添加图片和html代码
|
|
|
279
|
- bodyMultipart.addBodyPart(htmlPart);
|
|
|
280
|
-
|
|
|
281
|
- //html代码
|
|
|
282
|
- htmlPart.setContent("ok", "text/html;charset=utf-8");
|
|
|
283
|
-
|
|
|
284
|
- //生成文件邮件
|
|
|
285
|
- msg.saveChanges();
|
|
|
286
|
-
|
|
|
287
|
-
|
|
|
288
|
- Transport transport = session.getTransport();
|
|
|
289
|
- transport.connect("lxc1317@126.com", "luoxiuchun");
|
|
|
290
|
- transport.sendMessage(msg, msg.getAllRecipients());
|
|
|
291
|
- }
|
|
|
292
|
-
|
|
|
293
|
- private ByteArrayDataSource buildDataSource(List<TradeBillResult> tradeBillResults) {
|
229
|
+ private String buildDate(List<TradeBillResult> tradeBillResults) {
|
294
|
StringBuffer text = new StringBuffer();
|
230
|
StringBuffer text = new StringBuffer();
|
295
|
text.append("用户UID,订单编号,商品货号,商品名称,商品金额,税费,平台服务费,打款金额,金额类型");
|
231
|
text.append("用户UID,订单编号,商品货号,商品名称,商品金额,税费,平台服务费,打款金额,金额类型");
|
296
|
tradeBillResults.forEach(tradeBillResult -> text.append("\n")
|
232
|
tradeBillResults.forEach(tradeBillResult -> text.append("\n")
|
|
@@ -304,11 +240,7 @@ public class HkAccountSettlement { |
|
@@ -304,11 +240,7 @@ public class HkAccountSettlement { |
304
|
.append(tradeBillResult.getPayAmount()).append(",")
|
240
|
.append(tradeBillResult.getPayAmount()).append(",")
|
305
|
.append(tradeBillResult.getPayType())
|
241
|
.append(tradeBillResult.getPayType())
|
306
|
);
|
242
|
);
|
307
|
- try {
|
|
|
308
|
- return new ByteArrayDataSource(text.toString(), "application/x-csv;charset=utf-8");
|
|
|
309
|
- } catch (IOException e) {
|
|
|
310
|
- throw new IllegalStateException(e);
|
|
|
311
|
- }
|
243
|
+ return text.toString();
|
312
|
}
|
244
|
}
|
313
|
|
245
|
|
314
|
} |
246
|
} |