Forráskód Böngészése

update 调整流程定义配置逻辑

gssong 1 éve
szülő
commit
af77657a86

+ 1 - 1
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/controller/ActTaskController.java

@@ -53,7 +53,7 @@ public class ActTaskController extends BaseController {
     @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);
     }

+ 14 - 1
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/controller/WfDefinitionConfigController.java

@@ -38,7 +38,7 @@ public class WfDefinitionConfigController extends BaseController {
      */
     @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 @@ public class WfDefinitionConfigController extends BaseController {
                           @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));
+    }
+
 }

+ 7 - 2
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/WfDefinitionConfig.java

@@ -28,9 +28,9 @@ public class WfDefinitionConfig extends BaseEntity {
     private Long id;
 
     /**
-     * 表单ID
+     * 表
      */
-    private Long formId;
+    private String tableName;
 
     /**
      * 流程定义ID
@@ -42,6 +42,11 @@ public class WfDefinitionConfig extends BaseEntity {
      */
     private String processKey;
 
+    /**
+     * 流程版本
+     */
+    private Integer version;
+
     /**
      * 备注
      */

+ 6 - 2
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 @@ public class StartProcessBo implements Serializable {
     /**
      * 业务唯一值id
      */
+    @NotBlank(message = "业务ID不能为空", groups = {AddGroup.class})
     private String businessKey;
 
     /**
-     * 流程执行key
+     * 表名
      */
-    private String processKey;
+    @NotBlank(message = "表名不能为空", groups = {AddGroup.class})
+    private String tableName;
 
     /**
      * 流程变量,前端会提交一个元素{'entity': {业务详情数据对象}}

+ 9 - 3
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/bo/WfDefinitionConfigBo.java

@@ -27,10 +27,10 @@ public class WfDefinitionConfigBo extends BaseEntity {
     private Long id;
 
     /**
-     * 表单ID
+     * 表
      */
-    @NotNull(message = "表单ID不能为空", groups = {AddGroup.class})
-    private Long formId;
+    @NotBlank(message = "表名不能为空", groups = {AddGroup.class})
+    private String tableName;
 
     /**
      * 流程定义ID
@@ -44,6 +44,12 @@ public class WfDefinitionConfigBo extends BaseEntity {
     @NotBlank(message = "流程KEY不能为空", groups = {AddGroup.class})
     private String processKey;
 
+    /**
+     * 流程版本
+     */
+    @NotNull(message = "流程版本不能为空", groups = {AddGroup.class})
+    private Integer version;
+
     /**
      * 备注
      */

+ 10 - 3
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/domain/vo/WfDefinitionConfigVo.java

@@ -31,10 +31,10 @@ public class WfDefinitionConfigVo implements Serializable {
     private Long id;
 
     /**
-     * 表单ID
+     * 表
      */
-    @ExcelProperty(value = "表单ID")
-    private Long formId;
+    @ExcelProperty(value = "表")
+    private String tableName;
 
     /**
      * 流程定义ID
@@ -48,6 +48,13 @@ public class WfDefinitionConfigVo implements Serializable {
     @ExcelProperty(value = "流程KEY")
     private String processKey;
 
+
+    /**
+     * 流程版本
+     */
+    @ExcelProperty(value = "流程版本")
+    private Integer version;
+
     /**
      * 备注
      */

+ 26 - 0
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/IWfDefinitionConfigService.java

@@ -22,6 +22,32 @@ public interface IWfDefinitionConfigService {
      */
     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);
+
     /**
      * 查询流程定义配置列表
      *

+ 9 - 3
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java

@@ -30,6 +30,7 @@ import org.dromara.workflow.flowable.strategy.FlowTaskEventHandler;
 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 @@ public class ActTaskServiceImpl implements IActTaskService {
     private final IWfTaskBackNodeService iWfTaskBackNodeService;
     private final ActHiTaskinstMapper actHiTaskinstMapper;
     private final IWfNodeConfigService iWfNodeConfigService;
+    private final IWfDefinitionConfigService iWfDefinitionConfigService;
 
     /**
      * 启动任务
@@ -106,6 +108,10 @@ public class ActTaskServiceImpl implements IActTaskService {
             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 @@ public class ActTaskServiceImpl implements IActTaskService {
         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());

+ 46 - 0
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;
@@ -34,6 +35,49 @@ public class WfDefinitionConfigServiceImpl implements IWfDefinitionConfigService
         return baseMapper.selectVoOne(new LambdaQueryWrapper<WfDefinitionConfig>().eq(WfDefinitionConfig::getDefinitionId, definitionId));
     }
 
+    /**
+     * 查询流程定义配置
+     *
+     * @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));
+    }
+
     /**
      * 查询流程定义配置列表
      */
@@ -49,6 +93,8 @@ public class WfDefinitionConfigServiceImpl implements IWfDefinitionConfigService
     @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());

+ 2 - 1
script/sql/flowable.sql

@@ -79,9 +79,10 @@ create table wf_definition_config
 (
     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 '创建时间',

+ 5 - 3
script/sql/oracle/flowable.sql

@@ -125,9 +125,10 @@ create table WF_DEFINITION_CONFIG
     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 @@ create table WF_DEFINITION_CONFIG
 );
 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 '创建者'

+ 6 - 3
script/sql/postgres/flowable.sql

@@ -169,9 +169,10 @@ create table wf_definition_config
     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 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 '租户id';
 
 comment on column wf_definition_config.create_dept is '创建部门';

+ 9 - 4
script/sql/sqlserver/flowable.sql

@@ -215,11 +215,12 @@ go
 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 @@ go
 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 @@ exec sp_addextendedproperty 'MS_Description', N'流程KEY', 'SCHEMA', 'dbo', 'TA
      '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