package cn.slienceme.gulimall.coupon.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.slienceme.common.utils.PageUtils;
import cn.slienceme.common.utils.Query;

import cn.slienceme.gulimall.coupon.dao.SeckillSkuRelationDao;
import cn.slienceme.gulimall.coupon.entity.SeckillSkuRelationEntity;
import cn.slienceme.gulimall.coupon.service.SeckillSkuRelationService;
import org.springframework.util.StringUtils;


@Service("seckillSkuRelationService")
public class SeckillSkuRelationServiceImpl extends ServiceImpl<SeckillSkuRelationDao, SeckillSkuRelationEntity> implements SeckillSkuRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<SeckillSkuRelationEntity> seckillRelationEntityQueryWrapper = new QueryWrapper<>();
        String promotionSessionId = params.get("promotionSessionId").toString();
        if (!StringUtils.isEmpty(promotionSessionId)) {
            seckillRelationEntityQueryWrapper.eq("promotion_session_id", promotionSessionId);
        }
        IPage<SeckillSkuRelationEntity> page = this.page(
                new Query<SeckillSkuRelationEntity>().getPage(params),
                seckillRelationEntityQueryWrapper
        );

        return new PageUtils(page);
    }

}
