flowable 6.4.2 - 历史《任务实例》列表sql


### 历史任务实例列表 - ACT_HI_TASKINST


```
<select id="selectHistoricTaskInstancesWithRelatedEntitiesByQueryCriteria" parameterType="org.flowable.task.service.impl.HistoricTaskInstanceQueryImpl" resultMap="historicTaskAndRelatedEntitiesResultMap">
    <!--要查询的字段-->
	<sql id="selectHistoricTaskInstancesWithRelatedEntitiesByQueryCriteriaColumns">
	    <if test="firstResult != null and firstResult &gt;= 0">${limitBefore}</if>
	    <if test="_databaseId != 'db2' and _databaseId != 'mssql'">
	      select distinct RES.*,
	      <if test="includeTaskLocalVariables or includeProcessVariables">
	        VAR.ID_ as VAR_ID_, VAR.NAME_ as VAR_NAME_, VAR.VAR_TYPE_ as VAR_TYPE_, VAR.REV_ as VAR_REV_,
	        VAR.PROC_INST_ID_ as VAR_PROC_INST_ID_, VAR.EXECUTION_ID_ as VAR_EXECUTION_ID_, VAR.TASK_ID_ as VAR_TASK_ID_,
	        VAR.BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, VAR.DOUBLE_ as VAR_DOUBLE_,
	        VAR.TEXT_ as VAR_TEXT_, VAR.TEXT2_ as VAR_TEXT2_, VAR.LAST_UPDATED_TIME_ as VAR_LAST_UPDATED_TIME_, VAR.LONG_ as VAR_LONG_
	      </if>
	      <if test="(includeTaskLocalVariables or includeProcessVariables) and includeIdentityLinks">
	       ,
	      </if>
	      <if test="includeIdentityLinks">
	        ILINK.ID_ as ILINK_ID_, ILINK.TYPE_ as ILINK_TYPE_, ILINK.USER_ID_ as ILINK_USER_ID_,
	        ILINK.GROUP_ID_ as ILINK_GROUP_ID_, ILINK.TASK_ID_ as ILINK_TASK_ID_,
	        ILINK.PROC_INST_ID_ as ILINK_PROC_INST_ID_, ILINK.CREATE_TIME_ as ILINK_CREATE_TIME_
	      </if>
	      <if test="firstResult != null and firstResult &gt;= 0">${limitBetween}</if>
	    </if>
	    <if test="_databaseId == 'db2' || _databaseId == 'mssql'">
	      select distinct TEMPRES_ID_ as ID_, TEMPRES_REV_ as REV_,
	      TEMPRES_TASK_DEF_ID_ as TASK_DEF_ID_, TEMPRES_PROC_DEF_ID_ as PROC_DEF_ID_, TEMPRES_PROC_INST_ID_ as PROC_INST_ID_,
	      TEMPRES_EXECUTION_ID_ as EXECUTION_ID_, TEMPRES_NAME_ as NAME_, TEMPRES_PARENT_TASK_ID_ as PARENT_TASK_ID_,
	      TEMPRES_DESCRIPTION_ as DESCRIPTION_, TEMPRES_OWNER_ as OWNER_, TEMPRES_ASSIGNEE_ as ASSIGNEE_,
	      TEMPRES_START_TIME_ as START_TIME_, TEMPRES_CLAIM_TIME_ as CLAIM_TIME_, TEMPRES_END_TIME_ as END_TIME_,
	      TEMPRES_DURATION_ as DURATION_, TEMPRES_TASK_DEF_KEY_ as TASK_DEF_KEY_, TEMPRES_FORM_KEY_ as FORM_KEY_,
	      TEMPRES_PRIORITY_ as PRIORITY_, TEMPRES_DUE_DATE_ as DUE_DATE_, TEMPRES_CATEGORY_ as CATEGORY_,
	      TEMPRES_DELETE_REASON_ as DELETE_REASON_, TEMPRES_TENANT_ID_ as TENANT_ID_, TEMPRES_LAST_UPDATED_TIME_ as LAST_UPDATED_TIME_
	      <if test="includeTaskLocalVariables or includeProcessVariables">
	        ,
	        TEMPVAR_ID_ as VAR_ID_, TEMPVAR_NAME_ as VAR_NAME_, TEMPVAR_TYPE_ as VAR_TYPE_, TEMPVAR_REV_ as VAR_REV_,
	        TEMPVAR_PROC_INST_ID_ as VAR_PROC_INST_ID_, TEMPVAR_EXECUTION_ID_ as VAR_EXECUTION_ID_, TEMPVAR_TASK_ID_ as VAR_TASK_ID_,
	        TEMPVAR_BYTEARRAY_ID_ as VAR_BYTEARRAY_ID_, TEMPVAR_DOUBLE_ as VAR_DOUBLE_,
	        TEMPVAR_TEXT_ as VAR_TEXT_, TEMPVAR_LAST_UPDATED_TIME_ as VAR_LAST_UPDATED_TIME_, TEMPVAR_TEXT2_ as VAR_TEXT2_, TEMPVAR_LONG_ as VAR_LONG_
	      </if>
	      <if test="includeIdentityLinks">
	        ,
	        TEMPILINK_ID_ as ILINK_ID_, TEMPILINK_TYPE_ as ILINK_TYPE_, TEMPILINK_USER_ID_ as ILINK_USER_ID_,
	        TEMPILINK_GROUP_ID_ as ILINK_GROUP_ID_, TEMPILINK_TASK_ID_ as ILINK_TASK_ID_,
	        TEMPILINK_PROC_INST_ID_ as ILINK_PROC_INST_ID_, TEMPILINK_CREATE_TIME_ as ILINK_CREATE_TIME_
	      </if>
	      <if test="firstResult != null and firstResult &gt;= 0">${limitOuterJoinBetween}</if>
	      RES.ID_ as TEMPRES_ID_, RES.REV_ as TEMPRES_REV_, RES.TASK_DEF_ID_ as TEMPRES_TASK_DEF_ID_,
	      RES.PROC_DEF_ID_ as TEMPRES_PROC_DEF_ID_, RES.PROC_INST_ID_ as TEMPRES_PROC_INST_ID_,
	      RES.EXECUTION_ID_ as TEMPRES_EXECUTION_ID_, RES.NAME_ as TEMPRES_NAME_ , RES.PARENT_TASK_ID_ as TEMPRES_PARENT_TASK_ID_,
	      RES.DESCRIPTION_ as TEMPRES_DESCRIPTION_, RES.OWNER_ as TEMPRES_OWNER_, RES.ASSIGNEE_ as TEMPRES_ASSIGNEE_,
	      RES.START_TIME_ as TEMPRES_START_TIME_, RES.END_TIME_ as TEMPRES_END_TIME_, RES.CLAIM_TIME_ as TEMPRES_CLAIM_TIME_,
	      RES.DURATION_ as TEMPRES_DURATION_, RES.TASK_DEF_KEY_ as TEMPRES_TASK_DEF_KEY_,
	      RES.FORM_KEY_ as TEMPRES_FORM_KEY_, RES.PRIORITY_ as TEMPRES_PRIORITY_,
	      RES.DUE_DATE_ as TEMPRES_DUE_DATE_, RES.CATEGORY_ as TEMPRES_CATEGORY_, RES.DELETE_REASON_ as TEMPRES_DELETE_REASON_,
	      RES.TENANT_ID_ as TEMPRES_TENANT_ID_, RES.LAST_UPDATED_TIME_ as TEMPRES_LAST_UPDATED_TIME_
	      <if test="includeTaskLocalVariables or includeProcessVariables">
	        ,
	        VAR.ID_ as TEMPVAR_ID_, VAR.NAME_ as TEMPVAR_NAME_, VAR.VAR_TYPE_ as TEMPVAR_TYPE_, VAR.REV_ as TEMPVAR_REV_,
	        VAR.PROC_INST_ID_ as TEMPVAR_PROC_INST_ID_, VAR.EXECUTION_ID_ as TEMPVAR_EXECUTION_ID_, VAR.TASK_ID_ as TEMPVAR_TASK_ID_,
	        VAR.BYTEARRAY_ID_ as TEMPVAR_BYTEARRAY_ID_, VAR.DOUBLE_ as TEMPVAR_DOUBLE_,
	        VAR.TEXT_ as TEMPVAR_TEXT_, VAR.TEXT2_ as TEMPVAR_TEXT2_, VAR.LAST_UPDATED_TIME_ as TEMPVAR_LAST_UPDATED_TIME_, VAR.LONG_ as TEMPVAR_LONG_
	      </if>
	      <if test="includeIdentityLinks">
	        ,
	        ILINK.ID_ as TEMPILINK_ID_, ILINK.TYPE_ as TEMPILINK_TYPE_, ILINK.USER_ID_ as TEMPILINK_USER_ID_,
	        ILINK.GROUP_ID_ as TEMPILINK_GROUP_ID_, ILINK.TASK_ID_ as TEMPILINK_TASK_ID_,
	        ILINK.PROC_INST_ID_ as TEMPILINK_PROC_INST_ID_, ILINK.CREATE_TIME_ as TEMPILINK_CREATE_TIME_
	      </if>
	    </if>
	</sql>
	<!--要查询的表和join的表-->
	<sql id="selectHistoricTaskInstancesWithRelatedEntitiesByQueryCriteriaSql">
	    from ${prefix}ACT_HI_TASKINST RES
	    <choose>
	      <when test="includeTaskLocalVariables &amp;&amp; includeProcessVariables">
	        left outer join ${prefix}ACT_HI_VARINST VAR ON RES.ID_ = VAR.TASK_ID_ or (RES.PROC_INST_ID_ = VAR.EXECUTION_ID_)
	      </when>
	      <otherwise>
	        <if test="includeTaskLocalVariables">
	          left outer join ${prefix}ACT_HI_VARINST VAR ON RES.ID_ = VAR.TASK_ID_
	        </if>
	        <if test="includeProcessVariables">
	          left outer join ${prefix}ACT_HI_VARINST VAR ON RES.PROC_INST_ID_ = VAR.EXECUTION_ID_
	        </if>
	      </otherwise>
	    </choose>
	    <if test="includeIdentityLinks">
	      left outer join ${prefix}ACT_HI_IDENTITYLINK ILINK on RES.ID_ = ILINK.TASK_ID_
	    </if>
	    <!--查询条件-->
	    <sql id="commonSelectHistoricTaskInstancesByQueryCriteriaSql">
		    <if test="processFinished || processUnfinished || processInstanceBusinessKey != null || processInstanceBusinessKeyLike != null || processInstanceBusinessKeyLikeIgnoreCase != null">
		      inner join ${prefix}ACT_HI_PROCINST HPI ON RES.PROC_INST_ID_ = HPI.ID_
		    </if>
		    <if test="processDefinitionKey != null || processDefinitionKeyLike != null || processDefinitionKeyLikeIgnoreCase != null || processDefinitionName != null || processDefinitionNameLike != null || (processCategoryInList != null &amp;&amp; processCategoryInList.size() &gt; 0) || (processCategoryNotInList != null &amp;&amp; processCategoryNotInList.size() &gt; 0) || (processDefinitionKeys != null &amp;&amp; processDefinitionKeys.size() &gt; 0)">
		      inner join ${prefix}ACT_RE_PROCDEF D on RES.PROC_DEF_ID_ = D.ID_
		    </if>
		    <if test="deploymentId != null || (deploymentIds != null &amp;&amp; deploymentIds.size() &gt; 0)">
		      left outer join ${prefix}ACT_RE_PROCDEF DEPLOY_P ON RES.PROC_DEF_ID_ = DEPLOY_P.ID_
		    </if>
		    <if test="cmmnDeploymentId != null || (cmmnDeploymentIds != null &amp;&amp; cmmnDeploymentIds.size() &gt; 0)">
		      left outer join ${prefix}ACT_CMMN_CASEDEF DEPLOY_C ON RES.SCOPE_DEFINITION_ID_ = DEPLOY_C.ID_
		    </if>
		    <foreach collection="queryVariableValues" index="index" item="var">
		      <if test="!var.operator.equals('EXISTS') &amp;&amp; !var.operator.equals('NOT_EXISTS')">
		          <choose>
		            <when test="var.local">
		              inner join ${prefix}ACT_HI_VARINST A${index} on RES.ID_ = A${index}.TASK_ID_
		            </when>
		            <otherwise>
		              inner join ${prefix}ACT_HI_VARINST A${index} on RES.PROC_INST_ID_ = A${index}.PROC_INST_ID_
		            </otherwise>
		          </choose>
		      </if>
		    </foreach>
		    <foreach collection="orQueryObjects" index="orIndex" item="orQueryObject">
		      <if test="orQueryObject.processFinished || orQueryObject.processUnfinished || orQueryObject.processInstanceBusinessKey != null || orQueryObject.processInstanceBusinessKeyLike != null || orQueryObject.processInstanceBusinessKeyLikeIgnoreCase != null">
		        inner join ${prefix}ACT_HI_PROCINST HPI_OR${orIndex} ON RES.PROC_INST_ID_ = HPI_OR${orIndex}.ID_
		      </if>
		      <if test="orQueryObject.processDefinitionKey != null || orQueryObject.processDefinitionKeyLike != null || orQueryObject.processDefinitionKeyLikeIgnoreCase != null || orQueryObject.processDefinitionName != null || orQueryObject.processDefinitionNameLike != null || (orQueryObject.processCategoryInList != null &amp;&amp; orQueryObject.processCategoryInList.size() &gt; 0) || (orQueryObject.processCategoryNotInList != null &amp;&amp; orQueryObject.processCategoryNotInList.size() &gt; 0) || (orQueryObject.processDefinitionKeys != null &amp;&amp; orQueryObject.processDefinitionKeys.size() &gt; 0)">
		        left outer join ${prefix}ACT_RE_PROCDEF D_OR${orIndex} on RES.PROC_DEF_ID_ = D_OR${orIndex}.ID_
		      </if>
		      <if test="orQueryObject.deploymentId != null || (orQueryObject.deploymentIds != null &amp;&amp; orQueryObject.deploymentIds.size() &gt; 0)">
		        left outer join ${prefix}ACT_RE_PROCDEF DEPLOY_P_OR${orIndex} ON RES.PROC_DEF_ID_ = DEPLOY_P_OR${orIndex}.ID_
		      </if>
		      <if test="orQueryObject.cmmnDeploymentId != null || (orQueryObject.cmmnDeploymentIds != null &amp;&amp; orQueryObject.cmmnDeploymentIds.size() &gt; 0)">
		        left outer join ${prefix}ACT_CMMN_CASEDEF DEPLOY_C_OR${orIndex} ON RES.SCOPE_DEFINITION_ID_ = DEPLOY_C_OR${orIndex}.ID_
		      </if>
		      <if test="orQueryObject.queryVariableValues.size() &gt; 0">
		        <if test="orQueryObject.hasValueComparisonQueryVariables()">
		            <if test="orQueryObject.hasLocalQueryVariableValue()">
		              left outer join ${prefix}ACT_HI_VARINST A_L_OR${orIndex} on RES.ID_ = A_L_OR${orIndex}.TASK_ID_
		            </if>
		            <if test="orQueryObject.hasNonLocalQueryVariableValue()">
		              left outer join ${prefix}ACT_HI_VARINST A_OR${orIndex} on RES.PROC_INST_ID_ = A_OR${orIndex}.PROC_INST_ID_
		            </if>
		        </if>
		      </if>
		    </foreach>
		    <where>
		      <if test="taskId != null">
		        RES.ID_ = #{taskId}
		      </if>
		      <if test="taskDefinitionId != null">
		        and RES.TASK_DEF_ID_ = #{taskDefinitionId}
		      </if>
		      <if test="processDefinitionId != null">
		        and RES.PROC_DEF_ID_ = #{processDefinitionId}
		      </if>
		      <if test="processDefinitionKey != null">
		        and D.KEY_ = #{processDefinitionKey}
		      </if>
		      <if test="processDefinitionKeyLike != null">
		        and D.KEY_ like #{processDefinitionKeyLike}${wildcardEscapeClause}
		      </if>
		       <if test="processDefinitionKeyLikeIgnoreCase != null">
		        and lower(D.KEY_) like #{processDefinitionKeyLikeIgnoreCase}${wildcardEscapeClause}
		      </if>
		      <if test="processDefinitionKeys != null &amp;&amp; processDefinitionKeys.size() &gt; 0">
		        and D.KEY_ in
		        <foreach item="item" index="index" collection="processDefinitionKeys" open="(" separator="," close=")">
		          #{item}
		        </foreach>
		      </if>
		      <if test="processDefinitionName != null">
		        and D.NAME_ = #{processDefinitionName}
		      </if>
		      <if test="processDefinitionNameLike != null">
		        and D.NAME_ like #{processDefinitionNameLike}${wildcardEscapeClause}
		      </if>
		      <if test="processCategoryInList != null &amp;&amp; processCategoryInList.size() &gt; 0">
		        and D.CATEGORY_ IN
		        <foreach item="processCategory" index="index" collection="processCategoryInList"
		                 open="(" separator="," close=")">
		          #{processCategory}
		        </foreach>
		      </if>
		      <if test="processCategoryNotInList != null &amp;&amp; processCategoryNotInList.size() &gt; 0">
		        and D.CATEGORY_ NOT IN
		        <foreach item="processCategory" index="index" collection="processCategoryNotInList"
		                 open="(" separator="," close=")">
		          #{processCategory}
		        </foreach>
		      </if>
		      <if test="deploymentId != null &amp;&amp; cmmnDeploymentId == null">
		        and DEPLOY_P.DEPLOYMENT_ID_ = #{deploymentId}
		      </if>
		      <if test="deploymentIds != null &amp;&amp; deploymentIds.size() &gt; 0 &amp;&amp; cmmnDeploymentIds == null">
		        and DEPLOY_P.DEPLOYMENT_ID_ IN
		        <foreach item="deployment" index="index" collection="deploymentIds"
		                 open="(" separator="," close=")">
		          #{deployment}
		        </foreach>
		      </if>
		      <if test="cmmnDeploymentId != null &amp;&amp; deploymentId == null">
		        and DEPLOY_C.DEPLOYMENT_ID_ = #{cmmnDeploymentId}
		      </if>
		      <if test="cmmnDeploymentIds != null &amp;&amp; cmmnDeploymentIds.size() &gt; 0 &amp;&amp; deploymentIds == null">
		        and DEPLOY_C.DEPLOYMENT_ID_ IN
		        <foreach item="deployment" index="index" collection="cmmnDeploymentIds"
		                 open="(" separator="," close=")">
		          #{deployment}
		        </foreach>
		      </if>
		      <if test="deploymentId != null &amp;&amp; cmmnDeploymentId != null">
		        and (DEPLOY_P.DEPLOYMENT_ID_ = #{deploymentId} or DEPLOY_C.DEPLOYMENT_ID = #{cmmnDeploymentId})
		      </if>
		      <if test="cmmnDeploymentIds != null &amp;&amp; cmmnDeploymentIds.size() &gt; 0 &amp;&amp; deploymentIds != null &amp;&amp; deploymentIds.size() &gt; 0">
		        and (
		            DEPLOY_P.DEPLOYMENT_ID_ IN
		            <foreach item="deployment" index="index" collection="deploymentIds" open="(" separator="," close=")">
		                #{deployment}
		            </foreach>
		            or
		            DEPLOY_C.DEPLOYMENT_ID_ IN
		            <foreach item="cmmnDeployment" index="index" collection="cmmnDeploymentIds" open="(" separator="," close=")">
		                #{cmmnDeployment}
		            </foreach>
		        )
		      </if>
		      <if test="processInstanceId != null">
		        and RES.PROC_INST_ID_ = #{processInstanceId}
		      </if>
		      <if test="processInstanceIds != null &amp;&amp; processInstanceIds.size() &gt; 0">
		        and RES.PROC_INST_ID_ IN
		        <foreach item="processInstance" index="index" collection="processInstanceIds"
		                 open="(" separator="," close=")">
		          #{processInstance}
		        </foreach>
		      </if>
		      <if test="processInstanceBusinessKey != null">
		        and HPI.BUSINESS_KEY_ = #{processInstanceBusinessKey}
		      </if>
		      <if test="processInstanceBusinessKeyLike != null">
		        and HPI.BUSINESS_KEY_ like #{processInstanceBusinessKeyLike}${wildcardEscapeClause}
		      </if>
		      <if test="processInstanceBusinessKeyLikeIgnoreCase != null">
		        and lower(HPI.BUSINESS_KEY_) like #{processInstanceBusinessKeyLikeIgnoreCase}${wildcardEscapeClause}
		      </if>
		      <if test="taskDefinitionKey != null">
		        and RES.TASK_DEF_KEY_ = #{taskDefinitionKey}
		      </if>
		      <if test="taskDefinitionKeyLike != null">
		        and RES.TASK_DEF_KEY_ like #{taskDefinitionKeyLike}${wildcardEscapeClause}
		      </if>
		      <if test="executionId != null">
		        and RES.EXECUTION_ID_ = #{executionId}
		      </if>
		      <if test="scopeId != null">
		        and RES.SCOPE_ID_ = #{scopeId}
		      </if>
		      <if test="subScopeId != null">
		        and RES.SUB_SCOPE_ID_ = #{subScopeId}
		      </if>
		      <if test="scopeType != null">
		        and RES.SCOPE_TYPE_ = #{scopeType}
		      </if>
		      <if test="scopeDefinitionId != null">
		        and RES.SCOPE_DEFINITION_ID_ = #{scopeDefinitionId}
		      </if>
		      <if test="processInstanceIdWithChildren != null">
		        and exists(select ELINK.ID_ from ${prefix}ACT_HI_ENTITYLINK ELINK where ELINK.LINK_TYPE_ = 'child' and
		            ELINK.SCOPE_ID_ = #{processInstanceIdWithChildren} AND ELINK.SCOPE_TYPE_ = 'bpmn' and
		            ELINK.REF_SCOPE_ID_ = RES.ID_ and ELINK.REF_SCOPE_TYPE_ = 'task')
		      </if>
		      <if test="caseInstanceIdWithChildren != null">
		        and exists(select ELINK.ID_ from ${prefix}ACT_HI_ENTITYLINK ELINK where ELINK.LINK_TYPE_ = 'child' and
		            ELINK.SCOPE_ID_ = #{caseInstanceIdWithChildren} AND ELINK.SCOPE_TYPE_ = 'cmmn' and
		            ELINK.REF_SCOPE_ID_ = RES.ID_ and ELINK.REF_SCOPE_TYPE_ = 'task')
		      </if>
		      <if test="taskName != null">
		        and RES.NAME_ = #{taskName}
		      </if>
		      <if test="taskNameLike != null">
		        and RES.NAME_ like #{taskNameLike}${wildcardEscapeClause}
		      </if>
		      <if test="taskNameLikeIgnoreCase != null">
		        and lower(RES.NAME_) like #{taskNameLikeIgnoreCase}${wildcardEscapeClause}
		      </if>
		      <if test="taskNameList != null &amp;&amp; taskNameList.size() &gt; 0">
		        and RES.NAME_ IN
		        <foreach item="taskName" index="index" collection="taskNameList"
		                 open="(" separator="," close=")">
		          #{taskName}
		        </foreach>
		      </if>
		      <if test="taskNameListIgnoreCase != null &amp;&amp; taskNameListIgnoreCase.size() &gt; 0">
		        and lower(RES.NAME_) IN
		        <foreach item="taskName" index="index" collection="taskNameListIgnoreCase"
		                 open="(" separator="," close=")">
		          #{taskName}
		        </foreach>
		      </if>
		      <if test="taskParentTaskId != null">
		        and RES.PARENT_TASK_ID_ = #{taskParentTaskId}
		      </if>
		      <if test="taskDescription != null">
		        and RES.DESCRIPTION_ = #{taskDescription}
		      </if>
		      <if test="taskDescriptionLike != null">
		        and RES.DESCRIPTION_ like #{taskDescriptionLike}${wildcardEscapeClause}
		      </if>
		      <if test="taskDescriptionLikeIgnoreCase != null">
		        and lower(RES.DESCRIPTION_) like #{taskDescriptionLikeIgnoreCase}${wildcardEscapeClause}
		      </if>
		      <if test="taskDeleteReason != null">
		        and RES.DELETE_REASON_ = #{taskDeleteReason}
		      </if>
		      <if test="taskDeleteReasonLike != null">
		        and RES.DELETE_REASON_ like #{taskDeleteReasonLike}${wildcardEscapeClause}
		      </if>
		      <if test="taskOwner != null">
		        and RES.OWNER_ = #{taskOwner}
		      </if>
		      <if test="taskOwnerLike != null">
		        and RES.OWNER_ like #{taskOwnerLike}${wildcardEscapeClause}
		      </if>
		      <if test="taskOwnerLikeIgnoreCase != null">
		        and lower(RES.OWNER_) like #{taskOwnerLikeIgnoreCase}${wildcardEscapeClause}
		      </if>
		      <if test="taskAssignee != null">
		        and RES.ASSIGNEE_ = #{taskAssignee}
		      </if>
		      <if test="taskAssigneeLike != null">
		        and RES.ASSIGNEE_ like #{taskAssigneeLike}${wildcardEscapeClause}
		      </if>
		      <if test="taskAssigneeLikeIgnoreCase != null">
		        and lower(RES.ASSIGNEE_) like #{taskAssigneeLikeIgnoreCase}${wildcardEscapeClause}
		      </if>
		      <if test="taskAssigneeIds != null &amp;&amp; taskAssigneeIds.size() &gt; 0">
		        and RES.ASSIGNEE_ IN
		        <foreach item="assigneeId" index="index" collection="taskAssigneeIds"
		                 open="(" separator="," close=")">
		          #{assigneeId}
		        </foreach>
		      </if>
		      <if test="taskPriority != null">
		        and RES.PRIORITY_ = #{taskPriority}
		      </if>
		      <if test="taskMinPriority != null">
		        and RES.PRIORITY_ &gt;= #{taskMinPriority}
		      </if>
		      <if test="taskMaxPriority != null">
		        and RES.PRIORITY_ &lt;= #{taskMaxPriority}
		      </if>
		      <if test="unfinished">
		        and RES.END_TIME_ is null
		      </if>
		      <if test="finished">
		        and RES.END_TIME_ is not null
		      </if>
		      <if test="processFinished">
		        and HPI.END_TIME_ is not null
		      </if>
		      <if test="processUnfinished">
		        and HPI.END_TIME_ is null
		      </if>
		      <if test="dueDate != null">
		        and RES.DUE_DATE_ = #{dueDate}
		      </if>
		      <if test="dueBefore != null">
		        and RES.DUE_DATE_ &lt; #{dueBefore}
		      </if>
		      <if test="dueAfter != null">
		        and RES.DUE_DATE_ &gt; #{dueAfter}
		      </if>
		      <if test="withoutDueDate">
		        and RES.DUE_DATE_ is null
		      </if>
		      <if test="creationDate != null">
		        and RES.START_TIME_ = #{creationDate}
		      </if>
		      <if test="creationBeforeDate != null">
		        and RES.START_TIME_ &lt; #{creationBeforeDate}
		      </if>
		      <if test="creationAfterDate != null">
		        and RES.START_TIME_ &gt; #{creationAfterDate}
		      </if>
		      <if test="completedDate != null">
		        and RES.END_TIME_ = #{completedDate}
		      </if>
		      <if test="completedBeforeDate != null">
		        and RES.END_TIME_ &lt; #{completedBeforeDate}
		      </if>
		      <if test="completedAfterDate != null">
		        and RES.END_TIME_ &gt; #{completedAfterDate}
		      </if>
		      <if test="category != null">
		        and RES.CATEGORY_ = #{category}
		      </if>
		      <if test="withFormKey">
		        and RES.FORM_KEY_ IS NOT NULL
		      </if>
		      <if test="formKey != null">
		        and RES.FORM_KEY_ = #{formKey}
		      </if>
		      <if test="tenantId != null">
		        and RES.TENANT_ID_ = #{tenantId}
		      </if>
		      <if test="tenantIdLike != null">
		        and RES.TENANT_ID_ like #{tenantIdLike}${wildcardEscapeClause}
		      </if>
		      <if test="withoutTenantId">
		        and (RES.TENANT_ID_ = '' or RES.TENANT_ID_ is null)
		      </if>
		      <if test="withoutDeleteReason">
		        and (RES.DELETE_REASON_ = '' or RES.DELETE_REASON_ is null)
		      </if>
		      <if test="candidateUser != null || candidateGroups != null">
		        <if test="!ignoreAssigneeValue">
		            and RES.ASSIGNEE_ is null
		        </if>
		        and EXISTS(select LINK.ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where LINK.TYPE_ = 'candidate' and LINK.TASK_ID_ = RES.ID_
		            and
		            (
		              <if test="candidateUser != null">
		                LINK.USER_ID_ = #{candidateUser}
		              </if>
		              <if test="candidateUser != null &amp;&amp; candidateGroups != null &amp;&amp; candidateGroups.size() &gt; 0">
		                or
		              </if>
		              <if test="candidateGroups != null &amp;&amp; candidateGroups.size() &gt; 0">
		                LINK.GROUP_ID_ IN
		                <foreach item="group" index="index" collection="candidateGroups"
		                         open="(" separator="," close=")">
		                  #{group}
		                </foreach>
		              </if>
		            )
		        )
		      </if>
		      <if test="involvedUser != null">
		        and (
		          EXISTS(select LINK.ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where LINK.USER_ID_ = #{involvedUser} and LINK.TASK_ID_ = RES.ID_)
		          or RES.ASSIGNEE_ = #{involvedUser}
		          or RES.OWNER_ = #{involvedUser}
		          )
		      </if>
		      <if test="involvedGroups != null">
		        and EXISTS(select LINK.ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where LINK.TASK_ID_ = RES.ID_ and LINK.GROUP_ID_ in
		        <foreach item="involvedGroup" index="index" collection="involvedGroups" open="(" separator="," close=")">
		          #{involvedGroup}
		        </foreach>
		        )
		      </if>
		      <foreach item="queryVar" collection="queryVariableValues" index="index">
		        <choose>
		            <when test="queryVar.operator.equals('EXISTS')">
		              and EXISTS (
		                select ID_ from ${prefix}ACT_HI_VARINST where NAME_ = #{queryVar.name}
		                <if test="!queryVar.local">
		                    and RES.PROC_INST_ID_ = PROC_INST_ID_ and TASK_ID_ is null
		                </if>
		                <if test="queryVar.local">
		                    and RES.ID_ = TASK_ID_
		                </if>
		              )
		            </when>
		            <when test="queryVar.operator.equals('NOT_EXISTS')">
		              and NOT EXISTS (
		                select ID_ from ${prefix}ACT_HI_VARINST where NAME_ = #{queryVar.name}
		                <if test="!queryVar.local">
		                    and RES.PROC_INST_ID_ = PROC_INST_ID_ and TASK_ID_ is null
		                </if>
		                <if test="queryVar.local">
		                    and RES.ID_ = TASK_ID_
		                </if>
		              )
		            </when>
		            <otherwise>
		                <if test="!queryVar.local">
		                  <!-- When process instance variable is queried for, taskId should be null -->
		                  and A${index}.TASK_ID_ is null
		                </if>
		                <if test="queryVar.name != null">
		                  <!-- Match-all variable-names when name is null -->
		                  and A${index}.NAME_= #{queryVar.name}
		                </if>
		                <if test="!queryVar.type.equals('null')">
		                  and A${index}.VAR_TYPE_ = #{queryVar.type}
		                </if>
		                <!-- Variable value -->
		                <if test="queryVar.textValue != null &amp;&amp; queryVar.longValue == null &amp;&amp; queryVar.doubleValue == null">
		                  <choose>
		                    <when test="queryVar.operator.equals('EQUALS_IGNORE_CASE') || queryVar.operator.equals('NOT_EQUALS_IGNORE_CASE') || queryVar.operator.equals('LIKE_IGNORE_CASE')">
		                      and lower(A${index}.TEXT_)
		                    </when>
		                    <otherwise>
		                      and A${index}.TEXT_
		                    </otherwise>
		                  </choose>
		                  <choose>
		                      <when test="queryVar.operator.equals('LIKE') || queryVar.operator.equals('LIKE_IGNORE_CASE')">LIKE</when>
		                      <otherwise><include refid="executionVariableOperator" /></otherwise>
		                  </choose>
		                  #{queryVar.textValue}
		                  <choose>
		        			<when test="queryVar.operator.equals('LIKE') || queryVar.operator.equals('LIKE_IGNORE_CASE')">${wildcardEscapeClause}</when>
		        		  </choose>
		                </if>
		                <if test="queryVar.textValue2 != null">
		                  and A${index}.TEXT2_
		                  <choose>
		                    <when test="queryVar.operator.equals('LIKE')">LIKE</when>
		                    <otherwise><include refid="executionVariableOperator" /></otherwise>
		                  </choose>
		                  #{queryVar.textValue2}
		                  <choose>
		        			<when test="queryVar.operator.equals('LIKE')">${wildcardEscapeClause}</when>
		        		  </choose>
		                </if>
		                <if test="queryVar.longValue != null">
		                  and A${index}.LONG_
		                  <include refid="executionVariableOperator" />
		                  #{queryVar.longValue}
		                </if>
		                <if test="queryVar.doubleValue != null">
		                  and A${index}.DOUBLE_
		                  <include refid="executionVariableOperator" />
		                  #{queryVar.doubleValue}
		                </if>
		                <!-- Null variable type -->
		                <if test="queryVar.textValue == null &amp;&amp; queryVar.textValue2 == null &amp;&amp; queryVar.longValue == null &amp;&amp; queryVar.doubleValue == null">
		                  <choose>
		                    <when test="queryVar.operator.equals('NOT_EQUALS')">
		                      and (A${index}.TEXT_ is not null or A${index}.TEXT2_ is not null or A${index}.LONG_ is not null or A${index}.DOUBLE_ is not null or A${index}.BYTEARRAY_ID_ is not null)
		                    </when>
		                    <otherwise>
		                      and A${index}.TEXT_ is null and A${index}.TEXT2_ is null and A${index}.LONG_ is null and A${index}.DOUBLE_ is null and A${index}.BYTEARRAY_ID_ is null
		                    </otherwise>
		                  </choose>
		                </if>
		            </otherwise>
		        </choose>
		      </foreach>
		      <foreach item="orQueryObject" index="orIndex" collection="orQueryObjects">
		        and
		        <trim prefix="(" prefixOverrides="OR" suffix=")">
		          <if test="orQueryObject.taskId != null">
		            RES.ID_ = #{orQueryObject.taskId}
		          </if>
		          <if test="orQueryObject.taskDefinitionId != null">
		            or RES.TASK_DEF_ID_ = #{orQueryObject.taskDefinitionId}
		          </if>
		          <if test="orQueryObject.processDefinitionId != null">
		            or RES.PROC_DEF_ID_ = #{orQueryObject.processDefinitionId}
		          </if>
		          <if test="orQueryObject.processDefinitionKey != null">
		            or D_OR${orIndex}.KEY_ = #{orQueryObject.processDefinitionKey}
		          </if>
		          <if test="orQueryObject.processDefinitionKeyLike != null">
		            or D_OR${orIndex}.KEY_ like #{orQueryObject.processDefinitionKeyLike}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.processDefinitionKeyLikeIgnoreCase != null">
		            or lower(D_OR${orIndex}.KEY_) like #{orQueryObject.processDefinitionKeyLikeIgnoreCase}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.processDefinitionKeys != null &amp;&amp; orQueryObject.processDefinitionKeys.size() &gt; 0">
		            or D_OR${orIndex}.KEY_ in
		            <foreach item="item" index="index" collection="orQueryObject.processDefinitionKeys" open="(" separator="," close=")">
		              #{item}
		            </foreach>
		          </if>
		          <if test="orQueryObject.processDefinitionName != null">
		            or D_OR${orIndex}.NAME_ = #{orQueryObject.processDefinitionName}
		          </if>
		          <if test="orQueryObject.processDefinitionNameLike != null">
		            or D_OR${orIndex}.NAME_ like #{orQueryObject.processDefinitionNameLike}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.processCategoryInList != null &amp;&amp; orQueryObject.processCategoryInList.size() &gt; 0">
		            or D_OR${orIndex}.CATEGORY_ IN
		            <foreach item="processCategory" index="index" collection="orQueryObject.processCategoryInList"
		                     open="(" separator="," close=")">
		              #{processCategory}
		            </foreach>
		          </if>
		          <if test="orQueryObject.processCategoryNotInList != null &amp;&amp; orQueryObject.processCategoryNotInList.size() &gt; 0">
		            or D_OR${orIndex}.CATEGORY_ NOT IN
		            <foreach item="processCategory" index="index" collection="orQueryObject.processCategoryNotInList"
		                     open="(" separator="," close=")">
		              #{processCategory}
		            </foreach>
		          </if>
		          <if test="orQueryObject.deploymentId != null">
		            or DEPLOY_P_OR${orIndex}.DEPLOYMENT_ID_ = #{orQueryObject.deploymentId}
		          </if>
		          <if test="orQueryObject.deploymentIds != null &amp;&amp; orQueryObject.deploymentIds.size() &gt; 0">
		            or DEPLOY_P_OR${orIndex}.DEPLOYMENT_ID_ IN
		            <foreach item="deployment" index="index" collection="orQueryObject.deploymentIds"
		                     open="(" separator="," close=")">
		              #{deployment}
		            </foreach>
		          </if>
		          <if test="orQueryObject.cmmnDeploymentId != null">
		            or DEPLOY_C_OR${orIndex}.DEPLOYMENT_ID_ = #{orQueryObject.cmmnDeploymentId}
		          </if>
		          <if test="orQueryObject.cmmnDeploymentIds != null &amp;&amp; orQueryObject.cmmnDeploymentIds.size() &gt; 0">
		            or DEPLOY_C_OR${orIndex}.DEPLOYMENT_ID_ IN
		            <foreach item="deployment" index="index" collection="orQueryObject.cmmnDeploymentIds"
		                     open="(" separator="," close=")">
		              #{deployment}
		            </foreach>
		          </if>
		          <if test="orQueryObject.processInstanceId != null">
		            or RES.PROC_INST_ID_ = #{orQueryObject.processInstanceId}
		          </if>
		          <if test="orQueryObject.processInstanceIds != null &amp;&amp; orQueryObject.processInstanceIds.size() &gt; 0">
		            or RES.PROC_INST_ID_ IN
		            <foreach item="processInstance" index="index" collection="orQueryObject.processInstanceIds"
		                     open="(" separator="," close=")">
		              #{processInstance}
		            </foreach>
		          </if>
		          <if test="orQueryObject.processInstanceBusinessKey != null">
		            or HPI_OR${orIndex}.BUSINESS_KEY_ = #{orQueryObject.processInstanceBusinessKey}
		          </if>
		          <if test="orQueryObject.processInstanceBusinessKeyLike != null">
		            or HPI_OR${orIndex}.BUSINESS_KEY_ like #{orQueryObject.processInstanceBusinessKeyLike}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.processInstanceBusinessKeyLikeIgnoreCase != null">
		            or lower(HPI_OR${orIndex}.BUSINESS_KEY_) like #{orQueryObject.processInstanceBusinessKeyLikeIgnoreCase}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.taskDefinitionKey != null">
		            or RES.TASK_DEF_KEY_ = #{orQueryObject.taskDefinitionKey}
		          </if>
		          <if test="orQueryObject.taskDefinitionKeyLike != null">
		            or RES.TASK_DEF_KEY_ like #{orQueryObject.taskDefinitionKeyLike}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.executionId != null">
		            or RES.EXECUTION_ID_ = #{orQueryObject.executionId}
		          </if>
		          <if test="orQueryObject.scopeId != null">
		            or RES.SCOPE_ID_ = #{orQueryObject.scopeId}
		          </if>
		          <if test="orQueryObject.subScopeId != null">
		            or RES.SUB_SCOPE_ID_ = #{orQueryObject.subScopeId}
		          </if>
		          <if test="orQueryObject.scopeType != null">
		            or RES.SCOPE_TYPE_ = #{orQueryObject.scopeType}
		          </if>
		          <if test="orQueryObject.scopeDefinitionId != null">
		            or RES.SCOPE_DEFINITION_ID_ = #{orQueryObject.scopeDefinitionId}
		          </if>
		          <if test="orQueryObject.processInstanceIdWithChildren != null">
		            or exists(select ELINK.ID_ from ${prefix}ACT_HI_ENTITYLINK ELINK where ELINK.LINK_TYPE_ = 'child' and
		                ELINK.SCOPE_ID_ = #{orQueryObject.processInstanceIdWithChildren} AND ELINK.SCOPE_TYPE_ = 'bpmn' and
		                ELINK.REF_SCOPE_ID_ = RES.ID_ and ELINK.REF_SCOPE_TYPE_ = 'task')
		          </if>
		          <if test="orQueryObject.caseInstanceIdWithChildren != null">
		            or exists(select ELINK.ID_ from ${prefix}ACT_HI_ENTITYLINK ELINK where ELINK.LINK_TYPE_ = 'child' and
		                ELINK.SCOPE_ID_ = #{orQueryObject.caseInstanceIdWithChildren} AND ELINK.SCOPE_TYPE_ = 'cmmn' and
		                ELINK.REF_SCOPE_ID_ = RES.ID_ and ELINK.REF_SCOPE_TYPE_ = 'task')
		          </if>
		          <if test="orQueryObject.taskName != null">
		            or RES.NAME_ = #{orQueryObject.taskName}
		          </if>
		          <if test="orQueryObject.taskNameLike != null">
		            or RES.NAME_ like #{orQueryObject.taskNameLike}${wildcardEscapeClause}
		          </if>
		           <if test="orQueryObject.taskNameLikeIgnoreCase != null">
		            or lower(RES.NAME_) like #{orQueryObject.taskNameLikeIgnoreCase}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.taskNameList != null &amp;&amp; orQueryObject.taskNameList.size() &gt; 0">
		            or RES.NAME_ IN
		            <foreach item="taskName" index="index" collection="orQueryObject.taskNameList"
		                     open="(" separator="," close=")">
		              #{taskName}
		            </foreach>
		          </if>
		          <if test="orQueryObject.taskNameListIgnoreCase != null &amp;&amp; orQueryObject.taskNameListIgnoreCase.size() &gt; 0">
		            or lower(RES.NAME_) IN
		            <foreach item="taskName" index="index" collection="orQueryObject.taskNameListIgnoreCase"
		                     open="(" separator="," close=")">
		              #{taskName}
		            </foreach>
		          </if>
		          <if test="orQueryObject.taskParentTaskId != null">
		            or RES.PARENT_TASK_ID_ = #{orQueryObject.taskParentTaskId}
		          </if>
		          <if test="orQueryObject.taskDescription != null">
		            or RES.DESCRIPTION_ = #{orQueryObject.taskDescription}
		          </if>
		          <if test="orQueryObject.taskDescriptionLike != null">
		            or RES.DESCRIPTION_ like #{orQueryObject.taskDescriptionLike}${wildcardEscapeClause}
		          </if>
		           <if test="orQueryObject.taskDescriptionLikeIgnoreCase != null">
		            or lower(RES.DESCRIPTION_) like #{orQueryObject.taskDescriptionLikeIgnoreCase}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.taskDeleteReason != null">
		            or RES.DELETE_REASON_ = #{orQueryObject.taskDeleteReason}
		          </if>
		          <if test="orQueryObject.taskDeleteReasonLike != null">
		            or RES.DELETE_REASON_ like #{orQueryObject.taskDeleteReasonLike}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.taskOwner != null">
		            or RES.OWNER_ = #{orQueryObject.taskOwner}
		          </if>
		          <if test="orQueryObject.taskOwnerLike != null">
		            or RES.OWNER_ like #{orQueryObject.taskOwnerLike}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.taskOwnerLikeIgnoreCase != null">
		            or lower(RES.OWNER_) like #{orQueryObject.taskOwnerLikeIgnoreCase}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.taskAssignee != null">
		            or RES.ASSIGNEE_ = #{orQueryObject.taskAssignee}
		          </if>
		          <if test="orQueryObject.taskAssigneeLike != null">
		            or RES.ASSIGNEE_ like #{orQueryObject.taskAssigneeLike}${wildcardEscapeClause}
		          </if>
		           <if test="orQueryObject.taskAssigneeLikeIgnoreCase != null">
		            or RES.ASSIGNEE_ like #{orQueryObject.taskAssigneeLikeIgnoreCase}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.taskAssigneeIds != null &amp;&amp; orQueryObject.taskAssigneeIds.size() &gt; 0">
			        or RES.ASSIGNEE_ IN
			        <foreach item="assigneeId" index="index" collection="orQueryObject.taskAssigneeIds"
			                 open="(" separator="," close=")">
			          #{assigneeId}
			        </foreach>
			      </if>
		          <if test="orQueryObject.taskPriority != null">
		            or RES.PRIORITY_ = #{orQueryObject.taskPriority}
		          </if>
		          <if test="orQueryObject.taskMinPriority != null">
		            or RES.PRIORITY_ &gt;= #{orQueryObject.taskMinPriority}
		          </if>
		          <if test="orQueryObject.taskMaxPriority != null">
		            or RES.PRIORITY_ &lt;= #{orQueryObject.taskMaxPriority}
		          </if>
		          <if test="orQueryObject.unfinished">
		            or RES.END_TIME_ is null
		          </if>
		          <if test="orQueryObject.finished">
		            or RES.END_TIME_ is not null
		          </if>
		          <if test="orQueryObject.processFinished">
		            or HPI_OR${orIndex}.END_TIME_ is not null
		          </if>
		          <if test="orQueryObject.processUnfinished">
		            or HPI_OR${orIndex}.END_TIME_ is null
		          </if>
		          <if test="orQueryObject.dueDate != null">
		            or RES.DUE_DATE_ = #{orQueryObject.dueDate}
		          </if>
		          <if test="orQueryObject.dueBefore != null">
		            or RES.DUE_DATE_ &lt; #{orQueryObject.dueBefore}
		          </if>
		          <if test="orQueryObject.dueAfter != null">
		            or RES.DUE_DATE_ &gt; #{orQueryObject.dueAfter}
		          </if>
		          <if test="orQueryObject.withoutDueDate">
		            or RES.DUE_DATE_ is null
		          </if>
		          <if test="orQueryObject.creationDate != null">
		            or RES.START_TIME_ = #{orQueryObject.creationDate}
		          </if>
		          <if test="orQueryObject.creationBeforeDate != null">
		            or RES.START_TIME_ &lt; #{orQueryObject.creationBeforeDate}
		          </if>
		          <if test="orQueryObject.creationAfterDate != null">
		            or RES.START_TIME_ &gt; #{orQueryObject.creationAfterDate}
		          </if>
		          <if test="orQueryObject.completedDate != null">
		            or RES.END_TIME_ = #{orQueryObject.completedDate}
		          </if>
		          <if test="orQueryObject.completedBeforeDate != null">
		            or RES.END_TIME_ &lt; #{orQueryObject.completedBeforeDate}
		          </if>
		          <if test="orQueryObject.completedAfterDate != null">
		            or RES.END_TIME_ &gt; #{orQueryObject.completedAfterDate}
		          </if>
		          <if test="orQueryObject.category != null">
		            or RES.CATEGORY_ = #{orQueryObject.category}
		          </if>
		          <if test="orQueryObject.withFormKey">
		            or RES.FORM_KEY_ IS NOT NULL
		          </if>
		          <if test="orQueryObject.formKey != null">
		            or RES.FORM_KEY_ = #{orQueryObject.formKey}
		          </if>
		          <if test="orQueryObject.tenantId != null">
		            or RES.TENANT_ID_ = #{orQueryObject.tenantId}
		          </if>
		          <if test="orQueryObject.tenantIdLike != null">
		            or RES.TENANT_ID_ like #{orQueryObject.tenantIdLike}${wildcardEscapeClause}
		          </if>
		          <if test="orQueryObject.withoutTenantId">
		            or (RES.TENANT_ID_ = '' or RES.TENANT_ID_ is null)
		          </if>
		          <if test="orQueryObject.withoutDeleteReason">
		            or (RES.DELETE_REASON_ = '' or RES.DELETE_REASON_ is null)
		          </if>
		          <if test="orQueryObject.candidateUser != null || orQueryObject.candidateGroups != null">
		            or (EXISTS(select LINK.ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where LINK.TYPE_ = 'candidate' and LINK.TASK_ID_ = RES.ID_
		                and
		                (
		                  <if test="orQueryObject.candidateUser != null">
		                    LINK.USER_ID_ = #{orQueryObject.candidateUser}
		                  </if>
		                  <if test="orQueryObject.candidateUser != null &amp;&amp; orQueryObject.candidateGroups != null &amp;&amp; orQueryObject.candidateGroups.size() &gt; 0">
		                    or
		                  </if>
		                  <if test="orQueryObject.candidateGroups != null &amp;&amp; orQueryObject.candidateGroups.size() &gt; 0">
		                    LINK.GROUP_ID_ IN
		                    <foreach item="group" index="index" collection="orQueryObject.candidateGroups"
		                             open="(" separator="," close=")">
		                      #{group}
		                    </foreach>
		                  </if>
		                )
		              )
		            <if test="!orQueryObject.ignoreAssigneeValue">
		                and RES.ASSIGNEE_ is null
		            </if>
		            )
		          </if>
		          <if test="orQueryObject.involvedUser != null">
		            or (
		              EXISTS(select LINK.ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where LINK.USER_ID_ = #{orQueryObject.involvedUser} and LINK.TASK_ID_ = RES.ID_)
		              or RES.ASSIGNEE_ = #{orQueryObject.involvedUser}
		              or RES.OWNER_ = #{orQueryObject.involvedUser}
		              )
		          </if>
		          <if test="orQueryObject.involvedGroups != null">
		            or
		              EXISTS(select ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where LINK.TASK_ID_ = RES.ID_ and LINK.GROUP_ID_ in
		              <foreach item="involvedGroup" index="index" collection="orQueryObject.involvedGroups" open="(" separator="," close=")">
		                #{involvedGroup}
		              </foreach>
		              )
		          </if>
		          <foreach item="queryVar" collection="orQueryObject.queryVariableValues" index="index">
		            or
		            <trim prefix="(" prefixOverrides="AND" suffix=")">
		              <choose>
		                <when test="queryVar.operator.equals('EXISTS')">
		                    and EXISTS (
		                        select ID_ from ${prefix}ACT_HI_VARINST where NAME_ = #{queryVar.name}
		                    <if test="!queryVar.local">
		                        and RES.PROC_INST_ID_ = PROC_INST_ID_ and TASK_ID_ is null
		                    </if>
		                    <if test="queryVar.local">
		                        and RES.ID_ = TASK_ID_
		                    </if>
		                    )
		                </when>
		                <when test="queryVar.operator.equals('NOT_EXISTS')">
		                    and NOT EXISTS (
		                        select ID_ from ${prefix}ACT_HI_VARINST where NAME_ = #{queryVar.name}
		                    <if test="!queryVar.local">
		                        and RES.PROC_INST_ID_ = PROC_INST_ID_ and TASK_ID_ is null
		                    </if>
		                    <if test="queryVar.local">
		                        and RES.ID_ = TASK_ID_
		                    </if>
		                    )
		                </when>
		                <otherwise>
		                  <choose>
		                    <when test="!queryVar.local">
		                      <bind name="orLocal" value="''" />
		                      <!-- When process instance variable is queried for, taskId should be null -->
		                      and A_OR${orIndex}.TASK_ID_ is null
		                    </when>
		                    <otherwise>
		                      <bind name="orLocal" value="'L_'" />
		                    </otherwise>
		                  </choose>
		                  <if test="queryVar.name != null">
		                    <!-- Match-all variable-names when name is null -->
		                    and A_${orLocal}OR${orIndex}.NAME_= #{queryVar.name}
		                  </if>
		                  <if test="!queryVar.type.equals('null')">
		                    and A_${orLocal}OR${orIndex}.VAR_TYPE_ = #{queryVar.type}
		                  </if>
		                  <!-- Variable value -->
		                  <if test="queryVar.textValue != null &amp;&amp; queryVar.longValue == null &amp;&amp; queryVar.doubleValue == null">
		                    <choose>
		                      <when test="queryVar.operator.equals('EQUALS_IGNORE_CASE') || queryVar.operator.equals('NOT_EQUALS_IGNORE_CASE') || queryVar.operator.equals('LIKE_IGNORE_CASE')">
		                        and lower(A_${orLocal}OR${orIndex}.TEXT_)
		                      </when>
		                      <otherwise>
		                        and A_${orLocal}OR${orIndex}.TEXT_
		                      </otherwise>
		                    </choose>
		                    <choose>
		                        <when test="queryVar.operator.equals('LIKE') || queryVar.operator.equals('LIKE_IGNORE_CASE')">LIKE</when>
		                        <otherwise><include refid="executionVariableOperator" /></otherwise>
		                    </choose>
		                    #{queryVar.textValue}
		                    <choose>
		                      <when test="queryVar.operator.equals('LIKE') || queryVar.operator.equals('LIKE_IGNORE_CASE')">${wildcardEscapeClause}</when>
		                    </choose>
		                  </if>
		                  <if test="queryVar.textValue2 != null">
		                    and A_${orLocal}OR${orIndex}.TEXT2_
		                    <choose>
		                      <when test="queryVar.operator.equals('LIKE')">LIKE</when>
		                      <otherwise><include refid="executionVariableOperator" /></otherwise>
		                    </choose>
		                    #{queryVar.textValue2}
		                    <choose>
		                      <when test="queryVar.operator.equals('LIKE')">${wildcardEscapeClause}</when>
		                    </choose>
		                  </if>
		                  <if test="queryVar.longValue != null">
		                    and A_${orLocal}OR${orIndex}.LONG_
		                    <include refid="executionVariableOperator" />
		                    #{queryVar.longValue}
		                  </if>
		                  <if test="queryVar.doubleValue != null">
		                    and A_OR${orIndex}_${index}.DOUBLE_
		                    <include refid="executionVariableOperator" />
		                    #{queryVar.doubleValue}
		                  </if>
		                  <!-- Null variable type -->
		                  <if test="queryVar.textValue == null &amp;&amp; queryVar.textValue2 == null &amp;&amp; queryVar.longValue == null &amp;&amp; queryVar.doubleValue == null">
		                    <choose>
		                      <when test="queryVar.operator.equals('NOT_EQUALS')">
		                        and (A_${orLocal}OR${orIndex}.TEXT_ is not null or A_${orLocal}OR${orIndex}.TEXT2_ is not null or A_${orLocal}OR${orIndex}.LONG_ is not null or A_${orLocal}OR${orIndex}.DOUBLE_ is not null or A_${orLocal}OR${orIndex}.BYTEARRAY_ID_ is not null)
		                      </when>
		                      <otherwise>
		                        and A_${orLocal}OR${orIndex}.TEXT_ is null and A_${orLocal}OR${orIndex}.TEXT2_ is null and A_${orLocal}OR${orIndex}.LONG_ is null and A_${orLocal}OR${orIndex}.DOUBLE_ is null and A_${orLocal}OR${orIndex}.BYTEARRAY_ID_ is null
		                      </otherwise>
		                    </choose>
		                  </if>
		              </otherwise>
		             </choose>
		            </trim>
		          </foreach>
		        </trim>
		      </foreach>
		    </where>
		  </sql>
	</sql>
	${orderBy}
	<if test="firstResult != null and firstResult &gt;= 0">${limitAfter}</if>
</select>
```

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值