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.AboutUs;
import com.izouma.awesomeadmin.service.AboutUsService;
import com.izouma.awesomeadmin.dao.AboutUsMapper;

/**
*  service接口实现类
*/
@Service
public class AboutUsServiceImpl implements AboutUsService{

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

    @Autowired
    private AboutUsMapper aboutUsMapper;

    @Override
    public List<AboutUs> getAboutUsList(AboutUs record) {

        logger.info("getAboutUsList");
        try {

        return aboutUsMapper.queryAllAboutUs(record);
        } catch (Exception e) {
        logger.error("getAboutUsList", e);
        }

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

        logger.info("getAboutUsByPage");
        try {

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

        return aboutUsMapper.queryAboutUsByPage(parameter);
        } catch (Exception e) {
        logger.error("getAboutUsByPage", e);
        }

        return null;
    }

    @Override
    public AboutUs getAboutUsById(String id) {

        logger.info("getAboutUsyId");
        try {

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

        return null;
    }

    @Override
    public AboutUs getAboutUs(AboutUs record) {

        logger.info("getAboutUs");
        try {

            return aboutUsMapper.queryAboutUs(record);
        } catch (Exception e) {
        logger.error("getAboutUs", e);
        }

        return null;
    }

    @Override
    public boolean createAboutUs(AboutUs record) {

        logger.info("createAboutUs");
        try {

            int updates = aboutUsMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteAboutUs(String id) {

        logger.info("deleteAboutUs");
        try {

             int updates = aboutUsMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateAboutUs(AboutUs record) {

        logger.info("updateAboutUs");
        try {

            int updates = aboutUsMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

