package com.younike.system.service.impl;

import java.util.List;
import java.time.LocalDateTime;

import com.younike.system.param.OredrRefundParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.younike.system.mapper.OrderRefundMapper;
import com.younike.system.domain.OrderRefund;
import com.younike.system.service.IOrderRefundService;

/**
 * 订单--退款处理Service业务层处理
 *
 * @author elev
 * @date 2022-01-10
 */
@Service
public class OrderRefundServiceImpl implements IOrderRefundService {
    @Autowired
    private OrderRefundMapper orderRefundMapper;

    @Override
    public OrderRefund selectOrderRefundByOrderId(String orderId) {
        List<OrderRefund> orderRefunds = orderRefundMapper.selectOrderRefundByOrderId(orderId);
        if (orderRefunds == null || orderRefunds.size() == 0) {
            return null;
        }
        return orderRefunds.get(0);
    }

    /**
     * 查询订单--退款处理
     *
     * @param orderRefundId 订单--退款处理主键
     * @return 订单--退款处理
     */
    @Override
    public OrderRefund selectOrderRefundByOrderRefundId(Long orderRefundId) {
        return orderRefundMapper.selectOrderRefundByOrderRefundId(orderRefundId);
    }

    /**
     * 查询订单--退款处理列表
     *
     * @param orderRefund 订单--退款处理
     * @return 订单--退款处理
     */
    @Override
    public List<OrderRefund> selectOrderRefundList(OrderRefund orderRefund) {
        return orderRefundMapper.selectOrderRefundList(orderRefund);
    }

    /**
     * 新增订单--退款处理
     *
     * @param orderRefund 订单--退款处理
     * @return 结果
     */
    @Override
    public int insertOrderRefund(OrderRefund orderRefund) {
        orderRefund.setCreateTime(LocalDateTime.now());
        return orderRefundMapper.insertOrderRefund(orderRefund);
    }

    /**
     * 修改订单--退款处理
     *
     * @param orderRefund 订单--退款处理
     * @return 结果
     */
    @Override
    public int updateOrderRefund(OrderRefund orderRefund) {
        orderRefund.setUpdateTime(LocalDateTime.now());
        return orderRefundMapper.updateOrderRefund(orderRefund);
    }

    /**
     * 批量删除订单--退款处理
     *
     * @param orderRefundIds 需要删除的订单--退款处理主键
     * @return 结果
     */
    @Override
    public int deleteOrderRefundByOrderRefundIds(Long[] orderRefundIds) {
        return orderRefundMapper.deleteOrderRefundByOrderRefundIds(orderRefundIds);
    }

    /**
     * 删除订单--退款处理信息
     *
     * @param orderRefundId 订单--退款处理主键
     * @return 结果
     */
    @Override
    public int deleteOrderRefundByOrderRefundId(Long orderRefundId)
    {
        return orderRefundMapper.deleteOrderRefundByOrderRefundId(orderRefundId);
    }

    /**
     * 根据订单id查询订单退款记录
     * @param orderId
     * @return
     */
    @Override
    public OredrRefundParam selectOrderId(Long orderId) {
        return orderRefundMapper.selectOrderId(orderId);
    }
}
