推送OA消息待办
This commit is contained in:
parent
7b06344c25
commit
c4eadecde8
|
@ -0,0 +1,750 @@
|
|||
package shkd.cosmic.cxkg.integration;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.workflow.engine.msg.AbstractMessageServiceHandler;
|
||||
import kd.bos.workflow.engine.msg.ctx.MessageContext;
|
||||
import kd.bos.workflow.engine.msg.info.MessageInfo;
|
||||
import kd.bos.workflow.engine.msg.info.ToDoInfo;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
public class MessageListen extends AbstractMessageServiceHandler {
|
||||
private static final Log log = LogFactory.getLog(MessageListen.class);
|
||||
static Map<String, String> processInstanceStateMap = new HashMap();
|
||||
static Map<String, String> taskStateMap = new HashMap();
|
||||
static Map<String, String> operationTypeMap = new HashMap();
|
||||
static Map<String, String> decisionTypeMap = new HashMap();
|
||||
|
||||
static {
|
||||
processInstanceStateMap.put("1", "1");
|
||||
processInstanceStateMap.put("2", "2");
|
||||
taskStateMap.put("dismissed", "被驳回");
|
||||
taskStateMap.put("willApproval", "待审批");
|
||||
taskStateMap.put("freeze", "已冻结");
|
||||
taskStateMap.put("willHandled", "待处理");
|
||||
taskStateMap.put("unConverted", "待转换");
|
||||
taskStateMap.put("converted", "已转换");
|
||||
taskStateMap.put("converting", "转换中");
|
||||
taskStateMap.put("manualSuspended", "已挂起");
|
||||
operationTypeMap.put("transfer", "1");
|
||||
operationTypeMap.put("coordinateRequest", "2");
|
||||
operationTypeMap.put("coordinateReply", "3");
|
||||
operationTypeMap.put("coordinateCancel", "4");
|
||||
operationTypeMap.put("addComment", "5");
|
||||
operationTypeMap.put("withdraw", "6");
|
||||
operationTypeMap.put("circulation", "7");
|
||||
operationTypeMap.put("reminders", "8");
|
||||
operationTypeMap.put("jump", "9");
|
||||
operationTypeMap.put("addsign", "10");
|
||||
operationTypeMap.put("suspend", "11");
|
||||
operationTypeMap.put("suspendCancel", "12");
|
||||
operationTypeMap.put("terminal_f", "13");
|
||||
operationTypeMap.put("delegate", "14");
|
||||
operationTypeMap.put("textMessage", "15");
|
||||
operationTypeMap.put("converted", "16");
|
||||
decisionTypeMap.put("approve", "同意");
|
||||
decisionTypeMap.put("reject", "驳回");
|
||||
decisionTypeMap.put("terminate", "终止");
|
||||
}
|
||||
|
||||
public MessageListen() {
|
||||
}
|
||||
|
||||
public void createToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
|
||||
int tasktype = 0;
|
||||
log.info("待办任务~~~~~~~~~~");
|
||||
List<Map<String, Object>> requestBodyList = this.getRequestBodyList(messageContext, toDoInfo, tasktype, false);
|
||||
log.info("推送待办任务内容:{}", requestBodyList);
|
||||
|
||||
Map resultMap;
|
||||
for (Iterator var6 = requestBodyList.iterator(); var6.hasNext(); resultMap.get("code")) {
|
||||
Map<String, Object> requestBody = (Map) var6.next();
|
||||
String jsonStr = this.pushZHData(requestBody);
|
||||
log.info("推送结果 jsonStr:" + jsonStr);
|
||||
resultMap = (Map) JSON.parseObject(jsonStr, Map.class);
|
||||
if ("1".equals(resultMap.get("operResult"))) {
|
||||
log.info("推送待办任务内容成功");
|
||||
} else {
|
||||
log.info("推送待办任务内容失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void dealToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
|
||||
// int tasktype = 2;
|
||||
// log.info("已办任务~~~~~~~~~~");
|
||||
// List<Map<String, Object>> requestBodyList = this.getRequestBodyList(messageContext, toDoInfo, tasktype, false);
|
||||
// log.info("推送已办任务内容:{}", requestBodyList);
|
||||
//
|
||||
// Map resultMap;
|
||||
// for(Iterator var6 = requestBodyList.iterator(); var6.hasNext(); resultMap.get("code")) {
|
||||
// Map<String, Object> requestBody = (Map)var6.next();
|
||||
// String jsonStr = this.pushZHData(requestBody);
|
||||
// log.info("推送结果 jsonStr:"+jsonStr);
|
||||
// resultMap = (Map)JSON.parseObject(jsonStr, Map.class);
|
||||
// resultMap.get("code");
|
||||
// if ("1".equals(resultMap.get("operResult"))) {
|
||||
// log.info("推送已办任务内容成功");
|
||||
// } else {
|
||||
// log.info("推送已办任务内容失败");
|
||||
// }
|
||||
// }
|
||||
|
||||
int tasktype = 2;
|
||||
log.info("已办任务~~~~~~~~~~");
|
||||
List<Map<String, Object>> requestBodyList = this.getRequestBodyList(messageContext, toDoInfo, tasktype, false);
|
||||
log.info("推送已办任务内容:{}", requestBodyList);
|
||||
Map resultMap;
|
||||
for (Iterator<Map<String, Object>> var6 = requestBodyList.iterator(); var6.hasNext(); resultMap.get("code")) {
|
||||
Map<String, Object> requestBody = var6.next();
|
||||
String jsonStr = pushZHData(requestBody);
|
||||
log.info("已办任务结果~"+jsonStr);
|
||||
resultMap = (Map) JSON.parseObject(jsonStr, Map.class);
|
||||
resultMap.get("code");
|
||||
if ("200".equals(resultMap.get("code"))) {
|
||||
log.info("推送已办任务内容成功");
|
||||
} else {
|
||||
log.info("推送已办任务内容失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(MessageContext ctx, MessageInfo message) {
|
||||
int tasktype = 4;
|
||||
super.sendMessage(ctx, message);
|
||||
log.info("消息通知~~~~~~~~~~");
|
||||
List<Map<String, Object>> requestBodyList = getRequestBodyList2(message);
|
||||
log.info("推送消息通知内容:{}", requestBodyList);
|
||||
|
||||
Map resultMap;
|
||||
for (Iterator var6 = requestBodyList.iterator(); var6.hasNext(); resultMap.get("code")) {
|
||||
Map<String, Object> requestBody = (Map) var6.next();
|
||||
String jsonStr = this.pushZHData(requestBody);
|
||||
log.info("传阅结果 jsonStr:" + jsonStr);
|
||||
resultMap = (Map) JSON.parseObject(jsonStr, Map.class);
|
||||
resultMap.get("errcode");
|
||||
if ("0".equals(resultMap.get("errcode"))) {
|
||||
log.info("推送已办任务内容成功");
|
||||
} else {
|
||||
log.info("推送已办任务内容失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
|
||||
log.info("删除待办~~~~~~~~~~");
|
||||
int tasktype = 2;
|
||||
List<Map<String, Object>> requestBodyList = this.getRequestBodyList(messageContext, toDoInfo, tasktype, true);
|
||||
log.info("推送删除任务内容:{}", requestBodyList);
|
||||
|
||||
Map resultMap;
|
||||
for (Iterator var6 = requestBodyList.iterator(); var6.hasNext(); resultMap.get("code")) {
|
||||
Map<String, Object> requestBody = (Map) var6.next();
|
||||
String jsonStr = this.pushZHData(requestBody);
|
||||
log.info("推送结果 jsonStr:" + jsonStr);
|
||||
resultMap = (Map) JSON.parseObject(jsonStr, Map.class);
|
||||
resultMap.get("code");
|
||||
if ("1".equals(resultMap.get("operResult"))) {
|
||||
log.info("推送删除任务内容成功");
|
||||
} else {
|
||||
log.info("推送删除任务内容失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getRequestBodyList(MessageContext messageContext, ToDoInfo toDoInfo, int tasktype, boolean isdel) {
|
||||
Long processDefinitionId = messageContext.getProcessDefinitionId();
|
||||
String processDefinitionName = "";
|
||||
Long processInstanceId = messageContext.getProcessInstanceId();
|
||||
String processInstanceState = "";
|
||||
String nodename = "";
|
||||
Long createDateUnix = 0L;
|
||||
Long modifyDateUnix = 0L;
|
||||
String createDateString = "";
|
||||
String url = toDoInfo.getUrl();
|
||||
Long startUserId = messageContext.getStartUserId();
|
||||
String startUserMobile = "";
|
||||
String startUserName = "";
|
||||
Long executionId = messageContext.getExecutionId();
|
||||
String executionName = "";
|
||||
Long taskId = messageContext.getTaskId();
|
||||
String taskName = "";
|
||||
String taskState = "";
|
||||
Long taskCreateDateUnix = 0L;
|
||||
Long taskUpdateDateUnix = 0L;
|
||||
String taskCreateDateString = "";
|
||||
List<Long> userIds = toDoInfo.getUserIds();
|
||||
List<String> userMobiles = new ArrayList();
|
||||
List<String> userNames = new ArrayList();
|
||||
String operationType = "";
|
||||
String operationUserMobile = "";
|
||||
String msg_type = "";
|
||||
String MessageState = "";
|
||||
String billno = "";
|
||||
String title = isdel ? "流程撤回" : toDoInfo.getContent();
|
||||
String entityName = messageContext.getEntityName();
|
||||
if (title != null) {
|
||||
int dex = title.indexOf("单", 0);
|
||||
if (dex != -1) {
|
||||
title = title.substring(dex + 1);//截取单后面的字符串
|
||||
}
|
||||
}
|
||||
// if (title == null) {
|
||||
// title = "任务:" + taskId + "已办";
|
||||
// }
|
||||
|
||||
DynamicObject processDefinition = BusinessDataServiceHelper.loadSingle(processDefinitionId, "wf_processdefinition");
|
||||
if (processDefinition != null) {
|
||||
processDefinitionName = processDefinition.getString("name");
|
||||
}
|
||||
DynamicObject[] processInstance = BusinessDataServiceHelper.load("wf_execution", "createdate", new QFilter("id", "=", processInstanceId).toArray());
|
||||
if (processInstance.length != 0) {
|
||||
Date createDate = processInstance[0].getDate("createdate");
|
||||
if (createDate != null) {
|
||||
createDateString = isdel ? (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()) : (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(createDate);
|
||||
}
|
||||
}
|
||||
|
||||
DynamicObject startUser = BusinessDataServiceHelper.loadSingle(startUserId, "bos_user");
|
||||
if (startUser != null) {
|
||||
startUserMobile = startUser.getString("phone");
|
||||
startUserName = startUser.getString("username");
|
||||
}
|
||||
|
||||
|
||||
// DynamicObject execution = BusinessDataServiceHelper.loadSingle(executionId, "wf_execution");
|
||||
// if (execution != null) {
|
||||
// executionName = execution.getString("name");
|
||||
// if (executionName != null){
|
||||
// String[] split = executionName.split("/");
|
||||
// if (split != null){
|
||||
// billno = split[0];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
DynamicObject[] task = BusinessDataServiceHelper.load("wf_task", "name,handlestate,createdate", new QFilter("id", "=", taskId).toArray());
|
||||
if (task.length != 0) {
|
||||
taskName = task[0].getString("name");
|
||||
String handleState = task[0].getString("handlestate");
|
||||
taskState = (String) taskStateMap.get(handleState);
|
||||
Date taskCreateDate = task[0].getDate("createdate");
|
||||
if (taskCreateDate != null) {
|
||||
taskCreateDateString = isdel ? (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()) : (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(taskCreateDate);
|
||||
}
|
||||
}
|
||||
|
||||
QFilter operationLogFilter;
|
||||
if (CollectionUtils.isNotEmpty(userIds)) {
|
||||
operationLogFilter = new QFilter("id", "in", userIds);
|
||||
DynamicObject[] userList = BusinessDataServiceHelper.load("bos_user", "phone,username", operationLogFilter.toArray());
|
||||
Arrays.stream(userList).forEach((user) -> {
|
||||
if (user != null) {
|
||||
String mobile = user.getString("phone");
|
||||
userMobiles.add(mobile);
|
||||
String name = user.getString("username");
|
||||
userNames.add(name);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// operationLogFilter = new QFilter("taskid", "=", taskId);
|
||||
// QFilter operationLogFilter1 = new QFilter("type", "!=", "circulation");
|
||||
// QFilter[] operationLogFilters = new QFilter[]{operationLogFilter, operationLogFilter1};
|
||||
// DynamicObject[] operationLogs = BusinessDataServiceHelper.load("wf_operationlog", "ownerid,type,createdate,decisiontype", operationLogFilters, "createdate desc");
|
||||
// if (operationLogs.length != 0) {
|
||||
// DynamicObject operationLog = operationLogs[0];
|
||||
// Long ownerId = operationLog.getLong("ownerid");
|
||||
// DynamicObject operationUser = BusinessDataServiceHelper.loadSingle(ownerId, "bos_user");
|
||||
// if (operationUser != null) {
|
||||
// operationUserMobile = operationUser.getString("phone");
|
||||
// }
|
||||
//
|
||||
// String type = operationLog.getString("type");
|
||||
// if ("comment".equals(type)) {
|
||||
// String decisionType = operationLog.getString("decisiontype");
|
||||
// if (!StringUtils.isEmpty(decisionType)) {
|
||||
// operationType = (String)decisionTypeMap.get(decisionType);
|
||||
// }
|
||||
// } else if (tasktype != 1) {
|
||||
// operationType = (String)operationTypeMap.get(type);
|
||||
// }
|
||||
// }
|
||||
//// String data = createDateString.substring(0,10);//截取日期前十位
|
||||
// if (title == null) {
|
||||
// title = "任务:" + billno + processDefinitionName + "已处理";
|
||||
// }
|
||||
// QFilter startUserFilter;
|
||||
// if (CollectionUtils.isNotEmpty(userIds)) {
|
||||
// startUserFilter = new QFilter("id", "in", userIds);
|
||||
// DynamicObject[] userList = BusinessDataServiceHelper.load("bos_user", "phone,username", startUserFilter.toArray());
|
||||
// Arrays.stream(userList).forEach((user) -> {
|
||||
// if (user != null) {
|
||||
// String mobile = user.getString("phone");
|
||||
// userMobiles.add(mobile);
|
||||
// String name = user.getString("username");
|
||||
// userNames.add(name);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// }
|
||||
// String receiverUser = "";
|
||||
// DynamicObject receiver = BusinessDataServiceHelper.loadSingle(userIds, "bos_user");
|
||||
// if (startUser != null) {
|
||||
//// startUserMobile = receiver.getString("phone");
|
||||
// receiverUser = receiver.getString("username");
|
||||
// }
|
||||
userNames.add(startUserName);
|
||||
List<Map<String, Object>> requestBodyList = new ArrayList();
|
||||
Iterator var47 = userNames.iterator();
|
||||
|
||||
while (var47.hasNext()) {
|
||||
String userName = (String) var47.next();
|
||||
if (userName.equals(startUserName)) {
|
||||
Map<String, Object> requestBody = new HashMap();
|
||||
requestBody.put("syscode", "kingdee");
|
||||
requestBody.put("flowid", String.valueOf(processInstanceId));
|
||||
requestBody.put("requestname", "主题:"+title);
|
||||
requestBody.put("workflowname", entityName + "审批流程");
|
||||
requestBody.put("nodename", taskName);
|
||||
requestBody.put("pcurl", url);
|
||||
requestBody.put("appurl", url != null ? getAppurl(url) : null);
|
||||
requestBody.put("isremark", String.valueOf(tasktype));
|
||||
requestBody.put("viewtype", "1");
|
||||
requestBody.put("creator", startUserName);
|
||||
requestBody.put("createdatetime", createDateString);
|
||||
requestBody.put("receiver", userName);
|
||||
requestBody.put("receivedatetime", taskCreateDateString);
|
||||
requestBody.put("receivets", String.valueOf((new Date()).getTime()));
|
||||
requestBody.put("userid", userName);
|
||||
requestBody.put("bizState", String.valueOf(tasktype));
|
||||
requestBody.put("lastNameList", userName);
|
||||
// requestBody.put("targetId", "588|"+String.valueOf(processInstanceId));
|
||||
// requestBodyList.add(requestBody);
|
||||
} else {
|
||||
Map<String, Object> requestBody = new HashMap();
|
||||
requestBody.put("syscode", "kingdee");
|
||||
requestBody.put("flowid", String.valueOf(processInstanceId));
|
||||
if(title!=null){
|
||||
requestBody.put("requestname", title);
|
||||
}else{
|
||||
requestBody.put("requestname", entityName);
|
||||
}
|
||||
|
||||
requestBody.put("workflowname", entityName + "审批流程");
|
||||
requestBody.put("nodename", taskName);
|
||||
requestBody.put("pcurl", url);
|
||||
requestBody.put("appurl", getAppurl(url));
|
||||
requestBody.put("isremark", String.valueOf(tasktype));
|
||||
requestBody.put("viewtype", "0");
|
||||
requestBody.put("creator", startUserName);
|
||||
requestBody.put("createdatetime", createDateString);
|
||||
requestBody.put("receiver", userName);
|
||||
requestBody.put("receivedatetime", taskCreateDateString);
|
||||
requestBody.put("receivets", String.valueOf((new Date()).getTime()));
|
||||
requestBody.put("userid", userName);
|
||||
requestBody.put("bizState", String.valueOf(tasktype));
|
||||
requestBody.put("lastNameList", userName);
|
||||
// requestBody.put("targetId", "588|"+String.valueOf(processInstanceId));
|
||||
requestBodyList.add(requestBody);
|
||||
}
|
||||
}
|
||||
|
||||
return requestBodyList;
|
||||
}
|
||||
|
||||
private static String getAppurl(String pcurl) {
|
||||
if (pcurl != null) {
|
||||
String appurl = pcurl.replace("integration/yzjShareOpen.do", "mobile.html").replace("formId=wf_approvalpage_bac", "form=wf_approvalpagemobile_bac");
|
||||
return appurl;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getRequestBodyList2(MessageInfo message) {
|
||||
Map<String, Object> messageContext = JSON.parseObject(message.getParams().get("messageContext").toString());
|
||||
Long createDateUnix = 0L;
|
||||
Long processInstanceId = (Long) messageContext.get("processInstanceId");//processInstanceId
|
||||
Long modifyDateUnix = 0L;
|
||||
Long taskCreateDateUnix = 0L;
|
||||
Long taskUpdateDateUnix = 0L;
|
||||
String taskName = "";
|
||||
String taskState = "";
|
||||
String processInstanceState = "";
|
||||
String taskCreateDateString = "";
|
||||
String startUserName = "";
|
||||
String createDateString = "";
|
||||
String title = message.getTitle();
|
||||
String content = message.getContent();
|
||||
String url = message.getContentUrl();
|
||||
String taskId = messageContext.get("taskId").toString();
|
||||
List<Long> userIds = message.getUserIds();
|
||||
List<String> userMobiles = new ArrayList();
|
||||
List<String> userNames = new ArrayList();
|
||||
Long senderId = message.getSenderId();
|
||||
String senderMobile = "";
|
||||
Long startUserId = (Long) messageContext.get("startUserId");
|
||||
String startUserMobile = null;
|
||||
Date sendTime = message.getSendTime();
|
||||
String entityName = null;
|
||||
Long processDefinitionId = Long.parseLong(messageContext.get("processDefinitionId").toString());
|
||||
String processDefinitionName = "";
|
||||
String noticeId = message.getId().toString();
|
||||
DynamicObject processDefinition = BusinessDataServiceHelper.loadSingle(processDefinitionId, "wf_processdefinition");
|
||||
if (processDefinition != null) {
|
||||
processDefinitionName = processDefinition.getString("name");
|
||||
}
|
||||
QFilter startUserFilter;
|
||||
if (CollectionUtils.isNotEmpty(userIds)) {
|
||||
startUserFilter = new QFilter("id", "in", userIds);
|
||||
DynamicObject[] userList = BusinessDataServiceHelper.load("bos_user", "phone,username", startUserFilter.toArray());
|
||||
Arrays.stream(userList).forEach((user) -> {
|
||||
if (user != null) {
|
||||
String mobile = user.getString("phone");
|
||||
userMobiles.add(mobile);
|
||||
String name = user.getString("username");
|
||||
userNames.add(name);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
DynamicObject startUser;
|
||||
if (senderId != null && senderId != 0L) {
|
||||
startUserFilter = new QFilter("id", "=", senderId);
|
||||
startUser = BusinessDataServiceHelper.loadSingleFromCache("bos_user", startUserFilter.toArray());
|
||||
if (startUser != null) {
|
||||
senderMobile = startUser.getString("phone");
|
||||
}
|
||||
}
|
||||
if (startUserId != null) {
|
||||
startUserFilter = new QFilter("id", "=", startUserId);
|
||||
startUser = BusinessDataServiceHelper.loadSingleFromCache("bos_user", startUserFilter.toArray());
|
||||
if (startUser != null) {
|
||||
startUserMobile = startUser.getString("phone");
|
||||
}
|
||||
DynamicObject startUser1 = BusinessDataServiceHelper.loadSingle(startUserId, "bos_user");
|
||||
if (startUser1 != null) {
|
||||
startUserName = startUser1.getString("username");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (messageContext.get("entityName") != null) {
|
||||
entityName = messageContext.get("entityName").toString();
|
||||
}
|
||||
|
||||
DynamicObject processInstance = BusinessDataServiceHelper.loadSingle(processInstanceId, "wf_execution");
|
||||
if (processInstance != null) {
|
||||
Date createDate = processInstance.getDate("createdate");
|
||||
if (createDate != null) {
|
||||
createDateUnix = createDate.getTime();
|
||||
createDateString = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(createDate);
|
||||
}
|
||||
|
||||
Date modifyDate = processInstance.getDate("modifydate");
|
||||
if (modifyDate != null) {
|
||||
modifyDateUnix = modifyDate.getTime();
|
||||
}
|
||||
|
||||
String suspensionstate = processInstance.getString("suspensionstate");
|
||||
processInstanceState = (String) processInstanceStateMap.get(suspensionstate);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> requestBodyList = new ArrayList();
|
||||
Iterator var21 = userNames.iterator();
|
||||
|
||||
int i = 1;
|
||||
while (var21.hasNext()) {
|
||||
String username = (String) var21.next();
|
||||
Map<String, Object> requestBody = new HashMap();
|
||||
// requestBody.put("code", 588);
|
||||
// requestBody.put("title", title);
|
||||
// requestBody.put("requestname", title);
|
||||
// requestBody.put("flowid", String.valueOf(processInstanceId+i));
|
||||
// requestBody.put("workflowname", entityName+"审批流程");
|
||||
// requestBody.put("content", content);
|
||||
// requestBody.put("context", content);
|
||||
// requestBody.put("pcurl", url);
|
||||
// requestBody.put("appurl", getAppurl(url));
|
||||
//// requestBody.put("taskId", taskId);
|
||||
////// requestBody.put("userMobile", userMobile);
|
||||
// requestBody.put("senderMobile", senderMobile);
|
||||
// requestBody.put("startUserMobile", startUserMobile);
|
||||
//// requestBody.put("sendTime", sendTime);
|
||||
// requestBody.put("entityName", entityName);
|
||||
////// requestBody.put("receiver", username);
|
||||
////// requestBody.put("userids", username);
|
||||
// requestBody.put("isremark", "8");
|
||||
// requestBody.put("viewtype", "0");
|
||||
// requestBody.put("creater", startUserName);
|
||||
// requestBody.put("createdatetime", createDateString);
|
||||
// requestBody.put("receivedatetime", createDateString);
|
||||
// requestBody.put("processDefinitionId", processDefinitionId.toString());
|
||||
// requestBody.put("processDefinitionName", processDefinitionName);
|
||||
////// requestBody.put("receivets", String.valueOf((new Date()).getTime()));
|
||||
// requestBody.put("noticeId", noticeId);
|
||||
// requestBody.put("loginIdList", username);
|
||||
// requestBody.put("linkUrl", url);
|
||||
// requestBody.put("linkMobileUrl", getAppurl(url));
|
||||
// requestBody.put("loginIdList", "zhangqj");
|
||||
//// requestBody.put("linkMobileUrl", "http://oatest.zhonghuangroup.com:8999");
|
||||
|
||||
// String appurl = getAppurl(url);
|
||||
String encode = Base64.getEncoder().encodeToString(url.getBytes());
|
||||
QFilter filter = new QFilter("number", "=", "003");
|
||||
DynamicObject kd21_oa_matters = BusinessDataServiceHelper.loadSingle("kd21_oa_matters", "id,name,kd21_largetextfield", new QFilter[]{filter});
|
||||
String kd21_largetextfield = kd21_oa_matters.getString("kd21_largetextfield");
|
||||
requestBody.put("code", "588");
|
||||
requestBody.put("loginIdList", username);
|
||||
requestBody.put("creater", startUserName);
|
||||
requestBody.put("title", title);
|
||||
requestBody.put("context", content);
|
||||
requestBody.put("linkUrl", url);
|
||||
requestBody.put("linkMobileUrl", kd21_largetextfield + encode);
|
||||
requestBody.put("targetId", "588|" + String.valueOf(processInstanceId));
|
||||
requestBody.put("bizState", "0");
|
||||
requestBodyList.add(requestBody);
|
||||
i++;
|
||||
}
|
||||
return requestBodyList;
|
||||
}
|
||||
|
||||
// private String pushZHData(Map<String, Object> params) {
|
||||
// log.info("推送消息到中环.....");
|
||||
// Map<String, Object> registAppid = TokenAuthentication.registAppid();
|
||||
// Map<String, Object> token = TokenAuthentication.getToken();
|
||||
// QFilter filter = new QFilter("number","=","001");
|
||||
//// DynamicObject kd21_oa_matters = BusinessDataServiceHelper.loadSingle("kd21_oa_matters", "id,name,kd21_largetextfield", new QFilter[]{filter});
|
||||
//// String kd21_largetextfield = kd21_oa_matters.getString("kd21_largetextfield");
|
||||
// String kd21_largetextfield = "/rest/ofs/ReceiveRequestInfoByJson";
|
||||
// String apiUrl = kd21_largetextfield;//获取接口的地址
|
||||
// log.info("推送接口地址:"+apiUrl+"");
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
// headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// String jsonBody = JSON.toJSONString(params);
|
||||
// String postRestful = TokenAuthentication.postRestful(apiUrl, jsonBody);
|
||||
// HttpEntity<String> requestEntity = new HttpEntity(jsonBody, headers);
|
||||
//// log.info("推送完成,返回结果:{}", "postRestful"+postRestful);
|
||||
// ResponseEntity<String> responseEntity = restTemplate.postForEntity(apiUrl, requestEntity, String.class, new Object[0]);
|
||||
// log.info("推送完成,返回结果:responseEntity{}", responseEntity);
|
||||
// String jsonStr = (String)responseEntity.getBody();
|
||||
// log.info("推送完成,返回结果:{}", jsonStr);
|
||||
// return jsonStr;
|
||||
// }
|
||||
// private String pushZHMessage(Map<String, Object> params) {
|
||||
// log.info("推送待办到中环.....");
|
||||
// QFilter filter = new QFilter("number","=","002");
|
||||
// DynamicObject kd21_oa_matters = BusinessDataServiceHelper.loadSingle("kd21_oa_matters", "id,name,kd21_largetextfield", new QFilter[]{filter});
|
||||
// String kd21_largetextfield = kd21_oa_matters.getString("kd21_largetextfield");
|
||||
//// String kd21_largetextfield = "/api/ec/dev/message/sendCustomMessageSingle";
|
||||
// String apiUrl = kd21_largetextfield;//获取接口的地址
|
||||
// log.info("传阅接口地址:"+apiUrl+"");
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
//
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// String jsonBody = JSON.toJSONString(params);
|
||||
// HttpEntity<String> requestEntity = new HttpEntity(jsonBody, headers);
|
||||
// log.info("传阅接口:"+requestEntity+"");
|
||||
//// Map<String, Object> token = TokenAuthentication.getToken();
|
||||
//// String postRestful = TokenAuthentication.postRestful(apiUrl, jsonBody);
|
||||
// ResponseEntity<String> responseEntity = restTemplate.postForEntity(apiUrl, requestEntity, String.class, new Object[0]);
|
||||
// log.info("传阅完成,返回结果:responseEntity{}", responseEntity);
|
||||
// String jsonStr = (String)responseEntity.getBody();
|
||||
// log.info("传阅完成,返回结果:{}", jsonStr);
|
||||
// return jsonStr;
|
||||
//// log.info("推送完成,返回结果:{}", "postRestful"+postRestful);
|
||||
//// return postRestful;
|
||||
// }
|
||||
//
|
||||
// private String pushZHDelete(Map<String, Object> params) {
|
||||
// log.info("删除待办到中环.....");
|
||||
// QFilter filter = new QFilter("number","=","003");
|
||||
// DynamicObject kd21_oa_matters = BusinessDataServiceHelper.loadSingle("kd21_oa_matters", "id,name,kd21_largetextfield", new QFilter[]{filter});
|
||||
// String kd21_largetextfield = kd21_oa_matters.getString("kd21_largetextfield");
|
||||
//// String kd21_largetextfield = "/rest/ofs/deleteUserRequestInfoByJson";
|
||||
// String apiUrl = kd21_largetextfield;//获取接口的地址
|
||||
// log.info("删除接口地址:"+apiUrl+"");
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
//
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// String jsonBody = JSON.toJSONString(params);
|
||||
// HttpEntity<String> requestEntity = new HttpEntity(jsonBody, headers);
|
||||
// log.info("删除接口:"+requestEntity+"");
|
||||
// ResponseEntity<String> responseEntity = restTemplate.postForEntity(apiUrl, requestEntity, String.class, new Object[0]);
|
||||
// log.info("删除完成,返回结果:responseEntity{}", responseEntity);
|
||||
// String jsonStr = (String)responseEntity.getBody();
|
||||
// log.info("删除完成,返回结果:{}", jsonStr);
|
||||
// return jsonStr;
|
||||
// }
|
||||
// private String pushZHAfter(Map<String, Object> params) {
|
||||
// log.info("已办待办到中环.....");
|
||||
// QFilter filter = new QFilter("number","=","004");
|
||||
// DynamicObject kd21_oa_matters = BusinessDataServiceHelper.loadSingle("kd21_oa_matters", "id,name,kd21_largetextfield", new QFilter[]{filter});
|
||||
// String kd21_largetextfield = kd21_oa_matters.getString("kd21_largetextfield");
|
||||
//// String kd21_largetextfield = "/rest/ofs/deleteUserRequestInfoByJson";
|
||||
// String apiUrl = kd21_largetextfield;//获取接口的地址
|
||||
// log.info("已办接口地址:"+apiUrl+"");
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// String jsonBody = JSON.toJSONString(params);
|
||||
// HttpEntity<String> requestEntity = new HttpEntity(jsonBody, headers);
|
||||
// log.info("已办接口:"+requestEntity+"");
|
||||
// ResponseEntity<String> responseEntity = restTemplate.postForEntity(apiUrl, requestEntity, String.class, new Object[0]);
|
||||
// log.info("已办完成,返回结果:responseEntity{}", responseEntity);
|
||||
// String jsonStr = (String)responseEntity.getBody();
|
||||
// log.info("已办完成,返回结果:{}", jsonStr);
|
||||
// return jsonStr;
|
||||
// }
|
||||
//}
|
||||
private String pushZHData(Map<String, Object> params) {
|
||||
// log.info("推送消息到中环.....");
|
||||
// QFilter filter = new QFilter("number", "=", "001");
|
||||
// DynamicObject kd21_oa_matters = BusinessDataServiceHelper.loadSingle("kd21_oa_matters", "id,name,kd21_largetextfield", new QFilter[] { filter });
|
||||
// String kd21_largetextfield = kd21_oa_matters.getString("kd21_largetextfield");
|
||||
// String apiUrl = kd21_largetextfield;
|
||||
//// String apiUrl = "http://oatest.zhonghuangroup.com:8081/rest/ofs/ReceiveRequestInfoByJson";
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
// String jsonBody = JSON.toJSONString(params);
|
||||
// HttpEntity<String> requestEntity = new HttpEntity(jsonBody, headers);
|
||||
// ResponseEntity<String> responseEntity = restTemplate.postForEntity(apiUrl, requestEntity, String.class, new Object[0]);
|
||||
// String jsonStr = (String)responseEntity.getBody();
|
||||
// log.info("{已办完成}", jsonStr);
|
||||
|
||||
log.info("推送消息到中环.....");
|
||||
QFilter filter = new QFilter("number", "=", "001");
|
||||
DynamicObject kd21_oa_matters = BusinessDataServiceHelper.loadSingle("kd21_oa_matters", "id,name,kd21_largetextfield", new QFilter[]{filter});
|
||||
String kd21_largetextfield = kd21_oa_matters.getString("kd21_largetextfield");
|
||||
String apiUrl = kd21_largetextfield;
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
String jsonBody = JSON.toJSONString(params);
|
||||
HttpEntity<String> requestEntity = new HttpEntity(jsonBody, headers);
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity(apiUrl, requestEntity, String.class, new Object[0]);
|
||||
String jsonStr = (String) responseEntity.getBody();
|
||||
log.info("{已办完成}", jsonStr);
|
||||
return jsonStr;
|
||||
}
|
||||
|
||||
|
||||
// private String pushZHMessage(Map<String, Object> params) {
|
||||
// log.info("推送待办到中环....." + params);
|
||||
// QFilter filter = new QFilter("number", "=", "002");
|
||||
// DynamicObject kd21_oa_matters = BusinessDataServiceHelper.loadSingle("kd21_oa_matters", "id,name,kd21_largetextfield", new QFilter[]{filter});
|
||||
// String kd21_largetextfield = kd21_oa_matters.getString("kd21_largetextfield");
|
||||
// String apiUrl = kd21_largetextfield;
|
||||
// Map map = new HashMap<String, String>();
|
||||
// log.info("接口地址" + apiUrl);
|
||||
// String jsonBody = JSON.toJSONString(params);
|
||||
// log.info("jsonBody" + jsonBody);
|
||||
// Map<String, String> js = new Gson().fromJson(jsonBody, map.getClass());
|
||||
// String post = post(apiUrl, js, js);
|
||||
// log.info("推送完成,返回结果:{}", post);
|
||||
//
|
||||
// return post;
|
||||
// }
|
||||
|
||||
|
||||
public static String post(String path, Map<String, String> params, Map<String, String> data) {
|
||||
try {
|
||||
String str = "";
|
||||
// if (params != null) {
|
||||
// StringBuilder stringBuilder = new StringBuilder("?");
|
||||
// for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
// stringBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
||||
// }
|
||||
// if (stringBuilder.length() > 1)
|
||||
// path += stringBuilder.substring(0, stringBuilder.length() - 1);
|
||||
// }
|
||||
URL url = new URL(path);
|
||||
//打开和url之间的连接
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
// PrintWriter out = null;
|
||||
// 请求参数 编码为 utf-8
|
||||
//请求方式
|
||||
conn.setRequestMethod("POST");
|
||||
//设置通用的请求属性
|
||||
conn.setRequestProperty("accept", "*/*");
|
||||
conn.setRequestProperty("connection", "Keep-Alive");
|
||||
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
|
||||
if (data != null)
|
||||
for (Map.Entry<String, String> entry : data.entrySet())
|
||||
conn.setRequestProperty(entry.getKey(), entry.getValue());
|
||||
//设置是否向httpUrlConnection输出,设置是否从httpUrlConnection读入,此外发送post请求必须设置这两个
|
||||
//最常用的Http请求无非是get和post,get请求可以获取静态页面,也可以把参数放在URL字串后面,传递给servlet,
|
||||
//post与get的 不同之处在于post的参数不是放在URL字串里面,而是放在http请求的正文内。
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8");
|
||||
if (params != null)
|
||||
out.write(mapToStr(params));
|
||||
//缓冲数据
|
||||
out.flush();
|
||||
out.close();
|
||||
//获取URLConnection对象对应的输入流
|
||||
InputStream is = conn.getInputStream();
|
||||
//构造一个字符流缓存
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
|
||||
String result = "";
|
||||
while ((str = br.readLine()) != null) {
|
||||
result = str;
|
||||
}
|
||||
//关闭流
|
||||
is.close();
|
||||
//断开连接,最好写上,disconnect是在底层tcp socket链接空闲时才切断。如果正在被其他线程使用就不切断。
|
||||
//固定多线程的话,如果不disconnect,链接会增多,直到收发不出信息。写上disconnect后正常一些。
|
||||
conn.disconnect();
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Map转换成字符串参数,用于POST GET 请求
|
||||
*
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
public static String mapToStr(Map<String, String> map) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (map != null) {
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
stringBuilder.append(entry.getKey());
|
||||
if (entry.getValue() != null)
|
||||
stringBuilder.append("=").append(entry.getValue());
|
||||
stringBuilder.append("&");
|
||||
}
|
||||
}
|
||||
if (stringBuilder.length() > 0)
|
||||
return stringBuilder.substring(0, stringBuilder.length() - 1);
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue