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.ProductComment;
import com.izouma.awesomeadmin.service.ProductCommentService;
import com.izouma.awesomeadmin.dao.ProductCommentMapper;

/**
 * service接口实现类
 */
@Service
public class ProductCommentServiceImpl implements ProductCommentService {

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

    @Autowired
    private ProductCommentMapper productCommentMapper;

    @Override
    public List<ProductComment> getProductCommentList(ProductComment record) {

        logger.info("getProductCommentList");
        try {

            return productCommentMapper.queryAllProductComment(record);
        } catch (Exception e) {
            logger.error("getProductCommentList", e);
        }

        return null;
    }

    @Override
    public List<ProductComment> getProductCommentByPage(Page page, ProductComment record) {

        logger.info("getProductCommentByPage");
        try {

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

            return productCommentMapper.queryProductCommentByPage(parameter);
        } catch (Exception e) {
            logger.error("getProductCommentByPage", e);
        }

        return null;
    }

    @Override
    public ProductComment getProductCommentById(String id) {

        logger.info("getProductCommentyId");
        try {

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

        return null;
    }

    @Override
    public ProductComment getProductComment(ProductComment record) {

        logger.info("getProductComment");
        try {

            return productCommentMapper.queryProductComment(record);
        } catch (Exception e) {
            logger.error("getProductComment", e);
        }

        return null;
    }

    @Override
    public ProductComment getCount(ProductComment record) {

        logger.info("getCount");
        try {

            return productCommentMapper.getCount(record);
        } catch (Exception e) {
            logger.error("getCount", e);
        }

        return null;
    }

    @Override
    public boolean createProductComment(ProductComment record) {

        logger.info("createProductComment");
        try {

            int updates = productCommentMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteProductComment(String id) {

        logger.info("deleteProductComment");
        try {

            int updates = productCommentMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateProductComment(ProductComment record) {

        logger.info("updateProductComment");
        try {

            int updates = productCommentMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

