package cn.newfeifan.mall.module.distri.dal.mysql.ordersettlement;

import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.newfeifan.mall.module.distri.controller.admin.ordersettlement.vo.*;
import cn.newfeifan.mall.module.distri.dal.dataobject.ordersettlement.OrderSettlementDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 订单结算表,记录有那些订单参与了本次结算 Mapper
 *
 * @author 非繁人
 */
@Mapper
public interface OrderSettlementMapper extends BaseMapperX<OrderSettlementDO> {

    default PageResult<OrderSettlementDO> selectPage(OrderSettlementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<OrderSettlementDO>()
                .eqIfPresent(OrderSettlementDO::getTradeShopSettlementId, reqVO.getTradeShopSettlementId())
                .eqIfPresent(OrderSettlementDO::getTradeOrderId, reqVO.getTradeOrderId())
                .betweenIfPresent(OrderSettlementDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(OrderSettlementDO::getId));
    }

    default List<Long> selectOrderIdsByShopSettlementId(Long shopSettlementId){
        return selectList(OrderSettlementDO::getTradeShopSettlementId, shopSettlementId).stream().map(OrderSettlementDO::getTradeOrderId).collect(Collectors.toList());
    }
}