<?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.zg.project.information.mapper.DeliveryMtdMapper">
    
    <resultMap type="DeliveryMtd" id="DeliveryMtdResult">
        <result property="Id"    column="Id"    />
        <result property="wlNo"    column="wl_no"    />
        <result property="wlMs"    column="wl_ms"    />
        <result property="dw"    column="dw"    />
        <result property="weightKg"    column="weight_kg"    />
        <result property="volumeM3"    column="volume_m3"    />
        <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="isDelete"    column="is_delete"    />
    </resultMap>

    <sql id="selectDeliveryMtdVo">
        select Id, wl_no, wl_ms, dw, weight_kg, volume_m3, create_by, create_time, update_by, update_time, is_delete from delivery_mtd
    </sql>

    <select id="selectDeliveryMtdList" parameterType="DeliveryMtd" resultMap="DeliveryMtdResult">
        <include refid="selectDeliveryMtdVo"/>
        <where>  
            <if test="wlNo != null  and wlNo != ''"> and wl_no = #{wlNo}</if>
            <if test="wlMs != null  and wlMs != ''"> and wl_ms = #{wlMs}</if>
            <if test="dw != null  and dw != ''"> and dw = #{dw}</if>
            <if test="weightKg != null "> and weight_kg = #{weightKg}</if>
            <if test="volumeM3 != null "> and volume_m3 = #{volumeM3}</if>
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
        </where>
    </select>
    
    <select id="selectDeliveryMtdById" parameterType="Long" resultMap="DeliveryMtdResult">
        <include refid="selectDeliveryMtdVo"/>
        where Id = #{Id}
    </select>

    <insert id="insertDeliveryMtd" parameterType="DeliveryMtd" useGeneratedKeys="true" keyProperty="Id">
        insert into delivery_mtd
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wlNo != null">wl_no,</if>
            <if test="wlMs != null">wl_ms,</if>
            <if test="dw != null">dw,</if>
            <if test="weightKg != null">weight_kg,</if>
            <if test="volumeM3 != null">volume_m3,</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="isDelete != null">is_delete,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wlNo != null">#{wlNo},</if>
            <if test="wlMs != null">#{wlMs},</if>
            <if test="dw != null">#{dw},</if>
            <if test="weightKg != null">#{weightKg},</if>
            <if test="volumeM3 != null">#{volumeM3},</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="isDelete != null">#{isDelete},</if>
         </trim>
    </insert>

    <update id="updateDeliveryMtd" parameterType="DeliveryMtd">
        update delivery_mtd
        <trim prefix="SET" suffixOverrides=",">
            <if test="wlNo != null">wl_no = #{wlNo},</if>
            <if test="wlMs != null">wl_ms = #{wlMs},</if>
            <if test="dw != null">dw = #{dw},</if>
            <if test="weightKg != null">weight_kg = #{weightKg},</if>
            <if test="volumeM3 != null">volume_m3 = #{volumeM3},</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="isDelete != null">is_delete = #{isDelete},</if>
        </trim>
        where Id = #{Id}
    </update>

    <insert id="batchUpsertDeliveryMtd" parameterType="java.util.List">
        INSERT INTO delivery_mtd
        (wl_no, wl_ms, dw, weight_kg, volume_m3, create_by, create_time, update_by, update_time, is_delete)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.wlNo}, #{item.wlMs}, #{item.dw}, #{item.weightKg}, #{item.volumeM3},
            #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.isDelete})
        </foreach>
        ON DUPLICATE KEY UPDATE
        wl_ms        = VALUES(wl_ms),
        dw           = VALUES(dw),
        weight_kg    = VALUES(weight_kg),
        volume_m3    = VALUES(volume_m3),
        update_by    = VALUES(update_by),
        update_time  = VALUES(update_time),
        is_delete    = VALUES(is_delete)
    </insert>

    <delete id="deleteDeliveryMtdById" parameterType="Long">
        delete from delivery_mtd where Id = #{Id}
    </delete>

    <delete id="deleteDeliveryMtdByIds" parameterType="String">
        delete from delivery_mtd where Id in 
        <foreach item="Id" collection="array" open="(" separator="," close=")">
            #{Id}
        </foreach>
    </delete>
</mapper>