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

import cn.iocoder.yudao.module.rescue.domain.RescueCarInfo;
import cn.iocoder.yudao.module.rescue.domain.RescueCarSpend;
import cn.iocoder.yudao.module.rescue.mapper.RescueCarSpendMapper;
import cn.iocoder.yudao.module.rescue.service.IRescueCarInfoService;
import cn.iocoder.yudao.module.rescue.service.IRescueCarSpendService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.Valid;
import java.util.List;

/**
 * 车辆消费管理Service业务层处理
 *
 * @author zcy
 * @date 2023-11-30
 */
@Service
public class RescueCarSpendServiceImpl extends ServiceImpl<RescueCarSpendMapper, RescueCarSpend> implements IRescueCarSpendService {
    @Autowired
    private RescueCarSpendMapper rescueCarSpendMapper;
    @Autowired
    private IRescueCarInfoService carInfoService;

    /**
     * 查询车辆消费管理
     *
     * @param id 车辆消费管理主键
     * @return 车辆消费管理
     */
    @Override
    public RescueCarSpend selectRescueCarSpendById(Long id) {
        return rescueCarSpendMapper.selectRescueCarSpendById(id);
    }

    /**
     * 查询车辆消费管理列表
     *
     * @param rescueCarSpend 车辆消费管理
     * @return 车辆消费管理
     */
    @Override
    public IPage<RescueCarSpend> selectRescueCarSpendList(RescueCarSpend rescueCarSpend, Page<RescueCarSpend> page) {
        return rescueCarSpendMapper.selectRescueCarSpendList(rescueCarSpend, page);
    }

    /**
     * 新增车辆消费管理
     *
     * @param rescueCarSpend 车辆消费管理
     * @return 结果
     */
    @Override
    public int insertRescueCarSpend(@Valid RescueCarSpend rescueCarSpend) {
        RescueCarInfo rescueCarInfo = carInfoService.selectRescueCarInfoById(rescueCarSpend.getRescueCarId());
        rescueCarSpend.setCarNum(rescueCarInfo.getRescueCarNum());
        return rescueCarSpendMapper.insertRescueCarSpend(rescueCarSpend);
    }

    /**
     * 修改车辆消费管理
     *
     * @param rescueCarSpend 车辆消费管理
     * @return 结果
     */
    @Override
    public int updateRescueCarSpend(@Valid RescueCarSpend rescueCarSpend) {
        RescueCarInfo rescueCarInfo = carInfoService.selectRescueCarInfoById(rescueCarSpend.getRescueCarId());
        rescueCarSpend.setCarNum(rescueCarInfo.getRescueCarNum());
        return rescueCarSpendMapper.updateRescueCarSpend(rescueCarSpend);
    }

    /**
     * 批量删除车辆消费管理
     *
     * @param ids 需要删除的车辆消费管理主键
     * @return 结果
     */
    @Override
    public int deleteRescueCarSpendByIds(Long[] ids) {
        return rescueCarSpendMapper.deleteRescueCarSpendByIds(ids);
    }

    /**
     * 删除车辆消费管理信息
     *
     * @param id 车辆消费管理主键
     * @return 结果
     */
    @Override
    public int deleteRescueCarSpendById(Long id) {
        return rescueCarSpendMapper.deleteRescueCarSpendById(id);
    }
}
