工作流审核撤回/回退/拒绝/同意/反悔钩子使用

目录

1. 流程撤回、拒绝和回退调用自定义函数
1.1 工作流【撤销】回调钩子
1.2 撤销【回退】回调钩子
1.3 工作流【拒绝】回调钩子
1.4 工作流【同意】回调钩子
1.4 工作流【反悔】回调钩子
1.4 回调钩子在业务系统中的调用示例
2. 自定义审批方式、自定义审批节点名称

1.流程撤回、拒绝和回退调用自定义函数

1.1工作流【撤销】回调钩子

使用方式:把该方法放置到XXX模型的Action下面,或@Fun(XXX.MODEL_MODEL)
触发方式:当流程实例被撤销时
调用入口:pro.shushi.pamirs.workflow.app.core.service.impl.WorkflowInstanceServiceImpl#undoInstance

/**
 * XXX为当前流程触发方式为模型触发时对应的触发模型、
 * 对应返回不影响流程上下文
 * @param data 入参为触发时的业务数据,数据的JsonString
 * @return
 */
@Function
public XXX recall(String data) {
      // TODO: 根据实际的业务逻辑把data转换为对象
       WorkRecord workRecord = JsonUtils.parseObject(data, new TypeReference<WorkRecord>(){});
      // TODO: 增加自定义业务逻辑
      return new XXX();
}

1.2撤销【回退】回调钩子

使用方式:把该方法放置到XXX模型的Action下面,或@Fun(XXX.MODEL_MODEL)
触发方式:流程待办进行回退操作时
调用入口:pro.shushi.pamirs.workflow.app.core.service.operator.ApprovalFallbackOperatorService

/**
 * XXX为当前流程触发方式为模型触发时对应的触发模型
 * 对应返回不影响流程上下文
 * @param data 入参为触发时的业务数据,数据的JsonString
 * @return
 */
@Function
public XXX fallBack(String data) {
    // TODO: 根据实际的业务逻辑把data转换为对象
    WorkRecord workRecord = JsonUtils.parseObject(data, new TypeReference<WorkRecord>(){});
    // TODO: 增加自定义业务逻辑
    return new XXX();
}

1.3工作流【拒绝】回调钩子

使用方式:把该方法放置到XXX模型的Action下面,或@Fun(XXX.MODEL_MODEL)
触发方式:流程待办进行拒绝操作时
调用入口:pro.shushi.pamirs.workflow.app.core.service.operator.ApprovalFallbackOperatorService

/**
 * XXX为当前流程触发方式为模型触发时对应的触发模型
 * 对应返回不影响流程上下文
 * @param data 入参为触发时的业务数据,数据的JsonString
 * @return
 */
@Function
public XXX reject(String data) {
    // TODO: 根据实际的业务逻辑把data转换为对象
    WorkRecord workRecord = JsonUtils.parseObject(data, new TypeReference<WorkRecord>(){});
    // TODO: 增加自定义业务逻辑
    return new XXX();
}

1.4 工作流【同意】回调钩子

使用方式:把该方法放置到XXX模型的Action下面,或@Fun(XXX.MODEL_MODEL)
触发方式:流程待办进行同意操作时
调用入口:pro.shushi.pamirs.workflow.app.core.util.ArtificialTaskUtils

    @Function(summary = "发起的审批同意时会自动调用此方法")
    @Function.Advanced(displayName = "审批同意")
    public Teacher agree(String data) {
        // TODO: 根据实际的业务逻辑把data转换为对象
//        WorkRecord workRecord = JsonUtils.parseObject(data, new TypeReference<WorkRecord>(){});
        // TODO: 增加自定义业务逻辑
        return new Teacher();
    }

1.4 工作流【反悔】回调钩子

使用方式:把该方法放置到XXX模型的Action下面,或@Fun(XXX.MODEL_MODEL)
触发方式:流程待办进行反悔操作时
使用场景:流程待办进行反悔操作时,需要额外更改其他的业务数据逻辑时可用该回调钩子。

注意:该函数的namespace需要设置为流程触发模型。

调用入口:pro.shushi.pamirs.workflow.app.core.service.operator.ArtificialRetractOperatorService

  @Function
  @Function.fun(WorkflowBizCallConstants.retract)
  public void retract(WorkflowUserTask workflowUserTask) {
      // 获取流程实例
      workflowUserTask.fieldQuery(WorkflowUserTask::getInstance);
      WorkflowInstance instance = workflowUserTask.getInstance();
      // 获取用户任务实例
      WorkflowUserInstance userInstance = new WorkflowUserInstance()
              .setId(workflowUserTask.getWorkflowUserInstanceId())
              .queryById();
      // 反悔的用户id
      Long userId = workflowUserTask.getUserId();
      // 反悔的节点id
      String nodeId = workflowUserTask.getNodeId();
  }

