<?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.purchase.mapper.DrpPurPlanDetailMapper">

    <!-- 获取指定采购计划的详情列表 -->
    <select id="selectListByPlanId" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpPurPlanDetailPageVO">
        select dppd.detail_id,
               dppd.material_id,
               mm.material_name,
               mm.category_id,
               mm.material_code,
               mmc.category_name,
               dppd.unit_id,
               du.unit_name,
               dppd.size,
               dppd.pur_num,
               dppd.pro_plan_num,
               dppd.remark,
               dpp.pur_user_id,
               mm.image_url,
               if(mu.nick_name is null or mu.nick_name = '', mu.user_name, mu.nick_name) purUserName,
               dppd.inventory_num,
               dppd.unit_price,
               dppd.purchasing_budget_price,
               ( SELECT single_price FROM drp_order_goods_detail dogd where dogd.material_id =  dppd.material_id  order by create_time desc limit 1) AS lastPurMaterialPrice,
                ast.stall_name,
                ast.stall_id,
               dms1.supplier_id,
               ds1.supplier_name,
               dms1.alternative_supplier,
               dms2.supplier_id ca_supplier_id,
               ds2.supplier_name ca_supplier_name,
               dms2.alternative_supplier ca_alternative_supplier,
               dpp.canteen_id,
               mm.cert_id,
                dc.cert_name
        from drp_pur_plan_detail dppd
                 left join drp_purchase_plan dpp on dppd.plan_id = dpp.plan_id
                 left join sys_user mu on dpp.pur_user_id = mu.user_id
                 left join menu_material mm on dppd.material_id = mm.material_id
                 left join drp_unit du on dppd.unit_id = du.unit_id
                 left join menu_material_category mmc on mmc.category_id = mm.category_id
                 left join alloc_stall ast on dppd.stall_id = ast.stall_id
                 left join drp_menu_material_supplier dms1 on mm.material_id = dms1.material_id and dms1.canteen_id = dpp.canteen_id
                 left join drp_supplier ds1 on dms1.supplier_id = ds1.supplier_id
                 left join drp_menu_material_supplier dms2 on mm.category_id = dms2.category_id and dms2.canteen_id = dpp.canteen_id
                 left join drp_supplier ds2 on dms2.supplier_id = ds2.supplier_id
                 LEFT JOIN drp_certificate dc ON mm.cert_id = dc.cert_id
        where dppd.plan_id = #{planId}
    </select>
    <select id="listDetailById" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpPurPlanDetailListVO">
        SELECT
            a.detail_id,
            a.material_id,
            b.material_name,
            b.category_id,
            d.category_name,
            a.pur_num,
            a.pro_plan_num,
            a.unit_id,
            c.unit_name,
            a.size
        FROM
            drp_pur_plan_detail a
            LEFT JOIN menu_material b ON a.material_id = b.material_id
            LEFT JOIN drp_unit c ON c.unit_id = a.unit_id
            LEFT JOIN menu_material_category d ON d.category_id = b.category_id
        WHERE
            a.plan_id = #{planId}
    </select>
<!--    <select id="listExcelPurPlanDetail" resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpExcelPurPlanDetailVO">-->
<!--        SELECT-->
<!--            b.material_code,-->
<!--            b.material_name,-->
<!--            c.category_name,-->
<!--            e.unit_name,-->
<!--            a.pur_num,-->
<!--            a.pro_plan_num-->
<!--        FROM-->
<!--            drp_pur_plan_detail a-->
<!--            LEFT JOIN menu_material b ON b.material_id = a.material_id-->
<!--            LEFT JOIN menu_material_category c ON c.category_id = b.category_id-->
<!--            LEFT JOIN drp_unit e ON e.unit_id = a.unit_id-->
<!--        WHERE-->
<!--            a.plan_id = #{planId}-->
<!--    </select>-->
<!--    <select id="listDetailByIdList" resultType="com.bonus.canteen.core.supply.purchase.domain.bo.PurPlanDetailModel">-->
<!--        SELECT material_id,-->
<!--               unit_id,-->
<!--               pur_num,-->
<!--               pro_plan_num,-->
<!--               stall_id,-->
<!--               inventory_num,-->
<!--               purchasing_budget_price,-->
<!--               unit_price,-->
<!--               original_quantity-->
<!--        FROM drp_pur_plan_detail-->
<!--        WHERE-->
<!--        plan_id IN-->
<!--        <foreach collection="planIdList" item="planId" separator="," open="(" close=")">-->
<!--            #{planId}-->
<!--        </foreach>-->
<!--    </select>-->
<!--    <select id="pageFetchMaterialImportPurPlanDetail"-->
<!--            resultType="com.bonus.canteen.core.supply.purchase.domain.vo.DrpFetchMaterialImportPurPlanDetailPageVO">-->
<!--        SELECT a.detail_id,-->
<!--        a.material_id,-->
<!--        c.material_code,-->
<!--        c.material_name,-->
<!--        c.category_id,-->
<!--        e.category_name,-->
<!--        c.unit_id,-->
<!--        d.unit_name,-->
<!--        b.inventory_id,-->
<!--        b.material_num inventoryNum,-->
<!--        a.original_quantity as purNum,-->
<!--        a.stall_id,-->
<!--        ast.stall_name-->
<!--        FROM drp_pur_plan_detail a-->
<!--        JOIN drp_inventory b ON b.material_id = a.material_id-->
<!--        LEFT JOIN menu_material c ON c.material_id = a.material_id-->
<!--        LEFT JOIN drp_unit d ON d.unit_id = c.unit_id-->
<!--        LEFT JOIN menu_material_category e ON e.category_id = c.category_id-->
<!--        left join alloc_stall ast on ast.stall_id = a.stall_id-->
<!--        WHERE a.plan_id = #{content.planId}-->
<!--        AND b.warehouse_id = #{content.warehouseId}-->
<!--        <if test="content.stallIdList != null != null and content.stallIdList.size() > 0">-->
<!--            and a.stall_id IN-->
<!--            <foreach collection="content.stallIdList" item="item" separator="," open="(" close=")">-->
<!--                #{item}-->
<!--            </foreach>-->
<!--        </if>-->
<!--    </select>-->

</mapper>















































