大家好 现在 给大家带来 activiti任务回退 回退到上一级
我把所有的 bpmn文件的路径还有bpmn文件的 路径存在 DB中了 做成了一个模板
废话少说 我直接开始讲我写的这个接口
public class BaseProcessDto {
/**
* 模板id
*/
private String tempId;
/**
* 业务id
*/
private String busId;
/**
* 角色
*/
private String role;
/**
* 回退原因
*/
private String rejectCause;
}
还有就是我这个模板的实体
/**
* id
*/
@TableId(type = IdType.ID_WORKER_STR)
private String id;
/**
* 流程模板名称
*/
@TableField(value = "process_temp_name")
private String processTempName;
/**
* 中文名称
*/
@TableField(value = "temp_name")
private String tempName;
/**
* 唯一key
*/
@TableField("temp_key")
private String tempKey;
/**
* 文件路径
*/
@TableField("bpmn_path")
private String bpmnPath;
/**
* 图片路径
*/
@TableField("png_path")
private String pngPath;
/**
* 流程人数
*/
@TableField(value = "process_num")
private String processNum;
/**
* 是否删除
*/
@TableField(value = "is_del")
private String isDel;
/**
* 指定用户
*/
@TableField("users")
private String users;
我直接贴代码吧 因为不爱扯太多 注释都是打好的 我上面贴了entity 你们应该就能看的懂了
/**
* 流程回退
*
* @param busId
* @return
*/
@Override
public SuperResult processBack(BaseProcessDto dto) {
if ((dto)) {
return (ResultStatus.ERROR_REQUEST);
}
//获取流程详情
Purchase businessEntity = (());
if (().equals(())) {
("流程已经结束,不可退回该流程:{}", businessEntity);
return (ResultStatus.PROCESS_END);
}
//获取流程模板
ProcessTemp temp = getProcessTemp(());
Task task = ()
.processInstanceBusinessKey(())
.singleResult();
if (null == task) {
return ();
}
// 取得所有历史任务按时间降序排序
List<HistoricTaskInstance> htiList = getHistoryTaskList(());
Integer size = 2;
if ((htiList) || () < size) {
return ();
}
// list里的第二条代表上一个任务
HistoricTaskInstance lastTask = (1);
// list里第一条代表当前任务
HistoricTaskInstance curTask = (0);
// 当前节点的executionId
String curExecutionId = ();
// 上个节点的taskId
String lastTaskId = ();
// 上个节点的executionId
String lastExecutionId = ();
if (null == lastTaskId) {
throw new NullPointerException("上一个节点为空无法回退到上一个节点:{}");
}
String processDefinitionId = ();
BpmnModel bpmnModel = (processDefinitionId);
String lastActivityId = null;
List<HistoricActivityInstance> haiFinishedList = ()
.executionId(lastExecutionId).finished().list();
for (HistoricActivityInstance hai : haiFinishedList) {
if ((())) {
// 得到ActivityId,只有HistoricActivityInstance对象里才有此方法
lastActivityId = ();
break;
}
}
// 得到上个节点的信息
FlowNode lastFlowNode = (FlowNode) ().getFlowElement(lastActivityId);
// 取得当前节点的信息
Execution execution = ().executionId(curExecutionId).singleResult();
String curActivityId = ();
FlowNode curFlowNode = (FlowNode) ().getFlowElement(curActivityId);
// 记录当前节点的原活动方向
List<SequenceFlow> oriSequenceFlows = new ArrayList<>();
(());
// 清理活动方向
().clear();
// 建立新方向
List<SequenceFlow> newSequenceFlowList = new ArrayList<>();
SequenceFlow newSequenceFlow = new SequenceFlow();
("flow4");
(curFlowNode);
(lastFlowNode);
(newSequenceFlow);
(newSequenceFlowList);
// 完成任务
(());
// 恢复原方向
(oriSequenceFlows);
List<Task> list = ().processInstanceId(()).list();
// 设置执行人
if (list != null) {
//((), ());
((0).getId(), ());
}
//回退后修改状态为已驳回
(())
.setWriting(())
.setRejectCause(());
(businessEntity);
return ();
}
/**
* 根据实例获取历史实例信息
*
* @param processInstanceId
* @return
*/
public List<HistoricTaskInstance> getHistoryTaskList(String processInstanceId) {
return ().processInstanceId(processInstanceId)
.orderByTaskCreateTime().desc().list();
}
回退不了来找我