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.ContactRecord;
import com.izouma.awesomeadmin.service.ContactRecordService;
import com.izouma.awesomeadmin.dao.ContactRecordMapper;

/**
*  service接口实现类
*/
@Service
public class ContactRecordServiceImpl implements ContactRecordService{

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

    @Autowired
    private ContactRecordMapper contactRecordMapper;

    @Override
    public List<ContactRecord> getContactRecordList(ContactRecord record) {

        logger.info("getContactRecordList");
        try {

        return contactRecordMapper.queryAllContactRecord(record);
        } catch (Exception e) {
        logger.error("getContactRecordList", e);
        }

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

        logger.info("getContactRecordByPage");
        try {

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

        return contactRecordMapper.queryContactRecordByPage(parameter);
        } catch (Exception e) {
        logger.error("getContactRecordByPage", e);
        }

        return null;
    }

    @Override
    public ContactRecord getContactRecordById(String id) {

        logger.info("getContactRecordyId");
        try {

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

        return null;
    }

    @Override
    public ContactRecord getContactRecord(ContactRecord record) {

        logger.info("getContactRecord");
        try {

            return contactRecordMapper.queryContactRecord(record);
        } catch (Exception e) {
        logger.error("getContactRecord", e);
        }

        return null;
    }

    @Override
    public boolean createContactRecord(ContactRecord record) {

        logger.info("createContactRecord");
        try {

            int updates = contactRecordMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteContactRecord(String id) {

        logger.info("deleteContactRecord");
        try {

             int updates = contactRecordMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateContactRecord(ContactRecord record) {

        logger.info("updateContactRecord");
        try {

            int updates = contactRecordMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

