package com.cf.imes.module.executor.dal.mysql.planitem;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.module.executor.controller.admin.order.vo.order.LabelOrderPlateData;
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderPlanPlateNumAndAreaRespVO;
import com.cf.imes.module.executor.controller.admin.plan.vo.*;
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
import com.cf.imes.module.executor.dal.dataobject.planitem.PlanItemDO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDetailDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;

/**
 * 订单开料排单明细 Mapper
 *
 * @author 晨丰科技
 */
@Mapper
public interface PlanItemMapper extends BaseMapperX<PlanItemDO> {

    /**
     * 未排单订单查询
     *
     * @param page
     * @param wrapper
     * @param type
     * @param orderGoodsIds 商品id列表
     * @param rootIds      父级订单数组
     * @return
     */
    IPage<OrderRespVOCopy> selectOrderList(@Param("page") IPage<OrderRespVOCopy> page,
                                           @Param(Constants.WRAPPER) Wrapper<OrderDO> wrapper,
                                           @Param("type") int type,
                                           @Param("orderGoodsIds") List<Long> orderGoodsIds,
                                           @Param("rootIds") List<Long> rootIds);

    /**
     * 未排单顶级订单id列表
     *
     * @param page
     * @param wrapper
     * @return
     */
    IPage<Long> selectRootOrderIdList(@Param("page") IPage<OrderRespVOCopy> page,
                                      @Param(Constants.WRAPPER) Wrapper<OrderDO> wrapper);

    /**
     * 未排单子单查询
     *
     * @param wrapper
     * @param type
     * @param orderGoodsIds 商品id列表
     * @param orderIds      父级订单数组
     * @return
     */
    List<OrderRespVOCopy> selectOrderChildList(@Param(Constants.WRAPPER) Wrapper<OrderDO> wrapper,
                                           @Param("type") int type,
                                           @Param("orderGoodsIds") List<Long> orderGoodsIds,
                                           @Param("orderIds") Long... orderIds);

    /**
     * 查询排单小板
     *
     * @param planId
     * @param organId
     * @return
     */
    List<PlateDetailDO> selectPlanPlateDetailList(@Param("planId") Long planId, @Param("orderIds") List<Long> orderIds, @Param("organId") Long organId);

    /**
     * 查询排单大板列表
     *
     * @param planIds  排单id列表
     * @param orderIds 订单id列表
     * @param organId  组织id
     * @return 排单小板列表
     */
    List<PlateInfoVO> selectOrderPlanGoodsList(@Param("planIds") List<Long> planIds, @Param("orderIds") Collection<Long> orderIds, @Param("organId") Long organId);

    List<PlateResList> selectPlateListByPlanId(@Param("planId") Long planId, @Param("organId")  Long organId);

    /**
     * 查询订单、房间、柜体下未排单大板
     *
     * @param page
     * @param wrapper
     * @param organId
     * @return
     */
    IPage<OrderGoodsResp> selectNoPlanGoodsByRoomAndBodyIds(@Param("page") IPage<OrderGoodsResp> page, @Param(Constants.WRAPPER) Wrapper<PlanItemDO> wrapper,@Param("organId") Long organId);

    /**
     * 查询订单下未排单大板
     *
     * @param page
     * @param wrapper
     * @param organId
     * @return
     */
    IPage<OrderGoodsResp> selectNoPlanGoodsList(@Param("page") IPage<OrderGoodsResp> page, @Param(Constants.WRAPPER) Wrapper<PlanItemDO> wrapper, @Param("organId") Long organId);

    List<OrderGoodsResp> selectNoOrderGoodsIdList(@Param(Constants.WRAPPER) Wrapper<PlanItemDO> wrapper, @Param("organId") Long organId, @Param("type") int type);

    Long selectIsCuttingPlate(@Param("planId") Long planId,@Param("organId") Long organId);

    List<LabelOrderPlateData> selectLabelOrderPlateDataByPlanId(@Param("planId") Long planId, @Param("organId") Long organId);


    List<SavePlanPlateList.GoodsItemList> selectPlanGoodsList(@Param("planId") Long planId, @Param("organId") Long organId);

    /**
     * 统计排单板件数量和面积
     *
     * @param planId
     * @return
     */
    OrderPlanPlateNumAndAreaRespVO selectPlanPlateNumAndArea(@Param("planId") Long planId);

    /**
     * 批量统计排单板件数量和面积
     *
     * @param planIds 排单id列表
     * @return 每个排单的板件数量和面积
     */
    List<OrderPlanPlateNumAndAreaRespVO> selectPlanPlateNumAndAreaGroup(@Param("planIds") List<Long> planIds);
}