<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tourism.common.flow.dao.FlowEntryMapper">
    <resultMap id="BaseResultMap" type="com.tourism.common.flow.model.FlowEntry">
        <id column="entry_id" jdbcType="BIGINT" property="entryId"/>
        <result column="tenant_id" jdbcType="BIGINT" property="tenantId"/>
        <result column="app_code" jdbcType="VARCHAR" property="appCode"/>
        <result column="process_definition_name" jdbcType="VARCHAR" property="processDefinitionName"/>
        <result column="process_definition_key" jdbcType="VARCHAR" property="processDefinitionKey"/>
        <result column="category_id" jdbcType="BIGINT" property="categoryId"/>
        <result column="main_entry_publish_id" jdbcType="BIGINT" property="mainEntryPublishId"/>
        <result column="latest_publish_time" jdbcType="TIMESTAMP" property="latestPublishTime"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="bpmn_xml" jdbcType="LONGVARCHAR" property="bpmnXml"/>
        <result column="diagram_type" jdbcType="INTEGER" property="diagramType"/>
        <result column="bind_form_type" jdbcType="INTEGER" property="bindFormType"/>
        <result column="page_id" jdbcType="BIGINT" property="pageId"/>
        <result column="default_form_id" jdbcType="BIGINT" property="defaultFormId"/>
        <result column="default_router_name" jdbcType="VARCHAR" property="defaultRouterName"/>
        <result column="encoded_rule" jdbcType="VARCHAR" property="encodedRule"/>
        <result column="extension_data" jdbcType="VARCHAR" property="extensionData"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
    </resultMap>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.common.flow.dao.FlowEntryMapper.inputFilterRef"/>
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="flowEntryFilter != null">
            <if test="flowEntryFilter.tenantId == null">
                AND zz_flow_entry.tenant_id IS NULL
            </if>
            <if test="flowEntryFilter.tenantId != null">
                AND zz_flow_entry.tenant_id = #{flowEntryFilter.tenantId}
            </if>
            <if test="flowEntryFilter.appCode == null">
                AND zz_flow_entry.app_code IS NULL
            </if>
            <if test="flowEntryFilter.appCode != null">
                AND zz_flow_entry.app_code = #{flowEntryFilter.appCode}
            </if>
            <if test="flowEntryFilter.processDefinitionName != null and flowEntryFilter.processDefinitionName != ''">
                AND zz_flow_entry.process_definition_name = #{flowEntryFilter.processDefinitionName}
            </if>
            <if test="flowEntryFilter.processDefinitionKey != null and flowEntryFilter.processDefinitionKey != ''">
                AND zz_flow_entry.process_definition_key = #{flowEntryFilter.processDefinitionKey}
            </if>
            <if test="flowEntryFilter.categoryId != null">
                AND zz_flow_entry.category_id = #{flowEntryFilter.categoryId}
            </if>
            <if test="flowEntryFilter.status != null">
                AND zz_flow_entry.status = #{flowEntryFilter.status}
            </if>
        </if>
    </sql>

    <select id="getFlowEntryList" resultMap="BaseResultMap" parameterType="com.tourism.common.flow.model.FlowEntry">
        SELECT
            entry_id,
            app_code,
            process_definition_name,
            process_definition_key,
            category_id,
            main_entry_publish_id,
            latest_publish_time,
            status,
            diagram_type,
            bind_form_type,
            page_id,
            default_form_id,
            default_router_name,
            encoded_rule,
            extension_data,
            update_time,
            update_user_id,
            create_time,
            create_user_id
        FROM
            zz_flow_entry
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
