<?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.ximai.mes.md.mapper.MdSaleOrderTypeMapper">

    <resultMap type="MdSaleOrderType" id="MdSaleOrderTypeResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="enableFlag"    column="enable_flag"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectMdSaleOrderTypeVo">
        select id, code, name, enable_flag, remark from md_sale_order_type
    </sql>

    <select id="selectMdSaleOrderTypeList" parameterType="MdSaleOrderType" resultMap="MdSaleOrderTypeResult">
        <include refid="selectMdSaleOrderTypeVo"/>
        <where>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="enableFlag != null and enableFlag != ''" > and enable_flag = #{enableFlag}</if>
        </where>
    </select>

    <select id="selectMdSaleOrderTypeById" parameterType="Long" resultMap="MdSaleOrderTypeResult">
        <include refid="selectMdSaleOrderTypeVo"/>
        where id = #{id}
    </select>

    <insert id="insertMdSaleOrderType" parameterType="MdSaleOrderType">
        insert into md_sale_order_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="code != null">code,</if>
            <if test="name != null">name,</if>
            <if test="enableFlag != null">enable_flag,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="code != null">#{code},</if>
            <if test="name != null">#{name},</if>
            <if test="enableFlag != null">#{enableFlag},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateMdSaleOrderType" parameterType="MdSaleOrderType">
        update md_sale_order_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null">code = #{code},</if>
            <if test="name != null">name = #{name},</if>
            <if test="enableFlag != null">enable_flag = #{enableFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMdSaleOrderTypeById" parameterType="Long">
        delete from md_sale_order_type where id = #{id}
    </delete>

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