acttiviti6.0 改变流程历史变量数据

  1.  流程结束后,想要改变历史,必须使用执行器,才能调用引擎流程提供的`Manage`接口,不然都会出现上下文问题.
    
  2.  还在运行的流程不需要这样做,直接使用提供的`Service`接口就可以了.
    

ProcessEngineConfigurationImpl processEngineConfigurationImpl;

HistoryService historyService;

使用执行器运行
processEngineConfigurationImpl.getCommandExecutor().execute(new Command<Object>() {
    @Override
    public Object execute(CommandContext commandContext) {
        // -- 这里的historicProcessInstance就是你需要修改的参数实例数据
        HistoricVariableInstanceEntityImpl historicVariableInstanceEntityImpl = ((HistoricVariableInstanceEntityImpl) historicProcessInstance)

        // 序列化. -- 下面是因为修改的是ref对象,所以需要用到序列号等操作.
        VariableTypes variableTypes = processEngineConfigurationImpl.getVariableTypes();
        // 用于序列号和反序列号
        SerializableType serializableType = (SerializableType) variableTypes.getVariableType(SerializableType.TYPE_NAME);
        byte[] data = serializableType.serialize(formData, historicVariableInstanceEntityImpl);
        ByteArrayEntity byteArrayEntity = historicVariableInstanceEntityImpl.getByteArrayRef().getEntity();
        byteArrayEntity.setBytes(data);

        // 使用上下文调用Manage中的更新接口. --更新历史数据
        return commandContext.getByteArrayEntityManager().update(byteArrayEntity);
    }
});
posted @ 2021-02-05 11:17  Monato  阅读(500)  评论(0编辑  收藏  举报