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.ProductCollection;
import com.izouma.awesomeadmin.service.ProductCollectionService;
import com.izouma.awesomeadmin.dao.ProductCollectionMapper;

/**
*  service接口实现类
*/
@Service
public class ProductCollectionServiceImpl implements ProductCollectionService{

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

    @Autowired
    private ProductCollectionMapper productCollectionMapper;

    @Override
    public List<ProductCollection> getProductCollectionList(ProductCollection record) {

        logger.info("getProductCollectionList");
        try {

        return productCollectionMapper.queryAllProductCollection(record);
        } catch (Exception e) {
        logger.error("getProductCollectionList", e);
        }

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

        logger.info("getProductCollectionByPage");
        try {

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

        return productCollectionMapper.queryProductCollectionByPage(parameter);
        } catch (Exception e) {
        logger.error("getProductCollectionByPage", e);
        }

        return null;
    }

    @Override
    public ProductCollection getProductCollectionById(String id) {

        logger.info("getProductCollectionyId");
        try {

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

        return null;
    }

    @Override
    public ProductCollection getProductCollection(ProductCollection record) {

        logger.info("getProductCollection");
        try {

            return productCollectionMapper.queryProductCollection(record);
        } catch (Exception e) {
        logger.error("getProductCollection", e);
        }

        return null;
    }

    @Override
    public boolean createProductCollection(ProductCollection record) {

        logger.info("createProductCollection");
        try {

            int updates = productCollectionMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteProductCollection(String id) {

        logger.info("deleteProductCollection");
        try {

             int updates = productCollectionMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateProductCollection(ProductCollection record) {

        logger.info("updateProductCollection");
        try {

            int updates = productCollectionMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

