Commit a8082d43 by guanchen

添加新增文件--代理商每日邮件

parent 69bc6d9f
package com.lanren.huhu.partner.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lanren.huhu.partner.domain.AgentExpandCityAgentDetail;
import com.lanren.huhu.partner.model.MailContentRow;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface AgentExpandCityAgentDetailMapper extends BaseMapper<AgentExpandCityAgentDetail> {
int updateBatch(List<AgentExpandCityAgentDetail> list);
int batchInsert(@Param("list") List<AgentExpandCityAgentDetail> list);
int insertOrUpdate(AgentExpandCityAgentDetail record);
int insertOrUpdateSelective(AgentExpandCityAgentDetail record);
MailContentRow getPingtuiChildRow(String dat, Integer agentId, String monthBegin, String monthEnd);
}
\ No newline at end of file
package com.lanren.huhu.partner.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lanren.huhu.partner.domain.AgentMailList;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface AgentMailListMapper extends BaseMapper<AgentMailList> {
int batchInsert(@Param("list") List<AgentMailList> list);
int insertOrUpdate(AgentMailList record);
int insertOrUpdateSelective(AgentMailList record);
}
\ No newline at end of file
package com.lanren.huhu.partner.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName(value = "agent_expand_city_agent_detail")
public class AgentExpandCityAgentDetail implements Serializable {
@TableId(value = "dat", type = IdType.INPUT)
private Date dat;
@TableId(value = "agent_id", type = IdType.INPUT)
private Integer agentId;
@TableId(value = "expand_agent_id", type = IdType.INPUT)
private Integer expandAgentId;
@TableField(value = "user_id")
private Integer userId;
@TableField(value = "expand_user_id")
private Integer expandUserId;
@TableField(value = "expand_agent_time")
private Date expandAgentTime;
@TableField(value = "created_at")
private Integer createdAt;
@TableField(value = "updated_at")
private Integer updatedAt;
private static final long serialVersionUID = 1L;
public static final String COL_USER_ID = "user_id";
public static final String COL_EXPAND_USER_ID = "expand_user_id";
public static final String COL_EXPAND_AGENT_TIME = "expand_agent_time";
public static final String COL_CREATED_AT = "created_at";
public static final String COL_UPDATED_AT = "updated_at";
}
\ No newline at end of file
package com.lanren.huhu.partner.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import lombok.Data;
@Data
@TableName(value = "agent_mail_list")
public class AgentMailList implements Serializable {
@TableField(value = "id")
private Integer id;
/**
* 代理商id
*/
@TableField(value = "agent_id")
private Integer agentId;
/**
* 代理商名字
*/
@TableField(value = "agent_name")
private String agentName;
/**
* 代理商手机号
*/
@TableField(value = "agent_phone")
private String agentPhone;
/**
* 邮箱
*/
@TableField(value = "agent_mail")
private String agentMail;
/**
* 抄送邮箱
*/
@TableField(value = "agent_cc")
private String agentCc;
/**
* 类型
*/
@TableField(value = "mail_type")
private Integer mailType;
private static final long serialVersionUID = 1L;
public static final String COL_ID = "id";
public static final String COL_AGENT_ID = "agent_id";
public static final String COL_AGENT_NAME = "agent_name";
public static final String COL_AGENT_PHONE = "agent_phone";
public static final String COL_AGENT_MAIL = "agent_mail";
public static final String COL_AGENT_CC = "agent_cc";
public static final String COL_MAIL_TYPE = "mail_type";
}
\ No newline at end of file
package com.lanren.huhu.partner.model;
import com.lanren.huhu.partner.model.base.BaseModel;
import lombok.Data;
/**
* @author chen
* @title: MailContentRow
* @projectName partner
* @description: TODO
* @package com.lanren.huhu.partner.model
* @date 2019-09-26 23:50
*/
@Data
public class MailContentRow extends BaseModel {
String c1;
String c2;
String c3;
String c4;
String c5;
String c6;
@Override
public MailContentRow clone() {
MailContentRow mailContentRow = new MailContentRow();
mailContentRow.setC1(this.c1);
mailContentRow.setC2(this.c2);
mailContentRow.setC3(this.c3);
mailContentRow.setC4(this.c4);
mailContentRow.setC5(this.c5);
mailContentRow.setC6(this.c6);
return mailContentRow;
}
}
package com.lanren.huhu.partner.schedule;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lanren.huhu.partner.constants.Constants;
import com.lanren.huhu.partner.domain.AgentExpandCityAgentDetail;
import com.lanren.huhu.partner.domain.AgentMailList;
import com.lanren.huhu.partner.domain.UserAgent;
import com.lanren.huhu.partner.model.MailContentRow;
import com.lanren.huhu.partner.model.ParentAgent;
import com.lanren.huhu.partner.service.*;
import com.lanren.huhu.partner.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.*;
/**
* @author chen
* @title: NewAgentDailyExpandTask
* @projectName partner
* @description: 代理商每日邮件发送
* @package com.lanren.huhu.partner.schedule
* @date 2019-07-08 15:50
*/
@Component
public class AgentDailyMailTask {
private static Logger logger = LoggerFactory.getLogger(AgentDailyMailTask.class);
private static final String MAIL_ROW_FORMAT = "" +
"<tr>" +
"<td height=\"15px\">%s</td>" +
"<td>%s</td>" +
"<td>%s</td>" +
"<td>%s</td>" +
"<td>%s</td>" +
"<td>%s</td>" +
"</tr>";
@Autowired
AgentMailListService agentMailListService;
@Autowired
UserAgentService userAgentService;
@Autowired
UserService userService;
@Autowired
AgentExpandCityAgentDetailService agentExpandCityAgentDetailService;
@Autowired
MailReportService mailReportService;
/**
* 注入发送邮件的接口
*/
@Autowired
private IMailService mailService;
private String buildMailContent(Integer agentId) {
Date yesterday = DateUtils.getDateBefore(new Date(), 1);
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 monthEnd = new Date(DateUtils.getMonthLastTimestamp(now));
String yesterdayStr = DateUtils.format(yesterday, DateUtils.FORMAT_SHORT);
String yesterdayBeginStr = DateUtils.format(yesterdayBegin, DateUtils.FORMAT_LONG);
String yesterdayEndStr = DateUtils.format(yesterdayEnd, DateUtils.FORMAT_LONG);
String monthBeginStr = DateUtils.format(monthBegin, DateUtils.FORMAT_LONG);
String monthEndStr = DateUtils.format(monthEnd, DateUtils.FORMAT_LONG);
StringBuilder sb = new StringBuilder();
/**
* 表头
*/
MailContentRow headerRow = createRow("拓展用户的身份", "来源", "昨日新增数量(个)", "8月16日之后数量(个)", "当月总计数量(个)", "总计数量(个)");
sb.append(formatMailRow(headerRow));
/**
* 代理商拓展 注册并登录用户
*/
MailContentRow regRow = mailReportService.getRegRow(yesterdayStr, agentId, monthBeginStr, monthEndStr);
logger.info("regRow is {}", regRow);
sb.append(formatMailRow(regRow));
sb.append(emptyRow());
/**
* 获取代理商拓展 VIP 数据
*/
List<MailContentRow> vipRows = mailReportService.getVipRows(yesterdayBeginStr, yesterdayEndStr, agentId, monthBeginStr, monthEndStr);
MailContentRow sumVip = createRow("Vip会员", "总计", "0", "0", "0", "0");
MailContentRow directVip = null;
MailContentRow indirectVip = null;
for (MailContentRow row : vipRows) {
if ("直接".equals(row.getC2()) && "Vip会员".equals(row.getC1())) {
directVip = row.clone();
logger.info("directVip is {}", directVip);
}
if ("间接".equals(row.getC2()) && "Vip会员".equals(row.getC1())) {
indirectVip = row.clone();
logger.info("indirectVip is {}", indirectVip);
}
}
appendVipRows(sb, sumVip, directVip, indirectVip);
sb.append(emptyRow());
/**
* 获取代理商拓展 超级VIP 数据
*/
List<MailContentRow> sVipRows = mailReportService.getsVipRows(yesterdayBeginStr, yesterdayEndStr, agentId, monthBeginStr, monthEndStr);
MailContentRow sumsvip = createRow("超级Vip会员", "总计", "0", "0", "0", "0");
MailContentRow directsvip = null;
MailContentRow indirectsvip = null;
for (MailContentRow row : sVipRows) {
if ("直接".equals(row.getC2()) && "超级Vip会员".equals(row.getC1())) {
directsvip = row.clone();
logger.info("directsvip is {}", directsvip);
}
if ("间接".equals(row.getC2()) && "超级Vip会员".equals(row.getC1())) {
indirectsvip = row.clone();
logger.info("indirectsvip is {}", indirectsvip);
}
}
appendVipRows(sb, sumsvip, directsvip, indirectsvip);
/**
* 获取代理商拓展 层级下级代理数据
*/
List<MailContentRow> cengjiChildRows = mailReportService.getCengjiChildRows(yesterdayBeginStr, yesterdayEndStr, agentId, monthBeginStr, monthEndStr);
MailContentRow sumAgent = createRow("代理商", "总计", "0", "0", "0", "0");
MailContentRow directlv2 = null;
MailContentRow directlv34 = null;
MailContentRow indirectlv34 = null;
MailContentRow directlv5 = null;
MailContentRow indirectlv5 = null;
for (MailContentRow row : cengjiChildRows) {
if ("直接".equals(row.getC2()) && "分公司".equals(row.getC1())) {
directlv2 = row.clone();
logger.info("directlv2 is {}", directlv2);
}
if ("直接".equals(row.getC2()) && "城市代理".equals(row.getC1())) {
directlv34 = row.clone();
logger.info("directlv34 is {}", directlv34);
}
if ("间接".equals(row.getC2()) && "城市代理".equals(row.getC1())) {
indirectlv34 = row.clone();
logger.info("indirectlv34 is {}", indirectlv34);
}
if ("直接".equals(row.getC2()) && "联盟商户".equals(row.getC1())) {
directlv5 = row.clone();
logger.info("directlv5 is {}", directlv5);
}
if ("间接".equals(row.getC2()) && "联盟商户".equals(row.getC1())) {
indirectlv5 = row.clone();
logger.info("indirectlv5 is {}", indirectlv5);
}
}
sb.append(emptyRow());
// /**
// * 联盟商户
// */
// appendRow(sb, directlv5);
// appendRow(sb, indirectlv5);
/**
* 代理商 2-4 级
*/
sumAgentRows(sumAgent, directlv2, null);
sumAgentRows(sumAgent, directlv34, indirectlv34);
sb.append(formatMailRow(sumAgent));
appendRow(sb, directlv2);
appendRow(sb, directlv34);
appendRow(sb, indirectlv34);
sb.append(emptyRow());
/**
* 获取代理商拓展 平推下级代理数据
*/
MailContentRow pingtuiRow = mailReportService.getPingtuiChildRow(yesterdayStr, agentId, monthBeginStr, monthEndStr);
appendRow(sb, pingtuiRow);
return sb.toString();
}
private void appendRow(StringBuilder sb, MailContentRow row) {
if (row != null) {
sb.append(formatMailRow(row));
}
}
private void appendVipRows(StringBuilder sb, MailContentRow sumRow, MailContentRow directRow, MailContentRow indirectRow) {
if (directRow != null) {
sum2Row(sumRow, directRow);
}
if (indirectRow != null) {
sum2Row(sumRow, indirectRow);
}
sb.append(formatMailRow(sumRow));
if (directRow != null) {
sb.append(formatMailRow(directRow));
}
if (indirectRow != null) {
sb.append(formatMailRow(indirectRow));
}
}
private void sumAgentRows(MailContentRow sumRow, MailContentRow directRow, MailContentRow indirectRow) {
if (directRow != null) {
sum2Row(sumRow, directRow);
}
if (indirectRow != null) {
sum2Row(sumRow, indirectRow);
}
}
private void sum2Row(MailContentRow sumRow, MailContentRow row) {
sumRow.setC3((Integer.parseInt(row.getC3()) + Integer.parseInt(sumRow.getC3())) + "");
sumRow.setC4((Integer.parseInt(row.getC4()) + Integer.parseInt(sumRow.getC4())) + "");
sumRow.setC5((Integer.parseInt(row.getC5()) + Integer.parseInt(sumRow.getC5())) + "");
sumRow.setC6((Integer.parseInt(row.getC6()) + Integer.parseInt(sumRow.getC6())) + "");
}
private void sendMail(AgentMailList agentMailList) {
Date yesterday = DateUtils.getDateBefore(new Date(), 1);
String yesterdayStr = DateUtils.format(yesterday, DateUtils.FORMAT_SHORT);
StringBuilder sb = new StringBuilder();
sb.append(agentMailList.getAgentName() + ", 您好:<br>");
sb.append("<table border=1>");
sb.append(buildMailContent(agentMailList.getAgentId()));
sb.append("</table>");
String[] tos = agentMailList.getAgentMail().split(";");
String[] cc = agentMailList.getAgentCc().split(";");
for (int i=0; i<5; i++) {
try {
if (StringUtils.isEmpty(cc)) {
mailService.sendMail(
"代理商每日邮件-" + yesterdayStr,
sb.toString(),
null,
tos
);
} else {
mailService.sendMailWithCc(
"代理商每日邮件-" + yesterdayStr,
sb.toString(),
null,
tos,
cc
);
}
break;
} catch (Exception e) {
logger.error("发送邮件失败, 第{}次", i);
}
}
}
public void runExpandCityAgent() {
try {
/**
* 查询全部城市代理, 然后查找他们的B端推荐上级
* 如果上级有邮件列表中的代理, 记一条拓展记录
*/
List<AgentMailList> mailList = agentMailListService.list();
Set<Integer> mailAgentIdSet = new HashSet<Integer>();
for (AgentMailList agent : mailList) {
mailAgentIdSet.add(agent.getAgentId());
}
List<UserAgent> cityAgentList = userAgentService.selectCityAgentList();
List<AgentExpandCityAgentDetail> expandRecordList = new ArrayList<AgentExpandCityAgentDetail>();
for (UserAgent cityAgent : cityAgentList) {
try {
List<ParentAgent> parentAgentList = userService.getAgentListByUserId(cityAgent.getUserId(), Constants.PARENT_COLUMN_NAME_PINGTUI);
for (ParentAgent parentAgent : parentAgentList) {
try {
if (mailAgentIdSet.contains(parentAgent.getAgentId())) {
addToExpand(cityAgent, parentAgent, expandRecordList);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
Thread.sleep(200L);
}
}
/**
* 正常处理后, 写入结果
*/
if (expandRecordList.size() > 0) {
QueryWrapper<AgentExpandCityAgentDetail> wrapper = new QueryWrapper<AgentExpandCityAgentDetail>();
wrapper.in("agent_id", mailAgentIdSet);
agentExpandCityAgentDetailService.remove(wrapper);
// logger.info("sleep");
// Thread.sleep(15000L);
agentExpandCityAgentDetailService.batchInsert(expandRecordList);
}
/**
* 发邮件
*/
for (AgentMailList agentMailList : mailList) {
sendMail(agentMailList);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
private void addToExpand(UserAgent cityAgent, ParentAgent parentAgent, List<AgentExpandCityAgentDetail> expandRecordList) {
int now = (int) (System.currentTimeMillis() / 1000L);
AgentExpandCityAgentDetail record = new AgentExpandCityAgentDetail();
Date expandTime = new Date(cityAgent.getActiveTime() * 1000L);
record.setDat(expandTime);
record.setAgentId(parentAgent.getAgentId());
record.setUserId(parentAgent.getUserId());
record.setExpandUserId(cityAgent.getUserId());
record.setExpandAgentId(cityAgent.getAgentId());
record.setExpandAgentTime(expandTime);
record.setCreatedAt(now);
record.setUpdatedAt(now);
expandRecordList.add(record);
}
private String formatMailRow(MailContentRow mailContentRow) {
return String.format(MAIL_ROW_FORMAT,
mailContentRow.getC1(),
mailContentRow.getC2(),
mailContentRow.getC3(),
mailContentRow.getC4(),
mailContentRow.getC5(),
mailContentRow.getC6()
);
}
private String emptyRow() {
return String.format(MAIL_ROW_FORMAT,
"",
"",
"",
"",
"",
""
);
}
private MailContentRow createRow(String c1, String c2, String c3, String c4, String c5, String c6) {
MailContentRow row = new MailContentRow();
row.setC1(c1);
row.setC2(c2);
row.setC3(c3);
row.setC4(c4);
row.setC5(c5);
row.setC6(c6);
return row;
}
}
package com.lanren.huhu.partner.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lanren.huhu.partner.domain.AgentExpandCityAgentDetail;
import com.lanren.huhu.partner.model.MailContentRow;
import java.util.List;
/**
* @title: ${NAME}
* @projectName partner
* @description: TODO
* @author chen
* @package ${PACKAGE_NAME}
* @date 2019-09-26 15:31
*/
public interface AgentExpandCityAgentDetailService extends IService<AgentExpandCityAgentDetail>{
int updateBatch(List<AgentExpandCityAgentDetail> list);
int batchInsert(List<AgentExpandCityAgentDetail> list);
int insertOrUpdate(AgentExpandCityAgentDetail record);
int insertOrUpdateSelective(AgentExpandCityAgentDetail record);
MailContentRow getPingtuiChildRow(String dat, Integer agentId, String monthBegin, String monthEnd);
}
package com.lanren.huhu.partner.service;
import java.util.List;
import com.lanren.huhu.partner.domain.AgentMailList;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @author chen
* @title: ${NAME}
* @projectName partner
* @description: TODO
* @package ${PACKAGE_NAME}
* @date 2019-09-26 15:13
*/
public interface AgentMailListService extends IService<AgentMailList> {
int batchInsert(List<AgentMailList> list);
int insertOrUpdate(AgentMailList record);
int insertOrUpdateSelective(AgentMailList record);
}
package com.lanren.huhu.partner.service;
import javax.mail.MessagingException;
import java.io.File;
/**
* @author chen
* @title: IMailService
* @projectName partner
* @package com.lanren.huhu.partner.service
* @date 2019-09-26 19:58
*/
public interface IMailService {
void sendMail(String subject, String text, File attachment, String[] tos) throws MessagingException;
void sendMailWithCc(String subject, String text, File attachment, String[] tos, String[] cc) throws MessagingException;
}
\ No newline at end of file
package com.lanren.huhu.partner.service;
import com.lanren.huhu.partner.model.MailContentRow;
import java.util.List;
/**
* @author chen
* @title: MailReportService
* @projectName partner
* @package com.lanren.huhu.partner.service
* @date 2019-09-26 23:38
*/
public interface MailReportService {
/**
* 获取代理商拓展 注册并登录用户
*/
MailContentRow getRegRow(String dat, Integer agentId, String monthBegin, String monthEnd);
/**
* 获取代理商拓展 VIP 超V 数据
*/
List<MailContentRow> getVipRows(String yesterdayBegin, String yesterdayEnd, Integer agentId, String monthBegin, String monthEnd);
/**
* 获取代理商拓展 层级下级代理数据
*/
List<MailContentRow> getCengjiChildRows(String yesterdayBegin, String yesterdayEnd, Integer agentId, String monthBegin, String monthEnd);
/**
* 获取代理商拓展 平推下级代理数据
*/
MailContentRow getPingtuiChildRow(String dat, Integer agentId, String monthBegin, String monthEnd);
List<MailContentRow> getsVipRows(String yesterdayBegin, String yesterdayEnd, Integer agentId, String monthBegin, String monthEnd);
}
package com.lanren.huhu.partner.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanren.huhu.partner.dao.AgentExpandCityAgentDetailMapper;
import com.lanren.huhu.partner.domain.AgentExpandCityAgentDetail;
import com.lanren.huhu.partner.model.MailContentRow;
import com.lanren.huhu.partner.service.AgentExpandCityAgentDetailService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @title: ${NAME}
* @projectName partner
* @description: TODO
* @author chen
* @package ${PACKAGE_NAME}
* @date 2019-09-26 15:31
*/
@Service
public class AgentExpandCityAgentDetailServiceImpl extends ServiceImpl<AgentExpandCityAgentDetailMapper, AgentExpandCityAgentDetail> implements AgentExpandCityAgentDetailService{
@Override
public int updateBatch(List<AgentExpandCityAgentDetail> list) {
return baseMapper.updateBatch(list);
}
@Override
public int batchInsert(List<AgentExpandCityAgentDetail> list) {
return baseMapper.batchInsert(list);
}
@Override
public int insertOrUpdate(AgentExpandCityAgentDetail record) {
return baseMapper.insertOrUpdate(record);
}
@Override
public int insertOrUpdateSelective(AgentExpandCityAgentDetail record) {
return baseMapper.insertOrUpdateSelective(record);
}
@Override
public MailContentRow getPingtuiChildRow(String dat, Integer agentId, String monthBegin, String monthEnd) {
return baseMapper.getPingtuiChildRow(dat, agentId, monthBegin, monthEnd);
}
}
package com.lanren.huhu.partner.service.impl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import com.lanren.huhu.partner.domain.AgentMailList;
import com.lanren.huhu.partner.dao.AgentMailListMapper;
import com.lanren.huhu.partner.service.AgentMailListService;
/**
* @author chen
* @title: ${NAME}
* @projectName partner
* @description: TODO
* @package ${PACKAGE_NAME}
* @date 2019-09-26 15:13
*/
@Service
public class AgentMailListServiceImpl extends ServiceImpl<AgentMailListMapper, AgentMailList> implements AgentMailListService {
@Override
public int batchInsert(List<AgentMailList> list) {
return baseMapper.batchInsert(list);
}
@Override
public int insertOrUpdate(AgentMailList record) {
return baseMapper.insertOrUpdate(record);
}
@Override
public int insertOrUpdateSelective(AgentMailList record) {
return baseMapper.insertOrUpdateSelective(record);
}
}
package com.lanren.huhu.partner.service.impl;
import com.lanren.huhu.partner.service.IMailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.util.Properties;
/**
* @author chen
* @title: IMailServiceImpl
* @projectName partner
* @package com.lanren.huhu.partner.service.impl
* @date 2019-09-26 19:59
*/
@Service
public class IMailServiceImpl implements IMailService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
/**
* Spring Boot 提供了一个发送邮件的简单抽象,使用的是下面这个接口,这里直接注入即可使用
*/
@Autowired
private JavaMailSenderImpl mailSender;
/**
* 配置
*/
@Value("${spring.mail.host}")
private String host;
@Value("${spring.mail.username}")
private String username;
@Value("${spring.mail.password}")
private String password;
@Value("${spring.mail.port}")
private String port;
@Value("${spring.mail.from}")
private String from;
@Override
public void sendMail(String subject, String text, File attachment, String[] tos) throws MessagingException {
MimeMessage mailMessage = configMailMessage();
configMessageHelper(mailMessage, subject, text, attachment, tos, new String[]{});
mailSender.send(mailMessage);
}
@Override
public void sendMailWithCc(String subject, String text, File attachment, String[] tos, String[] cc) throws MessagingException {
MimeMessage mailMessage = configMailMessage();
MimeMessageHelper mimeMessageHelper = configMessageHelper(mailMessage, subject, text, attachment, tos, new String[]{});
mimeMessageHelper.setCc(cc);
mailSender.send(mailMessage);
}
private MimeMessage configMailMessage() {
mailSender.setHost(host);
mailSender.setPort(Integer.parseInt(port));
mailSender.setUsername(username);
mailSender.setPassword(password);
mailSender.setDefaultEncoding("UTF-8");
Properties javaMailProperties = new Properties();
javaMailProperties.setProperty("mail.smtp.auth", "true");
javaMailProperties.setProperty("mail.smtp.timeout", "25000");
mailSender.setJavaMailProperties(javaMailProperties);
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.setFrom(from);
mimeMessageHelper.setSubject(subject);
mimeMessageHelper.setText(text, true);
if (attachment != null) {
mimeMessageHelper.addAttachment(attachment.getName(), attachment);
}
mimeMessageHelper.setTo(tos);
return mimeMessageHelper;
}
}
package com.lanren.huhu.partner.service.impl;
import com.lanren.huhu.partner.model.MailContentRow;
import com.lanren.huhu.partner.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author chen
* @title: MailReportServiceImpl
* @projectName partner
* @description: TODO
* @package com.lanren.huhu.partner.service.impl
* @date 2019-09-26 23:41
*/
@Service
public class MailReportServiceImpl implements MailReportService {
@Autowired
AgentExpandDailyService agentExpandDailyService;
@Autowired
AgentRewardService agentRewardService;
@Autowired
AgentExpandDetailService agentExpandDetailService;
@Autowired
AgentExpandCityAgentDetailService agentExpandCityAgentDetailService;
@Override
public MailContentRow getRegRow(String dat, Integer agentId, String monthBegin, String monthEnd) {
return agentExpandDailyService.getRegRow(dat, agentId, monthBegin, monthEnd);
}
@Override
public List<MailContentRow> getVipRows(String yesterdayBegin, String yesterdayEnd, Integer agentId, String monthBegin, String monthEnd) {
return agentExpandDailyService.getVipRows(yesterdayBegin, yesterdayEnd, agentId, monthBegin, monthEnd);
}
@Override
public List<MailContentRow> getCengjiChildRows(String yesterdayBegin, String yesterdayEnd, Integer agentId, String monthBegin, String monthEnd) {
return agentExpandDetailService.getCengjiChildRows(yesterdayBegin, yesterdayEnd, agentId, monthBegin, monthEnd);
}
@Override
public MailContentRow getPingtuiChildRow(String dat, Integer agentId, String monthBegin, String monthEnd) {
return agentExpandCityAgentDetailService.getPingtuiChildRow(dat, agentId, monthBegin, monthEnd);
}
@Override
public List<MailContentRow> getsVipRows(String yesterdayBegin, String yesterdayEnd, Integer agentId, String monthBegin, String monthEnd) {
return agentExpandDetailService.getsVipRows(yesterdayBegin, yesterdayEnd, agentId, monthBegin, monthEnd);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lanren.huhu.partner.dao.AgentExpandCityAgentDetailMapper">
<resultMap id="BaseResultMap" type="com.lanren.huhu.partner.domain.AgentExpandCityAgentDetail">
<!--@mbg.generated-->
<id column="dat" jdbcType="DATE" property="dat" />
<id column="agent_id" jdbcType="INTEGER" property="agentId" />
<id column="expand_agent_id" jdbcType="INTEGER" property="expandAgentId" />
<result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="expand_user_id" jdbcType="INTEGER" property="expandUserId" />
<result column="expand_agent_time" jdbcType="TIMESTAMP" property="expandAgentTime" />
<result column="created_at" jdbcType="INTEGER" property="createdAt" />
<result column="updated_at" jdbcType="INTEGER" property="updatedAt" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
dat, agent_id, expand_agent_id, user_id, expand_user_id, expand_agent_time, created_at,
updated_at
</sql>
<update id="updateBatch" parameterType="java.util.List">
<!--@mbg.generated-->
update agent_expand_city_agent_detail
<trim prefix="set" suffixOverrides=",">
<trim prefix="user_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when dat = #{item.dat,jdbcType=DATE} then #{item.userId,jdbcType=INTEGER}
</foreach>
</trim>
<trim prefix="expand_user_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when dat = #{item.dat,jdbcType=DATE} then #{item.expandUserId,jdbcType=INTEGER}
</foreach>
</trim>
<trim prefix="expand_agent_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when dat = #{item.dat,jdbcType=DATE} then #{item.expandAgentTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
<trim prefix="created_at = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when dat = #{item.dat,jdbcType=DATE} then #{item.createdAt,jdbcType=INTEGER}
</foreach>
</trim>
<trim prefix="updated_at = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when dat = #{item.dat,jdbcType=DATE} then #{item.updatedAt,jdbcType=INTEGER}
</foreach>
</trim>
</trim>
where dat in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.dat,jdbcType=DATE}
</foreach>
</update>
<insert id="batchInsert" parameterType="map">
<!--@mbg.generated-->
insert into agent_expand_city_agent_detail
(dat, agent_id, expand_agent_id, user_id, expand_user_id, expand_agent_time, created_at,
updated_at)
values
<foreach collection="list" item="item" separator=",">
(#{item.dat,jdbcType=DATE}, #{item.agentId,jdbcType=INTEGER}, #{item.expandAgentId,jdbcType=INTEGER},
#{item.userId,jdbcType=INTEGER}, #{item.expandUserId,jdbcType=INTEGER}, #{item.expandAgentTime,jdbcType=TIMESTAMP},
#{item.createdAt,jdbcType=INTEGER}, #{item.updatedAt,jdbcType=INTEGER})
</foreach>
</insert>
<insert id="insertOrUpdate" parameterType="com.lanren.huhu.partner.domain.AgentExpandCityAgentDetail">
<!--@mbg.generated-->
insert into agent_expand_city_agent_detail
(dat, agent_id, expand_agent_id, user_id, expand_user_id, expand_agent_time, created_at,
updated_at)
values
(#{dat,jdbcType=DATE}, #{agentId,jdbcType=INTEGER}, #{expandAgentId,jdbcType=INTEGER},
#{userId,jdbcType=INTEGER}, #{expandUserId,jdbcType=INTEGER}, #{expandAgentTime,jdbcType=TIMESTAMP},
#{createdAt,jdbcType=INTEGER}, #{updatedAt,jdbcType=INTEGER})
on duplicate key update
dat = #{dat,jdbcType=DATE},
agent_id = #{agentId,jdbcType=INTEGER},
expand_agent_id = #{expandAgentId,jdbcType=INTEGER},
user_id = #{userId,jdbcType=INTEGER},
expand_user_id = #{expandUserId,jdbcType=INTEGER},
expand_agent_time = #{expandAgentTime,jdbcType=TIMESTAMP},
created_at = #{createdAt,jdbcType=INTEGER},
updated_at = #{updatedAt,jdbcType=INTEGER}
</insert>
<insert id="insertOrUpdateSelective" parameterType="com.lanren.huhu.partner.domain.AgentExpandCityAgentDetail">
<!--@mbg.generated-->
insert into agent_expand_city_agent_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="dat != null">
dat,
</if>
<if test="agentId != null">
agent_id,
</if>
<if test="expandAgentId != null">
expand_agent_id,
</if>
<if test="userId != null">
user_id,
</if>
<if test="expandUserId != null">
expand_user_id,
</if>
<if test="expandAgentTime != null">
expand_agent_time,
</if>
<if test="createdAt != null">
created_at,
</if>
<if test="updatedAt != null">
updated_at,
</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="dat != null">
#{dat,jdbcType=DATE},
</if>
<if test="agentId != null">
#{agentId,jdbcType=INTEGER},
</if>
<if test="expandAgentId != null">
#{expandAgentId,jdbcType=INTEGER},
</if>
<if test="userId != null">
#{userId,jdbcType=INTEGER},
</if>
<if test="expandUserId != null">
#{expandUserId,jdbcType=INTEGER},
</if>
<if test="expandAgentTime != null">
#{expandAgentTime,jdbcType=TIMESTAMP},
</if>
<if test="createdAt != null">
#{createdAt,jdbcType=INTEGER},
</if>
<if test="updatedAt != null">
#{updatedAt,jdbcType=INTEGER},
</if>
</trim>
on duplicate key update
<trim suffixOverrides=",">
<if test="dat != null">
dat = #{dat,jdbcType=DATE},
</if>
<if test="agentId != null">
agent_id = #{agentId,jdbcType=INTEGER},
</if>
<if test="expandAgentId != null">
expand_agent_id = #{expandAgentId,jdbcType=INTEGER},
</if>
<if test="userId != null">
user_id = #{userId,jdbcType=INTEGER},
</if>
<if test="expandUserId != null">
expand_user_id = #{expandUserId,jdbcType=INTEGER},
</if>
<if test="expandAgentTime != null">
expand_agent_time = #{expandAgentTime,jdbcType=TIMESTAMP},
</if>
<if test="createdAt != null">
created_at = #{createdAt,jdbcType=INTEGER},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="getPingtuiChildRow" resultType="com.lanren.huhu.partner.model.MailContentRow">
SELECT
'城市代理' c1,
'推荐' c2,
COUNT(case when dat=#{dat} then expand_agent_id else 0 end) c3,
COUNT(case when dat>='2019-08-16' then expand_agent_id else 0 end) c4,
COUNT(case when dat between date(#{monthBegin}) and date(#{monthEnd}) then expand_agent_id else 0 end) c5,
COUNT(expand_agent_id) c6
FROM agent_expand_city_agent_detail
WHERE agent_id=#{agentId}
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lanren.huhu.partner.dao.AgentMailListMapper">
<resultMap id="BaseResultMap" type="com.lanren.huhu.partner.domain.AgentMailList">
<!--@mbg.generated-->
<result column="id" jdbcType="INTEGER" property="id" />
<result column="agent_id" jdbcType="INTEGER" property="agentId" />
<result column="agent_name" jdbcType="VARCHAR" property="agentName" />
<result column="agent_phone" jdbcType="VARCHAR" property="agentPhone" />
<result column="agent_mail" jdbcType="VARCHAR" property="agentMail" />
<result column="agent_cc" jdbcType="VARCHAR" property="agentCc" />
<result column="mail_type" jdbcType="TINYINT" property="mailType" />
</resultMap>
<insert id="batchInsert" parameterType="map">
<!--@mbg.generated-->
insert into agent_mail_list
(id, agent_id, agent_name, agent_phone, agent_mail, agent_cc, mail_type)
values
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=INTEGER}, #{item.agentId,jdbcType=INTEGER}, #{item.agentName,jdbcType=VARCHAR},
#{item.agentPhone,jdbcType=VARCHAR}, #{item.agentMail,jdbcType=VARCHAR}, #{item.agentCc,jdbcType=VARCHAR},
#{item.mailType,jdbcType=TINYINT})
</foreach>
</insert>
<insert id="insertOrUpdate" parameterType="com.lanren.huhu.partner.domain.AgentMailList">
<!--@mbg.generated-->
insert into agent_mail_list
(id, agent_id, agent_name, agent_phone, agent_mail, agent_cc, mail_type)
values
(#{id,jdbcType=INTEGER}, #{agentId,jdbcType=INTEGER}, #{agentName,jdbcType=VARCHAR},
#{agentPhone,jdbcType=VARCHAR}, #{agentMail,jdbcType=VARCHAR}, #{agentCc,jdbcType=VARCHAR},
#{mailType,jdbcType=TINYINT})
on duplicate key update
id = #{id,jdbcType=INTEGER},
agent_id = #{agentId,jdbcType=INTEGER},
agent_name = #{agentName,jdbcType=VARCHAR},
agent_phone = #{agentPhone,jdbcType=VARCHAR},
agent_mail = #{agentMail,jdbcType=VARCHAR},
agent_cc = #{agentCc,jdbcType=VARCHAR},
mail_type = #{mailType,jdbcType=TINYINT}
</insert>
<insert id="insertOrUpdateSelective" parameterType="com.lanren.huhu.partner.domain.AgentMailList">
<!--@mbg.generated-->
insert into agent_mail_list
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="agentId != null">
agent_id,
</if>
<if test="agentName != null">
agent_name,
</if>
<if test="agentPhone != null">
agent_phone,
</if>
<if test="agentMail != null">
agent_mail,
</if>
<if test="agentCc != null">
agent_cc,
</if>
<if test="mailType != null">
mail_type,
</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="agentId != null">
#{agentId,jdbcType=INTEGER},
</if>
<if test="agentName != null">
#{agentName,jdbcType=VARCHAR},
</if>
<if test="agentPhone != null">
#{agentPhone,jdbcType=VARCHAR},
</if>
<if test="agentMail != null">
#{agentMail,jdbcType=VARCHAR},
</if>
<if test="agentCc != null">
#{agentCc,jdbcType=VARCHAR},
</if>
<if test="mailType != null">
#{mailType,jdbcType=TINYINT},
</if>
</trim>
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
</if>
<if test="agentId != null">
agent_id = #{agentId,jdbcType=INTEGER},
</if>
<if test="agentName != null">
agent_name = #{agentName,jdbcType=VARCHAR},
</if>
<if test="agentPhone != null">
agent_phone = #{agentPhone,jdbcType=VARCHAR},
</if>
<if test="agentMail != null">
agent_mail = #{agentMail,jdbcType=VARCHAR},
</if>
<if test="agentCc != null">
agent_cc = #{agentCc,jdbcType=VARCHAR},
</if>
<if test="mailType != null">
mail_type = #{mailType,jdbcType=TINYINT},
</if>
</trim>
</insert>
</mapper>
\ No newline at end of file
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