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.
341 lines
17 KiB
Java
341 lines
17 KiB
Java
package com.customization.dito.sendtodo;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.constant.Constants;
|
|
import com.engine.core.interceptor.CommandContext;
|
|
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.List;
|
|
import java.util.Map;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* 流程增加代办后给门户发送增加代办消息,进行同步
|
|
*/
|
|
public class SendPortalWithAddTodoCmd {
|
|
private Map<String,Object> params;
|
|
public static String EMAIL_REGEX_DEFAULT = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
|
|
|
|
public SendPortalWithAddTodoCmd(Map<String,Object> params){
|
|
this.params=params;
|
|
}
|
|
|
|
public Map<String, Object> execute(CommandContext commandContext) {
|
|
|
|
List<Map<String,Object>> todolist = (List<Map<String,Object>>)(params.get("TodoDatas"));
|
|
String requestid = Util.null2String(params.get("requestid"));
|
|
String bpm_app_workflowurl = PropBean.getUfPropValue("bpm_app_workflowurl");
|
|
String bpm_app_requesturl = PropBean.getUfPropValue("bpm_app_requesturl");
|
|
String portal_todourl = PropBean.getUfPropValue("portal_todourl");
|
|
String username = PropBean.getUfPropValue("username");
|
|
String passwd = PropBean.getUfPropValue("passwd");
|
|
String center = PropBean.getUfPropValue("center");
|
|
String bpm_workflowurl = PropBean.getUfPropValue("bpm_workflowurl");
|
|
|
|
sendTodoDataByNode(requestid,todolist,username,passwd,center,portal_todourl,bpm_workflowurl,bpm_app_workflowurl,bpm_app_requesturl);
|
|
|
|
|
|
return null;
|
|
}
|
|
|
|
private String getShortMessageTitle(String messageTitle) {
|
|
if (messageTitle.length() > 20) {
|
|
messageTitle = messageTitle.substring(0, 17) + "...";
|
|
}
|
|
return messageTitle;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param username
|
|
* @param passwd
|
|
* @param portal_todourl
|
|
* @param bpm_workflowurl
|
|
* @param bpm_app_workflowurl
|
|
* @param bpm_app_requesturl
|
|
*/
|
|
public void sendTodoDataByNode(String requestid,List<Map<String,Object>> todolist,String username,String passwd,String center,String portal_todourl,String bpm_workflowurl,String bpm_app_workflowurl,String bpm_app_requesturl){
|
|
HttpRequestUtil httpRequestUtil = new HttpRequestUtil();
|
|
|
|
String mobileJumpUrl = PropBean.getUfPropValue("mobileJumpUrl");
|
|
|
|
JSONObject requestObject = new JSONObject();
|
|
RecordSet rs = new RecordSet();
|
|
|
|
BaseBean bb = new BaseBean();
|
|
bb.writeLog("SendPortalQithRawRunnable--sendTodoDataByNode");
|
|
|
|
String terminal = "1" ;
|
|
String taskType = "0";
|
|
String actionType = "2" ;
|
|
String objectAction = "0" ;
|
|
String objectType = "0";
|
|
|
|
try {
|
|
String sql = "";
|
|
|
|
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 requestname = "" ;
|
|
String workflowname = "" ;
|
|
String nodeId = "" ;
|
|
String nodeName = "" ;
|
|
String lastName = "";
|
|
sql =" select t1.requestname,t1.currentnodeid as nodeid,d1.nodename,t3.workflowname,h2.lastname"+
|
|
" 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")) ;
|
|
nodeId = Util.null2String(rs.getString("nodeid")) ;
|
|
nodeName = Util.null2String(rs.getString("nodeName")) ;
|
|
lastName = Util.null2String(rs.getString("lastname")) ;
|
|
}
|
|
|
|
requestObject.put("center",center);
|
|
requestObject.put("title",requestname);
|
|
requestObject.put("creator",lastName);
|
|
requestObject.put("taskCode","weaver"+requestid);
|
|
|
|
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",nodeName);
|
|
requestObject.put("ticketType",workflowname);
|
|
|
|
|
|
|
|
String cus_staff = PropBean.getUfPropValue("cus_staff") ;
|
|
String scopeid = "-1";
|
|
String scope = "HrmCustomFieldByInfoType" ;
|
|
|
|
|
|
JSONArray taskObjectList = new JSONArray();
|
|
for (Map<String,Object> todoMap: todolist){
|
|
JSONObject taskObject = new JSONObject();
|
|
|
|
sql = " select count(0) num "+
|
|
" 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 t1.currentnodetype <> 3"+
|
|
" and t2.isremark in ('2','9','8')\n" +
|
|
" and t2.preisremark in ('8','9')\n" +
|
|
" and t2.islasttimes = 1\n" +
|
|
" and (t2.isprocessing = '' or t2.isprocessing is null)\n" +
|
|
" and t2.requestid = "+requestid + " and t2.userid = "+todoMap.get("id");
|
|
rs.executeQuery(sql);
|
|
int num = 0;
|
|
if(rs.next()){
|
|
num = rs.getInt("num");
|
|
}
|
|
if (num > 0){
|
|
continue;
|
|
}
|
|
bb.writeLog("num :"+num+",userid:"+todoMap.get("id"));
|
|
|
|
sql = " select t2.userid,h1.loginid,h1.lastname,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 t1.currentnodetype = 3"+
|
|
" and ((t2.isremark = '8' and t2.preisremark='8') or (t2.isremark = '9' and t2.preisremark='9'))\n" +
|
|
" and t2.islasttimes = 1\n" +
|
|
" and (t2.isprocessing = '' or t2.isprocessing is null)\n" +
|
|
" and t2.requestid = "+requestid+ " and t2.userid = "+todoMap.get("id");
|
|
rs.executeQuery(sql);
|
|
boolean hasData = true;
|
|
if (rs.next()){
|
|
hasData = false;
|
|
JSONArray list = new JSONArray();
|
|
JSONObject requestObject2 = new JSONObject();
|
|
requestObject2.putAll(requestObject);
|
|
|
|
SendPortalErrorUtil sendPortalErrorUtil = new SendPortalErrorUtil();
|
|
//归档节点抄送
|
|
String email = Util.null2String(rs.getString("email"));
|
|
requestObject2.put("nodeName",rs.getString("nodename"));
|
|
requestObject2.put("nodeId",rs.getString("nodeid"));
|
|
//requestObject2.put("taskCode",rs.getString("requestid")+"_cs_"+nodeId+"_"+rs.getString("userid"));
|
|
requestObject2.put("taskCode",rs.getString("requestid")+"_cs_"+rs.getString("userid"));
|
|
|
|
|
|
String creator = rs.getString("loginid");
|
|
if("sysadmin".equals(creator)){
|
|
creator = "Admin";
|
|
}
|
|
taskObject.put("objectAction","0");
|
|
taskObject.put("objectType","0");
|
|
taskObject.put("objectCode",creator);
|
|
taskObject.put("objectId",rs.getString("staffid"));
|
|
taskObject.put("operatorCode",creator);
|
|
list.add(taskObject);
|
|
|
|
//归档节点抄送
|
|
String emailArray = "";
|
|
Pattern regex = Pattern.compile(EMAIL_REGEX_DEFAULT);
|
|
|
|
requestObject2.put("messageTitle",getShortMessageTitle(requestname));
|
|
requestObject2.put("messageContent", requestname);
|
|
requestObject2.put("terminal", "1");
|
|
requestObject2.put("taskType", "1");
|
|
requestObject2.put("actionType", "2");
|
|
|
|
requestObject2.put("taskObjectList",list);
|
|
|
|
String auth = username + ":" + passwd;
|
|
|
|
bb.writeLog("SendPortalToReadUtil--requestObject:" + requestObject2.toJSONString());
|
|
String msgdata = httpRequestUtil.doPostByAuth(Constants.portal_todourl, requestObject2.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<String,String> templateMap = getEmailTemplate(requestname,rs.getString("lastname"),processTime);
|
|
String notificationSubject = templateMap.get("notificationSubject");
|
|
String notificationContent = templateMap.get("notificationContent");
|
|
//sendMailUtil.sendMail(requestid, emailArray, notificationSubject, notificationContent);
|
|
}
|
|
|
|
sendPortalErrorUtil.doRecordPortalErrorInfo(requestid,nodeId,rs.getString("nodename"),rs.getString("userid"),requestObject2.toJSONString(),resultCode,"");
|
|
|
|
}else if ("TODO-FAIL-002".equals(resultCode)){
|
|
//The task does not exist.任务不存在,则新增
|
|
User user = new User();
|
|
user.setUid(Integer.valueOf(todoMap.get("id").toString()));
|
|
SendPortalToReadUtil sendPortalToReadUtil = new SendPortalToReadUtil();
|
|
sendPortalToReadUtil.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,rs.getString("nodename"),rs.getString("userid"),requestObject2.toJSONString(),resultCode,resultmsg);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (hasData){
|
|
SendPortalErrorUtil sendPortalErrorUtil = new SendPortalErrorUtil();
|
|
String userSql = "select "+cus_staff+" as staffid from cus_fielddata where scopeid=-1 and scope='HrmCustomFieldByInfoType' and id=?";
|
|
rs.executeQuery(userSql,todoMap.get("id"));
|
|
requestObject.put("nodeId",nodeId+todoMap.get("id"));
|
|
|
|
String loginid = Util.null2String(todoMap.get("loginid"));
|
|
if("sysadmin".equals(loginid)){
|
|
loginid = "Admin";
|
|
}
|
|
if (rs.next()){
|
|
String staffid = Util.null2String(rs.getString("staffid"));
|
|
taskObject.put("objectId",staffid);
|
|
}
|
|
taskObject.put("objectAction",objectAction);
|
|
taskObject.put("objectType",objectType);
|
|
taskObject.put("objectCode",loginid);
|
|
taskObject.put("operatorCode",loginid);
|
|
taskObjectList.add(taskObject);
|
|
}
|
|
}
|
|
//发送待办
|
|
if (taskObjectList.size() > 0){
|
|
requestObject.put("taskObjectList",taskObjectList);
|
|
|
|
String auth = username + ":" + passwd;
|
|
bb.writeLog("sendTodoDataByNode---requestObject:"+requestObject.toJSONString());
|
|
String msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth);
|
|
bb.writeLog("msgdata:"+msgdata);
|
|
Map<String,Object> map = new HashMap<>();
|
|
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)){
|
|
map.put("resultCode","0");
|
|
}else{
|
|
bb.writeLog(msgObject.get("resultMsg"));
|
|
map.put("resultCode",resultCode);
|
|
map.put("resultMsg",msgObject.get("resultMsg"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
/***
|
|
*
|
|
* @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-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;
|
|
}
|
|
|
|
}
|