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.OrderMessage;
import com.izouma.awesomeadmin.service.OrderMessageService;
import com.izouma.awesomeadmin.dao.OrderMessageMapper;

/**
*  service接口实现类
*/
@Service
public class OrderMessageServiceImpl implements OrderMessageService{

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

    @Autowired
    private OrderMessageMapper orderMessageMapper;

    @Override
    public List<OrderMessage> getOrderMessageList(OrderMessage record) {

        logger.info("getOrderMessageList");
        try {

        return orderMessageMapper.queryAllOrderMessage(record);
        } catch (Exception e) {
        logger.error("getOrderMessageList", e);
        }

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

        logger.info("getOrderMessageByPage");
        try {

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

        return orderMessageMapper.queryOrderMessageByPage(parameter);
        } catch (Exception e) {
        logger.error("getOrderMessageByPage", e);
        }

        return null;
    }

    @Override
    public OrderMessage getOrderMessageById(String id) {

        logger.info("getOrderMessageyId");
        try {

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

        return null;
    }

    @Override
    public OrderMessage getOrderMessage(OrderMessage record) {

        logger.info("getOrderMessage");
        try {

            return orderMessageMapper.queryOrderMessage(record);
        } catch (Exception e) {
        logger.error("getOrderMessage", e);
        }

        return null;
    }

    @Override
    public boolean createOrderMessage(OrderMessage record) {

        logger.info("createOrderMessage");
        try {

            int updates = orderMessageMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteOrderMessage(String id) {

        logger.info("deleteOrderMessage");
        try {

             int updates = orderMessageMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateOrderMessage(OrderMessage record) {

        logger.info("updateOrderMessage");
        try {

            int updates = orderMessageMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

