package com.repair.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.repair.mapper.RepairTrackRecordMapper;
import com.repair.model.pojo.RepairTrackRecord;
import com.repair.model.result.PageUtils;
import com.repair.model.vo.TrackDetailsVo;
import com.repair.services.RepairTrackRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-07-20
 */
@Service
public class RepairTrackRecordServiceImpl extends ServiceImpl<RepairTrackRecordMapper, RepairTrackRecord> implements RepairTrackRecordService {

    @Autowired
    private RepairTrackRecordMapper repairTrackRecordMapper;

    @Override
    public int insertRepairTrackRecord(RepairTrackRecord rtr) {
        int result = repairTrackRecordMapper.insert(rtr);
        return result;
    }

    @Override
    public int updateRepairTrackRecord(RepairTrackRecord rtr) {
        int result = repairTrackRecordMapper.updateById(rtr);
        return result;
    }

    @Override
    public PageUtils<RepairTrackRecord> queryPageRepairTrackRecords(int currentPage, int pageCount, String name) {
        Page<RepairTrackRecord> page = new Page<>(currentPage, pageCount);
        QueryWrapper<RepairTrackRecord> queryWrapper = new QueryWrapper<>();
        IPage<RepairTrackRecord> result = repairTrackRecordMapper.selectPage(page, queryWrapper);
        return new PageUtils(result);
    }

    @Override
    public int deleteRepairTrackRecordById(int id) {
        int result = repairTrackRecordMapper.deleteById(id);
        return result;
    }

    @Override
    public RepairTrackRecord getRepairById(int id) {
        RepairTrackRecord result = repairTrackRecordMapper.selectById(id);
        return result;
    }

    @Override
    public List<RepairTrackRecord> getRepairs() {
        List<RepairTrackRecord> result = repairTrackRecordMapper.selectList(null);
        return result;
    }

    @Override
    public List<TrackDetailsVo> queryDetailData(Integer recordId) {
        List<TrackDetailsVo> result = repairTrackRecordMapper.queryDetailData(recordId);
        return result;
    }
}
