提交 2a33e5bd 编写于 作者: tangyaolong's avatar tangyaolong

抄送实现

上级 61b5dcea
...@@ -5,17 +5,16 @@ import cn.ibizlab.core.workflow.extensions.domain.FlowUser; ...@@ -5,17 +5,16 @@ import cn.ibizlab.core.workflow.extensions.domain.FlowUser;
import cn.ibizlab.core.workflow.extensions.service.WFCoreService; import cn.ibizlab.core.workflow.extensions.service.WFCoreService;
import cn.ibizlab.core.workflow.extensions.service.WFModelService; import cn.ibizlab.core.workflow.extensions.service.WFModelService;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.client.IBZNotifyFeignClient;
import cn.ibizlab.util.service.RemoteService; import cn.ibizlab.util.service.RemoteService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.ExtensionAttribute;
import org.flowable.bpmn.model.ExtensionElement;
import org.flowable.bpmn.model.FormProperty; import org.flowable.bpmn.model.FormProperty;
import org.flowable.bpmn.model.UserTask; import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.api.delegate.event.*; import org.flowable.common.engine.api.delegate.event.AbstractFlowableEventListener;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType; import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventType;
import org.flowable.common.engine.impl.event.FlowableEntityEventImpl; import org.flowable.common.engine.impl.event.FlowableEntityEventImpl;
import org.flowable.engine.TaskService; import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.DelegateExecution;
...@@ -31,7 +30,9 @@ import org.flowable.task.service.impl.persistence.entity.TaskEntity; ...@@ -31,7 +30,9 @@ import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.context.expression.MapAccessor; import org.springframework.context.expression.MapAccessor;
import org.springframework.expression.*; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -319,6 +320,38 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener { ...@@ -319,6 +320,38 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
} }
} }
else if(evt instanceof FlowableActivityEventImpl) {
FlowableActivityEventImpl event = ((FlowableActivityEventImpl) evt);
FlowableEventType eventType = event.getType();
if (eventType == FlowableEngineEventType.ACTIVITY_COMPLETED && "userTask".equals(event.getActivityType())) {
if (event.getExecution().getCurrentFlowElement() instanceof UserTask) {
UserTask task = (UserTask) event.getExecution().getCurrentFlowElement();
List<Task> exTask = taskService.createTaskQuery().processInstanceId(event.getProcessInstanceId()).list();
String sendCopyTag = wfCoreService.getParam(task,"form","procfunc");
if(sendCopyTag.contains("sendcopy")){
// 从模板中读取抄送人名单
String sendCopyUserList = wfCoreService.getParam(task,"form","senduser");
if(StringUtils.isEmpty(sendCopyUserList)){
throw new BadRequestAlertException("获取节点抄送用户失败","","");
}
String userIds = wfCoreService.getGroupUsers(sendCopyUserList, event.getExecution());
TaskEntity sendCopyTask = null;
if(exTask.size()>0){
sendCopyTask = wfCoreService.createTask(exTask.get(0));
}
sendCopyTask.setId(UUID.randomUUID().toString().toLowerCase());
sendCopyTask.setScopeType("sendcopy");
taskService.saveTask(sendCopyTask);
// 生成待阅抄送给用户
if(!StringUtils.isEmpty(userIds)){
for (String userid : userIds.split(",")) {
taskService.addUserIdentityLink(sendCopyTask.getId(), userid, "sendcopy");
}
}
}
}
}
}
else if(evt instanceof FlowableActivityEventImpl) else if(evt instanceof FlowableActivityEventImpl)
{ {
FlowableActivityEventImpl event=((FlowableActivityEventImpl) evt); FlowableActivityEventImpl event=((FlowableActivityEventImpl) evt);
......
...@@ -34,7 +34,6 @@ import org.flowable.engine.history.HistoricProcessInstance; ...@@ -34,7 +34,6 @@ import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.history.ProcessInstanceHistoryLog; import org.flowable.engine.history.ProcessInstanceHistoryLog;
import org.flowable.engine.repository.Deployment; import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder; import org.flowable.engine.repository.DeploymentBuilder;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance; import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.task.Comment; import org.flowable.engine.task.Comment;
import org.flowable.identitylink.api.IdentityLink; import org.flowable.identitylink.api.IdentityLink;
...@@ -81,6 +80,8 @@ import java.security.Principal; ...@@ -81,6 +80,8 @@ import java.security.Principal;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@Service("wfCoreService") @Service("wfCoreService")
@Slf4j @Slf4j
...@@ -279,7 +280,6 @@ public class WFCoreService ...@@ -279,7 +280,6 @@ public class WFCoreService
taskMap.put(templateCode, listMap); taskMap.put(templateCode, listMap);
} }
} }
} }
/** /**
...@@ -1598,6 +1598,28 @@ public class WFCoreService ...@@ -1598,6 +1598,28 @@ public class WFCoreService
} }
return null; return null;
} }
/**
* 清除link已读完的task
* @param element
* @param property
* @param attribute
* @return
*/
public String removeTask(FlowElement element, String property, String attribute) {
List<ExtensionElement> formProps = element.getExtensionElements().get(property);
if (formProps == null) {
return null;
}
for (ExtensionElement prop : formProps) {
if (prop.getAttributes() == null)
return null;
Map<String, List<ExtensionAttribute>> attributes = prop.getAttributes();
if (attributes.containsKey(attribute)) {
return ObjectUtils.isEmpty(attributes.get(attribute)) ? null : String.valueOf(attributes.get(attribute).get(0).getValue());
}
}
return null;
}
/** /**
* 获取流程节点所有参数 * 获取流程节点所有参数
...@@ -1750,7 +1772,7 @@ public class WFCoreService ...@@ -1750,7 +1772,7 @@ public class WFCoreService
* @param sourceTask * @param sourceTask
* @return * @return
*/ */
protected TaskEntity createTask(Task sourceTask) { public TaskEntity createTask(Task sourceTask) {
TaskEntity task = null; TaskEntity task = null;
if (sourceTask != null) { if (sourceTask != null) {
//1.生成子任务 //1.生成子任务
...@@ -1896,6 +1918,7 @@ public class WFCoreService ...@@ -1896,6 +1918,7 @@ public class WFCoreService
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId); List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
identityLinks.forEach(idl->{ identityLinks.forEach(idl->{
if(userId.equals(idl.getUserId())){ if(userId.equals(idl.getUserId())){
completeSendCopy(identityLinks,task,userId);
Map map =new HashMap(); Map map =new HashMap();
map.put("taskid",task.getId()); map.put("taskid",task.getId());
map.put("userid",userId); map.put("userid",userId);
...@@ -1906,6 +1929,21 @@ public class WFCoreService ...@@ -1906,6 +1929,21 @@ public class WFCoreService
return true; return true;
} }
/**
* 判断除了本身其他link是否已读
* @return
*/
public void completeSendCopy(List<IdentityLink> identityLinks,Task task,String userId){
List<IdentityLink> noReadLinks = identityLinks.stream().filter(link -> StringUtils.isEmpty(link.getScopeType())).collect(Collectors.toList());
// 全部消息已读之后,将抄送任务推送到history表中
String type = task.getScopeType() == null ? "" : task.getScopeType();
if(type.equals("sendcopy") && noReadLinks.size() == 1){
if(noReadLinks.get(0).getUserId().equals(userId)){
taskService.complete(task.getId());
}
}
}
/** /**
* @param taskId 当前需要回退的节点 * @param taskId 当前需要回退的节点
* @return 回退上一个节点 * @return 回退上一个节点
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册