<?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.ztmap.project.zhny.strategycondition.mapper.TStrategyConditionMapper">
    
    <resultMap type="TStrategyCondition" id="TStrategyConditionResult">
        <result property="id"    column="id"    />
        <result property="strategyId"    column="strategy_id"    />
        <result property="conditionParams"    column="condition_params"    />
        <result property="conditionType"    column="condition_type"    />
        <result property="targetCondition"    column="target_condition"    />
        <result property="conditionParams2"    column="condition_params2"    />
        <result property="conditionType2"    column="condition_type2"    />
        <result property="targetCondition2"    column="target_condition2"    />
        <result property="conditionParams3"    column="condition_params3"    />
        <result property="conditionType3"    column="condition_type3"    />
        <result property="targetCondition3"    column="target_condition3"    />
        <!--   条件1     -->
        <result property="qufen"    column="qufen"    />
        <result property="condition_field1"    column="condition_field1"    />
        <result property="condition_field_type1"    column="condition_field_type1"    />
        <result property="condition_field2"    column="condition_field2"    />
        <result property="condition_field_type2"    column="condition_field_type2"    />
        <result property="condition_field3"    column="condition_field3"    />
        <result property="condition_field4"    column="condition_field4"    />
        <!--   条件1     -->
        <result property="qufen2"    column="qufen2"    />
        <result property="condition2_field1"    column="condition2_field1"    />
        <result property="condition2_field_type1"    column="condition2_field_type1"    />
        <result property="condition2_field2"    column="condition2_field2"    />
        <result property="condition2_field_type2"    column="condition2_field_type2"    />
        <result property="condition2_field3"    column="condition2_field3"    />
        <result property="condition2_field4"    column="condition2_field4"    />
        <!--   条件1     -->
        <result property="qufen3"    column="qufen3"    />
        <result property="condition3_field1"    column="condition3_field1"    />
        <result property="condition3_field_type1"    column="condition3_field_type1"    />
        <result property="condition3_field2"    column="condition3_field2"    />
        <result property="condition3_field_type2"    column="condition3_field_type2"    />
        <result property="condition3_field3"    column="condition3_field3"    />
        <result property="condition3_field4"    column="condition3_field4"    />
    </resultMap>

    <sql id="selectTStrategyConditionVo">
        select
               id,
               strategy_id,
               condition_params,
               condition_type,
               target_condition,
               condition_params2,
               condition_type2,
               target_condition2,
               condition_params3,
               condition_type3,
               target_condition3,
                qufen,
               condition_field1,
               condition_field_type1,
               condition_field2,
               condition_field_type2,
               condition_field3,
               condition_field4,
               qufen2,
               condition2_field1,
               condition2_field_type1,
               condition2_field2,
               condition2_field_type2,
               condition2_field3,
               condition2_field4,
               qufen3,
               condition3_field1,
               condition3_field_type1,
               condition3_field2,
               condition3_field_type2,
               condition3_field3,
               condition3_field4
        from t_strategy_condition
    </sql>

    <select id="selectTStrategyConditionList" parameterType="TStrategyCondition" resultMap="TStrategyConditionResult">
        <include refid="selectTStrategyConditionVo"/>
        <where>  
            <if test="strategyId != null "> and strategy_id = #{strategyId}</if>
            <if test="conditionParams != null  and conditionParams != ''"> and condition_params = #{conditionParams}</if>
            <if test="conditionType != null "> and condition_type = #{conditionType}</if>
            <if test="targetCondition != null  and targetCondition != ''"> and target_condition = #{targetCondition}</if>
            <if test="conditionParams2 != null  and conditionParams2 != ''"> and condition_params2 = #{conditionParams2}</if>
            <if test="conditionType2 != null "> and condition_type2 = #{conditionType2}</if>
            <if test="targetCondition2 != null  and targetCondition2 != ''"> and target_condition2 = #{targetCondition2}</if>
            <if test="conditionParams3 != null  and conditionParams3 != ''"> and condition_params3 = #{conditionParams3}</if>
            <if test="conditionType3 != null "> and condition_type3 = #{conditionType3}</if>
            <if test="targetCondition3 != null  and targetCondition3 != ''"> and target_condition3 = #{targetCondition3}</if>
        </where>
    </select>
    
    <select id="selectTStrategyConditionById" parameterType="Long" resultMap="TStrategyConditionResult">
        <include refid="selectTStrategyConditionVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTStrategyCondition" parameterType="TStrategyCondition" useGeneratedKeys="true" keyProperty="id">
        insert into t_strategy_condition
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="strategyId != null">strategy_id,</if>
            <if test="conditionParams != null">condition_params,</if>
            <if test="conditionType != null">condition_type,</if>
            <if test="targetCondition != null">target_condition,</if>
            <if test="conditionParams2 != null">condition_params2,</if>
            <if test="conditionType2 != null">condition_type2,</if>
            <if test="targetCondition2 != null">target_condition2,</if>
            <if test="conditionParams3 != null">condition_params3,</if>
            <if test="conditionType3 != null">condition_type3,</if>
            <if test="targetCondition3 != null">target_condition3,</if>
            <!-- 条件1 -->
            <if test="qufen != null">qufen,</if>
            <if test="condition_field1 != null">condition_field1,</if>
            <if test="condition_field_type1 != null">condition_field_type1,</if>
            <if test="condition_field2 != null">condition_field2,</if>
            <if test="condition_field_type2 != null">condition_field_type2,</if>
            <if test="condition_field3 != null">condition_field3,</if>
            <if test="condition_field4 != null">condition_field4,</if>
            <!-- 条件2 -->
            <if test="qufen2 != null">qufen2,</if>
            <if test="condition2_field1 != null">condition2_field1,</if>
            <if test="condition2_field_type1 != null">condition2_field_type1,</if>
            <if test="condition2_field2 != null">condition2_field2,</if>
            <if test="condition2_field_type2 != null">condition2_field_type2,</if>
            <if test="condition2_field3 != null">condition2_field3,</if>
            <if test="condition2_field4 != null">condition2_field4,</if>
            <!-- 条件3 -->
            <if test="qufen3 != null">qufen,</if>
            <if test="condition3_field1 != null">condition3_field1,</if>
            <if test="condition3_field_type1 != null">condition3_field_type1,</if>
            <if test="condition3_field2 != null">condition3_field2,</if>
            <if test="condition3_field_type2 != null">condition3_field_type2,</if>
            <if test="condition3_field3 != null">condition3_field3,</if>
            <if test="condition3_field4 != null">condition3_field4,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="strategyId != null">#{strategyId},</if>
            <if test="conditionParams != null">#{conditionParams},</if>
            <if test="conditionType != null">#{conditionType},</if>
            <if test="targetCondition != null">#{targetCondition},</if>
            <if test="conditionParams2 != null">#{conditionParams2},</if>
            <if test="conditionType2 != null">#{conditionType2},</if>
            <if test="targetCondition2 != null">#{targetCondition2},</if>
            <if test="conditionParams3 != null">#{conditionParams3},</if>
            <if test="conditionType3 != null">#{conditionType3},</if>
            <if test="targetCondition3 != null">#{targetCondition3},</if>
            <!-- 条件1 -->
            <if test="qufen != null">#{qufen},</if>
            <if test="condition_field1 != null">#{condition_field1},</if>
            <if test="condition_field_type1 != null">#{condition_field_type1},</if>
            <if test="condition_field2 != null">#{condition_field2},</if>
            <if test="condition_field_type2 != null">#{condition_field_type2},</if>
            <if test="condition_field3 != null">#{condition_field3},</if>
            <if test="condition_field4 != null">#{condition_field4},</if>
            <!-- 条件2 -->
            <if test="qufen2 != null">#{qufen2},</if>
            <if test="condition2_field1 != null">#{condition2_field1},</if>
            <if test="condition2_field_type1 != null">#{condition2_field_type1},</if>
            <if test="condition2_field2 != null">#{condition2_field2},</if>
            <if test="condition2_field_type2 != null">#{condition2_field_type2},</if>
            <if test="condition2_field3 != null">#{condition2_field3},</if>
            <if test="condition2_field4 != null">#{condition2_field4},</if>
            <!-- 条件3 -->
            <if test="qufen3 != null">#{qufen3},</if>
            <if test="condition3_field1 != null">#{condition3_field1},</if>
            <if test="condition3_field_type1 != null">#{condition3_field_type1},</if>
            <if test="condition3_field2 != null">#{condition3_field2},</if>
            <if test="condition3_field_type2 != null">#{condition3_field_type2},</if>
            <if test="condition3_field3 != null">#{condition3_field3},</if>
            <if test="condition3_field4 != null">#{condition3_field4},</if>
         </trim>
    </insert>

    <update id="updateTStrategyCondition" parameterType="TStrategyCondition">
        update t_strategy_condition
        <trim prefix="SET" suffixOverrides=",">
            <if test="strategyId != null">strategy_id = #{strategyId},</if>
            <if test="conditionParams != null">condition_params = #{conditionParams},</if>
            <if test="conditionType != null">condition_type = #{conditionType},</if>
            <if test="targetCondition != null">target_condition = #{targetCondition},</if>
            <if test="conditionParams2 != null">condition_params2 = #{conditionParams2},</if>
            <if test="conditionType2 != null">condition_type2 = #{conditionType2},</if>
            <if test="targetCondition2 != null">target_condition2 = #{targetCondition2},</if>
            <if test="conditionParams3 != null">condition_params3 = #{conditionParams3},</if>
            <if test="conditionType3 != null">condition_type3 = #{conditionType3},</if>
            <if test="targetCondition3 != null">target_condition3 = #{targetCondition3},</if>
            <!-- 条件1 -->
            <if test="qufen != null">qufen = #{qufen},</if>
            <if test="condition_field1 != null">condition_field1 = #{condition_field1},</if>
            <if test="condition_field_type1 != null">condition_field_type1 = #{condition_field_type1},</if>
            <if test="condition_field2 != null">condition_field2 = #{condition_field2},</if>
            <if test="condition_field_type2 != null">condition_field_type2 = #{condition_field_type2},</if>
            <if test="condition_field3 != null">condition_field3 = #{condition_field3},</if>
            <if test="condition_field4 != null">condition_field4 = #{condition_field4},</if>
            <!-- 条件2 -->
            <if test="qufen2 != null">qufen2 = #{qufen2},</if>
            <if test="condition2_field1 != null">condition2_field1 = #{condition2_field1},</if>
            <if test="condition2_field_type1 != null">condition2_field_type1 = #{condition2_field_type1},</if>
            <if test="condition2_field2 != null">condition2_field2 = #{condition2_field2},</if>
            <if test="condition2_field_type2 != null">condition2_field_type2 = #{condition2_field_type2},</if>
            <if test="condition2_field3 != null">condition2_field3 = #{condition2_field3},</if>
            <if test="condition2_field4 != null">condition2_field4 = #{condition2_field4},</if>
            <!-- 条件3 -->
            <if test="qufen3 != null">qufen3 = #{qufen3},</if>
            <if test="condition3_field1 != null">condition3_field1 = #{condition3_field1},</if>
            <if test="condition3_field_type1 != null">condition3_field_type1 = #{condition3_field_type1},</if>
            <if test="condition3_field2 != null">condition3_field2 = #{condition3_field2},</if>
            <if test="condition3_field_type2 != null">condition3_field_type2 = #{condition3_field_type2},</if>
            <if test="condition3_field3 != null">condition3_field3 = #{condition3_field3},</if>
            <if test="condition3_field4 != null">condition3_field4 = #{condition3_field4},</if>

        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTStrategyConditionById" parameterType="Long">
        delete from t_strategy_condition where id = #{id}
    </delete>

    <delete id="deleteTStrategyConditionByIds" parameterType="String">
        delete from t_strategy_condition where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>