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.NewsInfo;
import com.izouma.awesomeadmin.service.NewsInfoService;
import com.izouma.awesomeadmin.dao.NewsInfoMapper;

/**
*  service接口实现类
*/
@Service
public class NewsInfoServiceImpl implements NewsInfoService{

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

    @Autowired
    private NewsInfoMapper newsInfoMapper;

    @Override
    public List<NewsInfo> getNewsInfoList(NewsInfo record) {

        logger.info("getNewsInfoList");
        try {

        return newsInfoMapper.queryAllNewsInfo(record);
        } catch (Exception e) {
        logger.error("getNewsInfoList", e);
        }

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

        logger.info("getNewsInfoByPage");
        try {

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

        return newsInfoMapper.queryNewsInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getNewsInfoByPage", e);
        }

        return null;
    }

    @Override
    public NewsInfo getNewsInfoById(String id) {

        logger.info("getNewsInfoyId");
        try {

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

        return null;
    }

    @Override
    public NewsInfo getNewsInfo(NewsInfo record) {

        logger.info("getNewsInfo");
        try {

            return newsInfoMapper.queryNewsInfo(record);
        } catch (Exception e) {
        logger.error("getNewsInfo", e);
        }

        return null;
    }

    @Override
    public boolean createNewsInfo(NewsInfo record) {

        logger.info("createNewsInfo");
        try {

            int updates = newsInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteNewsInfo(String id) {

        logger.info("deleteNewsInfo");
        try {

             int updates = newsInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateNewsInfo(NewsInfo record) {

        logger.info("updateNewsInfo");
        try {

            int updates = newsInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

