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

import cn.iocoder.yudao.module.rescue.domain.RescueInfo;
import cn.iocoder.yudao.module.rescue.domain.RescueRefuelRecord;
import cn.iocoder.yudao.module.rescue.service.IRescueRefuelRecordService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.iocoder.yudao.module.rescue.mapper.RescueRefuelRecordMapper;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 加油记录Service业务层处理
 *
 * @author zcy
 * @date 2023-09-26
 */
@Service
public class RescueRefuelRecordServiceImpl extends ServiceImpl<RescueRefuelRecordMapper, RescueRefuelRecord> implements IRescueRefuelRecordService {

    /**
     * 查询加油记录
     *
     * @param id 加油记录主键
     * @return 加油记录
     */
    @Override
    public RescueRefuelRecord selectRescueRefuelRecordById(Long id) {
        return baseMapper.selectRescueRefuelRecordById(id);
    }

    /**
     * 查询加油记录列表
     *
     * @param rescueRefuelRecord 加油记录
     * @return 加油记录
     */
    @Override
    public IPage<RescueRefuelRecord> selectRescueRefuelRecordList(RescueRefuelRecord rescueRefuelRecord, Page<RescueRefuelRecord> page) {
        return baseMapper.selectRescueRefuelRecordList(rescueRefuelRecord, page);
    }

    /**
     * 新增加油记录
     *
     * @param rescueRefuelRecord 加油记录
     * @return 结果
     */
    @Override
    public int insertRescueRefuelRecord(RescueRefuelRecord rescueRefuelRecord) {
        return baseMapper.insert(rescueRefuelRecord);
    }

    /**
     * 修改加油记录
     *
     * @param rescueRefuelRecord 加油记录
     * @return 结果
     */
    @Override
    public int updateRescueRefuelRecord(RescueRefuelRecord rescueRefuelRecord) {
        return baseMapper.updateById(rescueRefuelRecord);
    }

    /**
     * 批量删除加油记录
     *
     * @param ids 需要删除的加油记录主键
     * @return 结果
     */
    @Override
    public int deleteRescueRefuelRecordByIds(Long[] ids) {
        return baseMapper.deleteByIds(Arrays.asList(ids));
    }

    /**
     * 删除加油记录信息
     *
     * @param id 加油记录主键
     * @return 结果
     */
    @Override
    public int deleteRescueRefuelRecordById(Long id) {
        return baseMapper.deleteRescueRefuelRecordById(id);
    }


    //通过司机主键和时间计算该月的加油总数和行驶总公里数
    @Override
    public JSONObject getMonthRescueRefuelRecord(Long driverId, String time, Long carId) {
        return baseMapper.getMonthRescueRefuelRecord(driverId, time, carId);

    }

    @Override
    public JSONObject listData(RescueInfo rescueInfo) {
        return baseMapper.listData(rescueInfo);
    }
}
