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.RepairLeaveMessageMapper;
import com.repair.model.pojo.RepairLeaveMessage;
import com.repair.model.result.PageUtils;
import com.repair.services.RepairLeaveMessageService;
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 RepairLeaveMessageServiceImpl extends ServiceImpl<RepairLeaveMessageMapper, RepairLeaveMessage> implements RepairLeaveMessageService {

    @Autowired
    private RepairLeaveMessageMapper repairLeaveMessageMapper;

    @Override
    public int insertRepairLeaveMessage(RepairLeaveMessage rlm) {
        int result = repairLeaveMessageMapper.insert(rlm);
        return result;
    }

    @Override
    public int updateRepairLeaveMessage(RepairLeaveMessage rlm) {
        int result = repairLeaveMessageMapper.updateById(rlm);
        return result;
    }

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

    @Override
    public int deleteRepairLeaveMessageById(int id) {
        int result = repairLeaveMessageMapper.deleteById(id);
        return result;
    }

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

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

    @Override
    public boolean inserBatchLeaveMessage(List<RepairLeaveMessage> datas) {
        boolean result = this.saveBatch(datas, datas.size());
        return result;
    }

    @Override
    public List<RepairLeaveMessage> getRepairsByRecordIds(List<Integer> recordIds) {
        QueryWrapper<RepairLeaveMessage> queryWrapper = new QueryWrapper();
        queryWrapper.in("record_id", recordIds);
        List<RepairLeaveMessage> result = repairLeaveMessageMapper.selectList(queryWrapper);
        return result;
    }
}
