parent
4d7ee1769f
commit
1031b78f64
|
@ -31,7 +31,6 @@ public class BpmProcessInstanceController {
|
|||
public CommonResult<String> createProcessInstance(@Valid @RequestBody BpmProcessInstanceCreateReqVO createReqVO) {
|
||||
return success(processInstanceService.createProcessInstance(getLoginUserId(), createReqVO));
|
||||
// processInstanceService.getMyProcessInstancePage(getLoginUserId());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.bpm.convert.definition;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.BpmProcessDefinitionPageItemRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
|
@ -25,17 +25,17 @@ public interface BpmDefinitionConvert {
|
|||
BpmDefinitionConvert INSTANCE = Mappers.getMapper(BpmDefinitionConvert.class);
|
||||
|
||||
default List<BpmProcessDefinitionPageItemRespVO> convertList(List<ProcessDefinition> list, Map<String, Deployment> deploymentMap,
|
||||
Map<String, BpmProcessDefinitionDO> processDefinitionDOMap, Map<Long, BpmFormDO> formMap) {
|
||||
Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap, Map<Long, BpmFormDO> formMap) {
|
||||
return CollectionUtils.convertList(list, definition -> {
|
||||
Deployment deployment = definition.getDeploymentId() != null ? deploymentMap.get(definition.getDeploymentId()) : null;
|
||||
BpmProcessDefinitionDO definitionDO = processDefinitionDOMap.get(definition.getId());
|
||||
BpmProcessDefinitionExtDO definitionDO = processDefinitionDOMap.get(definition.getId());
|
||||
BpmFormDO form = definitionDO != null ? formMap.get(definitionDO.getFormId()) : null;
|
||||
return convert(definition, deployment, definitionDO, form);
|
||||
});
|
||||
}
|
||||
|
||||
default BpmProcessDefinitionPageItemRespVO convert(ProcessDefinition bean, Deployment deployment,
|
||||
BpmProcessDefinitionDO processDefinitionDO, BpmFormDO form) {
|
||||
BpmProcessDefinitionExtDO processDefinitionDO, BpmFormDO form) {
|
||||
BpmProcessDefinitionPageItemRespVO respVO = convert(bean);
|
||||
respVO.setSuspensionState(bean.isSuspended() ? SuspensionState.SUSPENDED.getStateCode() : SuspensionState.ACTIVE.getStateCode());
|
||||
if (deployment != null) {
|
||||
|
@ -53,6 +53,6 @@ public interface BpmDefinitionConvert {
|
|||
|
||||
BpmProcessDefinitionPageItemRespVO convert(ProcessDefinition bean);
|
||||
|
||||
BpmProcessDefinitionDO convert2(BpmDefinitionCreateReqDTO bean);
|
||||
BpmProcessDefinitionExtDO convert2(BpmDefinitionCreateReqDTO bean);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.bpm.convert.task;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
|
||||
import org.activiti.engine.runtime.ProcessInstance;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 流程实例 Convert
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface BpmProcessInstanceConvert {
|
||||
|
||||
BpmProcessInstanceConvert INSTANCE = Mappers.getMapper(BpmProcessInstanceConvert.class);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "startUserId", target = "userId"),
|
||||
@Mapping(source = "id", target = "processInstanceId"),
|
||||
@Mapping(source = "startTime", target = "createTime")
|
||||
})
|
||||
BpmProcessInstanceExtDO convert(ProcessInstance bean);
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow;
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.convert.task;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.TaskStepVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.TodoTaskRespVO;
|
|
@ -13,14 +13,14 @@ import org.activiti.engine.repository.ProcessDefinition;
|
|||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName(value = "bpm_process_definition", autoResultMap = true)
|
||||
@TableName(value = "bpm_process_definition_ext", autoResultMap = true)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BpmProcessDefinitionDO extends BaseDO {
|
||||
public class BpmProcessDefinitionExtDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
|
@ -1,7 +1,7 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.ProcessInstanceResultEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.ProcessInstanceStatusEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
@ -44,13 +44,13 @@ public class BpmProcessInstanceExtDO extends BaseDO {
|
|||
/**
|
||||
* 流程实例的状态
|
||||
*
|
||||
* 枚举 {@link ProcessInstanceStatusEnum}
|
||||
* 枚举 {@link BpmProcessInstanceStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 结果
|
||||
*
|
||||
* 枚举 {@link ProcessInstanceResultEnum}
|
||||
* 枚举 {@link BpmProcessInstanceResultEnum}
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
@ -9,10 +9,10 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BpmProcessDefinitionMapper extends BaseMapper<BpmProcessDefinitionDO> {
|
||||
public interface BpmProcessDefinitionExtMapper extends BaseMapper<BpmProcessDefinitionExtDO> {
|
||||
|
||||
default List<BpmProcessDefinitionDO> selectListByProcessDefinitionIds(Collection<String> processDefinitionIds) {
|
||||
return selectList(new QueryWrapper<BpmProcessDefinitionDO>().in("process_definition_id", processDefinitionIds));
|
||||
default List<BpmProcessDefinitionExtDO> selectListByProcessDefinitionIds(Collection<String> processDefinitionIds) {
|
||||
return selectList(new QueryWrapper<BpmProcessDefinitionExtDO>().in("process_definition_id", processDefinitionIds));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.task;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BpmProcessInstanceExtMapper extends BaseMapper<BpmProcessInstanceExtDO> {
|
||||
}
|
|
@ -10,7 +10,7 @@ import lombok.Getter;
|
|||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ProcessInstanceResultEnum {
|
||||
public enum BpmProcessInstanceResultEnum {
|
||||
|
||||
PROCESS(1, "处理中"),
|
||||
PASS(2, "通过"),
|
|
@ -10,7 +10,7 @@ import lombok.Getter;
|
|||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ProcessInstanceStatusEnum {
|
||||
public enum BpmProcessInstanceStatusEnum {
|
||||
|
||||
RUNNING(1, "进行中"),
|
||||
FINISH(2, "已完成");
|
||||
|
@ -18,7 +18,7 @@ public enum ProcessInstanceStatusEnum {
|
|||
/**
|
||||
* 状态
|
||||
*/
|
||||
private final Integer result;
|
||||
private final Integer status;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
|
@ -0,0 +1,26 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener.BpmProcessInstanceEventListener;
|
||||
import org.activiti.spring.SpringProcessEngineConfiguration;
|
||||
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* BPM 模块的 Activiti 配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class BpmActivitiConfiguration implements ProcessEngineConfigurationConfigurer {
|
||||
|
||||
@Resource
|
||||
private BpmProcessInstanceEventListener processInstanceEventListener;
|
||||
|
||||
@Override
|
||||
public void configure(SpringProcessEngineConfiguration configuration) {
|
||||
// 注册监听器,例如说 BpmProcessInstanceEventListener
|
||||
configuration.setEventListeners(Arrays.asList(processInstanceEventListener));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* 属于 bpm 模块的 framework 封装
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.framework;
|
|
@ -5,9 +5,9 @@ import cn.hutool.core.util.StrUtil;
|
|||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.BpmProcessDefinitionPageItemRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.BpmProcessDefinitionPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmDefinitionConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmProcessDefinitionMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmProcessDefinitionExtMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService;
|
||||
|
@ -56,7 +56,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
|
|||
private BpmFormService bpmFormService;
|
||||
|
||||
@Resource
|
||||
private BpmProcessDefinitionMapper processDefinitionMapper;
|
||||
private BpmProcessDefinitionExtMapper processDefinitionMapper;
|
||||
|
||||
@Override
|
||||
public PageResult<BpmProcessDefinitionPageItemRespVO> getProcessDefinitionPage(BpmProcessDefinitionPageReqVO pageVO) {
|
||||
|
@ -77,14 +77,14 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
|
|||
Map<String, Deployment> deploymentMap = getDeploymentMap(deploymentIds);
|
||||
|
||||
// 获得 BpmProcessDefinitionDO Map
|
||||
List<BpmProcessDefinitionDO> processDefinitionDOs = Collections.emptyList();
|
||||
List<BpmProcessDefinitionExtDO> processDefinitionDOs = Collections.emptyList();
|
||||
processDefinitionDOs = processDefinitionMapper.selectListByProcessDefinitionIds(
|
||||
convertList(processDefinitions, ProcessDefinition::getId));
|
||||
Map<String, BpmProcessDefinitionDO> processDefinitionDOMap = CollectionUtils.convertMap(processDefinitionDOs,
|
||||
BpmProcessDefinitionDO::getProcessDefinitionId);
|
||||
Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap = CollectionUtils.convertMap(processDefinitionDOs,
|
||||
BpmProcessDefinitionExtDO::getProcessDefinitionId);
|
||||
|
||||
// 获得 Form Map
|
||||
Set<Long> formIds = CollectionUtils.convertSet(processDefinitionDOs, BpmProcessDefinitionDO::getFormId);
|
||||
Set<Long> formIds = CollectionUtils.convertSet(processDefinitionDOs, BpmProcessDefinitionExtDO::getFormId);
|
||||
Map<Long, BpmFormDO> formMap = bpmFormService.getFormMap(formIds);
|
||||
|
||||
// 拼接结果
|
||||
|
@ -169,7 +169,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
|
|||
}
|
||||
|
||||
// 插入拓展表
|
||||
BpmProcessDefinitionDO definitionDO = BpmDefinitionConvert.INSTANCE.convert2(createReqDTO)
|
||||
BpmProcessDefinitionExtDO definitionDO = BpmDefinitionConvert.INSTANCE.convert2(createReqDTO)
|
||||
.setProcessDefinitionId(definition.getId());
|
||||
processDefinitionMapper.insert(definitionDO);
|
||||
return definition.getId();
|
||||
|
|
|
@ -2,7 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.oa;
|
|||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.oa.OALeaveMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.ProcessInstanceResultEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import org.activiti.engine.delegate.DelegateExecution;
|
||||
import org.activiti.engine.delegate.ExecutionListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -29,9 +29,9 @@ public class LeaveApplyEndProcessor implements ExecutionListener {
|
|||
OALeaveDO updateDo = new OALeaveDO();
|
||||
updateDo.setId(Long.valueOf(businessKey));
|
||||
if (Objects.equals(approved, true)) {
|
||||
updateDo.setStatus(ProcessInstanceResultEnum.PASS.getResult());
|
||||
updateDo.setStatus(BpmProcessInstanceResultEnum.PASS.getResult());
|
||||
} else {
|
||||
updateDo.setStatus(ProcessInstanceResultEnum.REJECT.getResult());
|
||||
updateDo.setStatus(BpmProcessInstanceResultEnum.REJECT.getResult());
|
||||
}
|
||||
|
||||
leaveMapper.updateById(updateDo);
|
||||
|
|
|
@ -6,7 +6,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.controller.oa.vo.*;
|
|||
import cn.iocoder.yudao.adminserver.modules.bpm.convert.oa.OALeaveConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.leave.OALeaveDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.oa.OALeaveMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.ProcessInstanceResultEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.oa.OALeaveService;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dept.SysPostMapper;
|
||||
|
@ -62,7 +62,7 @@ public class OALeaveServiceImpl implements OALeaveService {
|
|||
public Long createLeave(OALeaveCreateReqVO createReqVO) {
|
||||
// 插入 OA 请假单
|
||||
OALeaveDO leave = OALeaveConvert.INSTANCE.convert(createReqVO);
|
||||
leave.setStatus(ProcessInstanceResultEnum.PROCESS.getResult());
|
||||
leave.setStatus(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||
// TODO @jason:应该是存储 userId??
|
||||
leave.setUserId(SecurityFrameworkUtils.getLoginUser().getUsername());
|
||||
leaveMapper.insert(leave);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.bpm.service.task;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener.BpmProcessInstanceEventListener;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
|
|
|
@ -2,13 +2,17 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl;
|
|||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.BpmProcessInstanceConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.task.BpmProcessInstanceExtMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceStatusEnum;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService;
|
||||
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.activiti.engine.HistoryService;
|
||||
import org.activiti.engine.RepositoryService;
|
||||
import org.activiti.engine.RuntimeService;
|
||||
import org.activiti.engine.TaskService;
|
||||
import org.activiti.engine.history.HistoricProcessInstance;
|
||||
|
@ -44,8 +48,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
|
|||
@Slf4j
|
||||
public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService {
|
||||
|
||||
@Resource
|
||||
private RepositoryService repositoryService;
|
||||
@Resource
|
||||
private RuntimeService runtimeService;
|
||||
@Resource
|
||||
|
@ -58,7 +60,11 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
|||
@Resource
|
||||
private BpmProcessDefinitionService processDefinitionService;
|
||||
|
||||
@Resource
|
||||
private BpmProcessInstanceExtMapper processInstanceExtMapper;
|
||||
|
||||
@Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
public String createProcessInstance(Long userId, BpmProcessInstanceCreateReqVO createReqVO) {
|
||||
// 校验流程定义
|
||||
ProcessDefinition definition = processDefinitionService.getProcessDefinition(createReqVO.getProcessDefinitionId());
|
||||
|
@ -72,6 +78,10 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
|||
// 创建流程实例
|
||||
Map<String, Object> variables = createReqVO.getVariables();
|
||||
ProcessInstance instance = runtimeService.startProcessInstanceById(createReqVO.getProcessDefinitionId(), variables);
|
||||
// 设置流程名字
|
||||
runtimeService.setProcessInstanceName(instance.getId(), definition.getName());
|
||||
// 记录流程实例的拓展表
|
||||
createProcessInstanceExt(instance, definition.getName());
|
||||
|
||||
// 添加初始的评论 TODO 芋艿:在思考下
|
||||
Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult();
|
||||
|
@ -88,6 +98,20 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
|||
return instance.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建流程实例的拓展
|
||||
*
|
||||
* @param instance 流程实例
|
||||
* @param name 实例名。此时,instance 的 name 为空,所以需要传递该参数
|
||||
*/
|
||||
private void createProcessInstanceExt(ProcessInstance instance, String name) {
|
||||
BpmProcessInstanceExtDO instanceExt = BpmProcessInstanceConvert.INSTANCE.convert(instance);
|
||||
instanceExt.setName(name);
|
||||
instanceExt.setStatus(BpmProcessInstanceStatusEnum.RUNNING.getStatus());
|
||||
instanceExt.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||
processInstanceExtMapper.insert(instanceExt);
|
||||
}
|
||||
|
||||
public void getMyProcessInstancePage(Long userId) {
|
||||
// id title 所属流程 当前审批环节 状态 结果 创建时间 提交申请时间 【标题、状态】「ActBusiness」
|
||||
// id title 流程类别 流程版本 提交时间 流程状态 耗时 当前节点 办理 【标题、提交时间】「HistoricProcessInstanceQuery」
|
||||
|
@ -103,4 +127,24 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得流程实例
|
||||
*
|
||||
* @param id 流程实例的编号
|
||||
* @return 流程实例
|
||||
*/
|
||||
private ProcessInstance getProcessInstance(String id) {
|
||||
return runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得历史的流程实例
|
||||
*
|
||||
* @param id 流程实例的编号
|
||||
* @return 历史的流程实例
|
||||
*/
|
||||
private HistoricProcessInstance getHistoricProcessInstance(String id) {
|
||||
return historyService.createHistoricProcessInstanceQuery().processInstanceId(id).singleResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl;
|
|||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.*;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.convert.workflow.TaskConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.TaskConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener;
|
||||
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService;
|
||||
import org.activiti.engine.delegate.event.ActivitiEvent;
|
||||
import org.activiti.engine.delegate.event.ActivitiEventListener;
|
||||
import org.activiti.engine.delegate.event.ActivitiEventType;
|
||||
import org.activiti.engine.runtime.ProcessInstance;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 监听 {@link ProcessInstance} 的开始与完成,创建与更新对应的 {@link BpmProcessInstanceExtDO} 记录
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Component
|
||||
public class BpmProcessInstanceEventListener implements ActivitiEventListener {
|
||||
|
||||
@Resource
|
||||
@Lazy // 解决循环依赖
|
||||
private BpmProcessInstanceService processInstanceService;
|
||||
|
||||
@Override
|
||||
public void onEvent(ActivitiEvent event) {
|
||||
// 不处理 ActivitiEventType.PROCESS_STARTED 事件。原因:事件发布时,流程实例还没进行入库,就已经发布了 ActivitiEvent 事件
|
||||
|
||||
// 正常完成
|
||||
if (event.getType() == ActivitiEventType.PROCESS_COMPLETED
|
||||
|| event.getType() == ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT) {
|
||||
return;
|
||||
}
|
||||
// 取消
|
||||
if (event.getType() == ActivitiEventType.PROCESS_CANCELLED) {
|
||||
// TODO
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFailOnException() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package cn.iocoder.yudao.framework.activiti.core.util;
|
||||
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import org.activiti.engine.impl.identity.Authentication;
|
||||
|
||||
/**
|
||||
|
@ -9,6 +11,19 @@ import org.activiti.engine.impl.identity.Authentication;
|
|||
*/
|
||||
public class ActivitiUtils {
|
||||
|
||||
static {
|
||||
setAuthenticationThreadLocal();
|
||||
}
|
||||
|
||||
/**
|
||||
* 反射修改 Authentication 的 authenticatedUserIdThreadLocal 静态变量,使用 TTL 线程变量
|
||||
* 目的:保证 @Async 等异步执行时,变量丢失的问题
|
||||
*/
|
||||
private static void setAuthenticationThreadLocal() {
|
||||
ReflectUtil.setFieldValue(Authentication.class, "authenticatedUserIdThreadLocal",
|
||||
new TransmittableThreadLocal<String>());
|
||||
}
|
||||
|
||||
public static void setAuthenticatedUserId(Long userId) {
|
||||
Authentication.setAuthenticatedUserId(String.valueOf(userId));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.mybatis.core.dataobject;
|
|||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
Loading…
Reference in New Issue