2024-11-09 02:35:26 +00:00
|
|
|
|
package shkd.todotask;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
import kd.bos.logging.Log;
|
|
|
|
|
import kd.bos.logging.LogFactory;
|
|
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
|
import kd.bos.util.StringUtils;
|
|
|
|
|
import kd.bos.workflow.engine.impl.persistence.entity.operationlog.OperationLogEntity;
|
|
|
|
|
import kd.bos.workflow.engine.msg.AbstractMessageServiceHandler;
|
|
|
|
|
import kd.bos.workflow.engine.msg.ctx.MessageContext;
|
2024-11-13 10:35:26 +00:00
|
|
|
|
import kd.bos.workflow.engine.msg.info.MessageInfo;
|
2024-11-09 02:35:26 +00:00
|
|
|
|
import kd.bos.workflow.engine.msg.info.ToDoInfo;
|
|
|
|
|
import kd.bos.workflow.service.WorkflowService;
|
|
|
|
|
import kd.bos.workflow.service.impl.ServiceFactory;
|
|
|
|
|
import shkd.utils.OAUtils;
|
|
|
|
|
|
2024-11-11 06:15:10 +00:00
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.URLEncoder;
|
2024-11-09 02:35:26 +00:00
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import static shkd.utils.OAUtils.*;
|
|
|
|
|
|
2024-11-19 02:36:33 +00:00
|
|
|
|
public class todoZyTaskServiceHandler extends AbstractMessageServiceHandler {
|
2024-11-09 02:35:26 +00:00
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(todoZyTaskServiceHandler.class);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过人员id获取人员信息
|
2024-11-19 02:36:33 +00:00
|
|
|
|
*
|
|
|
|
|
* @param userIds 人员id集合
|
2024-11-09 02:35:26 +00:00
|
|
|
|
* @param approvers 人员信息集合
|
|
|
|
|
*/
|
2024-11-19 02:36:33 +00:00
|
|
|
|
private List<DynamicObject> getApprovers(List<Long> userIds, List<DynamicObject> approvers) {
|
2024-11-09 02:35:26 +00:00
|
|
|
|
for (Long userId : userIds) {
|
|
|
|
|
DynamicObject user = BusinessDataServiceHelper.loadSingle(userId, "bos_user");
|
|
|
|
|
approvers.add(user);
|
|
|
|
|
}
|
|
|
|
|
return approvers;
|
|
|
|
|
}
|
2024-11-19 02:36:33 +00:00
|
|
|
|
|
2024-11-09 02:35:26 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void createToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
|
|
|
|
|
System.out.println("createToDo");
|
|
|
|
|
|
|
|
|
|
//获取流程实例ID
|
|
|
|
|
Long processInstanceId = messageContext.getProcessInstanceId();
|
|
|
|
|
//获取任务步骤
|
|
|
|
|
Long executionId = messageContext.getExecutionId(); // 节点ID
|
|
|
|
|
//获取当前任务ID
|
|
|
|
|
Long taskId = messageContext.getTaskId();
|
|
|
|
|
//获取单据编码
|
|
|
|
|
String billNo = messageContext.getBillNo();
|
|
|
|
|
//获取审批人集合
|
|
|
|
|
List<DynamicObject> approvers = new ArrayList<>();
|
|
|
|
|
List<Long> userIds = toDoInfo.getUserIds(); // 审批人ID集合
|
|
|
|
|
List<DynamicObject> approversLists = getApprovers(userIds, approvers);
|
|
|
|
|
//获取任务标题
|
|
|
|
|
Map<String, Object> params = toDoInfo.getParams();
|
|
|
|
|
String subjectJson = (String) params.get("subject");
|
|
|
|
|
JSONObject subjectObj = JSONObject.parseObject(subjectJson);
|
|
|
|
|
String title = subjectObj.getString("zh_CN");
|
|
|
|
|
// 节点名称
|
|
|
|
|
String executionName = "";
|
|
|
|
|
DynamicObject execution = BusinessDataServiceHelper.loadSingle(executionId, "wf_execution");
|
2024-11-19 02:36:33 +00:00
|
|
|
|
if (execution != null) {
|
2024-11-09 02:35:26 +00:00
|
|
|
|
executionName = execution.getString("activityname");// 节点名称
|
|
|
|
|
}
|
|
|
|
|
//获取Url
|
|
|
|
|
String url = toDoInfo.getUrl(); // 链接
|
2024-11-13 10:35:26 +00:00
|
|
|
|
String url1 = toDoInfo.getUrl(); // 链接
|
2024-11-11 06:15:10 +00:00
|
|
|
|
try {
|
|
|
|
|
url = URLEncoder.encode(url, "UTF-8");
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
url = "http://172.31.254.240:9090/seeyon/isc.do?method=ssoISC&toUrl=" + url;
|
|
|
|
|
|
|
|
|
|
|
2024-11-09 02:35:26 +00:00
|
|
|
|
//获取任务创建人
|
|
|
|
|
Long startUserId = messageContext.getStartUserId(); // 审批实例发起人id
|
|
|
|
|
DynamicObject startUser = BusinessDataServiceHelper.loadSingle(startUserId, "bos_user");
|
|
|
|
|
String startNumber = "";
|
|
|
|
|
String startName = "";
|
|
|
|
|
if (null != startUser) {
|
|
|
|
|
startNumber = startUser.getString("number");
|
|
|
|
|
startName = startUser.getString("name");
|
|
|
|
|
if (!userIds.contains(startUserId)) {
|
|
|
|
|
approversLists.add(startUser);//添加发起人到审批人集合_便于后续接口调用(用户绑定接口)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//待办创建时间(格式:yyyy-MM-dd HH:mm:ss)
|
|
|
|
|
Date createDate = messageContext.getCreateDate();
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
String createDateStr = sdf.format(createDate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取token
|
|
|
|
|
String oaToken = OAUtils.getOaToken(billNo);
|
|
|
|
|
if (StringUtils.isNotEmpty(oaToken)) {
|
|
|
|
|
|
|
|
|
|
//todo OA人员绑定接口
|
2024-11-19 02:36:33 +00:00
|
|
|
|
thirdpartyUser(approversLists, oaToken, billNo);
|
2024-11-09 02:35:26 +00:00
|
|
|
|
|
|
|
|
|
HashMap<String, Object> thirdPartyMap = new HashMap<>();
|
2024-11-19 02:36:33 +00:00
|
|
|
|
thirdPartyMap.put("oaToken", oaToken);
|
|
|
|
|
thirdPartyMap.put("approversLists", approversLists);
|
|
|
|
|
thirdPartyMap.put("taskId", taskId);
|
|
|
|
|
thirdPartyMap.put("title", title);
|
|
|
|
|
thirdPartyMap.put("startName", startName);
|
|
|
|
|
thirdPartyMap.put("createDateStr", createDateStr);
|
|
|
|
|
thirdPartyMap.put("url", url);
|
|
|
|
|
thirdPartyMap.put("url1", url1);
|
|
|
|
|
thirdPartyMap.put("billNo", billNo);
|
|
|
|
|
thirdPartyMap.put("startNumber", startNumber);//发起人
|
2024-11-09 02:35:26 +00:00
|
|
|
|
|
|
|
|
|
//推送OA待办新增接口
|
|
|
|
|
thirdParty(thirdPartyMap);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
System.out.println("createToDo");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void dealToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
|
|
|
|
|
//select * from t_wf_operationlog where fbillno = '测试:待办推送致远(1106-1915)'
|
|
|
|
|
//todo 待办推送第三方,节点审批通过或者驳回到某节点时都会进入(dealToDo)方法,代码如何判断该节点是驳回还是审批通过
|
|
|
|
|
//获取当前任务ID
|
|
|
|
|
Long taskId = messageContext.getTaskId();
|
2024-11-13 10:35:26 +00:00
|
|
|
|
//获取任务步骤
|
|
|
|
|
Long executionId = messageContext.getExecutionId();
|
|
|
|
|
List<OperationLogEntity> operationLogByTaskId = ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId);
|
|
|
|
|
String decisionType = "";
|
|
|
|
|
if (operationLogByTaskId.size() > 0) {
|
|
|
|
|
decisionType = ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId).get(0).getDecisionType();
|
2024-11-19 02:36:33 +00:00
|
|
|
|
} else {
|
2024-11-13 10:35:26 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-11-09 02:35:26 +00:00
|
|
|
|
|
2024-11-13 10:35:26 +00:00
|
|
|
|
String subState = "0";
|
2024-11-09 02:35:26 +00:00
|
|
|
|
//驳回
|
2024-11-19 02:36:33 +00:00
|
|
|
|
if ("reject".equals(decisionType)) {
|
2024-11-09 02:35:26 +00:00
|
|
|
|
subState = "3";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取流程实例ID
|
|
|
|
|
Long processInstanceId = messageContext.getProcessInstanceId();
|
|
|
|
|
|
|
|
|
|
//获取单据编码
|
|
|
|
|
String billNo = messageContext.getBillNo();
|
|
|
|
|
|
|
|
|
|
//获取token
|
|
|
|
|
String oaToken = OAUtils.getOaToken(billNo);
|
|
|
|
|
if (StringUtils.isNotEmpty(oaToken)) {
|
|
|
|
|
|
|
|
|
|
HashMap<String, Object> updateStateMap = new HashMap<>();
|
2024-11-19 02:36:33 +00:00
|
|
|
|
updateStateMap.put("oaToken", oaToken);
|
|
|
|
|
updateStateMap.put("taskId", taskId);
|
|
|
|
|
updateStateMap.put("state", "1");
|
|
|
|
|
updateStateMap.put("subState", subState);
|
|
|
|
|
updateStateMap.put("billNo", billNo);
|
2024-11-09 02:35:26 +00:00
|
|
|
|
|
|
|
|
|
//推送OA待办变更接口
|
|
|
|
|
updatePendingState(updateStateMap);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
System.out.println("createToDo");
|
|
|
|
|
System.out.println("createToDo");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
|
|
|
|
|
|
|
|
|
|
//获取流程实例ID
|
|
|
|
|
Long processInstanceId = messageContext.getProcessInstanceId();
|
|
|
|
|
//获取任务步骤
|
|
|
|
|
Long executionId = messageContext.getExecutionId(); // 节点ID
|
|
|
|
|
//获取当前任务ID
|
|
|
|
|
Long taskId = messageContext.getTaskId();
|
|
|
|
|
|
|
|
|
|
String decisionType = ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId).get(0).getDecisionType();
|
2024-11-13 10:35:26 +00:00
|
|
|
|
String subState = "3";
|
|
|
|
|
// //单据撤销
|
|
|
|
|
// if("reject".equals(decisionType)){
|
|
|
|
|
// subState = "2";
|
|
|
|
|
// }
|
|
|
|
|
// //终止流程
|
|
|
|
|
// else if ("approve".equals(decisionType)) {
|
|
|
|
|
// subState = "3";
|
|
|
|
|
// }
|
2024-11-09 02:35:26 +00:00
|
|
|
|
|
|
|
|
|
//获取单据编码
|
|
|
|
|
String billNo = messageContext.getBillNo();
|
|
|
|
|
|
|
|
|
|
//获取token
|
|
|
|
|
String oaToken = OAUtils.getOaToken(billNo);
|
|
|
|
|
if (StringUtils.isNotEmpty(oaToken)) {
|
|
|
|
|
|
|
|
|
|
HashMap<String, Object> updateStateMap = new HashMap<>();
|
2024-11-19 02:36:33 +00:00
|
|
|
|
updateStateMap.put("oaToken", oaToken);
|
|
|
|
|
updateStateMap.put("taskId", taskId);
|
|
|
|
|
updateStateMap.put("state", "1");
|
|
|
|
|
updateStateMap.put("subState", subState);
|
|
|
|
|
updateStateMap.put("billNo", billNo);
|
2024-11-09 02:35:26 +00:00
|
|
|
|
|
|
|
|
|
//推送OA待办变更接口
|
|
|
|
|
updatePendingState(updateStateMap);
|
|
|
|
|
|
|
|
|
|
}
|
2024-11-13 10:35:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void sendMessage(MessageContext messageContext, MessageInfo message) {
|
|
|
|
|
super.sendMessage(messageContext, message);
|
2024-11-19 02:36:33 +00:00
|
|
|
|
//https://developer.kingdee.com/article/195641480978054400?productLineId=29&lang=zh-CN
|
|
|
|
|
//JSONObject.parseObject(String.valueOf(message.getParams().get("messageContext")));
|
|
|
|
|
|
|
|
|
|
Map<String, Object> params = message.getParams();
|
|
|
|
|
String billNo = "";
|
|
|
|
|
Long taskId = 0L;
|
|
|
|
|
if (params != null) {
|
|
|
|
|
String messagContext = String.valueOf(params.get("messageContext"));
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(messagContext);
|
|
|
|
|
if (null != jsonObject) {
|
|
|
|
|
billNo = jsonObject.getString("billNo");//获取单据编码
|
|
|
|
|
taskId = jsonObject.getLong("taskId");//获取当前任务ID
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-13 10:35:26 +00:00
|
|
|
|
//消息内容
|
|
|
|
|
String content = message.getContent();
|
|
|
|
|
//消息时间
|
2024-11-16 03:05:06 +00:00
|
|
|
|
// Date createDate = messageContext.getCreateDate();
|
|
|
|
|
// Date createDate = new Date();
|
|
|
|
|
Date createDate = message.getSendTime();
|
2024-11-13 10:35:26 +00:00
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
String createDateStr = sdf.format(createDate);
|
2024-11-19 02:36:33 +00:00
|
|
|
|
|
2024-11-16 03:05:06 +00:00
|
|
|
|
|
2024-11-13 10:35:26 +00:00
|
|
|
|
//获取审批人集合
|
|
|
|
|
List<DynamicObject> approvers = new ArrayList<>();
|
|
|
|
|
List<Long> userIds = message.getUserIds(); // 审批人ID集合
|
|
|
|
|
List<DynamicObject> approversLists = getApprovers(userIds, approvers);
|
2024-11-16 03:05:06 +00:00
|
|
|
|
//获取任务创建人 // 信息发送人
|
2024-11-20 02:20:27 +00:00
|
|
|
|
// ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId).get(0).getDecisionType();
|
|
|
|
|
Long startUserId = ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId).get(0).getOwnerId();
|
|
|
|
|
// Long startUserId = message.getSenderId();
|
2024-11-16 03:05:06 +00:00
|
|
|
|
// Long startUserId = messageContext.getStartUserId(); // 审批实例发起人id
|
2024-11-13 10:35:26 +00:00
|
|
|
|
String startNumber = "";
|
|
|
|
|
String startName = "";
|
2024-11-16 04:15:46 +00:00
|
|
|
|
if (null != startUserId) {
|
|
|
|
|
DynamicObject startUser = BusinessDataServiceHelper.loadSingle(startUserId, "bos_user");
|
|
|
|
|
if (null != startUser) {
|
|
|
|
|
startNumber = startUser.getString("number");
|
|
|
|
|
startName = startUser.getString("name");
|
|
|
|
|
if (!userIds.contains(startUserId)) {
|
|
|
|
|
approversLists.add(startUser);//添加发起人到审批人集合_便于后续接口调用(用户绑定接口)
|
|
|
|
|
}
|
2024-11-13 10:35:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//获取Url
|
|
|
|
|
String url = message.getContentUrl(); // 链接
|
|
|
|
|
String url1 = message.getContentUrl(); // 链接
|
|
|
|
|
try {
|
|
|
|
|
url = URLEncoder.encode(url, "UTF-8");
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
url = "http://172.31.254.240:9090/seeyon/isc.do?method=ssoISC&toUrl=" + url;
|
|
|
|
|
|
|
|
|
|
//获取token
|
|
|
|
|
String oaToken = OAUtils.getOaToken(billNo);
|
|
|
|
|
if (StringUtils.isNotEmpty(oaToken)) {
|
|
|
|
|
|
|
|
|
|
HashMap<String, Object> thirdPartyMap = new HashMap<>();
|
2024-11-19 02:36:33 +00:00
|
|
|
|
thirdPartyMap.put("oaToken", oaToken);
|
|
|
|
|
thirdPartyMap.put("approversLists", approversLists);
|
|
|
|
|
thirdPartyMap.put("taskId", taskId);
|
|
|
|
|
thirdPartyMap.put("content", content);
|
|
|
|
|
thirdPartyMap.put("createDateStr", createDateStr);
|
|
|
|
|
thirdPartyMap.put("url", url);
|
|
|
|
|
thirdPartyMap.put("url1", url1);
|
|
|
|
|
thirdPartyMap.put("billNo", billNo);
|
|
|
|
|
thirdPartyMap.put("startNumber", startNumber);//发起人
|
2024-11-13 10:35:26 +00:00
|
|
|
|
|
2024-11-16 03:08:02 +00:00
|
|
|
|
//推送OA消息新增接口
|
2024-11-13 10:35:26 +00:00
|
|
|
|
thirdpartyMessage(thirdPartyMap);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-11-09 02:35:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|