package shop.alien.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import shop.alien.entity.store.LifeReverseGroupBuying;
import shop.alien.entity.store.vo.LifeReverseGroupBuyingStoreVo;
import shop.alien.entity.store.vo.LifeReverseGroupBuyingUserVo;

/**
 * 用户反向团购表 Mapper 接口
 *
 * @author ssk
 * @since 2025-03-05
 */
public interface LifeReverseGroupBuyingMapper extends BaseMapper<LifeReverseGroupBuying> {

    /**
     * 用户-分页查询
     *
     * @param page         分页参数
     * @param queryWrapper 查询条件
     * @return IPage<LifeReverseGroupBuyingUserVo>
     */
    @Select("SELECT a.*, b.order_no FROM life_reverse_group_buying a left join life_user_order b on a.order_id = b.id ${ew.customSqlSegment}")
    IPage<LifeReverseGroupBuyingUserVo> getUserPage(IPage<LifeReverseGroupBuyingUserVo> page, @Param(Constants.WRAPPER) QueryWrapper<LifeReverseGroupBuyingUserVo> queryWrapper);


    /**
     * 商家-分页查询
     *
     * @param page         分页参数
     * @param queryWrapper 查询条件
     * @return IPage<LifeReverseGroupBuyingStoreVo>
     */
    @Select("SELECT a.*, COUNT(b.id) joinStoreCount, c.user_name, c.user_image userImgUrl " +
            "FROM life_reverse_group_buying a " +
            "LEFT JOIN life_reverse_group_bidding b ON a.id = b.reverse_group_id " +
            "left join life_user c on a.user_id = c.id ${ew.customSqlSegment}")
    IPage<LifeReverseGroupBuyingStoreVo> getStorePage(IPage<LifeReverseGroupBuyingStoreVo> page, @Param(Constants.WRAPPER) QueryWrapper<LifeReverseGroupBuyingStoreVo> queryWrapper);
}
