dobe_comic8/main/java/shkd/todotask/todoZyTaskServiceHandler.java

294 lines
12 KiB
Java
Raw Normal View History

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;
import kd.bos.workflow.engine.msg.info.MessageInfo;
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;
import java.text.SimpleDateFormat;
import java.util.*;
import static shkd.utils.OAUtils.*;
public class todoZyTaskServiceHandler extends AbstractMessageServiceHandler {
private static final Log logger = LogFactory.getLog(todoZyTaskServiceHandler.class);
/**
* 通过人员id获取人员信息
*
* @param userIds 人员id集合
* @param approvers 人员信息集合
*/
private List<DynamicObject> getApprovers(List<Long> userIds, List<DynamicObject> approvers) {
for (Long userId : userIds) {
DynamicObject user = BusinessDataServiceHelper.loadSingle(userId, "bos_user");
approvers.add(user);
}
return approvers;
}
@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");
if (execution != null) {
executionName = execution.getString("activityname");// 节点名称
}
//获取Url
String url = toDoInfo.getUrl(); // 链接
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;
//获取任务创建人
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人员绑定接口
thirdpartyUser(approversLists, oaToken, billNo);
HashMap<String, Object> thirdPartyMap = new HashMap<>();
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);//发起人
//推送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();
//获取任务步骤
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();
} else {
return;
}
String subState = "0";
//驳回
if ("reject".equals(decisionType)) {
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<>();
updateStateMap.put("oaToken", oaToken);
updateStateMap.put("taskId", taskId);
updateStateMap.put("state", "1");
updateStateMap.put("subState", subState);
updateStateMap.put("billNo", billNo);
//推送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();
String subState = "3";
// //单据撤销
// if("reject".equals(decisionType)){
// subState = "2";
// }
// //终止流程
// else if ("approve".equals(decisionType)) {
// subState = "3";
// }
//获取单据编码
String billNo = messageContext.getBillNo();
//获取token
String oaToken = OAUtils.getOaToken(billNo);
if (StringUtils.isNotEmpty(oaToken)) {
HashMap<String, Object> updateStateMap = new HashMap<>();
updateStateMap.put("oaToken", oaToken);
updateStateMap.put("taskId", taskId);
updateStateMap.put("state", "1");
updateStateMap.put("subState", subState);
updateStateMap.put("billNo", billNo);
//推送OA待办变更接口
updatePendingState(updateStateMap);
}
}
@Override
public void sendMessage(MessageContext messageContext, MessageInfo message) {
super.sendMessage(messageContext, message);
//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
}
}
//消息内容
String content = message.getContent();
//消息时间
2024-11-16 03:05:06 +00:00
// Date createDate = messageContext.getCreateDate();
// Date createDate = new Date();
Date createDate = message.getSendTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String createDateStr = sdf.format(createDate);
2024-11-16 03:05:06 +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
//获取任务创建人 // 信息发送人
// 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
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);//添加发起人到审批人集合_便于后续接口调用(用户绑定接口)
}
}
}
//获取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<>();
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-16 03:08:02 +00:00
//推送OA消息新增接口
thirdpartyMessage(thirdPartyMap);
}
}
}