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

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zfire.mall.manager.bean.admin.AdminUserCom;
import com.zfire.mall.manager.bean.manage.v2.take.TakerRecordVO;
import com.zfire.mall.manager.commonmapper.manage.take.TakerRecordReserveMapper;
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.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class TakerRecordV2Logic {

    @Resource
    TakerRecordReserveMapper takerRecordReserveMapper;
    @Resource
    CommonLogic commonLogic;

    public IPage<TakerRecordVO> v2ListPage(ZfireParamBean zfireParamBean) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        if (CollectionUtils.isNotEmpty(adminUser.getAdminCompanyIds())) {
            zfireParamBean.getParams().add(new QueryParamBean().setParam("a.admin_company_id")
                    .setCompare("IN")
                    .setValue(adminUser.getAdminCompanyIds()));
        }
        if (adminUser.getIsCustomer()) {
            zfireParamBean.getParams().add(new QueryParamBean().setParam("a.customer_id")
                    .setCompare("=")
                    .setValue(adminUser.getCustomerId()));
        }
/*        zfireParamBean.getParams().add(new QueryParamBean().setParam("a.expire_time")
                .setCompare(">=")
                .setValue(DateUtil.formatDate(DateUtil.date())));*/
        FieldUtils.supplyParam(zfireParamBean);
        return takerRecordReserveMapper.v2ListPage(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
    }
}
