package com.ghy.order.service.impl;

import com.ghy.common.constant.UserConstants;
import com.ghy.common.core.text.Convert;
import com.ghy.order.domain.OrderDetail;
import com.ghy.order.mapper.OrderDetailMapper;
import com.ghy.order.service.OrderDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderDetailServiceImpl implements OrderDetailService {

    @Resource
    private OrderDetailMapper orderDetailMapper;

    @Override
    public int insertOrderDetail(OrderDetail orderDetail) {
        return orderDetailMapper.insertOrderDetail(orderDetail);
    }

    @Override
    public int updateOrderDetail(OrderDetail orderDetail) {
        return orderDetailMapper.updateOrderDetail(orderDetail);
    }

    @Override
    public List<OrderDetail> selectOrderDetailList(OrderDetail orderDetail) {
        return orderDetailMapper.selectOrderDetailList(orderDetail);
    }

    @Override
    public OrderDetail selectById(Long orderDetailId) {
        return orderDetailMapper.selectById(orderDetailId);
    }

    @Override
    public int deleteOrderDetailByIds(String ids) {
        Long[] orderDetailIds = Convert.toLongArray(ids);
        return orderDetailMapper.deleteOrderDetailByIds(orderDetailIds);
    }

    @Override
    public String checkOrderDetailCodeUnique(OrderDetail orderDetail) {
        long orderDetailId = orderDetail.getId() == null ? -1L : orderDetail.getId();
        OrderDetail info = orderDetailMapper.checkOrderDetailCodeUnique(orderDetail.getCode());
        if (info != null && info.getId() != orderDetailId) {
            return UserConstants.ORDER_CODE_NOT_UNIQUE;
        }
        return UserConstants.ORDER_CODE_UNIQUE;
    }
}
