|
|
@@ -25,6 +25,8 @@ import com.kingdee.eas.basedata.person.IPerson;
|
|
|
import com.kingdee.eas.basedata.person.PersonFactory;
|
|
|
import com.kingdee.eas.basedata.person.PersonInfo;
|
|
|
import com.kingdee.eas.common.EASBizException;
|
|
|
+import com.kingdee.eas.util.app.DbUtil;
|
|
|
+import com.kingdee.jdbc.rowset.IRowSet;
|
|
|
import okhttp3.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.log4j.Logger;
|
|
|
@@ -73,8 +75,22 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean addMessage(WSMessage message) {
|
|
|
- logger.error("*********OAMessageWebServiceDao addMessage 消息监听开始**********");
|
|
|
- return sendMessage(message, "0", "0", null);
|
|
|
+ try {
|
|
|
+ logger.error("*********OAMessageWebServiceDao addMessage 消息监听开始**********");
|
|
|
+ boolean result = sendMessage(message, "0", "0", null);
|
|
|
+ Context ctx = message.getContext();
|
|
|
+ String msgID = message.getMsgID();
|
|
|
+ IAssignRead assignReadIns = AssignReadFactory.getLocalInstance(ctx);
|
|
|
+ AssignReadInfo assignReadInfo = assignReadIns.getAssignReadInfo(new ObjectUuidPK(msgID));
|
|
|
+ String assignId = assignReadInfo.getAssignID().toString();
|
|
|
+ String billId = message.getBillId();
|
|
|
+ String workflowname = getFlowTypeNameyBillId(ctx, msgID, billId, assignId);
|
|
|
+ addMsgId(ctx, msgID, assignId, billId, workflowname);
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -155,11 +171,12 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
String bosType = bosId.getType().toString();
|
|
|
logger.error("*********OAMessageWebServiceDao bosType " + bosType);
|
|
|
if ("9623EB51".equals(bosType)) {
|
|
|
+ String assignID = "";
|
|
|
try {
|
|
|
//任务阅读表
|
|
|
IAssignRead assignReadIns = AssignReadFactory.getLocalInstance(ctx);
|
|
|
AssignReadInfo assignReadInfo = assignReadIns.getAssignReadInfo(new ObjectUuidPK(id));
|
|
|
- String assignID = assignReadInfo.getAssignID().toString();
|
|
|
+ assignID = assignReadInfo.getAssignID().toString();
|
|
|
IAssign iAssign = AssignFactory.getLocalInstance(ctx);
|
|
|
IPerson iPerson = PersonFactory.getLocalInstance(ctx);
|
|
|
AssignInfo assignInfo = iAssign.getValue(new ObjectUuidPK(assignID));
|
|
|
@@ -207,10 +224,15 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean addCompletedMessage(WfrAssignMessage wfrAssignMessage) {
|
|
|
+ String msgId = "";
|
|
|
+ Context ctx = wfrAssignMessage.getCtx();
|
|
|
+ //工作流实列
|
|
|
+ String procInstId = wfrAssignMessage.getProcInstId();
|
|
|
+ String assignId = wfrAssignMessage.getAssignId();
|
|
|
try {
|
|
|
logger.error("*********OAMessageWebServiceDao addCompletedMessage 消息监听开始**********");
|
|
|
- String assignId = wfrAssignMessage.getAssignId();
|
|
|
logger.error("*********OAMessageWebServiceDao assignId " + assignId);
|
|
|
+ System.out.println("procInstId: " + procInstId);
|
|
|
String assignSubject = wfrAssignMessage.getAssignSubject();
|
|
|
String billID = wfrAssignMessage.getBillID();
|
|
|
String handler = wfrAssignMessage.getHandler();
|
|
|
@@ -218,14 +240,13 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
String state = wfrAssignMessage.getState();
|
|
|
logger.error("*********OAMessageWebServiceDao state " + state);
|
|
|
WfAssignmentState stateEnum = WfAssignmentState.getEnum(state);
|
|
|
- Context ctx = wfrAssignMessage.getCtx();
|
|
|
IAssignRead iAssignRead = AssignReadFactory.getLocalInstance(ctx);
|
|
|
AssignReadCollection assignReadCollection = iAssignRead.getAssignReadCollection("where assignID='" + assignId + "'");
|
|
|
- String msgId = null;
|
|
|
if (assignReadCollection.size() > 0) {
|
|
|
msgId = assignReadCollection.get(0).getId().toString();
|
|
|
} else {
|
|
|
- throw new RuntimeException("未找到对应的任务阅读表 assignId: " + assignId);
|
|
|
+ //throw new RuntimeException("未找到对应的任务阅读表 assignId: " + assignId);
|
|
|
+ msgId = getMsgId(ctx, assignId);
|
|
|
}
|
|
|
if (WfAssignmentState.COMPLETED.equals(stateEnum)
|
|
|
|| WfAssignmentState.REJECTED.equals(stateEnum)
|
|
|
@@ -243,7 +264,7 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
wsMessage.setRecieverID(wfrAssignMessage.getHandlerId());
|
|
|
return sendMessage(wsMessage, "2", "1", assignId);
|
|
|
}
|
|
|
- } catch (BOSException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return false;
|
|
|
@@ -257,19 +278,22 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
*/
|
|
|
private boolean sendMessage(WSMessage message, String isremark, String viewtype, String assignId) {
|
|
|
Context ctx = message.getContext();
|
|
|
+ String msgID = message.getMsgID();
|
|
|
+ String billId = null;
|
|
|
+ String receiveOAPath = prop.getProperty("receiveOAPath");
|
|
|
+ JSONObject params = null;
|
|
|
try {
|
|
|
String serverName = prop.getProperty("serverName");
|
|
|
- String receiveOAPath = prop.getProperty("receiveOAPath");
|
|
|
if (StringUtils.isEmpty(receiveOAPath)) {
|
|
|
- throw new RuntimeException("发送OA待办消息,推送异步消息地址不能为空! 请检查配置文件: " + propPath);
|
|
|
+ throw new BOSException("发送OA待办消息,推送异步消息地址不能为空! 请检查配置文件: " + propPath);
|
|
|
}
|
|
|
- JSONObject params = new JSONObject();
|
|
|
+ params = new JSONObject();
|
|
|
String syscode = prop.getProperty("syscode", "SHR");
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
Date date = new Date();
|
|
|
String now = sdf.format(date);
|
|
|
params.put("syscode", syscode);//异构系统标识
|
|
|
- params.put("flowid", message.getMsgID());//流程实例id
|
|
|
+ params.put("flowid", msgID);//流程实例id
|
|
|
//业务类型
|
|
|
MsgBizType bizType = message.getBizType();
|
|
|
if (MsgBizType.URGENT.equals(bizType)) {
|
|
|
@@ -278,13 +302,9 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
} else {
|
|
|
params.put("requestname", message.getTitle());//标题
|
|
|
}
|
|
|
- String billId = message.getBillId();
|
|
|
+ billId = message.getBillId();
|
|
|
logger.error("billId: " + billId);
|
|
|
//MsgType type = message.getType();
|
|
|
- String workflowname = getFlowTypeNameyBillId(ctx, message.getMsgID(), billId, assignId);
|
|
|
- params.put("workflowname", workflowname);//流程类型名称
|
|
|
- params.put("pcurl", getPcUrl(ctx, serverName, message, bizType, assignId));//PC地址(相对路径/开头)
|
|
|
- params.put("appurl", getAppUrl(ctx, serverName, message, bizType, assignId));//APP地址(相对路径/开头)
|
|
|
params.put("nodename", "sHR");//步骤名称(节点名称)
|
|
|
params.put("isremark", isremark);//流程处理状态
|
|
|
params.put("viewtype", viewtype);//流程查看状态
|
|
|
@@ -294,6 +314,13 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
params.put("receivedatetime", now);//接收日期时间
|
|
|
//时间戳字段,客户端使用线程调用接口的时候,根据此字段判断是否需要更新数据,防止后发的请求数据被之前的覆盖
|
|
|
params.put("receivets", String.valueOf(date.getTime()));
|
|
|
+ if (StringUtils.isBlank(msgID)) {
|
|
|
+ throw new BOSException("msgID为空!");
|
|
|
+ }
|
|
|
+ params.put("pcurl", getPcUrl(ctx, serverName, message, bizType, assignId));//PC地址(相对路径/开头)
|
|
|
+ params.put("appurl", getAppUrl(ctx, serverName, message, bizType, assignId));//APP地址(相对路径/开头)
|
|
|
+ String workflowname = getFlowTypeNameyBillId(ctx, msgID, billId, assignId);
|
|
|
+ params.put("workflowname", workflowname);//流程类型名称
|
|
|
logger.error("addMessage -> params: " + params);
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
@@ -310,15 +337,23 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
String operResult = jsonObject.getString("operResult");
|
|
|
if ("1".equals(operResult)) {
|
|
|
+ addOAMsgCallLog(ctx, msgID, assignId, billId, receiveOAPath, params.toJSONString(), result, 1, "成功");
|
|
|
return true;
|
|
|
} else {
|
|
|
logger.error(jsonObject.getString("message"));
|
|
|
+ throw new BOSException(jsonObject.getString("message"));
|
|
|
}
|
|
|
} else {
|
|
|
logger.error("发送OA待办消息 超时");
|
|
|
+ throw new BOSException("发送OA待办消息 超时");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ String paramsStr = null;
|
|
|
+ if (params != null) {
|
|
|
+ paramsStr = params.toString();
|
|
|
+ }
|
|
|
+ addOAMsgCallLog(ctx, msgID, assignId, billId, receiveOAPath, paramsStr, "", 0, e.getMessage());
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
@@ -476,6 +511,7 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
|
|
|
/**
|
|
|
* 根据单据id获取流程单据类型名称
|
|
|
+ *
|
|
|
* @param ctx
|
|
|
* @param msgId
|
|
|
* @param billId
|
|
|
@@ -512,4 +548,94 @@ public class OAMessageWebServiceDao implements MessageWebServiceDao {
|
|
|
}
|
|
|
return flowTypeName;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取消息阅读表id
|
|
|
+ * 流程撤销时,阅读表数据会先删除,然后再进addCompletedMessage方法,由于msgId作为OA待办消息的唯一标识
|
|
|
+ *
|
|
|
+ * @param ctx
|
|
|
+ * @param assignID
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getMsgId(
|
|
|
+ Context ctx,
|
|
|
+ String assignID) {
|
|
|
+ String msgId = "";
|
|
|
+ try {
|
|
|
+ String sql = "select MsgId from assignReadRecord where assignID = ?";
|
|
|
+ IRowSet iRowSet = DbUtil.executeQuery(ctx, sql, new Object[]{assignID});
|
|
|
+ while (iRowSet.next()) {
|
|
|
+ msgId = iRowSet.getString("MsgId");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e);
|
|
|
+ }
|
|
|
+ return msgId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写入消息阅读表Id
|
|
|
+ *
|
|
|
+ * @param ctx
|
|
|
+ * @param assignID
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void addMsgId(
|
|
|
+ Context ctx,
|
|
|
+ String msgId,
|
|
|
+ String assignID,
|
|
|
+ String billId,
|
|
|
+ String workflowname) {
|
|
|
+ try {
|
|
|
+ String insertSql = "insert into assignReadRecord(MsgId,assignID,billId,workflowname) values(?,?,?,?)";
|
|
|
+ DbUtil.execute(ctx, insertSql, new Object[]{
|
|
|
+ getStringOrDefault(msgId),
|
|
|
+ getStringOrDefault(assignID),
|
|
|
+ getStringOrDefault(billId),
|
|
|
+ getStringOrDefault(workflowname)});
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写入待办消息记录表
|
|
|
+ *
|
|
|
+ * @param ctx
|
|
|
+ * @param assignID
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private void addOAMsgCallLog(
|
|
|
+ Context ctx,
|
|
|
+ String msgId,
|
|
|
+ String assignID,
|
|
|
+ String billId,
|
|
|
+ String requestUrl,
|
|
|
+ String requestParams,
|
|
|
+ String responseResult,
|
|
|
+ int statusCode,
|
|
|
+ String message) {
|
|
|
+ try {
|
|
|
+ String insertSql = "insert into OAMsgCallLog(MsgId,assignID,billId,RequestUrl,RequestParams,ResponseResult,StatusCode,Message) values(?,?,?,?,?,?,?,?)";
|
|
|
+ DbUtil.execute(ctx, insertSql, new Object[]{
|
|
|
+ getStringOrDefault(msgId),
|
|
|
+ getStringOrDefault(assignID),
|
|
|
+ getStringOrDefault(billId),
|
|
|
+ getStringOrDefault(requestUrl),
|
|
|
+ getStringOrDefault(requestParams),
|
|
|
+ getStringOrDefault(responseResult),
|
|
|
+ statusCode,
|
|
|
+ getStringOrDefault(message)});
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getStringOrDefault(String value) {
|
|
|
+ if (StringUtils.isBlank(value)) {
|
|
|
+ return "";
|
|
|
+ } else {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|