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

    <resultMap type="MdSaleOrderOffice" id="MdSaleOrderOfficeResult">
        <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="selectMdSaleOrderOfficeVo">
        select id, code, name, enable_flag, remark from md_sale_order_office
    </sql>

    <select id="selectMdSaleOrderOfficeList" parameterType="MdSaleOrderOffice" resultMap="MdSaleOrderOfficeResult">
        <include refid="selectMdSaleOrderOfficeVo"/>
        <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="selectMdSaleOrderOfficeById" parameterType="Long" resultMap="MdSaleOrderOfficeResult">
        <include refid="selectMdSaleOrderOfficeVo"/>
        where id = #{id}
    </select>

    <insert id="insertMdSaleOrderOffice" parameterType="MdSaleOrderOffice">
        insert into md_sale_order_office
        <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="updateMdSaleOrderOffice" parameterType="MdSaleOrderOffice">
        update md_sale_order_office
        <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="deleteMdSaleOrderOfficeById" parameterType="Long">
        delete from md_sale_order_office where id = #{id}
    </delete>

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