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.ArContent;
import com.izouma.awesomeadmin.service.ArContentService;
import com.izouma.awesomeadmin.dao.ArContentMapper;

/**
*  service接口实现类
*/
@Service
public class ArContentServiceImpl implements ArContentService{

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

    @Autowired
    private ArContentMapper arContentMapper;

    @Override
    public List<ArContent> getArContentList(ArContent record) {

        logger.info("getArContentList");
        try {

        return arContentMapper.queryAllArContent(record);
        } catch (Exception e) {
        logger.error("getArContentList", e);
        }

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

        logger.info("getArContentByPage");
        try {

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

        return arContentMapper.queryArContentByPage(parameter);
        } catch (Exception e) {
        logger.error("getArContentByPage", e);
        }

        return null;
    }

    @Override
    public ArContent getArContentById(String id) {

        logger.info("getArContentyId");
        try {

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

        return null;
    }

    @Override
    public ArContent getArContent(ArContent record) {

        logger.info("getArContent");
        try {

            return arContentMapper.queryArContent(record);
        } catch (Exception e) {
        logger.error("getArContent", e);
        }

        return null;
    }

    @Override
    public boolean createArContent(ArContent record) {

        logger.info("createArContent");
        try {

            int updates = arContentMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteArContent(ArContent record) {

        logger.info("deleteArContent");
        try {

             int updates = arContentMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateArContent(ArContent record) {

        logger.info("updateArContent");
        try {

            int updates = arContentMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

