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

    <resultMap type="com.ximai.mes.md.domain.MdBrandOrderQuantity" id="MdBrandOrderQuantityResult">
        <result property="brandOrderQuantityId"    column="brand_order_quantity_id"    />
        <result property="brandId"    column="brand_id"    />
        <result property="brandCode"    column="brand_code"    />
        <result property="brandName"    column="brand_name"    />
        <result property="time"    column="time"    />
        <result property="region"    column="region"    />
        <result property="orderQuantity"    column="order_quantity"    />
        <result property="enableFlag"    column="enable_flag"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMdBrandOrderQuantityVo">
        select c.brand_order_quantity_id,c.brand_id,a.brand_code,a.brand_name,c.time,c.region, c.order_quantity, c.enable_flag, c.remark, c.create_by, c.create_time, c.update_by, c.update_time from md_brand_order_quantity as c LEFT JOIN md_brand as a on c.brand_id = a.brand_id
    </sql>

    <select id="selectMdBrandOrderQuantityList" parameterType="com.ximai.mes.md.domain.MdBrandOrderQuantity" resultMap="MdBrandOrderQuantityResult">
        <include refid="selectMdBrandOrderQuantityVo"/>
        <where>
            <if test="brandId != null "> and c.brand_id = #{brandId}</if>
            <if test="brandCode != null  and brandCode != ''"> and a.brand_code like concat('%', #{brandCode}, '%')</if>
            <if test="brandName != null  and brandName != ''"> and a.brand_name like concat('%', #{brandName}, '%')</if>
            <if test="time != null  and time != ''"> and c.time = #{time}</if>
            <if test="region != null  and region != ''"> and c.region = #{region}</if>
            <if test="orderQuantity != null "> and c.order_quantity = #{orderQuantity}</if>
            <if test="enableFlag != null  and enableFlag != ''"> and c.enable_flag = #{enableFlag}</if>
        </where>
    </select>

    <select id="selectMdBrandOrderQuantityByBrandOrderQuantityId" parameterType="Long" resultMap="MdBrandOrderQuantityResult">
        <include refid="selectMdBrandOrderQuantityVo"/>
        where brand_order_quantity_id = #{brandOrderQuantityId}
    </select>

    <insert id="insertMdBrandOrderQuantity" parameterType="MdBrandOrderQuantity" useGeneratedKeys="true" keyProperty="brandOrderQuantityId">
        insert into md_brand_order_quantity
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brandId != null">brand_id,</if>
            <if test="time != null and time != ''">time,</if>
            <if test="region != null and region != ''">region,</if>
            <if test="orderQuantity != null">order_quantity,</if>
            <if test="enableFlag != null">enable_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brandId != null">#{brandId},</if>
            <if test="time != null and time != ''">#{time},</if>
            <if test="region != null and region != ''">#{region},</if>
            <if test="orderQuantity != null">#{orderQuantity},</if>
            <if test="enableFlag != null">#{enableFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateMdBrandOrderQuantity" parameterType="MdBrandOrderQuantity">
        update md_brand_order_quantity
        <trim prefix="SET" suffixOverrides=",">
            <if test="brandId != null">brand_id = #{brandId},</if>
            <if test="time != null and time != ''">time = #{time},</if>
            <if test="region != null and region != ''">region = #{region},</if>
            <if test="orderQuantity != null">order_quantity = #{orderQuantity},</if>
            <if test="enableFlag != null">enable_flag = #{enableFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where brand_order_quantity_id = #{brandOrderQuantityId}
    </update>

    <delete id="deleteMdBrandOrderQuantityByBrandOrderQuantityId" parameterType="Long">
        delete from md_brand_order_quantity where brand_order_quantity_id = #{brandOrderQuantityId}
    </delete>

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