package co.yixiang.yshop.module.cart.dal.mysql.storecart;

import java.util.*;

import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.module.cart.dal.dataobject.storecart.StoreCartDO;
import org.apache.ibatis.annotations.Mapper;
import co.yixiang.yshop.module.cart.controller.admin.storecart.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 购物车 Mapper
 *
 * @author yshop
 */
@Mapper
public interface StoreCartMapper extends BaseMapperX<StoreCartDO> {

    default PageResult<StoreCartDO> selectPage(StoreCartPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<StoreCartDO>()
                .eqIfPresent(StoreCartDO::getUid, reqVO.getUid())
                .eqIfPresent(StoreCartDO::getType, reqVO.getType())
                .eqIfPresent(StoreCartDO::getProductId, reqVO.getProductId())
                .eqIfPresent(StoreCartDO::getProductAttrUnique, reqVO.getProductAttrUnique())
                .eqIfPresent(StoreCartDO::getCartNum, reqVO.getCartNum())
                .eqIfPresent(StoreCartDO::getIsPay, reqVO.getIsPay())
                .eqIfPresent(StoreCartDO::getIsNew, reqVO.getIsNew())
                .eqIfPresent(StoreCartDO::getCombinationId, reqVO.getCombinationId())
                .eqIfPresent(StoreCartDO::getSeckillId, reqVO.getSeckillId())
                .eqIfPresent(StoreCartDO::getBargainId, reqVO.getBargainId())
                .betweenIfPresent(StoreCartDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StoreCartDO::getId));
    }



    @Select("select IFNULL(sum(cart_num),0) from yshop_store_cart " +
            "where is_pay=0 and deleted=0 and is_new=0 and uid=#{uid}")
    int cartSum(@Param("uid") Long uid);

}
