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.
haojing/src/com/customization/dito/sendtodo/SendPortalAgentCmd.java

232 lines
12 KiB
Java

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.Util;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.dito.comInfo.PropBean;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
/**
* @Title
* @Author wangchaofa
* @CreateDate 2023/11/15
* @Version 1.0
* @Description
*/
public class SendPortalAgentCmd {
/**
*
* @param agenterid
* @param beagenterid
* @param workflowids id
* @param user
*/
public void DealPortalTodoAndDone(int agenterid, int beagenterid, String workflowids, User user){
RecordSet rs = new RecordSet();
RecordSet rs1 = new RecordSet();
JSONArray taskObjectList = new JSONArray();
String EMAIL_REGEX_DEFAULT = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
Pattern regex = Pattern.compile(EMAIL_REGEX_DEFAULT);
JSONObject taskObject = new JSONObject();
rs.writeLog("==================== SendPortalAgentCmd DealPortalTodoAndDone ===================");
rs.writeLog("==================== SendPortalAgentCmd DealPortalTodoAndDone agenterid ==================="+ agenterid);
rs.writeLog("==================== SendPortalAgentCmd DealPortalTodoAndDone beagenterid ==================="+ beagenterid);
try {
taskObject.put("objectAction", "0");
taskObject.put("objectType", "0");
taskObject.put("objectCode", new ResourceComInfo().getWorkcode(String.valueOf(agenterid)));
taskObject.put("objectId", getStaffId(agenterid));
taskObject.put("operatorCode", new ResourceComInfo().getWorkcode(String.valueOf(agenterid)));
taskObjectList.add(taskObject);
HttpRequestUtil httpRequestUtil = new HttpRequestUtil();
SendPortalErrorUtil sendPortalErrorUtil = new SendPortalErrorUtil();
SendMailUtil sendMailUtil = new SendMailUtil();
String scopeid = "-1";
String scope = "HrmCustomFieldByInfoType";
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");
String mobileJumpUrl = PropBean.getUfPropValue("mobileJumpUrl");
String cus_staff = PropBean.getUfPropValue("cus_staff") ;
String processTime = DateUtil.getCurrentTime("yyyy-MM-dd HH:mm:ss");
String sql = " select distinct t1.requestid,t1.requestname,t1.createdate,h1.lastname as creatorname,t2.receivedate,t2.receivetime " +
" from workflow_base t " +
" left join workflow_requestbase t1 on t.id=t1.workflowid " +
" left join workflow_currentoperator t2 on t1.requestid = t2.requestid " +
" left join hrmresource h1 on h1.id = t1.creater "+
" where t2.usertype=0 and t2.userid in (" + beagenterid +") and t.id in (" + workflowids +") "+
" and ((t2.isremark =0 and (t2.takisremark is null or t2.takisremark ='0')) or t2.isremark in('1','5','9','7','8','9','11') ) " +
" and t2.islasttimes=1 " +
" and (t.isvalid=3 or t.isvalid=1) ";
rs.writeLog("SendPortalAgentCmd DealPortalTodoAndDone -- sql:" + sql);
String zhjkbs = "com.engine.workflow.cmd.agent.SaveAgentDetailCmd.DealPortalTodoAndDone";
String actionType = "1";
String terminal = "1";
String taskType = "0";
rs1.executeQuery(sql);
while (rs1.next()) {
String requestid = Util.null2String(rs1.getString("requestid"));
String workflowname = "";
String nodeId = "";
String nodeName = "";
JSONObject requestObject = new JSONObject();
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 msgdata = "";
String requestname = "";
String lastname = "";
String userids = "";
String loginid = "";
String emailArray = "";
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;
rs.writeLog("SendPortalAgentCmd DealPortalTodoAndDone -- sql:" + 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") + user.getUID());
nodeName = Util.null2String(rs.getString("nodeName"));
lastname = Util.null2String(rs.getString("lastname"));
loginid = Util.null2String(rs.getString("loginid"));
}
requestObject.put("center", center);
requestObject.put("title", requestname);
requestObject.put("creator", loginid);
requestObject.put("taskCode", "weaver" + requestid);
requestObject.put("nodeId", nodeId);
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);
JSONObject taskObject1 = new JSONObject();
taskObject1.put("objectAction", "1");
taskObject1.put("objectType", "0");
taskObject1.put("objectCode", new ResourceComInfo().getWorkcode(String.valueOf(beagenterid)));
taskObject1.put("objectId", getStaffId(beagenterid));
taskObject1.put("operatorCode", new ResourceComInfo().getWorkcode(String.valueOf(beagenterid)));
taskObjectList.add(taskObject1);
if (taskObjectList.size() > 0) {
requestObject.put("taskObjectList", taskObjectList);
} else {
requestObject.put("actionType", "3");
}
String auth = username + ":" + passwd;
rs.writeLog("================== SendPortalAgentCmd DealPortalTodoAndDone ======================== "+requestObject.toJSONString());
msgdata = httpRequestUtil.doPostByAuth(portal_todourl, requestObject.toJSONString(), auth);
if (!"".equals(msgdata)) {
JSONObject msgObject = JSONObject.parseObject(msgdata);
if (msgObject.containsKey("resultCode")) {
String resultCode = msgObject.getString("resultCode");
if ("0".equals(resultCode)) {
rs.writeLog("AddAgentSaveCmd emailArray:" + emailArray);
if (StringUtils.isNotEmpty(emailArray)) {
Map<String, String> 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, String.valueOf(beagenterid), requestObject.toJSONString(), resultCode, "",zhjkbs, String.valueOf(agenterid));
} else {
String resultmsg = msgObject.getString("resultMsg");
sendPortalErrorUtil.doRecordPortalErrorInfo4Phase2(requestid, nodeId, nodeName, String.valueOf(beagenterid), requestObject.toJSONString(), resultCode, resultmsg ,zhjkbs, String.valueOf(agenterid));
}
}
}
}
}catch (Exception e){
e.printStackTrace();
rs.writeLog(e);
}
}
public 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-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;
}
public int getStaffId(int userid){
int result = -1;
String cus_staff = PropBean.getUfPropValue("cus_staff") ;
RecordSet rs = new RecordSet();
rs.executeQuery("select "+ cus_staff + " from cus_fielddata where scopeid=-1 and scope = 'HrmCustomFieldByInfoType' and id=?",userid);
rs.next();
result = Util.getIntValue(rs.getString(cus_staff));
return result;
}
}