<?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.HsFlowConditionModelMapper">

    <resultMap type="com.willalp.flow.domain.HsFlowConditionModel" id="HsFlowConditionModelResult">
        <result property="id" column="id"/>
        <result property="groupId" column="group_id"/>
        <result property="paramName" column="param_name"/>
        <result property="conditionType" column="condition_type"/>
        <result property="conditionChar" column="condition_char"/>
        <result property="thresholdValue" column="threshold_value"/>
        <result property="upStepId" column="up_step_id"/>
        <result property="downStepId" column="down_step_id"/>
    </resultMap>

    <sql id="selectHsFlowConditionModelVo">
        select id,
               group_id,
               param_name,
               condition_char,
               condition_type,
               threshold_value,
               up_step_id,
               down_step_id
        from hs_flow_condition_model
    </sql>

    <select id="selectHsFlowConditionModelList" parameterType="HsFlowConditionModel"
            resultMap="HsFlowConditionModelResult">
        <include refid="selectHsFlowConditionModelVo"/>
        <where>
            <if test="paramName != null  and paramName != ''">
                and param_name like concat('%', #{paramName}, '%')
            </if>
            <if test="conditionType != null  and conditionType != ''">
                and condition_type = #{conditionType}
            </if>
            <if test="conditionChar != null  and conditionChar != ''">
                and condition_char = #{conditionChar}
            </if>
            <if test="thresholdValue != null  and thresholdValue != ''">
                and threshold_value like concat('%', #{thresholdValue}, '%')
            </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>
        </where>
    </select>
    <select id="queryConditionGroup" resultType="com.willalp.flow.domain.HsFlowConditionModel">
        SELECT hfcm.id,
               hfcm.param_name,
               hfcm.condition_char,
               hfcm.condition_type,
               hfcm.threshold_value
        FROM `hs_flow_base` hfb
                 LEFT JOIN hs_flow_condition_model hfcm ON hfb.term_module_id = hfcm.id
        WHERE hfb.group_id = #{groupId}
          AND hfb.up_step_id = #{parentId}
    </select>
</mapper>
