<?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.muyu.warning.mapper.WarnStrategyMapper">

    <resultMap type="WarnStrategy" id="WarnStrategyResult">
        <result property="id"    column="id"    />
        <result property="carTypeId"    column="car_type_id"    />
        <result property="strategyName"    column="strategy_name"    />
        <result property="msgId"    column="msg_id"    />
    </resultMap>

    <sql id="selectWarnStrategyVo">
        select id, car_type_id, strategy_name, msg_id from warn_strategy
    </sql>

    <select id="selectWarnStrategyList" parameterType="WarnStrategy" resultMap="WarnStrategyResult">
        <include refid="selectWarnStrategyVo"/>
        <where>
            <if test="carTypeId != null "> and car_type_id = #{carTypeId}</if>
            <if test="strategyName != null  and strategyName != ''"> and strategy_name like concat('%', #{strategyName}, '%')</if>
            <if test="msgId != null "> and msg_id = #{msgId}</if>
        </where>
    </select>

    <select id="selectWarnStrategyById" parameterType="Long" resultMap="WarnStrategyResult">
        <include refid="selectWarnStrategyVo"/>
        where id = #{id}
    </select>

    <insert id="insertWarnStrategy" parameterType="WarnStrategy" useGeneratedKeys="true" keyProperty="id">
        insert into warn_strategy
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="carTypeId != null">car_type_id,</if>
            <if test="strategyName != null">strategy_name,</if>
            <if test="msgId != null">msg_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="carTypeId != null">#{carTypeId},</if>
            <if test="strategyName != null">#{strategyName},</if>
            <if test="msgId != null">#{msgId},</if>
         </trim>
    </insert>

    <update id="updateWarnStrategy" parameterType="WarnStrategy">
        update warn_strategy
        <trim prefix="SET" suffixOverrides=",">
            <if test="carTypeId != null">car_type_id = #{carTypeId},</if>
            <if test="strategyName != null">strategy_name = #{strategyName},</if>
            <if test="msgId != null">msg_id = #{msgId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWarnStrategyById" parameterType="Long">
        delete from warn_strategy where id = #{id}
    </delete>

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