在Flowable中,你可以通过自定义查询来使用MySQL视图。以下是一个简单的步骤来说明如何在Flowable中使用MySQL视图:
process_instance_with_variables
的视图,它包含了流程实例和相关变量的信息。CREATE VIEW process_instance_with_variables AS
SELECT
pi.id_ AS process_instance_id,
pi.name_ AS process_instance_name,
pv.name_ AS variable_name,
pv.value_ AS variable_value
FROM
act_ru_execution pi
JOIN
act_ru_variable pv ON pi.id_ = pv.execution_id_;
<bean id="customQuery" class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="customMybatisMappers">
<list>
<value>com.example.CustomMybatisMapper</value>
</list>
</property>
</bean>
package com.example;
import java.util.List;
import org.apache.ibatis.annotations.Select;
public interface CustomMybatisMapper {
@Select("SELECT * FROM process_instance_with_variables WHERE process_instance_id = #{processInstanceId}")
List<ProcessInstanceWithVariables> getProcessInstanceWithVariables(String processInstanceId);
}
RuntimeService
或ManagementService
来调用这个自定义查询。@Autowired
private RuntimeService runtimeService;
public List<ProcessInstanceWithVariables> getProcessInstanceWithVariables(String processInstanceId) {
CustomMybatisMapper customMybatisMapper = (CustomMybatisMapper) runtimeService.getCommandExecutor()
.execute(new Command<Object>() {
@Override
public Object execute(CommandContext commandContext) {
return commandContext.getDbSqlSession().getSqlSession().getMapper(CustomMybatisMapper.class);
}
});
return customMybatisMapper.getProcessInstanceWithVariables(processInstanceId);
}
现在,你已经成功地在Flowable中使用了MySQL视图。你可以根据需要修改查询和视图,以满足你的业务需求。