<?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.cf.imes.module.executor.dal.mysql.planitem.PlanItemMapper">



    <resultMap id="GoodsListMap" type="com.cf.imes.module.executor.controller.admin.plan.vo.PlateInfoVO">
        <result property="planId" column="planId"/>
        <result property="material" column="material"/>
        <result property="width" column="width"/>
        <result property="height" column="height"/>
        <result property="thickness" column="thickness"/>
        <result property="color" column="color"/>
        <result property="count" column="plateNum"/>
        <result property="area" column="area"/>

    </resultMap>
    <select id="selectGoodsList" resultMap="GoodsListMap" parameterType="java.lang.Long">


        select distinct
            opi.plan_id as planId,
            og.material as material,
            og.width as width,
            og.height as height,
            og.thickness as thickness ,
            og.color as color,
        count(oi.plate_id) as plateNum,
        ROUND(og.height * og.width , 2) as area

        from order_plan_item opi
            join order_item oi on opi.item_id = oi.id and opi.organ_id = oi.organ_id
            join order_goods og on oi.order_id = og.order_id and oi.organ_id = og.organ_id

        where opi.organ_id = #{organId}
            and
            opi.plan_id  in
        <foreach collection="planIds" item="ids" open="(" close=")" separator=",">
            #{ids}
        </foreach>

        group by planId,material,width,height,thickness,color;

    </select>


    <select id="selectOrderList"
            resultType="com.cf.imes.module.executor.controller.admin.plan.vo.PlanOrderRespVO">



        select distinct
            opi.plan_id as planId,
            o.*

        from order_plan_item opi
                 join order_item oi on opi.item_id = oi.id and opi.organ_id = oi.organ_id
                 join orders o on oi.order_id = o.id
        where opi.organ_id = #{organId}
        and
        opi.plan_id  in
        <foreach collection="planIds" item="ids" open="(" close=")" separator=",">
            #{ids}
        </foreach>


    </select>


</mapper>