You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
353 lines
18 KiB
Java
353 lines
18 KiB
Java
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 nextNodeUserIds = "" ;
|
|
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")) ;
|
|
nextNodeUserIds += StringUtils.isEmpty(nextNodeUserIds) ? userid : ","+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<String,String> 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,currentUserId,requestObject.toJSONString(),resultCode,"",zhjkbs,nextNodeUserIds);
|
|
|
|
}else{
|
|
String resultmsg = msgObject.getString("resultMsg");
|
|
sendPortalErrorUtil.doRecordPortalErrorInfo4Phase2(requestid,currentNodeId,currentNodeName,currentUserId,requestObject.toJSONString(),resultCode,resultmsg,zhjkbs,nextNodeUserIds);
|
|
}
|
|
}
|
|
}
|
|
|
|
} 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<String,String> getEmailTemplate(String requestname, String operator, String operatorTime){
|
|
Map<String,String> dataMap = new HashMap<String,String>();
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
}
|