package com.yc.ship.module.trade.dal.mysql.orderpolicy;

import java.util.*;

import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.module.trade.controller.admin.order.vo.order.OrderTotalPolicyVO;
import com.yc.ship.module.trade.dal.dataobject.orderpolicy.OrderPolicyDO;
import org.apache.ibatis.annotations.Mapper;
import com.yc.ship.module.trade.controller.admin.orderpolicy.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 订单使用的优惠政策 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface OrderPolicyMapper extends BaseMapperX<OrderPolicyDO> {

    default PageResult<OrderPolicyDO> selectPage(OrderPolicyPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<OrderPolicyDO>()
                .eqIfPresent(OrderPolicyDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(OrderPolicyDO::getOrderNo, reqVO.getOrderNo())
                .eqIfPresent(OrderPolicyDO::getPolicyId, reqVO.getPolicyId())
                .eqIfPresent(OrderPolicyDO::getPreUseNum, reqVO.getPreUseNum())
                .eqIfPresent(OrderPolicyDO::getRealUseNum, reqVO.getRealUseNum())
                .eqIfPresent(OrderPolicyDO::getAmount, reqVO.getAmount())
                .betweenIfPresent(OrderPolicyDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(OrderPolicyDO::getId));
    }

    default void deleteByOrderId(Long orderId) {
        delete(new LambdaQueryWrapperX<OrderPolicyDO>().eq(OrderPolicyDO::getOrderId, orderId));
    }

    default List<OrderPolicyDO> selectByOrderId(Long orderId) {
        return selectList(new LambdaQueryWrapperX<OrderPolicyDO>().eq(OrderPolicyDO::getOrderId, orderId));
    }

    /**
     * 统计订单使用优惠策略的统计数据
     *
     * @param orderIds 订单编号数组
     * @return 统计数据
     */
    List<OrderTotalPolicyVO> selectOrderPolicyStatsByOrderIds(@Param("orderIds") List<Long> orderIds);
}