update - 自测任务节点相关功能

This commit is contained in:
wangli 2023-07-14 13:51:39 +08:00
parent b58b3b2914
commit 06e121e8f0
9 changed files with 143 additions and 63 deletions

View File

@ -10,6 +10,7 @@ import org.flowable.engine.delegate.event.FlowableCancelledEvent;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.runtime.ProcessInstance;
import javax.annotation.Nullable;
import javax.validation.Valid;
public interface BpmProcessInstanceService {
@ -33,20 +34,22 @@ public interface BpmProcessInstanceService {
/**
* 获得流程实例
*
* @param id 流程实例的编号
* @return 流程实例, 租户Id不必传
* @param businessKey 创建工作流实例时,业务传入的 businessKey
* @param tenantId 租户 ID,非必传
* @return 流程实例
*/
ProcessInstance getProcessInstance(String id, String tenantId);
ProcessInstance getProcessInstanceByBusinessKey(String businessKey, @Nullable String tenantId,
@Nullable Boolean hasVariables);
/**
* 获得流程实例
*
* @param id 流程实例的编号
* @param tenantId 租户Id
* @param id 流程实例的编号
* @param tenantId 租户Id
* @param hasVariable 查询结果是否包含流程参数
* @return 流程实例, 租户Id不必传
*/
ProcessInstance getProcessInstance(String id, String tenantId, boolean hasVariable);
ProcessInstance getProcessInstance(String id, @Nullable String tenantId, @Nullable Boolean hasVariable);
/**
* 获得流程实例
@ -68,10 +71,12 @@ public interface BpmProcessInstanceService {
/**
* 获得流程实例 VO 信息
*
* @param id 流程实例的编号
* @param processInstanceId 流程实例的编号
* @param businessKey 业务key
* @param tenantId 租户 ID
* @return 流程实例
*/
BpmProcessInstanceVO getProcessInstanceVO(String id, String tenantId);
BpmProcessInstanceVO getProcessInstanceVO(String processInstanceId, String businessKey, String tenantId);
/**
* 撤销流程实例
@ -98,4 +103,6 @@ public interface BpmProcessInstanceService {
* @param event
*/
void updateProcessInstanceExtCancel(FlowableCancelledEvent event);
}

View File

@ -0,0 +1,34 @@
package cn.axzo.workflow.core.service.dto.request.process;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* TODO
*
* @author wangli
* @since 2023/7/14 13:48
*/
@Data
public class BpmBasicProcessInstanceQueryDTO {
/**
* 流程实例 ID
*/
@ApiModelProperty(value = "流程实例 Id")
private String processInstanceId;
/**
* 业务 key
*/
@ApiModelProperty("业务key")
private String businessKey;
/**
* 租户 ID
*/
@ApiModelProperty("租户 ID")
@NotBlank(message = "租户不能为空")
private String tenantId;
}

View File

@ -4,6 +4,7 @@ import cn.axzo.workflow.core.service.dto.request.BpmPageParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class BpmProcessDefinitionPageDTO extends BpmPageParam {

View File

@ -40,7 +40,7 @@ public class BpmProcessInstanceCreateDTO {
/**
* 发起人所在的项目部下的具体公司ID
*/
private Long companyId;
// private Long companyId;
/**
* 发起人的身份ID

View File

@ -0,0 +1,23 @@
package cn.axzo.workflow.core.service.dto.request.process;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 查询流程实例的入参模型
*
* @author wangli
* @since 2023/7/14 10:12
*/
@Data
@ApiModel("查询流程实例的入参模型")
public class BpmProcessInstanceQueryDTO extends BpmBasicProcessInstanceQueryDTO {
/**
* 是否包含参数
*/
@ApiModelProperty("是否包含实例运行参数")
private Boolean hasVariable;
}

View File

@ -1,10 +1,8 @@
package cn.axzo.workflow.core.service.dto.response.process;
import cn.axzo.workflow.core.repository.entity.BpmProcessInstanceExtDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.flowable.engine.runtime.ProcessInstance;
import java.util.Date;
import java.util.Map;
@ -28,7 +26,7 @@ public class BpmProcessInstanceVO {
private Integer result;
@ApiModelProperty(value = "提交时间", required = true)
private Date createTime;
private Date createAt;
@ApiModelProperty(value = "结束时间", required = true)
private Date endTime;
@ -39,10 +37,10 @@ public class BpmProcessInstanceVO {
@ApiModelProperty(value = "业务的唯一标识", example = "1", notes = "例如说,请假申请的编号")
private String businessKey;
@ApiModelProperty("引擎表内部的ProcessInstance对象")
private ProcessInstance processInstance;
// @ApiModelProperty("引擎表内部的ProcessInstance对象")
// private ProcessInstance processInstance;
private BpmProcessInstanceExtDO processInstanceExtDO;
// private BpmProcessInstanceExtDO processInstanceExtDO;
@ApiModelProperty("发起人姓名")
private String startUserName;
@ -50,4 +48,6 @@ public class BpmProcessInstanceVO {
@ApiModelProperty("发起人ID")
private String startIdentifyId;
private Object ext;
}

View File

@ -37,6 +37,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Nullable;
import javax.validation.Valid;
import java.util.*;
@ -66,10 +67,15 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
@Autowired
private HistoryService historyService;
@Override
public ProcessInstance getProcessInstance(String id, String tenantId) {
ProcessInstanceQuery instanceQuery = runtimeService.createProcessInstanceQuery()
.processInstanceId(id);
public ProcessInstance getProcessInstanceByBusinessKey(String businessKey, @Nullable String tenantId,
@Nullable Boolean hasVariable) {
ProcessInstanceQuery instanceQuery =
runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(businessKey);
if (Boolean.TRUE.equals(hasVariable)) {
instanceQuery.includeProcessVariables();
}
if (StringUtils.isNotBlank(tenantId)) {
instanceQuery.processInstanceTenantId(tenantId);
}
@ -95,10 +101,9 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
}
@Override
public ProcessInstance getProcessInstance(String id, String tenantId, boolean hasVariable) {
ProcessInstanceQuery instanceQuery = runtimeService.createProcessInstanceQuery();
instanceQuery.processInstanceId(id);
if (hasVariable) {
public ProcessInstance getProcessInstance(String id, String tenantId, Boolean hasVariable) {
ProcessInstanceQuery instanceQuery = runtimeService.createProcessInstanceQuery().processInstanceId(id);
if (Boolean.TRUE.equals(hasVariable)) {
instanceQuery.includeProcessVariables();
}
if (StringUtils.isNotBlank(tenantId)) {
@ -165,7 +170,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
extDO.setProcessInstanceId(instance.getId());
extDO.setName(name);
extDO.setTenantId(createDTO.getTenantId());
extDO.setStartCompanyId(createDTO.getCompanyId());
// extDO.setStartCompanyId(createDTO.getCompanyId());
extDO.setStartIdentityId(createDTO.getIdentityId());
extDO.setStartUserName(createDTO.getUserName());
extDO.setFormVariables(createDTO.getVariables());
@ -178,19 +183,34 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
@Override
public HistoricProcessInstance getHistoricProcessInstance(String id, String tenantId) {
return null;
return historyService.createHistoricProcessInstanceQuery().processInstanceId(id)
.processInstanceTenantId(tenantId)
.singleResult();
}
public HistoricProcessInstance getHistoricProcessInstanceByBusinessKey(String businessKey, String tenantId) {
return historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(businessKey)
.processInstanceTenantId(tenantId)
.singleResult();
}
@Override
public BpmProcessInstanceVO getProcessInstanceVO(String id, String tenantId) {
public BpmProcessInstanceVO getProcessInstanceVO(String processInstanceId, String businessKey, String tenantId) {
ProcessInstance processInstance = null;
if (StringUtils.isNotBlank(processInstanceId)) {
processInstance = getProcessInstance(processInstanceId, tenantId, false);
} else if (StringUtils.isNotBlank(businessKey)) {
processInstance = getProcessInstanceByBusinessKey(businessKey, tenantId, false);
}
// 获得流程实例
HistoricProcessInstance processInstance = getHistoricProcessInstance(id, tenantId);
if (processInstance == null) {
return null;
}
BpmProcessInstanceExtDO processInstanceExt = processInstanceExtMapper.selectByProcessInstanceId(
id, tenantId);
Assert.notNull(processInstanceExt, "流程实例拓展({}) 不存在", id);
processInstance.getId(), tenantId);
Assert.notNull(processInstanceExt, "流程实例拓展({}) 不存在", processInstance.getId());
// 获得流程定义
ProcessDefinition processDefinition = processDefinitionService
@ -199,6 +219,12 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
BpmProcessInstanceVO bpmProcessInstanceVO = new BpmProcessInstanceVO();
BeanUtils.copyProperties(processInstanceExt, bpmProcessInstanceVO);
// bpmProcessInstanceVO.setProcessInstance(processInstance);
// bpmProcessInstanceVO.setProcessInstanceExtDO(processInstanceExt);
bpmProcessInstanceVO.setId(processInstance.getId());
bpmProcessInstanceVO.setBusinessKey(processInstance.getBusinessKey());
bpmProcessInstanceVO.setStartIdentifyId(processInstance.getStartUserId());
bpmProcessInstanceVO.setExt(processInstanceExt.getExt());
// 拼接结果
return bpmProcessInstanceVO;
}
@ -207,7 +233,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
public Boolean withdrawProcessInstance(BpmProcessInstanceWithdrawDTO withdrawDTO) {
// 校验流程实例存在
ProcessInstance instance = getProcessInstance(withdrawDTO.getId(),
String.valueOf(withdrawDTO.getTenantId()));
String.valueOf(withdrawDTO.getTenantId()), false);
if (instance == null) {
throw new WorkflowEngineException(PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS);
}
@ -299,7 +325,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
@Transactional(rollbackFor = Exception.class)
public void updateProcessInstanceExtReject(String id, String comment, String tenantId) {
// 需要主动查询因为 instance 只有 id 属性
ProcessInstance processInstance = getProcessInstance(id, tenantId);
ProcessInstance processInstance = getProcessInstance(id, tenantId, false);
// 删除流程实例以实现驳回任务时取消整个审批流程
deleteProcessInstance(id, StrUtil.format(BpmProcessInstanceDeleteReasonEnum.REJECT_TASK.format(comment)));

View File

@ -251,7 +251,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
// 校验流程实例存在
ProcessInstance instance = processInstanceService.getProcessInstance(
task.getProcessInstanceId(), null);
task.getProcessInstanceId(), null, null);
if (instance == null) {
throw new WorkflowEngineException(PROCESS_INSTANCE_NOT_EXISTS);

View File

@ -1,9 +1,7 @@
package cn.axzo.server.controller.web;
import cn.axzo.workflow.core.service.BpmProcessInstanceService;
import cn.axzo.workflow.core.service.dto.request.process.BpmProcessInstanceCreateDTO;
import cn.axzo.workflow.core.service.dto.request.process.BpmProcessInstanceMyPageReqVO;
import cn.axzo.workflow.core.service.dto.request.process.BpmProcessInstanceWithdrawDTO;
import cn.axzo.workflow.core.service.dto.request.process.*;
import cn.axzo.workflow.core.service.dto.response.BpmPageResult;
import cn.axzo.workflow.core.service.dto.response.process.BpmProcessInstancePageItemVO;
import cn.axzo.workflow.core.service.dto.response.process.BpmProcessInstanceVO;
@ -13,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@ -31,7 +30,7 @@ public class BpmProcessInstanceController {
*/
@GetMapping("/getOwnTaskPage")
public CommonResponse<BpmPageResult<BpmProcessInstancePageItemVO>> getMyProcessInstancePage(@RequestBody BpmProcessInstanceMyPageReqVO dto) {
log.info("我发起的审批列表 getOwnTaskPage===>>>参数:{}", dto);
log.info("我发起的审批列表 getOwnTaskPage===>>>参数:{}", JSON.toJSONString(dto));
BpmPageResult<BpmProcessInstancePageItemVO> result = bpmProcessInstanceService.getMyProcessInstancePage(dto);
return CommonResponse.success(result);
}
@ -46,44 +45,33 @@ public class BpmProcessInstanceController {
return CommonResponse.success(result);
}
/**
* 获得流程实例
*
* @param id 流程实例的编号
* @param dto {@link BpmProcessInstanceQueryDTO} 可根据 Id,BusinessKey进行查询
* @return 流程实例, 租户Id不必传
*/
@GetMapping("/get")
public CommonResponse<ProcessInstance> getProcessInstance(@RequestBody String id, String tenantId) {
log.info("获得流程实例 getProcessInstance===>>>参数:{},{}", id, tenantId);
ProcessInstance result = bpmProcessInstanceService.getProcessInstance(id, tenantId);
public CommonResponse<ProcessInstance> getProcessInstance(@RequestBody BpmProcessInstanceQueryDTO dto) {
log.info("获得流程实例 getProcessInstance===>>>参数:{}}", JSON.toJSONString(dto));
ProcessInstance result = null;
if (StringUtils.hasLength(dto.getProcessInstanceId())) {
result = bpmProcessInstanceService.getProcessInstance(dto.getProcessInstanceId(), dto.getTenantId(),
dto.getHasVariable());
} else if (StringUtils.hasLength(dto.getBusinessKey())) {
result = bpmProcessInstanceService.getProcessInstanceByBusinessKey(dto.getBusinessKey(),
dto.getTenantId(), dto.getHasVariable());
}
return CommonResponse.success(result);
}
/**
* 获得流程实例
*
* @param id 流程实例的编号
* @param tenantId 租户Id
* @param hasVariable 查询结果是否包含流程参数
* @return 流程实例, 租户Id不必传
*/
@GetMapping("/hasVariable/get")
public CommonResponse<ProcessInstance> getProcessInstances(@RequestBody String id, String tenantId,
boolean hasVariable) {
log.info("获得流程实例 getProcessInstances===>>>参数:{},{}", id, tenantId);
ProcessInstance result = bpmProcessInstanceService.getProcessInstance(id, tenantId, hasVariable);
return CommonResponse.success(result);
}
/**
* 获得流程实例
*
* @param processInstanceId 流程实例的编号
* @param status 租户Id
*/
@GetMapping("/updateProcessStatus")
@GetMapping("/status/update")
public CommonResponse<Boolean> updateProcessStatus(@RequestBody String processInstanceId, String status) {
log.info("获得流程实例 updateProcessStatus===>>>参数:{},{}", processInstanceId, status);
Boolean result = bpmProcessInstanceService.updateProcessStatus(processInstanceId, status);
@ -108,13 +96,14 @@ public class BpmProcessInstanceController {
/**
* 获得流程实例 VO 信息
*
* @param id 流程实例的编号
* @param {@link BpmProcessInstanceQueryDTO }
* @return 流程实例
*/
@GetMapping("/getProcessInstanceVO")
public CommonResponse<BpmProcessInstanceVO> getProcessInstanceVO(@RequestBody String id, String tenantId) {
log.info("获得历史的流程实例 getProcessInstanceVO===>>>参数:{},{}", id, tenantId);
BpmProcessInstanceVO result = bpmProcessInstanceService.getProcessInstanceVO(id, tenantId);
@GetMapping("/vo/get")
public CommonResponse<BpmProcessInstanceVO> getProcessInstanceVO(@RequestBody BpmBasicProcessInstanceQueryDTO dto) {
log.info("获得历史的流程实例 getProcessInstanceVO===>>>参数:{}", JSON.toJSONString(dto));
BpmProcessInstanceVO result = bpmProcessInstanceService.getProcessInstanceVO(dto.getProcessInstanceId(), null
, dto.getTenantId());
return CommonResponse.success(result);
}