<?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.orderGroup.OrderGroupMapper">

    <update id="updatePlateNumById" >
        update `order_group` set plate_num = #{plateNum} where id = #{orderId}
    </update>

    <select id="getOrderGroupByOrderId" resultType="com.cf.imes.module.executor.dal.dataobject.orderGroup.OrderGroupDO">
        select gp.id, gp.order_id, gp.name, gp.body_id
        from `order_group` as gp
        where gp.order_id = #{orderId} and gp.organ_id = #{organId} and gp.deleted = 0
    </select>


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


        select ${filed}  from order_group
                                 where
                                     organ_id = #{organId}
                                    and deleted = false
                                    and id  in
        <foreach item="groupIds" collection="groupIds" open="(" separator="," close=")">
            #{groupIds}
        </foreach>
                        ${field2}

    </select>


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


        select distinct og.order_id

        from order_group og

                 left join order_item oi on og.organ_id = oi.organ_id  and og.order_id = oi.order_id and og.id = oi.group_id

                 left join order_plate op on oi.organ_id = op.organ_id and oi.order_id = op.order_id and oi.plate_id = op.id

                 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 and op.deleted = ogs.deleted

            ${ew.customSqlSegment}


    </select>

    <select id="selectFilterOrderPlateList" resultType="java.lang.Long">

        select distinct og.order_id

        from order_group og

                 left join order_item oi on og.organ_id = oi.organ_id  and og.order_id = oi.order_id and og.id = oi.group_id

                 left join order_plate op on oi.organ_id = op.organ_id and oi.order_id = op.order_id and oi.plate_id = op.id

                 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 and op.deleted = ogs.deleted

            ${ew.customSqlSegment}

    </select>


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

        select distinct ogs.goods_id

        from order_group og

                 left join order_item oi on og.organ_id = oi.organ_id  and og.order_id = oi.order_id and og.id = oi.group_id

                 left join order_plate op on oi.organ_id = op.organ_id and oi.order_id = op.order_id and oi.plate_id = op.id

                 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 and op.deleted = ogs.deleted

            ${ew.customSqlSegment}


    </select>


    <select id="selectFilterGoodsPlateList" resultType="com.cf.imes.module.executor.controller.admin.plan.bo.OrderIds">

        select distinct ogs.goods_id,
                        ogs.order_id

        from order_group og

                 left join order_item oi on og.organ_id = oi.organ_id  and og.order_id = oi.order_id and og.id = oi.group_id

                 left join order_plate op on oi.organ_id = op.organ_id and oi.order_id = op.order_id and oi.plate_id = op.id

                 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 and op.deleted = ogs.deleted

            ${ew.customSqlSegment}

    </select>

</mapper>