<?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.wms.mapper.WmsWarehouseMaterialMapper">

    <resultMap type="WmsWarehouseMaterial" id="WmsWarehouseMaterialResult">
        <result property="warehouseMaterialId"    column="warehouse_material_id"    />
        <result property="warehouseId"    column="warehouse_id"    />
        <result property="locationCode"    column="location_code"    />
        <result property="storageType"    column="storage_type"    />
        <result property="storageId"    column="storage_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="materialCode"    column="material_code"    />
        <result property="materialName"    column="material_name"    />
    </resultMap>

    <sql id="selectWmsWarehouseMaterialVo">
        select warehouse_id, location_code, storage_type, storage_id, create_time, create_by from wms_warehouse_material
    </sql>

    <select id="selectWmsWarehouseMaterialList" parameterType="WmsWarehouseMaterial" resultMap="WmsWarehouseMaterialResult">
        <include refid="selectWmsWarehouseMaterialVo"/>
        <where>
        </where>
    </select>

    <select id="selectWmsWarehouseMaterialByWarehouseId" parameterType="Long" resultMap="WmsWarehouseMaterialResult">
        <include refid="selectWmsWarehouseMaterialVo"/>
        where warehouse_id = #{warehouseId}
    </select>

    <insert id="insertWmsWarehouseMaterial" parameterType="WmsWarehouseMaterial">
        insert into wms_warehouse_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="warehouseId != null">warehouse_id,</if>
            <if test="locationCode != null">location_code,</if>
            <if test="storageType != null">storage_type,</if>
            <if test="storageId != null">storage_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="warehouseId != null">#{warehouseId},</if>
            <if test="locationCode != null">#{locationCode},</if>
            <if test="storageType != null">#{storageType},</if>
            <if test="storageId != null">#{storageId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
         </trim>
    </insert>

    <update id="updateWmsWarehouseMaterial" parameterType="WmsWarehouseMaterial">
        update wms_warehouse_material
        <trim prefix="SET" suffixOverrides=",">
            <if test="locationCode != null">location_code = #{locationCode},</if>
            <if test="storageType != null">storage_type = #{storageType},</if>
            <if test="storageId != null">storage_id = #{storageId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
        </trim>
        where warehouse_id = #{warehouseId}
    </update>

    <delete id="deleteWmsWarehouseMaterialByWarehouseMaterialId" parameterType="Long">
        delete from wms_warehouse_material where warehouse_material_id = #{warehouseMaterialId}
    </delete>

    <delete id="deleteWmsWarehouseMaterialByWarehouseMaterialIds" parameterType="String">
        delete from wms_warehouse_material where warehouse_material_id in
        <foreach item="warehouseMaterialId" collection="array" open="(" separator="," close=")">
            #{warehouseMaterialId}
        </foreach>
    </delete>




    <select id="selectWmsWarehouseMaterialJoinList" parameterType="WmsWarehouseMaterial" resultMap="WmsWarehouseMaterialResult">
        select wwm.warehouse_material_id,wwm.warehouse_id, wwm.location_code, wwm.storage_type, wwm.storage_id, wwm.create_time, wwm.create_by,
        mbm.material_code,mbm.material_name
        from wms_warehouse_material wwm left join mes_base_material_info mbm on wwm.storage_id=mbm.material_id and wwm.storage_type='1'
        <where>
            <if test="warehouseId != null "> and warehouse_id = #{warehouseId}</if>
        </where>
    </select>

    <insert id="batchInsertWarehouseMaterial">
        insert into wms_warehouse_material(warehouse_id, storage_type,storage_id,create_time,create_by) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.warehouseId},#{item.storageType},#{item.storageId},#{item.createTime},#{item.createBy})
        </foreach>
    </insert>


</mapper>
