发邮件功能处理提交
日志功能修复
This commit is contained in:
@@ -76,14 +76,15 @@ serverIp=http://127.0.0.1:7060/
|
||||
#MAIL_USERNAME=cagds@catarc.ac.cn
|
||||
#MAIL_PASSWORD=Cagds9760
|
||||
|
||||
MAIL_SMTP =smtp.163.com
|
||||
MAIL_SMTP_PORT=465
|
||||
MAIL_USERNAME=simashihao@163.com
|
||||
MAIL_PASSWORD=VQBNNQBLDIALAYCV
|
||||
spring.mail.host=smtp.qq.com
|
||||
spring.mail.port=587
|
||||
spring.mail.username=lixuetao0606@foxmail.com
|
||||
spring.mail.password=redkceqbcgrzbfba
|
||||
spring.mail.from=lixuetao0606@foxmail.com
|
||||
|
||||
#MAIL_SMTP =cmp.changan.com
|
||||
#MAIL_SMTP_PORT=25
|
||||
MAIL_POP_PORT=110
|
||||
#MAIL_POP_PORT=110
|
||||
#MAIL_USERNAME=64459@Any3.com
|
||||
#MAIL_PASSWORD=65316975Xiaoq
|
||||
|
||||
|
||||
@@ -62,7 +62,12 @@ public class ReportLogAspect {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
LogEntity entity = new LogEntity();
|
||||
|
||||
entity.setAccount(UserUtils.getUser().getAccount());
|
||||
if (UserUtils.getUser() == null){
|
||||
entity.setAccount("系统自动操作");
|
||||
} else {
|
||||
entity.setAccount(UserUtils.getUser().getAccount());
|
||||
}
|
||||
|
||||
entity.setClassName(cs.getName());
|
||||
entity.setOperateTime(format.format(new Date()));
|
||||
entity.setMethod(name);
|
||||
|
||||
@@ -765,7 +765,12 @@ public class ReportManageConroller {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
LogEntity entity = new LogEntity();
|
||||
|
||||
entity.setAccount(UserUtils.getUser().getAccount());
|
||||
if (UserUtils.getUser() == null){
|
||||
entity.setAccount("系统自动操作");
|
||||
} else {
|
||||
entity.setAccount(UserUtils.getUser().getAccount());
|
||||
}
|
||||
|
||||
entity.setClassName("com.adc.da.report.controller.ReportManageConroller");
|
||||
entity.setOperateTime(format.format(new Date()));
|
||||
entity.setMethod("downloadPic");
|
||||
|
||||
@@ -931,7 +931,12 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
LogEntity entity = new LogEntity();
|
||||
|
||||
entity.setAccount(UserUtils.getUser().getAccount());
|
||||
if (UserUtils.getUser() == null){
|
||||
entity.setAccount("系统自动操作");
|
||||
} else {
|
||||
entity.setAccount(UserUtils.getUser().getAccount());
|
||||
}
|
||||
|
||||
entity.setClassName("com.adc.da.report.service.impl.IReportServiceImpl");
|
||||
entity.setOperateTime(format.format(new Date()));
|
||||
entity.setMethod("reportDetail");
|
||||
|
||||
+8
-3
@@ -170,10 +170,15 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>javax.mail</groupId>-->
|
||||
<!-- <artifactId>mail</artifactId>-->
|
||||
<!-- <version>1.4.7</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.4.7</version>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.adc.da.sys.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.File;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EmailUtil {
|
||||
|
||||
//Spring Boot 提供了一个发送邮件的简单抽象,使用的是下面这个接口,这里直接注入即可使用
|
||||
@Resource
|
||||
private JavaMailSender mailSender;
|
||||
|
||||
// 配置文件中我的qq邮箱
|
||||
@Value("${spring.mail.from}")
|
||||
private String from;
|
||||
|
||||
/**
|
||||
* 简单文本邮件
|
||||
* @param to 收件人
|
||||
* @param subject 主题
|
||||
* @param content 内容
|
||||
*/
|
||||
public void sendSimpleMail(String to, String subject, String content) {
|
||||
//创建SimpleMailMessage对象
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
//邮件发送人
|
||||
message.setFrom(from);
|
||||
//邮件接收人
|
||||
message.setTo(to);
|
||||
//邮件主题
|
||||
message.setSubject(subject);
|
||||
//邮件内容
|
||||
message.setText(content);
|
||||
//发送邮件
|
||||
mailSender.send(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* html邮件
|
||||
* @param to 收件人,多个时参数形式 :"xxx@xxx.com,xxx@xxx.com,xxx@xxx.com"
|
||||
* @param subject 主题
|
||||
* @param content 内容
|
||||
*/
|
||||
public void sendHtmlMail(String to, String subject, String content) {
|
||||
//获取MimeMessage对象
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper messageHelper;
|
||||
try {
|
||||
messageHelper = new MimeMessageHelper(message, true);
|
||||
//邮件发送人
|
||||
messageHelper.setFrom(from);
|
||||
//邮件接收人,设置多个收件人地址
|
||||
InternetAddress[] internetAddressTo = InternetAddress.parse(to);
|
||||
messageHelper.setTo(internetAddressTo);
|
||||
//messageHelper.setTo(to);
|
||||
//邮件主题
|
||||
message.setSubject(subject);
|
||||
//邮件内容,html格式
|
||||
messageHelper.setText(content, true);
|
||||
//发送
|
||||
mailSender.send(message);
|
||||
//日志信息
|
||||
log.info("邮件已经发送。");
|
||||
} catch (Exception e) {
|
||||
log.error("发送邮件时发生异常!", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 带附件的邮件
|
||||
* @param to 收件人
|
||||
* @param subject 主题
|
||||
* @param content 内容
|
||||
* @param filePath 附件
|
||||
*/
|
||||
public void sendAttachmentsMail(String to, String subject, String content, String filePath) {
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
try {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||
helper.setFrom(from);
|
||||
helper.setTo(to);
|
||||
helper.setSubject(subject);
|
||||
helper.setText(content, true);
|
||||
|
||||
FileSystemResource file = new FileSystemResource(new File(filePath));
|
||||
String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
|
||||
helper.addAttachment(fileName, file);
|
||||
mailSender.send(message);
|
||||
//日志信息
|
||||
log.info("邮件已经发送。");
|
||||
} catch (Exception e) {
|
||||
log.error("发送邮件时发生异常!", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+49
@@ -1,8 +1,16 @@
|
||||
package com.adc.da.wkflow.listener.powerApply;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.adc.da.login.util.UserUtils;
|
||||
import com.adc.da.report.dao.mysql.PowerApplyActDao;
|
||||
import com.adc.da.report.dao.mysql.ReportDao;
|
||||
import com.adc.da.report.eo.PowerApplyAct;
|
||||
import com.adc.da.report.service.IReportService;
|
||||
import com.adc.da.report.vo.ReportDetailVo;
|
||||
import com.adc.da.sys.entity.UserEO;
|
||||
import com.adc.da.sys.service.iservice.IUserEoService;
|
||||
import com.adc.da.sys.util.EmailUtil;
|
||||
import com.adc.da.sys.util.EncryptUtil;
|
||||
import com.adc.da.wkflow.business_main.entity.BusProcessApprove;
|
||||
import com.adc.da.wkflow.business_main.entity.BusProcessNew;
|
||||
import com.adc.da.wkflow.business_main.service.IBusProcessApproveService;
|
||||
@@ -14,6 +22,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.activiti.engine.delegate.DelegateTask;
|
||||
import org.activiti.engine.delegate.TaskListener;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -26,6 +35,10 @@ public class oneApplyAfter implements TaskListener {
|
||||
PowerApplyActDao powerApplyActDao = SpringContextUtil.getBean(PowerApplyActDao.class);
|
||||
IBusProcessNewService busBean = SpringContextUtil.getBean(IBusProcessNewService.class);
|
||||
IBusProcessApproveService approveService = SpringContextUtil.getBean(IBusProcessApproveService.class);
|
||||
IUserEoService userEoService = SpringContextUtil.getBean(IUserEoService.class);
|
||||
EmailUtil emailUtil = SpringContextUtil.getBean(EmailUtil.class);
|
||||
ReportDao reportDao = SpringContextUtil.getBean(ReportDao.class);
|
||||
|
||||
//查询task任务
|
||||
LambdaQueryWrapper<PowerApplyAct> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(PowerApplyAct::getPrcId, delegateTask.getProcessInstanceId());
|
||||
@@ -59,5 +72,41 @@ public class oneApplyAfter implements TaskListener {
|
||||
//审批人
|
||||
delegateTask.setVariable("oneApprove",object.getString("oneApprove"));
|
||||
delegateTask.setVariable("twoApprove",object.getString("twoApprove"));
|
||||
|
||||
try {
|
||||
if (StrUtil.isNotEmpty(powerApplyAct.getUserId())){
|
||||
UserEO userEO = userEoService.getUserById(powerApplyAct.getUserId());
|
||||
if (userEO != null && StrUtil.isNotEmpty(userEO.getEmail())){
|
||||
// 给email解码
|
||||
String email = EncryptUtil.decrypt(userEO.getEmail()).toString();
|
||||
|
||||
// 获取文件信息
|
||||
String reportId = powerApplyAct.getReportId();
|
||||
ReportDetailVo reportDetailVo = reportDao.reportDetail(reportId);
|
||||
|
||||
String approveOption = "";
|
||||
if ("1".equals(s)){
|
||||
approveOption = "通过";
|
||||
} else {
|
||||
approveOption = "不通过";
|
||||
}
|
||||
|
||||
String title = reportDetailVo.getName() + "文件权限申请一级审批" + approveOption;
|
||||
|
||||
String powerStr = "";
|
||||
if(powerApplyAct.getPower() == 1){
|
||||
powerStr = "预览";
|
||||
} else if(powerApplyAct.getPower() == 2){
|
||||
powerStr = "预览+下载";
|
||||
}
|
||||
|
||||
String content = reportDetailVo.getName() + "文件" + powerStr + "权限申请一级审批完成,审核结果:" + approveOption + "。";
|
||||
// 发邮件给发起人
|
||||
emailUtil.sendSimpleMail(email, title, content);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+49
@@ -1,9 +1,16 @@
|
||||
package com.adc.da.wkflow.listener.powerApply;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.adc.da.login.util.UserUtils;
|
||||
import com.adc.da.report.dao.mysql.PowerApplyActDao;
|
||||
import com.adc.da.report.dao.mysql.PowerApplyDao;
|
||||
import com.adc.da.report.dao.mysql.ReportDao;
|
||||
import com.adc.da.report.eo.PowerApplyAct;
|
||||
import com.adc.da.report.vo.ReportDetailVo;
|
||||
import com.adc.da.sys.entity.UserEO;
|
||||
import com.adc.da.sys.service.iservice.IUserEoService;
|
||||
import com.adc.da.sys.util.EmailUtil;
|
||||
import com.adc.da.sys.util.EncryptUtil;
|
||||
import com.adc.da.wkflow.business_main.entity.BusProcessApprove;
|
||||
import com.adc.da.wkflow.business_main.entity.BusProcessNew;
|
||||
import com.adc.da.wkflow.business_main.service.IBusProcessApproveService;
|
||||
@@ -16,6 +23,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.activiti.engine.delegate.DelegateTask;
|
||||
import org.activiti.engine.delegate.TaskListener;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -23,6 +31,7 @@ import java.util.List;
|
||||
*/
|
||||
public class twoApplyAfter implements TaskListener {
|
||||
|
||||
|
||||
@Override
|
||||
public void notify(DelegateTask delegateTask) {
|
||||
PowerApplyActDao powerApplyActDao = SpringContextUtil.getBean(PowerApplyActDao.class);
|
||||
@@ -30,6 +39,10 @@ public class twoApplyAfter implements TaskListener {
|
||||
IBusProcessNewService busBean = SpringContextUtil.getBean(IBusProcessNewService.class);
|
||||
IBusProcessNameService busProcessNameService = SpringContextUtil.getBean(IBusProcessNameService.class);
|
||||
IBusProcessApproveService approveService = SpringContextUtil.getBean(IBusProcessApproveService.class);
|
||||
IUserEoService userEoService = SpringContextUtil.getBean(IUserEoService.class);
|
||||
EmailUtil emailUtil = SpringContextUtil.getBean(EmailUtil.class);
|
||||
ReportDao reportDao = SpringContextUtil.getBean(ReportDao.class);
|
||||
|
||||
//查询task任务
|
||||
LambdaQueryWrapper<PowerApplyAct> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(PowerApplyAct::getPrcId, delegateTask.getProcessInstanceId());
|
||||
@@ -65,5 +78,41 @@ public class twoApplyAfter implements TaskListener {
|
||||
powerApplyDao.savePowerAct(powerApplyAct);
|
||||
busProcessNameService.stopAct(delegateTask.getProcessInstanceId());
|
||||
}
|
||||
|
||||
try {
|
||||
if (StrUtil.isNotEmpty(powerApplyAct.getUserId())){
|
||||
UserEO userEO = userEoService.getUserById(powerApplyAct.getUserId());
|
||||
if (userEO != null && StrUtil.isNotEmpty(userEO.getEmail())){
|
||||
// 给email解码
|
||||
String email = EncryptUtil.decrypt(userEO.getEmail()).toString();
|
||||
|
||||
// 获取文件信息
|
||||
String reportId = powerApplyAct.getReportId();
|
||||
ReportDetailVo reportDetailVo = reportDao.reportDetail(reportId);
|
||||
|
||||
String approveOption = "";
|
||||
if ("1".equals(s)){
|
||||
approveOption = "通过";
|
||||
} else {
|
||||
approveOption = "不通过";
|
||||
}
|
||||
|
||||
String title = reportDetailVo.getName() + "文件权限申请二级审批" + approveOption;
|
||||
|
||||
String powerStr = "";
|
||||
if(powerApplyAct.getPower() == 1){
|
||||
powerStr = "预览";
|
||||
} else if(powerApplyAct.getPower() == 2){
|
||||
powerStr = "预览+下载";
|
||||
}
|
||||
|
||||
String content = reportDetailVo.getName() + "文件" + powerStr + "权限申请二级审批完成,审核结果:" + approveOption + "。";
|
||||
// 发邮件给发起人
|
||||
emailUtil.sendSimpleMail(email, title, content);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user