<?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.bonus.canteen.core.supply.mapper.DrpOrderGoodsDetailMapperV2">
    <update id="plusIntoNum">
        UPDATE drp_order_goods_detail set into_num = IFNULL(into_num,0) + #{plusNum} where order_goods_detail_id = #{orderGoodsDetailId}
    </update>
    <update id="minusIntoNum">
        UPDATE drp_order_goods_detail set into_num = into_num - #{minusNum} where order_goods_detail_id = #{orderGoodsDetailId}
    </update>
    <select id="getDrpOrderGoodsDetailVOListByOrderGoodsId" resultType="com.bonus.canteen.core.supply.vo.DrpOrderGoodsDetailVO">
        SELECT t1.order_goods_detail_id,
               t1.order_goods_id,
               t1.material_id,
               t2.material_name,
               t2.category_id,
               t2.material_code,
               t3.category_name,
               t2.unit_id,
               t4.unit_name,
               t1.size,
               t1.order_num,
               t1.single_price,
               t1.total_price,
               t2.image_url,
               t5.supplier_id,
               t6.supplier_name,
               t1.into_num,
               t1.remark,
               t1.stall_id,
               ast.stall_name
        FROM drp_order_goods_detail t1
                 LEFT JOIN menu_material t2 ON t1.material_id = t2.material_id
                 LEFT JOIN menu_material_category t3 ON t3.category_id = t2.category_id
                 LEFT JOIN drp_unit t4 ON t2.unit_id = t4.unit_id
                 left join drp_order_goods t5 on t5.order_goods_id = t1.order_goods_id
                 left join drp_supplier t6 on t6.supplier_id = t5.supplier_id
                 left join alloc_stall ast on t1.stall_id = ast.stall_id
        WHERE t1.order_goods_id = #{orderGoodsId}
    </select>
    <select id="listOrderIntoNum" resultType="com.bonus.canteen.core.supply.po.OrderIntoNumModel">
        SELECT
            order_goods_id,
            IF(sum( into_num ) is NULL,0,sum( into_num )) totalIntoNum
        FROM
            drp_order_goods_detail
        where order_goods_id in
        <foreach collection="orderGoodsIdList" item="orderGoodsId" separator="," open="(" close=")">
            #{orderGoodsId}
        </foreach>
            GROUP BY order_goods_id
    </select>
    <select id="listMaterialStallNum"
            resultType="com.bonus.canteen.core.supply.po.DrpOrderGoodsMaterialStallNumModel">
        select material_id,stall_id,order_num-into_num notIntoNum from drp_order_goods_detail where order_goods_id = #{orderGoodsId}
    </select>
</mapper>
