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.OrderAddress;
import com.izouma.awesomeadmin.service.OrderAddressService;
import com.izouma.awesomeadmin.dao.OrderAddressMapper;

/**
*  service接口实现类
*/
@Service
public class OrderAddressServiceImpl implements OrderAddressService{

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

    @Autowired
    private OrderAddressMapper orderAddressMapper;

    @Override
    public List<OrderAddress> getOrderAddressList(OrderAddress record) {

        logger.info("getOrderAddressList");
        try {

        return orderAddressMapper.queryAllOrderAddress(record);
        } catch (Exception e) {
        logger.error("getOrderAddressList", e);
        }

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

        logger.info("getOrderAddressByPage");
        try {

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

        return orderAddressMapper.queryOrderAddressByPage(parameter);
        } catch (Exception e) {
        logger.error("getOrderAddressByPage", e);
        }

        return null;
    }

    @Override
    public OrderAddress getOrderAddressById(String id) {

        logger.info("getOrderAddressyId");
        try {

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

        return null;
    }

    @Override
    public OrderAddress getOrderAddress(OrderAddress record) {

        logger.info("getOrderAddress");
        try {

            return orderAddressMapper.queryOrderAddress(record);
        } catch (Exception e) {
        logger.error("getOrderAddress", e);
        }

        return null;
    }

    @Override
    public boolean createOrderAddress(OrderAddress record) {

        logger.info("createOrderAddress");
        try {

            int updates = orderAddressMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteOrderAddress(String id) {

        logger.info("deleteOrderAddress");
        try {

             int updates = orderAddressMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateOrderAddress(OrderAddress record) {

        logger.info("updateOrderAddress");
        try {

            int updates = orderAddressMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

