提交 55a871b4 authored 作者: luojie's avatar luojie

新增定时发送邮件,修改首页商品接口

上级 9463f368
......@@ -4,9 +4,11 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableCaching
@EnableScheduling
public class ZionApplication extends SpringBootServletInitializer {
//tomcat 设置
/*@Override
......
......@@ -8,4 +8,6 @@ public class EmailTemplateConstant {
public static String REGISTER="email-template.ftl";
//注册
public static String REGISTERS="email-templates.ftl";
//20191227
public static String REGISTER20191227="email-template2019-12-27.ftl";
}
......@@ -67,5 +67,7 @@ public interface TbCfUserInfoDao extends BaseDao<TbCfUserInfoEntity> {
List<TbCfUserInfoEntity> selectUserByPhone();
List<String> findEmails();
String findEmails();
int updateIsSend(String email);
}
......@@ -130,7 +130,6 @@ public class TbCfOrderEntity implements Serializable {
*/
private Integer enableFlag;
/**
* 商品品名
*/
......
......@@ -38,6 +38,11 @@ public class TbCfStationItemEntity implements Serializable {
* 商品价格
*/
private BigDecimal itemPrice;
/**
* 商品折扣价格
*/
private BigDecimal discountPrice;
/**
* 商品链接
*/
......@@ -282,4 +287,16 @@ public class TbCfStationItemEntity implements Serializable {
public String getItemDescritionId() {
return itemDescritionId;
}
/**
* 设置:商品折扣价格
*/
public BigDecimal getDiscountPrice() {
return discountPrice;
}
/**
* 获取:商品折扣价格
*/
public void setDiscountPrice(BigDecimal discountPrice) {
this.discountPrice = discountPrice;
}
}
......@@ -98,6 +98,11 @@ public class TbCfUserInfoEntity implements Serializable {
*/
private Integer emailFlag;
/**
* 是否已发送邮件 0 未发送,1已发送
*/
private Integer isSend;
/**
* 设置:用户id
*/
......@@ -366,4 +371,12 @@ public class TbCfUserInfoEntity implements Serializable {
public void setEmailFlag(Integer emailFlag) {
this.emailFlag = emailFlag;
}
public Integer getIsSend() {
return isSend;
}
public void setIsSend(Integer isSend) {
this.isSend = isSend;
}
}
......@@ -180,7 +180,10 @@ public interface TbCfUserInfoService {
Result queryUserByUserId(String userId);
List<TbCfUserInfoEntity> selectUserByPhone();
List<String> findEmails();
String sendRegister(String email) throws EmailException, TemplateException, IOException;
String findEmails();
int updateIsSend(String email);
}
......@@ -559,15 +559,21 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
return tbCfUserInfoDao.selectUserByPhone();
}
@Override
public String sendRegister(String email) throws EmailException, TemplateException, IOException {
emailHelper.sendEmail(email, EmailTemplateConstant.REGISTER20191227);
return "s";
}
@Override
public List<String> findEmails() {
public String findEmails() {
return tbCfUserInfoDao.findEmails();
}
@Override
public String sendRegister(String email) throws EmailException, TemplateException, IOException {
emailHelper.sendEmail(email, EmailTemplateConstant.REGISTERS);
return "s";
public int updateIsSend(String email) {
return tbCfUserInfoDao.updateIsSend(email);
}
......
package com.diaoyun.zion.master.quartz;
import com.diaoyun.zion.chinafrica.service.TbCfUserInfoService;
import freemarker.template.TemplateException;
import org.apache.commons.mail.EmailException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.List;
@Component
public class QuartzMethod {
@Autowired
private TbCfUserInfoService tbCfUserInfoService;
//@Scheduled(cron = "0 0/1 * * * ? ")
public void sendEmail() throws EmailException, TemplateException, IOException {
System.out.println("////////////////////////////////////////////////////");
String email= tbCfUserInfoService.findEmails();
// String email= "1203063316@qq.com";
if(email!=null){
String s = tbCfUserInfoService.sendRegister(email);
if(s!=null){
System.out.println("已发送邮件:"+email);
}
}
}
}
package com.diaoyun.zion.master.util;
import com.diaoyun.zion.chinafrica.service.TbCfUserInfoService;
import com.diaoyun.zion.master.bo.EmailTemplateBo;
import com.diaoyun.zion.master.config.DomainProperties;
import freemarker.template.Configuration;
......@@ -24,6 +25,8 @@ public class EmailHelper {
private Configuration configuration;
@Autowired
private DomainProperties domainProperties;
@Autowired
private TbCfUserInfoService tbCfUserInfoService;
private static Logger logger = LoggerFactory.getLogger(EmailHelper.class);
......@@ -53,10 +56,9 @@ public class EmailHelper {
//logger.info("邮件发送结果:"+res);
return emailTemplateBo.getIdentifyCode();
}
public void sendEmail(String email, String templateName) throws IOException, TemplateException, EmailException {
Template t = configuration.getTemplate(templateName);
Map<String,Object> model = new HashMap<>();
Map<String[],Object> model = new HashMap<>();
String html = FreeMarkerTemplateUtils.processTemplateIntoString(t, model);
HtmlEmail emails = new HtmlEmail();//创建一个HtmlEmail实例对象
emails.setHostName(domainProperties.getProperty("email.hostName"));//邮箱的SMTP服务器,一般123邮箱的是smtp.123.com,qq邮箱为smtp.qq.com
......@@ -65,9 +67,12 @@ public class EmailHelper {
emails.addTo(email);//设置收件人
emails.setFrom(domainProperties.getProperty("email.from.email"), domainProperties.getProperty("email.from.name"));//发送人的邮箱为自己的,用户名可以随便填
emails.setAuthentication(domainProperties.getProperty("email.authentication.userName"), domainProperties.getProperty("email.authentication.password"));//设置发送人的邮箱和用户名和授权码(授权码是自己设置的)
emails.setSubject(domainProperties.getProperty("email.subject"));//设置发送主题
emails.setSubject(domainProperties.getProperty("email.project"));//设置发送主题
emails.setMsg(html);//设置发送内容
String res=emails.send();
if(res!=null){
tbCfUserInfoService.updateIsSend(email);
}
logger.info("邮件发送结果:"+res);
}
}
......@@ -10,6 +10,7 @@
<result property="itemBrief" column="item_brief"/>
<result property="itemCategory" column="item_category"/>
<result property="itemPrice" column="item_price"/>
<result property="discountPrice" column="discount_price"/>
<result property="itemUrl" column="item_url"/>
<result property="itemImg" column="item_img"/>
<result property="itemNum" column="item_num"/>
......@@ -29,6 +30,7 @@
`item_brief`,
`item_category`,
`item_price`,
`discount_price`,
`item_url`,
`item_img`,
`item_num`,
......@@ -50,6 +52,7 @@
`item_brief`,
`item_category`,
`item_price`,
`discount_price`,
`item_url`,
`item_img`,
`item_num`,
......@@ -93,6 +96,7 @@
`item_brief`,
`item_category`,
`item_price`,
`discount_price`,
`item_url`,
`item_img`,
`item_num`,
......@@ -109,6 +113,7 @@
#{itemBrief},
#{itemCategory},
#{itemPrice},
#{discountPrice},
#{itemUrl},
#{itemImg},
#{itemNum},
......@@ -128,6 +133,7 @@
<if test="itemBrief != null">`item_brief` = #{itemBrief},</if>
<if test="itemCategory != null">`item_category` = #{itemCategory},</if>
<if test="itemPrice != null">`item_price` = #{itemPrice},</if>
<if test="discountPrice != null">`discount_price` = #{discountPrice},</if>
<if test="itemUrl != null">`item_url` = #{itemUrl},</if>
<if test="itemImg != null">`item_img` = #{itemImg},</if>
<if test="itemNum != null">`item_num` = #{itemNum},</if>
......@@ -160,6 +166,7 @@
`item_brief`,
`item_category`,
`item_price`,
`discount_price`,
`item_url`,
`item_img`,
`item_num`,
......@@ -182,6 +189,7 @@
`item_brief`,
`item_category`,
`item_price`,
`discount_price`,
`item_url`,
`item_img`,
`item_num`,
......@@ -201,6 +209,7 @@
`item_brief`,
`item_category`,
`item_price`,
`discount_price`,
`item_url`,
`item_img`,
`item_num`,
......@@ -221,6 +230,7 @@
`item_brief`,
`item_category`,
`item_price`,
`discount_price`,
`item_url`,
`item_img`,
`item_num`,
......
......@@ -25,6 +25,7 @@
<result property="invitedCount" column="invited_count"/>
<result property="enableFlag" column="enable_flag"/>
<result property="emailFlag" column="email_flag"/>
<result property="isSend" column="is_send"/>
</resultMap>
<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfUserInfoEntity">
......@@ -49,7 +50,8 @@
`invited_user_id`,
`invited_count`,
`enable_flag`,
`email_flag`
`email_flag`,
`is_send`
from tb_cf_user_info
where user_id = #{id}
</select>
......@@ -76,7 +78,8 @@
`invited_user_id`,
`invited_count`,
`enable_flag`,
`email_flag`
`email_flag`,
`is_send`
from tb_cf_user_info
WHERE 1=1
<if test="name != null and name.trim() != ''">
......@@ -134,7 +137,9 @@
`invited_user_id`,
`invited_count`,
`enable_flag`,
`email_flag`)
`email_flag`,
`is_send`
)
values(
#{userId},
#{userNo},
......@@ -156,7 +161,8 @@
#{invitedUserId},
#{invitedCount},
#{enableFlag},
#{emailFlag}
#{emailFlag},
#{isSend}
)
</insert>
......@@ -180,6 +186,7 @@
<if test="invitedCount != null">`invited_count` = #{invitedCount},</if>
<if test="enableFlag != null">`enable_flag` = #{enableFlag},</if>
<if test="emailFlag != null">`email_flag` = #{emailFlag}</if>
<if test="isSend != null">`is_send` = #{isSend}</if>
</set>
where user_id = #{userId}
</update>
......@@ -195,8 +202,14 @@
</foreach>
</delete>
<select id="findEmails" resultType="String">
select account from tb_cf_user_info where account LIKE concat('%@%')
select account from tb_cf_user_info where is_send=0 and account like '%@%' order by rand() limit 1
</select>
<!-- 修改用户是否发送邮件-->
<update id="updateIsSend">
update tb_cf_user_info set is_send=1 where account=#{email}
</update>
<!--根据nickname获取用户信息-->
<select id="getByNickname" resultType="com.diaoyun.zion.chinafrica.entity.TbCfUserInfoEntity">
select * from tb_cf_user_info where nickname=#{nickname}
......
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Afrishop Verification</title>
</head>
<body>
<section style="width: 600px;height :720px;margin:0 auto;box-sizing: border-box;position: relative;">
<img style="position:absolute;width: 600px;height :720px;top:0;left:0;" src="http://q2bspr5ox.bkt.clouddn.com/afrishop20191227.jpg" alt="背景图">
</section>
</body>
</html>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论