package com.pine.admin.modules.business.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import com.pine.common.dto.Page;
import org.springframework.transaction.annotation.Transactional;

import com.pine.admin.modules.business.dao.OrderAttrDao;
import com.pine.admin.modules.business.entity.OrderAttr;
import com.pine.admin.modules.business.service.OrderAttrService;


@Service("orderAttrService")
@Slf4j
public class OrderAttrServiceImpl implements OrderAttrService {

    @Autowired
    private OrderAttrDao orderAttrDao;


    @Override
    @Transactional
    public List<OrderAttr> getAllList(OrderAttr record) {

        log.info("getOrderAttrList");
        try {

            return orderAttrDao.queryAll(record);
        } catch (Exception e) {
            log.error("getOrderAttrList", e);
        }

        return null;
    }

    @Override
    public OrderAttr queryByOrderId(long orderId) {
        log.debug("queryByOrderId and orderId:{}", orderId);
        return orderAttrDao.queryByOrderId(orderId);
    }

    @Override
    @Transactional
    public List<OrderAttr> getByPage(Page page, OrderAttr record) {

        log.info("getOrderAttrByPage");
        try {

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

            return orderAttrDao.queryByPage(parameter);
        } catch (Exception e) {
            log.error("getOrderAttrByPage", e);
        }

        return null;
    }

    @Override
    @Transactional
    public OrderAttr getById(String id) {

        log.info("getOrderAttrById");
        try {

            return orderAttrDao.selectByPrimaryKey(Integer.valueOf(id));
        } catch (Exception e) {
            log.error("getOrderAttrById", e);
        }

        return null;
    }

    @Override
    @Transactional
    public OrderAttr getOne(OrderAttr record) {

        log.info("getOrderAttr");
        try {

            return orderAttrDao.queryOne(record);
        } catch (Exception e) {
            log.error("getOrderAttr", e);
        }

        return null;
    }

    @Override
    @Transactional
    public boolean create(OrderAttr record) {

        log.info("createOrderAttr");
        try {

            int updates = orderAttrDao.insertSelective(record);

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

        return false;
    }

    @Override
    @Transactional
    public boolean delete(String id) {

        log.info("deleteOrderAttr");
        try {

            int updates = orderAttrDao.delete(Integer.valueOf(id));

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

        return false;
    }

    @Override
    @Transactional
    public boolean deltetByIds(String ids) {

        log.info("deleteeOrderAttr byIDS");
        try {

            String[] id = ids.split(";");
            int updates = orderAttrDao.deleteIds(id);

            if (id.length == updates) {
                return true;
            }
        } catch (Exception e) {
            log.error("deleteeOrderAttr byIDS", e);
        }

        return false;
    }

    @Override
    @Transactional
    public boolean update(OrderAttr record) {

        log.info("updateOrderAttr");
        try {

            int updates = orderAttrDao.updateByPrimaryKeySelective(record);

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

        return false;
    }

}
