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.RepairTransferRecordMapper;
import com.repair.model.pojo.RepairShiftSettings;
import com.repair.model.pojo.RepairTransferRecord;
import com.repair.model.result.PageUtils;
import com.repair.model.vo.TransferDetailVo;
import com.repair.services.RepairTransferRecordService;
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 RepairTransferRecordServiceImpl extends ServiceImpl<RepairTransferRecordMapper, RepairTransferRecord> implements RepairTransferRecordService {

    @Autowired
    private RepairTransferRecordMapper repairTransferRecordMapper;

    @Override
    public int insertRepairTransferRecord(RepairTransferRecord rtr) {
        int result = repairTransferRecordMapper.insert(rtr);
        return result;
    }

    @Override
    public int updateRepairTransferRecord(RepairTransferRecord rtr) {
        int result = repairTransferRecordMapper.updateById(rtr);
        return result;
    }

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

    @Override
    public int deleteRepairTransferRecordById(int id) {
        int result = repairTransferRecordMapper.deleteById(id);
        return result;
    }

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

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

    @Override
    public RepairTransferRecord getRepairByRecordId(Integer recordId) {

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

    @Override
    public TransferDetailVo queryTransferDetail(Integer recordId) {
        TransferDetailVo result = repairTransferRecordMapper.queryTransferDetail(recordId);
        return result;
    }
}
