在Flowable中,你可以通過自定義查詢來使用MySQL視圖。以下是一個簡單的步驟來說明如何在Flowable中使用MySQL視圖:
process_instance_with_variables
的視圖,它包含了流程實例和相關(guān)變量的信息。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
來調(diào)用這個自定義查詢。@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);
}
現(xiàn)在,你已經(jīng)成功地在Flowable中使用了MySQL視圖。你可以根據(jù)需要修改查詢和視圖,以滿足你的業(yè)務(wù)需求。