<?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="cn.iocoder.yudao.module.system.dal.mysql.biz.MaterialOutboundOrderItemMapper">

    <!--
        统计一批入库明细（ref_inbound_item_id）在指定时间范围内对应的出库数量之和
     -->
    <select id="selectSumOutQtyByInboundItemIdsAndDate" resultType="java.util.Map">
        SELECT
            oi.ref_inbound_item_id AS refInboundItemId,
            SUM(oi.quantity)       AS totalQty
        FROM material_outbound_order_item oi
                 INNER JOIN material_outbound_order o ON oi.outbound_order_id = o.id
        WHERE oi.ref_inbound_item_id IN
              <foreach collection="inboundItemIds" item="id" open="(" separator="," close=")">
                  #{id}
              </foreach>
          <if test="startDate != null">
              AND o.order_date &gt;= #{startDate}
          </if>
          <if test="endDate != null">
              AND o.order_date &lt; #{endDate}
          </if>
        GROUP BY oi.ref_inbound_item_id
    </select>

</mapper>


