package com.zfire.mall.manager.logic.manage.v2.material;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zfire.mall.manager.bean.admin.AdminUserCom;
import com.zfire.mall.manager.bean.manage.v2.material.ProductComposeVO;
import com.zfire.mall.manager.commonmapper.manage.material.ProductComposeReserveMapper;
import com.zfire.mall.manager.logic.common.CommonLogic;
import com.zfire.mall.manager.zfire.bean.QueryParamBean;
import com.zfire.mall.manager.zfire.bean.ZfireParamBean;
import com.zfire.mall.manager.zfire.util.FieldUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class ProductComposeV2Logic {
    @Resource
    CommonLogic commonLogic;
    @Resource
    ProductComposeReserveMapper productComposeReserveMapper;

    public IPage<ProductComposeVO> v2ListPage(ZfireParamBean zfireParamBean) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        String adminCompanyId = adminUser.getAdminCompanyId();
        if (StringUtils.isNotBlank(adminCompanyId)) {
            zfireParamBean.getParams().add(new QueryParamBean().setParam("a.admin_company_id")
                    .setCompare("=")
                    .setValue(adminCompanyId));
        }

        FieldUtils.supplyParam(zfireParamBean);

        return productComposeReserveMapper.v2ListPage(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
    }
}
