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.UserComment;
import com.izouma.awesomeadmin.service.UserCommentService;
import com.izouma.awesomeadmin.dao.UserCommentMapper;

/**
*  service接口实现类
*/
@Service
public class UserCommentServiceImpl implements UserCommentService{

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

    @Autowired
    private UserCommentMapper userCommentMapper;

    @Override
    public List<UserComment> getUserCommentList(UserComment record) {

        logger.info("getUserCommentList");
        try {

        return userCommentMapper.queryAllUserComment(record);
        } catch (Exception e) {
        logger.error("getUserCommentList", e);
        }

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

        logger.info("getUserCommentByPage");
        try {

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

        return userCommentMapper.queryUserCommentByPage(parameter);
        } catch (Exception e) {
        logger.error("getUserCommentByPage", e);
        }

        return null;
    }

    @Override
    public UserComment getUserCommentById(String id) {

        logger.info("getUserCommentyId");
        try {

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

        return null;
    }

    @Override
    public UserComment getUserComment(UserComment record) {

        logger.info("getUserComment");
        try {

            return userCommentMapper.queryUserComment(record);
        } catch (Exception e) {
        logger.error("getUserComment", e);
        }

        return null;
    }

    @Override
    public boolean createUserComment(UserComment record) {

        logger.info("createUserComment");
        try {

            int updates = userCommentMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteUserComment(UserComment record) {

        logger.info("deleteUserComment");
        try {

             int updates = userCommentMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateUserComment(UserComment record) {

        logger.info("updateUserComment");
        try {

            int updates = userCommentMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

