package com.gree.mall.miniapp.logic;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
import com.gree.mall.miniapp.logic.common.CommonLogic;
import com.gree.mall.miniapp.plus.entity.CarouselMap;
import com.gree.mall.miniapp.plus.service.CarouselMapService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Service
public class CarouselMapLogic {

    @Resource
    CarouselMapService carouselMapService;
    @Autowired
    CommonLogic commonLogic;

    /**
     * 轮播图列表分页
     */
    public IPage<CarouselMap> page(HttpServletRequest request,Boolean state,String port, Integer pageNum, Integer pageSize) {

        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
        if(StringUtils.isBlank(port)){
            port = "SHOP";
        }
        IPage<CarouselMap> carouselMaps = carouselMapService.lambdaQuery()
                .eq(CarouselMap::getCompanyWechatId , currentCompanyWechat.getCurrentCompanyWechatId())
                .eq(StringUtils.isNotBlank(port),CarouselMap::getPort,port)
                .eq(state != null,CarouselMap::getState,state)
                .orderByAsc(CarouselMap::getSortNum)
                .page(new Page(pageNum, pageSize));
        return carouselMaps;
    }
}
