<?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.willalp.flow.mapper.HsFlowBaseMapper">

    <resultMap type="com.willalp.flow.domain.HsFlowBase" id="HsFlowBaseResult">
        <result property="id" column="id"/>
        <result property="modelType" column="model_type"/>
        <result property="examplesId" column="examples_id"/>
        <result property="groupId" column="group_id"/>
        <result property="flowModuleName" column="flow_module_name"/>
        <result property="upStepId" column="up_step_id"/>
        <result property="downStepId" column="down_step_id"/>
        <result property="assignStepId" column="assign_step_id"/>
        <result property="isAudit" column="is_audit"/>
        <result property="passTrueStepId" column="pass_true_step_id"/>
        <result property="passFalseStepId" column="pass_false_step_id"/>
        <result property="operator" column="operator"/>
        <result property="termModuleId" column="term_module_id"/>
        <result property="countersignId" column="countersign_id"/>
    </resultMap>

    <sql id="selectHsFlowBaseVo">
        select id,
               model_type,
               examples_id,
               group_id,
               flow_module_name,
               up_step_id,
               down_step_id,
               assign_step_id,
               is_audit,
               pass_true_step_id,
               pass_false_step_id,
               operator,
               term_module_id,
               countersign_id
        from hs_flow_base
    </sql>

    <select id="selectHsFlowBaseList" parameterType="HsFlowBase" resultMap="HsFlowBaseResult">
        <include refid="selectHsFlowBaseVo"/>
        <where>
            <if test="modelType != null  and modelType != ''">
                and model_type = #{modelType}
            </if>
            <if test="examplesId != null  and examplesId != ''">
                and examples_id = #{examplesId}
            </if>
            <if test="groupId != null  and groupId != ''">
                and group_id = #{groupId}
            </if>
            <if test="flowModuleName != null  and flowModuleName != ''">
                and flow_module_name like concat('%', #{flowModuleName}, '%')
            </if>
            <if test="upStepId != null  and upStepId != ''">
                and up_step_id = #{upStepId}
            </if>
            <if test="downStepId != null  and downStepId != ''">
                and down_step_id = #{downStepId}
            </if>
            <if test="assignStepId != null  and assignStepId != ''">
                and assign_step_id = #{assignStepId}
            </if>
            <if test="isAudit != null  and isAudit != ''">
                and is_audit = #{isAudit}
            </if>
            <if test="passTrueStepId != null  and passTrueStepId != ''">
                and pass_true_step_id = #{passTrueStepId}
            </if>
            <if test="passFalseStepId != null  and passFalseStepId != ''">
                and pass_false_step_id = #{passFalseStepId}
            </if>
            <if test="operator != null  and operator != ''">
                and operator = #{operator}
            </if>
            <if test="termModuleId != null  and termModuleId != ''">
                and term_module_id = #{termModuleId}
            </if>
            <if test="countersignId != null  and countersignId != ''">
                and countersign_id = #{countersignId}
            </if>
        </where>
    </select>
    <select id="firstFlowBase" resultType="com.willalp.flow.domain.HsFlowBase">
        <include refid="selectHsFlowBaseVo"/>
        where
        id = (SELECT down_step_id FROM
        hs_flow_base
        WHERE
        examples_id = #{examplesId} AND
        group_id = id)
    </select>
</mapper>
