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


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.module.product.controller.admin.voyagestockdistributeNew.vo.VoyageStockDistributeNewDetailReqVO;
import com.yc.ship.module.product.controller.admin.voyagestockdistributeNew.vo.VoyageStockDistributeNewPageReqVO;
import com.yc.ship.module.product.controller.admin.voyagestockdistributeNew.vo.VoyageStockDistributeNewPageRespVO;
import com.yc.ship.module.product.dal.dataobject.voyagestockdistribute.VoyageStockDistributeNewDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;

/**
 * 航次库存分配 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface VoyageStockDistributeNewMapper extends BaseMapperX<VoyageStockDistributeNewDO> {


    default List<VoyageStockDistributeNewDO> selectListByVoyageId(Long voyageId,Integer type) {
        return selectList(new LambdaQueryWrapperX<VoyageStockDistributeNewDO>()
                .eq(VoyageStockDistributeNewDO::getVoyageId, voyageId)
                .eq(VoyageStockDistributeNewDO::getType, type));
    }

    IPage<VoyageStockDistributeNewPageRespVO> selectPage(IPage<VoyageStockDistributeNewPageRespVO> page, @Param("params") VoyageStockDistributeNewPageReqVO reqVO);

    default List<VoyageStockDistributeNewDO> selectListByVoyageIdAndObjectId(VoyageStockDistributeNewDetailReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<VoyageStockDistributeNewDO>()
                .eq(VoyageStockDistributeNewDO::getVoyageId, reqVO.getVoyageId())
                .eqIfPresent(VoyageStockDistributeNewDO::getObjectId, reqVO.getObjectId())
                .eqIfPresent(VoyageStockDistributeNewDO::getDistributorId, reqVO.getDistributorId())
                .eq(VoyageStockDistributeNewDO::getType, reqVO.getType()));
    }

    /**
     * 获取航次已分配给分销商的库存总数
     * @param voyageId
     * @return
     */
    BigDecimal selectTotalDistributeNum(Long voyageId);

    default void deleteByVoyageId(Long id) {
        delete(new LambdaQueryWrapperX<VoyageStockDistributeNewDO>()
                .eq(VoyageStockDistributeNewDO::getVoyageId, id));
    }

    List<VoyageStockDistributeNewPageRespVO> selectGroupList(@Param("voyageIds") List<Long> voyageIds, @Param("params") VoyageStockDistributeNewPageReqVO reqVO);
}