<?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="selectProductList"
            resultType="com.cf.imes.module.executor.controller.admin.plate.vo.PlateRespVO">
        SELECT DISTINCT a.id, a.plate_no, a.height, a.thickness, a.width, a.name, a.area, a.seal_left, a.seal_right,
                        a.seal_up, a.seal_down, a.texture, a.hole_face, a.hole_arrange, a.unregular_point_count, a.front_hole_count, a.back_hole_count,
                        a.side_hole_count, a.front_model_count, a.back_model_count, a.remark, c.material, c.color
        FROM order_plate a
                 LEFT JOIN order_goods c ON a.goods_id = c.id AND a.order_id = c.order_id and a.organ_id = c.organ_id
                 LEFT JOIN order_item b ON a.id = b.plate_id and a.organ_id = b.organ_id
        WHERE b.organ_id = #{organId} and  b.order_id = #{orderId}
          AND (#{roomId} IS NULL OR b.room_id = #{roomId})
          AND (#{bodyId} IS NULL OR b.body_id = #{bodyId})
        GROUP BY a.id, c.material, c.color;
    </select>



    <resultMap id="PlateDetialMap" type="com.cf.imes.module.executor.controller.admin.plan.vo.PlateDetailRespVO">

        <result property="plateId" column="plateId"/>
        <result property="orderId" column="orderId"/>
        <result property="id" column="goodsId"/>
        <result property="goodsId" column="plateGoodsId"/>
        <result property="plateNo" column="plateNo"/>
        <result property="customPlateNo" column="customPlateNo"/>
        <result property="name" column="name"/>
        <result property="color" column="color"/>
        <result property="material" column="material"/>
        <result property="brand" column="brand"/>
        <result property="height" column="height"/>
        <result property="width" column="width"/>
        <result property="thickness" column="thickness"/>
        <result property="splitWidth" column="splitWidth"/>
        <result property="splitHeight" column="splitHeight"/>
        <result property="splitThickness" column="splitThickness"/>
        <result property="isSpecialShaped" column="isSpecialShaped"/>
        <result property="sealLeft" column="sealLeft"/>
        <result property="sealRight" column="sealRight"/>
        <result property="sealUp" column="sealUp"/>
        <result property="sealDown" column="sealDown"/>
        <result property="area" column="area"/>
        <result property="texture" column="texture"/>
        <result property="holeFace" column="holeFace"/>
        <result property="holeArrange" column="holeArrange"/>
        <result property="unregularPointCount" column="unregularPointCount"/>
        <result property="frontHoleCount" column="frontHoleCount"/>
        <result property="backHoleCount" column="backHoleCount"/>
        <result property="sideHoleCount" column="sideHoleCount"/>
        <result property="frontModelCount" column="frontModelCount"/>
        <result property="backModelCount" column="backModelCount"/>
        <result property="isDoor" column="isDoor"/>
        <result property="isArcAcross" column="isArcAcross"/>
        <result property="moduleTypeId" column="moduleTypeId"/>
        <result property="isSculpt" column="isSculpt"/>
        <result property="filterType" column="filterType"/>
        <result property="offsetX" column="offsetX"/>
        <result property="offsetY" column="offsetY"/>
        <result property="remark" column="remark"/>
        <result property="isCancel" column="isCancel"/>
        <result property="type" column="type"/>
        <result property="openDoorType" column="openDoorType"/>
        <result property="hasHole" column="hasHole"/>

        <result property="bodyId" column="bodyId"/>
        <result property="goodsName" column="goodsName"/>
        <result property="roomId" column="roomId"/>
        <result property="bodyName" column="bodyName"/>
        <result property="roomName" column="roomName"/>
        <result property="hasHole" column="hasHole"/>

        <result property="isSideSculpt" column="isSideSculpt"/>
        <result property="is2v" column="is2v"/>
        <result property="isSide2v" column="isSide2v"/>

        <collection property="processGroupLists" javaType="java.util.List"   ofType="com.cf.imes.module.executor.controller.admin.plan.bo.ProcessGroupList"  >

            <result property="groupId" column="groupId"/>
            <result property="groupName" column="groupName"/>
        </collection >
    </resultMap>



    <select id="selectPlateGoodsList" resultType="com.cf.imes.module.executor.controller.admin.plate.vo.PlateGoodsRespVO">

        select distinct
               op.id,
               op.name,
               op.goods_id,
               ogs.goods_name,
               op.front_hole_count,
               op.back_hole_count,
               op.side_hole_count,
               op.unregular_point_count,
               op.front_model_count,
               op.back_model_count,
               op.hole_arrange,
               op.hole_face,
               op.texture,
               op.type,
               op.open_door_type,
               op.filter_type,
               op.seal_left,
               op.seal_right,
               op.seal_up,
               op.seal_down,
               op.offset_x,
               op.offset_y,
               op.is_arc_across,
               op.is_door,
               op.is_cancel,
               op.remark,
               op.plate_no,
               op.split_height,
               op.split_width,
               op.split_thickness,
               op.module_type_id,
               op.height,
               op.width,
               op.thickness,
               op.area,
               op.is_special_shaped,
               op.is_sculpt,
               ogs.price,
               ogs.brand,
               ogs.height    as goods_height,
               ogs.width     as goods_width,
               ogs.thickness as goods_thickness,
               ogs.color,
               ogs.material,
               ogs.spec,
               bdy.id as body_id,
               bdy.`name` as body_name,
               bdy.room_id,
               bdy.room_name
        from order_plate op
                 left join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id
                 left join order_item its on op.organ_id = its.organ_id and op.order_id = its.order_id and op.id = its.plate_id
                 left join order_body bdy on its.organ_id = bdy.organ_id and its.order_id = bdy.order_id and its.body_id = bdy.id
        where op.organ_id = #{organId}
          and op.deleted = #{deleted}
          and op.order_id = #{orderId}
    </select>

    <select id="selectPlateGoodsListSummary" resultType="com.cf.imes.module.executor.controller.admin.plate.vo.PlateGoodsRespVO">

        select distinct
               op.id,
               op.name,
               op.open_door_type,
               op.height,
               op.width,
               op.thickness,
               op.area,
               ogs.thickness as goods_thickness,
               ogs.color,
               ogs.material,
               ogs.spec,
               bdy.id as body_id,
               bdy.`name` as body_name,
               bdy.room_id,
               bdy.room_name
        from order_plate op
                 left join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id
                 left join order_item its on op.organ_id = its.organ_id and op.order_id = its.order_id and op.id = its.plate_id
                 left join order_body bdy on its.organ_id = bdy.organ_id and its.order_id = bdy.order_id and its.body_id = bdy.id
        where op.order_id = #{orderId}
          and op.organ_id = #{organId}
          and op.deleted = #{deleted}
    </select>

    <update id="updateDeletedById">
        UPDATE order_plate
        SET deleted = #{deleted},is_optimized = false
        WHERE  organ_id = #{organId}
        and order_id = #{orderId}
        and id IN
        <foreach item="plateId" collection="plateIds" open="(" separator="," close=")">
            #{plateId}
        </foreach>
    </update>


    <update id="updateDeletedPlate">
        UPDATE order_plate
        SET deleted = true,is_optimized = false
        WHERE  organ_id = #{organId}
        and order_id = #{orderId}
        and id IN
        <foreach item="plateId" collection="plateIds" open="(" separator="," close=")">
            #{plateId}
        </foreach>
    </update>


    <update id="updateNoDeletedPlate">
        UPDATE order_plate
        SET deleted = false,is_optimized = false
        WHERE  organ_id = #{organId}
        and order_id = #{orderId}
        and id IN
        <foreach item="plateId" collection="plateIds" open="(" separator="," close=")">
            #{plateId}
        </foreach>
    </update>



    <delete id="deletedById">
        DELETE FROM order_plate
        WHERE id IN
        <foreach collection="plateIds" item="plateId" open="(" separator="," close=")">
            #{plateId}
        </foreach>
        AND organ_id = #{organId}
    </delete>

    <select id="countPlateByOrderId" resultType="java.lang.Integer">
        SELECT count(*) FROM order_plate
        WHERE order_id = #{orderId} AND organ_id = #{organId} AND deleted = #{deleted}
    </select>

    <select id="selectPlateSize" resultType="java.math.BigDecimal">


        select sum(area) from order_plate where order_id = #{orderId};


    </select>


    <select id="selectPlateIdListByBodyId" resultType="java.lang.Long">
        SELECT plate_id FROM order_item
        WHERE body_id = #{bodyId} AND organ_id = #{organId}
    </select>

    <select id="selectPlateGoodsListByList" resultType="com.cf.imes.module.executor.controller.admin.plate.vo.PlateGoodsIdVO">
        SELECT order_id, id, goods_id, deleted
        FROM order_plate op
        WHERE op.organ_id = #{organId} AND op.order_id = #{orderId} AND op.id in

        <foreach collection="plates" item="plate" open="(" close=")" separator=",">

            #{plate}

        </foreach>
    </select>


    <resultMap id="GoodsPageMap" type="com.cf.imes.module.executor.controller.admin.plan.vo.NotPlanOrderPlateRespVO">


        <result property="width" column="width"/>
        <result property="height" column="height"/>
        <result property="thickness" column="thickness"/>
        <result property="goodsName" column="goods_name"/>
        <result property="material" column="material"/>
        <result property="color" column="color"/>
        <result property="texture" column="texture"/>
        <result property="brand" column="brand"/>
        <result property="goodsId" column="goodsId"/>

        <collection property="orderIdList" ofType="com.cf.imes.module.executor.controller.admin.plan.bo.OrderIds" resultMap="OrderIdMap"/>

    </resultMap>

    <resultMap id="OrderIdMap" type="com.cf.imes.module.executor.controller.admin.plan.bo.OrderIds">

        <result property="orderId" column="orderId"/>
        <result property="id" column="id"/>
        <result property="goodsId" column="goodsId"/>

    </resultMap>


<select id="selectPlateTypeByRoomId"
        resultType="com.cf.imes.module.executor.dal.dataobject.plate.PlateDO" parameterType="java.lang.Long">

        SELECT distinct p.*
            FROM order_plate p
        LEFT JOIN order_item i ON p.organ_id = i.organ_id and p.order_id = i.order_id and p.id = i.plate_id
            WHERE i.organ_id = #{organId} AND i.order_id = #{orderId} AND p.deleted = #{deleted}
                            AND i.body_id IN
                        <foreach item="roomIdItem" collection="bodyIds" open="(" separator="," close=")">
                                #{roomIdItem}
                        </foreach>
</select>


    <select id="selectNoDeletedPlate"
            resultType="com.cf.imes.module.executor.dal.dataobject.plate.PlateDO" parameterType="java.lang.Long">

        SELECT distinct p.*
        FROM order_plate p
        LEFT JOIN order_item i ON p.organ_id = i.organ_id and p.order_id = i.order_id and p.id = i.plate_id
        WHERE i.organ_id = #{organId}
          AND i.order_id = #{orderId}
          AND i.body_id IN
        <foreach item="roomIdItem" collection="bodyIds" open="(" separator="," close=")">
              #{roomIdItem}
        </foreach>
          AND p.deleted = false

    </select>


    <select id="selectDeletedPlate"
            resultType="com.cf.imes.module.executor.dal.dataobject.plate.PlateDO" parameterType="java.lang.Long">

        SELECT distinct p.*
        FROM order_plate p
        LEFT JOIN order_item i ON p.organ_id = i.organ_id and p.order_id = i.order_id and p.id = i.plate_id
        WHERE i.organ_id = #{organId}
        AND i.order_id = #{orderId}
        AND i.body_id IN
        <foreach item="roomIdItem" collection="bodyIds" open="(" separator="," close=")">
            #{roomIdItem}
        </foreach>
        AND p.deleted = true

    </select>




    <select id="selectPlanPlateListDataSource" resultType="java.util.Map">


        select ${filed} from order_plate
                        where   organ_id = #{organId}
                          and deleted = false
                          and order_id in
        <foreach collection="orderIds" item="orderIds" open="(" close=")" separator=",">
            #{orderIds}
        </foreach>
                          and goods_id in
        <foreach collection="goodsIdList" item="goodsIdList" open="(" close=")" separator=",">
            #{goodsIdList}
        </foreach>

        ${field2}

    </select>

    <resultMap id="OrderSourcePlateDetialMap" type="com.cf.imes.module.executor.controller.admin.plan.vo.PlateDetailRespVO">
        <result property="goodsId" column="plateGoodsId"/>
        <result property="goodsName" column="goodsName"/>
        <result property="brand" column="brand"/>
        <result property="color" column="color"/>
        <result property="material" column="material"/>
        <result property="plateId" column="plateId"/>
        <result property="orderId" column="orderId"/>
        <result property="name" column="name"/>
        <result property="plateNo" column="plateNo"/>
        <result property="customPlateNo" column="customPlateNo"/>
        <result property="type" column="type"/>
        <result property="id" column="goodsId"/>
        <result property="width" column="width"/>
        <result property="height" column="height"/>
        <result property="thickness" column="thickness"/>
        <result property="splitWidth" column="splitWidth"/>
        <result property="splitHeight" column="splitHeight"/>
        <result property="sealLeft" column="sealLeft"/>
        <result property="sealRight" column="sealRight"/>
        <result property="sealUp" column="sealUp"/>
        <result property="sealDown" column="sealDown"/>
        <result property="area" column="area"/>
        <result property="texture" column="texture"/>
        <result property="holeFace" column="holeFace"/>
        <result property="openDoorType" column="openDoorType"/>
        <result property="offsetX" column="offsetX"/>
        <result property="offsetY" column="offsetY"/>
        <result property="isSpecialShaped" column="isSpecialShaped"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <select id="selectPlateListByGoodsIds"
            resultMap="OrderSourcePlateDetialMap">

        select
        ogs.goods_id as plateGoodsId,
        ogs.goods_name as goodsName,
        ogs.brand as brand,
        ogs.color as color,
        ogs.material as material,
        op.id as plateId,
        op.order_id as orderId,
        op.name as name,
        op.plate_no as plateNo,
        op.custom_plate_no as customPlateNo,
        op.type as type,
        op.goods_id as goodsId,
        op.width as width,
        op.height as height,
        op.thickness as thickness,
        op.seal_left as sealLeft,
        op.seal_right as sealRight,
        op.seal_up as sealUp,
        op.seal_down as sealDown,
        op.area as area,
        op.texture as texture,
        op.hole_face as holeFace,
        op.open_door_type as openDoorType,
        op.is_special_shaped as isSpecialShaped,
        op.remark as remark

        from order_plate op
            join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id

        where op.organ_id = #{organId}
          and op.deleted = false
          and op.order_id = #{orderId}

    </select>





    <select id="selectNoPlanPlate" resultMap="PlateDetialMap">


        select distinct
            oi.group_id as groupId,
            og.name as groupName,
            ogs.goods_id as plateGoodsId,
            ogs.goods_name as goodsName,

            ogs.color as color,
            ogs.material as material,
            op.id as plateId,
            op.order_id as orderId,
            op.name as name,
            op.plate_no as plateNo,
            op.custom_plate_no as customPlateNo,
            op.type as type,
            op.goods_id as goodsId,
            op.width as width,
            op.height as height,
            op.thickness as thickness,
            op.split_width as splitWidth,
            op.split_height as splitHeight,
            op.split_thickness as splitThickness,
            op.seal_left as sealLeft,
            op.seal_right as sealRight,
            op.seal_up as sealUp,
            op.seal_down as sealDown,
            op.area as area,
            op.texture as texture,
            op.hole_face as holeFace,
            op.hole_arrange as holeArrange,
            op.is_door as isDoor,
            op.open_door_type as openDoorType,
            op.offset_x as offsetX,
            op.offset_y as offsetY,
            op.is_special_shaped as isSpecialShaped,
            op.is_sculpt as isSculpt,
            op.is_row_hole as hasHole,
            op.remark as remark

        from order_plate op
                 join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id
                 left join order_item oi on op.organ_id = oi.organ_id and op.order_id  = oi.order_id and op.id = oi.plate_id and oi.plate_id != 0
                 left join order_group og on oi.organ_id = og.organ_id and oi.order_id = og.order_id and oi.group_id = og.id
        where op.organ_id = #{organId}

        and op.order_id in
        <foreach collection="orderIds" item="orderIds" open="(" close=")" separator=",">
            #{orderIds}
        </foreach>

        and op.goods_id in
        <foreach collection="ids" item="ids" open="(" close=")" separator=",">
            #{ids}
        </foreach>

        and op.deleted = false

        and op.plan_id = 0


    </select>










    <resultMap id="PlatePageMap" type="com.cf.imes.module.executor.controller.admin.plan.vo.PlatePage">

        <result property="orderId" column="orderId"/>
        <result property="plateId" column="plateId"/>
        <result property="area" column="area"/>


    </resultMap>



    <update id="updatePlateOptimized" parameterType="java.lang.Long">

        update order_plate

        set is_optimized = true

        where organ_id = #{organId}
          and deleted = false

          and order_id in
        <foreach item="orderIdList" collection="orderIdList" open="(" separator="," close=")">
            #{orderIdList}
        </foreach>

          and goods_id in
        <foreach item="ids" collection="ids" open="(" separator="," close=")">
            #{ids}
        </foreach>

          and is_optimized = false

    </update>



    <update id="updatePlateIsOptimized" parameterType="java.lang.Long">

        update order_plate

        set is_optimized = true

        where organ_id = #{organId}
        and deleted = false

        and order_id in
        <foreach item="orderIdList" collection="orderIdList" open="(" separator="," close=")">
            #{orderIdList}
        </foreach>

        and goods_id in
        <foreach item="ids" collection="ids" open="(" separator="," close=")">
            #{ids}
        </foreach>

        and id in
        <foreach item="plateIds" collection="plateIds" open="(" separator="," close=")">
            #{plateIds}
        </foreach>

        and is_optimized = false

    </update>





    <update id="updateNoPlateOptimized">

        update order_plate

        set is_optimized = false

        <where> organ_id = #{organId}
        and deleted = false
        and order_id in
        <foreach item="orderIdList" collection="orderIdList" open="(" separator="," close=")">
            #{orderIdList}
        </foreach>
        and goods_id in
        <foreach item="ids" collection="ids" open="(" separator="," close=")">
            #{ids}
        </foreach>

        <if test="plateIds != null">
            and id in
            <foreach item="plateIds" collection="plateIds" open="(" separator="," close=")">
                #{plateIds}
            </foreach>
        </if>

        and is_optimized = true
        </where>

    </update>


    <resultMap id="PackListMap" type="com.cf.imes.module.executor.controller.admin.plan.saveOptimize.PrintOrderPackReqVO">

        <result property="orderId" column="orderId"/>
        <result property="packId" column="packId"/>
        <result property="packNo" column="packNo"/>
        <result property="packNum" column="packNum"/>

        <collection property="plateId" ofType="java.lang.Long" column="plateId"/>

    </resultMap>


    <select id="selectPlanPackList"
            parameterType="java.lang.Long"
            resultMap="PackListMap">


        select distinct op.id as plateId,
        op.order_id as orderId,
        o.id as packId,
        o.package_no as packNo
        from order_plate op
        left join order_item oi on op.organ_id = oi.organ_id and op.order_id = oi.order_id and op.id = oi.plate_id
        left join order_package o on oi.organ_id = o.organ_id and oi.order_id = o.order_id and oi.package_id = o.id

        where op.organ_id = #{organId}
        and op.deleted = false
        and op.goods_id in
        <foreach item="ids" collection="ids" open="(" separator="," close=")">
            #{ids}
        </foreach>
        and oi.parts_id = 0
        and oi.package_id !=0


    </select>


    <select id="selectOrderPackList" parameterType="java.lang.Long" resultMap="PackListMap">

        select distinct op.id as plateId,
                        op.order_id as orderId,
                        o.id as packId,
                        o.package_no as packNo
        from order_plate op
                 left join order_item oi on op.organ_id = oi.organ_id and op.order_id = oi.order_id and op.id = oi.plate_id
                 left join order_package o on oi.organ_id = o.organ_id and oi.order_id = o.order_id and oi.package_id = o.id

        where op.organ_id = #{organId}
          and op.deleted = false
          and op.order_id = #{orderId}
          and oi.parts_id = 0
          and oi.package_id !=0


    </select>


    <update id="updatePlateOptimizedStatus">

        update order_plate

        set is_optimized = true

        where organ_id = #{organId}
        and deleted = false
        and order_id = #{orderId}
        and id in
        <foreach item="plateDOList" collection="plateDOList" open="(" separator="," close=")">
            #{plateDOList}
        </foreach>

    </update>






    <select id="selectOrderPlateListSummary" resultType="com.cf.imes.module.executor.controller.admin.plate.vo.PlateGoodsRespVO">

        select distinct
            op.id,
            op.name,
            op.open_door_type,
            op.height,
            op.width,
            op.thickness,
            op.area,
            ogs.thickness as goods_thickness,
            ogs.color,
            ogs.material,
            ogs.spec,
            bdy.id as body_id,
            bdy.`name` as body_name,
            bdy.room_id,
            bdy.room_name
        from order_plate op
                 left join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id
                 left join order_item its on op.organ_id = its.organ_id and op.order_id = its.order_id and op.id = its.plate_id
                 left join order_body bdy on its.organ_id = bdy.organ_id and its.order_id = bdy.order_id and its.body_id = bdy.id
        where op.order_id = #{orderId}
          and op.organ_id = #{organId}
          and op.deleted = #{deleted}
        <if test="roomId != null">
            and its.room_id = #{roomId}
        </if>
        <if test="bodyId != null">
            and its.body_id = #{bodyId}
        </if>
        <if test="bodyId == null">
            and its.id = #{plateId}
        </if>
    </select>

    <select id="selectListByOrderId"
            resultType="com.cf.imes.module.executor.controller.admin.manage.process.vo.PlateDetails">


        select  id as plateId ,plate_no,height as length, width,thickness
        from order_plate  where order_id = #{orderId} and organ_id = #{organId};


    </select>


    <resultMap id="PlateMap" type="com.cf.imes.module.executor.controller.admin.manage.pack.vo.PackRespVO">


        <result property="id" column="orderId"/>

        <collection property="plateIdList" ofType="java.lang.Long" column="plateId"/>


    </resultMap>



    <select id="selectPackPlateNum" resultMap="PlateMap">

        select
        order_id as orderId,
        id as plateId

        from order_plate

        where organ_id = #{organId}

        and deleted = false

        and order_id  in
        <foreach item="orderIds" collection="orderIds" open="(" separator="," close=")">
            #{orderIds}
        </foreach>


    </select>

    <resultMap id="PlateDetailsMap" type="com.cf.imes.module.executor.controller.admin.manage.pack.vo.PlateDetailsRespVO">
        <result property="packageId" column="packageId"/>
        <result property="roomName" column="roomName"/>
        <result property="cabinetName" column="bodyName"/>
        <result property="plateId" column="plateId"/>
        <result property="plateNo" column="plateNo"/>
        <result property="orderId" column="orderId"/>
        <result property="plateName" column="plateName"/>
        <result property="customPlateNo" column="customPlateNo"/>
        <result property="material" column="plateMaterial"/>
        <result property="color" column="plateColor"/>
        <result property="width" column="plateWidth"/>
        <result property="height" column="plateHeight"/>
        <result property="thickness" column="plateThickness"/>
        <result property="area" column="plateArea"/>
        <result property="texture" column="texture"/>
        <result property="specialShaped" column="specialShaped"/>
        <result property="profiling" column="profiling"/>
        <result property="rowHole" column="rowHole"/>
        <result property="remark" column="remark"/>
        <result property="holeFace" column="holeFace"/>
        <result property="holeArrange" column="holeArrange"/>
        <result property="openDoorType" column="openDoorType"/>

        <result property="isSideSculpt" column="isSideSculpt"/>
        <result property="is2v" column="is2v"/>
        <result property="isSide2v" column="isSide2v"/>

        <collection property="processGroupNameList" javaType="java.util.List"  ofType="com.cf.imes.module.executor.controller.admin.manage.pack.vo.GroupNameList">
            <result property="name" column="name"/>
        </collection>

    </resultMap>

    <select id="selectOrderNoPackPlateList"
            parameterType="java.lang.Long"
            resultMap="PlateDetailsMap" >


        select distinct
            og.name as name,
            ob.room_name as roomName,
            ob.name as bodyName,
            op.id as plateId,
            op.plate_no as plateNo,
            op.name as plateName,
            op.custom_plate_no as customPlateNo,
            ogs.material as plateMaterial,
            ogs.color as plateColor,
            op.order_id as orderId,
            op.height as plateHeight,
            op.width as plateWidth,
            op.thickness as plateThickness,
            op.area as plateArea,
            op.texture as texture ,
            op.remark as remark,
            op.is_special_shaped as specialShaped,
            op.is_sculpt as profiling,
            op.is_row_hole as rowHole,
            op.hole_face as holeFace,
            op.hole_arrange as holeArrange,
            op.open_door_type as openDoorType,
            op.is_side_sculpt as isSideSculpt,
            op.is_2v as is2v,
            op.is_side_2v as isSide2v

        from order_plate op
                 left join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id
                 left join order_item oi on op.organ_id = oi.organ_id and op.order_id  = oi.order_id and op.id = oi.plate_id
                 left join order_group og on oi.organ_id = og.organ_id and oi.order_id = og.order_id and oi.group_id = og.id
                 left join order_body ob on oi.organ_id = ob.organ_id and oi.order_id = ob.order_id and oi.body_id = ob.id
        where
            op.organ_id = #{organId} and op.deleted = false and op.order_id = #{orderId} and oi.package_id = 0 ;


    </select>


    <select id="selectOrderPackPlateList"
            parameterType="java.lang.Long"
            resultMap="PlateDetailsMap">


        select distinct
        oi.package_id as packageId,
        og.name as name,
        ob.room_name as roomName,
        ob.name as bodyName,
        op.id as plateId,
        op.plate_no as plateNo,
        op.custom_plate_no as customPlateNo,
        op.name as plateName,
        ogs.material as plateMaterial,
        ogs.color as plateColor,
        op.order_id as orderId,
        op.height as plateHeight,
        op.width as plateWidth,
        op.thickness as plateThickness,
        op.area as plateArea,
        op.texture as texture ,
        op.remark as remark,
        op.is_special_shaped as specialShaped,
        op.is_sculpt as profiling,
        op.is_row_hole as rowHole,
        op.hole_face as holeFace,
        op.hole_arrange as holeArrange,
        op.open_door_type as openDoorType,
        op.is_side_sculpt as isSideSculpt,
        op.is_2v as is2v,
        op.is_side_2v as isSide2v

        from order_plate op
        left join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id
        left join order_item oi on op.organ_id = oi.organ_id and op.order_id  = oi.order_id and op.id = oi.plate_id
        left join order_group og on oi.organ_id = og.organ_id and oi.order_id = og.order_id and oi.group_id = og.id
        left join order_body ob on oi.organ_id = ob.organ_id and oi.order_id = ob.order_id and oi.body_id = ob.id
        where
        op.organ_id = #{organId}

        and op.deleted = false
        and op.order_id in
        <foreach item="orderIds" collection="orderIds" open="(" separator="," close=")">
            #{orderIds}
        </foreach>

    </select>

    <select id="selectPackPlateList"
            parameterType="java.lang.Long"
            resultMap="orderItemMap">


        select distinct
            op.order_id as orderId,
            og.name as name,
            ob.room_name as roomName,
            ob.name as bodyName,
            op.plate_no as plateNo,
            op.custom_plate_no as customPlateNo,
            op.id as plateId,
            op.name as plateName,
            ogs.material as plateMaterial,
            ogs.color as palteColor,
            op.height as plateHeight,
            op.width as plateWidth,
            op.thickness as plateThickness,
            op.area as plateArea,
            op.texture as texture ,
            op.remark as remark,
            op.is_special_shaped as specialShaped,
            op.is_sculpt as profiling,
            op.is_row_hole as rowHole

        from order_plate op
                 left join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id
                 left join order_item oi on op.organ_id = oi.organ_id and op.order_id  = oi.order_id and op.id = oi.plate_id
                 left join order_group og on oi.organ_id = og.organ_id and oi.order_id = og.order_id and oi.group_id = og.id
                 left join order_body ob on oi.organ_id = ob.organ_id and oi.order_id = ob.order_id and oi.body_id = ob.id

        where
            oi.organ_id = #{organId} and oi.package_id =#{packageId} and op.deleted = false



    </select>


    <select id="selectLabelOrderPlateDataByOrderId"
            resultType="com.cf.imes.module.executor.controller.admin.order.vo.order.LabelOrderPlateData">


        select distinct

            oi.body_id as bodyGroupNo,
            oi.room_id as roomGroupNo,
            ob.name as bodyName,
            ob.room_name as roomName,
            oi.package_id as packageNo,
            ogs.color as plateColor,
            ogs.material as plateMaterial,
            op.id as plateId,
            op.plan_id as planId,
            op.order_id as orderId,
            ogs.goods_name as goodsPlateName,
            ogs.raw_goods_id as rawGoodsId,
            op.name as plateName,
            op.plate_no as plateNo,
            op.custom_plate_no as customPlateNo,

            op.width as plateWidth,
            op.height as plateLength,
            op.thickness as plateThickness,
            ogs.width as goodsPlateWidth,
            ogs.height as goodsPlateLength,
            ogs.thickness as goodsPlateThickness,

            op.split_width as splitWidth,
            op.split_height as splitHeight,
            op.split_thickness as splitThickness,
            op.seal_left as sealLeft,
            op.seal_right as sealRight,
            op.seal_up as sealUp,
            op.seal_down as sealDown,
            op.remark as plateRemark

        from order_plate  op
        left join order_goods ogs on op.organ_id = ogs.organ_id and op.order_id = ogs.order_id and op.goods_id = ogs.id
        left join order_item oi on op.organ_id = oi.organ_id and op.order_id  = oi.order_id and op.id = oi.plate_id
        left join order_body ob on op.organ_id = ob.organ_id and oi.order_id = ob.order_id and oi.body_id = ob.id

        where op.organ_id = #{organId}
        and op.deleted = false
        and op.order_id = #{orderId}

    </select>


    <resultMap id="orderItemMap" type="com.cf.imes.module.executor.controller.admin.manage.query.vo.pack.PackageDetailsRespVO">
        <result property="orderId" column="orderId"/>
        <result property="roomName" column="roomName"/>
        <result property="cabinetName" column="bodyName"/>
        <result property="plateId" column="plateId"/>
        <result property="plateNo" column="plateNo"/>
        <result property="customPlateNo" column="customPlateNo"/>
        <result property="plateName" column="plateName"/>
        <result property="material" column="plateMaterial"/>
        <result property="color" column="palteColor"/>
        <result property="width" column="plateWidth"/>
        <result property="height" column="plateHeight"/>
        <result property="thickness" column="plateThickness"/>
        <result property="area" column="plateArea"/>
        <result property="texture" column="texture"/>
        <result property="specialShaped" column="specialShaped"/>
        <result property="profiling" column="profiling"/>
        <result property="rowHole" column="rowHole"/>
        <result property="remark" column="remark"/>

        <collection property="processGroupNameList" javaType="java.util.List"  ofType="com.cf.imes.module.executor.controller.admin.manage.pack.vo.GroupNameList">
            <result property="name" column="name"/>
        </collection>
    </resultMap>
</mapper>