diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java index 81c96db24..c0430d28b 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmProcessInstanceController.java @@ -31,7 +31,6 @@ public class BpmProcessInstanceController { public CommonResult createProcessInstance(@Valid @RequestBody BpmProcessInstanceCreateReqVO createReqVO) { return success(processInstanceService.createProcessInstance(getLoginUserId(), createReqVO)); // processInstanceService.getMyProcessInstancePage(getLoginUserId()); - return null; } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmDefinitionConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmDefinitionConvert.java index e5df3771d..895f410d0 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmDefinitionConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmDefinitionConvert.java @@ -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 convertList(List list, Map deploymentMap, - Map processDefinitionDOMap, Map formMap) { + Map processDefinitionDOMap, Map 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); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmProcessInstanceConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmProcessInstanceConvert.java new file mode 100644 index 000000000..0d8f2fa4e --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmProcessInstanceConvert.java @@ -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); + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/TaskConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/TaskConvert.java similarity index 96% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/TaskConvert.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/TaskConvert.java index bcbb1372e..7d8b3dd0c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/workflow/TaskConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/TaskConvert.java @@ -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; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionExtDO.java similarity index 89% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionDO.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionExtDO.java index ed4b4a9bd..63b5e3382 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionExtDO.java @@ -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 { /** * 编号 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/task/BpmProcessInstanceExtDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/task/BpmProcessInstanceExtDO.java index 256f28f8d..d1c912172 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/task/BpmProcessInstanceExtDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/task/BpmProcessInstanceExtDO.java @@ -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; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmProcessDefinitionMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmProcessDefinitionExtMapper.java similarity index 50% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmProcessDefinitionMapper.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmProcessDefinitionExtMapper.java index 01dd786ad..623db9e94 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmProcessDefinitionMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmProcessDefinitionExtMapper.java @@ -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 { +public interface BpmProcessDefinitionExtMapper extends BaseMapper { - default List selectListByProcessDefinitionIds(Collection processDefinitionIds) { - return selectList(new QueryWrapper().in("process_definition_id", processDefinitionIds)); + default List selectListByProcessDefinitionIds(Collection processDefinitionIds) { + return selectList(new QueryWrapper().in("process_definition_id", processDefinitionIds)); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java new file mode 100644 index 000000000..602820d15 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java @@ -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 { +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/ProcessInstanceResultEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceResultEnum.java similarity index 91% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/ProcessInstanceResultEnum.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceResultEnum.java index d59c9d958..6f5f10cc9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/ProcessInstanceResultEnum.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceResultEnum.java @@ -10,7 +10,7 @@ import lombok.Getter; */ @Getter @AllArgsConstructor -public enum ProcessInstanceResultEnum { +public enum BpmProcessInstanceResultEnum { PROCESS(1, "处理中"), PASS(2, "通过"), diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/ProcessInstanceStatusEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceStatusEnum.java similarity index 82% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/ProcessInstanceStatusEnum.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceStatusEnum.java index 9413f539c..887883598 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/ProcessInstanceStatusEnum.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/task/BpmProcessInstanceStatusEnum.java @@ -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; /** * 描述 */ diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/BpmActivitiConfiguration.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/BpmActivitiConfiguration.java new file mode 100644 index 000000000..e4e158e29 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/BpmActivitiConfiguration.java @@ -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)); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/package-info.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/package-info.java new file mode 100644 index 000000000..cec0edd20 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/package-info.java @@ -0,0 +1,6 @@ +/** + * 属于 bpm 模块的 framework 封装 + * + * @author 芋道源码 + */ +package cn.iocoder.yudao.adminserver.modules.bpm.framework; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java index 04158464a..4fe4bef30 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java @@ -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 getProcessDefinitionPage(BpmProcessDefinitionPageReqVO pageVO) { @@ -77,14 +77,14 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ Map deploymentMap = getDeploymentMap(deploymentIds); // 获得 BpmProcessDefinitionDO Map - List processDefinitionDOs = Collections.emptyList(); + List processDefinitionDOs = Collections.emptyList(); processDefinitionDOs = processDefinitionMapper.selectListByProcessDefinitionIds( convertList(processDefinitions, ProcessDefinition::getId)); - Map processDefinitionDOMap = CollectionUtils.convertMap(processDefinitionDOs, - BpmProcessDefinitionDO::getProcessDefinitionId); + Map processDefinitionDOMap = CollectionUtils.convertMap(processDefinitionDOs, + BpmProcessDefinitionExtDO::getProcessDefinitionId); // 获得 Form Map - Set formIds = CollectionUtils.convertSet(processDefinitionDOs, BpmProcessDefinitionDO::getFormId); + Set formIds = CollectionUtils.convertSet(processDefinitionDOs, BpmProcessDefinitionExtDO::getFormId); Map 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(); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java index cef077924..e67749be1 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/LeaveApplyEndProcessor.java @@ -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); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/impl/OALeaveServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/impl/OALeaveServiceImpl.java index cf6f1199a..a5a996d48 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/impl/OALeaveServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/oa/impl/OALeaveServiceImpl.java @@ -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); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java index 5c755bc0e..d3587ecf4 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java @@ -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; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java index c7b13e885..32a6a2009 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java @@ -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 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(); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java index 381c4ab35..3652dc548 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java @@ -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; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java new file mode 100644 index 000000000..970a0b541 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java @@ -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; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/core/util/ActivitiUtils.java b/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/core/util/ActivitiUtils.java index 2a6c97b46..6897c720a 100644 --- a/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/core/util/ActivitiUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/core/util/ActivitiUtils.java @@ -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()); + } + public static void setAuthenticatedUserId(Long userId) { Authentication.setAuthenticatedUserId(String.valueOf(userId)); } diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java index f63f054de..e3df175f5 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java @@ -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;