Commit bc1dac47 by guanchen

更新发邮件端口

parent 45b5a8e5
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
</parent> </parent>
<groupId>com.lanren.huhu</groupId> <groupId>com.lanren.huhu</groupId>
<artifactId>report_expand</artifactId> <!--<artifactId>report_expand</artifactId>-->
<!--<artifactId>report_mail</artifactId>--> <artifactId>report_mail</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>partner</name> <name>partner</name>
<description>呼呼省钱合伙人相关服务</description> <description>呼呼省钱合伙人相关服务</description>
......
...@@ -41,6 +41,6 @@ public class ReportPartnerApplication implements ApplicationRunner { ...@@ -41,6 +41,6 @@ public class ReportPartnerApplication implements ApplicationRunner {
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
logger.info("profile active is {}", profilesActive); logger.info("profile active is {}", profilesActive);
// agentDailyExpandTask.runExpandPartner(); // agentDailyExpandTask.runExpandPartner();
// agentDailyMailTask.runExpandCity2ndAgentMail(); agentDailyMailTask.runExpandCity2ndAgentMail();
} }
} }
...@@ -12,9 +12,11 @@ import com.lanren.huhu.partner.util.DateUtils; ...@@ -12,9 +12,11 @@ import com.lanren.huhu.partner.util.DateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSendException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.mail.SendFailedException;
import java.util.*; import java.util.*;
/** /**
...@@ -58,13 +60,11 @@ public class AgentDailyMailTask { ...@@ -58,13 +60,11 @@ public class AgentDailyMailTask {
private String buildMailContent(Integer agentId) { private String buildMailContent(Integer agentId) {
Date yesterday = DateUtils.getDateBefore(new Date(), 1); Date yesterday = DateUtils.getDateBefore(new Date(), 1);
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Date yesterdayBegin = new Date(yesterday.getTime() - yesterday.getTime() % (24 * 60 * 60 * 1000L));
Date yesterdayEnd = new Date(yesterdayBegin.getTime() + (24 * 60 * 60 - 1) * 1000L);
Date monthBegin = new Date(DateUtils.getMonth1stTimestamp(now)); Date monthBegin = new Date(DateUtils.getMonth1stTimestamp(now));
Date monthEnd = new Date(DateUtils.getMonthLastTimestamp(now)); Date monthEnd = new Date(DateUtils.getMonthLastTimestamp(now));
String yesterdayStr = DateUtils.format(yesterday, DateUtils.FORMAT_SHORT); String yesterdayStr = DateUtils.format(yesterday, DateUtils.FORMAT_SHORT);
String yesterdayBeginStr = DateUtils.format(yesterdayBegin, DateUtils.FORMAT_LONG); String yesterdayBeginStr = DateUtils.format(yesterday, DateUtils.FORMAT_SHORT) + " 00:00:00";
String yesterdayEndStr = DateUtils.format(yesterdayEnd, DateUtils.FORMAT_LONG); String yesterdayEndStr = DateUtils.format(yesterday, DateUtils.FORMAT_SHORT) + " 23:59:59";
String monthBeginStr = DateUtils.format(monthBegin, DateUtils.FORMAT_LONG); String monthBeginStr = DateUtils.format(monthBegin, DateUtils.FORMAT_LONG);
String monthEndStr = DateUtils.format(monthEnd, DateUtils.FORMAT_LONG); String monthEndStr = DateUtils.format(monthEnd, DateUtils.FORMAT_LONG);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
...@@ -240,6 +240,20 @@ public class AgentDailyMailTask { ...@@ -240,6 +240,20 @@ public class AgentDailyMailTask {
} }
break; break;
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e);
if (e instanceof MailSendException) {
Exception[] messageExceptions = ((MailSendException) e).getMessageExceptions();
SendFailedException sendFail;
try {
sendFail = (SendFailedException) messageExceptions[0];
} catch (ClassCastException ee) {
logger.error("class cast exception:[{}]", ee.getMessage());
return;
}
logger.error("send mail eerror,the invalid mail address:{}", sendFail.getInvalidAddresses());
}
logger.error("发送邮件失败, 第{}次", i); logger.error("发送邮件失败, 第{}次", i);
} }
} }
......
...@@ -3,7 +3,6 @@ package com.lanren.huhu.partner.service.impl; ...@@ -3,7 +3,6 @@ package com.lanren.huhu.partner.service.impl;
import com.lanren.huhu.partner.service.IMailService; import com.lanren.huhu.partner.service.IMailService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.mail.javamail.MimeMessageHelper;
...@@ -28,55 +27,64 @@ public class IMailServiceImpl implements IMailService { ...@@ -28,55 +27,64 @@ public class IMailServiceImpl implements IMailService {
/** /**
* Spring Boot 提供了一个发送邮件的简单抽象,使用的是下面这个接口,这里直接注入即可使用 * Spring Boot 提供了一个发送邮件的简单抽象,使用的是下面这个接口,这里直接注入即可使用
*/ */
@Autowired // @Autowired
private JavaMailSenderImpl mailSender; // private JavaMailSenderImpl mailSender;
/** /**
* 配置 * 配置
*/ */
@Value("${spring.mail.host}")
private String host;
@Value("${spring.mail.username}") @Value("${spring.mail.username}")
private String username; private String username;
@Value("${spring.mail.password}") @Value("${spring.mail.password}")
private String password; private String password;
@Value("${spring.mail.port}")
private String port;
@Value("${spring.mail.from}") @Value("${spring.mail.from}")
private String from; private String from;
@Value("${spring.mail.smtp.host}")
private String host;
@Override @Override
public void sendMail(String subject, String text, File attachment, String[] tos) throws MessagingException { public void sendMail(String subject, String text, File attachment, String[] tos) throws MessagingException {
MimeMessage mailMessage = configMailMessage(); JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
configMessageHelper(mailMessage, subject, text, attachment, tos, new String[]{}); mailSender.setHost(host);
mailSender.setUsername(username);
mailSender.setPassword(password);
mailSender.setPort(465);
mailSender.setDefaultEncoding("UTF-8");
Properties javaMailProperties = new Properties();
javaMailProperties.setProperty("mail.smtp.auth", "true");
javaMailProperties.setProperty("mail.smtp.timeout", "25000");
javaMailProperties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
javaMailProperties.setProperty("mail.smtp.socketFactory.fallback", "false");
javaMailProperties.setProperty("mail.smtp.socketFactory.port", "465");
mailSender.setJavaMailProperties(javaMailProperties);
MimeMessage mailMessage = mailSender.createMimeMessage();
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8");
mimeMessageHelper.setFrom(from);
mimeMessageHelper.setSubject(subject);
mimeMessageHelper.setText(text, true);
if (attachment != null) {
mimeMessageHelper.addAttachment(attachment.getName(), attachment);
}
mimeMessageHelper.setTo(tos);
mailSender.send(mailMessage); mailSender.send(mailMessage);
} }
@Override @Override
public void sendMailWithCc(String subject, String text, File attachment, String[] tos, String[] cc) throws MessagingException { public void sendMailWithCc(String subject, String text, File attachment, String[] tos, String[] cc) throws MessagingException {
MimeMessage mailMessage = configMailMessage(); JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
MimeMessageHelper mimeMessageHelper = configMessageHelper(mailMessage, subject, text, attachment, tos, new String[]{});
mimeMessageHelper.setCc(cc);
mailSender.send(mailMessage);
}
private MimeMessage configMailMessage() {
mailSender.setHost(host); mailSender.setHost(host);
mailSender.setPort(Integer.parseInt(port));
mailSender.setUsername(username); mailSender.setUsername(username);
mailSender.setPassword(password); mailSender.setPassword(password);
mailSender.setPort(465);
mailSender.setDefaultEncoding("UTF-8"); mailSender.setDefaultEncoding("UTF-8");
Properties javaMailProperties = new Properties(); Properties javaMailProperties = new Properties();
javaMailProperties.setProperty("mail.smtp.auth", "true"); javaMailProperties.setProperty("mail.smtp.auth", "true");
javaMailProperties.setProperty("mail.smtp.timeout", "25000"); javaMailProperties.setProperty("mail.smtp.timeout", "25000");
javaMailProperties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
javaMailProperties.setProperty("mail.smtp.socketFactory.fallback", "false");
javaMailProperties.setProperty("mail.smtp.socketFactory.port", "465");
mailSender.setJavaMailProperties(javaMailProperties); mailSender.setJavaMailProperties(javaMailProperties);
MimeMessage mailMessage = mailSender.createMimeMessage();
return mailSender.createMimeMessage();
}
private MimeMessageHelper configMessageHelper(MimeMessage mailMessage, String subject, String text, File attachment, String[] tos, String[] cc)
throws MessagingException {
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8"); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8");
mimeMessageHelper.setFrom(from); mimeMessageHelper.setFrom(from);
mimeMessageHelper.setSubject(subject); mimeMessageHelper.setSubject(subject);
...@@ -85,7 +93,7 @@ public class IMailServiceImpl implements IMailService { ...@@ -85,7 +93,7 @@ public class IMailServiceImpl implements IMailService {
mimeMessageHelper.addAttachment(attachment.getName(), attachment); mimeMessageHelper.addAttachment(attachment.getName(), attachment);
} }
mimeMessageHelper.setTo(tos); mimeMessageHelper.setTo(tos);
return mimeMessageHelper; mimeMessageHelper.setCc(cc);
mailSender.send(mailMessage);
} }
} }
...@@ -60,15 +60,11 @@ spring: ...@@ -60,15 +60,11 @@ spring:
preferred-json-mapper: fastjson preferred-json-mapper: fastjson
#邮箱配置 #邮箱配置
mail: mail:
host: smtp.exmail.qq.com #发送邮件服务器
username: report@wasair.com #发送邮件的邮箱地址 username: report@wasair.com #发送邮件的邮箱地址
password: Wasai123 #客户端授权码,不是邮箱密码,这个在qq邮箱设置里面自动生成的 password: Wasai123 #客户端授权码,不是邮箱密码,这个在qq邮箱设置里面自动生成的
port: 25 #端口号465或587
from: report@wasair.com # 发送邮件的地址,和上面username一致 from: report@wasair.com # 发送邮件的地址,和上面username一致
properties: smtp:
mail: host: smtp.exmail.qq.com
smtp:
auth: true
# properties.mail.smtp.starttls.enable: true # properties.mail.smtp.starttls.enable: true
# properties.mail.smtp.starttls.required: true # properties.mail.smtp.starttls.required: true
# properties.mail.smtp.ssl.enable: true # properties.mail.smtp.ssl.enable: true
......
...@@ -200,14 +200,14 @@ ...@@ -200,14 +200,14 @@
SELECT SELECT
'Vip会员' c1, 'Vip会员' c1,
case when b.invite_user_id = a.user_id then '直接' else '间接' end c2, case when b.invite_user_id = a.user_id then '直接' else '间接' end c2,
COUNT(a.recharge_time between #{yesterdayBegin} and #{yesterdayEnd} or NULL) c3, COUNT(c.become_high_time between #{yesterdayBegin} and #{yesterdayEnd} or NULL) c3,
COUNT(a.recharge_time >= '2019-08-16 23:59:59' or NULL) c4, COUNT(c.become_high_time >= '2019-08-16 23:59:59' or NULL) c4,
COUNT(a.recharge_time between #{monthBegin} and #{monthEnd} or NULL) c5, COUNT(c.become_high_time between #{monthBegin} and #{monthEnd} or NULL) c5,
COUNT(*) c6 COUNT(*) c6
FROM agent_reward a FROM agent_expand_detail a
LEFT JOIN partner_invite_relation b on a.source_user_id=b.user_id JOIN partner_invite_relation b on a.expand_user_id=b.user_id
JOIN partner_account c on a.expand_user_id=c.user_id and c.is_super_partner=0 and c.partner_level=20
WHERE a.agent_id = #{agentId} WHERE a.agent_id = #{agentId}
AND a.reward_type in (30,20,710,720,730)
GROUP BY 1,2 GROUP BY 1,2
</select> </select>
<insert id="insertByDetail"> <insert id="insertByDetail">
......
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