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.ProductImage;
import com.izouma.awesomeadmin.service.ProductImageService;
import com.izouma.awesomeadmin.dao.ProductImageMapper;

/**
*  service接口实现类
*/
@Service
public class ProductImageServiceImpl implements ProductImageService{

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

    @Autowired
    private ProductImageMapper productImageMapper;

    @Override
    public List<ProductImage> getProductImageList(ProductImage record) {

        logger.info("getProductImageList");
        try {

        return productImageMapper.queryAllProductImage(record);
        } catch (Exception e) {
        logger.error("getProductImageList", e);
        }

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

        logger.info("getProductImageByPage");
        try {

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

        return productImageMapper.queryProductImageByPage(parameter);
        } catch (Exception e) {
        logger.error("getProductImageByPage", e);
        }

        return null;
    }

    @Override
    public ProductImage getProductImageById(String id) {

        logger.info("getProductImageyId");
        try {

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

        return null;
    }

    @Override
    public ProductImage getProductImage(ProductImage record) {

        logger.info("getProductImage");
        try {

            return productImageMapper.queryProductImage(record);
        } catch (Exception e) {
        logger.error("getProductImage", e);
        }

        return null;
    }

    @Override
    public boolean createProductImage(ProductImage record) {

        logger.info("createProductImage");
        try {

            int updates = productImageMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteProductImage(String id) {

        logger.info("deleteProductImage");
        try {

             int updates = productImageMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateProductImage(ProductImage record) {

        logger.info("updateProductImage");
        try {

            int updates = productImageMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

