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

209 lines
8.0 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.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(); // 链接
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("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<OperationLogEntity> 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<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 = "";
//单据撤销
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);
}
System.out.println("createToDo");
System.out.println("createToDo");
}
}