<?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.dv.mapper.devBrandQuotation.DvBrandQuotationMapper">

    <resultMap type="DvBrandQuotation" id="DevBrandQuotationResult">
        <result property="brandQuotationId"    column="brand_quotation_id"    />
        <result property="brandQuotationCode"    column="brand_quotation_code"    />
        <result property="brandQuotationName"    column="brand_quotation_name"    />
        <result property="brandId"    column="brand_id"    />
        <result property="brandName"    column="brand_name"    />
        <result property="itemName"    column="item_name"    />
        <result property="routeName"    column="route_name"    />
        <result property="itemId"    column="item_id"    />
        <result property="routeId"    column="route_id"    />
        <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"    />
        <result property="amount"    column="amount"    />
    </resultMap>

    <sql id="selectDevBrandQuotationVo">
        select
            a.brand_quotation_id,
            a.brand_quotation_code,
            a.brand_quotation_name,
            a.brand_id,
            b.brand_name,
            a.item_id,
            c.item_name,
            a.route_id,
            d.route_name,
            a.amount,
            a.remark,
            a.create_by,
            a.create_time,
            a.update_by,
            a.update_time
        from dev_brand_quotation a
                 left join md_brand b on a.brand_id=b.brand_id
                 left join md_item c on a.item_id= c.item_id
                 left join pro_route d on a.route_id=d.route_id
    </sql>

    <select id="selectDevBrandQuotationList" parameterType="DvBrandQuotationVo" resultMap="DevBrandQuotationResult">
        <include refid="selectDevBrandQuotationVo"/>
        <where>
            <if test="brandQuotationCode != null  and brandQuotationCode != ''"> and a.brand_quotation_code = #{brandQuotationCode}</if>
            <if test="brandQuotationName != null  and brandQuotationName != ''"> and a.brand_quotation_name like concat('%', #{brandQuotationName}, '%')</if>
            <if test="brandName != null  and brandName != ''"> and   b.brand_name like concat('%', #{brandName}, '%')</if>
            <if test="itemName!= null  and itemName != ''"> and   c.item_name like concat('%', #{itemName}, '%')</if>
            <if test="routeName!= null  and routeName != ''"> and  d.route_name like concat('%', #{routeName}, '%')</if>
            <if test="brandId != null "> and a.brand_id = #{brandId}</if>
            <if test="itemId != null "> and a.item_id = #{itemId}</if>
            <if test="routeId != null "> and a.route_id = #{routeId}</if>
        </where>
    </select>

    <select id="selectDevBrandQuotationByBrandQuotationId" parameterType="Long" resultMap="DevBrandQuotationResult">
        <include refid="selectDevBrandQuotationVo"/>
        where a.brand_quotation_id = #{brandQuotationId}
    </select>

    <insert id="insertDevBrandQuotation" parameterType="DvBrandQuotationVo" useGeneratedKeys="true" keyProperty="brandQuotationId">
        insert into dev_brand_quotation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brandQuotationCode != null">brand_quotation_code,</if>
            <if test="brandQuotationName != null">brand_quotation_name,</if>
            <if test="brandId != null">brand_id,</if>
            <if test="itemId != null">item_id,</if>
            <if test="routeId != null">route_id,</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>
            <if test="amount != null">amount,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brandQuotationCode != null">#{brandQuotationCode},</if>
            <if test="brandQuotationName != null">#{brandQuotationName},</if>
            <if test="brandId != null">#{brandId},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="routeId != null">#{routeId},</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>
            <if test="amount != null">#{amount},</if>
        </trim>
    </insert>

    <update id="updateDevBrandQuotation" parameterType="DvBrandQuotation">
        update dev_brand_quotation
        <trim prefix="SET" suffixOverrides=",">
            <if test="brandQuotationCode != null">brand_quotation_code = #{brandQuotationCode},</if>
            <if test="brandQuotationName != null">brand_quotation_name = #{brandQuotationName},</if>
            brand_id = #{brandId},
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="routeId != null">route_id = #{routeId},</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>
            <if test="amount != null">amount = #{amount},</if>
        </trim>
        where brand_quotation_id = #{brandQuotationId}
    </update>

    <delete id="deleteDevBrandQuotationByBrandQuotationId" parameterType="Long">
        delete from dev_brand_quotation where brand_quotation_id = #{brandQuotationId}
    </delete>

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