package com.slodon.b2b2c.model.seller;


import com.slodon.b2b2c.core.response.PagerInfo;
import com.slodon.b2b2c.dao.read.seller.StoreNameReadMapper;
import com.slodon.b2b2c.dao.write.seller.StoreNameWriteMapper;

import com.slodon.b2b2c.seller.example.StoreNameExample;
import com.slodon.b2b2c.seller.pojo.StoreName;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
@Slf4j
public class StoreNameModel {

    @Resource
    private StoreNameReadMapper storeNameReadMapper;
    @Resource
    private StoreNameWriteMapper storeNameWriteMapper;


    public List<StoreName> getStoreNameList(StoreNameExample example, PagerInfo pager) {
        List<StoreName> storeNameList;
        if (pager != null) {
            pager.setRowsCount(storeNameReadMapper.countByExample(example));
            storeNameList = storeNameReadMapper.listPageByExample(example, pager.getStart(), pager.getPageSize());
        } else {
            storeNameList = storeNameReadMapper.listByExample(example);
        }
        return storeNameList;
    }

    public StoreName getStoreNameByExample(StoreNameExample example) {
        List<StoreName> storeNameList = storeNameReadMapper.listByExample(example);
        return CollectionUtils.isEmpty(storeNameList) ? null : storeNameList.get(0);
    }
}