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.ProductPrice;
import com.izouma.awesomeadmin.service.ProductPriceService;
import com.izouma.awesomeadmin.dao.ProductPriceMapper;

/**
*  service接口实现类
*/
@Service
public class ProductPriceServiceImpl implements ProductPriceService{

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

    @Autowired
    private ProductPriceMapper productPriceMapper;

    @Override
    public List<ProductPrice> getProductPriceList(ProductPrice record) {

        logger.info("getProductPriceList");
        try {

        return productPriceMapper.queryAllProductPrice(record);
        } catch (Exception e) {
        logger.error("getProductPriceList", e);
        }

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

        logger.info("getProductPriceByPage");
        try {

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

        return productPriceMapper.queryProductPriceByPage(parameter);
        } catch (Exception e) {
        logger.error("getProductPriceByPage", e);
        }

        return null;
    }

    @Override
    public ProductPrice getProductPriceById(String id) {

        logger.info("getProductPriceyId");
        try {

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

        return null;
    }

    @Override
    public ProductPrice getProductPrice(ProductPrice record) {

        logger.info("getProductPrice");
        try {

            return productPriceMapper.queryProductPrice(record);
        } catch (Exception e) {
        logger.error("getProductPrice", e);
        }

        return null;
    }

    @Override
    public boolean createProductPrice(ProductPrice record) {

        logger.info("createProductPrice");
        try {

            int updates = productPriceMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteProductPrice(String id) {

        logger.info("deleteProductPrice");
        try {

             int updates = productPriceMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateProductPrice(ProductPrice record) {

        logger.info("updateProductPrice");
        try {

            int updates = productPriceMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

