|
楼主 |
发表于 2013-11-27 11:24:02
|
显示全部楼层
发送html格式邮件,可以通过点击链接去处理审批
本帖最后由 song_ning_ning 于 2014-1-21 09:38 编辑
这个邮件的格式是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");
- 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'];
- 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);
- };
- }
- });
- }
复制代码 |
|