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.RepairCollaborateRecordMapper;
import com.repair.model.pojo.RepairCollaborateRecord;
import com.repair.model.pojo.RepairTransferRecord;
import com.repair.model.result.PageUtils;
import com.repair.model.vo.CollaborateDetailVo;
import com.repair.model.vo.CollaborateRecordVo;
import com.repair.services.RepairCollaborateRecordService;
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 RepairCollaborateRecordServiceImpl extends ServiceImpl<RepairCollaborateRecordMapper, RepairCollaborateRecord> implements RepairCollaborateRecordService {

    @Autowired
    private RepairCollaborateRecordMapper repairCollaborateRecordMapper;

    @Override
    public int insertRepairCollaborateRecord(RepairCollaborateRecord rcr) {
        int result = repairCollaborateRecordMapper.insert(rcr);
        return result;
    }

    @Override
    public int updateRepairCollaborateRecord(RepairCollaborateRecord rcr) {
        int result = repairCollaborateRecordMapper.updateById(rcr);
        return result;
    }

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

    @Override
    public int deleteRepairCollaborateRecordById(int id) {
        int result = repairCollaborateRecordMapper.deleteById(id);
        return result;
    }

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

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

    @Override
    public List<CollaborateRecordVo> queryRepairCollaborate(List<Integer> recordIds) {
        List<CollaborateRecordVo> result = repairCollaborateRecordMapper.queryCollaborateRecordList(recordIds);
        return result;
    }

    @Override
    public RepairCollaborateRecord getRepairByRecordId(Integer recordId) {
        QueryWrapper<RepairCollaborateRecord> queryWrapper = new QueryWrapper();
        queryWrapper.eq("record_id", recordId);
        queryWrapper.eq("approval_statu", 2);
        RepairCollaborateRecord result = repairCollaborateRecordMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public RepairCollaborateRecord getRepairNeByRecordId(Integer recordId) {
        QueryWrapper<RepairCollaborateRecord> queryWrapper = new QueryWrapper();
        queryWrapper.eq("record_id", recordId);
        queryWrapper.ne("approval_statu", 0);
        RepairCollaborateRecord result = repairCollaborateRecordMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public CollaborateDetailVo queryCollaborateDetail(Integer recordId) {
        CollaborateDetailVo result = repairCollaborateRecordMapper.queryCollaborateDetail(recordId);
        return result;
    }
}
