package com.customization.dito.sendtodo; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.time.util.DateUtil; import org.apache.commons.lang.StringUtils; import weaver.conn.RecordSet; import weaver.general.BaseBean; import weaver.general.Util; import weaver.hrm.User; import weaver.interfaces.dito.comInfo.PropBean; import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SendPortalToReadUtil { //public static String EMAIL_REGEX_DEFAULT = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; public static String EMAIL_REGEX_DEFAULT = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; /*** * 流程发起节点,提交到下个节点,发起节点没有待办,下个节点有待办 * @param requestid * @param user */ public void sendToReadDataByCreateNode(String requestid,User user,String portal_todourl,String bpm_app_workflowurl,String username,String passwd,String bpm_workflowurl,String center,String bpm_app_requesturl){ HttpRequestUtil httpRequestUtil = new HttpRequestUtil(); SendMailUtil sendMailUtil = new SendMailUtil(); SendPortalErrorUtil sendPortalErrorUtil = new SendPortalErrorUtil(); RecordSet rs = new RecordSet(); BaseBean bb = new BaseBean(); bb.writeLog("SendPortalToReadUtil-sendToReadDataByCreateNode"); String mobileJumpUrl = PropBean.getUfPropValue("mobileJumpUrl"); String cus_staff = PropBean.getUfPropValue("cus_staff") ; String scopeid = "-1"; String scope = "HrmCustomFieldByInfoType" ; JSONObject requestObject = new JSONObject(); Pattern regex = Pattern.compile(EMAIL_REGEX_DEFAULT); String terminal = "1" ; String actionType = "0" ; String taskType = "1"; String objectAction = "0" ; String objectType = "0"; String emailArray = ""; try { String processTime = DateUtil.getCurrentTime("yyyy-MM-dd HH:mm:ss"); JSONArray taskObjectList = new JSONArray(); // int u_userid = user.getUID(); String lastname = ""; String loginid = "" ; // String workcode = ""; // String sql = " select * from (select id, lastname,loginid from hrmresource where status = 1 union all select id, lastname,loginid from hrmresourcemanager ) w where w.id = '" + u_userid + "'"; // rs.executeQuery(sql); // while (rs.next()) { // workcode = Util.null2String(rs.getString("loginid")); // } String urlPc = "[newtab]"+bpm_workflowurl+"/workflow/request/ViewRequestForwardSPA.jsp?requestid="+requestid ; // String app_requestUrl = bpm_app_requesturl+requestid; // app_requestUrl = URLEncoder.encode(app_requestUrl,"UTF-8"); String replace = bpm_app_workflowurl.replace("/bpm", ""); // String urlDing = replace+bpm_app_requesturl+requestid; // bb.writeLog("urlDing", urlDing); // String urlApp = replace+bpm_app_requesturl+requestid; String urlDing = replace+bpm_app_requesturl+requestid; String urlApp = replace+bpm_app_requesturl+requestid; if(StringUtils.isNotEmpty(mobileJumpUrl)){ urlDing += "&returnUrl="+URLEncoder.encode(mobileJumpUrl,"UTF-8"); urlApp += "&returnUrl="+URLEncoder.encode(mobileJumpUrl,"UTF-8"); } String requestname = ""; String workflowname = "" ; // sql =" select t1.requestname,t1.requestmark,t3.workflowname\n" + // " from workflow_requestbase t1\n" + // " inner join workflow_base t3 on t1.workflowid = t3.id\n" + // " left join workflow_nodebase d1 on d1.id = t1.currentnodeid "+ // " where (t1.deleted <> 1 or t1.deleted is null or t1.deleted = '')\n" + // " and t1.requestid = "+requestid ; String sql =" select t1.requestname,t1.currentnodeid as nodeid,d1.nodename,t3.workflowname,h2.lastname,h2.loginid "+ " from workflow_requestbase t1\n" + " inner join workflow_base t3 on t1.workflowid = t3.id\n" + " left join workflow_nodebase d1 on d1.id = t1.currentnodeid "+ " left join (select id,lastname,loginid from hrmresource where status = 1 union all select id,lastname,loginid from hrmresourcemanager ) h2 on h2.id = t1.creater \n" + " where (t1.deleted <> 1 or t1.deleted is null or t1.deleted = '')\n" + " and t1.requestid = "+requestid ; bb.writeLog("sendToReadDataByNode--sql:"+sql); rs.executeQuery(sql); if (rs.next()){ workflowname = Util.null2String(rs.getString("workflowname")) ; requestname = Util.null2String(rs.getString("requestname")) ; lastname = Util.null2String(rs.getString("lastname")) ; loginid = Util.null2String(rs.getString("loginid")) ; } requestObject.put("center",center); requestObject.put("title",requestname); requestObject.put("taskType",taskType); requestObject.put("actionType",actionType); requestObject.put("createDate",processTime); requestObject.put("messageTitle",getShortMessageTitle(requestname)); requestObject.put("messageContent",requestname); requestObject.put("terminal",terminal); requestObject.put("urlPc",urlPc); requestObject.put("urlDing",urlDing); requestObject.put("ticketType",workflowname); requestObject.put("urlApp",urlApp); requestObject.put("creator",loginid); sql = " select t2.userid,h1.loginid,h1.email,t2.isremark,t1.requestid,t2.nodeid,d1.nodename,c1."+cus_staff+" as staffid "+ " from workflow_requestbase t1\n" + " inner join workflow_currentoperator t2 on t1.requestid = t2.requestid\n" + " left join cus_fielddata c1 on c1.id = t2.userid and c1.scopeid= "+scopeid+" and c1.scope = '"+scope+"' "+ " left join (select id, lastname,loginid,email from hrmresource where STATUS = 1 union all select id,lastname,loginid,'' as email from hrmresourcemanager ) h1 on h1.id = t2.userid\n" + " left join workflow_nodebase d1 on d1.id = t2.nodeid "+ " where (t1.deleted <> 1 or t1.deleted is null or t1.deleted = '')\n" + " and t2.isremark in ('8','9')\n" + " and t2.islasttimes = 1\n" + " and (t2.isprocessing = '' or t2.isprocessing is null)\n" + " and t2.requestid = "+requestid ; bb.writeLog("sendToReadDataByNode--sql:"+sql); rs.executeQuery(sql); while (rs.next()){ String lcid = Util.null2String(rs.getString("requestid")) ; String nodeid = Util.null2String(rs.getString("nodeid")) ; String nodename = Util.null2String(rs.getString("nodename")) ; String email = Util.null2String(rs.getString("email")) ; String staffid = Util.null2String(rs.getString("staffid")) ; String creator = Util.null2String(rs.getString("loginid")) ; String userid = Util.null2String(rs.getString("userid")) ; JSONObject taskObject = new JSONObject(); taskObject.put("lcid",lcid); taskObject.put("nodeid",nodeid); taskObject.put("nodename",nodename); taskObject.put("email",email); taskObject.put("creator",creator); taskObject.put("staffid",staffid); taskObject.put("userid",userid); taskObjectList.add(taskObject); } for(int i=0;i templateMap = getEmailTemplate(requestname,lastname,processTime); String notificationSubject = templateMap.get("notificationSubject"); String notificationContent = templateMap.get("notificationContent"); //sendMailUtil.sendMail(requestid,emailArray,notificationSubject,notificationContent); } sendPortalErrorUtil.doRecordPortalErrorInfo(requestid,nodeid,nodename,userid,requestObject.toJSONString(),resultCode,""); }else{ String resultmsg = msgObject.getString("resultMsg"); sendPortalErrorUtil.doRecordPortalErrorInfo(requestid,nodeid,nodename,userid,requestObject.toJSONString(),resultCode,resultmsg); } } } } } catch (Exception e) { e.printStackTrace(); } } /*** * 流程提交到写个节点, * 如果流程提交节点还有待办,意味着流程还是提交节点,只是提交节点一个人删除待办 * 如果流程提交节点没有待办,意味着流程流转到下个节点,那么查询出来的待办都有新增,并且删除提交节点的所有待办 * @param requestid * @param noideid * @param user */ public void sendToReadDataByNode(String requestid,String noideid,User user,String portal_todourl,String bpm_app_workflowurl,String username,String passwd,String bpm_workflowurl,String center,String bpm_app_requesturl){ HttpRequestUtil httpRequestUtil = new HttpRequestUtil(); SendMailUtil sendMailUtil = new SendMailUtil(); SendPortalErrorUtil sendPortalErrorUtil = new SendPortalErrorUtil(); Pattern regex = Pattern.compile(EMAIL_REGEX_DEFAULT); String mobileJumpUrl = PropBean.getUfPropValue("mobileJumpUrl"); RecordSet rs = new RecordSet(); BaseBean bb = new BaseBean(); bb.writeLog("SendPortalToReadUtil-sendToReadDataByNode"); String cus_staff = PropBean.getUfPropValue("cus_staff") ; String scopeid = "-1"; String scope = "HrmCustomFieldByInfoType" ; JSONObject requestObject = new JSONObject(); String emailArray = ""; String actionType = "2"; String objectAction = "0"; String objectType = "0"; String terminal = "1" ; String taskType = "1"; try { // int u_userid = user.getUID(); String lastname = ""; // // String workcode = ""; // String sql = " select * from (select id, lastname,loginid from hrmresource where status = 1 union all select id, lastname,loginid from hrmresourcemanager ) w where w.id = '" + u_userid + "'"; // rs.executeQuery(sql); // while (rs.next()) { // workcode = Util.null2String(rs.getString("loginid")); // } int count = 0 ; String countSql =" select t2.userid \n" + " from workflow_requestbase t1\n" + " inner join workflow_currentoperator t2 on t1.requestid = t2.requestid\n" + " where (t1.deleted <> 1 or t1.deleted is null or t1.deleted = '')\n" + " and ((t2.isremark = '0' and (t2.takisremark is null or t2.takisremark = 0)) or t2.isremark in ('1', '5', '7', '11'))\n" + " and t2.islasttimes = 1\n" + " and (t2.isprocessing = '' or t2.isprocessing is null)\n" + " and t2.requestid = "+requestid+ " and t2.nodeid = " + noideid ; bb.writeLog("sendToReadDataByNode--countSql:"+countSql); rs.executeQuery(countSql); while (rs.next()){ count++; } bb.writeLog("SendPortalToReadUtil-sendToReadDataByNode--count:"+count); if(count == 0) { String processTime = DateUtil.getCurrentTime("yyyy-MM-dd HH:mm:ss"); String urlPc = "[newtab]"+bpm_workflowurl+"/workflow/request/ViewRequestForwardSPA.jsp?requestid="+requestid ; String replace = bpm_app_workflowurl.replace("/bpm", ""); // String urlDing = replace+bpm_app_requesturl+requestid; //// String urlApp = bpm_app_workflowurl+"/interface/mobilelogin/loginsso.jsp?em_auth_usercode="+creator+"&forwardurl="+app_requestUrl; // String urlApp = replace+bpm_app_requesturl+requestid; String urlDing = replace+bpm_app_requesturl+requestid; String urlApp = replace+bpm_app_requesturl+requestid; if(StringUtils.isNotEmpty(mobileJumpUrl)){ urlDing += "&returnUrl="+URLEncoder.encode(mobileJumpUrl,"UTF-8"); urlApp += "&returnUrl="+URLEncoder.encode(mobileJumpUrl,"UTF-8"); } bb.writeLog("urlDing", urlDing); String workflowname = "" ; String requestname = ""; String loginid = ""; JSONArray taskObjectList = new JSONArray(); // sql =" select t1.workflowid,t1.requestname,t1.requestmark,t3.workflowname\n" + // " from workflow_requestbase t1\n" + // " inner join workflow_base t3 on t1.workflowid = t3.id\n" + // " where (t1.deleted <> 1 or t1.deleted is null or t1.deleted = '')\n" + // " and t1.requestid = " + requestid; String sql =" select t1.requestname,t1.currentnodeid as nodeid,d1.nodename,t3.workflowname,h2.lastname,h2.loginid "+ " from workflow_requestbase t1\n" + " inner join workflow_base t3 on t1.workflowid = t3.id\n" + " left join workflow_nodebase d1 on d1.id = t1.currentnodeid "+ " left join (select id,lastname,loginid from hrmresource where status = 1 union all select id,lastname,loginid from hrmresourcemanager ) h2 on h2.id = t1.creater \n" + " where (t1.deleted <> 1 or t1.deleted is null or t1.deleted = '')\n" + " and t1.requestid = "+requestid ; bb.writeLog("SendPortalToReadUtil-sendToReadDataByNode--sql:" + sql); rs.executeQuery(sql); if (rs.next()) { workflowname = Util.null2String(rs.getString("workflowname")); requestname = Util.null2String(rs.getString("requestname")); lastname = Util.null2String(rs.getString("lastname")) ; loginid = Util.null2String(rs.getString("loginid")) ; } requestObject.put("center", center); requestObject.put("title", requestname); requestObject.put("taskType", taskType); requestObject.put("actionType", actionType); requestObject.put("createDate", processTime); requestObject.put("messageTitle",getShortMessageTitle(requestname)); requestObject.put("messageContent", requestname); requestObject.put("terminal", terminal); requestObject.put("urlPc", urlPc); requestObject.put("urlDing", urlDing); requestObject.put("ticketType", workflowname); requestObject.put("creator",loginid); requestObject.put("urlApp",urlApp); sql = " select t2.userid,h1.loginid,h1.email,t2.isremark,t1.requestid,t2.nodeid,d1.nodename,c1."+cus_staff+" as staffid "+ " from workflow_requestbase t1\n" + " inner join workflow_currentoperator t2 on t1.requestid = t2.requestid\n" + " left join cus_fielddata c1 on c1.id = t2.userid and c1.scopeid= "+scopeid+" and c1.scope = '"+scope+"' "+ " left join (select id, lastname,loginid,email from hrmresource where STATUS = 1 union all select id,lastname,loginid,'' as email from hrmresourcemanager ) h1 on h1.id = t2.userid\n" + " left join workflow_nodebase d1 on d1.id = t2.nodeid "+ " where (t1.deleted <> 1 or t1.deleted is null or t1.deleted = '')\n" + " and t2.isremark in ('8','9')\n" + " and t2.islasttimes = 1\n" + " and (t2.isprocessing = '' or t2.isprocessing is null)\n" + " and t2.requestid = "+requestid ; bb.writeLog("SendPortalToReadUtil-sendToReadDataByNode--sql:" + sql); rs.executeQuery(sql); while (rs.next()) { String lcid = Util.null2String(rs.getString("requestid")) ; String nodeid = Util.null2String(rs.getString("nodeid")) ; String nodename = Util.null2String(rs.getString("nodename")) ; String email = Util.null2String(rs.getString("email")) ; String staffid = Util.null2String(rs.getString("staffid")) ; String creator = Util.null2String(rs.getString("loginid")) ; String userid = Util.null2String(rs.getString("userid")) ; JSONObject taskObject = new JSONObject(); taskObject.put("lcid",lcid); taskObject.put("nodeid",nodeid); taskObject.put("nodename",nodename); taskObject.put("email",email); taskObject.put("creator",creator); taskObject.put("staffid",staffid); taskObject.put("userid",userid); taskObjectList.add(taskObject); } for (int i = 0; i < taskObjectList.size(); i++) { JSONObject dataObject = taskObjectList.getJSONObject(i); String lcid = dataObject.getString("lcid"); String nodeid = dataObject.getString("nodeid"); String nodename = dataObject.getString("nodename"); String email = dataObject.getString("email"); String creator = dataObject.getString("creator"); String userid = dataObject.getString("userid"); if("sysadmin".equals(creator)){ creator = "Admin"; } JSONObject taskObject = new JSONObject(); String objectCode = creator ; String operatorCode = creator ; String staffid = dataObject.getString("staffid"); taskObject.put("objectAction",objectAction); taskObject.put("objectType",objectType); taskObject.put("objectCode",objectCode); taskObject.put("objectId",staffid); taskObject.put("operatorCode",operatorCode); JSONArray taskArray = new JSONArray(); taskArray.add(taskObject); requestObject.put("nodeName",nodename); requestObject.put("nodeId",nodeid); //requestObject.put("taskCode",lcid+"_cs_"+nodeid+"_"+userid); requestObject.put("taskCode", lcid+"_cs_"+userid); requestObject.put("taskObjectList",taskArray); String auth = username + ":" + passwd; bb.writeLog("SendPortalToReadUtil--requestObject:" + requestObject.toJSONString()); String msgdata = httpRequestUtil.doPostByAuth(portal_todourl, requestObject.toJSONString(), auth); bb.writeLog("SendPortalToReadUtil-msgdata:" + msgdata); if (!"".equals(msgdata)) { JSONObject msgObject = JSONObject.parseObject(msgdata); //{"resultCode":"1","resultMsg":"No Result"} if (msgObject.containsKey("resultCode")) { String resultCode = msgObject.getString("resultCode"); if ("0".equals(resultCode)) { Matcher matcher = regex.matcher(email); if (matcher.matches()) { emailArray += StringUtils.isEmpty(emailArray) ? email : "," + email; } bb.writeLog("emailArray:" + emailArray); if (StringUtils.isNotEmpty(emailArray)) { Map templateMap = getEmailTemplate(requestname,lastname,processTime); String notificationSubject = templateMap.get("notificationSubject"); String notificationContent = templateMap.get("notificationContent"); //sendMailUtil.sendMail(requestid, emailArray, notificationSubject, notificationContent); } sendPortalErrorUtil.doRecordPortalErrorInfo(requestid,nodeid,nodename,userid,requestObject.toJSONString(),resultCode,""); }else if ("TODO-FAIL-002".equals(resultCode)){ //The task does not exist.任务不存在,则新增 sendToReadDataByCreateNode(requestid,user,portal_todourl,bpm_app_workflowurl,username,passwd,bpm_workflowurl,center,bpm_app_requesturl); } else{ String resultmsg = msgObject.getString("resultMsg"); sendPortalErrorUtil.doRecordPortalErrorInfo(requestid,nodeid,nodename,userid,requestObject.toJSONString(),resultCode,resultmsg); } } } } } } catch (Exception e) { e.printStackTrace(); } } private String getShortMessageTitle(String messageTitle) { if (messageTitle.length() > 20) { messageTitle = messageTitle.substring(0, 17) + "..."; } return messageTitle; } /*** * * @param requestname * @param operator * @param operatorTime * @return */ public Map getEmailTemplate(String requestname,String operator,String operatorTime){ Map dataMap = new HashMap(); String notificationSubject = "You have a new To-Read - <"+requestname+"> "; String notificationContent = operator + " created this task on "+operatorTime+"\n" + " Please handle it in time."; dataMap.put("notificationSubject",notificationSubject); dataMap.put("notificationContent",notificationContent); return dataMap; } }