<?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.hw.mes.mapper.MesBaseMaterialInfoMapper">

    <resultMap type="MesBaseMaterialInfo" id="MesBaseMaterialInfoResult">
        <result property="materialId"    column="material_id"    />
        <result property="materialCode"    column="material_code"    />
        <result property="materialName"    column="material_name"    />
        <result property="materialCategories"    column="material_categories"    />
        <result property="materialSubclass"    column="material_subclass"    />
        <result property="materialTypeId"    column="material_type_id"    />
        <result property="materialUnit"    column="material_unit"    />
        <result property="materialMatkl"    column="material_matkl"    />
        <result property="materialSpec"    column="material_spec"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="prodlineId"    column="prodline_id"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="erpId"    column="erp_id"    />
        <result property="deletedFlag"    column="deleted_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="selectMesBaseMaterialInfoVo">
        select material_id, material_code, material_name, material_categories, material_subclass, material_type_id, material_unit, material_matkl, material_spec, factory_id, prodline_id, is_flag, erp_id, deleted_flag, remark, create_by, create_time, update_by, update_time from mes_base_material_info
    </sql>

    <select id="selectMesBaseMaterialInfoList" parameterType="MesBaseMaterialInfo" resultMap="MesBaseMaterialInfoResult">
        <include refid="selectMesBaseMaterialInfoVo"/>
        <where>
            <if test="materialCode != null  and materialCode != ''"> and material_code = #{materialCode}</if>
            <if test="materialName != null  and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
            <if test="materialCategories != null  and materialCategories != ''"> and material_categories = #{materialCategories}</if>
            <if test="materialSubclass != null  and materialSubclass != ''"> and material_subclass = #{materialSubclass}</if>
            <if test="materialTypeId != null "> and material_type_id = #{materialTypeId}</if>
            <if test="materialUnit != null  and materialUnit != ''"> and material_unit = #{materialUnit}</if>
            <if test="materialMatkl != null  and materialMatkl != ''"> and material_matkl = #{materialMatkl}</if>
            <if test="materialSpec != null  and materialSpec != ''"> and material_spec = #{materialSpec}</if>
            <if test="factoryId != null "> and factory_id = #{factoryId}</if>
            <if test="prodlineId != null  and prodlineId != ''"> and prodline_id = #{prodlineId}</if>
            <if test="isFlag != null "> and is_flag = #{isFlag}</if>
            <if test="erpId != null "> and erp_id = #{erpId}</if>
            <if test="deletedFlag != null  and deletedFlag != ''"> and deleted_flag = #{deletedFlag}</if>
        </where>
    </select>

    <select id="selectMesBaseMaterialInfoByMaterialId" parameterType="Long" resultMap="MesBaseMaterialInfoResult">
        <include refid="selectMesBaseMaterialInfoVo"/>
        where material_id = #{materialId}
    </select>

    <insert id="insertMesBaseMaterialInfo" parameterType="MesBaseMaterialInfo" useGeneratedKeys="true" keyProperty="materialId">
        insert into mes_base_material_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="materialCode != null and materialCode != ''">material_code,</if>
            <if test="materialName != null and materialName != ''">material_name,</if>
            <if test="materialCategories != null and materialCategories != ''">material_categories,</if>
            <if test="materialSubclass != null">material_subclass,</if>
            <if test="materialTypeId != null">material_type_id,</if>
            <if test="materialUnit != null">material_unit,</if>
            <if test="materialMatkl != null">material_matkl,</if>
            <if test="materialSpec != null">material_spec,</if>
            <if test="factoryId != null">factory_id,</if>
            <if test="prodlineId != null">prodline_id,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="erpId != null">erp_id,</if>
            <if test="deletedFlag != null">deleted_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="materialCode != null and materialCode != ''">#{materialCode},</if>
            <if test="materialName != null and materialName != ''">#{materialName},</if>
            <if test="materialCategories != null and materialCategories != ''">#{materialCategories},</if>
            <if test="materialSubclass != null">#{materialSubclass},</if>
            <if test="materialTypeId != null">#{materialTypeId},</if>
            <if test="materialUnit != null">#{materialUnit},</if>
            <if test="materialMatkl != null">#{materialMatkl},</if>
            <if test="materialSpec != null">#{materialSpec},</if>
            <if test="factoryId != null">#{factoryId},</if>
            <if test="prodlineId != null">#{prodlineId},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="erpId != null">#{erpId},</if>
            <if test="deletedFlag != null">#{deletedFlag},</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="updateMesBaseMaterialInfo" parameterType="MesBaseMaterialInfo">
        update mes_base_material_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="materialCode != null and materialCode != ''">material_code = #{materialCode},</if>
            <if test="materialName != null and materialName != ''">material_name = #{materialName},</if>
            <if test="materialCategories != null and materialCategories != ''">material_categories = #{materialCategories},</if>
            <if test="materialSubclass != null">material_subclass = #{materialSubclass},</if>
            <if test="materialTypeId != null">material_type_id = #{materialTypeId},</if>
            <if test="materialUnit != null">material_unit = #{materialUnit},</if>
            <if test="materialMatkl != null">material_matkl = #{materialMatkl},</if>
            <if test="materialSpec != null">material_spec = #{materialSpec},</if>
            <if test="factoryId != null">factory_id = #{factoryId},</if>
            <if test="prodlineId != null">prodline_id = #{prodlineId},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="erpId != null">erp_id = #{erpId},</if>
            <if test="deletedFlag != null">deleted_flag = #{deletedFlag},</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 material_id = #{materialId}
    </update>

    <delete id="deleteMesBaseMaterialInfoByMaterialId" parameterType="Long">
        delete from mes_base_material_info where material_id = #{materialId}
    </delete>

    <delete id="deleteMesBaseMaterialInfoByMaterialIds" parameterType="String">
        delete from mes_base_material_info where material_id in
        <foreach item="materialId" collection="array" open="(" separator="," close=")">
            #{materialId}
        </foreach>
    </delete>





    <select id="selectMesBaseMaterialInfoListByMaterialIds" parameterType="String" resultMap="MesBaseMaterialInfoResult">
        <include refid="selectMesBaseMaterialInfoVo"/>
        where material_id in
        <foreach item="materialId" collection="array" open="(" separator="," close=")">
            #{materialId}
        </foreach>
    </select>


</mapper>
