package com.gree.mall.manager.logic.websit;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.manager.bean.admin.AdminWebsitBean;
import com.gree.mall.manager.plus.entity.*;
import com.gree.mall.manager.plus.service.AdminWebsitService;
import com.gree.mall.manager.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class WebsitLogic {
    @Autowired
    private AdminWebsitService adminWebsitService;
//    @Autowired
//    private EnterpriseWechatWorkerService enterpriseWechatWorkerService;

    public IPage<AdminWebsit> list(HttpServletRequest request, Integer pageNo, Integer pageSize) {
        List<String> websitNoList = new ArrayList<>();
        AdminWebsitBean adminWebsitBean = CommonUtils.getAdminUser(request);
        if (adminWebsitBean.getType() == 0) {
            websitNoList = adminWebsitBean.getWeidsitIds().stream().map(WebsitZone::getWebsitNumber).collect(Collectors.toList());
        }
        return adminWebsitService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(websitNoList), AdminWebsit::getWebsitNumber,websitNoList)
                .page(new Page<>(pageNo, pageSize));
    }

//    public IPage<EnterpriseWechatWorker> positionList(Integer pageNo, Integer pageSize) {
//        return enterpriseWechatWorkerService.lambdaQuery()
//                .isNotNull(EnterpriseWechatWorker::getPosition)
//                .ne(EnterpriseWechatWorker::getPosition,"")
//                .groupBy(EnterpriseWechatWorker::getPosition)
//                .page(new Page<>(pageNo, pageSize));
//    }
}
