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.ProductInfo;
import com.izouma.awesomeadmin.service.ProductInfoService;
import com.izouma.awesomeadmin.dao.ProductInfoMapper;

/**
*  service接口实现类
*/
@Service
public class ProductInfoServiceImpl implements ProductInfoService{

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

    @Autowired
    private ProductInfoMapper productInfoMapper;

    @Override
    public List<ProductInfo> getProductInfoList(ProductInfo record) {

        logger.info("getProductInfoList");
        try {

        return productInfoMapper.queryAllProductInfo(record);
        } catch (Exception e) {
        logger.error("getProductInfoList", e);
        }

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

        logger.info("getProductInfoByPage");
        try {

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

        return productInfoMapper.queryProductInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getProductInfoByPage", e);
        }

        return null;
    }

    @Override
    public ProductInfo getProductInfoById(String id) {

        logger.info("getProductInfoyId");
        try {

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

        return null;
    }

    @Override
    public ProductInfo getProductInfo(ProductInfo record) {

        logger.info("getProductInfo");
        try {

            return productInfoMapper.queryProductInfo(record);
        } catch (Exception e) {
        logger.error("getProductInfo", e);
        }

        return null;
    }

    @Override
    public boolean createProductInfo(ProductInfo record) {

        logger.info("createProductInfo");
        try {

            int updates = productInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteProductInfo(String id) {

        logger.info("deleteProductInfo");
        try {

             int updates = productInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateProductInfo(ProductInfo record) {

        logger.info("updateProductInfo");
        try {

            int updates = productInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }

}