1.4回调钩子在业务系统中的调用示例

    @Function(summary = "发起的流程撤销时会自动调用此方法")
    @Function.Advanced(displayName = "撤销流程")
    public PurchaseProjectProxy recall(String data) {
        Object tempObj = BeanDefinitionUtils.findFirst(ClientDataConverter.class).out(PurchaseProjectProxy.MODEL_MODEL, JsonUtils.parseMap(data));
        PurchaseProjectProxy proxy = BeanDefinitionUtils.getBean(ClientDataConverter.class)
                .<PurchaseProjectProxy>in(new ModelComputeContext(), PurchaseProjectProxy.MODEL_MODEL, tempObj);

        PurchaseProject purchaseProject = service.recall(ArgUtils.convert(PurchaseProjectProxy.MODEL_MODEL, PurchaseProject.MODEL_MODEL, proxy));
        return ArgUtils.convert(PurchaseProject.MODEL_MODEL, PurchaseProjectProxy.MODEL_MODEL, purchaseProject);
    }

2.自定义审批方式、自定义审批节点名称

【注意】 流程自定义函数需指定:category = FunctionCategoryEnum.CUSTOM_DESIGNER

@Model.model(审批模型.MODEL_MODEL)
@Component
public class 审批模型Action {

    /**
     * 自定义审批方式
     * @param json json为业务数据,可用JsonUtils转换
     * @return 返回参数:
     * COUNTERSIGN_ONEAGREE_ONEREJUST 或签(一名审批人同意或拒绝即可)
     * COUNTERSIGN_ALLAGREE_ONEREJUST 会签(需所有审批人同意才为同意,一名审批人拒绝即为拒绝)
     * COUNTERSIGN_ONEAGREE_ALLREJUST 会签(一名审批人同意即为同意,需所有审批人拒绝才为拒绝)
     * SINGLE 单人
     */
    @Function
    @Function.Advanced(category = FunctionCategoryEnum.CUSTOM_DESIGNER, displayName = "测试自定义审批类型")
    public WorkflowSignTypeEnum signType(String json) {
        // TODO: 增加自定义业务逻辑
        return WorkflowSignTypeEnum.COUNTERSIGN_ONEAGREE_ONEREJUST;
    }

    /**
     * 自定义审批节点名称
     * @return
     */
    @Function
    @Function.Advanced(category = FunctionCategoryEnum.CUSTOM_DESIGNER, displayName = "测试自定义审批名称")
    public String customApprovalName() {
        return UUID.randomUUID().toString();
    }
}

Oinone社区 作者:望闲原创文章,如若转载,请注明出处:https://doc.oinone.top/backend/4542.html

访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验

(0)
望闲的头像望闲数式管理员
上一篇 2023年11月15日 pm2:19
下一篇 2023年11月16日

