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.BannerInfo;
import com.izouma.awesomeadmin.service.BannerInfoService;
import com.izouma.awesomeadmin.dao.BannerInfoMapper;

/**
*  service接口实现类
*/
@Service
public class BannerInfoServiceImpl implements BannerInfoService{

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

    @Autowired
    private BannerInfoMapper bannerInfoMapper;

    @Override
    public List<BannerInfo> getBannerInfoList(BannerInfo record) {

        logger.info("getBannerInfoList");
        try {

        return bannerInfoMapper.queryAllBannerInfo(record);
        } catch (Exception e) {
        logger.error("getBannerInfoList", e);
        }

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

        logger.info("getBannerInfoByPage");
        try {

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

        return bannerInfoMapper.queryBannerInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getBannerInfoByPage", e);
        }

        return null;
    }

    @Override
    public BannerInfo getBannerInfoById(String id) {

        logger.info("getBannerInfoyId");
        try {

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

        return null;
    }

    @Override
    public BannerInfo getBannerInfo(BannerInfo record) {

        logger.info("getBannerInfo");
        try {

            return bannerInfoMapper.queryBannerInfo(record);
        } catch (Exception e) {
        logger.error("getBannerInfo", e);
        }

        return null;
    }

    @Override
    public boolean createBannerInfo(BannerInfo record) {

        logger.info("createBannerInfo");
        try {

            int updates = bannerInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteBannerInfo(String id) {

        logger.info("deleteBannerInfo");
        try {

             int updates = bannerInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateBannerInfo(BannerInfo record) {

        logger.info("updateBannerInfo");
        try {

            int updates = bannerInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

