package com.yc.ship.module.product.dal.mysql.voyagestock;


import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.framework.tenant.core.aop.TenantIgnore;
import com.yc.ship.module.product.dal.dataobject.voyagestock.VoyageStockRoomUsedDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 已被使用的房间 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface VoyageStockRoomUsedMapper extends BaseMapperX<VoyageStockRoomUsedDO> {
    /**
     * 获取完全被使用的房间
     * @param voyageId
     * @return
     */
    @TenantIgnore
    default List<VoyageStockRoomUsedDO> selectAllUsedList(Long voyageId) {
        return selectList(new LambdaQueryWrapperX<VoyageStockRoomUsedDO>()
                .eq(VoyageStockRoomUsedDO::getVoyageId, voyageId)
                .eq(VoyageStockRoomUsedDO::getNum, 1));
    }

    /**
     * 获取使用了一半的房间
     * @param voyageId
     * @return
     */
    @TenantIgnore
    default List<VoyageStockRoomUsedDO> selectHalfUsedRoom(Long voyageId) {
        return selectList(new LambdaQueryWrapperX<VoyageStockRoomUsedDO>()
                .eq(VoyageStockRoomUsedDO::getVoyageId, voyageId)
                .eq(VoyageStockRoomUsedDO::getNum, 0.5));
    }

    /**
     * 获取已被使用的房间
     * @param voyageId
     * @return
     */
    default List<VoyageStockRoomUsedDO> selectListByVoyageId(Long voyageId) {
        return selectList(new LambdaQueryWrapperX<VoyageStockRoomUsedDO>()
                .eq(VoyageStockRoomUsedDO::getVoyageId, voyageId));
    }

    /**
     * 删除当前订单使用的房间记录
     * @param orderId
     */
    default void deleteByOrderId(Long orderId) {
        delete(new LambdaQueryWrapperX<VoyageStockRoomUsedDO>()
                .eq(VoyageStockRoomUsedDO::getOrderId, orderId));
    }
}