<?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.keyDmMaterialLog" name="物料操作日志">

    <insert id="insertLog" parameterType="map">
        INSERT INTO jl_key_dm_material_log(
            id,category_id,material_id,op_type,relation_id,relation_item_id,quantity,unit_price,total_amount,is_used,create_by,create_time
        ) VALUES
        <foreach collection="details" item="item" separator=",">
        (
            UUID(),#{item.category_id},#{item.material_id},#{op_type},#{id},#{item.material_id},#{item.apply_quantity},#{item.unit_price},#{item.total_amount},1,#{approver_id},NOW()
        )
        </foreach>
    </insert>
    <insert id="insertLogByInbound" parameterType="map">
        INSERT INTO jl_key_dm_material_log(
        id,category_id,material_id,op_type,relation_id,relation_item_id,quantity,unit_price,total_amount,is_used,create_by,create_time
        ) VALUES
        <foreach collection="details" item="item" separator=",">
            (
            UUID(),#{item.category_id},#{item.material_id},#{inbound_type},#{id},#{item.material_id},#{item.inbound_quantity},#{item.unit_price},#{item.total_amount},1,#{create_by},NOW()
            )
        </foreach>
    </insert>
    <insert id="insertLogByReturn" parameterType="map">
        INSERT INTO jl_key_dm_material_log(
        id,category_id,material_id,op_type,relation_id,relation_item_id,quantity,unit_price,total_amount,is_used,create_by,create_time
        ) VALUES
        <foreach collection="details" item="item" separator=",">
            (
            UUID(),#{item.category_id},#{item.material_id},#{inbound_type},#{inbound_id},#{item.material_id},#{item.apply_quantity},#{item.unit_price},#{item.total_amount},1,#{create_by},NOW()
            )
        </foreach>
    </insert>
    <select id="selectLogsByApplicationId" parameterType="map" resultType="map">
        SELECT ml.*,m.material_name
        FROM jl_key_dm_material_log as ml
        left join jl_key_dm_material as m
        on ml.material_id = m.id
        WHERE relation_id = #{id}
        AND ml.is_used = 1 ORDER BY ml.create_time ASC
    </select>

</mapper>


