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.JoinUs;
import com.izouma.awesomeadmin.service.JoinUsService;
import com.izouma.awesomeadmin.dao.JoinUsMapper;

/**
*  service接口实现类
*/
@Service
public class JoinUsServiceImpl implements JoinUsService{

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

    @Autowired
    private JoinUsMapper joinUsMapper;

    @Override
    public List<JoinUs> getJoinUsList(JoinUs record) {

        logger.info("getJoinUsList");
        try {

        return joinUsMapper.queryAllJoinUs(record);
        } catch (Exception e) {
        logger.error("getJoinUsList", e);
        }

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

        logger.info("getJoinUsByPage");
        try {

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

        return joinUsMapper.queryJoinUsByPage(parameter);
        } catch (Exception e) {
        logger.error("getJoinUsByPage", e);
        }

        return null;
    }

    @Override
    public JoinUs getJoinUsById(String id) {

        logger.info("getJoinUsyId");
        try {

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

        return null;
    }

    @Override
    public JoinUs getJoinUs(JoinUs record) {

        logger.info("getJoinUs");
        try {

            return joinUsMapper.queryJoinUs(record);
        } catch (Exception e) {
        logger.error("getJoinUs", e);
        }

        return null;
    }

    @Override
    public boolean createJoinUs(JoinUs record) {

        logger.info("createJoinUs");
        try {

            int updates = joinUsMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteJoinUs(String id) {

        logger.info("deleteJoinUs");
        try {

             int updates = joinUsMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateJoinUs(JoinUs record) {

        logger.info("updateJoinUs");
        try {

            int updates = joinUsMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