相关推荐

  • Oinone平台可视化调试工具

    为方便开发者定位问题,我们提供了可视化的调试工具。
    该文档将介绍可视化调试工具的基本使用方法。

    2024年4月13日
    99100
  • 字段类型之关系描述的特殊场景(常量关联)

    场景概述 【字段类型之关系与引用】一文中已经描述了各种关系字段的常规写法,还有一些特殊场景如:关系映射中存在常量,或者M2M中间表是大于两个字段构成。 场景描述 1、PetTalent模型增加talentType字段2、PetItem与PetTalent的多对多关系增加talentType(达人类型),3、PetItemRelPetTalent中间表维护petItemId、petTalentId以及talentType,PetDogItem和PetCatItem分别重写petTalents字段,关系中增加常量描述。示意图如下: 实际操作步骤 Step1 新增 TalentTypeEnum package pro.shushi.pamirs.demo.api.enumeration; import pro.shushi.pamirs.meta.annotation.Dict; import pro.shushi.pamirs.meta.common.enmu.BaseEnum; @Dict(dictionary = TalentTypeEnum.DICTIONARY,displayName = "达人类型") public class TalentTypeEnum extends BaseEnum<TalentTypeEnum,Integer> { public static final String DICTIONARY ="demo.TalentTypeEnum"; public final static TalentTypeEnum DOG =create("DOG",1,"狗达人","狗达人"); public final static TalentTypeEnum CAT =create("CAT",2,"猫达人","猫达人"); } Step2 PetTalent模型增加talentType字段 package pro.shushi.pamirs.demo.api.model; import pro.shushi.pamirs.demo.api.enumeration.TalentTypeEnum; import pro.shushi.pamirs.meta.annotation.Field; import pro.shushi.pamirs.meta.annotation.Model; @Model.model(PetTalent.MODEL_MODEL) @Model(displayName = "宠物达人",summary="宠物达人",labelFields ={"name"}) public class PetTalent extends AbstractDemoIdModel{ public static final String MODEL_MODEL="demo.PetTalent"; @Field(displayName = "达人") private String name; @Field(displayName = "达人类型") private TalentTypeEnum talentType; } Step3 修改PetItem的petTalents字段,在关系描述中增加talentType(达人类型) @Field.many2many(relationFields = {"petItemId"},referenceFields = {"petTalentId","talentType"},through = PetItemRelPetTalent.MODEL_MODEL ) @Field.Relation(relationFields = {"id"}, referenceFields = {"id","talentType"}) @Field(displayName = "推荐达人",summary = "推荐该商品的达人们") private List<PetTalent> petTalents; Step4 PetDogItem增加petTalents字段,重写父类PetItem的关系描述 talentType配置为常量,填入枚举的值 增加domain描述用户页面选择的时候自动过滤出特定类型的达人,RSQL用枚举的name @Field(displayName = "推荐达人") @Field.many2many( through = "PetItemRelPetTalent", relationFields = {"petItemId"}, referenceFields = {"petTalentId","talentType"} ) @Field.Relation(relationFields = {"id"}, referenceFields = {"id", "#1#"}, domain = " talentType == DOG") private List<PetTalent> petTalents; Step5 PetCatItem增加petTalents字段,重写父类PetItem的关系描述 talentType配置为常量,填入枚举的值 增加domain描述用户页面选择的时候自动过滤出特定类型的达人,RSQL用枚举的name @Field(displayName = "推荐达人") @Field.many2many( through = "PetItemRelPetTalent", relationFields = {"petItemId"}, referenceFields = {"petTalentId","talentType"} ) @Field.Relation(relationFields = {"id"}, referenceFields = {"id", "#2#"}, domain = " talentType == CAT") private List<PetTalent> petTalents; Step6 PetCatItem增加petTalents字段,many2one关系示例 talentType配置为常量,填入枚举的值 增加domain描述用户页面选择的时候自动过滤出特定类型的达人,RSQL用枚举的name @Model.model(PetPet.MODEL_MODEL) @Model(displayName…

    2024年5月25日
    1.4K00
  • 缓存连接由Jedis切换为Lettuce

    Jedis和Lettuce的区别 Jedis是同步的,不支持异步,Jedis客户端实例不是线程安全的,需要每个线程一个Jedis实例,所以一般通过连接池来使用Jedis; Lettuce是基于Netty框架的事件驱动的Redis客户端,其方法调用是异步的,Lettuce的API也是线程安全的,所以多个线程可以操作单个Lettuce连接来完成各种操作,同时Lettuce也支持连接池; Jedis切换Lettuce 依赖修改boot启动工程pom.xml改动 properties <lettuce.version>5.3.6.RELEASE</lettuce.version> <commons-pool2.version>2.8.1</commons-pool2.version> dependencies <dependency> <groupId>pro.shushi.pamirs.framework</groupId> <artifactId>pamirs-connectors-data-api</artifactId> <exclusions> <exclusion> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> <version>${lettuce.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <version>${commons-pool2.version}</version> </dependency> 配置修改application.yml配置修改 spring: redis: database: 0 host: 127.0.0.1 port: 6379 prefix: pamirs timeout: 2000 # 可选 password: xxxxx # 可选 # cluster: # nodes: # – 127.0.0.1:6379 # timeout: 2000 # max-redirects: 7 lettuce: pool: enable: true max-idle: 16 min-idle: 1 max-active: 16 max-wait: 2000

    2024年2月2日
    77100
  • 如何自定义SQL(Mapper)语句

    场景描述 在实际业务场景中,存在复杂SQL的情况,具体表现为: 单表单SQL满足不了的情况下 有复杂的Join关系或者子查询 复杂SQL的逻辑通过程序逻辑难以实现或实现代价较大 在此情况下,通过原生的mybatis/mybatis-plus, 自定义Mapper的方式实现业务功能 1、编写所需的Mapper SQL Mapper写法无限制,与使用原生的mybaits/mybaits-plus用法一样; Mapper(DAO)和SQL可以写在一个文件中,也分开写在两个文件中。 package pro.shushi.pamirs.demo.core.map; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; import java.util.Map; @Mapper public interface DemoItemMapper { @Select("<script>select sum(item_price) as itemPrice,sum(inventory_quantity) as inventoryQuantity,categoryId from ${demoItemTable} as core_demo_item ${where} group by category_id</script>") List<Map<String, Object>> groupByCategoryId(@Param("demoItemTable") String pamirsUserTable, @Param("where") String where); } 2.调用mapper 调用Mapper代码示例 package pro.shushi.pamirs.demo.core.map; import com.google.api.client.util.Lists; import org.springframework.stereotype.Component; import pro.shushi.pamirs.demo.api.model.DemoItem; import pro.shushi.pamirs.framework.connectors.data.api.datasource.DsHintApi; import pro.shushi.pamirs.meta.api.core.orm.convert.DataConverter; import pro.shushi.pamirs.meta.api.session.PamirsSession; import pro.shushi.pamirs.meta.common.spring.BeanDefinitionUtils; import java.util.List; import java.util.Map; @Component public class DemoItemDAO { public List<DemoItem> customSqlDemoItem(){ try (DsHintApi dsHint = DsHintApi.model(DemoItem.MODEL_MODEL)) { String demoItemTable = PamirsSession.getContext().getModelCache().get(DemoItem.MODEL_MODEL).getTable(); DemoItemMapper demoItemMapper = BeanDefinitionUtils.getBean(DemoItemMapper.class); String where = " where status = 'ACTIVE'"; List<Map<String, Object>> dataList = demoItemMapper.groupByCategoryId(demoItemTable,where); DataConverter persistenceDataConverter = BeanDefinitionUtils.getBean(DataConverter.class); return persistenceDataConverter.out(DemoItem.MODEL_MODEL, dataList); } return Lists.newArrayList(); } } 调用Mapper一些说明 启动类需要配置扫描包MapperScan @MapperScan(value = "pro.shushi", annotationClass = Mapper.class) @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, FreeMarkerAutoConfiguration.class}) public class DemoApplication { 调用Mapper接口的时候,需要指定数据源;即上述示例代码中的 DsHintApi dsHint = DsHintApi.model(DemoItem.MODEL_MODEL), 实际代码中使用 try-with-resources语法。 从Mapper返回的结果中获取数据 如果SQL Mapper中已定义了resultMap,调用Mapper(DAO)返回的就是Java对象 如果Mapper返回的是Map<String, Object>,则通过 DataConverter.out进行转化,参考上面的示例 其他参考:Oinone连接外部数据源方案:https://doc.oinone.top/backend/4562.html

    2023年11月27日
    1.2K00
  • 【MSSQL】后端部署使用MSSQL数据库(SQLServer)

    MSSQL数据库配置 驱动配置 Maven配置(2017版本可用) <mssql.version>9.4.0.jre8</mssql.version> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> <version>${mssql.version}</version> </dependency> 离线驱动下载 mssql-jdbc-7.4.1.jre8.jarmssql-jdbc-9.4.0.jre8.jarmssql-jdbc-12.2.0.jre8.jar JDBC连接配置 pamirs: datasource: base: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=base username: xxxxxx password: xxxxxx initialSize: 5 maxActive: 200 minIdle: 5 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true asyncInit: true 连接url配置 暂无官方资料 url格式 jdbc:sqlserver://${host}:${port};DatabaseName=${database} 在jdbc连接配置时,${database}必须配置,不可缺省。 其他连接参数如需配置,可自行查阅相关资料进行调优。 方言配置 pamirs方言配置 pamirs: dialect: ds: base: type: MSSQL version: 2017 major-version: 2017 pamirs: type: MSSQL version: 2017 major-version: 2017 数据库版本 type version majorVersion 2017 MSSQL 2017 2017 PS:由于方言开发环境为2017版本,其他类似版本原则上不会出现太大差异,如出现其他版本无法正常支持的,可在文档下方留言。 schedule方言配置 pamirs: event: enabled: true schedule: enabled: true dialect: type: MSSQL version: 2017 major-version: 2017 type version majorVersion MSSQL 2017 2017 PS:由于schedule的方言在多个版本中并无明显差异,目前仅提供一种方言配置。 其他配置 逻辑删除的值配置 pamirs: mapper: global: table-info: logic-delete-value: CAST(DATEDIFF(S, CAST('1970-01-01 00:00:00' AS DATETIME), GETUTCDATE()) AS BIGINT) * 1000000 + DATEPART(NS, SYSUTCDATETIME()) / 100 MSSQL数据库用户初始化及授权 — init root user (user name can be modified by oneself) CREATE LOGIN [root] WITH PASSWORD = 'password'; — if using mssql database, this authorization is required. ALTER SERVER ROLE [sysadmin] ADD MEMBER [root];

    2024年10月18日
    86800

Leave a Reply

登录后才能评论