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.ToDoInfo; import kd.bos.workflow.service.WorkflowService; import kd.bos.workflow.service.impl.ServiceFactory; import shkd.utils.OAUtils; 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 getApprovers(List userIds,List 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 approvers = new ArrayList<>(); List userIds = toDoInfo.getUserIds(); // 审批人ID集合 List approversLists = getApprovers(userIds, approvers); //获取任务标题 Map 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(); // 链接 //获取任务创建人 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 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("billNo",billNo); //推送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(); // List operationLogByTaskId = ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId); String decisionType = ServiceFactory.getService(WorkflowService.class).getTaskService().getOperationLogByTaskId(taskId).get(0).getDecisionType(); String subState = ""; //驳回 if("reject".equals(decisionType)){ subState = "3"; } //审批通过 else if ("approve".equals(decisionType)) { subState = "0"; } //获取流程实例ID Long processInstanceId = messageContext.getProcessInstanceId(); //获取任务步骤 Long executionId = messageContext.getExecutionId(); // 节点ID //获取单据编码 String billNo = messageContext.getBillNo(); //获取token String oaToken = OAUtils.getOaToken(billNo); if (StringUtils.isNotEmpty(oaToken)) { HashMap 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 = ""; //单据撤销 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 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"); } }