<?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.plate.PlateMapper">
    <select id="selectPlatePage" resultType="com.cf.imes.module.executor.controller.admin.plan.vo.PlatePage">
        select a.id as plateId, a.name, a.width, a.height, a.thickness, a.area,
        b.custom_order_no, b.customer, b.address, b.remark, b.id as orderId,
        c.goods_name, c.material, c.color, c.goods_id
        from order_plate a
        LEFT JOIN order_plan_item p on a.id = p.item_id
        LEFT JOIN `order` b on a.order_id = b.id
        LEFT JOIN order_goods c on a.order_id = c.order_id
        <where>
            p.id is null
            and a.is_cancel = 0
            <if test="orderId !=null">
               and a.order_id = #{orderId}
            </if>
            <if test="goodsId !=null and goodsId != '' ">
               and c.id = #{goodsId}
            </if>
        </where>
    </select>
    <select id="selectPlateByPlanId"
            resultType="com.cf.imes.module.executor.controller.admin.plan.vo.PlateResList">
        select a.order_id, a.plate_no , a.name, e.material, e.color, e.width, e.height, e.thickness, b.room_id, b.body_id
        from order_plate a
        LEFT JOIN order_item b ON a.id = b.plate_id
        LEFT JOIN order_goods e ON e.goods_id = a.goods_id AND e.order_id = a.order_id
        LEFT JOIN order_plan_item p ON b.id = p.item_id
            ${ew.customSqlSegment}


    </select>
    <select id="selectPlateList"
            resultType="com.cf.imes.module.executor.controller.admin.plan.vo.PlateParam">
        select a.id, a.plate_no, a.height length, a.width, a.texture, a.hole_arrange, a.hole_face,  if ( (count(a.unregular_point_count) = 0), 1, 0) as  isRect
        from order_plate a
        left join order_item b on a.id = b.plate_id
        where b.plan_id = #{planId}
        group by a.id

    </select>
</mapper>