package com.izouma.awesomeadmin.service.impl;

import java.util.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.izouma.awesomeadmin.constant.AppConstant;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.model.StoreCollection;
import com.izouma.awesomeadmin.service.StoreCollectionService;
import com.izouma.awesomeadmin.dao.StoreCollectionMapper;

/**
*  service接口实现类
*/
@Service
public class StoreCollectionServiceImpl implements StoreCollectionService{

    private static Logger logger = Logger.getLogger(StoreCollectionServiceImpl.class);

    @Autowired
    private StoreCollectionMapper storeCollectionMapper;

    @Override
    public List<StoreCollection> getStoreCollectionList(StoreCollection record) {

        logger.info("getStoreCollectionList");
        try {

        return storeCollectionMapper.queryAllStoreCollection(record);
        } catch (Exception e) {
        logger.error("getStoreCollectionList", e);
        }

        return null;
    }
    @Override
    public List<StoreCollection> getStoreCollectionByPage(Page page, StoreCollection record) {

        logger.info("getStoreCollectionByPage");
        try {

        Map<String, Object> parameter = new HashMap<String, Object>();
        parameter.put("record", record);
        parameter.put(AppConstant.PAGE, page);

        return storeCollectionMapper.queryStoreCollectionByPage(parameter);
        } catch (Exception e) {
        logger.error("getStoreCollectionByPage", e);
        }

        return null;
    }

    @Override
    public StoreCollection getStoreCollectionById(String id) {

        logger.info("getStoreCollectionyId");
        try {

            return storeCollectionMapper.selectByPrimaryKey(Integer.valueOf(id));
        } catch (Exception e) {
        logger.error("getStoreCollectionById", e);
        }

        return null;
    }

    @Override
    public StoreCollection getStoreCollection(StoreCollection record) {

        logger.info("getStoreCollection");
        try {

            return storeCollectionMapper.queryStoreCollection(record);
        } catch (Exception e) {
        logger.error("getStoreCollection", e);
        }

        return null;
    }

    @Override
    public boolean createStoreCollection(StoreCollection record) {

        logger.info("createStoreCollection");
        try {

            int updates = storeCollectionMapper.insertSelective(record);

            if (updates > 0) {
                 return true;
            }
        } catch (Exception e) {
            logger.error("createStoreCollection", e);
        }

        return false;
    }

    @Override
    public boolean deleteStoreCollection(String id) {

        logger.info("deleteStoreCollection");
        try {

             int updates = storeCollectionMapper.delete(id);

            if (updates > 0) {
                 return true;
            }
        } catch (Exception e) {
             logger.error("deleteStoreCollection", e);
        }

        return false;
    }

    @Override
    public boolean updateStoreCollection(StoreCollection record) {

        logger.info("updateStoreCollection");
        try {

            int updates = storeCollectionMapper.updateByPrimaryKeySelective(record);

            if (updates > 0) {
                 return true;
            }
        } catch (Exception e) {
             logger.error("updateStoreCollection", e);
        }

        return false;
    }
}

