package com.yiqi.order.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yiqi.app.domain.AppUser;
import com.yiqi.app.service.IAppUserService;
import com.yiqi.common.utils.DateUtils;
import com.yiqi.common.utils.SecurityUtils;
import com.yiqi.system.domain.SysStore;
import com.yiqi.system.service.ISysStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yiqi.order.mapper.OrderRechargeRefundMapper;
import com.yiqi.order.domain.OrderRechargeRefund;
import com.yiqi.order.service.IOrderRechargeRefundService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 充值卡退款管理Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-10
 */
@Service
public class OrderRechargeRefundServiceImpl extends ServiceImpl<OrderRechargeRefundMapper,OrderRechargeRefund> implements IOrderRechargeRefundService {

    @Autowired
    private IAppUserService appUserService;

    @Autowired
    private ISysStoreService sysStoreService;

    //<editor-folder desc="基础韩素">
    /**
     * 查询充值卡退款管理
     *
     * @param id 充值卡退款管理主键
     * @return 充值卡退款管理
     */
    @Override
    public OrderRechargeRefund selectOrderRechargeRefundById(Long id) {
        return baseMapper.selectById(id);
    }

    /**
     * 查询充值卡退款管理列表
     *
     * @param orderNo 充值卡退款管理
     */
    @Override
    public OrderRechargeRefund selectOrderRechargeOrderNo(String orderNo) {
        return baseMapper.selectOne(new QueryWrapper<OrderRechargeRefund>().eq("order_no", orderNo).last("limit 1"));
    }

    /**
     * 查询充值卡退款管理列表
     *
     * @param orderRechargeRefund 充值卡退款管理
     * @return 充值卡退款管理
     */
    @Override
    public List<OrderRechargeRefund> selectOrderRechargeRefundList(OrderRechargeRefund orderRechargeRefund) {
        List<OrderRechargeRefund>  orderRechargeRefundList = baseMapper.selectOrderRechargeRefundList(orderRechargeRefund);

        for(OrderRechargeRefund orderRechargeRefund_ : orderRechargeRefundList){
            if(orderRechargeRefund_.getRechargeUserId()!=null){
                AppUser appUser = appUserService.selectAppUserById(orderRechargeRefund_.getRechargeUserId());
                if(appUser != null){
                    orderRechargeRefund_.setAppUserName(appUser.getNickName());
                    orderRechargeRefund_.setAppUserPhone(appUser.getPhoneNumber());
                }
            }
            if(orderRechargeRefund_.getStoreId()!=null){
                orderRechargeRefund_.setStoreName(sysStoreService.selectSysStoreById(orderRechargeRefund_.getStoreId()).getName());
            }
        }
        return orderRechargeRefundList;
    }

    /**
     * 新增充值卡退款管理
     *
     * @param orderRechargeRefund 充值卡退款管理
     * @return 结果
     */
    @Override
    public int insertOrderRechargeRefund(OrderRechargeRefund orderRechargeRefund) {
        orderRechargeRefund.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertOrderRechargeRefund(orderRechargeRefund);
    }

    /**
     * 修改充值卡退款管理
     *
     * @param orderRechargeRefund 充值卡退款管理
     * @return 结果
     */
    @Override
    public int updateOrderRechargeRefund(OrderRechargeRefund orderRechargeRefund) {
        orderRechargeRefund.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateOrderRechargeRefund(orderRechargeRefund);
    }

    /**
     * 批量删除充值卡退款管理
     *
     * @param ids 需要删除的充值卡退款管理主键
     * @return 结果
     */
    @Override
    public int deleteOrderRechargeRefundByIds(Long[] ids) {
        return baseMapper.deleteOrderRechargeRefundByIds(ids);
    }

    /**
     * 删除充值卡退款管理信息
     *
     * @param id 充值卡退款管理主键
     * @return 结果
     */
    @Override
    public int deleteOrderRechargeRefundById(Long id) {
        return baseMapper.deleteOrderRechargeRefundById(id);
    }

    @Override
    public int refundRechargeNo(OrderRechargeRefund orderRechargeRefund) {
        return 0;
    }


}
