package com.gree.mall.miniapp.logic.material.parts;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.miniapp.bean.material.parts.WebsitExtends;
import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
import com.gree.mall.miniapp.commonmapper.MaterialMapper;
import com.gree.mall.miniapp.logic.common.CommonLogic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class BuyLogic {

    @Resource
    MaterialMapper materialMapper;
    @Resource
    CommonLogic commonLogic;

    public WebsitExtends defaultWebsit(String websitId, String longitude, String latitude) {
        final CurrentCompanyWechat wechat = commonLogic.getCurrentCompanyWechat();
        IPage<WebsitExtends> shopExtendsIPage = materialMapper.queryWebsitList(new Page(1, 1,false), wechat.getCompanyWechatId(), websitId, longitude, latitude);
        if(shopExtendsIPage.getRecords().size() > 0){
            return shopExtendsIPage.getRecords().get(0);
        }
        return null;
    }

    public IPage<WebsitExtends> queryWebsitList(String websitId, String longitude, String latitude, Integer pageNo, Integer pageSize) {
        final CurrentCompanyWechat wechat = commonLogic.getCurrentCompanyWechat();
        return materialMapper.queryWebsitList(new Page(pageNo, pageSize), wechat.getCompanyWechatId(), websitId, longitude, latitude);
    }
}
