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

    <resultMap type="MdBaseInfo" id="MdBaseInfoResult">
        <result property="itemId"    column="item_id"    />
        <result property="productNo"    column="product_no"    />
        <result property="productEnglishName"    column="product_english_name"    />
        <result property="unitOfMeasure"    column="unit_of_measure"    />
        <result property="expirationDateStart"    column="expiration_date_start"    />
        <result property="expirationDateEnd"    column="expiration_date_end"    />
        <result property="brandId"    column="brand_id"    />
        <result property="sizeGroupId"    column="size_group_id"    />
        <result property="layout"    column="layout"    />
        <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="brandName"    column="brand_name"    />
        <result property="sizeGroupName"    column="size_group_name"    />
        <result property="brandCode"    column="brand_code"    />
        <result property="layout"    column="layout"    />
        <result property="grossWeight"    column="gross_weight"    />
        <result property="netWeight"    column="net_weight"    />
        <result property="weightUnit"    column="weight_unit"    />
        <result property="volume"    column="volume"    />
        <result property="volumeUnit"    column="volume_unit"    />
        <result property="packageNum"    column="package_num"    />
        <result property="encasementNum"    column="encasement_num"    />
        <result property="isLayout"    column="is_layout"    />

    </resultMap>

    <resultMap type="com.ximai.mes.md.vo.MdBaseInfoVo" id="MdBaseInfoVoResult">
        <result property="itemId"    column="item_id"    />
        <result property="productNo"    column="product_no"    />
        <result property="productEnglishName"    column="product_english_name"    />
        <result property="unitOfMeasure"    column="unit_of_measure"    />
        <result property="expirationDateStart"    column="expiration_date_start"    />
        <result property="expirationDateEnd"    column="expiration_date_end"    />
        <result property="brandId"    column="brand_id"    />
        <result property="sizeGroupId"    column="size_group_id"    />
        <result property="layout"    column="layout"    />
        <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="brandName"    column="brand_name"    />
        <result property="sizeGroupName"    column="size_group_name"    />
        <result property="layout"    column="layout"    />
        <result property="grossWeight"    column="gross_weight"    />
        <result property="netWeight"    column="net_weight"    />
        <result property="weightUnit"    column="weight_unit"    />
        <result property="volume"    column="volume"    />
        <result property="volumeUnit"    column="volume_unit"    />
        <result property="packageNum"    column="package_num"    />
        <result property="encasementNum"    column="encasement_num"    />
        <result property="isLayout"    column="is_layout"    />

    </resultMap>

    <sql id="selectMdBaseInfoVo">
        select item_id, product_no, product_english_name, is_layout, unit_of_measure, expiration_date_start, expiration_date_end, brand_id, size_group_id, layout,
               package_num, encasement_num, create_by, create_time, update_by, update_time from md_base_info
    </sql>

    <sql id="Base_Column_List">
        bi.item_id, bi.product_no, bi.is_layout, bi.product_english_name, bi.unit_of_measure, bi.expiration_date_start, bi.expiration_date_end,
            bi.brand_id, bi.size_group_id, bi.layout, bi.create_by, bi.create_time, bi.update_by, bi.update_time,bi.brand_name ,bi.size_group_name,
                  bi.package_num, bi.encasement_num
    </sql>

    <select id="selectMdBaseInfoByItemId" parameterType="Long" resultMap="MdBaseInfoVoResult">
        select
        <include refid="Base_Column_List"/>
        from md_base_info bi
        left join md_brand b on bi.brand_id = b.brand_id
        left join md_size_group sg on bi.size_group_id = sg.size_group_id
        where item_id = #{itemId}
    </select>

    <insert id="insertMdBaseInfo" parameterType="MdBaseInfo">
        insert into md_base_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="itemId != null">item_id,</if>
            <if test="productNo != null">product_no,</if>
            <if test="productEnglishName != null">product_english_name,</if>
            <if test="unitOfMeasure != null">unit_of_measure,</if>
            <if test="expirationDateStart != null">expiration_date_start,</if>
            <if test="expirationDateEnd != null">expiration_date_end,</if>
            <if test="brandCode != null">brand_code,</if>
            <if test="brandName != null">brand_name,</if>
            <if test="sizeGroupId != null">size_group_id,</if>
            <if test="sizeGroupName != null">size_group_name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="layout != null">layout,</if>
            <if test="grossWeight != null">gross_weight,</if>
            <if test="netWeight != null">net_weight,</if>
            <if test="weightUnit != null">weight_unit,</if>
            <if test="volume != null">volume,</if>
            <if test="volumeUnit != null">volume_unit,</if>
            <if test="packageNum != null">package_num,</if>
            <if test="encasementNum != null">encasement_num,</if>
            <if test="isLayout != null">is_layout,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="itemId != null">#{itemId},</if>
            <if test="productNo != null">#{productNo},</if>
            <if test="productEnglishName != null">#{productEnglishName},</if>
            <if test="unitOfMeasure != null">#{unitOfMeasure},</if>
            <if test="expirationDateStart != null">#{expirationDateStart},</if>
            <if test="expirationDateEnd != null">#{expirationDateEnd},</if>
            <if test="brandCode != null">#{brandCode},</if>
            <if test="brandName != null">#{brandName},</if>
            <if test="sizeGroupId != null">#{sizeGroupId},</if>
            <if test="sizeGroupName != null">#{sizeGroupName},</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="layout != null">#{layout},</if>
            <if test="grossWeight != null">#{grossWeight},</if>
            <if test="netWeight != null">#{netWeight},</if>
            <if test="weightUnit != null">#{weightUnit},</if>
            <if test="volume != null">#{volume},</if>
            <if test="volumeUnit != null">#{volumeUnit},</if>
            <if test="packageNum != null">#{packageNum},</if>
            <if test="encasementNum != null">#{encasementNum},</if>
            <if test="isLayout != null">#{isLayout},</if>
            sysdate()
        </trim>
    </insert>

    <update id="updateMdBaseInfo" parameterType="MdBaseInfo">
        update md_base_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="productNo != null">product_no = #{productNo},</if>
            <if test="productEnglishName != null">product_english_name = #{productEnglishName},</if>
            <if test="unitOfMeasure != null">unit_of_measure = #{unitOfMeasure},</if>
            <if test="expirationDateStart != null">expiration_date_start = #{expirationDateStart},</if>
            <if test="expirationDateEnd != null">expiration_date_end = #{expirationDateEnd},</if>
            <if test="brandCode != null">brand_code = #{brandCode},</if>
            <if test="brandName != null">brand_name = #{brandName},</if>
            <if test="sizeGroupId != null">size_group_id = #{sizeGroupId},</if>
            <if test="sizeGroupName != null">size_group_name = #{sizeGroupName},</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="layout != null">layout = #{layout},</if>
            <if test="grossWeight != null">gross_weight = #{grossWeight},</if>
            <if test="netWeight != null">net_weight = #{netWeight},</if>
            <if test="weightUnit != null">weight_unit = #{weightUnit},</if>
            <if test="volume != null">volume = #{volume},</if>
            <if test="volumeUnit != null">volume_unit = #{volumeUnit},</if>
            <if test="packageNum != null">package_num = #{packageNum},</if>
            <if test="encasementNum != null">encasement_num = #{encasementNum},</if>
            <if test="isLayout != null">is_layout = #{isLayout},</if>
            update_time = sysdate()
        </trim>
        where item_id = #{itemId}
    </update>

    <delete id="deleteMdBaseInfoByItemId" parameterType="Long">
        delete from md_base_info where item_id = #{itemId}
    </delete>

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