Commit f65c7568 by dengshichuan

Merge branch 'dsc' into 'develop'

Dsc

See merge request 8timerv2/8timerapiv200!119
parents e3c1a587 8926af15
/**
* <p>Title: SendMessage.java</p>
* <p>Description: </p>
* @author dsc
* @date 2020年5月26日
* @version 1.0
*/
package cn.timer.api.bean.email;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* <p>Title: SendMessage.java</p>
* <p>Description: </p>
* @author dsc
* @date 2020年5月26日
* @version 1.0
*/
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "send_message")
@ApiModel("企业邮箱信息表")
public class SendMessage extends Model<SendMessage>{
private static final long serialVersionUID = -1599962875587367209L;
@Id
@GeneratedValue
@TableId(type = IdType.AUTO)
@ApiModelProperty(value = "编号")
private Integer id;
@ApiModelProperty(value = "创建id")
private Integer createdUser;
@ApiModelProperty(value = "创建时间")
private Date createdTime;
@ApiModelProperty(value = "邮件主题")
private String subject;
@ApiModelProperty(value = "邮件内容")
private String content;
@ApiModelProperty(value = "收件人邮箱")
private String receiverEmail;
}
...@@ -642,11 +642,24 @@ public class LoginController { ...@@ -642,11 +642,24 @@ public class LoginController {
} }
/**
* 绑定邮箱
*
* @param empNum
* @return
*/
@GetMapping(value = "/band/{empNum}") @GetMapping(value = "/band/{empNum}")
public Result<Object> bandEmail(@PathVariable Integer empNum) { public Result<Object> bandEmail(@PathVariable Integer empNum) {
if (QyzxEmpLogin.builder().id(empNum).emailStatus(1).build().updateById()) { QyzxEmpLogin qyzxEmpLogin = QyzxEmpLogin.builder().id(empNum).build().selectById();
return ResultUtil.success("绑定成功"); if (qyzxEmpLogin == null)
} return ResultUtil.error("员工不存在");
Integer emailStatus = qyzxEmpLogin.getEmailStatus();
if (emailStatus != 0 && emailStatus != 1)
return ResultUtil.error("请确认邮箱绑定状态");
if (emailStatus == 1)
return ResultUtil.error("邮箱已绑定,请勿重复绑定");
if (QyzxEmpLogin.builder().id(empNum).emailStatus(1).build().updateById())
return ResultUtil.error("绑定成功");
return ResultUtil.error("绑定失败"); return ResultUtil.error("绑定失败");
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
package cn.timer.api.controller.email; package cn.timer.api.controller.email;
import java.io.File; import java.io.File;
import java.util.Date;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
...@@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import cn.timer.api.bean.email.SendMessage;
import cn.timer.api.bean.qyzx.QyzxEmpLogin; import cn.timer.api.bean.qyzx.QyzxEmpLogin;
import cn.timer.api.config.annotation.CurrentUser; import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean; import cn.timer.api.config.annotation.UserBean;
...@@ -72,7 +74,7 @@ public class EmailController { ...@@ -72,7 +74,7 @@ public class EmailController {
@PostMapping("/sendHtmlMail") @PostMapping("/sendHtmlMail")
@ApiOperation(value = "发送html邮件", httpMethod = "POST", notes = "接口发布说明") @ApiOperation(value = "发送html邮件", httpMethod = "POST", notes = "接口发布说明")
public Result<Void> sendHtmlMail(String to, String subject, String content) { public Result<Void> sendHtmlMail(@CurrentUser UserBean userBean, String to, String subject, String content) {
MimeMessage message = mailSender.createMimeMessage(); MimeMessage message = mailSender.createMimeMessage();
try { try {
MimeMessageHelper helper = new MimeMessageHelper(message, true); MimeMessageHelper helper = new MimeMessageHelper(message, true);
...@@ -81,10 +83,14 @@ public class EmailController { ...@@ -81,10 +83,14 @@ public class EmailController {
helper.setSubject(subject); helper.setSubject(subject);
helper.setText(content, true); helper.setText(content, true);
mailSender.send(message); mailSender.send(message);
} catch (MessagingException e) { } catch (MessagingException e) {
e.printStackTrace(); e.printStackTrace();
} }
return ResultUtil.success(); if (SendMessage.builder().content(content).createdTime(new Date()).createdUser(userBean.getEmpNum())
.receiverEmail(to).subject(subject).build().insert())
return ResultUtil.success("邮件发送成功");
return ResultUtil.error("邮件发送失败");
} }
@PostMapping("/sendAttchmentMail") @PostMapping("/sendAttchmentMail")
...@@ -128,35 +134,34 @@ public class EmailController { ...@@ -128,35 +134,34 @@ public class EmailController {
return ResultUtil.success(); return ResultUtil.success();
} }
@Transactional
@PostMapping("/bindEmailAddress") @PostMapping("/bindEmailAddress")
@ApiOperation(value = "绑定邮箱", httpMethod = "POST", notes = "接口发布说明") @ApiOperation(value = "绑定邮箱", httpMethod = "POST", notes = "接口发布说明")
public Result<Void> bindEmailAddress(@CurrentUser UserBean userBean, String to) { public Result<Void> bindEmailAddress(@CurrentUser UserBean userBean, String to) {
QyzxEmpLogin.builder().id(userBean.getEmpNum()).email(to).emailStatus(0).build().updateById(); Integer empNum = userBean.getEmpNum();
return sendHtmlMail(to, "8小时账号邮箱验证", "<html>\r\n" + QyzxEmpLogin qyzxEmpLogin = QyzxEmpLogin.builder().id(empNum).build().selectById();
"<head>\r\n" + if (qyzxEmpLogin == null)
"<meta charset=\"UTF-8\">\r\n" + return ResultUtil.error("请确认员工状态");
"</head>\r\n" + if (qyzxEmpLogin.getEmail() != null && qyzxEmpLogin.getEmailStatus() != null
"<body>\r\n" + && qyzxEmpLogin.getEmailStatus() == 1)
" <h1>您好,感谢绑定<a href=\"http://8timer.cn\">8小时人事管家</a>,点击下面链接完成验证,感谢支持!<h1>\r\n" + return ResultUtil.error("该账号已绑定过邮箱");
" <br />\r\n" + qyzxEmpLogin.setEmail(to);
" <a href=\"http://test-8timer-api.youlingrc.com/login/band/"+userBean.getEmpNum()+"\">激活账户</a>\r\n" + qyzxEmpLogin.setEmailStatus(0);
"</body>\r\n" + qyzxEmpLogin.updateById();
"</html>"); return sendHtmlMail(userBean, to, "8小时账号邮箱验证",
"<html>\r\n" + "<head>\r\n" + "<meta charset=\"UTF-8\">\r\n" + "</head>\r\n" + "<body>\r\n"
+ " <h1>您好,感谢绑定<a href=\"http://8timer.cn\">8小时人事管家</a>,点击下面链接完成验证,感谢支持!<h1>\r\n"
+ " <br />\r\n" + " <a href=\"http://test-8timer-api.youlingrc.com/login/band/" + empNum
+ "\">激活账户</a>\r\n" + "</body>\r\n" + "</html>");
} }
@PostMapping("/sendVerifyMail") @PostMapping("/sendVerifyMail")
@ApiOperation(value = "发送注册验证邮件", httpMethod = "POST", notes = "接口发布说明") @ApiOperation(value = "发送注册验证邮件", httpMethod = "POST", notes = "接口发布说明")
public Result<Void> sendVerifyMail(@CurrentUser UserBean userBean, String to) { public Result<Void> sendVerifyMail(@CurrentUser UserBean userBean, String to) {
return sendHtmlMail(to, "8小时账号邮箱验证", "<html>\r\n" + return sendHtmlMail(userBean, to, "8小时账号邮箱验证",
"<head>\r\n" + "<html>\r\n" + "<head>\r\n" + "<meta charset=\"UTF-8\">\r\n" + "</head>\r\n" + "<body>\r\n"
"<meta charset=\"UTF-8\">\r\n" + + " <h1>您好,感谢注册<a href=\"http://8timer.cn\">8小时人事管家</a>,点击下面链接完成验证,感谢支持!<h1>\r\n"
"</head>\r\n" + + " <br />\r\n" + " <a href=\"https://www.4399.com\">激活账户</a>\r\n" + "</body>\r\n" + "</html>");
"<body>\r\n" +
" <h1>您好,感谢注册<a href=\"http://8timer.cn\">8小时人事管家</a>,点击下面链接完成验证,感谢支持!<h1>\r\n" +
" <br />\r\n" +
" <a href=\"https://www.4399.com\">激活账户</a>\r\n" +
"</body>\r\n" +
"</html>");
} }
} }
package cn.timer.api.dao.email;
import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.timer.api.bean.email.SendMessage;
@Repository
public interface SendMessageMapper extends BaseMapper<SendMessage> {
}
...@@ -87,13 +87,11 @@ spring: ...@@ -87,13 +87,11 @@ spring:
invert: false # Whether images should be inverted for dark terminal themes. invert: false # Whether images should be inverted for dark terminal themes.
mail: mail:
host: smtp.qq.com host: smtp.youlingrc.com
username: 544939826@qq.com #dsc username: postmaster@youlingrc.com
password: cxvkrjyjzfpbbbce password: YoulingRC2020
default-encoding: utf-8 default-encoding: utf-8
######### Spring boot应用健康监控 ######### Spring boot应用健康监控
management: management:
server: server:
......
...@@ -86,9 +86,9 @@ spring: ...@@ -86,9 +86,9 @@ spring:
margin: 2 # Left hand image margin in chars. margin: 2 # Left hand image margin in chars.
invert: false # Whether images should be inverted for dark terminal themes. invert: false # Whether images should be inverted for dark terminal themes.
mail: mail:
host: smtp.qq.com host: smtp.youlingrc.com
username: username: postmaster@youlingrc.com
password: password: YoulingRC2020
default-encoding: utf-8 default-encoding: utf-8
# mybatis-plus # mybatis-plus
......
...@@ -86,9 +86,9 @@ spring: ...@@ -86,9 +86,9 @@ spring:
margin: 2 # Left hand image margin in chars. margin: 2 # Left hand image margin in chars.
invert: false # Whether images should be inverted for dark terminal themes. invert: false # Whether images should be inverted for dark terminal themes.
mail: mail:
host: smtp.qq.com host: smtp.youlingrc.com
username: 544939826@qq.com username: postmaster@youlingrc.com
password: cxvkrjyjzfpbbbce password: YoulingRC2020
default-encoding: utf-8 default-encoding: utf-8
# mybatis-plus # mybatis-plus
......
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