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.HotSearch;
import com.izouma.awesomeadmin.service.HotSearchService;
import com.izouma.awesomeadmin.dao.HotSearchMapper;

/**
*  service接口实现类
*/
@Service
public class HotSearchServiceImpl implements HotSearchService{

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

    @Autowired
    private HotSearchMapper hotSearchMapper;

    @Override
    public List<HotSearch> getHotSearchList(HotSearch record) {

        logger.info("getHotSearchList");
        try {

        return hotSearchMapper.queryAllHotSearch(record);
        } catch (Exception e) {
        logger.error("getHotSearchList", e);
        }

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

        logger.info("getHotSearchByPage");
        try {

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

        return hotSearchMapper.queryHotSearchByPage(parameter);
        } catch (Exception e) {
        logger.error("getHotSearchByPage", e);
        }

        return null;
    }

    @Override
    public HotSearch getHotSearchById(String id) {

        logger.info("getHotSearchyId");
        try {

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

        return null;
    }

    @Override
    public HotSearch getHotSearch(HotSearch record) {

        logger.info("getHotSearch");
        try {

            return hotSearchMapper.queryHotSearch(record);
        } catch (Exception e) {
        logger.error("getHotSearch", e);
        }

        return null;
    }

    @Override
    public boolean createHotSearch(HotSearch record) {

        logger.info("createHotSearch");
        try {

            int updates = hotSearchMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteHotSearch(String id) {

        logger.info("deleteHotSearch");
        try {

             int updates = hotSearchMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateHotSearch(HotSearch record) {

        logger.info("updateHotSearch");
        try {

            int updates = hotSearchMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

