代码开发,回调监听
This commit is contained in:
parent
5264d7abf7
commit
5a77fe1131
@ -13,7 +13,7 @@ import java.util.Map;
|
||||
@TableName(value = "bpm_task_ext", autoResultMap = true)
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
public class BpmTaskExtDO {
|
||||
public class BpmTaskExtDO extends BpmBaseDO{
|
||||
|
||||
/**
|
||||
* 编号,自增
|
||||
|
||||
@ -2,6 +2,7 @@ package cn.axzo.workflow.core.service;
|
||||
|
||||
import cn.axzo.workflow.core.service.dto.response.process.BpmProcessInstanceVO;
|
||||
import cn.axzo.workflow.core.service.dto.request.process.BpmProcessInstanceCreateDTO;
|
||||
import cn.axzo.workflow.core.service.dto.response.process.BpmProcessInstanceWithdrawDTO;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.repository.ProcessDefinition;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
@ -54,4 +55,6 @@ public interface BpmProcessInstanceService {
|
||||
* @return 流程实例
|
||||
*/
|
||||
BpmProcessInstanceVO getProcessInstanceVO(String id, String tenantId);
|
||||
|
||||
Boolean withdrawProcessInstance(BpmProcessInstanceWithdrawDTO withdrawDTO);
|
||||
}
|
||||
|
||||
@ -37,11 +37,6 @@ public interface BpmTaskService {
|
||||
* */
|
||||
void rejectTask(BpmTaskAuditDTO taskAuditDTO);
|
||||
|
||||
/**
|
||||
* 撤销
|
||||
* */
|
||||
void withdrawTask(BpmTaskAuditDTO taskAuditDTO);
|
||||
|
||||
/**
|
||||
* 获取历史已审批的列表详情
|
||||
*/
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
package cn.axzo.workflow.core.service.converter;
|
||||
|
||||
public class BpmProcessInstanceConverter {
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package cn.axzo.workflow.core.service.converter;
|
||||
|
||||
import cn.axzo.workflow.core.repository.entity.BpmTaskExtDO;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
|
||||
public class BpmTaskConvert {
|
||||
|
||||
public static BpmTaskExtDO convertTaskExt(DelegateTask task) {
|
||||
String assignee = task.getAssignee();
|
||||
BpmTaskExtDO taskExtDO = new BpmTaskExtDO();
|
||||
taskExtDO.setTaskId(task.getId());
|
||||
taskExtDO.setTenantId(task.getTenantId());
|
||||
taskExtDO.setIdentityId(Long.valueOf(assignee));
|
||||
taskExtDO.setProcessDefinitionId(task.getProcessDefinitionId());
|
||||
taskExtDO.setProcessInstanceId(task.getProcessInstanceId());
|
||||
taskExtDO.setName(task.getName());
|
||||
taskExtDO.setCreateTime(task.getCreateTime());
|
||||
taskExtDO.setUserName(task.getOwner());
|
||||
return taskExtDO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package cn.axzo.workflow.core.service.dto.response.process;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
@Data
|
||||
public class BpmProcessInstanceWithdrawDTO {
|
||||
|
||||
@ApiModelProperty(value = "流程实例的编号", required = true, example = "1024")
|
||||
@NotEmpty(message = "流程实例的编号不能为空")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "取消原因", required = true, example = "不请假了!")
|
||||
private String reason;
|
||||
|
||||
/**
|
||||
* 发起人所在的(企业/项目)工作台ID
|
||||
*/
|
||||
@ApiModelProperty(value = "租户Id", required = true, example = "1")
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 发起人的身份ID
|
||||
*/
|
||||
@ApiModelProperty(value = "操作人的身份 ID ", required = true, example = "1")
|
||||
private Long identityId;
|
||||
|
||||
@ApiModelProperty(value = "操作人的姓名", required = true, example = "张三")
|
||||
private String name;
|
||||
}
|
||||
@ -2,6 +2,8 @@ package cn.axzo.workflow.core.service.engine;
|
||||
|
||||
import cn.axzo.workflow.core.deletege.BpmTaskDelegate;
|
||||
import cn.axzo.workflow.core.listener.BpmTaskEventListener;
|
||||
import cn.axzo.workflow.core.service.BpmTaskService;
|
||||
import cn.axzo.workflow.core.service.impl.BpmTaskServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.engine.delegate.TaskListener;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
@ -20,17 +22,22 @@ public class EngineTaskEventListener implements TaskListener {
|
||||
@Lazy
|
||||
@Resource
|
||||
private BpmTaskDelegate taskDelegate;
|
||||
@Resource
|
||||
@Lazy // 解决循环依赖
|
||||
private BpmTaskServiceImpl taskService;
|
||||
|
||||
@Override
|
||||
public void notify(DelegateTask delegateTask) {
|
||||
if (delegateTask.getEventName().equals(TaskListener.EVENTNAME_CREATE)) {
|
||||
taskEventListener.created(delegateTask);
|
||||
taskService.createTaskExt(delegateTask);
|
||||
// 审批创建
|
||||
} else if (delegateTask.getEventName().equals(TaskListener.EVENTNAME_ASSIGNMENT)) {
|
||||
taskEventListener.assigned(delegateTask);
|
||||
} else if (delegateTask.getEventName().equals(TaskListener.EVENTNAME_COMPLETE)) {
|
||||
//审批完成
|
||||
taskEventListener.completed(delegateTask);
|
||||
taskService.updateTaskExtComplete(delegateTask);
|
||||
} else if (delegateTask.getEventName().equals(TaskListener.EVENTNAME_DELETE)) {
|
||||
// 审批删除
|
||||
taskEventListener.deleted(delegateTask);
|
||||
|
||||
@ -13,6 +13,7 @@ import cn.axzo.workflow.core.service.BpmProcessInstanceService;
|
||||
import cn.axzo.workflow.core.service.BpmTaskService;
|
||||
import cn.axzo.workflow.core.service.dto.request.process.BpmProcessInstanceCreateDTO;
|
||||
import cn.axzo.framework.domain.web.BizException;
|
||||
import cn.axzo.workflow.core.service.dto.response.process.BpmProcessInstanceWithdrawDTO;
|
||||
import cn.azxo.framework.common.utils.StringUtils;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@ -24,18 +25,16 @@ import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.repository.ProcessDefinition;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.engine.runtime.ProcessInstanceQuery;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.axzo.workflow.core.common.BpmConstants.INTERNAL_START_USER_NAME;
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.PROCESS_DEFINITION_IS_SUSPENDED;
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.PROCESS_DEFINITION_NOT_EXISTS;
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.*;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@ -158,20 +157,33 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
||||
Assert.notNull(processDefinition, "流程定义({}) 不存在", processInstance.getProcessDefinitionId());
|
||||
|
||||
BpmProcessInstanceVO bpmProcessInstanceVO = new BpmProcessInstanceVO();
|
||||
|
||||
// 设置发起人姓名
|
||||
String startUserName = processInstanceExtMapper.selectOne(
|
||||
new QueryWrapper<BpmProcessInstanceExtDO>().lambda()
|
||||
.eq(BpmProcessInstanceExtDO::getProcessInstanceId, processInstance.getId()))
|
||||
.getStartUserName();
|
||||
// BpmProcessInstanceRespVO.User startUser = bpmProcessInstanceRespVO.getStartUser();
|
||||
// startUser.setStartUserName(startUserName);
|
||||
// bpmProcessInstanceRespVO.setStartUser(startUser);
|
||||
|
||||
BeanUtils.copyProperties(processInstanceExt, bpmProcessInstanceVO);
|
||||
// 拼接结果
|
||||
return bpmProcessInstanceVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean withdrawProcessInstance(BpmProcessInstanceWithdrawDTO withdrawDTO) {
|
||||
// 校验流程实例存在
|
||||
ProcessInstance instance = getProcessInstance(withdrawDTO.getId(),
|
||||
String.valueOf(withdrawDTO.getTenantId()));
|
||||
if (instance == null) {
|
||||
throw new WorkflowEngineException(PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS);
|
||||
}
|
||||
|
||||
Long identityId = withdrawDTO.getIdentityId();
|
||||
if (!Objects.equals(instance.getStartUserId(),
|
||||
withdrawDTO.getIdentityId())) {
|
||||
throw new WorkflowEngineException(PROCESS_INSTANCE_CANCEL_FAIL_NOT_SELF);
|
||||
}
|
||||
|
||||
// 通过删除流程实例,实现流程实例的取消,
|
||||
// 删除流程实例,正则执行任务ACT_RU_TASK. 任务会被删除。通过历史表查询
|
||||
deleteProcessInstance(withdrawDTO.getId(),
|
||||
BpmProcessInstanceDeleteReasonEnum.CANCEL_TASK.format(withdrawDTO.getReason()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateProcessInstanceExtReject(String id, String comment, String tenantId) {
|
||||
// 需要主动查询,因为 instance 只有 id 属性
|
||||
|
||||
@ -7,12 +7,14 @@ import cn.axzo.workflow.core.repository.entity.BpmTaskExtDO;
|
||||
import cn.axzo.workflow.core.repository.mapper.BpmTaskExtMapper;
|
||||
import cn.axzo.workflow.core.service.BpmProcessInstanceService;
|
||||
import cn.axzo.workflow.core.service.BpmTaskService;
|
||||
import cn.axzo.workflow.core.service.converter.BpmTaskConvert;
|
||||
import cn.axzo.workflow.core.service.dto.request.task.BpmTaskAuditDTO;
|
||||
import cn.axzo.workflow.core.service.dto.request.task.BpmTaskTodoBpmPageDTO;
|
||||
import cn.axzo.workflow.core.service.dto.response.BpmPageResult;
|
||||
import cn.axzo.workflow.core.service.dto.response.task.BpmTaskDonePageItemVO;
|
||||
import cn.axzo.workflow.core.service.dto.response.task.BpmTaskTodoPageItemVO;
|
||||
import cn.azxo.framework.common.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
@ -21,6 +23,7 @@ import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.task.api.TaskQuery;
|
||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -42,7 +45,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||
@Autowired
|
||||
private RepositoryService repositoryService;
|
||||
@Resource
|
||||
private BpmProcessInstanceService processInstanceService;
|
||||
private BpmProcessInstanceServiceImpl processInstanceService;
|
||||
@Resource
|
||||
private BpmTaskExtMapper taskExtMapper;
|
||||
|
||||
@ -137,13 +140,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||
taskExtDO.setEndTime(new Date());
|
||||
taskExtMapper.updateByTaskId(taskExtDO);
|
||||
// 更新流程实例为不通过
|
||||
// processInstanceService.updateProcessInstanceExtReject(instance.getProcessInstanceId(),
|
||||
// reqVO.getComment(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withdrawTask(BpmTaskAuditDTO taskAuditDTO) {
|
||||
|
||||
processInstanceService.updateProcessInstanceExtReject(instance.getProcessInstanceId(), taskAuditDTO.getComment(), taskAuditDTO.getTenantId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -183,4 +180,16 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
||||
}
|
||||
return taskQuery.singleResult();
|
||||
}
|
||||
|
||||
public void createTaskExt(DelegateTask task) {
|
||||
BpmTaskExtDO taskExtDO = BpmTaskConvert.convertTaskExt(task);
|
||||
taskExtDO.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||
taskExtMapper.insert(taskExtDO);
|
||||
}
|
||||
|
||||
public void updateTaskExtComplete(DelegateTask task) {
|
||||
BpmTaskExtDO taskExtDO = BpmTaskConvert.convertTaskExt(task);
|
||||
taskExtDO.setEndTime(new Date());
|
||||
taskExtMapper.updateByTaskId(taskExtDO);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user