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.OrderInvoice;
import com.izouma.awesomeadmin.service.OrderInvoiceService;
import com.izouma.awesomeadmin.dao.OrderInvoiceMapper;

/**
*  service接口实现类
*/
@Service
public class OrderInvoiceServiceImpl implements OrderInvoiceService{

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

    @Autowired
    private OrderInvoiceMapper orderInvoiceMapper;

    @Override
    public List<OrderInvoice> getOrderInvoiceList(OrderInvoice record) {

        logger.info("getOrderInvoiceList");
        try {

        return orderInvoiceMapper.queryAllOrderInvoice(record);
        } catch (Exception e) {
        logger.error("getOrderInvoiceList", e);
        }

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

        logger.info("getOrderInvoiceByPage");
        try {

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

        return orderInvoiceMapper.queryOrderInvoiceByPage(parameter);
        } catch (Exception e) {
        logger.error("getOrderInvoiceByPage", e);
        }

        return null;
    }

    @Override
    public OrderInvoice getOrderInvoiceById(String id) {

        logger.info("getOrderInvoiceyId");
        try {

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

        return null;
    }

    @Override
    public OrderInvoice getOrderInvoice(OrderInvoice record) {

        logger.info("getOrderInvoice");
        try {

            return orderInvoiceMapper.queryOrderInvoice(record);
        } catch (Exception e) {
        logger.error("getOrderInvoice", e);
        }

        return null;
    }

    @Override
    public boolean createOrderInvoice(OrderInvoice record) {

        logger.info("createOrderInvoice");
        try {

            int updates = orderInvoiceMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteOrderInvoice(String id) {

        logger.info("deleteOrderInvoice");
        try {

             int updates = orderInvoiceMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateOrderInvoice(OrderInvoice record) {

        logger.info("updateOrderInvoice");
        try {

            int updates = orderInvoiceMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

