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.HelpText;
import com.izouma.awesomeadmin.service.HelpTextService;
import com.izouma.awesomeadmin.dao.HelpTextMapper;

/**
*  service接口实现类
*/
@Service
public class HelpTextServiceImpl implements HelpTextService{

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

    @Autowired
    private HelpTextMapper helpTextMapper;

    @Override
    public List<HelpText> getHelpTextList(HelpText record) {

        logger.info("getHelpTextList");
        try {

        return helpTextMapper.queryAllHelpText(record);
        } catch (Exception e) {
        logger.error("getHelpTextList", e);
        }

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

        logger.info("getHelpTextByPage");
        try {

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

        return helpTextMapper.queryHelpTextByPage(parameter);
        } catch (Exception e) {
        logger.error("getHelpTextByPage", e);
        }

        return null;
    }

    @Override
    public HelpText getHelpTextById(String id) {

        logger.info("getHelpTextyId");
        try {

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

        return null;
    }

    @Override
    public HelpText getHelpText(HelpText record) {

        logger.info("getHelpText");
        try {

            return helpTextMapper.queryHelpText(record);
        } catch (Exception e) {
        logger.error("getHelpText", e);
        }

        return null;
    }

    @Override
    public boolean createHelpText(HelpText record) {

        logger.info("createHelpText");
        try {

            int updates = helpTextMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteHelpText(String id) {

        logger.info("deleteHelpText");
        try {

             int updates = helpTextMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateHelpText(HelpText record) {

        logger.info("updateHelpText");
        try {

            int updates = helpTextMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

