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.RepairOfflineRecordMapper;
import com.repair.mapper.RepairOfflineRecordMapper;
import com.repair.model.pojo.RepairOfflineRecord;
import com.repair.model.pojo.RepairOfflineRecord;
import com.repair.model.result.PageUtils;
import com.repair.model.vo.OfflineDetailVo;
import com.repair.services.RepairOfflineRecordService;
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 RepairOfflineRecordServiceImpl extends ServiceImpl<RepairOfflineRecordMapper, RepairOfflineRecord> implements RepairOfflineRecordService {

    @Autowired
    private RepairOfflineRecordMapper repairOfflineRecordMapper;

    @Override
    public int insertRepairOfflineRecord(RepairOfflineRecord rtr) {
        int result = repairOfflineRecordMapper.insert(rtr);
        return result;
    }

    @Override
    public int updateRepairOfflineRecord(RepairOfflineRecord rtr) {
        int result = repairOfflineRecordMapper.updateById(rtr);
        return result;
    }

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

    @Override
    public int deleteRepairOfflineRecordById(int id) {
        int result = repairOfflineRecordMapper.deleteById(id);
        return result;
    }

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

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

    @Override
    public RepairOfflineRecord getRepairByRecordId(Integer recordId) {

        QueryWrapper<RepairOfflineRecord> queryWrapper = new QueryWrapper();
        queryWrapper.eq("record_id", recordId);
        queryWrapper.eq("approval_statu", 2);
        RepairOfflineRecord result = repairOfflineRecordMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public OfflineDetailVo queryOfflineDetail(Integer recordId) {
        OfflineDetailVo result = repairOfflineRecordMapper.queryOfflineDetail(recordId);
        return result;
    }
}
