gssong
2024-04-06 af77657a86713899cabe48aec37351734f8cfe32
update 调整流程定义配置逻辑
已修改13个文件
176 ■■■■ 文件已修改
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/controller/ActTaskController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/controller/WfDefinitionConfigController.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/WfDefinitionConfig.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/bo/StartProcessBo.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/bo/WfDefinitionConfigBo.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/vo/WfDefinitionConfigVo.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/IWfDefinitionConfigService.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/WfDefinitionConfigServiceImpl.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
script/sql/flowable.sql 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
script/sql/oracle/flowable.sql 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
script/sql/postgres/flowable.sql 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
script/sql/sqlserver/flowable.sql 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/controller/ActTaskController.java
@@ -53,7 +53,7 @@
    @Log(title = "任务管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/startWorkFlow")
    public R<Map<String, Object>> startWorkFlow(@RequestBody StartProcessBo startProcessBo) {
    public R<Map<String, Object>> startWorkFlow(@Validated(AddGroup.class) @RequestBody StartProcessBo startProcessBo) {
        Map<String, Object> map = actTaskService.startWorkFlow(startProcessBo);
        return R.ok("提交成功", map);
    }
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/controller/WfDefinitionConfigController.java
@@ -38,7 +38,7 @@
     */
    @GetMapping("/getByDefId/{definitionId}")
    public R<WfDefinitionConfigVo> getByDefId(@NotBlank(message = "流程定义ID不能为空")
                                            @PathVariable String definitionId) {
                                              @PathVariable String definitionId) {
        return R.ok(wfDefinitionConfigService.getByDefId(definitionId));
    }
@@ -63,4 +63,17 @@
                          @PathVariable Long[] ids) {
        return toAjax(wfDefinitionConfigService.deleteByIds(List.of(ids)));
    }
    /**
     * 查询流程定义配置排除当前查询的流程定义
     *
     * @param tableName    表名
     * @param definitionId 流程定义id
     */
    @GetMapping("/getByTableNameNotDefId/{tableName}/{definitionId}")
    public R<List<WfDefinitionConfigVo>> getByTableNameNotDefId(@NotBlank(message = "表名不能为空") @PathVariable String tableName,
                                                                @NotBlank(message = "流程定义ID不能为空") @PathVariable String definitionId) {
        return R.ok(wfDefinitionConfigService.getByTableNameNotDefId(tableName, definitionId));
    }
}
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/WfDefinitionConfig.java
@@ -28,9 +28,9 @@
    private Long id;
    /**
     * 表单ID
     * 表名
     */
    private Long formId;
    private String tableName;
    /**
     * 流程定义ID
@@ -43,6 +43,11 @@
    private String processKey;
    /**
     * 流程版本
     */
    private Integer version;
    /**
     * 备注
     */
    private String remark;
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/bo/StartProcessBo.java
@@ -1,7 +1,9 @@
package org.dromara.workflow.domain.bo;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.dromara.common.core.validate.AddGroup;
import java.io.Serial;
import java.io.Serializable;
@@ -23,12 +25,14 @@
    /**
     * 业务唯一值id
     */
    @NotBlank(message = "业务ID不能为空", groups = {AddGroup.class})
    private String businessKey;
    /**
     * 流程执行key
     * 表名
     */
    private String processKey;
    @NotBlank(message = "表名不能为空", groups = {AddGroup.class})
    private String tableName;
    /**
     * 流程变量,前端会提交一个元素{'entity': {业务详情数据对象}}
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/bo/WfDefinitionConfigBo.java
@@ -27,10 +27,10 @@
    private Long id;
    /**
     * 表单ID
     * 表名
     */
    @NotNull(message = "表单ID不能为空", groups = {AddGroup.class})
    private Long formId;
    @NotBlank(message = "表名不能为空", groups = {AddGroup.class})
    private String tableName;
    /**
     * 流程定义ID
@@ -45,6 +45,12 @@
    private String processKey;
    /**
     * 流程版本
     */
    @NotNull(message = "流程版本不能为空", groups = {AddGroup.class})
    private Integer version;
    /**
     * 备注
     */
    private String remark;
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/vo/WfDefinitionConfigVo.java
@@ -31,10 +31,10 @@
    private Long id;
    /**
     * 表单ID
     * 表名
     */
    @ExcelProperty(value = "表单ID")
    private Long formId;
    @ExcelProperty(value = "表名")
    private String tableName;
    /**
     * 流程定义ID
@@ -48,6 +48,13 @@
    @ExcelProperty(value = "流程KEY")
    private String processKey;
    /**
     * 流程版本
     */
    @ExcelProperty(value = "流程版本")
    private Integer version;
    /**
     * 备注
     */
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/IWfDefinitionConfigService.java
@@ -23,6 +23,32 @@
    WfDefinitionConfigVo getByDefId(String definitionId);
    /**
     * 查询流程定义配置
     *
     * @param tableName 表名
     * @return 结果
     */
    WfDefinitionConfigVo getByTableNameLastVersion(String tableName);
    /**
     * 查询流程定义配置
     *
     * @param definitionId 流程定义id
     * @param tableName    表名
     * @return 结果
     */
    WfDefinitionConfigVo getByDefIdAndTableName(String definitionId, String tableName);
    /**
     * 查询流程定义配置排除当前查询的流程定义
     *
     * @param definitionId 流程定义id
     * @param tableName    表名
     * @return 结果
     */
    List<WfDefinitionConfigVo> getByTableNameNotDefId(String tableName, String definitionId);
    /**
     * 查询流程定义配置列表
     *
     * @param definitionIds 流程定义id
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java
@@ -30,6 +30,7 @@
import org.dromara.workflow.mapper.ActHiTaskinstMapper;
import org.dromara.workflow.mapper.ActTaskMapper;
import org.dromara.workflow.service.IActTaskService;
import org.dromara.workflow.service.IWfDefinitionConfigService;
import org.dromara.workflow.service.IWfNodeConfigService;
import org.dromara.workflow.service.IWfTaskBackNodeService;
import org.dromara.workflow.utils.ModelUtils;
@@ -78,6 +79,7 @@
    private final IWfTaskBackNodeService iWfTaskBackNodeService;
    private final ActHiTaskinstMapper actHiTaskinstMapper;
    private final IWfNodeConfigService iWfNodeConfigService;
    private final IWfDefinitionConfigService iWfDefinitionConfigService;
    /**
     * 启动任务
@@ -106,6 +108,10 @@
            map.put("taskId", taskResult.get(0).getId());
            return map;
        }
        WfDefinitionConfigVo wfDefinitionConfigVo = iWfDefinitionConfigService.getByTableNameLastVersion(startProcessBo.getTableName());
        if (wfDefinitionConfigVo == null) {
            throw new ServiceException("请到流程定义绑定业务表名与流程KEY!");
        }
        // 设置启动人
        identityService.setAuthenticatedUserId(String.valueOf(LoginHelper.getUserId()));
        Authentication.setAuthenticatedUserId(String.valueOf(LoginHelper.getUserId()));
@@ -118,12 +124,12 @@
        ProcessInstance pi;
        try {
            if (TenantHelper.isEnable()) {
                pi = runtimeService.startProcessInstanceByKeyAndTenantId(startProcessBo.getProcessKey(), startProcessBo.getBusinessKey(), variables, TenantHelper.getTenantId());
                pi = runtimeService.startProcessInstanceByKeyAndTenantId(wfDefinitionConfigVo.getProcessKey(), startProcessBo.getBusinessKey(), variables, TenantHelper.getTenantId());
            } else {
                pi = runtimeService.startProcessInstanceByKey(startProcessBo.getProcessKey(), startProcessBo.getBusinessKey(), variables);
                pi = runtimeService.startProcessInstanceByKey(wfDefinitionConfigVo.getProcessKey(), startProcessBo.getBusinessKey(), variables);
            }
        } catch (FlowableObjectNotFoundException e) {
            throw new ServiceException("找不到当前【" + startProcessBo.getProcessKey() + "】流程定义!");
            throw new ServiceException("找不到当前【" + wfDefinitionConfigVo.getProcessKey() + "】流程定义!");
        }
        // 将流程定义名称 作为 流程实例名称
        runtimeService.setProcessInstanceName(pi.getProcessInstanceId(), pi.getProcessDefinitionName());
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/WfDefinitionConfigServiceImpl.java
@@ -1,5 +1,6 @@
package org.dromara.workflow.service.impl;
import cn.hutool.core.collection.CollUtil;
import org.dromara.common.core.utils.MapstructUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
@@ -35,6 +36,49 @@
    }
    /**
     * 查询流程定义配置
     *
     * @param tableName 表名
     * @return 结果
     */
    @Override
    public WfDefinitionConfigVo getByTableNameLastVersion(String tableName) {
        List<WfDefinitionConfigVo> wfDefinitionConfigVos = baseMapper.selectVoList(
            new LambdaQueryWrapper<WfDefinitionConfig>().eq(WfDefinitionConfig::getTableName, tableName).orderByDesc(WfDefinitionConfig::getVersion));
        if (CollUtil.isNotEmpty(wfDefinitionConfigVos)) {
            return wfDefinitionConfigVos.get(0);
        }
        return null;
    }
    /**
     * 查询流程定义配置
     *
     * @param definitionId 流程定义id
     * @param tableName    表名
     * @return 结果
     */
    @Override
    public WfDefinitionConfigVo getByDefIdAndTableName(String definitionId, String tableName) {
        return baseMapper.selectVoOne(new LambdaQueryWrapper<WfDefinitionConfig>()
            .eq(WfDefinitionConfig::getDefinitionId, definitionId)
            .eq(WfDefinitionConfig::getTableName, tableName));
    }
    /**
     * 查询流程定义配置排除当前查询的流程定义
     *
     * @param tableName    表名
     * @param definitionId 流程定义id
     */
    @Override
    public List<WfDefinitionConfigVo> getByTableNameNotDefId(String tableName, String definitionId) {
        return baseMapper.selectVoList(new LambdaQueryWrapper<WfDefinitionConfig>()
            .eq(WfDefinitionConfig::getTableName, tableName)
            .ne(WfDefinitionConfig::getDefinitionId, definitionId));
    }
    /**
     * 查询流程定义配置列表
     */
    @Override
