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

    <resultMap type="MdSizeGroup" id="MdSizeGroupResult">
        <result property="sizeGroupId"    column="size_group_id"    />
        <result property="sizeGroupCode"    column="size_group_code"    />
        <result property="sizeGroupName"    column="size_group_name"    />
        <result property="sizeType"    column="size_type"    />
        <result property="enableFlag"    column="enable_flag"    />
        <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="selectMdSizeGroupVo">
        select size_group_id, size_group_code, size_group_name, size_type, enable_flag, create_by, create_time, update_by, update_time from md_size_group
    </sql>

    <select id="selectMdSizeGroupList" parameterType="MdSizeGroup" resultMap="MdSizeGroupResult">
        <include refid="selectMdSizeGroupVo"/>
        <where>
            <if test="sizeGroupCode != null  and sizeGroupCode != ''"> and size_group_code = #{sizeGroupCode}</if>
            <if test="sizeGroupName != null  and sizeGroupName != ''"> and size_group_name like concat('%', #{sizeGroupName}, '%')</if>
            <if test="sizeType != null  and sizeType != ''"> and size_type = #{sizeType}</if>
            <if test="enableFlag != null  and enableFlag != ''"> and enable_flag = #{enableFlag}</if>
        </where>
    </select>

    <select id="selectMdSizeGroupBySizeGroupId" parameterType="Long" resultMap="MdSizeGroupResult">
        <include refid="selectMdSizeGroupVo"/>
        where size_group_id = #{sizeGroupId}
    </select>
    <select id="selectMdSizeGroupBySizeGroupCode" resultType="com.ximai.mes.md.domain.MdSizeGroup"
            parameterType="java.lang.String">
        select * from md_size_group where size_group_code = #{sizeGroupCode}
    </select>
    <select id="selectMdSizeGroupExportList" resultType="com.ximai.mes.md.vo.MdSizeGroupVo"
            parameterType="com.ximai.mes.md.domain.MdSizeGroup">
        select sg.size_group_id, sg.size_group_code, sg.size_group_name, sg.size_type, sg.enable_flag ,
               msgi.size_index, msgi.size_name, msgi.size_display_name
        from md_size_group sg
            left join md_size_group_item msgi
                on msgi.size_group_id = sg.size_group_id
        <where>
            <if test="sizeGroupCode != null  and sizeGroupCode != ''"> and sg.size_group_code like concat('%', #{sizeGroupCode}, '%')</if>
            <if test="sizeGroupName != null  and sizeGroupName != ''"> and sg.size_group_name like concat('%', #{sizeGroupName}, '%')</if>
            <if test="sizeType != null  and sizeType != ''"> and sg.size_type = #{sizeType}</if>
            <if test="enableFlag != null  and enableFlag != ''"> and sg.enable_flag = #{enableFlag}</if>
        </where>
        order by sg.size_group_code,msgi.size_index asc
    </select>

    <insert id="insertMdSizeGroup" parameterType="MdSizeGroup">
        insert into md_size_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sizeGroupId != null">size_group_id,</if>
            <if test="sizeGroupCode != null">size_group_code,</if>
            <if test="sizeGroupName != null">size_group_name,</if>
            <if test="sizeType != null">size_type,</if>
            <if test="enableFlag != null">enable_flag,</if>
            <if test="createBy != null">create_by,</if>
            create_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sizeGroupId != null">#{sizeGroupId},</if>
            <if test="sizeGroupCode != null">#{sizeGroupCode},</if>
            <if test="sizeGroupName != null">#{sizeGroupName},</if>
            <if test="sizeType != null">#{sizeType},</if>
            <if test="enableFlag != null">#{enableFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            sysdate()
         </trim>
    </insert>
    <insert id="insertMdSizeGroupAndReturnId" parameterType="com.ximai.mes.md.domain.MdSizeGroup">
        <selectKey resultType="java.lang.Long" order="AFTER" keyProperty="sizeGroupId" keyColumn="size_group_id">
            select LAST_INSERT_ID()
        </selectKey>
        insert into md_size_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sizeGroupId != null">size_group_id,</if>
            <if test="sizeGroupCode != null">size_group_code,</if>
            <if test="sizeGroupName != null">size_group_name,</if>
            <if test="sizeType != null">size_type,</if>
            <if test="enableFlag != null">enable_flag,</if>
            <if test="createBy != null">create_by,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sizeGroupId != null">#{sizeGroupId},</if>
            <if test="sizeGroupCode != null">#{sizeGroupCode},</if>
            <if test="sizeGroupName != null">#{sizeGroupName},</if>
            <if test="sizeType != null">#{sizeType},</if>
            <if test="enableFlag != null">#{enableFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            sysdate()
        </trim>
    </insert>

    <update id="updateMdSizeGroup" parameterType="MdSizeGroup">
        update md_size_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="sizeGroupCode != null">size_group_code = #{sizeGroupCode},</if>
            <if test="sizeGroupName != null">size_group_name = #{sizeGroupName},</if>
            <if test="sizeType != null">size_type = #{sizeType},</if>
            <if test="enableFlag != null">enable_flag = #{enableFlag},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = sysdate()
        </trim>
        where size_group_id = #{sizeGroupId}
    </update>

    <delete id="deleteMdSizeGroupBySizeGroupId" parameterType="Long">
        delete from md_size_group where size_group_id = #{sizeGroupId}
    </delete>

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