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){ String zhjkbs = "com.customization.dito.sendtodo.SendPortalToReadUtil.sendToReadDataByCreateNode" ; HttpRequestUtil httpRequestUtil = new HttpRequestUtil(); 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 currentUserId = user.getUID()+"" ; 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(); String createrLastname = ""; String createrLoginid = "" ; String requestname = ""; String workflowname = "" ; 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 = replace+bpm_app_requesturl+requestid; if(StringUtils.isNotEmpty(mobileJumpUrl)){ urlDing += "&returnUrl="+URLEncoder.encode(mobileJumpUrl,"UTF-8"); urlApp += "&returnUrl="+URLEncoder.encode(mobileJumpUrl,"UTF-8"); } 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")) ; createrLastname = Util.null2String(rs.getString("lastname")) ; createrLoginid = 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",createrLoginid); 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.doRecordPortalErrorInfo4Phase2(requestid,nodeid,nodename,currentUserId,requestObject.toJSONString(),resultCode,"",zhjkbs,userid); }else{ String resultmsg = msgObject.getString("resultMsg"); sendPortalErrorUtil.doRecordPortalErrorInfo4Phase2(requestid,nodeid,nodename,currentUserId,requestObject.toJSONString(),resultCode,resultmsg,zhjkbs,userid); } } } } } catch (Exception e) { e.printStackTrace(); } } /*** * 流程提交到写个节点, * 如果流程提交节点还有待办,意味着流程还是提交节点,只是提交节点一个人删除待办 * 如果流程提交节点没有待办,意味着流程流转到下个节点,那么查询出来的待办都有新增,并且删除提交节点的所有待办 * @param requestid * @param noideid * @param user */ public void sendToReadDataByNode(String requestid,User user,String noideid,String portal_todourl,String bpm_app_workflowurl,String username,String passwd,String bpm_workflowurl,String center,String bpm_app_requesturl){ String zhjkbs = "com.customization.dito.sendtodo.SendPortalToReadUtil.sendToReadDataByNode" ; 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 currentUserId = user.getUID()+"" ; 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 { 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 = 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); 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 workflowname = "" ; String requestname = ""; String createrLastname = ""; String createrLoginid = ""; JSONArray taskObjectList = new JSONArray(); 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")); createrLastname = Util.null2String(rs.getString("lastname")) ; createrLoginid = 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",createrLoginid); 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_"+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); 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,createrLastname,processTime); // String notificationSubject = templateMap.get("notificationSubject"); // String notificationContent = templateMap.get("notificationContent"); // //sendMailUtil.sendMail(requestid, emailArray, notificationSubject, notificationContent); // } sendPortalErrorUtil.doRecordPortalErrorInfo4Phase2(requestid,nodeid,nodename,currentUserId,requestObject.toJSONString(),resultCode,"",zhjkbs,userid); }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.doRecordPortalErrorInfo4Phase2(requestid,nodeid,nodename,currentUserId,requestObject.toJSONString(),resultCode,resultmsg,zhjkbs,userid); } } } } } } 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; } }