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

import com.cf.imes.framework.common.enums.OrderPackageStatusEnum;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.executor.controller.admin.manage.pack.vo.PackRespVO;
import com.cf.imes.module.executor.controller.admin.manage.query.vo.pack.OrderPackageVO;
import com.cf.imes.module.executor.dal.dataobject.pack.OrderPackagDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 *
 *
 * @author Gqr
 * @since 2026/3/25 13:55
 */
@Mapper
public interface OrderPackageMapper extends BaseMapperX<OrderPackagDO> {
    /**
     * 查询订单包裹数
     *
     * @param orderIds
     * @param organId
     * @return
     */
    List<PackRespVO> selectPackPage(@Param("orderIds") List<Long> orderIds, @Param("organId") Long organId);

    /**
     * 查询当前订单已经打包的板材数量
     *
     * @param orderIds
     * @param organId
     * @return
     */
    List<PackRespVO> selectPackPieceCount(@Param("orderIds") List<Long> orderIds, @Param("organId") Long organId);

    /**
     * 查询订单包裹列表
     * @param orderId
     * @param organId
     * @return
     */
    default List<OrderPackagDO> selectPackList(Long orderId, Long organId) {
        return selectList(new LambdaQueryWrapperX<OrderPackagDO>()
                .eq(OrderPackagDO::getOrganId, organId)
                .eq(OrderPackagDO::getDeleted, false)
                .eqIfPresent(OrderPackagDO::getOrderId, orderId)
                .eqIfPresent(OrderPackagDO::getStatus, OrderPackageStatusEnum.UNPACKED.getStatus()));
    }

    /**
     * 查询订单包裹列表
     *
     * @param orderId
     * @param organId
     * @return
     */
    default List<OrderPackagDO> selectPackStatus(Long orderId, Long organId) {
        return selectList(new LambdaQueryWrapperX<OrderPackagDO>()
                .eq(OrderPackagDO::getOrganId, organId)
                .eq(OrderPackagDO::getDeleted, false)
                .eqIfPresent(OrderPackagDO::getOrderId, orderId));
    }

    /**
     * 查询订单列表下的所有包裹编号
     *
     * @param orderIds
     * @return
     */
    List<OrderPackageVO> getPackageNoInOrderIds(@Param("orderIds") List<Long> orderIds);
}
