当前位置: 首页 > news >正文

饶平网站建设/推广普通话的内容

饶平网站建设,推广普通话的内容,潍坊行业网站,中国住房与城乡建设部网站有时候需要一些特定的查询条件,引擎自带的分页构造不满足需求,我们可以手动分页;这里以手动查询任务列表为例: 一、查看引擎分页查询逻辑 首先查看引擎的执行逻辑,在:包org.camunda.bpm.engine.impl.mapp…

有时候需要一些特定的查询条件,引擎自带的分页构造不满足需求,我们可以手动分页;这里以手动查询任务列表为例:

一、查看引擎分页查询逻辑

首先查看引擎的执行逻辑,在:包org.camunda.bpm.engine.impl.mapping.entity下的Task.xml(绝对路径:/org/camunda/bpm/engine/impl/mapping/entity/Task.xml
在这里插入图片描述

可以看到返回结果是mybatisresultMap

  <resultMap id="taskResultMap" type="org.camunda.bpm.engine.impl.persistence.entity.TaskEntity"><id property="id" column="ID_" jdbcType="VARCHAR"/><result property="revision" column="REV_" jdbcType="INTEGER"/><result property="nameWithoutCascade" column="NAME_" jdbcType="VARCHAR"/><result property="parentTaskIdWithoutCascade" column="PARENT_TASK_ID_" jdbcType="VARCHAR"/><result property="descriptionWithoutCascade" column="DESCRIPTION_" jdbcType="VARCHAR"/><result property="priorityWithoutCascade" column="PRIORITY_" jdbcType="INTEGER"/><result property="createTime" column="CREATE_TIME_" jdbcType="TIMESTAMP" /><result property="ownerWithoutCascade" column="OWNER_" jdbcType="VARCHAR"/><result property="assigneeWithoutCascade" column="ASSIGNEE_" jdbcType="VARCHAR"/><result property="delegationStateString" column="DELEGATION_" jdbcType="VARCHAR"/><result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR" /><result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" /><result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR"/><result property="caseExecutionId" column="CASE_EXECUTION_ID_" jdbcType="VARCHAR" /><result property="caseInstanceIdWithoutCascade" column="CASE_INST_ID_" jdbcType="VARCHAR" /><result property="caseDefinitionId" column="CASE_DEF_ID_" jdbcType="VARCHAR"/><result property="taskDefinitionKeyWithoutCascade" column="TASK_DEF_KEY_" jdbcType="VARCHAR"/><result property="dueDateWithoutCascade" column="DUE_DATE_" jdbcType="TIMESTAMP"/><result property="followUpDateWithoutCascade" column="FOLLOW_UP_DATE_" jdbcType="TIMESTAMP"/><result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER" /><result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" /><!-- note: if you add mappings here, make sure to select the columns in 'columnSelection' --></resultMap>

里面有很多查询方法,例如:

  <select id="selectTask" parameterType="string" resultMap="taskResultMap">select * from ${prefix}ACT_RU_TASK where ID_ = #{id}</select>
<select id="selectTaskByQueryCriteria" parameterType="org.camunda.bpm.engine.impl.TaskQueryImpl" resultMap="taskResultMap"><include refid="org.camunda.bpm.engine.impl.persistence.entity.Commons.bindOrderBy"/>${limitBefore}select ${distinct}<include refid="columnSelection"/>${limitBetween}<if test="taskNameCaseInsensitive">, lower(RES.NAME_) LOWER_NAME_</if><include refid="org.camunda.bpm.engine.impl.persistence.entity.Commons.orderBySelection"/><include refid="selectTaskByQueryCriteriaSql"/>${orderBy}${limitAfter}</select>

二、手写分页mapper

我们同样用org.camunda.bpm.engine.impl.persistence.entity.TaskEntity作为返回值,并且可以自己添加与移除一些筛选条件

    <select id="countByTaskQuery" resultType="java.lang.Long">select count(distinct RES.ID_ )FROM ACT_RU_TASK RESWHERE RES.ASSIGNEE_ = #{userId} and RES.TENANT_ID_ = #{tenantId}<if test="processDefinitionId!=null">and RES.PROC_DEF_ID_ = #{processDefinitionId}</if><if test="executionId!=null">and RES.EXECUTION_ID_ = #{executionId}</if><if test="processInstanceId!=null">and RES.PROC_INST_ID_ = #{processInstanceId}</if></select><resultMap id="taskResultMap" type="org.camunda.bpm.engine.impl.persistence.entity.TaskEntity"><id property="id" column="ID_" jdbcType="VARCHAR"/><result property="revision" column="REV_" jdbcType="INTEGER"/><result property="nameWithoutCascade" column="NAME_" jdbcType="VARCHAR"/><result property="parentTaskIdWithoutCascade" column="PARENT_TASK_ID_" jdbcType="VARCHAR"/><result property="descriptionWithoutCascade" column="DESCRIPTION_" jdbcType="VARCHAR"/><result property="priorityWithoutCascade" column="PRIORITY_" jdbcType="INTEGER"/><result property="createTime" column="CREATE_TIME_" jdbcType="TIMESTAMP"/><result property="ownerWithoutCascade" column="OWNER_" jdbcType="VARCHAR"/><result property="assigneeWithoutCascade" column="ASSIGNEE_" jdbcType="VARCHAR"/><result property="delegationStateString" column="DELEGATION_" jdbcType="VARCHAR"/><result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR"/><result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR"/><result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR"/><result property="caseExecutionId" column="CASE_EXECUTION_ID_" jdbcType="VARCHAR"/><result property="caseInstanceIdWithoutCascade" column="CASE_INST_ID_" jdbcType="VARCHAR"/><result property="caseDefinitionId" column="CASE_DEF_ID_" jdbcType="VARCHAR"/><result property="taskDefinitionKeyWithoutCascade" column="TASK_DEF_KEY_" jdbcType="VARCHAR"/><result property="dueDateWithoutCascade" column="DUE_DATE_" jdbcType="TIMESTAMP"/><result property="followUpDateWithoutCascade" column="FOLLOW_UP_DATE_" jdbcType="TIMESTAMP"/><result property="suspensionState" column="SUSPENSION_STATE_" jdbcType="INTEGER"/><result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR"/><!-- note: if you add mappings here, make sure to select the columns in 'columnSelection' --></resultMap><select id="selectByTaskQuery" resultMap="taskResultMap">SELECT DISTINCTRES.REV_,RES.ID_,RES.NAME_,RES.PARENT_TASK_ID_,RES.DESCRIPTION_,RES.PRIORITY_,RES.CREATE_TIME_,RES.OWNER_,RES.ASSIGNEE_,RES.DELEGATION_,RES.EXECUTION_ID_,RES.PROC_INST_ID_,RES.PROC_DEF_ID_,RES.CASE_EXECUTION_ID_,RES.CASE_INST_ID_,RES.CASE_DEF_ID_,RES.TASK_DEF_KEY_,RES.DUE_DATE_,RES.FOLLOW_UP_DATE_,RES.SUSPENSION_STATE_,RES.TENANT_ID_FROMACT_RU_TASK RESWHERE RES.ASSIGNEE_ = #{userId} and RES.TENANT_ID_ = #{tenantId}<if test="processDefinitionId!=null">and RES.PROC_DEF_ID_ = #{processDefinitionId}</if><if test="executionId!=null">and RES.EXECUTION_ID_ = #{executionId}</if><if test="processInstanceId!=null">and RES.PROC_INST_ID_ = #{processInstanceId}</if>ORDER BY RES.CREATE_TIME_ DESCLIMIT #{pageSize} OFFSET #{startIndex}</select>

引擎自带分页与手写对比

分页工具类:

@ToString
@Getter
@Setter
public class PageResult<T> {private int pageIndex;private int pageSize;private int pages;private long total;private List<T> data;public PageResult(int pageIndex, int pageSize, long total, List<T> data) {this.pageIndex = pageIndex;this.pageSize = pageSize;this.data = data;this.total = total;this.pages = initPages(pageSize, total);}private int initPages(int pageSize, long total) {if (total % pageSize == 0) {return (int) (total / pageSize);} else {return (int) (total / pageSize) + 1;}}public static <T> PageResult<T> pageEmpty(int pageIndex, int pageSize) {PageResult<T> pageResult = new PageResult<>(pageIndex, pageSize, 0L, null);pageResult.setPages(0);pageResult.setData(Lists.newArrayList());pageResult.setPageIndex(pageIndex);pageResult.setPageSize(pageSize);return pageResult;}public static int firstRow(int pageIndex, int pageSize) {return pageSize * (pageIndex - 1);}
}

使用引擎自带分页:

        TaskQuery taskQuery = buildBaseTaskQuery(tenantId, executionId, processDefinitionId, processInstanceId);long total = taskQuery.count();if (total == 0L) {return PageResult.pageEmpty(pageIndex, pageSize);}List<Task> taskList = taskQuery.orderByTaskCreateTime().desc().listPage(PageResult.firstRow(pageIndex, pageSize), pageSize);
    private TaskQuery buildBaseTaskQuery(String tenantId, String executionId, String processDefinitionId,String processInstanceId) {TaskQuery taskQuery = taskService.createTaskQuery().tenantIdIn(tenantId);if (StringUtils.isNotBlank(processDefinitionId)) {taskQuery = taskQuery.processDefinitionId(processDefinitionId);}if (StringUtils.isNotBlank(processInstanceId)) {taskQuery = taskQuery.processInstanceId(processInstanceId);}if (StringUtils.isNotBlank(executionId)) {taskQuery = taskQuery.executionId(executionId);}return taskQuery;}

自定义手写分页:

        long total = taskMapper.countByTaskQuery(userId, tenantId, executionId, processDefinitionId, processInstanceId);if (total == 0L) {return PageResult.pageEmpty(pageIndex, pageSize);}List<TaskEntity> taskList = taskMapper.selectByTaskQuery(userId, tenantId, executionId, processDefinitionId, processInstanceId, PageResult.firstRow(pageIndex, pageSize), pageSize);return new PageResult<>(pageIndex, pageSize, total, taskList);

相关文章:

  • magento网站用什么专用主机/推广普通话的内容简短