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.OrderSkuDao;
import com.pine.admin.modules.business.entity.OrderSku;
import com.pine.admin.modules.business.service.OrderSkuService;


@Service("orderSkuService")
@Slf4j
public class OrderSkuServiceImpl implements OrderSkuService {

    @Autowired
    private OrderSkuDao orderSkuDao;


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

        log.info("getOrderSkuList");
        try {

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

        return null;
    }

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

        log.info("getOrderSkuByPage");
        try {

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

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

        return null;
    }

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

        log.info("getOrderSkuById");
        try {

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

        return null;
    }

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

        log.info("getOrderSku");
        try {

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

        return null;
    }

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

        log.info("createOrderSku");
        try {

            int updates = orderSkuDao.insertSelective(record);

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

        return false;
    }

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

        log.info("deleteOrderSku");
        try {

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

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

        return false;
    }

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

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

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

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

        return false;
    }

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

        log.info("updateOrderSku");
        try {

            int updates = orderSkuDao.updateByPrimaryKeySelective(record);

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

        return false;
    }

    @Override
    public List<OrderSku> queryByOrderId(Long orderId) {
        log.debug("queryByOrderId and orderId:{}", orderId);
        return orderSkuDao.queryByOrderId(orderId);
    }
}
