<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.keyDmInboundDetail" name="入库明细">

    <insert id="insertDetail" parameterType="map">
        INSERT INTO jl_key_dm_inbound_detail(
            id,inbound_id,material_id,inbound_type,inbound_quantity,unit_price,total_amount,production_date,expiry_date,is_used,create_by,create_time
        ) VALUES (
            #{id},#{inbound_id},#{material_id},#{inbound_type},#{inbound_quantity},#{unit_price},#{total_amount},#{production_date},#{expiry_date},1,#{_user.id},NOW()
        )
    </insert>

    <select id="selectDetailsByInboundId" parameterType="map" resultType="map">
        SELECT i.*,
        m.material_code, m.material_name, m.category_id
        FROM jl_key_dm_inbound_detail as i
        left join jl_key_dm_material as m
        on i.material_id = m.id
        WHERE i.inbound_id = #{id} AND i.is_used = 1 ORDER BY i.create_time ASC
    </select>

<!--    <delete id="deleteDetailsByInboundId" parameterType="map">-->
<!--        DELETE FROM jl_key_dm_inbound_detail WHERE inbound_id = #{id}-->
<!--    </delete>-->

    <update id="deleteDetailsByInboundId" parameterType="map">
        UPDATE jl_key_dm_inbound_detail SET is_used = 0, update_by = #{_user.id}, update_time = NOW() WHERE inbound_id = #{id}
    </update>
</mapper>


