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.Feedback;
import com.izouma.awesomeadmin.service.FeedbackService;
import com.izouma.awesomeadmin.dao.FeedbackMapper;

/**
*  service接口实现类
*/
@Service
public class FeedbackServiceImpl implements FeedbackService{

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

    @Autowired
    private FeedbackMapper feedbackMapper;

    @Override
    public List<Feedback> getFeedbackList(Feedback record) {

        logger.info("getFeedbackList");
        try {

        return feedbackMapper.queryAllFeedback(record);
        } catch (Exception e) {
        logger.error("getFeedbackList", e);
        }

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

        logger.info("getFeedbackByPage");
        try {

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

        return feedbackMapper.queryFeedbackByPage(parameter);
        } catch (Exception e) {
        logger.error("getFeedbackByPage", e);
        }

        return null;
    }

    @Override
    public Feedback getFeedbackById(String id) {

        logger.info("getFeedbackyId");
        try {

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

        return null;
    }

    @Override
    public Feedback getFeedback(Feedback record) {

        logger.info("getFeedback");
        try {

            return feedbackMapper.queryFeedback(record);
        } catch (Exception e) {
        logger.error("getFeedback", e);
        }

        return null;
    }

    @Override
    public boolean createFeedback(Feedback record) {

        logger.info("createFeedback");
        try {

            int updates = feedbackMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteFeedback(String id) {

        logger.info("deleteFeedback");
        try {

             int updates = feedbackMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateFeedback(Feedback record) {

        logger.info("updateFeedback");
        try {

            int updates = feedbackMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

