泛微E9二次开发,用计划任务定时发送邮件提醒
需求:员工借用的物品到期后,发送邮件提醒员工归还;
建模引擎有个提醒功能可以配置,但是按照教程配置之后一直不生效,只能自己动手写个计划任务来定期发送提醒了
1、源代码DeviceNotification.java
package weaver.interfaces.schedule;import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;public class DeviceNotification extends BaseCronJob {public String ccReceiver;//传入的参数,增加抄送人public void execute() {String title = "归还提醒";String content = "";String receiver = "";ccReceiver = this.getccReceiver();String userid = "";String username = "";String assetnum = "";String assetname = "";String returndate = "";RecordSet rs0 = new RecordSet();RecordSet rs = new RecordSet();RecordSet rs1 = new RecordSet();RecordSet rs2 = new RecordSet();RecordSet rs3 = new RecordSet();RecordSet rs4 = new RecordSet();String sql0 = "select distinct(resourceid) userid from cptcapital where capitalgroupid=26 and isdata=2 and enddate<=current_date()";rs0.execute(sql0);while (rs0.next()) {String assetinfo = "<table border=\"1\"><tr><th>编号</th><th>名称</th><th>序列号</th><th>预计归还日期</th></tr>";List<String> list = new ArrayList<>();String cReceiver = "";userid = Util.null2String(rs0.getString("userid"));String sql1 = "select lastname,email,managerid from hrmresource where id='" + userid + "'";rs1.execute(sql1);if (rs1.next()) {receiver = Util.null2String(rs1.getString("email"));//使用人邮箱username = Util.null2String(rs1.getString("lastname"));list.add(Util.null2String(rs1.getString("managerid")));}String sql = "select resourceid,mark,name,sn,enddate,tmanager from cptcapital where capitalgroupid=26 and isdata=2 and enddate<=current_date() and resourceid="+userid+" order by enddate asc";rs.execute(sql);while (rs.next()) {assetnum = Util.null2String(rs.getString("mark"));assetname = Util.null2String(rs.getString("name"));returndate = Util.null2String(rs.getString("enddate"));String sn = Util.null2String(rs.getString("sn"));if(!Util.null2String(rs.getString("tmanager")).equals("")){list.add(Util.null2String(rs.getString("tmanager")));}assetinfo+="<tr><td>"+assetnum+"</td><td>"+assetname+"</td><td>"+sn+"</td><td>"+returndate+"</td></tr>";//借用的物品在邮件中用表格来展示}String liststr = String.join(",", list.stream().distinct().collect(Collectors.toList()));//将集合转换为分割的字符串,比如A,B,C,D,E格式,并且去重String sql4 = "select email from hrmresource where id in (" + liststr + ")";String comma = "";rs4.execute(sql4);while (rs4.next()) {cReceiver+=comma+Util.null2String(rs4.getString("email"));comma = ",";}cReceiver+=ccReceiver;assetinfo+="</table>";content = "Dear"+username+",<br><br>  下列您申请的设备已逾期,请尽快归还:<br><br>"+assetinfo+"<br><br>  如果需要延期使用,请您在收到邮件的3个工作日内,在OA发起延期申请,同时写明延期原因。<br><br>  如有任何疑问,请联系总部管理员。";EmailUtil.sendEmail(title, content, receiver, cReceiver);}}public String getccReceiver() {return ccReceiver;}}
附发送邮件代码EmailUtil.java
package weaver.interfaces.schedule;import weaver.general.Util;import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.*;public class EmailUtil {static Properties props;static final String ACCOUNT = "*****";//邮箱账号static final String PWD = "*****";//邮箱密码static {props = new Properties();props.setProperty("mail.transport.protocol", "smtp");// 使用协议:smtpprops.setProperty("mail.smtp.host", "smtp.office365.com");// 协议地址props.setProperty("mail.smtp.port", "25");// 协议端口props.setProperty("mail.smtp.starttls.enable", "true");// 打开加密props.setProperty("mail.smtp.auth", "false");// 关闭授权校验}public static void sendEmail(String title, String content, String receive) {Email email = new Email(title, content, receive);sendEmail(email);}public static void sendEmail(String title, String content, String receive, String cReceive) {Email email = new Email(title, content, receive, cReceive);sendEmail(email);}public static void sendEmail(String title, String content, String receive, String cReceive, String bReceive) {Email email = new Email(title, content, receive, cReceive, bReceive);sendEmail(email);}public static void sendEmail(Email email) {List<Email> emails = new ArrayList<>();emails.add(email);sendEmails(emails);}public static void sendEmails(List<Email> emails) {Transport transport = null;try {Session session = Session.getInstance(props);// 产生session对象session.setDebug(false);// 打开可查看日志transport = session.getTransport();// 创建连接对象transport.connect(ACCOUNT, PWD);// 建立连接(用户名、授权码)for (Email email : emails) {MimeMessage message = createMessage(session, email.getTitle(), email.getContent(),ACCOUNT, email.getReceive(), email.getcReceive(), email.getbReceive());transport.sendMessage(message, message.getAllRecipients());}} catch (Exception e) {e.printStackTrace();} finally {try {if (null != transport)transport.close();// 发送完毕关闭连接对象} catch (MessagingException me) {me.printStackTrace();} catch (Exception e) {e.printStackTrace();}}}/*** 创建邮件方法** @param session javax.mail.session对象* @param sender 发件人地址* @param receive 收件人地址* @param cReceive 抄送人* @param bReceive 密送人* @return*/public static MimeMessage createMessage(Session session, String title, String content,String sender, String receive, String cReceive, String bReceive) {MimeMessage message = new MimeMessage(session);try {// 标题、正文、发件人、收件人message.setSubject(title, "UTF-8");// 标题、标题编码Address addr = new InternetAddress(sender);// 构建发件人对象message.setFrom(addr);// 设置发件人message.setContent(content, "text/html;charset=utf-8");// 设置正文内容/*** 设置收件人* 收件人:MimeMessage.RecipientType.TO* 抄送:MimeMessage.RecipientType.CC* 密送:MimeMessage.RecipientType.BCC*/message.setRecipients(MimeMessage.RecipientType.TO,InternetAddress.parse(receive, true));// 收件人if (null != cReceive)message.setRecipients(MimeMessage.RecipientType.CC,InternetAddress.parse(cReceive, true));// 抄送人if (null != bReceive)message.setRecipients(MimeMessage.RecipientType.BCC,InternetAddress.parse(bReceive, true));// 密送人message.setSentDate(new Date());// 设置发件时间message.saveChanges();// 保存邮件} catch (Exception e) {e.printStackTrace();}return message;}static class Email {private String title;private String content;private String receive;private String cReceive;private String bReceive;public Email() {}public Email(String title, String content, String receive, String cReceive, String bReceive) {this.title = title;this.content = content;this.receive = receive;this.cReceive = cReceive;this.bReceive = bReceive;}public Email(String title, String content, String receive, String cReceive) {this.title = title;this.content = content;this.receive = receive;this.cReceive = cReceive;}public Email(String title, String content, String receive) {this.title = title;this.content = content;this.receive = receive;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}public String getReceive() {return receive;}public void setReceive(String receive) {this.receive = receive;}public String getcReceive() {return cReceive;}public void setcReceive(String cReceive) {this.cReceive = cReceive;}public String getbReceive() {return bReceive;}public void setbReceive(String bReceive) {this.bReceive = bReceive;}}
}
2、将代码放在/weaver/ecology/classbean/weaver/interfaces/schedule路径下
3、打开E9后端应用中心,进入【集成中心】-【功能集成】-【计划任务】-新建-保存
计划任务标识:自己命名,不可重复
计划任务类 :weaver.interfaces.schedule.DeviceNotification,代码存放的路径
定时时间:Cron表达式,按需求设置,这里设置的是每个月最后一天触发
参数:ccReceiver,抄送人
泛微E9二次开发,用计划任务定时发送邮件提醒相关推荐
- 泛微E9二次开发,对接金蝶云星空,数据同步,表单同步。
文章目录 泛微E9二次开发,对接金蝶云星空 一.搭建开发环境,引入相关依赖 一.创建项目 二.配置javaSDK 三.配置项目依赖 四.编写测试代码 五.配置编译 六.resin远程debug配置 二 ...
- 超全 泛微 E9 Ecology 9开发资料大全 开源资源下载 泛微E9二次开发 泛微开发实战经验 泛微开发实战例子 泛微二次开发项目例子 泛微二次开发Demo 泛微二次开发完整例子 泛微二次开发入门
由于工作需要,E9在泛微一推出来,以前所在的企业就第一时间上线了,经过四年多的运行,功能强大再加上在上面开发非常多的业务,一般的企业员工只需要打开泛微就可以处理完平时信息化的业务.后来 ...
- 泛微E9二次开发资料完整总结版
文章目录 1.EC9系统说明 1.1.系统核心框架 1.2.系统目录结构 2.环境搭建 2.1.Ecology测试环境搭建 2.2.后端开发环境搭建 2.3.ecode使用说明 2.4.e9技术站 2 ...
- 泛微OA二次开发环境搭建
泛微OA二次开发环境搭建 **前言:**本次分享主要分两个方面,1.基于泛微e8测试安装包的二次开发环境:2.基于公司内容OA搭建备份后的二次开发环境,20190819这天是我搭建成功的第一天,经验欠 ...
- 泛微OA二次开发后处理接口编写
泛微OA二次开发后处理接口编写 一.所需的依赖文件 二.demo代码解析 三.小技巧 四.注意事项 一.所需的依赖文件 weaver.soa.workflow.request.RequestInfo ...
- 泛微OA二次开发E8之UE富文本编辑器增加按钮操作
泛微OA协同办公系统在这里就不多作描述,有需要的可自行了解. 现在说说我遇到的问题以及解决方案. 遇到的需求问题 公司有自己的文件存储服务器,所以想把图片上传和文件上传都传输到自己的服务器上,所以需要 ...
- 泛微OA二次开发基础培训文档
一 ECOLOGY系统框架结构 Ecology系统说明 e-cology8.0文件页面编码为UTF-8 e-cology8.0 JDK版本 1.6 e-cology8.0 应用服务器为Resin E ...
- 泛微E9 OA 二次开发创建流程
泛微E9OA二次开发通过Java代码发起流程,可以通过以下方式进行实现. public String createWorkFlow(String userId) {/****************流 ...
- 关于泛微E9 OA系统手机端无法使用的抢救过程
关于泛微E9 OA系统手机端无法使用的抢救过程 1.重启emp目录中,sh rsstart.sh,启动过程显示mysql服务启动异常. 2.关闭服务,重启再试一下.sh stop.sh 还是显示mys ...
最新文章
- C++中MessageBox的常见用法
- 超好用的移动端布局自适应大小rem判断js文件及超过一定高度回到顶部按钮代码...
- IOS 中runtime 不可变数组__NSArray0 和__NSArrayI
- debian 9 安装后的配置,debian 9 开发环境。
- 前端:根据类型获取正则表达式字符串​
- 将Visual Studio Code设置为jshell中的默认编辑器
- python泰坦尼克号数据预测_机器学习入门之Python机器学习:泰坦尼克号获救预测一...
- Python学习笔记之用户输入
- 网安入门须知:Python基础导读
- win7系统两台电脑之间利用Socket实现文件传输---C++实现
- BLOB:大数据,大对象,在数据库中用来存储超长文本的数据,例如图片等
- UI设计之不同抠图工具的使用技巧
- 从零開始搭建微信硬件开发环境全过程——1小时掌握微信硬件开发流程
- 如何设计管理员和用户登录界面C语言,管理员登录设计(第7节)
- 捣鼓openwrt不死bootloader (1)
- 灯具如何利用网络打造品牌品牌实现销售增长?
- ebcdic java_在Java中将EBCDIC转换为ASCII
- Faster-rcnn中Anchor的理解
- 碉堡了: 兜宝让iPhone双卡双待成为现实
- 【UML基础教程】- 协作图(通信图)collaboration diagram