package com.ruoyi.system.service.impl;

import java.time.LocalDate;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.dto.OrderDetailDto;
import com.ruoyi.system.domain.dto.OrderListDto;
import com.ruoyi.system.domain.dto.SysOrderPayBackDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysOrderMapper;
import com.ruoyi.system.domain.SysOrder;
import com.ruoyi.system.service.ISysOrderService;

/**
 * 订单信息Service业务层处理
 * 
 * @author haotian
 * @date 2024-11-21
 */
@Service
public class SysOrderServiceImpl implements ISysOrderService 
{
    @Autowired
    private SysOrderMapper sysOrderMapper;

    /**
     * 查询订单信息
     * 
     * @param orderId 订单信息主键
     * @return 订单信息
     */
    @Override
    public SysOrder selectSysOrderByOrderId(Long orderId)
    {
        return sysOrderMapper.selectSysOrderByOrderId(orderId);
    }

    /**
     * 查询订单信息列表
     * 
     * @param sysOrder 订单信息
     * @return 订单信息
     */
    @Override
    public List<SysOrder> selectSysOrderList(SysOrder sysOrder)
    {
        return sysOrderMapper.selectSysOrderList(sysOrder);
    }

    /**
     * 新增订单信息
     * 
     * @param sysOrder 订单信息
     * @return 结果
     */
    @Override
    public int insertSysOrder(SysOrder sysOrder)
    {
        sysOrder.setCreateTime(DateUtils.getNowDate());
        return sysOrderMapper.insertSysOrder(sysOrder);
    }

    /**
     * 修改订单信息
     * 
     * @param sysOrder 订单信息
     * @return 结果
     */
    @Override
    public int updateSysOrder(SysOrder sysOrder)
    {
        // 设置更新时间
        sysOrder.setUpdateTime(DateUtils.getNowDate());
        return sysOrderMapper.updateSysOrder(sysOrder);
    }

    /**
     * 批量删除订单信息
     * 
     * @param orderIds 需要删除的订单信息主键
     * @return 结果
     */
    @Override
    public int deleteSysOrderByOrderIds(Long[] orderIds)
    {
        return sysOrderMapper.deleteSysOrderByOrderIds(orderIds);
    }

    /**
     * 删除订单信息信息
     * 
     * @param orderId 订单信息主键
     * @return 结果
     */
    @Override
    public int deleteSysOrderByOrderId(Long orderId)
    {
        return sysOrderMapper.deleteSysOrderByOrderId(orderId);
    }

    @Override
    public int isTimeLegal(LocalDate startTime, LocalDate endTime, Long sourceId) {
        return sysOrderMapper.isTimeLegal(startTime, endTime, sourceId);
    }

    @Override
    public List<OrderListDto> getOrderListDto(SysOrder sysOrder){
        return sysOrderMapper.getOrderListDto(sysOrder);
    }

    @Override
    public OrderDetailDto getOrderDetailDto(Long orderId, Long id){
        return sysOrderMapper.getOrderDetailDto(orderId, id);
    }
    /*
     * 系统每天--根据日期和订单状态 计数收入/退款
     * */
    @Override
    public Long getMoneybyDateAndStatus(LocalDate date){
        return sysOrderMapper.getMoneybyDateAndStatus(date);
    }

    /*
     * 系统每天--根据日期计数退款
     * */
    @Override
    public Long getRefund(LocalDate date){
        return sysOrderMapper.getRefund(date);
    }

    /**
     *
     * 支付回调后根据orderId返回订单详情
     * */
    @Override
    public SysOrderPayBackDto getSysOrderPayBackDto(Long orderId){
        return sysOrderMapper.getSysOrderPayBackDto(orderId);
    }

    /**
     *
     * 根据wordId返回订单列表
     * */
    @Override
    public List<SysOrder> getSysOrderByWordId(Long wordId){
        return sysOrderMapper.getSysOrderByWordId(wordId);
    }

    /**
     * 根据orderInfoId退款
     * */
    @Override
    public int updateSysOrderByOrderInfoId(String orderInfoId, String status, Long money){
        return sysOrderMapper.updateSysOrderByOrderInfoId(orderInfoId, status, money);
    }
}
