package cn.iocoder.yudao.module.rescue.service.impl;

import cn.iocoder.yudao.module.rescue.domain.RescueOrderInfo;
import cn.iocoder.yudao.module.rescue.domain.RescueOrderReturn;
import cn.iocoder.yudao.module.rescue.mapper.RescueOrderReturnMapper;
import cn.iocoder.yudao.module.rescue.service.IRescueOrderInfoService;
import cn.iocoder.yudao.module.rescue.service.IRescueOrderReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 签单归还Service业务层处理
 *
 * @author zcy
 * @date 2023-11-25
 */
@Service
public class RescueOrderReturnServiceImpl implements IRescueOrderReturnService
{
    @Autowired
    private RescueOrderReturnMapper rescueOrderReturnMapper;
    @Autowired
    private IRescueOrderInfoService orderInfoService;

    /**
     * 查询签单归还
     *
     * @param id 签单归还主键
     * @return 签单归还
     */
    @Override
    public RescueOrderReturn selectRescueOrderReturnById(Long id)
    {
        return rescueOrderReturnMapper.selectRescueOrderReturnById(id);
    }

    /**
     * 查询签单归还列表
     *
     * @param rescueOrderReturn 签单归还
     * @return 签单归还
     */
    @Override
    public List<RescueOrderReturn> selectRescueOrderReturnList(RescueOrderReturn rescueOrderReturn)
    {
        return rescueOrderReturnMapper.selectRescueOrderReturnList(rescueOrderReturn);
    }

    /**
     * 新增签单归还
     *
     * @param rescueOrderReturn 签单归还
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertRescueOrderReturn(RescueOrderReturn rescueOrderReturn)
    {
        RescueOrderInfo orderInfo = orderInfoService.getById(rescueOrderReturn.getRescueOrderId());
        orderInfo.setOrderStatus("3");
        orderInfo.setPayMoney(rescueOrderReturn.getReturnMoney());
        orderInfo.setPayRemark(rescueOrderReturn.getRemark());
        orderInfo.setPayTime(new Date());
        //处理 订单状态
        orderInfoService.updateRescueOrderInfo(orderInfo);
        rescueOrderReturn.setReturnTime(new Date());
        return rescueOrderReturnMapper.insertRescueOrderReturn(rescueOrderReturn);
    }

    /**
     * 修改签单归还
     *
     * @param rescueOrderReturn 签单归还
     * @return 结果
     */
    @Override
    public int updateRescueOrderReturn(RescueOrderReturn rescueOrderReturn)
    {
        return rescueOrderReturnMapper.updateRescueOrderReturn(rescueOrderReturn);
    }

    /**
     * 批量删除签单归还
     *
     * @param ids 需要删除的签单归还主键
     * @return 结果
     */
    @Override
    public int deleteRescueOrderReturnByIds(Long[] ids)
    {
        return rescueOrderReturnMapper.deleteRescueOrderReturnByIds(ids);
    }

    /**
     * 删除签单归还信息
     *
     * @param id 签单归还主键
     * @return 结果
     */
    @Override
    public int deleteRescueOrderReturnById(Long id)
    {
        return rescueOrderReturnMapper.deleteRescueOrderReturnById(id);
    }
}