@@ -49,6 +93,8 @@
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveOrUpdate(WfDefinitionConfigBo bo) {
        WfDefinitionConfig add = MapstructUtils.convert(bo, WfDefinitionConfig.class);
        baseMapper.delete(new LambdaQueryWrapper<WfDefinitionConfig>().eq(WfDefinitionConfig::getTableName, bo.getTableName()));
        add.setTableName(add.getTableName().toLowerCase());
        boolean flag = baseMapper.insertOrUpdate(add);
        if (baseMapper.insertOrUpdate(add)) {
            bo.setId(add.getId());
script/sql/flowable.sql
@@ -79,9 +79,10 @@
(
    id            bigint                        not null comment '主键'
        primary key,
    form_id       bigint                        not null comment '表单ID',
    table_name    varchar(255)                  not null comment '表名',
    definition_id varchar(255)                  not null comment '流程定义ID',
    process_key   varchar(255)                  not null comment '流程KEY',
    version       int(10)                       not null comment '流程版本',
    create_dept   bigint                        null comment '创建部门',
    create_by     bigint                        null comment '创建者',
    create_time   datetime                      null comment '创建时间',
script/sql/oracle/flowable.sql
@@ -125,9 +125,10 @@
    ID            NUMBER(20) NOT NULL
        CONSTRAINT PK_WF_DEFINITION_CONFIG
        PRIMARY KEY,
    FORM_ID       NUMBER(20) NOT NULL,
    TABLE_NAME    VARCHAR2(255) NOT NULL,
    DEFINITION_ID VARCHAR2(255) NOT NULL,
    PROCESS_KEY   VARCHAR2(255)  NOT NULL,
    PROCESS_KEY   VARCHAR2(255) NOT NULL,
    VERSION       NUMBER(10)    NOT NULL,
    TENANT_ID     VARCHAR2(20),
    CREATE_DEPT   NUMBER(20),
    CREATE_BY     NUMBER(20),
@@ -139,9 +140,10 @@
);
comment on table WF_DEFINITION_CONFIG is '流程定义配置'
comment on column WF_DEFINITION_CONFIG.ID is '主键'
comment on column WF_DEFINITION_CONFIG.FORM_ID is '表单ID'
comment on column WF_DEFINITION_CONFIG.TABLE_NAME is '表名'
comment on column WF_DEFINITION_CONFIG.DEFINITION_ID is '流程定义ID'
comment on column WF_DEFINITION_CONFIG.PROCESS_KEY is '流程KEY'
comment on column WF_DEFINITION_CONFIG.VERSION is '流程版本'
comment on column WF_DEFINITION_CONFIG.TENANT_ID is '租户编号'
comment on column WF_DEFINITION_CONFIG.CREATE_DEPT is '创建部门'
comment on column WF_DEFINITION_CONFIG.CREATE_BY is '创建者'
script/sql/postgres/flowable.sql
@@ -169,9 +169,10 @@
    id            bigint not null
        constraint pk_wf_definition_config
        primary key,
    form_id       bigint(20) not null,
    table_name    varchar(255) not null,
    definition_id varchar(255) not null,
    process_key   varchar(255)  not null,
    process_key   varchar(255) not null,
    version       bigint       not null,
    tenant_id     varchar(20),
    create_dept   bigint,
    create_by     bigint,
@@ -184,12 +185,14 @@
comment on column wf_definition_config.id is '主键';
comment on column wf_definition_config.form_id is '表单ID';
comment on column wf_definition_config.table_name is '表名';
comment on column wf_definition_config.definition_id is '流程定义ID';
comment on column wf_definition_config.process_key is '流程KEY';
comment on column wf_definition_config.version is '流程版本';
comment on column wf_definition_config.tenant_id is '租户id';
comment on column wf_definition_config.create_dept is '创建部门';
script/sql/sqlserver/flowable.sql
@@ -215,11 +215,12 @@
create table wf_definition_config
(
    id            bigint not null primary key,
    form_id       bigint not null,
    definition_id nvarchar(255)
    table_name    nvarchar(255)  not null,
    definition_id nvarchar(255)  not null
        constraint uni_definition_id
        unique,
    process_key   nvarchar(255)  not null,
    version       bigint         not null,
    tenant_id     nvarchar(20),
    create_dept   bigint,
    create_by     bigint,
@@ -235,8 +236,8 @@
exec sp_addextendedproperty 'MS_Description', N'主键', 'SCHEMA', 'dbo', 'TABLE', 'wf_definition_config', 'COLUMN', 'id'
go
exec sp_addextendedproperty 'MS_Description', N'表单ID', 'SCHEMA', 'dbo', 'TABLE', 'wf_definition_config', 'COLUMN',
     'form_id'
exec sp_addextendedproperty 'MS_Description', N'表名', 'SCHEMA', 'dbo', 'TABLE', 'wf_definition_config', 'COLUMN',
     'table_name'
go
exec sp_addextendedproperty 'MS_Description', N'流程定义ID', 'SCHEMA', 'dbo', 'TABLE', 'wf_definition_config', 'COLUMN',
@@ -247,6 +248,10 @@
     'process_key'
go
exec sp_addextendedproperty 'MS_Description', N'流程版本', 'SCHEMA', 'dbo', 'TABLE', 'wf_definition_config', 'COLUMN',
     'version'
go
exec sp_addextendedproperty 'MS_Description', N'租户编号', 'SCHEMA', 'dbo', 'TABLE', 'wf_definition_config', 'COLUMN',
     'tenant_id'
go