审批流程预测审批人提醒

This commit is contained in:
zhangzhiguo 2025-03-27 16:03:26 +08:00
parent 944ba17c7e
commit 483b2fc098
1 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,75 @@
package zcgj.zcdev.zcdev.fs.plugin.workflow;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.message.api.MessageChannels;
import kd.bos.metadata.dao.MetaCategory;
import kd.bos.metadata.dao.MetadataDao;
import kd.bos.metadata.form.FormMetadata;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.servicehelper.workflow.WorkflowServiceHelper;
import kd.bos.workflow.api.AgentExecution;
import kd.bos.workflow.engine.extitf.IWorkflowPlugin;
import kd.bos.workflow.engine.impl.persistence.entity.runtime.ExecutionEntityImpl;
import kd.bos.workflow.engine.precomputor.IPreComputorRecord;
import kd.bos.workflow.engine.precomputor.IPreComputorRecordItem;
import kd.bos.servicehelper.workflow.MessageCenterServiceHelper;
import kd.bos.workflow.engine.msg.info.MessageInfo;
import java.util.ArrayList;
import java.util.List;
import kd.bos.dataentity.entity.LocaleString;
/**
* 审批流程预测审批人提醒
*/
public class SendMessageWorkFlowPlugin implements IWorkflowPlugin {
@Override
public void notify(AgentExecution execution) {
String businessKey = execution.getBusinessKey();
String entityNumber = execution.getEntityNumber();
long processId = WorkflowServiceHelper.getProcessInstanceIdByBusinessKey(businessKey);
IPreComputorRecord record = WorkflowServiceHelper.getPreComputorRecord(processId);
List<IPreComputorRecordItem> recordItems = record.getPcrData();
List<Long> userIds = new ArrayList<>();
for (IPreComputorRecordItem recordItem : recordItems) {
List<String> nextNodeId = recordItem.getNextNodeId();
if (nextNodeId.size() > 0) {
//获取下一个节点的审核人
List<Long> assignee = recordItem.getAssignee();
if (assignee.size() > 0) {
for (Long userId : assignee) {
userIds.add(userId);
}
}
}
}
if (!userIds.isEmpty()) {
sendMessage(userIds,entityNumber);
}
IWorkflowPlugin.super.notify(execution);
}
public void sendMessage(List<Long> userIds,String entityNumber) {
String id = MetadataDao.getIdByNumber(entityNumber, MetaCategory.Form);
FormMetadata formMeta = (FormMetadata) MetadataDao.readRuntimeMeta(id, MetaCategory.Form);
//单据名称
String billName = formMeta.getName().getLocaleValue();
//messageinfo 使用工作流包下的对象
MessageInfo messageInfo = new MessageInfo();
messageInfo.setTitle(billName+"-审批提醒");
LocaleString localeString = new LocaleString();
localeString.setLocaleValue_zh_CN(billName+"待审批提醒");
messageInfo.setMessageContent(localeString);
messageInfo.setUserIds(userIds);
//messageInfo.setType(MessageInfo.TYPE_TASK);
messageInfo.setType(MessageInfo.TYPE_MESSAGE);
messageInfo.setTag(billName+"-审批提醒");
messageInfo.setEntityNumber(entityNumber);
messageInfo.setNotifyType(MessageChannels.MC.getNumber());
MessageCenterServiceHelper.sendMessage(messageInfo);
}
}