发的邮件是文本格式,只有标题 实现通知功能
本例子是在请假申请环节流转后向总经理发邮件 如图:
1. 用附件中的mail.jar替换runtime\BusinessServer\WEB-INF\lib里面的mail.jar
2. 将附件中的MailSenderInfo.java MyAuthenticator.java SimpleMailSender.java三个文件(发邮件用)复制到流程目录下的dsrc目录下
3. 在请假申请环节的onAfterAdvance事件中获取信息发邮件 代码如下:
import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.justep.system.opm.api.Person; import com.justep.system.process.*; import com.justep.system.opm.api.PersonHelper; public class EmailProcess { public static void businessActivity1AfterAdvance() { String email = null; String title = null; String personName = null; Date date = new Date(); List exts = new ArrayList(); exts.add("sMail"); String personID = null; for (ActivityInstance ai : ProcessUtils.getAI().getAllNextAIs()) { if (ai.getNextAIs().isEmpty()) { for (Task t : ai.getTask().getExecutorTasks()) { title = t.getName(); Person person=PersonHelper.loadPerson(t.getExecutorPersonID(), exts); personName=person.getName(); email=(String) person.getExtValue("sMail"); //这个类主要是设置邮件 MailSenderInfo mailInfo = new MailSenderInfo(); mailInfo.setMailServerHost("smtp.163.com");//发送者邮箱的host mailInfo.setMailServerPort("25"); mailInfo.setValidate(true); mailInfo.setUserName("*********@163.com");//发送者邮箱名 mailInfo.setPassword("*********");//发送者的邮箱密码 mailInfo.setFromAddress("********@163.com");// 发送者邮箱地址 mailInfo.setToAddress(email);//接收者的邮箱地址 mailInfo.setSubject(personName + " " + title + " " + (new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(date)); mailInfo.setContent(" ");//这里邮件内容为空 //这个类主要来发送邮件 SimpleMailSender sms = new SimpleMailSender(); sms.sendTextMail(mailInfo);//发送文体格式 } } } } }
发送html格式邮件,可以通过点击链接去处理审批
这个邮件的格式是html的,接收到的邮件里面有个超链接,通过点击链接登陆到平台去处理审批过程:
点击链接,链接指向login.j文件 在login.j文件实现登陆 然后重定向到publicActivity.w文件 在publicActivity.w中的windowFrame组件上显示代办任务的页面
1. 将请假申请环节的onAfterAdvance事件中的代码替换为:
import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; import com.justep.model.ModelUtils; import com.justep.system.process.*; import com.justep.system.context.*; import com.justep.system.opm.*; import com.justep.system.opm.api.PersonHelper; import com.justep.util.Utils; public class EmailProcess { public static void businessActivity1AfterAdvance() { String email = null; String title = null; String userName = null; String password = null; String url = null; String task = null; String eUrl = null; String process = null; String activity = null; String executor = null; String personName = ContextHelper.getPerson().getName(); Date date = new Date(); Collection extOrgRelations = new ArrayList(); extOrgRelations.add("sMail"); String personID = null; for (ActivityInstance ai : ProcessUtils.getAI().getAllNextAIs()) { if (ai.getNextAIs().isEmpty()) { for (Task t : ai.getTask().getExecutorTasks()) { title = t.getName(); task = t.getId(); eUrl = t.getEURL(); process = t.getProcess(); activity = t.getActivity(); executor = t.getExecutorFID(); personID=OrgUtils.getPersonIDByFID(t.getExecutorFID()); email = (String) PersonHelper.loadPerson(personID, extOrgRelations).getExtValue("sMail"); userName = PersonHelper.loadPerson(personID, extOrgRelations).getCode(); password = PersonHelper.loadPerson(personID, extOrgRelations).getPassword(); url = "http://192.168.1.58:8080/x5/UI/demo/actions/process/integration/login.j?username=" + userName + "&password=" + password + "&task=" + task + "&eUrl=" + eUrl + "&process=" + process + "&activity=" + activity + "&executor=" + executor + ""; //这个类主要是设置邮件 MailSenderInfo mailInfo = new MailSenderInfo(); mailInfo.setMailServerHost("smtp.126.com");//发送者邮箱的host mailInfo.setMailServerPort("25"); mailInfo.setValidate(true); mailInfo.setUserName("song_ning_ning@126.com"); mailInfo.setPassword("SONGNINGNING0327");//您的邮箱密码 mailInfo.setFromAddress("song_ning_ning@126.com"); mailInfo.setToAddress(email); mailInfo.setSubject(personName + " " + title + " " + (new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(date)); mailInfo.setContent("<a href=" + url + ">请点击此链接去处理</a>"); //这个类主要来发送邮件 SimpleMailSender sms = new SimpleMailSender(); sms.sendHtmlMail(mailInfo);//发送html格式 } } } } }
2. 在UI/demo/actions/process/integration下新建login.j文件 实现登陆功能 代码如下:
import java.io.IOException; import java.sql.Date; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONException; import org.json.JSONObject; import com.justep.biz.client.ActionEngine; import com.justep.biz.client.ActionResult; import com.justep.biz.client.ActionUtils; public class Login extends com.justep.ui.impl.JProcessorImpl { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject content = null; String bsessionid = request.getParameter("bsessionid"); String username = null; String password = null; String task=null; String eUrl=null; String process=null; String activity=null; String executor=null; ActionResult checkResult = ActionEngine.checkSession(bsessionid, ActionUtils.JSON_CONTENT_TYPE); if (checkResult.isSessionTimeOut()) { username = request.getParameter("username"); password = request.getParameter("password"); task=request.getParameter("task"); eUrl=request.getParameter("eUrl"); process=request.getParameter("process"); activity=request.getParameter("activity"); executor=request.getParameter("executor"); String ip = request.getRemoteAddr(); String language = "zh_CN"; Date loginDate = new Date(System.currentTimeMillis()); ActionResult actionResult = ActionEngine.login2(username, password, ip, language, loginDate, null, ActionUtils.JSON_CONTENT_TYPE, null);; content = (JSONObject)actionResult.getContent(); bsessionid = actionResult.getBSessionID(); } else { content = (JSONObject)checkResult.getContent(); } try { content.put("bsessionid", bsessionid); } catch (JSONException e) { e.printStackTrace(); } response.setCharacterEncoding("UTF-8");</li> String url="http://192.168.1.58:8080/x5/Test/email/process/email/publicActivity.w?eUrl="+eUrl+"&task="+task+"&activity-pattern=do&process="+process+"&activity="+activity+"&$log=1&bsessionid="+bsessionid+"&executor="+executor+"&language=zh_CN"; response.sendRedirect(url); } }
3. 在UI/Test/email/process/email(对于本例子的路径)下新建publicActivity.w文件 在.w文件增加组件windowFrame 并设置高和宽为100% 区别在外部打开的代办还是在平台内部打开的代办 方便注销用户
在model的onload事件中写如下代码:
publicActivity.model1Load = function(event){ var eUrl=justep.Request.URLParams['eUrl']; var task=justep.Request.URLParams['task']; var process=justep.Request.URLParams['process']; var activity=justep.Request.URLParams['activity']; var bsessionid=justep.Request.URLParams['bsessionid']; var executor=justep.Request.URLParams['executor']; var url="http://192.168.1.58:8080/x5"+eUrl+"?task="+task+"&activity-pattern=do&process="+process+"&activity="+activity+"&$log=1&bsessionid="+bsessionid+"&executor="+executor+"&language=zh_CN"; var windowFrame=justep.xbl('windowFrame1'); windowFrame.open("待办任务",url); };
4. 在punlicActivity.js 文件中加入以下代码:实现处理完结果后关闭页面注销当前用户
window.onbeforeunload = function(){ var bsessionid=justep.Request.URLParams['bsessionid'];</li> var flag=justep.Request.URLParams['flag']; $.ajax({ async: false, type: 'POST', dataType: 'json', url: 'http://192.168.1.58:8080/x5/UI/demo/actions/process/integration/x5Logout.j?bsessionid=' + bsessionid, data: {}, error: function(error, status, text) { alert('注销失败:' + text); }, success: function(result){ if (result.flag) { alert("X5注销成功!"); } else { alert('注销失败:' + result.message); }; } }); }
本文由WeX5君整理,WeX5一款开源免费的html5开发工具,H5 App开发就用WeX5!
阅读其他app 开发相关文章:http://doc.wex5.com/?p=3443
评一波