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.RepairWorkTypeMapper;
import com.repair.model.pojo.RepairWorkType;
import com.repair.model.result.PageUtils;
import com.repair.model.vo.RepairWorkTypeVo;
import com.repair.services.RepairWorkTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2023-07-18
 */
@Service
public class RepairWorkTypeServiceImpl extends ServiceImpl<RepairWorkTypeMapper, RepairWorkType> implements RepairWorkTypeService {

    @Autowired
    private RepairWorkTypeMapper repairWorkTypeMapper;


    @Override
    public int insertRepairWorkType(RepairWorkType rns) {
        int result = repairWorkTypeMapper.insert(rns);
        return result;
    }

    @Override
    public int updateRepairWorkType(RepairWorkType rns) {
        int result = repairWorkTypeMapper.updateById(rns);
        return result;
    }

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

    @Override
    public int deleteRepairWorkTypeById(int id) {
        int result = repairWorkTypeMapper.deleteById(id);
        return result;
    }

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

    @Override
    public List<RepairWorkTypeVo> getRepairWorkTypes() {
        List<RepairWorkTypeVo> datas = repairWorkTypeMapper.queryWorkTypeList();
        return datas;
    }
}
