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.RepairSchoolMapper;
import com.repair.model.pojo.RepairSchool;
import com.repair.model.result.PageUtils;
import com.repair.services.RepairSchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-07-12
 */
@Service
public class RepairSchoolServiceImpl extends ServiceImpl<RepairSchoolMapper, RepairSchool> implements RepairSchoolService {

    @Autowired
    private RepairSchoolMapper repairSchoolMapper;

    @Override
    public int insertRepairSchool(RepairSchool rs) {
        int result = repairSchoolMapper.insert(rs);
        return result;
    }

    @Override
    public int updateRepairSchool(RepairSchool rs) {
        int result = repairSchoolMapper.updateById(rs);
        return result;
    }

    @Override
    public PageUtils<RepairSchool> queryPageRepairSchools(int currentPage, int pageCount, String name) {
        Page<RepairSchool> page = new Page<>(currentPage, pageCount);
        QueryWrapper<RepairSchool> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(name),"name",name);
        IPage<RepairSchool> result = repairSchoolMapper.selectPage(page, queryWrapper);
        return new PageUtils(result);
    }

    @Override
    public int deleteRepairSchoolById(int id) {
        int result = repairSchoolMapper.deleteById(id);
        return result;
    }

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