From 74fcf28f997f6bc5fc58182e6fb9875949aac3a7 Mon Sep 17 00:00:00 2001 From: shilei <798989044@qq.com> Date: Tue, 24 Oct 2023 10:46:27 +0800 Subject: [PATCH] =?UTF-8?q?#EC=5FHJ113#=20=E6=B5=81=E7=A8=8B=E4=BB=A3?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E8=A2=AB=E4=BB=A3=E7=90=86=E4=BA=BA=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=B5=81=E7=A8=8B=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent/SendPortalToReadByAgentUtil.java | 414 ++++++++++++++++++ .../agent/SendPortalTodoByAgentUtil.java | 347 +++++++++++++++ 2 files changed, 761 insertions(+) create mode 100644 src/com/customization/dito/sendtodo/agent/SendPortalToReadByAgentUtil.java create mode 100644 src/com/customization/dito/sendtodo/agent/SendPortalTodoByAgentUtil.java diff --git a/src/com/customization/dito/sendtodo/agent/SendPortalToReadByAgentUtil.java b/src/com/customization/dito/sendtodo/agent/SendPortalToReadByAgentUtil.java new file mode 100644 index 00000000..05698452 --- /dev/null +++ b/src/com/customization/dito/sendtodo/agent/SendPortalToReadByAgentUtil.java @@ -0,0 +1,414 @@ +package com.customization.dito.sendtodo.agent; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.customization.dito.sendtodo.HttpRequestUtil; +import com.customization.dito.sendtodo.SendMailUtil; +import com.customization.dito.sendtodo.SendPortalErrorUtil; +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 SendPortalToReadByAgentUtil { + + public static String EMAIL_REGEX_DEFAULT = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; + + + 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.util.SendPortalTodoByAgentUtil.sendTodoDataByNode"; + 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 terminal = "1" ; + String actionType = "0" ; + String taskType = "1"; + String objectAction = "0" ; + String objectType = "0"; + + try { + String processTime = DateUtil.getCurrentTime("yyyy-MM-dd HH:mm:ss"); + JSONArray taskObjectList = new JSONArray(); + + 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 requestname = ""; + String workflowname = "" ; + String currentNodeId = "" ; + String currentLastName = ""; + String currentLoginId = ""; + 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")) ; + currentLastName = Util.null2String(rs.getString("lastname")) ; + currentLoginId = Util.null2String(rs.getString("loginid")) ; + currentNodeId = Util.null2String(rs.getString("nodeid")) ; + } + 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",currentLoginId); + + 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 " + + " 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 + " and t2.nodeid = "+currentNodeId ; + + 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 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 = 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 createrLoginId = ""; + String currentNodeId = "" ; + String currentNodeName = "" ; + + 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")); + createrLoginId = Util.null2String(rs.getString("loginid")) ; + currentNodeId = Util.null2String(rs.getString("nodeid")) ; + currentNodeName = Util.null2String(rs.getString("nodename")) ; + } + + 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 +" and t2.nodeid="+currentNodeId ; + + bb.writeLog("SendPortalToReadUtil-sendToReadDataByNode--sql:" + sql); + rs.executeQuery(sql); + while (rs.next()) { + String lcid = Util.null2String(rs.getString("requestid")) ; + 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("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 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",currentNodeName); + requestObject.put("nodeId",currentNodeId); + 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)) { + + sendPortalErrorUtil.doRecordPortalErrorInfo4Phase2(requestid,currentNodeId,currentNodeName,f_weaver_belongto_userid,requestObject.toJSONString(),resultCode,"",zhjkbs); + + }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,currentNodeId,currentNodeName,f_weaver_belongto_userid,requestObject.toJSONString(),resultCode,resultmsg,zhjkbs); + + } + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /*** + * + * @param messageTitle + * @return + */ + 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; + } + +} diff --git a/src/com/customization/dito/sendtodo/agent/SendPortalTodoByAgentUtil.java b/src/com/customization/dito/sendtodo/agent/SendPortalTodoByAgentUtil.java new file mode 100644 index 00000000..8984142e --- /dev/null +++ b/src/com/customization/dito/sendtodo/agent/SendPortalTodoByAgentUtil.java @@ -0,0 +1,347 @@ +package com.customization.dito.sendtodo.agent; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.customization.dito.sendtodo.HttpRequestUtil; +import com.customization.dito.sendtodo.SendMailUtil; +import com.customization.dito.sendtodo.SendPortalErrorUtil; +import com.time.util.DateUtil; +import org.apache.commons.lang3.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 SendPortalTodoByAgentUtil { + + public static String EMAIL_REGEX_DEFAULT = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"; + + /*** + * 流程提交到写个节点, + * 如果流程提交节点还有待办,意味着流程还是提交节点,只是提交节点一个人删除待办 + * 如果流程提交节点没有待办,意味着流程流转到下个节点,那么查询出来的待办都有新增,并且删除提交节点的所有待办 + * @param requestid + * @param noideid + * @param user + */ + public void sendTodoDataByNode(String requestid,String noideid,String f_weaver_belongto_userid,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(); + + String zhjkbs = "com.customization.dito.sendtodo.util.SendPortalTodoByAgentUtil.sendTodoDataByNode"; + + SendMailUtil sendMailUtil = new SendMailUtil(); + SendPortalErrorUtil sendPortalErrorUtil = new SendPortalErrorUtil(); + String mobileJumpUrl = PropBean.getUfPropValue("mobileJumpUrl"); + JSONObject requestObject = new JSONObject(); + RecordSet rs = new RecordSet(); + + BaseBean bb = new BaseBean(); + bb.writeLog("sendTodoDataByNode"); + String cus_staff = PropBean.getUfPropValue("cus_staff") ; + String scopeid = "-1"; + String scope = "HrmCustomFieldByInfoType" ; + String msgdata = ""; + + String terminal = "1" ; + String taskType = "0"; + + String emailArray = ""; + Pattern regex = Pattern.compile(EMAIL_REGEX_DEFAULT); + try { + String createrLastName = ""; + String currentNodeId = "" ; + String currentNodeName = "" ; + String createrLoginId = "" ; + String workflowname = "" ; + String currentUserId = user.getUID()+"" ; + + String processTime = DateUtil.getCurrentTime("yyyy-MM-dd HH:mm:ss"); + + 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("sendTodoDataByNode--countSql:"+countSql); + rs.executeQuery(countSql); + while (rs.next()){ + count++; + } + bb.writeLog("sendTodoDataByNode--count:"+count); + String requestname = "" ; + + if(count >0){ + JSONArray taskObjectList = new JSONArray(); + String actionType = "1" ; + String objectAction = "1" ; + String objectType = "0"; + + String agentorStaffid = "" ; + String agentorbyagentid = "" ; + String agentorUserCode = "" ; + String sql = " select t2.agentorbyagentid,h2.loginid,c1."+cus_staff+" as staffid " + + " from workflow_currentoperator t2\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 from hrmresource where status = 1 union all select id,lastname,loginid from hrmresourcemanager ) h2 on h2.id = t2.agentorbyagentid " + + " where requestid = " +requestid+ + " and userid = " +f_weaver_belongto_userid+ + " and agenttype = 1\n" + + " and isremark = 2 " + + " and preisremark = 2" ; + + rs.executeQuery(sql); + if(rs.next()){ + agentorbyagentid = Util.null2String(rs.getString("agentorbyagentid")); + agentorStaffid = Util.null2String(rs.getString("staffid")); + agentorUserCode = Util.null2String(rs.getString("loginid")); + } + + if(StringUtils.isNotBlank(agentorbyagentid)) + { + 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("sendTodoDataByNode--sql:"+sql); + + rs.executeQuery(sql); + if (rs.next()){ + requestname = Util.null2String(rs.getString("requestname")) ; + workflowname = Util.null2String(rs.getString("workflowname")) ; + currentNodeId = Util.null2String(rs.getString("nodeid")+user.getUID()) ; + currentNodeName = Util.null2String(rs.getString("nodeName")) ; + createrLastName = Util.null2String(rs.getString("lastname")) ; + createrLoginId = Util.null2String(rs.getString("loginid")) ; + } + + 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); + requestObject.put("center",center); + requestObject.put("title",requestname); + requestObject.put("creator",createrLoginId); + requestObject.put("taskCode","weaver"+requestid); + requestObject.put("nodeId",currentNodeId); + 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("urlApp",urlApp); + requestObject.put("urlDing",urlDing); + requestObject.put("nodeName",currentNodeName); + requestObject.put("ticketType",workflowname); + + if("sysadmin".equals(agentorUserCode)){ + agentorUserCode = "Admin"; + } + + String objectCode = agentorUserCode ; + String operatorCode = agentorUserCode ; + + JSONObject taskObject = new JSONObject(); + taskObject.put("objectAction",objectAction); + taskObject.put("objectType",objectType); + taskObject.put("objectCode",objectCode); + taskObject.put("operatorCode",operatorCode); + taskObject.put("objectId",agentorStaffid); + taskObjectList.add(taskObject); + requestObject.put("taskObjectList",taskObjectList); + + if (taskObjectList.size() > 0){ + String auth = username + ":" + passwd; + msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth); + } + } + }else{ + String actionType = "2" ; + String objectAction = "0" ; + String objectType = "0"; + + 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("sendTodoDataByNode--sql2:"+sql); + + rs.executeQuery(sql); + if (rs.next()){ + requestname = Util.null2String(rs.getString("requestname")) ; + workflowname = Util.null2String(rs.getString("workflowname")) ; + currentNodeId = Util.null2String(rs.getString("nodeid")) ; + currentNodeName = Util.null2String(rs.getString("nodeName")) ; + createrLastName = Util.null2String(rs.getString("lastname")) ; + createrLoginId = Util.null2String(rs.getString("loginid")) ; + } + + 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); + + requestObject.put("center",center); + requestObject.put("title",requestname); + requestObject.put("creator",createrLoginId); + requestObject.put("taskCode","weaver"+requestid); + requestObject.put("nodeId",currentNodeId); + 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("urlApp",urlApp); + requestObject.put("urlDing",urlDing); + requestObject.put("nodeName",currentNodeName); + requestObject.put("ticketType",workflowname); + + sql = " select t2.userid,h1.loginid,h1.email,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" + + " 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 nodeid = "+currentNodeId; + + bb.writeLog("sendTodoDataByNode--sql:"+sql); + rs.executeQuery(sql); + while (rs.next()){ + + String usercode = Util.null2String(rs.getString("loginid")) ; + String staffid = Util.null2String(rs.getString("staffid")) ; + String userid = Util.null2String(rs.getString("userid")) ; + + if("sysadmin".equals(usercode)){ + usercode = "Admin"; + } + + String objectCode = usercode ; + String operatorCode = usercode ; + + JSONObject taskObject = new JSONObject(); + taskObject.put("objectAction",objectAction); + taskObject.put("objectType",objectType); + taskObject.put("objectCode",objectCode); + taskObject.put("objectId",staffid); + taskObject.put("operatorCode",operatorCode); + taskObjectList.add(taskObject); + + String email = Util.null2String(rs.getString("email")) ; + bb.writeLog("email3:"+email); + Matcher matcher = regex.matcher(email); + if(matcher.matches()){ + emailArray += StringUtils.isEmpty(emailArray) ? email : ","+email ; + } + } + if (taskObjectList.size() >0){ + requestObject.put("taskObjectList",taskObjectList); + }else { + requestObject.put("actionType","3"); + } + String auth = username + ":" + passwd; + msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth); + } + + bb.writeLog("msgdata:"+msgdata); + if(!"".equals(msgdata)){ + JSONObject msgObject = JSONObject.parseObject(msgdata); + if(msgObject.containsKey("resultCode")){ + String resultCode = msgObject.getString("resultCode"); + if("0".equals(resultCode)){ + + 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,currentNodeId,currentNodeName,f_weaver_belongto_userid,requestObject.toJSONString(),resultCode,"",zhjkbs); + + }else{ + String resultmsg = msgObject.getString("resultMsg"); + sendPortalErrorUtil.doRecordPortalErrorInfo4Phase2(requestid,currentNodeId,currentNodeName,f_weaver_belongto_userid,requestObject.toJSONString(),resultCode,resultmsg,zhjkbs); + } + } + } + + } 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-Do task - <"+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; + } + + + +}